Updated to 1.8

This commit is contained in:
lishid 2015-01-05 21:18:06 -05:00
parent 510222c0e4
commit 80f94301b8
161 changed files with 592 additions and 12527 deletions

2
README
View File

@ -1,4 +1,4 @@
Copyright (C) 2011-2012 lishid. All rights reserved. Copyright (C) 2011-2015 lishid. All rights reserved.
This program is free software: you can redistribute it and/or modify This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by it under the terms of the GNU General Public License as published by

80
pom.xml Normal file
View File

@ -0,0 +1,80 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.lishid</groupId>
<artifactId>orebfuscator</artifactId>
<packaging>jar</packaging>
<version>3.0.0</version>
<name>Orebfuscator</name>
<url>http://dev.bukkit.org/server-mods/orebfuscator/</url>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<repositories>
<repository>
<id>comphenix-snapshots</id>
<url>http://repo.comphenix.net/content/repositories/snapshots/</url>
</repository>
<repository>
<id>repobo-snap</id>
<url>http://repo.bukkit.org/content/groups/public</url>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
<id>bukkit-plugins</id>
<url>http://repo.bukkit.org/content/groups/public</url>
</pluginRepository>
</pluginRepositories>
<dependencies>
<dependency>
<groupId>org.bukkit</groupId>
<artifactId>craftbukkit</artifactId>
<version>1.8-R0.1-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.comphenix.protocol</groupId>
<artifactId>ProtocolLib</artifactId>
<version>3.5.0-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
</dependencies>
<build>
<defaultGoal>clean install</defaultGoal>
<sourceDirectory>src/main/java</sourceDirectory>
<testSourceDirectory>src/test/java</testSourceDirectory>
<resources>
<resource>
<directory>src/main/resources</directory>
<filtering>true</filtering>
<excludes>
<exclude>**/*.java</exclude>
</excludes>
</resource>
</resources>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.3.2</version>
<configuration>
<source>1.6</source>
<target>1.6</target>
</configuration>
</plugin>
</plugins>
</build>
<scm>
<connection>scm:git:git://github.com/lishid/Orebfuscator.git</connection>
<developerConnection>scm:git:git@github.com:lishid/Orebfuscator.git</developerConnection>
<url>https://github.com/lishid/Orebfuscator</url>
</scm>
</project>

View File

@ -1,29 +0,0 @@
/*
* Copyright (C) 2011-2014 lishid. All rights reserved.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, version 3.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.lishid.orebfuscator.internal;
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.File;
public interface IChunkCache {
public void clearCache();
public DataInputStream getInputStream(File folder, int x, int z);
public DataOutputStream getOutputStream(File folder, int x, int z);
}

View File

@ -1,21 +0,0 @@
/*
* Copyright (C) 2011-2014 lishid. All rights reserved.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, version 3.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.lishid.orebfuscator.internal;
public interface IChunkQueue {
public void FinishedProcessing(IPacket56 packet);
}

View File

@ -1,21 +0,0 @@
/*
* Copyright (C) 2011-2014 lishid. All rights reserved.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, version 3.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.lishid.orebfuscator.internal;
public interface IMinecraftWorldServer {
public void Notify(Object server, int x, int y, int z);
}

View File

@ -1,48 +0,0 @@
/*
* Copyright (C) 2011-2014 lishid. All rights reserved.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, version 3.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.lishid.orebfuscator.internal;
import java.io.DataInput;
import java.io.DataOutput;
public interface INBT {
public void reset();
public void setInt(String tag, int value);
public void setLong(String tag, long value);
public void setBoolean(String tag, boolean value);
public void setByteArray(String tag, byte[] value);
public void setIntArray(String tag, int[] value);
public int getInt(String tag);
public long getLong(String tag);
public boolean getBoolean(String tag);
public byte[] getByteArray(String tag);
public int[] getIntArray(String tag);
public void Read(DataInput stream);
public void Write(DataOutput stream);
}

View File

@ -1,46 +0,0 @@
/*
* Copyright (C) 2011-2014 lishid. All rights reserved.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, version 3.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.lishid.orebfuscator.internal;
import java.util.zip.Deflater;
public interface IPacket56 {
public void setPacket(Object packet);
public int getPacketChunkNumber();
public int[] getX();
public int[] getZ();
public int[] getChunkMask();
public int[] getExtraMask();
public Object getFieldData(String field);
public void setFieldData(String field, Object data);
public String getInflatedBuffers();
public String getBuildBuffer();
public String getOutputBuffer();
public void compress(Deflater deflater);
}

View File

@ -1,25 +0,0 @@
/*
* Copyright (C) 2011-2014 lishid. All rights reserved.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, version 3.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.lishid.orebfuscator.internal;
import org.bukkit.entity.Player;
public interface IPlayerHook {
public void HookNM(Player p);
public void HookChunkQueue(Player p);
}

View File

@ -1,90 +0,0 @@
/*
* Copyright (C) 2011-2014 lishid. All rights reserved.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, version 3.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.lishid.orebfuscator.internal;
import org.bukkit.Server;
import com.lishid.orebfuscator.Orebfuscator;
public class InternalAccessor {
public static InternalAccessor Instance;
private String version;
/*
* Returns false if version not supported
*/
public static boolean Initialize(Server server) {
Instance = new InternalAccessor();
String packageName = server.getClass().getPackage().getName();
Instance.version = packageName.substring(packageName.lastIndexOf('.') + 1);
try {
Class.forName("com.lishid.orebfuscator.internal." + Instance.version + ".PlayerHook");
return true;
}
catch (Exception e) {
return false;
}
}
public void PrintError() {
Orebfuscator.log("Orebfuscator encountered an error with the CraftBukkit version \"" + Instance.version + "\". Please look for an updated version of Orebfuscator.");
}
public INBT newNBT() {
return (INBT) createObject(INBT.class, "NBT");
}
public IChunkCache newChunkCache() {
return (IChunkCache) createObject(IChunkCache.class, "ChunkCache");
}
public IPacket51 newPacket51() {
return (IPacket51) createObject(IPacket51.class, "Packet51");
}
public IPacket56 newPacket56() {
return (IPacket56) createObject(IPacket56.class, "Packet56");
}
public IPlayerHook newPlayerHook() {
return (IPlayerHook) createObject(IPlayerHook.class, "PlayerHook");
}
public IBlockAccess newBlockAccess() {
return (IBlockAccess) createObject(IBlockAccess.class, "BlockAccess");
}
public IMinecraftWorldServer newMinecraftWorldServer() {
return (IMinecraftWorldServer) createObject(IMinecraftWorldServer.class, "MinecraftWorldServer");
}
private Object createObject(Class<? extends Object> assignableClass, String className) {
try {
Class<?> internalClass = Class.forName("com.lishid.orebfuscator.internal." + version + "." + className);
if (assignableClass.isAssignableFrom(internalClass)) {
return internalClass.getConstructor().newInstance();
}
}
catch (Exception e) {
PrintError();
Orebfuscator.log(e);
}
return null;
}
}

View File

@ -1,46 +0,0 @@
/*
* Copyright (C) 2011-2014 lishid. All rights reserved.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, version 3.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.lishid.orebfuscator.internal.craftbukkit;
import com.lishid.orebfuscator.internal.IBlockAccess;
import org.bukkit.entity.Player;
//Volatile
import net.minecraft.server.*;
import org.bukkit.craftbukkit.entity.*;
import org.bukkit.craftbukkit.*;
public class BlockAccess implements IBlockAccess {
@Override
public boolean isBlockTransparent(int id) {
return !Block.i(id);
}
@Override
public void updateBlockTileEntity(org.bukkit.block.Block block, Player player) {
CraftWorld world = (CraftWorld) block.getWorld();
TileEntity tileEntity = world.getTileEntityAt(block.getX(), block.getY(), block.getZ());
if (tileEntity == null) {
return;
}
Packet packet = tileEntity.getUpdatePacket();
if (packet != null) {
CraftPlayer player2 = (CraftPlayer) player;
player2.getHandle().netServerHandler.sendPacket(packet);
}
}
}

View File

@ -1,303 +0,0 @@
/*
* Copyright (C) 2011-2014 lishid. All rights reserved.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, version 3.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.lishid.orebfuscator.internal.craftbukkit;
import java.util.Collections;
import java.util.LinkedList;
import java.util.List;
import java.util.ListIterator;
import java.util.concurrent.atomic.AtomicBoolean;
import com.lishid.orebfuscator.hook.ChunkProcessingThread;
import com.lishid.orebfuscator.internal.IChunkQueue;
import com.lishid.orebfuscator.internal.IPacket56;
import com.lishid.orebfuscator.internal.InternalAccessor;
import com.lishid.orebfuscator.utils.ReflectionHelper;
//Volatile
import net.minecraft.server.*;
import org.bukkit.craftbukkit.entity.*;
public class ChunkQueue extends LinkedList<ChunkCoordIntPair> implements IChunkQueue {
private static final long serialVersionUID = -1928681564741152336L;
List<ChunkCoordIntPair> internalQueue = Collections.synchronizedList(new LinkedList<ChunkCoordIntPair>());
List<ChunkCoordIntPair> outputQueue = Collections.synchronizedList(new LinkedList<ChunkCoordIntPair>());
List<ChunkCoordIntPair> processingQueue = Collections.synchronizedList(new LinkedList<ChunkCoordIntPair>());
Packet56MapChunkBulk lastPacket;
CraftPlayer player;
Thread thread;
AtomicBoolean kill = new AtomicBoolean(false);
@SuppressWarnings({ "unchecked", "rawtypes" })
public ChunkQueue(CraftPlayer player, List previousEntries) {
this.player = player;
internalQueue.addAll(previousEntries);
}
@Override
public boolean remove(Object arg0) {
return internalQueue.remove(arg0) || processingQueue.remove(arg0) || outputQueue.remove(arg0);
}
// Called when the queue should be cleared
@Override
public void clear() {
// Clear the internal queue
internalQueue.clear();
super.clear();
}
// Called when new chunks are queued
@Override
public boolean add(ChunkCoordIntPair e) {
boolean result = internalQueue.add(e);
// Move everything into the internal queue
return result;
// return super.add(e);
}
// Called when the list should be sorted
@Override
public Object[] toArray() {
sort();
// Return the old array to be sorted
return internalQueue.toArray();
}
// This checks for chunks in the queue
@Override
public boolean contains(Object o) {
// Checks whether the coords are actually in
return internalQueue.contains(o) || processingQueue.contains(o);
}
@Override
public boolean isEmpty() {
// If the player is gone, then don't waste time
if (player.getHandle().netServerHandler.disconnected) {
// Cleanup all queues
internalQueue.clear();
processingQueue.clear();
outputQueue.clear();
lastPacket = null;
}
else {
// Process outputs and inputs
processOutput();
processInput();
}
return true;
}
public void sort() {
// Sort the internal array according to CB - See PlayerChunkMap.movePlayer(EntityPlayer entityplayer)
synchronized (internalQueue) {
java.util.Collections.sort(internalQueue, new ChunkCoordComparator(player.getHandle()));
}
}
@Override
public void FinishedProcessing(IPacket56 packet) {
if (lastPacket != null) {
player.getHandle().netServerHandler.sendPacket(lastPacket);
// Remove reference to the packet so it can be freed when possible
lastPacket = null;
}
outputQueue.addAll(processingQueue);
processingQueue.clear();
}
private void processOutput() {
// Chunk packet finished processing, output relevant packets
while (!outputQueue.isEmpty()) {
// Get the chunk coordinate
ChunkCoordIntPair chunk = outputQueue.remove(0);
// Check if the chunk is ready
if (chunk != null && ((WorldServer) player.getHandle().world).isLoaded(chunk.x << 4, 0, chunk.z << 4)) {
// Get all the TileEntities in the chunk
@SuppressWarnings("rawtypes")
List tileEntities = ((WorldServer) player.getHandle().world).getTileEntities(chunk.x * 16, 0, chunk.z * 16, chunk.x * 16 + 16, 256, chunk.z * 16 + 16);
for (Object o : tileEntities) {
// Send out packet for the tile entity data
this.updateTileEntity((TileEntity) o);
}
// Start tracking entities in the chunk
player.getHandle().p().getTracker().a(player.getHandle(), player.getHandle().p().getChunkAt(chunk.x, chunk.z));
}
}
}
private void processInput() {
// Queue next chunk packet out
if (processingQueue.isEmpty() && !internalQueue.isEmpty()) {
// Check if player's output queue has a lot of stuff waiting to be sent. If so, don't process and wait.
NetworkManager networkManager = (NetworkManager) player.getHandle().netServerHandler.networkManager;
// Network queue limit is 2097152 bytes
// Each chunk packet with 5 chunks is about 10000 - 25000 bytes
// We'll allow the size of 3 packets to be queued = 75000 bytes
// Try-catch so as to not disrupt chunk sending if something fails
try {
if (((int) (Integer) ReflectionHelper.getPrivateField(NetworkManager.class, networkManager, "y")) > 75000) {
return;
}
}
catch (Exception e) {
// e.printStackTrace();
}
// A list to queue chunks
List<Chunk> chunks = new LinkedList<Chunk>();
// Queue up to 5 chunks
while (!internalQueue.isEmpty() && chunks.size() < 5) {
// Dequeue a chunk from input
ChunkCoordIntPair chunkcoordintpair = internalQueue.remove(0);
// If the chunk is loaded and not null
if (chunkcoordintpair != null && player.getHandle().world.isLoaded(chunkcoordintpair.x << 4, 0, chunkcoordintpair.z << 4)) {
// Queue the chunk for processing
processingQueue.add(chunkcoordintpair);
// Add the chunk to the list to create a packet
chunks.add(player.getHandle().world.getChunkAt(chunkcoordintpair.x, chunkcoordintpair.z));
}
}
// If there are chunks to process
if (!chunks.isEmpty()) {
// Create a packet wrapper
IPacket56 packet = InternalAccessor.Instance.newPacket56();
// Create the actual packet
lastPacket = new Packet56MapChunkBulk(chunks);
// Put into wrapper
packet.setPacket(lastPacket);
// Send to Processing Thread
ChunkProcessingThread.Queue(packet, player, this);
}
}
}
private void updateTileEntity(TileEntity tileentity) {
if (tileentity != null) {
Packet packet = tileentity.getUpdatePacket();
if (packet != null) {
player.getHandle().netServerHandler.sendPacket(packet);
}
}
}
@Override
public ListIterator<ChunkCoordIntPair> listIterator() {
return new FakeIterator();
}
private class FakeIterator implements ListIterator<ChunkCoordIntPair> {
@Override
public boolean hasNext() {
return false;
}
@Override
public ChunkCoordIntPair next() {
return null;
}
@Override
public boolean hasPrevious() {
return false;
}
@Override
public ChunkCoordIntPair previous() {
return null;
}
@Override
public int nextIndex() {
return 0;
}
@Override
public int previousIndex() {
return 0;
}
@Override
public void remove() {}
@Override
public void set(ChunkCoordIntPair e) {}
@Override
public void add(ChunkCoordIntPair e) {}
}
private static class ChunkCoordComparator implements java.util.Comparator<ChunkCoordIntPair> {
private int x;
private int z;
public ChunkCoordComparator(EntityPlayer entityplayer) {
x = (int) entityplayer.locX >> 4;
z = (int) entityplayer.locZ >> 4;
}
public int compare(ChunkCoordIntPair a, ChunkCoordIntPair b) {
if (a.equals(b)) {
return 0;
}
// Subtract current position to set center point
int ax = a.x - this.x;
int az = a.z - this.z;
int bx = b.x - this.x;
int bz = b.z - this.z;
int result = ((ax - bx) * (ax + bx)) + ((az - bz) * (az + bz));
if (result != 0) {
return result;
}
if (ax < 0) {
if (bx < 0) {
return bz - az;
}
else {
return -1;
}
}
else {
if (bx < 0) {
return 1;
}
else {
return az - bz;
}
}
}
}
}

View File

@ -1,36 +0,0 @@
/*
* Copyright (C) 2011-2014 lishid. All rights reserved.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, version 3.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.lishid.orebfuscator.internal.craftbukkit;
import com.lishid.orebfuscator.internal.IMinecraftWorldServer;
import com.lishid.orebfuscator.internal.InternalAccessor;
//Volatile
import net.minecraft.server.*;
import org.bukkit.craftbukkit.*;
public class MinecraftWorldServer implements IMinecraftWorldServer {
public void Notify(Object world, int x, int y, int z) {
if (world instanceof CraftWorld) {
WorldServer server = (WorldServer) ((CraftWorld) world).getHandle();
server.notify(x, y, z);
}
else {
InternalAccessor.Instance.PrintError();
}
}
}

View File

@ -1,48 +0,0 @@
/*
* Copyright (C) 2011-2014 lishid. All rights reserved.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, version 3.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.lishid.orebfuscator.internal.craftbukkit;
import java.util.ArrayList;
import org.bukkit.entity.Player;
import com.lishid.orebfuscator.internal.IPacket51;
import com.lishid.orebfuscator.internal.InternalAccessor;
import com.lishid.orebfuscator.obfuscation.Calculations;
//Volatile
import net.minecraft.server.*;
public class NetworkQueue extends ArrayList<Packet> {
private static final long serialVersionUID = 4252847662044263527L;
private Player player;
public NetworkQueue(Player player) {
this.player = player;
}
@Override
public boolean add(Packet packet) {
if (packet.k() == 51) {
IPacket51 packet51 = InternalAccessor.Instance.newPacket51();
packet51.setPacket(packet);
Calculations.Obfuscate(packet51, this.player);
}
return super.add(packet);
}
}

View File

@ -1,18 +0,0 @@
package com.lishid.orebfuscator.internal.craftbukkit;
import com.lishid.orebfuscator.hithack.BlockHitManager;
import net.minecraft.server.*;
public class Packet14Orebfuscator extends Packet14BlockDig {
@Override
public void handle(NetHandler handler) {
if (this.e == 1 && handler instanceof NetServerHandler) {
boolean canHit = BlockHitManager.hitBlock(((NetServerHandler) handler).getPlayer(), null);
if (!canHit) {
return;
}
}
super.handle(handler);
}
}

View File

@ -1,82 +0,0 @@
/*
* Copyright (C) 2011-2014 lishid. All rights reserved.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, version 3.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.lishid.orebfuscator.internal.craftbukkit;
import java.util.zip.Deflater;
import com.lishid.orebfuscator.internal.IPacket51;
import com.lishid.orebfuscator.internal.InternalAccessor;
import com.lishid.orebfuscator.utils.ReflectionHelper;
//Volatile
import net.minecraft.server.*;
public class Packet51 implements IPacket51 {
private static Class<? extends Object> packetClass = Packet51MapChunk.class;
Packet51MapChunk packet;
@Override
public void setPacket(Object packet) {
if (packet instanceof Packet51MapChunk) {
this.packet = (Packet51MapChunk) packet;
}
else {
InternalAccessor.Instance.PrintError();
}
}
@Override
public int getX() {
return packet.a;
}
@Override
public int getZ() {
return packet.b;
}
@Override
public int getChunkMask() {
return packet.c;
}
@Override
public int getExtraMask() {
return packet.d;
}
@Override
public byte[] getBuffer() {
return (byte[]) ReflectionHelper.getPrivateField(packetClass, packet, "inflatedBuffer");
}
private byte[] getOutputBuffer() {
return (byte[]) ReflectionHelper.getPrivateField(packetClass, packet, "buffer");
}
@Override
public void compress(Deflater deflater) {
byte[] chunkInflatedBuffer = getBuffer();
byte[] chunkBuffer = getOutputBuffer();
deflater.reset();
deflater.setInput(chunkInflatedBuffer, 0, chunkInflatedBuffer.length);
deflater.finish();
ReflectionHelper.setPrivateField(packetClass, packet, "size", deflater.deflate(chunkBuffer));
}
}

View File

@ -1,115 +0,0 @@
/*
* Copyright (C) 2011-2014 lishid. All rights reserved.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, version 3.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.lishid.orebfuscator.internal.craftbukkit;
import java.util.zip.Deflater;
import com.lishid.orebfuscator.commands.OrebfuscatorCommandExecutor;
import com.lishid.orebfuscator.internal.IPacket56;
import com.lishid.orebfuscator.internal.InternalAccessor;
import com.lishid.orebfuscator.utils.ReflectionHelper;
//Volatile
import net.minecraft.server.*;
public class Packet56 implements IPacket56 {
Packet56MapChunkBulk packet;
@Override
public void setPacket(Object packet) {
if (packet instanceof Packet56MapChunkBulk) {
this.packet = (Packet56MapChunkBulk) packet;
}
else {
InternalAccessor.Instance.PrintError();
}
}
@Override
public int getPacketChunkNumber() {
return packet.d();
}
@Override
public int[] getX() {
return (int[]) ReflectionHelper.getPrivateField(packet, "c");
}
@Override
public int[] getZ() {
return (int[]) ReflectionHelper.getPrivateField(packet, "d");
}
@Override
public int[] getChunkMask() {
return packet.a;
}
@Override
public int[] getExtraMask() {
return packet.b;
}
@Override
public Object getFieldData(String field) {
return ReflectionHelper.getPrivateField(Packet56MapChunkBulk.class, packet, field);
}
@Override
public void setFieldData(String field, Object data) {
ReflectionHelper.setPrivateField(Packet56MapChunkBulk.class, packet, field, data);
}
public String getInflatedBuffers() {
return "inflatedBuffers";
}
public String getBuildBuffer() {
return "buildBuffer";
}
public String getOutputBuffer() {
return "buffer";
}
@Override
public void compress(Deflater deflater) {
if (getFieldData(getOutputBuffer()) != null) {
return;
}
byte[] buildBuffer = (byte[]) getFieldData(getBuildBuffer());
deflater.reset();
deflater.setInput(buildBuffer);
deflater.finish();
byte[] buffer = new byte[buildBuffer.length + 100];
ReflectionHelper.setPrivateField(packet, "buffer", buffer);
int size = deflater.deflate(buffer);
ReflectionHelper.setPrivateField(packet, "size", size);
// Free memory
ReflectionHelper.setPrivateField(packet, "buildBuffer", null);
ReflectionHelper.setPrivateField(packet, "inflatedBuffers", null);
if (OrebfuscatorCommandExecutor.DebugMode) {
System.out.println("Packet size: " + size);
}
}
}

View File

@ -1,96 +0,0 @@
/*
* Copyright (C) 2011-2014 lishid. All rights reserved.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, version 3.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.lishid.orebfuscator.internal.craftbukkit;
import java.lang.reflect.Field;
import java.util.Collections;
import java.util.Map;
import java.util.List;
import com.lishid.orebfuscator.Orebfuscator;
import com.lishid.orebfuscator.internal.IPlayerHook;
import com.lishid.orebfuscator.utils.ReflectionHelper;
import org.bukkit.entity.Player;
//Volatile
import net.minecraft.server.*;
import org.bukkit.craftbukkit.entity.*;
public class PlayerHook implements IPlayerHook {
@SuppressWarnings("unchecked")
public void HookNM(Player p) {
CraftPlayer player = (CraftPlayer) p;
// Update NetworkManager's lists
NetworkManager networkManager = (NetworkManager) player.getHandle().netServerHandler.networkManager;
Field[] networkFields = networkManager.getClass().getDeclaredFields();
for (Field field : networkFields) {
try {
if (List.class.isAssignableFrom(field.getType())) {
List<Packet> list = new NetworkQueue(p);
field.setAccessible(true);
List<Packet> oldList = (List<Packet>) field.get(networkManager);
// Move packets to new list
synchronized (ReflectionHelper.getPrivateField(networkManager, "h")) {
list.addAll(oldList);
oldList.clear();
}
// Replace with new list
field.set(networkManager, Collections.synchronizedList(list));
}
}
catch (Exception e) {
Orebfuscator.log(e);
}
}
hookPacket();
}
static boolean hookPacket = false;
@SuppressWarnings("unchecked")
private void hookPacket() {
if (hookPacket)
return;
hookPacket = true;
Packet.l.a(14, Packet14Orebfuscator.class);
// Use reflection to add into a and c
Field[] packetFields = Packet.class.getDeclaredFields();
for (Field field : packetFields) {
try {
if (Map.class.isAssignableFrom(field.getType())) {
field.setAccessible(true);
@SuppressWarnings({ "rawtypes" })
Map packets = (Map) field.get(null);
packets.put(Packet14Orebfuscator.class, 14);
}
}
catch (Exception e) {
Orebfuscator.log(e);
}
}
}
public void HookChunkQueue(Player p) {
CraftPlayer player = (CraftPlayer) p;
ReflectionHelper.setPrivateFinal(player.getHandle(), "chunkCoordIntPairQueue", new ChunkQueue(player, player.getHandle().chunkCoordIntPairQueue));
}
}

View File

@ -1,46 +0,0 @@
/*
* Copyright (C) 2011-2014 lishid. All rights reserved.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, version 3.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.lishid.orebfuscator.internal.v1_4_5;
import com.lishid.orebfuscator.internal.IBlockAccess;
import org.bukkit.entity.Player;
//Volatile
import net.minecraft.server.v1_4_5.*;
import org.bukkit.craftbukkit.v1_4_5.entity.*;
import org.bukkit.craftbukkit.v1_4_5.*;
public class BlockAccess implements IBlockAccess {
@Override
public boolean isBlockTransparent(int id) {
return !Block.i(id);
}
@Override
public void updateBlockTileEntity(org.bukkit.block.Block block, Player player) {
CraftWorld world = (CraftWorld) block.getWorld();
TileEntity tileEntity = world.getTileEntityAt(block.getX(), block.getY(), block.getZ());
if (tileEntity == null) {
return;
}
Packet packet = tileEntity.getUpdatePacket();
if (packet != null) {
CraftPlayer player2 = (CraftPlayer) player;
player2.getHandle().netServerHandler.sendPacket(packet);
}
}
}

View File

@ -1,92 +0,0 @@
/*
* Copyright (C) 2011-2014 lishid. All rights reserved.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, version 3.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.lishid.orebfuscator.internal.v1_4_5;
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.File;
import java.util.HashMap;
import com.lishid.orebfuscator.Orebfuscator;
import com.lishid.orebfuscator.OrebfuscatorConfig;
import com.lishid.orebfuscator.internal.IChunkCache;
//Volatile
import net.minecraft.server.v1_4_5.*;
public class ChunkCache implements IChunkCache {
private static final HashMap<File, RegionFile> cachedRegionFiles = new HashMap<File, RegionFile>();
private synchronized RegionFile getRegionFile(File folder, int x, int z) {
File path = new File(folder, "region");
File file = new File(path, "r." + (x >> 5) + "." + (z >> 5) + ".mcr");
try {
RegionFile regionFile = cachedRegionFiles.get(file);
if (regionFile != null) {
return regionFile;
}
if (!path.exists()) {
path.mkdirs();
}
if (cachedRegionFiles.size() >= OrebfuscatorConfig.MaxLoadedCacheFiles) {
clearCache();
}
regionFile = new RegionFile(file);
cachedRegionFiles.put(file, regionFile);
return regionFile;
}
catch (Exception e) {
try {
file.delete();
}
catch (Exception e2) {
Orebfuscator.log(e);
}
}
return null;
}
@Override
public DataInputStream getInputStream(File folder, int x, int z) {
RegionFile regionFile = getRegionFile(folder, x, z);
return regionFile.a(x & 0x1F, z & 0x1F);
}
@Override
public DataOutputStream getOutputStream(File folder, int x, int z) {
RegionFile regionFile = getRegionFile(folder, x, z);
return regionFile.b(x & 0x1F, z & 0x1F);
}
@Override
public synchronized void clearCache() {
for (RegionFile regionFile : cachedRegionFiles.values()) {
try {
if (regionFile != null)
regionFile.c();
}
catch (Exception e) {
e.printStackTrace();
}
}
cachedRegionFiles.clear();
}
}

View File

@ -1,303 +0,0 @@
/*
* Copyright (C) 2011-2014 lishid. All rights reserved.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, version 3.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.lishid.orebfuscator.internal.v1_4_5;
import java.util.Collections;
import java.util.LinkedList;
import java.util.List;
import java.util.ListIterator;
import java.util.concurrent.atomic.AtomicBoolean;
import com.lishid.orebfuscator.hook.ChunkProcessingThread;
import com.lishid.orebfuscator.internal.IChunkQueue;
import com.lishid.orebfuscator.internal.IPacket56;
import com.lishid.orebfuscator.internal.InternalAccessor;
import com.lishid.orebfuscator.utils.ReflectionHelper;
//Volatile
import net.minecraft.server.v1_4_5.*;
import org.bukkit.craftbukkit.v1_4_5.entity.*;
public class ChunkQueue extends LinkedList<ChunkCoordIntPair> implements IChunkQueue {
private static final long serialVersionUID = -1928681564741152336L;
List<ChunkCoordIntPair> internalQueue = Collections.synchronizedList(new LinkedList<ChunkCoordIntPair>());
List<ChunkCoordIntPair> outputQueue = Collections.synchronizedList(new LinkedList<ChunkCoordIntPair>());
List<ChunkCoordIntPair> processingQueue = Collections.synchronizedList(new LinkedList<ChunkCoordIntPair>());
Packet56MapChunkBulk lastPacket;
CraftPlayer player;
Thread thread;
AtomicBoolean kill = new AtomicBoolean(false);
@SuppressWarnings({ "unchecked", "rawtypes" })
public ChunkQueue(CraftPlayer player, List previousEntries) {
this.player = player;
internalQueue.addAll(previousEntries);
}
@Override
public boolean remove(Object arg0) {
return internalQueue.remove(arg0) || processingQueue.remove(arg0) || outputQueue.remove(arg0);
}
// Called when the queue should be cleared
@Override
public void clear() {
// Clear the internal queue
internalQueue.clear();
super.clear();
}
// Called when new chunks are queued
@Override
public boolean add(ChunkCoordIntPair e) {
boolean result = internalQueue.add(e);
// Move everything into the internal queue
return result;
// return super.add(e);
}
// Called when the list should be sorted
@Override
public Object[] toArray() {
sort();
// Return the old array to be sorted
return internalQueue.toArray();
}
// This checks for chunks in the queue
@Override
public boolean contains(Object o) {
// Checks whether the coords are actually in
return internalQueue.contains(o) || processingQueue.contains(o);
}
@Override
public boolean isEmpty() {
// If the player is gone, then don't waste time
if (player.getHandle().netServerHandler.disconnected) {
// Cleanup all queues
internalQueue.clear();
processingQueue.clear();
outputQueue.clear();
lastPacket = null;
}
else {
// Process outputs and inputs
processOutput();
processInput();
}
return true;
}
public void sort() {
// Sort the internal array according to CB - See PlayerChunkMap.movePlayer(EntityPlayer entityplayer)
synchronized (internalQueue) {
java.util.Collections.sort(internalQueue, new ChunkCoordComparator(player.getHandle()));
}
}
@Override
public void FinishedProcessing(IPacket56 packet) {
if (lastPacket != null) {
player.getHandle().netServerHandler.sendPacket(lastPacket);
// Remove reference to the packet so it can be freed when possible
lastPacket = null;
}
outputQueue.addAll(processingQueue);
processingQueue.clear();
}
private void processOutput() {
// Chunk packet finished processing, output relevant packets
while (!outputQueue.isEmpty()) {
// Get the chunk coordinate
ChunkCoordIntPair chunk = outputQueue.remove(0);
// Check if the chunk is ready
if (chunk != null && ((WorldServer) player.getHandle().world).isLoaded(chunk.x << 4, 0, chunk.z << 4)) {
// Get all the TileEntities in the chunk
@SuppressWarnings("rawtypes")
List tileEntities = ((WorldServer) player.getHandle().world).getTileEntities(chunk.x * 16, 0, chunk.z * 16, chunk.x * 16 + 16, 256, chunk.z * 16 + 16);
for (Object o : tileEntities) {
// Send out packet for the tile entity data
this.updateTileEntity((TileEntity) o);
}
// Start tracking entities in the chunk
player.getHandle().p().getTracker().a(player.getHandle(), player.getHandle().p().getChunkAt(chunk.x, chunk.z));
}
}
}
private void processInput() {
// Queue next chunk packet out
if (processingQueue.isEmpty() && !internalQueue.isEmpty()) {
// Check if player's output queue has a lot of stuff waiting to be sent. If so, don't process and wait.
NetworkManager networkManager = (NetworkManager) player.getHandle().netServerHandler.networkManager;
// Network queue limit is 2097152 bytes
// Each chunk packet with 5 chunks is about 10000 - 25000 bytes
// We'll allow the size of 3 packets to be queued = 75000 bytes
// Try-catch so as to not disrupt chunk sending if something fails
try {
if (((int) (Integer) ReflectionHelper.getPrivateField(NetworkManager.class, networkManager, "y")) > 75000) {
return;
}
}
catch (Exception e) {
// e.printStackTrace();
}
// A list to queue chunks
List<Chunk> chunks = new LinkedList<Chunk>();
// Queue up to 5 chunks
while (!internalQueue.isEmpty() && chunks.size() < 5) {
// Dequeue a chunk from input
ChunkCoordIntPair chunkcoordintpair = internalQueue.remove(0);
// If the chunk is loaded and not null
if (chunkcoordintpair != null && player.getHandle().world.isLoaded(chunkcoordintpair.x << 4, 0, chunkcoordintpair.z << 4)) {
// Queue the chunk for processing
processingQueue.add(chunkcoordintpair);
// Add the chunk to the list to create a packet
chunks.add(player.getHandle().world.getChunkAt(chunkcoordintpair.x, chunkcoordintpair.z));
}
}
// If there are chunks to process
if (!chunks.isEmpty()) {
// Create a packet wrapper
IPacket56 packet = InternalAccessor.Instance.newPacket56();
// Create the actual packet
lastPacket = new Packet56MapChunkBulk(chunks);
// Put into wrapper
packet.setPacket(lastPacket);
// Send to Processing Thread
ChunkProcessingThread.Queue(packet, player, this);
}
}
}
private void updateTileEntity(TileEntity tileentity) {
if (tileentity != null) {
Packet packet = tileentity.getUpdatePacket();
if (packet != null) {
player.getHandle().netServerHandler.sendPacket(packet);
}
}
}
@Override
public ListIterator<ChunkCoordIntPair> listIterator() {
return new FakeIterator();
}
private class FakeIterator implements ListIterator<ChunkCoordIntPair> {
@Override
public boolean hasNext() {
return false;
}
@Override
public ChunkCoordIntPair next() {
return null;
}
@Override
public boolean hasPrevious() {
return false;
}
@Override
public ChunkCoordIntPair previous() {
return null;
}
@Override
public int nextIndex() {
return 0;
}
@Override
public int previousIndex() {
return 0;
}
@Override
public void remove() {}
@Override
public void set(ChunkCoordIntPair e) {}
@Override
public void add(ChunkCoordIntPair e) {}
}
private static class ChunkCoordComparator implements java.util.Comparator<ChunkCoordIntPair> {
private int x;
private int z;
public ChunkCoordComparator(EntityPlayer entityplayer) {
x = (int) entityplayer.locX >> 4;
z = (int) entityplayer.locZ >> 4;
}
public int compare(ChunkCoordIntPair a, ChunkCoordIntPair b) {
if (a.equals(b)) {
return 0;
}
// Subtract current position to set center point
int ax = a.x - this.x;
int az = a.z - this.z;
int bx = b.x - this.x;
int bz = b.z - this.z;
int result = ((ax - bx) * (ax + bx)) + ((az - bz) * (az + bz));
if (result != 0) {
return result;
}
if (ax < 0) {
if (bx < 0) {
return bz - az;
}
else {
return -1;
}
}
else {
if (bx < 0) {
return 1;
}
else {
return az - bz;
}
}
}
}
}

View File

@ -1,36 +0,0 @@
/*
* Copyright (C) 2011-2014 lishid. All rights reserved.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, version 3.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.lishid.orebfuscator.internal.v1_4_5;
import com.lishid.orebfuscator.internal.IMinecraftWorldServer;
import com.lishid.orebfuscator.internal.InternalAccessor;
//Volatile
import net.minecraft.server.v1_4_5.*;
import org.bukkit.craftbukkit.v1_4_5.*;
public class MinecraftWorldServer implements IMinecraftWorldServer {
public void Notify(Object world, int x, int y, int z) {
if (world instanceof CraftWorld) {
WorldServer server = (WorldServer) ((CraftWorld) world).getHandle();
server.notify(x, y, z);
}
else {
InternalAccessor.Instance.PrintError();
}
}
}

View File

@ -1,95 +0,0 @@
/*
* Copyright (C) 2011-2014 lishid. All rights reserved.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, version 3.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.lishid.orebfuscator.internal.v1_4_5;
import java.io.DataInput;
import java.io.DataOutput;
import com.lishid.orebfuscator.internal.INBT;
//Volatile
import net.minecraft.server.v1_4_5.*;
public class NBT implements INBT {
NBTTagCompound nbt = new NBTTagCompound();
@Override
public void reset() {
nbt = new NBTTagCompound();
}
@Override
public void setInt(String tag, int value) {
nbt.setInt(tag, value);
}
@Override
public void setLong(String tag, long value) {
nbt.setLong(tag, value);
}
@Override
public void setBoolean(String tag, boolean value) {
nbt.setBoolean(tag, value);
}
@Override
public void setByteArray(String tag, byte[] value) {
nbt.setByteArray(tag, value);
}
@Override
public void setIntArray(String tag, int[] value) {
nbt.setIntArray(tag, value);
}
@Override
public int getInt(String tag) {
return nbt.getInt(tag);
}
@Override
public long getLong(String tag) {
return nbt.getLong(tag);
}
@Override
public boolean getBoolean(String tag) {
return nbt.getBoolean(tag);
}
@Override
public byte[] getByteArray(String tag) {
return nbt.getByteArray(tag);
}
@Override
public int[] getIntArray(String tag) {
return nbt.getIntArray(tag);
}
@Override
public void Read(DataInput stream) {
nbt = NBTCompressedStreamTools.a(stream);
}
@Override
public void Write(DataOutput stream) {
NBTCompressedStreamTools.a(nbt, stream);
}
}

View File

@ -1,48 +0,0 @@
/*
* Copyright (C) 2011-2014 lishid. All rights reserved.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, version 3.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.lishid.orebfuscator.internal.v1_4_5;
import java.util.ArrayList;
import org.bukkit.entity.Player;
import com.lishid.orebfuscator.internal.IPacket51;
import com.lishid.orebfuscator.internal.InternalAccessor;
import com.lishid.orebfuscator.obfuscation.Calculations;
//Volatile
import net.minecraft.server.v1_4_5.*;
public class NetworkQueue extends ArrayList<Packet> {
private static final long serialVersionUID = 4252847662044263527L;
private Player player;
public NetworkQueue(Player player) {
this.player = player;
}
@Override
public boolean add(Packet packet) {
if (packet.k() == 51) {
IPacket51 packet51 = InternalAccessor.Instance.newPacket51();
packet51.setPacket(packet);
Calculations.Obfuscate(packet51, this.player);
}
return super.add(packet);
}
}

View File

@ -1,18 +0,0 @@
package com.lishid.orebfuscator.internal.v1_4_5;
import com.lishid.orebfuscator.hithack.BlockHitManager;
import net.minecraft.server.v1_4_5.*;
public class Packet14Orebfuscator extends Packet14BlockDig {
@Override
public void handle(NetHandler handler) {
if (this.e == 1 && handler instanceof NetServerHandler) {
boolean canHit = BlockHitManager.hitBlock(((NetServerHandler) handler).getPlayer(), null);
if (!canHit) {
return;
}
}
super.handle(handler);
}
}

View File

@ -1,82 +0,0 @@
/*
* Copyright (C) 2011-2014 lishid. All rights reserved.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, version 3.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.lishid.orebfuscator.internal.v1_4_5;
import java.util.zip.Deflater;
import com.lishid.orebfuscator.internal.IPacket51;
import com.lishid.orebfuscator.internal.InternalAccessor;
import com.lishid.orebfuscator.utils.ReflectionHelper;
//Volatile
import net.minecraft.server.v1_4_5.*;
public class Packet51 implements IPacket51 {
private static Class<? extends Object> packetClass = Packet51MapChunk.class;
Packet51MapChunk packet;
@Override
public void setPacket(Object packet) {
if (packet instanceof Packet51MapChunk) {
this.packet = (Packet51MapChunk) packet;
}
else {
InternalAccessor.Instance.PrintError();
}
}
@Override
public int getX() {
return packet.a;
}
@Override
public int getZ() {
return packet.b;
}
@Override
public int getChunkMask() {
return packet.c;
}
@Override
public int getExtraMask() {
return packet.d;
}
@Override
public byte[] getBuffer() {
return (byte[]) ReflectionHelper.getPrivateField(packetClass, packet, "inflatedBuffer");
}
private byte[] getOutputBuffer() {
return (byte[]) ReflectionHelper.getPrivateField(packetClass, packet, "buffer");
}
@Override
public void compress(Deflater deflater) {
byte[] chunkInflatedBuffer = getBuffer();
byte[] chunkBuffer = getOutputBuffer();
deflater.reset();
deflater.setInput(chunkInflatedBuffer, 0, chunkInflatedBuffer.length);
deflater.finish();
ReflectionHelper.setPrivateField(packetClass, packet, "size", deflater.deflate(chunkBuffer));
}
}

View File

@ -1,115 +0,0 @@
/*
* Copyright (C) 2011-2014 lishid. All rights reserved.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, version 3.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.lishid.orebfuscator.internal.v1_4_5;
import java.util.zip.Deflater;
import com.lishid.orebfuscator.commands.OrebfuscatorCommandExecutor;
import com.lishid.orebfuscator.internal.IPacket56;
import com.lishid.orebfuscator.internal.InternalAccessor;
import com.lishid.orebfuscator.utils.ReflectionHelper;
//Volatile
import net.minecraft.server.v1_4_5.*;
public class Packet56 implements IPacket56 {
Packet56MapChunkBulk packet;
@Override
public void setPacket(Object packet) {
if (packet instanceof Packet56MapChunkBulk) {
this.packet = (Packet56MapChunkBulk) packet;
}
else {
InternalAccessor.Instance.PrintError();
}
}
@Override
public int getPacketChunkNumber() {
return packet.d();
}
@Override
public int[] getX() {
return (int[]) ReflectionHelper.getPrivateField(packet, "c");
}
@Override
public int[] getZ() {
return (int[]) ReflectionHelper.getPrivateField(packet, "d");
}
@Override
public int[] getChunkMask() {
return packet.a;
}
@Override
public int[] getExtraMask() {
return packet.b;
}
@Override
public Object getFieldData(String field) {
return ReflectionHelper.getPrivateField(Packet56MapChunkBulk.class, packet, field);
}
@Override
public void setFieldData(String field, Object data) {
ReflectionHelper.setPrivateField(Packet56MapChunkBulk.class, packet, field, data);
}
public String getInflatedBuffers() {
return "inflatedBuffers";
}
public String getBuildBuffer() {
return "buildBuffer";
}
public String getOutputBuffer() {
return "buffer";
}
@Override
public void compress(Deflater deflater) {
if (getFieldData(getOutputBuffer()) != null) {
return;
}
byte[] buildBuffer = (byte[]) getFieldData(getBuildBuffer());
deflater.reset();
deflater.setInput(buildBuffer);
deflater.finish();
byte[] buffer = new byte[buildBuffer.length + 100];
ReflectionHelper.setPrivateField(packet, "buffer", buffer);
int size = deflater.deflate(buffer);
ReflectionHelper.setPrivateField(packet, "size", size);
// Free memory
ReflectionHelper.setPrivateField(packet, "buildBuffer", null);
ReflectionHelper.setPrivateField(packet, "inflatedBuffers", null);
if (OrebfuscatorCommandExecutor.DebugMode) {
System.out.println("Packet size: " + size);
}
}
}

View File

@ -1,96 +0,0 @@
/*
* Copyright (C) 2011-2014 lishid. All rights reserved.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, version 3.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.lishid.orebfuscator.internal.v1_4_5;
import java.lang.reflect.Field;
import java.util.Collections;
import java.util.Map;
import java.util.List;
import com.lishid.orebfuscator.Orebfuscator;
import com.lishid.orebfuscator.internal.IPlayerHook;
import com.lishid.orebfuscator.utils.ReflectionHelper;
import org.bukkit.entity.Player;
//Volatile
import net.minecraft.server.v1_4_5.*;
import org.bukkit.craftbukkit.v1_4_5.entity.*;
public class PlayerHook implements IPlayerHook {
@SuppressWarnings("unchecked")
public void HookNM(Player p) {
CraftPlayer player = (CraftPlayer) p;
// Update NetworkManager's lists
NetworkManager networkManager = (NetworkManager) player.getHandle().netServerHandler.networkManager;
Field[] networkFields = networkManager.getClass().getDeclaredFields();
for (Field field : networkFields) {
try {
if (List.class.isAssignableFrom(field.getType())) {
List<Packet> list = new NetworkQueue(p);
field.setAccessible(true);
List<Packet> oldList = (List<Packet>) field.get(networkManager);
// Move packets to new list
synchronized (ReflectionHelper.getPrivateField(networkManager, "h")) {
list.addAll(oldList);
oldList.clear();
}
// Replace with new list
field.set(networkManager, Collections.synchronizedList(list));
}
}
catch (Exception e) {
Orebfuscator.log(e);
}
}
hookPacket();
}
static boolean hookPacket = false;
@SuppressWarnings("unchecked")
private void hookPacket() {
if (hookPacket)
return;
hookPacket = true;
Packet.l.a(14, Packet14Orebfuscator.class);
// Use reflection to add into a and c
Field[] packetFields = Packet.class.getDeclaredFields();
for (Field field : packetFields) {
try {
if (Map.class.isAssignableFrom(field.getType())) {
field.setAccessible(true);
@SuppressWarnings({ "rawtypes" })
Map packets = (Map) field.get(null);
packets.put(Packet14Orebfuscator.class, 14);
}
}
catch (Exception e) {
Orebfuscator.log(e);
}
}
}
public void HookChunkQueue(Player p) {
CraftPlayer player = (CraftPlayer) p;
ReflectionHelper.setPrivateFinal(player.getHandle(), "chunkCoordIntPairQueue", new ChunkQueue(player, player.getHandle().chunkCoordIntPairQueue));
}
}

View File

@ -1,92 +0,0 @@
/*
* Copyright (C) 2011-2014 lishid. All rights reserved.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, version 3.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.lishid.orebfuscator.internal.v1_4_6;
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.File;
import java.util.HashMap;
import com.lishid.orebfuscator.Orebfuscator;
import com.lishid.orebfuscator.OrebfuscatorConfig;
import com.lishid.orebfuscator.internal.IChunkCache;
//Volatile
import net.minecraft.server.v1_4_6.*;
public class ChunkCache implements IChunkCache {
private static final HashMap<File, RegionFile> cachedRegionFiles = new HashMap<File, RegionFile>();
private synchronized RegionFile getRegionFile(File folder, int x, int z) {
File path = new File(folder, "region");
File file = new File(path, "r." + (x >> 5) + "." + (z >> 5) + ".mcr");
try {
RegionFile regionFile = cachedRegionFiles.get(file);
if (regionFile != null) {
return regionFile;
}
if (!path.exists()) {
path.mkdirs();
}
if (cachedRegionFiles.size() >= OrebfuscatorConfig.MaxLoadedCacheFiles) {
clearCache();
}
regionFile = new RegionFile(file);
cachedRegionFiles.put(file, regionFile);
return regionFile;
}
catch (Exception e) {
try {
file.delete();
}
catch (Exception e2) {
Orebfuscator.log(e);
}
}
return null;
}
@Override
public DataInputStream getInputStream(File folder, int x, int z) {
RegionFile regionFile = getRegionFile(folder, x, z);
return regionFile.a(x & 0x1F, z & 0x1F);
}
@Override
public DataOutputStream getOutputStream(File folder, int x, int z) {
RegionFile regionFile = getRegionFile(folder, x, z);
return regionFile.b(x & 0x1F, z & 0x1F);
}
@Override
public synchronized void clearCache() {
for (RegionFile regionFile : cachedRegionFiles.values()) {
try {
if (regionFile != null)
regionFile.c();
}
catch (Exception e) {
e.printStackTrace();
}
}
cachedRegionFiles.clear();
}
}

View File

@ -1,304 +0,0 @@
/*
* Copyright (C) 2011-2014 lishid. All rights reserved.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, version 3.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.lishid.orebfuscator.internal.v1_4_6;
import java.util.Collections;
import java.util.LinkedList;
import java.util.List;
import java.util.ListIterator;
import java.util.concurrent.atomic.AtomicBoolean;
import com.lishid.orebfuscator.hook.ChunkProcessingThread;
import com.lishid.orebfuscator.internal.IChunkQueue;
import com.lishid.orebfuscator.internal.IPacket56;
import com.lishid.orebfuscator.internal.InternalAccessor;
import com.lishid.orebfuscator.utils.ReflectionHelper;
//Volatile
import net.minecraft.server.v1_4_6.*;
import org.bukkit.craftbukkit.v1_4_6.entity.*;
public class ChunkQueue extends LinkedList<ChunkCoordIntPair> implements IChunkQueue {
private static final long serialVersionUID = -1928681564741152336L;
List<ChunkCoordIntPair> internalQueue = Collections.synchronizedList(new LinkedList<ChunkCoordIntPair>());
List<ChunkCoordIntPair> outputQueue = Collections.synchronizedList(new LinkedList<ChunkCoordIntPair>());
List<ChunkCoordIntPair> processingQueue = Collections.synchronizedList(new LinkedList<ChunkCoordIntPair>());
Packet56MapChunkBulk lastPacket;
CraftPlayer player;
Thread thread;
AtomicBoolean kill = new AtomicBoolean(false);
@SuppressWarnings({ "unchecked", "rawtypes" })
public ChunkQueue(CraftPlayer player, List previousEntries) {
this.player = player;
internalQueue.addAll(previousEntries);
}
@Override
public boolean remove(Object arg0) {
return internalQueue.remove(arg0) || processingQueue.remove(arg0) || outputQueue.remove(arg0);
}
// Called when the queue should be cleared
@Override
public void clear() {
// Clear the internal queue
internalQueue.clear();
super.clear();
}
// Called when new chunks are queued
@Override
public boolean add(ChunkCoordIntPair e) {
boolean result = internalQueue.add(e);
// Move everything into the internal queue
return result;
// return super.add(e);
}
// Called when the list should be sorted
@Override
public Object[] toArray() {
sort();
// Return the old array to be sorted
return internalQueue.toArray();
}
// This checks for chunks in the queue
@Override
public boolean contains(Object o) {
// Checks whether the coords are actually in
return internalQueue.contains(o) || processingQueue.contains(o);
}
@Override
public boolean isEmpty() {
// If the player is gone, then don't waste time
if (player.getHandle().playerConnection.disconnected) {
// Cleanup all queues
internalQueue.clear();
processingQueue.clear();
outputQueue.clear();
lastPacket = null;
}
else {
// Process outputs and inputs
processOutput();
processInput();
}
return true;
}
public void sort() {
// Sort the internal array according to CB - See PlayerChunkMap.movePlayer(EntityPlayer entityplayer)
synchronized (internalQueue) {
java.util.Collections.sort(internalQueue, new ChunkCoordComparator(player.getHandle()));
}
}
@Override
public void FinishedProcessing(IPacket56 packet) {
if (lastPacket != null) {
player.getHandle().playerConnection.sendPacket(lastPacket);
// Remove reference to the packet so it can be freed when possible
lastPacket = null;
}
outputQueue.addAll(processingQueue);
processingQueue.clear();
}
private void processOutput() {
// Chunk packet finished processing, output relevant packets
while (!outputQueue.isEmpty()) {
// Get the chunk coordinate
ChunkCoordIntPair chunk = outputQueue.remove(0);
// Check if the chunk is ready
if (chunk != null && ((WorldServer) player.getHandle().world).isLoaded(chunk.x << 4, 0, chunk.z << 4)) {
// Get all the TileEntities in the chunk
@SuppressWarnings("rawtypes")
List tileEntities = ((WorldServer) player.getHandle().world).getTileEntities(chunk.x * 16, 0, chunk.z * 16, chunk.x * 16 + 16, 256, chunk.z * 16 + 16);
for (Object o : tileEntities) {
// Send out packet for the tile entity data
this.updateTileEntity((TileEntity) o);
}
// Start tracking entities in the chunk
player.getHandle().p().getTracker().a(player.getHandle(), player.getHandle().p().getChunkAt(chunk.x, chunk.z));
}
}
}
private void processInput() {
// Queue next chunk packet out
if (processingQueue.isEmpty() && !internalQueue.isEmpty()) {
// Check if player's output queue has a lot of stuff waiting to be sent. If so, don't process and wait.
// Network queue limit is 2097152 bytes
// Each chunk packet with 5 chunks is about 10000 - 25000 bytes
// We'll allow the size of 3 packets to be queued = 75000 bytes
// Try-catch so as to not disrupt chunk sending if something fails
try {
NetworkManager networkManager = (NetworkManager) player.getHandle().playerConnection.networkManager;
if (((int) (Integer) ReflectionHelper.getPrivateField(NetworkManager.class, networkManager, "y")) > 75000) {
return;
}
}
catch (Exception e) {
// e.printStackTrace();
}
// A list to queue chunks
List<Chunk> chunks = new LinkedList<Chunk>();
// Queue up to 5 chunks
while (!internalQueue.isEmpty() && chunks.size() < 5) {
// Dequeue a chunk from input
ChunkCoordIntPair chunkcoordintpair = internalQueue.remove(0);
// If the chunk is loaded and not null
if (chunkcoordintpair != null && player.getHandle().world.isLoaded(chunkcoordintpair.x << 4, 0, chunkcoordintpair.z << 4)) {
// Queue the chunk for processing
processingQueue.add(chunkcoordintpair);
// Add the chunk to the list to create a packet
chunks.add(player.getHandle().world.getChunkAt(chunkcoordintpair.x, chunkcoordintpair.z));
}
}
// If there are chunks to process
if (!chunks.isEmpty()) {
// Create a packet wrapper
IPacket56 packet = InternalAccessor.Instance.newPacket56();
// Create the actual packet
lastPacket = new Packet56MapChunkBulk(chunks);
// Put into wrapper
packet.setPacket(lastPacket);
// Send to Processing Thread
ChunkProcessingThread.Queue(packet, player, this);
}
}
}
private void updateTileEntity(TileEntity tileentity) {
if (tileentity != null) {
Packet packet = tileentity.getUpdatePacket();
if (packet != null) {
player.getHandle().playerConnection.sendPacket(packet);
}
}
}
@Override
public ListIterator<ChunkCoordIntPair> listIterator() {
return new FakeIterator();
}
private class FakeIterator implements ListIterator<ChunkCoordIntPair> {
@Override
public boolean hasNext() {
return false;
}
@Override
public ChunkCoordIntPair next() {
return null;
}
@Override
public boolean hasPrevious() {
return false;
}
@Override
public ChunkCoordIntPair previous() {
return null;
}
@Override
public int nextIndex() {
return 0;
}
@Override
public int previousIndex() {
return 0;
}
@Override
public void remove() {}
@Override
public void set(ChunkCoordIntPair e) {}
@Override
public void add(ChunkCoordIntPair e) {}
}
private static class ChunkCoordComparator implements java.util.Comparator<ChunkCoordIntPair> {
private int x;
private int z;
public ChunkCoordComparator(EntityPlayer entityplayer) {
x = (int) entityplayer.locX >> 4;
z = (int) entityplayer.locZ >> 4;
}
public int compare(ChunkCoordIntPair a, ChunkCoordIntPair b) {
if (a.equals(b)) {
return 0;
}
// Subtract current position to set center point
int ax = a.x - this.x;
int az = a.z - this.z;
int bx = b.x - this.x;
int bz = b.z - this.z;
int result = ((ax - bx) * (ax + bx)) + ((az - bz) * (az + bz));
if (result != 0) {
return result;
}
if (ax < 0) {
if (bx < 0) {
return bz - az;
}
else {
return -1;
}
}
else {
if (bx < 0) {
return 1;
}
else {
return az - bz;
}
}
}
}
}

View File

@ -1,36 +0,0 @@
/*
* Copyright (C) 2011-2014 lishid. All rights reserved.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, version 3.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.lishid.orebfuscator.internal.v1_4_6;
import com.lishid.orebfuscator.internal.IMinecraftWorldServer;
import com.lishid.orebfuscator.internal.InternalAccessor;
//Volatile
import net.minecraft.server.v1_4_6.*;
import org.bukkit.craftbukkit.v1_4_6.*;
public class MinecraftWorldServer implements IMinecraftWorldServer {
public void Notify(Object world, int x, int y, int z) {
if (world instanceof CraftWorld) {
WorldServer server = (WorldServer) ((CraftWorld) world).getHandle();
server.notify(x, y, z);
}
else {
InternalAccessor.Instance.PrintError();
}
}
}

View File

@ -1,95 +0,0 @@
/*
* Copyright (C) 2011-2014 lishid. All rights reserved.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, version 3.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.lishid.orebfuscator.internal.v1_4_6;
import java.io.DataInput;
import java.io.DataOutput;
import com.lishid.orebfuscator.internal.INBT;
//Volatile
import net.minecraft.server.v1_4_6.*;
public class NBT implements INBT {
NBTTagCompound nbt = new NBTTagCompound();
@Override
public void reset() {
nbt = new NBTTagCompound();
}
@Override
public void setInt(String tag, int value) {
nbt.setInt(tag, value);
}
@Override
public void setLong(String tag, long value) {
nbt.setLong(tag, value);
}
@Override
public void setBoolean(String tag, boolean value) {
nbt.setBoolean(tag, value);
}
@Override
public void setByteArray(String tag, byte[] value) {
nbt.setByteArray(tag, value);
}
@Override
public void setIntArray(String tag, int[] value) {
nbt.setIntArray(tag, value);
}
@Override
public int getInt(String tag) {
return nbt.getInt(tag);
}
@Override
public long getLong(String tag) {
return nbt.getLong(tag);
}
@Override
public boolean getBoolean(String tag) {
return nbt.getBoolean(tag);
}
@Override
public byte[] getByteArray(String tag) {
return nbt.getByteArray(tag);
}
@Override
public int[] getIntArray(String tag) {
return nbt.getIntArray(tag);
}
@Override
public void Read(DataInput stream) {
nbt = NBTCompressedStreamTools.a(stream);
}
@Override
public void Write(DataOutput stream) {
NBTCompressedStreamTools.a(nbt, stream);
}
}

View File

@ -1,48 +0,0 @@
/*
* Copyright (C) 2011-2014 lishid. All rights reserved.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, version 3.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.lishid.orebfuscator.internal.v1_4_6;
import java.util.ArrayList;
import org.bukkit.entity.Player;
import com.lishid.orebfuscator.internal.IPacket51;
import com.lishid.orebfuscator.internal.InternalAccessor;
import com.lishid.orebfuscator.obfuscation.Calculations;
//Volatile
import net.minecraft.server.v1_4_6.*;
public class NetworkQueue extends ArrayList<Packet> {
private static final long serialVersionUID = 4252847662044263527L;
private Player player;
public NetworkQueue(Player player) {
this.player = player;
}
@Override
public boolean add(Packet packet) {
if (packet.k() == 51) {
IPacket51 packet51 = InternalAccessor.Instance.newPacket51();
packet51.setPacket(packet);
Calculations.Obfuscate(packet51, this.player);
}
return super.add(packet);
}
}

View File

@ -1,18 +0,0 @@
package com.lishid.orebfuscator.internal.v1_4_6;
import com.lishid.orebfuscator.hithack.BlockHitManager;
import net.minecraft.server.v1_4_6.*;
public class Packet14Orebfuscator extends Packet14BlockDig {
@Override
public void handle(Connection handler) {
if (this.e == 1 && handler instanceof PlayerConnection) {
boolean canHit = BlockHitManager.hitBlock(((PlayerConnection) handler).getPlayer(), null);
if (!canHit) {
return;
}
}
super.handle(handler);
}
}

View File

@ -1,82 +0,0 @@
/*
* Copyright (C) 2011-2014 lishid. All rights reserved.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, version 3.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.lishid.orebfuscator.internal.v1_4_6;
import java.util.zip.Deflater;
import com.lishid.orebfuscator.internal.IPacket51;
import com.lishid.orebfuscator.internal.InternalAccessor;
import com.lishid.orebfuscator.utils.ReflectionHelper;
//Volatile
import net.minecraft.server.v1_4_6.*;
public class Packet51 implements IPacket51 {
private static Class<? extends Object> packetClass = Packet51MapChunk.class;
Packet51MapChunk packet;
@Override
public void setPacket(Object packet) {
if (packet instanceof Packet51MapChunk) {
this.packet = (Packet51MapChunk) packet;
}
else {
InternalAccessor.Instance.PrintError();
}
}
@Override
public int getX() {
return packet.a;
}
@Override
public int getZ() {
return packet.b;
}
@Override
public int getChunkMask() {
return packet.c;
}
@Override
public int getExtraMask() {
return packet.d;
}
@Override
public byte[] getBuffer() {
return (byte[]) ReflectionHelper.getPrivateField(packetClass, packet, "inflatedBuffer");
}
private byte[] getOutputBuffer() {
return (byte[]) ReflectionHelper.getPrivateField(packetClass, packet, "buffer");
}
@Override
public void compress(Deflater deflater) {
byte[] chunkInflatedBuffer = getBuffer();
byte[] chunkBuffer = getOutputBuffer();
deflater.reset();
deflater.setInput(chunkInflatedBuffer, 0, chunkInflatedBuffer.length);
deflater.finish();
ReflectionHelper.setPrivateField(packetClass, packet, "size", deflater.deflate(chunkBuffer));
}
}

View File

@ -1,115 +0,0 @@
/*
* Copyright (C) 2011-2014 lishid. All rights reserved.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, version 3.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.lishid.orebfuscator.internal.v1_4_6;
import java.util.zip.Deflater;
import com.lishid.orebfuscator.commands.OrebfuscatorCommandExecutor;
import com.lishid.orebfuscator.internal.IPacket56;
import com.lishid.orebfuscator.internal.InternalAccessor;
import com.lishid.orebfuscator.utils.ReflectionHelper;
//Volatile
import net.minecraft.server.v1_4_6.*;
public class Packet56 implements IPacket56 {
Packet56MapChunkBulk packet;
@Override
public void setPacket(Object packet) {
if (packet instanceof Packet56MapChunkBulk) {
this.packet = (Packet56MapChunkBulk) packet;
}
else {
InternalAccessor.Instance.PrintError();
}
}
@Override
public int getPacketChunkNumber() {
return packet.d();
}
@Override
public int[] getX() {
return (int[]) ReflectionHelper.getPrivateField(packet, "c");
}
@Override
public int[] getZ() {
return (int[]) ReflectionHelper.getPrivateField(packet, "d");
}
@Override
public int[] getChunkMask() {
return packet.a;
}
@Override
public int[] getExtraMask() {
return packet.b;
}
@Override
public Object getFieldData(String field) {
return ReflectionHelper.getPrivateField(Packet56MapChunkBulk.class, packet, field);
}
@Override
public void setFieldData(String field, Object data) {
ReflectionHelper.setPrivateField(Packet56MapChunkBulk.class, packet, field, data);
}
public String getInflatedBuffers() {
return "inflatedBuffers";
}
public String getBuildBuffer() {
return "buildBuffer";
}
public String getOutputBuffer() {
return "buffer";
}
@Override
public void compress(Deflater deflater) {
if (getFieldData(getOutputBuffer()) != null) {
return;
}
byte[] buildBuffer = (byte[]) getFieldData(getBuildBuffer());
deflater.reset();
deflater.setInput(buildBuffer);
deflater.finish();
byte[] buffer = new byte[buildBuffer.length + 100];
ReflectionHelper.setPrivateField(packet, "buffer", buffer);
int size = deflater.deflate(buffer);
ReflectionHelper.setPrivateField(packet, "size", size);
// Free memory
ReflectionHelper.setPrivateField(packet, "buildBuffer", null);
ReflectionHelper.setPrivateField(packet, "inflatedBuffers", null);
if (OrebfuscatorCommandExecutor.DebugMode) {
System.out.println("Packet size: " + size);
}
}
}

View File

@ -1,96 +0,0 @@
/*
* Copyright (C) 2011-2014 lishid. All rights reserved.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, version 3.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.lishid.orebfuscator.internal.v1_4_6;
import java.lang.reflect.Field;
import java.util.Collections;
import java.util.Map;
import java.util.List;
import com.lishid.orebfuscator.Orebfuscator;
import com.lishid.orebfuscator.internal.IPlayerHook;
import com.lishid.orebfuscator.utils.ReflectionHelper;
import org.bukkit.entity.Player;
//Volatile
import net.minecraft.server.v1_4_6.*;
import org.bukkit.craftbukkit.v1_4_6.entity.*;
public class PlayerHook implements IPlayerHook {
@SuppressWarnings("unchecked")
public void HookNM(Player p) {
CraftPlayer player = (CraftPlayer) p;
// Update NetworkManager's lists
NetworkManager networkManager = (NetworkManager) player.getHandle().playerConnection.networkManager;
Field[] networkFields = networkManager.getClass().getDeclaredFields();
for (Field field : networkFields) {
try {
if (List.class.isAssignableFrom(field.getType())) {
List<Packet> list = new NetworkQueue(p);
field.setAccessible(true);
List<Packet> oldList = (List<Packet>) field.get(networkManager);
// Move packets to new list
synchronized (ReflectionHelper.getPrivateField(networkManager, "h")) {
list.addAll(oldList);
oldList.clear();
}
// Replace with new list
field.set(networkManager, Collections.synchronizedList(list));
}
}
catch (Exception e) {
Orebfuscator.log(e);
}
}
hookPacket();
}
static boolean hookPacket = false;
@SuppressWarnings("unchecked")
private void hookPacket() {
if (hookPacket)
return;
hookPacket = true;
Packet.l.a(14, Packet14Orebfuscator.class);
// Use reflection to add into a and c
Field[] packetFields = Packet.class.getDeclaredFields();
for (Field field : packetFields) {
try {
if (Map.class.isAssignableFrom(field.getType())) {
field.setAccessible(true);
@SuppressWarnings({ "rawtypes" })
Map packets = (Map) field.get(null);
packets.put(Packet14Orebfuscator.class, 14);
}
}
catch (Exception e) {
Orebfuscator.log(e);
}
}
}
public void HookChunkQueue(Player p) {
CraftPlayer player = (CraftPlayer) p;
ReflectionHelper.setPrivateFinal(player.getHandle(), "chunkCoordIntPairQueue", new ChunkQueue(player, player.getHandle().chunkCoordIntPairQueue));
}
}

View File

@ -1,46 +0,0 @@
/*
* Copyright (C) 2011-2014 lishid. All rights reserved.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, version 3.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.lishid.orebfuscator.internal.v1_4_R1;
import com.lishid.orebfuscator.internal.IBlockAccess;
import org.bukkit.entity.Player;
//Volatile
import net.minecraft.server.v1_4_R1.*;
import org.bukkit.craftbukkit.v1_4_R1.entity.*;
import org.bukkit.craftbukkit.v1_4_R1.*;
public class BlockAccess implements IBlockAccess {
@Override
public boolean isBlockTransparent(int id) {
return !Block.i(id);
}
@Override
public void updateBlockTileEntity(org.bukkit.block.Block block, Player player) {
CraftWorld world = (CraftWorld) block.getWorld();
TileEntity tileEntity = world.getTileEntityAt(block.getX(), block.getY(), block.getZ());
if (tileEntity == null) {
return;
}
Packet packet = tileEntity.getUpdatePacket();
if (packet != null) {
CraftPlayer player2 = (CraftPlayer) player;
player2.getHandle().playerConnection.sendPacket(packet);
}
}
}

View File

@ -1,92 +0,0 @@
/*
* Copyright (C) 2011-2014 lishid. All rights reserved.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, version 3.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.lishid.orebfuscator.internal.v1_4_R1;
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.File;
import java.util.HashMap;
import com.lishid.orebfuscator.Orebfuscator;
import com.lishid.orebfuscator.OrebfuscatorConfig;
import com.lishid.orebfuscator.internal.IChunkCache;
//Volatile
import net.minecraft.server.v1_4_R1.*;
public class ChunkCache implements IChunkCache {
private static final HashMap<File, RegionFile> cachedRegionFiles = new HashMap<File, RegionFile>();
private synchronized RegionFile getRegionFile(File folder, int x, int z) {
File path = new File(folder, "region");
File file = new File(path, "r." + (x >> 5) + "." + (z >> 5) + ".mcr");
try {
RegionFile regionFile = cachedRegionFiles.get(file);
if (regionFile != null) {
return regionFile;
}
if (!path.exists()) {
path.mkdirs();
}
if (cachedRegionFiles.size() >= OrebfuscatorConfig.MaxLoadedCacheFiles) {
clearCache();
}
regionFile = new RegionFile(file);
cachedRegionFiles.put(file, regionFile);
return regionFile;
}
catch (Exception e) {
try {
file.delete();
}
catch (Exception e2) {
Orebfuscator.log(e);
}
}
return null;
}
@Override
public DataInputStream getInputStream(File folder, int x, int z) {
RegionFile regionFile = getRegionFile(folder, x, z);
return regionFile.a(x & 0x1F, z & 0x1F);
}
@Override
public DataOutputStream getOutputStream(File folder, int x, int z) {
RegionFile regionFile = getRegionFile(folder, x, z);
return regionFile.b(x & 0x1F, z & 0x1F);
}
@Override
public synchronized void clearCache() {
for (RegionFile regionFile : cachedRegionFiles.values()) {
try {
if (regionFile != null)
regionFile.c();
}
catch (Exception e) {
e.printStackTrace();
}
}
cachedRegionFiles.clear();
}
}

View File

@ -1,318 +0,0 @@
/*
* Copyright (C) 2011-2014 lishid. All rights reserved.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, version 3.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.lishid.orebfuscator.internal.v1_4_R1;
import java.util.Collections;
import java.util.LinkedList;
import java.util.List;
import java.util.ListIterator;
import java.util.concurrent.atomic.AtomicBoolean;
import com.lishid.orebfuscator.Orebfuscator;
import com.lishid.orebfuscator.hook.ChunkProcessingThread;
import com.lishid.orebfuscator.internal.IChunkQueue;
import com.lishid.orebfuscator.internal.IPacket56;
import com.lishid.orebfuscator.internal.InternalAccessor;
import com.lishid.orebfuscator.utils.ReflectionHelper;
//Volatile
import net.minecraft.server.v1_4_R1.*;
import org.bukkit.craftbukkit.v1_4_R1.entity.*;
public class ChunkQueue extends LinkedList<ChunkCoordIntPair> implements IChunkQueue {
private static final long serialVersionUID = -1928681564741152336L;
List<ChunkCoordIntPair> internalQueue = Collections.synchronizedList(new LinkedList<ChunkCoordIntPair>());
List<ChunkCoordIntPair> outputQueue = Collections.synchronizedList(new LinkedList<ChunkCoordIntPair>());
List<ChunkCoordIntPair> processingQueue = Collections.synchronizedList(new LinkedList<ChunkCoordIntPair>());
Packet56MapChunkBulk lastPacket;
CraftPlayer player;
Thread thread;
AtomicBoolean kill = new AtomicBoolean(false);
@SuppressWarnings({ "unchecked", "rawtypes" })
public ChunkQueue(CraftPlayer player, List previousEntries) {
this.player = player;
internalQueue.addAll(previousEntries);
}
@Override
public boolean remove(Object arg0) {
return internalQueue.remove(arg0) || processingQueue.remove(arg0) || outputQueue.remove(arg0);
}
// Called when the queue should be cleared
@Override
public void clear() {
// Clear the internal queue
internalQueue.clear();
super.clear();
}
// Called when new chunks are queued
@Override
public boolean add(ChunkCoordIntPair e) {
boolean result;
synchronized (internalQueue) {
result = internalQueue.add(e);
}
// Move everything into the internal queue
return result;
// return super.add(e);
}
// Called when the list should be sorted
@Override
public Object[] toArray() {
sort();
// Return the old array to be sorted
return internalQueue.toArray();
}
// This checks for chunks in the queue
@Override
public boolean contains(Object o) {
// Checks whether the coords are actually in
return internalQueue.contains(o) || processingQueue.contains(o);
}
@Override
public boolean isEmpty() {
try {
// If the player is gone, then don't waste time
if (player.getHandle().playerConnection.disconnected) {
// Cleanup all queues
synchronized (internalQueue) {
internalQueue.clear();
}
processingQueue.clear();
outputQueue.clear();
lastPacket = null;
}
else {
// Process outputs and inputs
processOutput();
processInput();
}
}
catch (Exception e) {
Orebfuscator.log(e);
}
return true;
}
public void sort() {
// Sort the internal array according to CB - See PlayerChunkMap.movePlayer(EntityPlayer entityplayer)
synchronized (internalQueue) {
java.util.Collections.sort(internalQueue, new ChunkCoordComparator(player.getHandle()));
}
}
@Override
public void FinishedProcessing(IPacket56 packet) {
if (lastPacket != null) {
player.getHandle().playerConnection.sendPacket(lastPacket);
// Remove reference to the packet so it can be freed when possible
lastPacket = null;
}
outputQueue.addAll(processingQueue);
processingQueue.clear();
}
private void processOutput() {
// Chunk packet finished processing, output relevant packets
while (!outputQueue.isEmpty()) {
// Get the chunk coordinate
ChunkCoordIntPair chunk = outputQueue.remove(0);
// Check if the chunk is ready
if (chunk != null && ((WorldServer) player.getHandle().world).isLoaded(chunk.x << 4, 0, chunk.z << 4)) {
// Get all the TileEntities in the chunk
@SuppressWarnings("rawtypes")
List tileEntities = ((WorldServer) player.getHandle().world).getTileEntities(chunk.x * 16, 0, chunk.z * 16, chunk.x * 16 + 16, 256, chunk.z * 16 + 16);
for (Object o : tileEntities) {
// Send out packet for the tile entity data
this.updateTileEntity((TileEntity) o);
}
// Start tracking entities in the chunk
player.getHandle().p().getTracker().a(player.getHandle(), player.getHandle().p().getChunkAt(chunk.x, chunk.z));
}
}
}
private void processInput() {
// Queue next chunk packet out
if (processingQueue.isEmpty() && !internalQueue.isEmpty()) {
// Check if player's output queue has a lot of stuff waiting to be sent. If so, don't process and wait.
// Network queue limit is 2097152 bytes
// Each chunk packet with 5 chunks is about 10000 - 25000 bytes
// We'll allow the size of 3 packets to be queued = 75000 bytes
// Try-catch so as to not disrupt chunk sending if something fails
if (!Orebfuscator.usePL) {
try {
NetworkManager networkManager = (NetworkManager) player.getHandle().playerConnection.networkManager;
if (((int) (Integer) ReflectionHelper.getPrivateField(NetworkManager.class, networkManager, "y")) > 75000) {
return;
}
}
catch (Exception e) {
// e.printStackTrace();
}
}
// A list to queue chunks
List<Chunk> chunks = new LinkedList<Chunk>();
// Queue up to 5 chunks
synchronized (internalQueue) {
while (!internalQueue.isEmpty() && chunks.size() < 5) {
// Dequeue a chunk from input
ChunkCoordIntPair chunkcoordintpair = internalQueue.remove(0);
// If the chunk is loaded and not null
if (chunkcoordintpair != null && player.getHandle().world.isLoaded(chunkcoordintpair.x << 4, 0, chunkcoordintpair.z << 4)) {
// Queue the chunk for processing
processingQueue.add(chunkcoordintpair);
// Add the chunk to the list to create a packet
chunks.add(player.getHandle().world.getChunkAt(chunkcoordintpair.x, chunkcoordintpair.z));
}
}
}
// If there are chunks to process
if (!chunks.isEmpty()) {
// Create a packet wrapper
IPacket56 packet = InternalAccessor.Instance.newPacket56();
// Create the actual packet
lastPacket = new Packet56MapChunkBulk(chunks);
// Put into wrapper
packet.setPacket(lastPacket);
// Send to Processing Thread
ChunkProcessingThread.Queue(packet, player, this);
}
}
}
private void updateTileEntity(TileEntity tileentity) {
if (tileentity != null) {
Packet packet = tileentity.getUpdatePacket();
if (packet != null) {
player.getHandle().playerConnection.sendPacket(packet);
}
}
}
@Override
public ListIterator<ChunkCoordIntPair> listIterator() {
return new FakeIterator();
}
private class FakeIterator implements ListIterator<ChunkCoordIntPair> {
@Override
public boolean hasNext() {
return false;
}
@Override
public ChunkCoordIntPair next() {
return null;
}
@Override
public boolean hasPrevious() {
return false;
}
@Override
public ChunkCoordIntPair previous() {
return null;
}
@Override
public int nextIndex() {
return 0;
}
@Override
public int previousIndex() {
return 0;
}
@Override
public void remove() {}
@Override
public void set(ChunkCoordIntPair e) {}
@Override
public void add(ChunkCoordIntPair e) {}
}
private static class ChunkCoordComparator implements java.util.Comparator<ChunkCoordIntPair> {
private int x;
private int z;
public ChunkCoordComparator(EntityPlayer entityplayer) {
x = (int) entityplayer.locX >> 4;
z = (int) entityplayer.locZ >> 4;
}
public int compare(ChunkCoordIntPair a, ChunkCoordIntPair b) {
if (a.equals(b)) {
return 0;
}
// Subtract current position to set center point
int ax = a.x - this.x;
int az = a.z - this.z;
int bx = b.x - this.x;
int bz = b.z - this.z;
int result = ((ax - bx) * (ax + bx)) + ((az - bz) * (az + bz));
if (result != 0) {
return result;
}
if (ax < 0) {
if (bx < 0) {
return bz - az;
}
else {
return -1;
}
}
else {
if (bx < 0) {
return 1;
}
else {
return az - bz;
}
}
}
}
}

View File

@ -1,36 +0,0 @@
/*
* Copyright (C) 2011-2014 lishid. All rights reserved.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, version 3.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.lishid.orebfuscator.internal.v1_4_R1;
import com.lishid.orebfuscator.internal.IMinecraftWorldServer;
import com.lishid.orebfuscator.internal.InternalAccessor;
//Volatile
import net.minecraft.server.v1_4_R1.*;
import org.bukkit.craftbukkit.v1_4_R1.*;
public class MinecraftWorldServer implements IMinecraftWorldServer {
public void Notify(Object world, int x, int y, int z) {
if (world instanceof CraftWorld) {
WorldServer server = (WorldServer) ((CraftWorld) world).getHandle();
server.notify(x, y, z);
}
else {
InternalAccessor.Instance.PrintError();
}
}
}

View File

@ -1,95 +0,0 @@
/*
* Copyright (C) 2011-2014 lishid. All rights reserved.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, version 3.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.lishid.orebfuscator.internal.v1_4_R1;
import java.io.DataInput;
import java.io.DataOutput;
import com.lishid.orebfuscator.internal.INBT;
//Volatile
import net.minecraft.server.v1_4_R1.*;
public class NBT implements INBT {
NBTTagCompound nbt = new NBTTagCompound();
@Override
public void reset() {
nbt = new NBTTagCompound();
}
@Override
public void setInt(String tag, int value) {
nbt.setInt(tag, value);
}
@Override
public void setLong(String tag, long value) {
nbt.setLong(tag, value);
}
@Override
public void setBoolean(String tag, boolean value) {
nbt.setBoolean(tag, value);
}
@Override
public void setByteArray(String tag, byte[] value) {
nbt.setByteArray(tag, value);
}
@Override
public void setIntArray(String tag, int[] value) {
nbt.setIntArray(tag, value);
}
@Override
public int getInt(String tag) {
return nbt.getInt(tag);
}
@Override
public long getLong(String tag) {
return nbt.getLong(tag);
}
@Override
public boolean getBoolean(String tag) {
return nbt.getBoolean(tag);
}
@Override
public byte[] getByteArray(String tag) {
return nbt.getByteArray(tag);
}
@Override
public int[] getIntArray(String tag) {
return nbt.getIntArray(tag);
}
@Override
public void Read(DataInput stream) {
nbt = NBTCompressedStreamTools.a(stream);
}
@Override
public void Write(DataOutput stream) {
NBTCompressedStreamTools.a(nbt, stream);
}
}

View File

@ -1,48 +0,0 @@
/*
* Copyright (C) 2011-2014 lishid. All rights reserved.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, version 3.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.lishid.orebfuscator.internal.v1_4_R1;
import java.util.ArrayList;
import org.bukkit.entity.Player;
import com.lishid.orebfuscator.internal.IPacket51;
import com.lishid.orebfuscator.internal.InternalAccessor;
import com.lishid.orebfuscator.obfuscation.Calculations;
//Volatile
import net.minecraft.server.v1_4_R1.*;
public class NetworkQueue extends ArrayList<Packet> {
private static final long serialVersionUID = 4252847662044263527L;
private Player player;
public NetworkQueue(Player player) {
this.player = player;
}
@Override
public boolean add(Packet packet) {
if (packet.k() == 51) {
IPacket51 packet51 = InternalAccessor.Instance.newPacket51();
packet51.setPacket(packet);
Calculations.Obfuscate(packet51, this.player);
}
return super.add(packet);
}
}

View File

@ -1,18 +0,0 @@
package com.lishid.orebfuscator.internal.v1_4_R1;
import com.lishid.orebfuscator.hithack.BlockHitManager;
import net.minecraft.server.v1_4_R1.*;
public class Packet14Orebfuscator extends Packet14BlockDig {
@Override
public void handle(Connection handler) {
if (this.e == 1 && handler instanceof PlayerConnection) {
boolean canHit = BlockHitManager.hitBlock(((PlayerConnection) handler).getPlayer(), null);
if (!canHit) {
return;
}
}
super.handle(handler);
}
}

View File

@ -1,82 +0,0 @@
/*
* Copyright (C) 2011-2014 lishid. All rights reserved.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, version 3.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.lishid.orebfuscator.internal.v1_4_R1;
import java.util.zip.Deflater;
import com.lishid.orebfuscator.internal.IPacket51;
import com.lishid.orebfuscator.internal.InternalAccessor;
import com.lishid.orebfuscator.utils.ReflectionHelper;
//Volatile
import net.minecraft.server.v1_4_R1.*;
public class Packet51 implements IPacket51 {
private static Class<? extends Object> packetClass = Packet51MapChunk.class;
Packet51MapChunk packet;
@Override
public void setPacket(Object packet) {
if (packet instanceof Packet51MapChunk) {
this.packet = (Packet51MapChunk) packet;
}
else {
InternalAccessor.Instance.PrintError();
}
}
@Override
public int getX() {
return packet.a;
}
@Override
public int getZ() {
return packet.b;
}
@Override
public int getChunkMask() {
return packet.c;
}
@Override
public int getExtraMask() {
return packet.d;
}
@Override
public byte[] getBuffer() {
return (byte[]) ReflectionHelper.getPrivateField(packetClass, packet, "inflatedBuffer");
}
private byte[] getOutputBuffer() {
return (byte[]) ReflectionHelper.getPrivateField(packetClass, packet, "buffer");
}
@Override
public void compress(Deflater deflater) {
byte[] chunkInflatedBuffer = getBuffer();
byte[] chunkBuffer = getOutputBuffer();
deflater.reset();
deflater.setInput(chunkInflatedBuffer, 0, chunkInflatedBuffer.length);
deflater.finish();
ReflectionHelper.setPrivateField(packetClass, packet, "size", deflater.deflate(chunkBuffer));
}
}

View File

@ -1,115 +0,0 @@
/*
* Copyright (C) 2011-2014 lishid. All rights reserved.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, version 3.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.lishid.orebfuscator.internal.v1_4_R1;
import java.util.zip.Deflater;
import com.lishid.orebfuscator.commands.OrebfuscatorCommandExecutor;
import com.lishid.orebfuscator.internal.IPacket56;
import com.lishid.orebfuscator.internal.InternalAccessor;
import com.lishid.orebfuscator.utils.ReflectionHelper;
//Volatile
import net.minecraft.server.v1_4_R1.*;
public class Packet56 implements IPacket56 {
Packet56MapChunkBulk packet;
@Override
public void setPacket(Object packet) {
if (packet instanceof Packet56MapChunkBulk) {
this.packet = (Packet56MapChunkBulk) packet;
}
else {
InternalAccessor.Instance.PrintError();
}
}
@Override
public int getPacketChunkNumber() {
return packet.d();
}
@Override
public int[] getX() {
return (int[]) ReflectionHelper.getPrivateField(packet, "c");
}
@Override
public int[] getZ() {
return (int[]) ReflectionHelper.getPrivateField(packet, "d");
}
@Override
public int[] getChunkMask() {
return packet.a;
}
@Override
public int[] getExtraMask() {
return packet.b;
}
@Override
public Object getFieldData(String field) {
return ReflectionHelper.getPrivateField(Packet56MapChunkBulk.class, packet, field);
}
@Override
public void setFieldData(String field, Object data) {
ReflectionHelper.setPrivateField(Packet56MapChunkBulk.class, packet, field, data);
}
public String getInflatedBuffers() {
return "inflatedBuffers";
}
public String getBuildBuffer() {
return "buildBuffer";
}
public String getOutputBuffer() {
return "buffer";
}
@Override
public void compress(Deflater deflater) {
if (getFieldData(getOutputBuffer()) != null) {
return;
}
byte[] buildBuffer = (byte[]) getFieldData(getBuildBuffer());
deflater.reset();
deflater.setInput(buildBuffer);
deflater.finish();
byte[] buffer = new byte[buildBuffer.length + 100];
ReflectionHelper.setPrivateField(packet, "buffer", buffer);
int size = deflater.deflate(buffer);
ReflectionHelper.setPrivateField(packet, "size", size);
// Free memory
ReflectionHelper.setPrivateField(packet, "buildBuffer", null);
ReflectionHelper.setPrivateField(packet, "inflatedBuffers", null);
if (OrebfuscatorCommandExecutor.DebugMode) {
System.out.println("Packet size: " + size);
}
}
}

View File

@ -1,95 +0,0 @@
/*
* Copyright (C) 2011-2014 lishid. All rights reserved.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, version 3.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.lishid.orebfuscator.internal.v1_4_R1;
import java.lang.reflect.Field;
import java.util.Collections;
import java.util.Map;
import java.util.List;
import com.lishid.orebfuscator.Orebfuscator;
import com.lishid.orebfuscator.internal.IPlayerHook;
import com.lishid.orebfuscator.utils.ReflectionHelper;
import org.bukkit.entity.Player;
//Volatile
import net.minecraft.server.v1_4_R1.*;
import org.bukkit.craftbukkit.v1_4_R1.entity.*;
public class PlayerHook implements IPlayerHook {
@SuppressWarnings("unchecked")
public void HookNM(Player p) {
CraftPlayer player = (CraftPlayer) p;
// Update NetworkManager's lists
NetworkManager networkManager = (NetworkManager) player.getHandle().playerConnection.networkManager;
Field[] networkFields = networkManager.getClass().getDeclaredFields();
for (Field field : networkFields) {
try {
if (List.class.isAssignableFrom(field.getType())) {
List<Packet> list = new NetworkQueue(p);
field.setAccessible(true);
List<Packet> oldList = (List<Packet>) field.get(networkManager);
// Move packets to new list
synchronized (ReflectionHelper.getPrivateField(networkManager, "h")) {
list.addAll(oldList);
oldList.clear();
}
// Replace with new list
field.set(networkManager, Collections.synchronizedList(list));
}
}
catch (Exception e) {
Orebfuscator.log(e);
}
}
hookPacket();
}
static boolean hookPacket = false;
@SuppressWarnings("unchecked")
private void hookPacket() {
if (hookPacket)
return;
hookPacket = true;
Packet.l.a(14, Packet14Orebfuscator.class);
// Use reflection to add into a and c
Field[] packetFields = Packet.class.getDeclaredFields();
for (Field field : packetFields) {
try {
if (Map.class.isAssignableFrom(field.getType())) {
field.setAccessible(true);
@SuppressWarnings({ "rawtypes" })
Map packets = (Map) field.get(null);
packets.put(Packet14Orebfuscator.class, 14);
}
}
catch (Exception e) {
Orebfuscator.log(e);
}
}
}
public void HookChunkQueue(Player p) {
CraftPlayer player = (CraftPlayer) p;
ReflectionHelper.setPrivateFinal(player.getHandle(), "chunkCoordIntPairQueue", new ChunkQueue(player, player.getHandle().chunkCoordIntPairQueue));
}
}

View File

@ -1,46 +0,0 @@
/*
* Copyright (C) 2011-2014 lishid. All rights reserved.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, version 3.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.lishid.orebfuscator.internal.v1_5_R2;
import com.lishid.orebfuscator.internal.IBlockAccess;
import org.bukkit.entity.Player;
//Volatile
import net.minecraft.server.v1_5_R2.*;
import org.bukkit.craftbukkit.v1_5_R2.entity.*;
import org.bukkit.craftbukkit.v1_5_R2.*;
public class BlockAccess implements IBlockAccess {
@Override
public boolean isBlockTransparent(int id) {
return !Block.l(id);
}
@Override
public void updateBlockTileEntity(org.bukkit.block.Block block, Player player) {
CraftWorld world = (CraftWorld) block.getWorld();
TileEntity tileEntity = world.getTileEntityAt(block.getX(), block.getY(), block.getZ());
if (tileEntity == null) {
return;
}
Packet packet = tileEntity.getUpdatePacket();
if (packet != null) {
CraftPlayer player2 = (CraftPlayer) player;
player2.getHandle().playerConnection.sendPacket(packet);
}
}
}

View File

@ -1,92 +0,0 @@
/*
* Copyright (C) 2011-2014 lishid. All rights reserved.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, version 3.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.lishid.orebfuscator.internal.v1_5_R2;
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.File;
import java.util.HashMap;
import com.lishid.orebfuscator.Orebfuscator;
import com.lishid.orebfuscator.OrebfuscatorConfig;
import com.lishid.orebfuscator.internal.IChunkCache;
//Volatile
import net.minecraft.server.v1_5_R2.*;
public class ChunkCache implements IChunkCache {
private static final HashMap<File, RegionFile> cachedRegionFiles = new HashMap<File, RegionFile>();
private synchronized RegionFile getRegionFile(File folder, int x, int z) {
File path = new File(folder, "region");
File file = new File(path, "r." + (x >> 5) + "." + (z >> 5) + ".mcr");
try {
RegionFile regionFile = cachedRegionFiles.get(file);
if (regionFile != null) {
return regionFile;
}
if (!path.exists()) {
path.mkdirs();
}
if (cachedRegionFiles.size() >= OrebfuscatorConfig.MaxLoadedCacheFiles) {
clearCache();
}
regionFile = new RegionFile(file);
cachedRegionFiles.put(file, regionFile);
return regionFile;
}
catch (Exception e) {
try {
file.delete();
}
catch (Exception e2) {
Orebfuscator.log(e);
}
}
return null;
}
@Override
public DataInputStream getInputStream(File folder, int x, int z) {
RegionFile regionFile = getRegionFile(folder, x, z);
return regionFile.a(x & 0x1F, z & 0x1F);
}
@Override
public DataOutputStream getOutputStream(File folder, int x, int z) {
RegionFile regionFile = getRegionFile(folder, x, z);
return regionFile.b(x & 0x1F, z & 0x1F);
}
@Override
public synchronized void clearCache() {
for (RegionFile regionFile : cachedRegionFiles.values()) {
try {
if (regionFile != null)
regionFile.c();
}
catch (Exception e) {
e.printStackTrace();
}
}
cachedRegionFiles.clear();
}
}

View File

@ -1,318 +0,0 @@
/*
* Copyright (C) 2011-2014 lishid. All rights reserved.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, version 3.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.lishid.orebfuscator.internal.v1_5_R2;
import java.util.Collections;
import java.util.LinkedList;
import java.util.List;
import java.util.ListIterator;
import java.util.concurrent.atomic.AtomicBoolean;
import com.lishid.orebfuscator.Orebfuscator;
import com.lishid.orebfuscator.hook.ChunkProcessingThread;
import com.lishid.orebfuscator.internal.IChunkQueue;
import com.lishid.orebfuscator.internal.IPacket56;
import com.lishid.orebfuscator.internal.InternalAccessor;
import com.lishid.orebfuscator.utils.ReflectionHelper;
//Volatile
import net.minecraft.server.v1_5_R2.*;
import org.bukkit.craftbukkit.v1_5_R2.entity.*;
public class ChunkQueue extends LinkedList<ChunkCoordIntPair> implements IChunkQueue {
private static final long serialVersionUID = -1928681564741152336L;
List<ChunkCoordIntPair> internalQueue = Collections.synchronizedList(new LinkedList<ChunkCoordIntPair>());
List<ChunkCoordIntPair> outputQueue = Collections.synchronizedList(new LinkedList<ChunkCoordIntPair>());
List<ChunkCoordIntPair> processingQueue = Collections.synchronizedList(new LinkedList<ChunkCoordIntPair>());
Packet56MapChunkBulk lastPacket;
CraftPlayer player;
Thread thread;
AtomicBoolean kill = new AtomicBoolean(false);
@SuppressWarnings({ "unchecked", "rawtypes" })
public ChunkQueue(CraftPlayer player, List previousEntries) {
this.player = player;
internalQueue.addAll(previousEntries);
}
@Override
public boolean remove(Object arg0) {
return internalQueue.remove(arg0) || processingQueue.remove(arg0) || outputQueue.remove(arg0);
}
// Called when the queue should be cleared
@Override
public void clear() {
// Clear the internal queue
internalQueue.clear();
super.clear();
}
// Called when new chunks are queued
@Override
public boolean add(ChunkCoordIntPair e) {
boolean result;
synchronized (internalQueue) {
result = internalQueue.add(e);
}
// Move everything into the internal queue
return result;
// return super.add(e);
}
// Called when the list should be sorted
@Override
public Object[] toArray() {
sort();
// Return the old array to be sorted
return internalQueue.toArray();
}
// This checks for chunks in the queue
@Override
public boolean contains(Object o) {
// Checks whether the coords are actually in
return internalQueue.contains(o) || processingQueue.contains(o);
}
@Override
public boolean isEmpty() {
try {
// If the player is gone, then don't waste time
if (player.getHandle().playerConnection.disconnected) {
// Cleanup all queues
synchronized (internalQueue) {
internalQueue.clear();
}
processingQueue.clear();
outputQueue.clear();
lastPacket = null;
}
else {
// Process outputs and inputs
processOutput();
processInput();
}
}
catch (Exception e) {
Orebfuscator.log(e);
}
return true;
}
public void sort() {
// Sort the internal array according to CB - See PlayerChunkMap.movePlayer(EntityPlayer entityplayer)
synchronized (internalQueue) {
java.util.Collections.sort(internalQueue, new ChunkCoordComparator(player.getHandle()));
}
}
@Override
public void FinishedProcessing(IPacket56 packet) {
if (lastPacket != null) {
player.getHandle().playerConnection.sendPacket(lastPacket);
// Remove reference to the packet so it can be freed when possible
lastPacket = null;
}
outputQueue.addAll(processingQueue);
processingQueue.clear();
}
private void processOutput() {
// Chunk packet finished processing, output relevant packets
while (!outputQueue.isEmpty()) {
// Get the chunk coordinate
ChunkCoordIntPair chunk = outputQueue.remove(0);
// Check if the chunk is ready
if (chunk != null && ((WorldServer) player.getHandle().world).isLoaded(chunk.x << 4, 0, chunk.z << 4)) {
// Get all the TileEntities in the chunk
@SuppressWarnings("rawtypes")
List tileEntities = ((WorldServer) player.getHandle().world).getTileEntities(chunk.x * 16, 0, chunk.z * 16, chunk.x * 16 + 16, 256, chunk.z * 16 + 16);
for (Object o : tileEntities) {
// Send out packet for the tile entity data
this.updateTileEntity((TileEntity) o);
}
// Start tracking entities in the chunk
((WorldServer) player.getHandle().world).getTracker().a(player.getHandle(), player.getHandle().world.getChunkAt(chunk.x, chunk.z));
}
}
}
private void processInput() {
// Queue next chunk packet out
if (processingQueue.isEmpty() && !internalQueue.isEmpty()) {
// Check if player's output queue has a lot of stuff waiting to be sent. If so, don't process and wait.
// Network queue limit is 2097152 bytes
// Each chunk packet with 5 chunks is about 10000 - 25000 bytes
// We'll allow the size of 3 packets to be queued = 75000 bytes
// Try-catch so as to not disrupt chunk sending if something fails
if (!Orebfuscator.useSpigot) {
try {
NetworkManager networkManager = (NetworkManager) player.getHandle().playerConnection.networkManager;
if (((int) (Integer) ReflectionHelper.getPrivateField(NetworkManager.class, networkManager, "z")) > 75000) {
return;
}
}
catch (Exception e) {
e.printStackTrace();
}
}
// A list to queue chunks
List<Chunk> chunks = new LinkedList<Chunk>();
// Queue up to 5 chunks
synchronized (internalQueue) {
while (!internalQueue.isEmpty() && chunks.size() < 5) {
// Dequeue a chunk from input
ChunkCoordIntPair chunkcoordintpair = internalQueue.remove(0);
// If the chunk is loaded and not null
if (chunkcoordintpair != null && player.getHandle().world.isLoaded(chunkcoordintpair.x << 4, 0, chunkcoordintpair.z << 4)) {
// Queue the chunk for processing
processingQueue.add(chunkcoordintpair);
// Add the chunk to the list to create a packet
chunks.add(player.getHandle().world.getChunkAt(chunkcoordintpair.x, chunkcoordintpair.z));
}
}
}
// If there are chunks to process
if (!chunks.isEmpty()) {
// Create a packet wrapper
IPacket56 packet = InternalAccessor.Instance.newPacket56();
// Create the actual packet
lastPacket = new Packet56MapChunkBulk(chunks);
// Put into wrapper
packet.setPacket(lastPacket);
// Send to Processing Thread
ChunkProcessingThread.Queue(packet, player, this);
}
}
}
private void updateTileEntity(TileEntity tileentity) {
if (tileentity != null) {
Packet packet = tileentity.getUpdatePacket();
if (packet != null) {
player.getHandle().playerConnection.sendPacket(packet);
}
}
}
@Override
public ListIterator<ChunkCoordIntPair> listIterator() {
return new FakeIterator();
}
private class FakeIterator implements ListIterator<ChunkCoordIntPair> {
@Override
public boolean hasNext() {
return false;
}
@Override
public ChunkCoordIntPair next() {
return null;
}
@Override
public boolean hasPrevious() {
return false;
}
@Override
public ChunkCoordIntPair previous() {
return null;
}
@Override
public int nextIndex() {
return 0;
}
@Override
public int previousIndex() {
return 0;
}
@Override
public void remove() {}
@Override
public void set(ChunkCoordIntPair e) {}
@Override
public void add(ChunkCoordIntPair e) {}
}
private static class ChunkCoordComparator implements java.util.Comparator<ChunkCoordIntPair> {
private int x;
private int z;
public ChunkCoordComparator(EntityPlayer entityplayer) {
x = (int) entityplayer.locX >> 4;
z = (int) entityplayer.locZ >> 4;
}
public int compare(ChunkCoordIntPair a, ChunkCoordIntPair b) {
if (a.equals(b)) {
return 0;
}
// Subtract current position to set center point
int ax = a.x - this.x;
int az = a.z - this.z;
int bx = b.x - this.x;
int bz = b.z - this.z;
int result = ((ax - bx) * (ax + bx)) + ((az - bz) * (az + bz));
if (result != 0) {
return result;
}
if (ax < 0) {
if (bx < 0) {
return bz - az;
}
else {
return -1;
}
}
else {
if (bx < 0) {
return 1;
}
else {
return az - bz;
}
}
}
}
}

View File

@ -1,36 +0,0 @@
/*
* Copyright (C) 2011-2014 lishid. All rights reserved.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, version 3.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.lishid.orebfuscator.internal.v1_5_R2;
import com.lishid.orebfuscator.internal.IMinecraftWorldServer;
import com.lishid.orebfuscator.internal.InternalAccessor;
//Volatile
import net.minecraft.server.v1_5_R2.*;
import org.bukkit.craftbukkit.v1_5_R2.*;
public class MinecraftWorldServer implements IMinecraftWorldServer {
public void Notify(Object world, int x, int y, int z) {
if (world instanceof CraftWorld) {
WorldServer server = (WorldServer) ((CraftWorld) world).getHandle();
server.notify(x, y, z);
}
else {
InternalAccessor.Instance.PrintError();
}
}
}

View File

@ -1,95 +0,0 @@
/*
* Copyright (C) 2011-2014 lishid. All rights reserved.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, version 3.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.lishid.orebfuscator.internal.v1_5_R2;
import java.io.DataInput;
import java.io.DataOutput;
import com.lishid.orebfuscator.internal.INBT;
//Volatile
import net.minecraft.server.v1_5_R2.*;
public class NBT implements INBT {
NBTTagCompound nbt = new NBTTagCompound();
@Override
public void reset() {
nbt = new NBTTagCompound();
}
@Override
public void setInt(String tag, int value) {
nbt.setInt(tag, value);
}
@Override
public void setLong(String tag, long value) {
nbt.setLong(tag, value);
}
@Override
public void setBoolean(String tag, boolean value) {
nbt.setBoolean(tag, value);
}
@Override
public void setByteArray(String tag, byte[] value) {
nbt.setByteArray(tag, value);
}
@Override
public void setIntArray(String tag, int[] value) {
nbt.setIntArray(tag, value);
}
@Override
public int getInt(String tag) {
return nbt.getInt(tag);
}
@Override
public long getLong(String tag) {
return nbt.getLong(tag);
}
@Override
public boolean getBoolean(String tag) {
return nbt.getBoolean(tag);
}
@Override
public byte[] getByteArray(String tag) {
return nbt.getByteArray(tag);
}
@Override
public int[] getIntArray(String tag) {
return nbt.getIntArray(tag);
}
@Override
public void Read(DataInput stream) {
nbt = NBTCompressedStreamTools.a(stream);
}
@Override
public void Write(DataOutput stream) {
NBTCompressedStreamTools.a(nbt, stream);
}
}

View File

@ -1,48 +0,0 @@
/*
* Copyright (C) 2011-2014 lishid. All rights reserved.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, version 3.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.lishid.orebfuscator.internal.v1_5_R2;
import java.util.ArrayList;
import org.bukkit.entity.Player;
import com.lishid.orebfuscator.internal.IPacket51;
import com.lishid.orebfuscator.internal.InternalAccessor;
import com.lishid.orebfuscator.obfuscation.Calculations;
//Volatile
import net.minecraft.server.v1_5_R2.*;
public class NetworkQueue extends ArrayList<Packet> {
private static final long serialVersionUID = 4252847662044263527L;
private Player player;
public NetworkQueue(Player player) {
this.player = player;
}
@Override
public boolean add(Packet packet) {
if (packet.n() == 51) {
IPacket51 packet51 = InternalAccessor.Instance.newPacket51();
packet51.setPacket(packet);
Calculations.Obfuscate(packet51, this.player);
}
return super.add(packet);
}
}

View File

@ -1,18 +0,0 @@
package com.lishid.orebfuscator.internal.v1_5_R2;
import com.lishid.orebfuscator.hithack.BlockHitManager;
import net.minecraft.server.v1_5_R2.*;
public class Packet14Orebfuscator extends Packet14BlockDig {
@Override
public void handle(Connection handler) {
if (this.e == 1 && handler instanceof PlayerConnection) {
boolean canHit = BlockHitManager.hitBlock(((PlayerConnection) handler).getPlayer(), null);
if (!canHit) {
return;
}
}
super.handle(handler);
}
}

View File

@ -1,82 +0,0 @@
/*
* Copyright (C) 2011-2014 lishid. All rights reserved.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, version 3.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.lishid.orebfuscator.internal.v1_5_R2;
import java.util.zip.Deflater;
import com.lishid.orebfuscator.internal.IPacket51;
import com.lishid.orebfuscator.internal.InternalAccessor;
import com.lishid.orebfuscator.utils.ReflectionHelper;
//Volatile
import net.minecraft.server.v1_5_R2.*;
public class Packet51 implements IPacket51 {
private static Class<? extends Object> packetClass = Packet51MapChunk.class;
Packet51MapChunk packet;
@Override
public void setPacket(Object packet) {
if (packet instanceof Packet51MapChunk) {
this.packet = (Packet51MapChunk) packet;
}
else {
InternalAccessor.Instance.PrintError();
}
}
@Override
public int getX() {
return packet.a;
}
@Override
public int getZ() {
return packet.b;
}
@Override
public int getChunkMask() {
return packet.c;
}
@Override
public int getExtraMask() {
return packet.d;
}
@Override
public byte[] getBuffer() {
return (byte[]) ReflectionHelper.getPrivateField(packetClass, packet, "inflatedBuffer");
}
private byte[] getOutputBuffer() {
return (byte[]) ReflectionHelper.getPrivateField(packetClass, packet, "buffer");
}
@Override
public void compress(Deflater deflater) {
byte[] chunkInflatedBuffer = getBuffer();
byte[] chunkBuffer = getOutputBuffer();
deflater.reset();
deflater.setInput(chunkInflatedBuffer, 0, chunkInflatedBuffer.length);
deflater.finish();
ReflectionHelper.setPrivateField(packetClass, packet, "size", deflater.deflate(chunkBuffer));
}
}

View File

@ -1,115 +0,0 @@
/*
* Copyright (C) 2011-2014 lishid. All rights reserved.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, version 3.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.lishid.orebfuscator.internal.v1_5_R2;
import java.util.zip.Deflater;
import com.lishid.orebfuscator.commands.OrebfuscatorCommandExecutor;
import com.lishid.orebfuscator.internal.IPacket56;
import com.lishid.orebfuscator.internal.InternalAccessor;
import com.lishid.orebfuscator.utils.ReflectionHelper;
//Volatile
import net.minecraft.server.v1_5_R2.*;
public class Packet56 implements IPacket56 {
Packet56MapChunkBulk packet;
@Override
public void setPacket(Object packet) {
if (packet instanceof Packet56MapChunkBulk) {
this.packet = (Packet56MapChunkBulk) packet;
}
else {
InternalAccessor.Instance.PrintError();
}
}
@Override
public int getPacketChunkNumber() {
return packet.d();
}
@Override
public int[] getX() {
return (int[]) ReflectionHelper.getPrivateField(packet, "c");
}
@Override
public int[] getZ() {
return (int[]) ReflectionHelper.getPrivateField(packet, "d");
}
@Override
public int[] getChunkMask() {
return packet.a;
}
@Override
public int[] getExtraMask() {
return packet.b;
}
@Override
public Object getFieldData(String field) {
return ReflectionHelper.getPrivateField(Packet56MapChunkBulk.class, packet, field);
}
@Override
public void setFieldData(String field, Object data) {
ReflectionHelper.setPrivateField(Packet56MapChunkBulk.class, packet, field, data);
}
public String getInflatedBuffers() {
return "inflatedBuffers";
}
public String getBuildBuffer() {
return "buildBuffer";
}
public String getOutputBuffer() {
return "buffer";
}
@Override
public void compress(Deflater deflater) {
if (getFieldData(getOutputBuffer()) != null) {
return;
}
byte[] buildBuffer = (byte[]) getFieldData(getBuildBuffer());
deflater.reset();
deflater.setInput(buildBuffer);
deflater.finish();
byte[] buffer = new byte[buildBuffer.length + 100];
ReflectionHelper.setPrivateField(packet, "buffer", buffer);
int size = deflater.deflate(buffer);
ReflectionHelper.setPrivateField(packet, "size", size);
// Free memory
ReflectionHelper.setPrivateField(packet, "buildBuffer", null);
ReflectionHelper.setPrivateField(packet, "inflatedBuffers", null);
if (OrebfuscatorCommandExecutor.DebugMode) {
System.out.println("Packet size: " + size);
}
}
}

View File

@ -1,95 +0,0 @@
/*
* Copyright (C) 2011-2014 lishid. All rights reserved.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, version 3.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.lishid.orebfuscator.internal.v1_5_R2;
import java.lang.reflect.Field;
import java.util.Collections;
import java.util.Map;
import java.util.List;
import com.lishid.orebfuscator.Orebfuscator;
import com.lishid.orebfuscator.internal.IPlayerHook;
import com.lishid.orebfuscator.utils.ReflectionHelper;
import org.bukkit.entity.Player;
//Volatile
import net.minecraft.server.v1_5_R2.*;
import org.bukkit.craftbukkit.v1_5_R2.entity.*;
public class PlayerHook implements IPlayerHook {
@SuppressWarnings("unchecked")
public void HookNM(Player p) {
CraftPlayer player = (CraftPlayer) p;
// Update NetworkManager's lists
NetworkManager networkManager = (NetworkManager) player.getHandle().playerConnection.networkManager;
Field[] networkFields = networkManager.getClass().getDeclaredFields();
for (Field field : networkFields) {
try {
if (List.class.isAssignableFrom(field.getType())) {
List<Packet> list = new NetworkQueue(p);
field.setAccessible(true);
List<Packet> oldList = (List<Packet>) field.get(networkManager);
// Move packets to new list
synchronized (ReflectionHelper.getPrivateField(networkManager, "h")) {
list.addAll(oldList);
oldList.clear();
}
// Replace with new list
field.set(networkManager, Collections.synchronizedList(list));
}
}
catch (Exception e) {
Orebfuscator.log(e);
}
}
hookPacket();
}
static boolean hookPacket = false;
@SuppressWarnings("unchecked")
private void hookPacket() {
if (hookPacket)
return;
hookPacket = true;
Packet.l.a(14, Packet14Orebfuscator.class);
// Use reflection to add into a and c
Field[] packetFields = Packet.class.getDeclaredFields();
for (Field field : packetFields) {
try {
if (Map.class.isAssignableFrom(field.getType())) {
field.setAccessible(true);
@SuppressWarnings({ "rawtypes" })
Map packets = (Map) field.get(null);
packets.put(Packet14Orebfuscator.class, 14);
}
}
catch (Exception e) {
Orebfuscator.log(e);
}
}
}
public void HookChunkQueue(Player p) {
CraftPlayer player = (CraftPlayer) p;
ReflectionHelper.setPrivateFinal(player.getHandle(), "chunkCoordIntPairQueue", new ChunkQueue(player, player.getHandle().chunkCoordIntPairQueue));
}
}

View File

@ -1,46 +0,0 @@
/*
* Copyright (C) 2011-2014 lishid. All rights reserved.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, version 3.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.lishid.orebfuscator.internal.v1_5_R3;
import com.lishid.orebfuscator.internal.IBlockAccess;
import org.bukkit.entity.Player;
//Volatile
import net.minecraft.server.v1_5_R3.*;
import org.bukkit.craftbukkit.v1_5_R3.entity.*;
import org.bukkit.craftbukkit.v1_5_R3.*;
public class BlockAccess implements IBlockAccess {
@Override
public boolean isBlockTransparent(int id) {
return !Block.l(id);
}
@Override
public void updateBlockTileEntity(org.bukkit.block.Block block, Player player) {
CraftWorld world = (CraftWorld) block.getWorld();
TileEntity tileEntity = world.getTileEntityAt(block.getX(), block.getY(), block.getZ());
if (tileEntity == null) {
return;
}
Packet packet = tileEntity.getUpdatePacket();
if (packet != null) {
CraftPlayer player2 = (CraftPlayer) player;
player2.getHandle().playerConnection.sendPacket(packet);
}
}
}

View File

@ -1,92 +0,0 @@
/*
* Copyright (C) 2011-2014 lishid. All rights reserved.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, version 3.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.lishid.orebfuscator.internal.v1_5_R3;
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.File;
import java.util.HashMap;
import com.lishid.orebfuscator.Orebfuscator;
import com.lishid.orebfuscator.OrebfuscatorConfig;
import com.lishid.orebfuscator.internal.IChunkCache;
//Volatile
import net.minecraft.server.v1_5_R3.*;
public class ChunkCache implements IChunkCache {
private static final HashMap<File, RegionFile> cachedRegionFiles = new HashMap<File, RegionFile>();
private synchronized RegionFile getRegionFile(File folder, int x, int z) {
File path = new File(folder, "region");
File file = new File(path, "r." + (x >> 5) + "." + (z >> 5) + ".mcr");
try {
RegionFile regionFile = cachedRegionFiles.get(file);
if (regionFile != null) {
return regionFile;
}
if (!path.exists()) {
path.mkdirs();
}
if (cachedRegionFiles.size() >= OrebfuscatorConfig.MaxLoadedCacheFiles) {
clearCache();
}
regionFile = new RegionFile(file);
cachedRegionFiles.put(file, regionFile);
return regionFile;
}
catch (Exception e) {
try {
file.delete();
}
catch (Exception e2) {
Orebfuscator.log(e);
}
}
return null;
}
@Override
public DataInputStream getInputStream(File folder, int x, int z) {
RegionFile regionFile = getRegionFile(folder, x, z);
return regionFile.a(x & 0x1F, z & 0x1F);
}
@Override
public DataOutputStream getOutputStream(File folder, int x, int z) {
RegionFile regionFile = getRegionFile(folder, x, z);
return regionFile.b(x & 0x1F, z & 0x1F);
}
@Override
public synchronized void clearCache() {
for (RegionFile regionFile : cachedRegionFiles.values()) {
try {
if (regionFile != null)
regionFile.c();
}
catch (Exception e) {
e.printStackTrace();
}
}
cachedRegionFiles.clear();
}
}

View File

@ -1,318 +0,0 @@
/*
* Copyright (C) 2011-2014 lishid. All rights reserved.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, version 3.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.lishid.orebfuscator.internal.v1_5_R3;
import java.util.Collections;
import java.util.LinkedList;
import java.util.List;
import java.util.ListIterator;
import java.util.concurrent.atomic.AtomicBoolean;
import com.lishid.orebfuscator.Orebfuscator;
import com.lishid.orebfuscator.hook.ChunkProcessingThread;
import com.lishid.orebfuscator.internal.IChunkQueue;
import com.lishid.orebfuscator.internal.IPacket56;
import com.lishid.orebfuscator.internal.InternalAccessor;
import com.lishid.orebfuscator.utils.ReflectionHelper;
//Volatile
import net.minecraft.server.v1_5_R3.*;
import org.bukkit.craftbukkit.v1_5_R3.entity.*;
public class ChunkQueue extends LinkedList<ChunkCoordIntPair> implements IChunkQueue {
private static final long serialVersionUID = -1928681564741152336L;
List<ChunkCoordIntPair> internalQueue = Collections.synchronizedList(new LinkedList<ChunkCoordIntPair>());
List<ChunkCoordIntPair> outputQueue = Collections.synchronizedList(new LinkedList<ChunkCoordIntPair>());
List<ChunkCoordIntPair> processingQueue = Collections.synchronizedList(new LinkedList<ChunkCoordIntPair>());
Packet56MapChunkBulk lastPacket;
CraftPlayer player;
Thread thread;
AtomicBoolean kill = new AtomicBoolean(false);
@SuppressWarnings({ "unchecked", "rawtypes" })
public ChunkQueue(CraftPlayer player, List previousEntries) {
this.player = player;
internalQueue.addAll(previousEntries);
}
@Override
public boolean remove(Object arg0) {
return internalQueue.remove(arg0) || processingQueue.remove(arg0) || outputQueue.remove(arg0);
}
// Called when the queue should be cleared
@Override
public void clear() {
// Clear the internal queue
internalQueue.clear();
super.clear();
}
// Called when new chunks are queued
@Override
public boolean add(ChunkCoordIntPair e) {
boolean result;
synchronized (internalQueue) {
result = internalQueue.add(e);
}
// Move everything into the internal queue
return result;
// return super.add(e);
}
// Called when the list should be sorted
@Override
public Object[] toArray() {
sort();
// Return the old array to be sorted
return internalQueue.toArray();
}
// This checks for chunks in the queue
@Override
public boolean contains(Object o) {
// Checks whether the coords are actually in
return internalQueue.contains(o) || processingQueue.contains(o);
}
@Override
public boolean isEmpty() {
try {
// If the player is gone, then don't waste time
if (player.getHandle().playerConnection.disconnected) {
// Cleanup all queues
synchronized (internalQueue) {
internalQueue.clear();
}
processingQueue.clear();
outputQueue.clear();
lastPacket = null;
}
else {
// Process outputs and inputs
processOutput();
processInput();
}
}
catch (Exception e) {
Orebfuscator.log(e);
}
return true;
}
public void sort() {
// Sort the internal array according to CB - See PlayerChunkMap.movePlayer(EntityPlayer entityplayer)
synchronized (internalQueue) {
java.util.Collections.sort(internalQueue, new ChunkCoordComparator(player.getHandle()));
}
}
@Override
public void FinishedProcessing(IPacket56 packet) {
if (lastPacket != null) {
player.getHandle().playerConnection.sendPacket(lastPacket);
// Remove reference to the packet so it can be freed when possible
lastPacket = null;
}
outputQueue.addAll(processingQueue);
processingQueue.clear();
}
private void processOutput() {
// Chunk packet finished processing, output relevant packets
while (!outputQueue.isEmpty()) {
// Get the chunk coordinate
ChunkCoordIntPair chunk = outputQueue.remove(0);
// Check if the chunk is ready
if (chunk != null && ((WorldServer) player.getHandle().world).isLoaded(chunk.x << 4, 0, chunk.z << 4)) {
// Get all the TileEntities in the chunk
@SuppressWarnings("rawtypes")
List tileEntities = ((WorldServer) player.getHandle().world).getTileEntities(chunk.x * 16, 0, chunk.z * 16, chunk.x * 16 + 16, 256, chunk.z * 16 + 16);
for (Object o : tileEntities) {
// Send out packet for the tile entity data
this.updateTileEntity((TileEntity) o);
}
// Start tracking entities in the chunk
((WorldServer) player.getHandle().world).getTracker().a(player.getHandle(), player.getHandle().world.getChunkAt(chunk.x, chunk.z));
}
}
}
private void processInput() {
// Queue next chunk packet out
if (processingQueue.isEmpty() && !internalQueue.isEmpty()) {
// Check if player's output queue has a lot of stuff waiting to be sent. If so, don't process and wait.
// Network queue limit is 2097152 bytes
// Each chunk packet with 5 chunks is about 10000 - 25000 bytes
// We'll allow the size of 3 packets to be queued = 75000 bytes
// Try-catch so as to not disrupt chunk sending if something fails
if (!Orebfuscator.useSpigot) {
try {
NetworkManager networkManager = (NetworkManager) player.getHandle().playerConnection.networkManager;
if (((int) (Integer) ReflectionHelper.getPrivateField(NetworkManager.class, networkManager, "z")) > 75000) {
return;
}
}
catch (Exception e) {
// e.printStackTrace();
}
}
// A list to queue chunks
List<Chunk> chunks = new LinkedList<Chunk>();
// Queue up to 5 chunks
synchronized (internalQueue) {
while (!internalQueue.isEmpty() && chunks.size() < 5) {
// Dequeue a chunk from input
ChunkCoordIntPair chunkcoordintpair = internalQueue.remove(0);
// If the chunk is loaded and not null
if (chunkcoordintpair != null && player.getHandle().world.isLoaded(chunkcoordintpair.x << 4, 0, chunkcoordintpair.z << 4)) {
// Queue the chunk for processing
processingQueue.add(chunkcoordintpair);
// Add the chunk to the list to create a packet
chunks.add(player.getHandle().world.getChunkAt(chunkcoordintpair.x, chunkcoordintpair.z));
}
}
}
// If there are chunks to process
if (!chunks.isEmpty()) {
// Create a packet wrapper
IPacket56 packet = InternalAccessor.Instance.newPacket56();
// Create the actual packet
lastPacket = new Packet56MapChunkBulk(chunks);
// Put into wrapper
packet.setPacket(lastPacket);
// Send to Processing Thread
ChunkProcessingThread.Queue(packet, player, this);
}
}
}
private void updateTileEntity(TileEntity tileentity) {
if (tileentity != null) {
Packet packet = tileentity.getUpdatePacket();
if (packet != null) {
player.getHandle().playerConnection.sendPacket(packet);
}
}
}
@Override
public ListIterator<ChunkCoordIntPair> listIterator() {
return new FakeIterator();
}
private class FakeIterator implements ListIterator<ChunkCoordIntPair> {
@Override
public boolean hasNext() {
return false;
}
@Override
public ChunkCoordIntPair next() {
return null;
}
@Override
public boolean hasPrevious() {
return false;
}
@Override
public ChunkCoordIntPair previous() {
return null;
}
@Override
public int nextIndex() {
return 0;
}
@Override
public int previousIndex() {
return 0;
}
@Override
public void remove() {}
@Override
public void set(ChunkCoordIntPair e) {}
@Override
public void add(ChunkCoordIntPair e) {}
}
private static class ChunkCoordComparator implements java.util.Comparator<ChunkCoordIntPair> {
private int x;
private int z;
public ChunkCoordComparator(EntityPlayer entityplayer) {
x = (int) entityplayer.locX >> 4;
z = (int) entityplayer.locZ >> 4;
}
public int compare(ChunkCoordIntPair a, ChunkCoordIntPair b) {
if (a.equals(b)) {
return 0;
}
// Subtract current position to set center point
int ax = a.x - this.x;
int az = a.z - this.z;
int bx = b.x - this.x;
int bz = b.z - this.z;
int result = ((ax - bx) * (ax + bx)) + ((az - bz) * (az + bz));
if (result != 0) {
return result;
}
if (ax < 0) {
if (bx < 0) {
return bz - az;
}
else {
return -1;
}
}
else {
if (bx < 0) {
return 1;
}
else {
return az - bz;
}
}
}
}
}

View File

@ -1,36 +0,0 @@
/*
* Copyright (C) 2011-2014 lishid. All rights reserved.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, version 3.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.lishid.orebfuscator.internal.v1_5_R3;
import com.lishid.orebfuscator.internal.IMinecraftWorldServer;
import com.lishid.orebfuscator.internal.InternalAccessor;
//Volatile
import net.minecraft.server.v1_5_R3.*;
import org.bukkit.craftbukkit.v1_5_R3.*;
public class MinecraftWorldServer implements IMinecraftWorldServer {
public void Notify(Object world, int x, int y, int z) {
if (world instanceof CraftWorld) {
WorldServer server = (WorldServer) ((CraftWorld) world).getHandle();
server.notify(x, y, z);
}
else {
InternalAccessor.Instance.PrintError();
}
}
}

View File

@ -1,95 +0,0 @@
/*
* Copyright (C) 2011-2014 lishid. All rights reserved.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, version 3.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.lishid.orebfuscator.internal.v1_5_R3;
import java.io.DataInput;
import java.io.DataOutput;
import com.lishid.orebfuscator.internal.INBT;
//Volatile
import net.minecraft.server.v1_5_R3.*;
public class NBT implements INBT {
NBTTagCompound nbt = new NBTTagCompound();
@Override
public void reset() {
nbt = new NBTTagCompound();
}
@Override
public void setInt(String tag, int value) {
nbt.setInt(tag, value);
}
@Override
public void setLong(String tag, long value) {
nbt.setLong(tag, value);
}
@Override
public void setBoolean(String tag, boolean value) {
nbt.setBoolean(tag, value);
}
@Override
public void setByteArray(String tag, byte[] value) {
nbt.setByteArray(tag, value);
}
@Override
public void setIntArray(String tag, int[] value) {
nbt.setIntArray(tag, value);
}
@Override
public int getInt(String tag) {
return nbt.getInt(tag);
}
@Override
public long getLong(String tag) {
return nbt.getLong(tag);
}
@Override
public boolean getBoolean(String tag) {
return nbt.getBoolean(tag);
}
@Override
public byte[] getByteArray(String tag) {
return nbt.getByteArray(tag);
}
@Override
public int[] getIntArray(String tag) {
return nbt.getIntArray(tag);
}
@Override
public void Read(DataInput stream) {
nbt = NBTCompressedStreamTools.a(stream);
}
@Override
public void Write(DataOutput stream) {
NBTCompressedStreamTools.a(nbt, stream);
}
}

View File

@ -1,48 +0,0 @@
/*
* Copyright (C) 2011-2014 lishid. All rights reserved.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, version 3.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.lishid.orebfuscator.internal.v1_5_R3;
import java.util.ArrayList;
import org.bukkit.entity.Player;
import com.lishid.orebfuscator.internal.IPacket51;
import com.lishid.orebfuscator.internal.InternalAccessor;
import com.lishid.orebfuscator.obfuscation.Calculations;
//Volatile
import net.minecraft.server.v1_5_R3.*;
public class NetworkQueue extends ArrayList<Packet> {
private static final long serialVersionUID = 4252847662044263527L;
private Player player;
public NetworkQueue(Player player) {
this.player = player;
}
@Override
public boolean add(Packet packet) {
if (packet.n() == 51) {
IPacket51 packet51 = InternalAccessor.Instance.newPacket51();
packet51.setPacket(packet);
Calculations.Obfuscate(packet51, this.player);
}
return super.add(packet);
}
}

View File

@ -1,18 +0,0 @@
package com.lishid.orebfuscator.internal.v1_5_R3;
import com.lishid.orebfuscator.hithack.BlockHitManager;
import net.minecraft.server.v1_5_R3.*;
public class Packet14Orebfuscator extends Packet14BlockDig {
@Override
public void handle(Connection handler) {
if (this.e == 1 && handler instanceof PlayerConnection) {
boolean canHit = BlockHitManager.hitBlock(((PlayerConnection) handler).getPlayer(), null);
if (!canHit) {
return;
}
}
super.handle(handler);
}
}

View File

@ -1,82 +0,0 @@
/*
* Copyright (C) 2011-2014 lishid. All rights reserved.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, version 3.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.lishid.orebfuscator.internal.v1_5_R3;
import java.util.zip.Deflater;
import com.lishid.orebfuscator.internal.IPacket51;
import com.lishid.orebfuscator.internal.InternalAccessor;
import com.lishid.orebfuscator.utils.ReflectionHelper;
//Volatile
import net.minecraft.server.v1_5_R3.*;
public class Packet51 implements IPacket51 {
private static Class<? extends Object> packetClass = Packet51MapChunk.class;
Packet51MapChunk packet;
@Override
public void setPacket(Object packet) {
if (packet instanceof Packet51MapChunk) {
this.packet = (Packet51MapChunk) packet;
}
else {
InternalAccessor.Instance.PrintError();
}
}
@Override
public int getX() {
return packet.a;
}
@Override
public int getZ() {
return packet.b;
}
@Override
public int getChunkMask() {
return packet.c;
}
@Override
public int getExtraMask() {
return packet.d;
}
@Override
public byte[] getBuffer() {
return (byte[]) ReflectionHelper.getPrivateField(packetClass, packet, "inflatedBuffer");
}
private byte[] getOutputBuffer() {
return (byte[]) ReflectionHelper.getPrivateField(packetClass, packet, "buffer");
}
@Override
public void compress(Deflater deflater) {
byte[] chunkInflatedBuffer = getBuffer();
byte[] chunkBuffer = getOutputBuffer();
deflater.reset();
deflater.setInput(chunkInflatedBuffer, 0, chunkInflatedBuffer.length);
deflater.finish();
ReflectionHelper.setPrivateField(packetClass, packet, "size", deflater.deflate(chunkBuffer));
}
}

View File

@ -1,115 +0,0 @@
/*
* Copyright (C) 2011-2014 lishid. All rights reserved.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, version 3.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.lishid.orebfuscator.internal.v1_5_R3;
import java.util.zip.Deflater;
import com.lishid.orebfuscator.commands.OrebfuscatorCommandExecutor;
import com.lishid.orebfuscator.internal.IPacket56;
import com.lishid.orebfuscator.internal.InternalAccessor;
import com.lishid.orebfuscator.utils.ReflectionHelper;
//Volatile
import net.minecraft.server.v1_5_R3.*;
public class Packet56 implements IPacket56 {
Packet56MapChunkBulk packet;
@Override
public void setPacket(Object packet) {
if (packet instanceof Packet56MapChunkBulk) {
this.packet = (Packet56MapChunkBulk) packet;
}
else {
InternalAccessor.Instance.PrintError();
}
}
@Override
public int getPacketChunkNumber() {
return packet.d();
}
@Override
public int[] getX() {
return (int[]) ReflectionHelper.getPrivateField(packet, "c");
}
@Override
public int[] getZ() {
return (int[]) ReflectionHelper.getPrivateField(packet, "d");
}
@Override
public int[] getChunkMask() {
return packet.a;
}
@Override
public int[] getExtraMask() {
return packet.b;
}
@Override
public Object getFieldData(String field) {
return ReflectionHelper.getPrivateField(Packet56MapChunkBulk.class, packet, field);
}
@Override
public void setFieldData(String field, Object data) {
ReflectionHelper.setPrivateField(Packet56MapChunkBulk.class, packet, field, data);
}
public String getInflatedBuffers() {
return "inflatedBuffers";
}
public String getBuildBuffer() {
return "buildBuffer";
}
public String getOutputBuffer() {
return "buffer";
}
@Override
public void compress(Deflater deflater) {
if (getFieldData(getOutputBuffer()) != null) {
return;
}
byte[] buildBuffer = (byte[]) getFieldData(getBuildBuffer());
deflater.reset();
deflater.setInput(buildBuffer);
deflater.finish();
byte[] buffer = new byte[buildBuffer.length + 100];
ReflectionHelper.setPrivateField(packet, "buffer", buffer);
int size = deflater.deflate(buffer);
ReflectionHelper.setPrivateField(packet, "size", size);
// Free memory
ReflectionHelper.setPrivateField(packet, "buildBuffer", null);
ReflectionHelper.setPrivateField(packet, "inflatedBuffers", null);
if (OrebfuscatorCommandExecutor.DebugMode) {
System.out.println("Packet size: " + size);
}
}
}

View File

@ -1,95 +0,0 @@
/*
* Copyright (C) 2011-2014 lishid. All rights reserved.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, version 3.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.lishid.orebfuscator.internal.v1_5_R3;
import java.lang.reflect.Field;
import java.util.Collections;
import java.util.Map;
import java.util.List;
import com.lishid.orebfuscator.Orebfuscator;
import com.lishid.orebfuscator.internal.IPlayerHook;
import com.lishid.orebfuscator.utils.ReflectionHelper;
import org.bukkit.entity.Player;
//Volatile
import net.minecraft.server.v1_5_R3.*;
import org.bukkit.craftbukkit.v1_5_R3.entity.*;
public class PlayerHook implements IPlayerHook {
@SuppressWarnings("unchecked")
public void HookNM(Player p) {
CraftPlayer player = (CraftPlayer) p;
// Update NetworkManager's lists
NetworkManager networkManager = (NetworkManager) player.getHandle().playerConnection.networkManager;
Field[] networkFields = networkManager.getClass().getDeclaredFields();
for (Field field : networkFields) {
try {
if (List.class.isAssignableFrom(field.getType())) {
List<Packet> list = new NetworkQueue(p);
field.setAccessible(true);
List<Packet> oldList = (List<Packet>) field.get(networkManager);
// Move packets to new list
synchronized (ReflectionHelper.getPrivateField(networkManager, "h")) {
list.addAll(oldList);
oldList.clear();
}
// Replace with new list
field.set(networkManager, Collections.synchronizedList(list));
}
}
catch (Exception e) {
Orebfuscator.log(e);
}
}
hookPacket();
}
static boolean hookPacket = false;
@SuppressWarnings("unchecked")
private void hookPacket() {
if (hookPacket)
return;
hookPacket = true;
Packet.l.a(14, Packet14Orebfuscator.class);
// Use reflection to add into a and c
Field[] packetFields = Packet.class.getDeclaredFields();
for (Field field : packetFields) {
try {
if (Map.class.isAssignableFrom(field.getType())) {
field.setAccessible(true);
@SuppressWarnings({ "rawtypes" })
Map packets = (Map) field.get(null);
packets.put(Packet14Orebfuscator.class, 14);
}
}
catch (Exception e) {
Orebfuscator.log(e);
}
}
}
public void HookChunkQueue(Player p) {
CraftPlayer player = (CraftPlayer) p;
ReflectionHelper.setPrivateFinal(player.getHandle(), "chunkCoordIntPairQueue", new ChunkQueue(player, player.getHandle().chunkCoordIntPairQueue));
}
}

View File

@ -1,46 +0,0 @@
/*
* Copyright (C) 2011-2014 lishid. All rights reserved.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, version 3.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.lishid.orebfuscator.internal.v1_6_R1;
import com.lishid.orebfuscator.internal.IBlockAccess;
import org.bukkit.entity.Player;
//Volatile
import net.minecraft.server.v1_6_R1.*;
import org.bukkit.craftbukkit.v1_6_R1.entity.*;
import org.bukkit.craftbukkit.v1_6_R1.*;
public class BlockAccess implements IBlockAccess {
@Override
public boolean isBlockTransparent(int id) {
return !Block.l(id);
}
@Override
public void updateBlockTileEntity(org.bukkit.block.Block block, Player player) {
CraftWorld world = (CraftWorld) block.getWorld();
TileEntity tileEntity = world.getTileEntityAt(block.getX(), block.getY(), block.getZ());
if (tileEntity == null) {
return;
}
Packet packet = tileEntity.getUpdatePacket();
if (packet != null) {
CraftPlayer player2 = (CraftPlayer) player;
player2.getHandle().playerConnection.sendPacket(packet);
}
}
}

View File

@ -1,92 +0,0 @@
/*
* Copyright (C) 2011-2014 lishid. All rights reserved.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, version 3.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.lishid.orebfuscator.internal.v1_6_R1;
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.File;
import java.util.HashMap;
import com.lishid.orebfuscator.Orebfuscator;
import com.lishid.orebfuscator.OrebfuscatorConfig;
import com.lishid.orebfuscator.internal.IChunkCache;
//Volatile
import net.minecraft.server.v1_6_R1.*;
public class ChunkCache implements IChunkCache {
private static final HashMap<File, RegionFile> cachedRegionFiles = new HashMap<File, RegionFile>();
private synchronized RegionFile getRegionFile(File folder, int x, int z) {
File path = new File(folder, "region");
File file = new File(path, "r." + (x >> 5) + "." + (z >> 5) + ".mcr");
try {
RegionFile regionFile = cachedRegionFiles.get(file);
if (regionFile != null) {
return regionFile;
}
if (!path.exists()) {
path.mkdirs();
}
if (cachedRegionFiles.size() >= OrebfuscatorConfig.MaxLoadedCacheFiles) {
clearCache();
}
regionFile = new RegionFile(file);
cachedRegionFiles.put(file, regionFile);
return regionFile;
}
catch (Exception e) {
try {
file.delete();
}
catch (Exception e2) {
Orebfuscator.log(e);
}
}
return null;
}
@Override
public DataInputStream getInputStream(File folder, int x, int z) {
RegionFile regionFile = getRegionFile(folder, x, z);
return regionFile.a(x & 0x1F, z & 0x1F);
}
@Override
public DataOutputStream getOutputStream(File folder, int x, int z) {
RegionFile regionFile = getRegionFile(folder, x, z);
return regionFile.b(x & 0x1F, z & 0x1F);
}
@Override
public synchronized void clearCache() {
for (RegionFile regionFile : cachedRegionFiles.values()) {
try {
if (regionFile != null)
regionFile.c();
}
catch (Exception e) {
e.printStackTrace();
}
}
cachedRegionFiles.clear();
}
}

View File

@ -1,318 +0,0 @@
/*
* Copyright (C) 2011-2014 lishid. All rights reserved.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, version 3.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.lishid.orebfuscator.internal.v1_6_R1;
import java.util.Collections;
import java.util.LinkedList;
import java.util.List;
import java.util.ListIterator;
import java.util.concurrent.atomic.AtomicBoolean;
import com.lishid.orebfuscator.Orebfuscator;
import com.lishid.orebfuscator.hook.ChunkProcessingThread;
import com.lishid.orebfuscator.internal.IChunkQueue;
import com.lishid.orebfuscator.internal.IPacket56;
import com.lishid.orebfuscator.internal.InternalAccessor;
import com.lishid.orebfuscator.utils.ReflectionHelper;
//Volatile
import net.minecraft.server.v1_6_R1.*;
import org.bukkit.craftbukkit.v1_6_R1.entity.*;
public class ChunkQueue extends LinkedList<ChunkCoordIntPair> implements IChunkQueue {
private static final long serialVersionUID = -1928681564741152336L;
List<ChunkCoordIntPair> internalQueue = Collections.synchronizedList(new LinkedList<ChunkCoordIntPair>());
List<ChunkCoordIntPair> outputQueue = Collections.synchronizedList(new LinkedList<ChunkCoordIntPair>());
List<ChunkCoordIntPair> processingQueue = Collections.synchronizedList(new LinkedList<ChunkCoordIntPair>());
Packet56MapChunkBulk lastPacket;
CraftPlayer player;
Thread thread;
AtomicBoolean kill = new AtomicBoolean(false);
@SuppressWarnings({ "unchecked", "rawtypes" })
public ChunkQueue(CraftPlayer player, List previousEntries) {
this.player = player;
internalQueue.addAll(previousEntries);
}
@Override
public boolean remove(Object arg0) {
return internalQueue.remove(arg0) || processingQueue.remove(arg0) || outputQueue.remove(arg0);
}
// Called when the queue should be cleared
@Override
public void clear() {
// Clear the internal queue
internalQueue.clear();
super.clear();
}
// Called when new chunks are queued
@Override
public boolean add(ChunkCoordIntPair e) {
boolean result;
synchronized (internalQueue) {
result = internalQueue.add(e);
}
// Move everything into the internal queue
return result;
// return super.add(e);
}
// Called when the list should be sorted
@Override
public Object[] toArray() {
sort();
// Return the old array to be sorted
return internalQueue.toArray();
}
// This checks for chunks in the queue
@Override
public boolean contains(Object o) {
// Checks whether the coords are actually in
return internalQueue.contains(o) || processingQueue.contains(o);
}
@Override
public boolean isEmpty() {
try {
// If the player is gone, then don't waste time
if (player.getHandle().playerConnection.disconnected) {
// Cleanup all queues
synchronized (internalQueue) {
internalQueue.clear();
}
processingQueue.clear();
outputQueue.clear();
lastPacket = null;
}
else {
// Process outputs and inputs
processOutput();
processInput();
}
}
catch (Exception e) {
Orebfuscator.log(e);
}
return true;
}
public void sort() {
// Sort the internal array according to CB - See PlayerChunkMap.movePlayer(EntityPlayer entityplayer)
synchronized (internalQueue) {
java.util.Collections.sort(internalQueue, new ChunkCoordComparator(player.getHandle()));
}
}
@Override
public void FinishedProcessing(IPacket56 packet) {
if (lastPacket != null) {
player.getHandle().playerConnection.sendPacket(lastPacket);
// Remove reference to the packet so it can be freed when possible
lastPacket = null;
}
outputQueue.addAll(processingQueue);
processingQueue.clear();
}
private void processOutput() {
// Chunk packet finished processing, output relevant packets
while (!outputQueue.isEmpty()) {
// Get the chunk coordinate
ChunkCoordIntPair chunk = outputQueue.remove(0);
// Check if the chunk is ready
if (chunk != null && ((WorldServer) player.getHandle().world).isLoaded(chunk.x << 4, 0, chunk.z << 4)) {
// Get all the TileEntities in the chunk
@SuppressWarnings("rawtypes")
List tileEntities = ((WorldServer) player.getHandle().world).getTileEntities(chunk.x * 16, 0, chunk.z * 16, chunk.x * 16 + 16, 256, chunk.z * 16 + 16);
for (Object o : tileEntities) {
// Send out packet for the tile entity data
this.updateTileEntity((TileEntity) o);
}
// Start tracking entities in the chunk
((WorldServer) player.getHandle().world).getTracker().a(player.getHandle(), player.getHandle().world.getChunkAt(chunk.x, chunk.z));
}
}
}
private void processInput() {
// Queue next chunk packet out
if (processingQueue.isEmpty() && !internalQueue.isEmpty()) {
// Check if player's output queue has a lot of stuff waiting to be sent. If so, don't process and wait.
// Network queue limit is 2097152 bytes
// Each chunk packet with 5 chunks is about 10000 - 25000 bytes
// We'll allow the size of 3 packets to be queued = 75000 bytes
// Try-catch so as to not disrupt chunk sending if something fails
if (!Orebfuscator.useSpigot) {
try {
NetworkManager networkManager = (NetworkManager) player.getHandle().playerConnection.networkManager;
if (((int) (Integer) ReflectionHelper.getPrivateField(NetworkManager.class, networkManager, "z")) > 75000) {
return;
}
}
catch (Exception e) {
// e.printStackTrace();
}
}
// A list to queue chunks
List<Chunk> chunks = new LinkedList<Chunk>();
// Queue up to 5 chunks
synchronized (internalQueue) {
while (!internalQueue.isEmpty() && chunks.size() < 5) {
// Dequeue a chunk from input
ChunkCoordIntPair chunkcoordintpair = internalQueue.remove(0);
// If the chunk is loaded and not null
if (chunkcoordintpair != null && player.getHandle().world.isLoaded(chunkcoordintpair.x << 4, 0, chunkcoordintpair.z << 4)) {
// Queue the chunk for processing
processingQueue.add(chunkcoordintpair);
// Add the chunk to the list to create a packet
chunks.add(player.getHandle().world.getChunkAt(chunkcoordintpair.x, chunkcoordintpair.z));
}
}
}
// If there are chunks to process
if (!chunks.isEmpty()) {
// Create a packet wrapper
IPacket56 packet = InternalAccessor.Instance.newPacket56();
// Create the actual packet
lastPacket = new Packet56MapChunkBulk(chunks);
// Put into wrapper
packet.setPacket(lastPacket);
// Send to Processing Thread
ChunkProcessingThread.Queue(packet, player, this);
}
}
}
private void updateTileEntity(TileEntity tileentity) {
if (tileentity != null) {
Packet packet = tileentity.getUpdatePacket();
if (packet != null) {
player.getHandle().playerConnection.sendPacket(packet);
}
}
}
@Override
public ListIterator<ChunkCoordIntPair> listIterator() {
return new FakeIterator();
}
private class FakeIterator implements ListIterator<ChunkCoordIntPair> {
@Override
public boolean hasNext() {
return false;
}
@Override
public ChunkCoordIntPair next() {
return null;
}
@Override
public boolean hasPrevious() {
return false;
}
@Override
public ChunkCoordIntPair previous() {
return null;
}
@Override
public int nextIndex() {
return 0;
}
@Override
public int previousIndex() {
return 0;
}
@Override
public void remove() {}
@Override
public void set(ChunkCoordIntPair e) {}
@Override
public void add(ChunkCoordIntPair e) {}
}
private static class ChunkCoordComparator implements java.util.Comparator<ChunkCoordIntPair> {
private int x;
private int z;
public ChunkCoordComparator(EntityPlayer entityplayer) {
x = (int) entityplayer.locX >> 4;
z = (int) entityplayer.locZ >> 4;
}
public int compare(ChunkCoordIntPair a, ChunkCoordIntPair b) {
if (a.equals(b)) {
return 0;
}
// Subtract current position to set center point
int ax = a.x - this.x;
int az = a.z - this.z;
int bx = b.x - this.x;
int bz = b.z - this.z;
int result = ((ax - bx) * (ax + bx)) + ((az - bz) * (az + bz));
if (result != 0) {
return result;
}
if (ax < 0) {
if (bx < 0) {
return bz - az;
}
else {
return -1;
}
}
else {
if (bx < 0) {
return 1;
}
else {
return az - bz;
}
}
}
}
}

View File

@ -1,36 +0,0 @@
/*
* Copyright (C) 2011-2014 lishid. All rights reserved.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, version 3.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.lishid.orebfuscator.internal.v1_6_R1;
import com.lishid.orebfuscator.internal.IMinecraftWorldServer;
import com.lishid.orebfuscator.internal.InternalAccessor;
//Volatile
import net.minecraft.server.v1_6_R1.*;
import org.bukkit.craftbukkit.v1_6_R1.*;
public class MinecraftWorldServer implements IMinecraftWorldServer {
public void Notify(Object world, int x, int y, int z) {
if (world instanceof CraftWorld) {
WorldServer server = (WorldServer) ((CraftWorld) world).getHandle();
server.notify(x, y, z);
}
else {
InternalAccessor.Instance.PrintError();
}
}
}

View File

@ -1,95 +0,0 @@
/*
* Copyright (C) 2011-2014 lishid. All rights reserved.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, version 3.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.lishid.orebfuscator.internal.v1_6_R1;
import java.io.DataInput;
import java.io.DataOutput;
import com.lishid.orebfuscator.internal.INBT;
//Volatile
import net.minecraft.server.v1_6_R1.*;
public class NBT implements INBT {
NBTTagCompound nbt = new NBTTagCompound();
@Override
public void reset() {
nbt = new NBTTagCompound();
}
@Override
public void setInt(String tag, int value) {
nbt.setInt(tag, value);
}
@Override
public void setLong(String tag, long value) {
nbt.setLong(tag, value);
}
@Override
public void setBoolean(String tag, boolean value) {
nbt.setBoolean(tag, value);
}
@Override
public void setByteArray(String tag, byte[] value) {
nbt.setByteArray(tag, value);
}
@Override
public void setIntArray(String tag, int[] value) {
nbt.setIntArray(tag, value);
}
@Override
public int getInt(String tag) {
return nbt.getInt(tag);
}
@Override
public long getLong(String tag) {
return nbt.getLong(tag);
}
@Override
public boolean getBoolean(String tag) {
return nbt.getBoolean(tag);
}
@Override
public byte[] getByteArray(String tag) {
return nbt.getByteArray(tag);
}
@Override
public int[] getIntArray(String tag) {
return nbt.getIntArray(tag);
}
@Override
public void Read(DataInput stream) {
nbt = NBTCompressedStreamTools.a(stream);
}
@Override
public void Write(DataOutput stream) {
NBTCompressedStreamTools.a(nbt, stream);
}
}

View File

@ -1,48 +0,0 @@
/*
* Copyright (C) 2011-2014 lishid. All rights reserved.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, version 3.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.lishid.orebfuscator.internal.v1_6_R1;
import java.util.ArrayList;
import org.bukkit.entity.Player;
import com.lishid.orebfuscator.internal.IPacket51;
import com.lishid.orebfuscator.internal.InternalAccessor;
import com.lishid.orebfuscator.obfuscation.Calculations;
//Volatile
import net.minecraft.server.v1_6_R1.*;
public class NetworkQueue extends ArrayList<Packet> {
private static final long serialVersionUID = 4252847662044263527L;
private Player player;
public NetworkQueue(Player player) {
this.player = player;
}
@Override
public boolean add(Packet packet) {
if (packet.n() == 51) {
IPacket51 packet51 = InternalAccessor.Instance.newPacket51();
packet51.setPacket(packet);
Calculations.Obfuscate(packet51, this.player);
}
return super.add(packet);
}
}

View File

@ -1,18 +0,0 @@
package com.lishid.orebfuscator.internal.v1_6_R1;
import com.lishid.orebfuscator.hithack.BlockHitManager;
import net.minecraft.server.v1_6_R1.*;
public class Packet14Orebfuscator extends Packet14BlockDig {
@Override
public void handle(Connection handler) {
if (this.e == 1 && handler instanceof PlayerConnection) {
boolean canHit = BlockHitManager.hitBlock(((PlayerConnection) handler).getPlayer(), null);
if (!canHit) {
return;
}
}
super.handle(handler);
}
}

View File

@ -1,82 +0,0 @@
/*
* Copyright (C) 2011-2014 lishid. All rights reserved.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, version 3.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.lishid.orebfuscator.internal.v1_6_R1;
import java.util.zip.Deflater;
import com.lishid.orebfuscator.internal.IPacket51;
import com.lishid.orebfuscator.internal.InternalAccessor;
import com.lishid.orebfuscator.utils.ReflectionHelper;
//Volatile
import net.minecraft.server.v1_6_R1.*;
public class Packet51 implements IPacket51 {
private static Class<? extends Object> packetClass = Packet51MapChunk.class;
Packet51MapChunk packet;
@Override
public void setPacket(Object packet) {
if (packet instanceof Packet51MapChunk) {
this.packet = (Packet51MapChunk) packet;
}
else {
InternalAccessor.Instance.PrintError();
}
}
@Override
public int getX() {
return packet.a;
}
@Override
public int getZ() {
return packet.b;
}
@Override
public int getChunkMask() {
return packet.c;
}
@Override
public int getExtraMask() {
return packet.d;
}
@Override
public byte[] getBuffer() {
return (byte[]) ReflectionHelper.getPrivateField(packetClass, packet, "inflatedBuffer");
}
private byte[] getOutputBuffer() {
return (byte[]) ReflectionHelper.getPrivateField(packetClass, packet, "buffer");
}
@Override
public void compress(Deflater deflater) {
byte[] chunkInflatedBuffer = getBuffer();
byte[] chunkBuffer = getOutputBuffer();
deflater.reset();
deflater.setInput(chunkInflatedBuffer, 0, chunkInflatedBuffer.length);
deflater.finish();
ReflectionHelper.setPrivateField(packetClass, packet, "size", deflater.deflate(chunkBuffer));
}
}

View File

@ -1,115 +0,0 @@
/*
* Copyright (C) 2011-2014 lishid. All rights reserved.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, version 3.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.lishid.orebfuscator.internal.v1_6_R1;
import java.util.zip.Deflater;
import com.lishid.orebfuscator.commands.OrebfuscatorCommandExecutor;
import com.lishid.orebfuscator.internal.IPacket56;
import com.lishid.orebfuscator.internal.InternalAccessor;
import com.lishid.orebfuscator.utils.ReflectionHelper;
//Volatile
import net.minecraft.server.v1_6_R1.*;
public class Packet56 implements IPacket56 {
Packet56MapChunkBulk packet;
@Override
public void setPacket(Object packet) {
if (packet instanceof Packet56MapChunkBulk) {
this.packet = (Packet56MapChunkBulk) packet;
}
else {
InternalAccessor.Instance.PrintError();
}
}
@Override
public int getPacketChunkNumber() {
return packet.d();
}
@Override
public int[] getX() {
return (int[]) ReflectionHelper.getPrivateField(packet, "c");
}
@Override
public int[] getZ() {
return (int[]) ReflectionHelper.getPrivateField(packet, "d");
}
@Override
public int[] getChunkMask() {
return packet.a;
}
@Override
public int[] getExtraMask() {
return packet.b;
}
@Override
public Object getFieldData(String field) {
return ReflectionHelper.getPrivateField(Packet56MapChunkBulk.class, packet, field);
}
@Override
public void setFieldData(String field, Object data) {
ReflectionHelper.setPrivateField(Packet56MapChunkBulk.class, packet, field, data);
}
public String getInflatedBuffers() {
return "inflatedBuffers";
}
public String getBuildBuffer() {
return "buildBuffer";
}
public String getOutputBuffer() {
return "buffer";
}
@Override
public void compress(Deflater deflater) {
if (getFieldData(getOutputBuffer()) != null) {
return;
}
byte[] buildBuffer = (byte[]) getFieldData(getBuildBuffer());
deflater.reset();
deflater.setInput(buildBuffer);
deflater.finish();
byte[] buffer = new byte[buildBuffer.length + 100];
ReflectionHelper.setPrivateField(packet, "buffer", buffer);
int size = deflater.deflate(buffer);
ReflectionHelper.setPrivateField(packet, "size", size);
// Free memory
ReflectionHelper.setPrivateField(packet, "buildBuffer", null);
ReflectionHelper.setPrivateField(packet, "inflatedBuffers", null);
if (OrebfuscatorCommandExecutor.DebugMode) {
System.out.println("Packet size: " + size);
}
}
}

View File

@ -1,95 +0,0 @@
/*
* Copyright (C) 2011-2014 lishid. All rights reserved.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, version 3.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.lishid.orebfuscator.internal.v1_6_R1;
import java.lang.reflect.Field;
import java.util.Collections;
import java.util.Map;
import java.util.List;
import com.lishid.orebfuscator.Orebfuscator;
import com.lishid.orebfuscator.internal.IPlayerHook;
import com.lishid.orebfuscator.utils.ReflectionHelper;
import org.bukkit.entity.Player;
//Volatile
import net.minecraft.server.v1_6_R1.*;
import org.bukkit.craftbukkit.v1_6_R1.entity.*;
public class PlayerHook implements IPlayerHook {
@SuppressWarnings("unchecked")
public void HookNM(Player p) {
CraftPlayer player = (CraftPlayer) p;
// Update NetworkManager's lists
NetworkManager networkManager = (NetworkManager) player.getHandle().playerConnection.networkManager;
Field[] networkFields = networkManager.getClass().getDeclaredFields();
for (Field field : networkFields) {
try {
if (List.class.isAssignableFrom(field.getType())) {
List<Packet> list = new NetworkQueue(p);
field.setAccessible(true);
List<Packet> oldList = (List<Packet>) field.get(networkManager);
// Move packets to new list
synchronized (ReflectionHelper.getPrivateField(networkManager, "h")) {
list.addAll(oldList);
oldList.clear();
}
// Replace with new list
field.set(networkManager, Collections.synchronizedList(list));
}
}
catch (Exception e) {
Orebfuscator.log(e);
}
}
hookPacket();
}
static boolean hookPacket = false;
@SuppressWarnings("unchecked")
private void hookPacket() {
if (hookPacket)
return;
hookPacket = true;
Packet.l.a(14, Packet14Orebfuscator.class);
// Use reflection to add into a and c
Field[] packetFields = Packet.class.getDeclaredFields();
for (Field field : packetFields) {
try {
if (Map.class.isAssignableFrom(field.getType())) {
field.setAccessible(true);
@SuppressWarnings({ "rawtypes" })
Map packets = (Map) field.get(null);
packets.put(Packet14Orebfuscator.class, 14);
}
}
catch (Exception e) {
Orebfuscator.log(e);
}
}
}
public void HookChunkQueue(Player p) {
CraftPlayer player = (CraftPlayer) p;
ReflectionHelper.setPrivateFinal(player.getHandle(), "chunkCoordIntPairQueue", new ChunkQueue(player, player.getHandle().chunkCoordIntPairQueue));
}
}

View File

@ -1,46 +0,0 @@
/*
* Copyright (C) 2011-2014 lishid. All rights reserved.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, version 3.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.lishid.orebfuscator.internal.v1_6_R2;
import com.lishid.orebfuscator.internal.IBlockAccess;
import org.bukkit.entity.Player;
//Volatile
import net.minecraft.server.v1_6_R2.*;
import org.bukkit.craftbukkit.v1_6_R2.entity.*;
import org.bukkit.craftbukkit.v1_6_R2.*;
public class BlockAccess implements IBlockAccess {
@Override
public boolean isBlockTransparent(int id) {
return !Block.l(id);
}
@Override
public void updateBlockTileEntity(org.bukkit.block.Block block, Player player) {
CraftWorld world = (CraftWorld) block.getWorld();
TileEntity tileEntity = world.getTileEntityAt(block.getX(), block.getY(), block.getZ());
if (tileEntity == null) {
return;
}
Packet packet = tileEntity.getUpdatePacket();
if (packet != null) {
CraftPlayer player2 = (CraftPlayer) player;
player2.getHandle().playerConnection.sendPacket(packet);
}
}
}

View File

@ -1,92 +0,0 @@
/*
* Copyright (C) 2011-2014 lishid. All rights reserved.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, version 3.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.lishid.orebfuscator.internal.v1_6_R2;
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.File;
import java.util.HashMap;
import com.lishid.orebfuscator.Orebfuscator;
import com.lishid.orebfuscator.OrebfuscatorConfig;
import com.lishid.orebfuscator.internal.IChunkCache;
//Volatile
import net.minecraft.server.v1_6_R2.*;
public class ChunkCache implements IChunkCache {
private static final HashMap<File, RegionFile> cachedRegionFiles = new HashMap<File, RegionFile>();
private synchronized RegionFile getRegionFile(File folder, int x, int z) {
File path = new File(folder, "region");
File file = new File(path, "r." + (x >> 5) + "." + (z >> 5) + ".mcr");
try {
RegionFile regionFile = cachedRegionFiles.get(file);
if (regionFile != null) {
return regionFile;
}
if (!path.exists()) {
path.mkdirs();
}
if (cachedRegionFiles.size() >= OrebfuscatorConfig.MaxLoadedCacheFiles) {
clearCache();
}
regionFile = new RegionFile(file);
cachedRegionFiles.put(file, regionFile);
return regionFile;
}
catch (Exception e) {
try {
file.delete();
}
catch (Exception e2) {
Orebfuscator.log(e);
}
}
return null;
}
@Override
public DataInputStream getInputStream(File folder, int x, int z) {
RegionFile regionFile = getRegionFile(folder, x, z);
return regionFile.a(x & 0x1F, z & 0x1F);
}
@Override
public DataOutputStream getOutputStream(File folder, int x, int z) {
RegionFile regionFile = getRegionFile(folder, x, z);
return regionFile.b(x & 0x1F, z & 0x1F);
}
@Override
public synchronized void clearCache() {
for (RegionFile regionFile : cachedRegionFiles.values()) {
try {
if (regionFile != null)
regionFile.c();
}
catch (Exception e) {
e.printStackTrace();
}
}
cachedRegionFiles.clear();
}
}

View File

@ -1,318 +0,0 @@
/*
* Copyright (C) 2011-2014 lishid. All rights reserved.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, version 3.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.lishid.orebfuscator.internal.v1_6_R2;
import java.util.Collections;
import java.util.LinkedList;
import java.util.List;
import java.util.ListIterator;
import java.util.concurrent.atomic.AtomicBoolean;
import com.lishid.orebfuscator.Orebfuscator;
import com.lishid.orebfuscator.hook.ChunkProcessingThread;
import com.lishid.orebfuscator.internal.IChunkQueue;
import com.lishid.orebfuscator.internal.IPacket56;
import com.lishid.orebfuscator.internal.InternalAccessor;
import com.lishid.orebfuscator.utils.ReflectionHelper;
//Volatile
import net.minecraft.server.v1_6_R2.*;
import org.bukkit.craftbukkit.v1_6_R2.entity.*;
public class ChunkQueue extends LinkedList<ChunkCoordIntPair> implements IChunkQueue {
private static final long serialVersionUID = -1928681564741152336L;
List<ChunkCoordIntPair> internalQueue = Collections.synchronizedList(new LinkedList<ChunkCoordIntPair>());
List<ChunkCoordIntPair> outputQueue = Collections.synchronizedList(new LinkedList<ChunkCoordIntPair>());
List<ChunkCoordIntPair> processingQueue = Collections.synchronizedList(new LinkedList<ChunkCoordIntPair>());
Packet56MapChunkBulk lastPacket;
CraftPlayer player;
Thread thread;
AtomicBoolean kill = new AtomicBoolean(false);
@SuppressWarnings({ "unchecked", "rawtypes" })
public ChunkQueue(CraftPlayer player, List previousEntries) {
this.player = player;
internalQueue.addAll(previousEntries);
}
@Override
public boolean remove(Object arg0) {
return internalQueue.remove(arg0) || processingQueue.remove(arg0) || outputQueue.remove(arg0);
}
// Called when the queue should be cleared
@Override
public void clear() {
// Clear the internal queue
internalQueue.clear();
super.clear();
}
// Called when new chunks are queued
@Override
public boolean add(ChunkCoordIntPair e) {
boolean result;
synchronized (internalQueue) {
result = internalQueue.add(e);
}
// Move everything into the internal queue
return result;
// return super.add(e);
}
// Called when the list should be sorted
@Override
public Object[] toArray() {
sort();
// Return the old array to be sorted
return internalQueue.toArray();
}
// This checks for chunks in the queue
@Override
public boolean contains(Object o) {
// Checks whether the coords are actually in
return internalQueue.contains(o) || processingQueue.contains(o);
}
@Override
public boolean isEmpty() {
try {
// If the player is gone, then don't waste time
if (player.getHandle().playerConnection.disconnected) {
// Cleanup all queues
synchronized (internalQueue) {
internalQueue.clear();
}
processingQueue.clear();
outputQueue.clear();
lastPacket = null;
}
else {
// Process outputs and inputs
processOutput();
processInput();
}
}
catch (Exception e) {
Orebfuscator.log(e);
}
return true;
}
public void sort() {
// Sort the internal array according to CB - See PlayerChunkMap.movePlayer(EntityPlayer entityplayer)
synchronized (internalQueue) {
java.util.Collections.sort(internalQueue, new ChunkCoordComparator(player.getHandle()));
}
}
@Override
public void FinishedProcessing(IPacket56 packet) {
if (lastPacket != null) {
player.getHandle().playerConnection.sendPacket(lastPacket);
// Remove reference to the packet so it can be freed when possible
lastPacket = null;
}
outputQueue.addAll(processingQueue);
processingQueue.clear();
}
private void processOutput() {
// Chunk packet finished processing, output relevant packets
while (!outputQueue.isEmpty()) {
// Get the chunk coordinate
ChunkCoordIntPair chunk = outputQueue.remove(0);
// Check if the chunk is ready
if (chunk != null && ((WorldServer) player.getHandle().world).isLoaded(chunk.x << 4, 0, chunk.z << 4)) {
// Get all the TileEntities in the chunk
@SuppressWarnings("rawtypes")
List tileEntities = ((WorldServer) player.getHandle().world).getTileEntities(chunk.x * 16, 0, chunk.z * 16, chunk.x * 16 + 16, 256, chunk.z * 16 + 16);
for (Object o : tileEntities) {
// Send out packet for the tile entity data
this.updateTileEntity((TileEntity) o);
}
// Start tracking entities in the chunk
((WorldServer) player.getHandle().world).getTracker().a(player.getHandle(), player.getHandle().world.getChunkAt(chunk.x, chunk.z));
}
}
}
private void processInput() {
// Queue next chunk packet out
if (processingQueue.isEmpty() && !internalQueue.isEmpty()) {
// Check if player's output queue has a lot of stuff waiting to be sent. If so, don't process and wait.
// Network queue limit is 2097152 bytes
// Each chunk packet with 5 chunks is about 10000 - 25000 bytes
// We'll allow the size of 3 packets to be queued = 75000 bytes
// Try-catch so as to not disrupt chunk sending if something fails
if (!Orebfuscator.useSpigot) {
try {
NetworkManager networkManager = (NetworkManager) player.getHandle().playerConnection.networkManager;
if (((int) (Integer) ReflectionHelper.getPrivateField(NetworkManager.class, networkManager, "z")) > 75000) {
return;
}
}
catch (Exception e) {
// e.printStackTrace();
}
}
// A list to queue chunks
List<Chunk> chunks = new LinkedList<Chunk>();
// Queue up to 5 chunks
synchronized (internalQueue) {
while (!internalQueue.isEmpty() && chunks.size() < 5) {
// Dequeue a chunk from input
ChunkCoordIntPair chunkcoordintpair = internalQueue.remove(0);
// If the chunk is loaded and not null
if (chunkcoordintpair != null && player.getHandle().world.isLoaded(chunkcoordintpair.x << 4, 0, chunkcoordintpair.z << 4)) {
// Queue the chunk for processing
processingQueue.add(chunkcoordintpair);
// Add the chunk to the list to create a packet
chunks.add(player.getHandle().world.getChunkAt(chunkcoordintpair.x, chunkcoordintpair.z));
}
}
}
// If there are chunks to process
if (!chunks.isEmpty()) {
// Create a packet wrapper
IPacket56 packet = InternalAccessor.Instance.newPacket56();
// Create the actual packet
lastPacket = new Packet56MapChunkBulk(chunks);
// Put into wrapper
packet.setPacket(lastPacket);
// Send to Processing Thread
ChunkProcessingThread.Queue(packet, player, this);
}
}
}
private void updateTileEntity(TileEntity tileentity) {
if (tileentity != null) {
Packet packet = tileentity.getUpdatePacket();
if (packet != null) {
player.getHandle().playerConnection.sendPacket(packet);
}
}
}
@Override
public ListIterator<ChunkCoordIntPair> listIterator() {
return new FakeIterator();
}
private class FakeIterator implements ListIterator<ChunkCoordIntPair> {
@Override
public boolean hasNext() {
return false;
}
@Override
public ChunkCoordIntPair next() {
return null;
}
@Override
public boolean hasPrevious() {
return false;
}
@Override
public ChunkCoordIntPair previous() {
return null;
}
@Override
public int nextIndex() {
return 0;
}
@Override
public int previousIndex() {
return 0;
}
@Override
public void remove() {}
@Override
public void set(ChunkCoordIntPair e) {}
@Override
public void add(ChunkCoordIntPair e) {}
}
private static class ChunkCoordComparator implements java.util.Comparator<ChunkCoordIntPair> {
private int x;
private int z;
public ChunkCoordComparator(EntityPlayer entityplayer) {
x = (int) entityplayer.locX >> 4;
z = (int) entityplayer.locZ >> 4;
}
public int compare(ChunkCoordIntPair a, ChunkCoordIntPair b) {
if (a.equals(b)) {
return 0;
}
// Subtract current position to set center point
int ax = a.x - this.x;
int az = a.z - this.z;
int bx = b.x - this.x;
int bz = b.z - this.z;
int result = ((ax - bx) * (ax + bx)) + ((az - bz) * (az + bz));
if (result != 0) {
return result;
}
if (ax < 0) {
if (bx < 0) {
return bz - az;
}
else {
return -1;
}
}
else {
if (bx < 0) {
return 1;
}
else {
return az - bz;
}
}
}
}
}

View File

@ -1,36 +0,0 @@
/*
* Copyright (C) 2011-2014 lishid. All rights reserved.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, version 3.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.lishid.orebfuscator.internal.v1_6_R2;
import com.lishid.orebfuscator.internal.IMinecraftWorldServer;
import com.lishid.orebfuscator.internal.InternalAccessor;
//Volatile
import net.minecraft.server.v1_6_R2.*;
import org.bukkit.craftbukkit.v1_6_R2.*;
public class MinecraftWorldServer implements IMinecraftWorldServer {
public void Notify(Object world, int x, int y, int z) {
if (world instanceof CraftWorld) {
WorldServer server = (WorldServer) ((CraftWorld) world).getHandle();
server.notify(x, y, z);
}
else {
InternalAccessor.Instance.PrintError();
}
}
}

View File

@ -1,95 +0,0 @@
/*
* Copyright (C) 2011-2014 lishid. All rights reserved.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, version 3.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.lishid.orebfuscator.internal.v1_6_R2;
import java.io.DataInput;
import java.io.DataOutput;
import com.lishid.orebfuscator.internal.INBT;
//Volatile
import net.minecraft.server.v1_6_R2.*;
public class NBT implements INBT {
NBTTagCompound nbt = new NBTTagCompound();
@Override
public void reset() {
nbt = new NBTTagCompound();
}
@Override
public void setInt(String tag, int value) {
nbt.setInt(tag, value);
}
@Override
public void setLong(String tag, long value) {
nbt.setLong(tag, value);
}
@Override
public void setBoolean(String tag, boolean value) {
nbt.setBoolean(tag, value);
}
@Override
public void setByteArray(String tag, byte[] value) {
nbt.setByteArray(tag, value);
}
@Override
public void setIntArray(String tag, int[] value) {
nbt.setIntArray(tag, value);
}
@Override
public int getInt(String tag) {
return nbt.getInt(tag);
}
@Override
public long getLong(String tag) {
return nbt.getLong(tag);
}
@Override
public boolean getBoolean(String tag) {
return nbt.getBoolean(tag);
}
@Override
public byte[] getByteArray(String tag) {
return nbt.getByteArray(tag);
}
@Override
public int[] getIntArray(String tag) {
return nbt.getIntArray(tag);
}
@Override
public void Read(DataInput stream) {
nbt = NBTCompressedStreamTools.a(stream);
}
@Override
public void Write(DataOutput stream) {
NBTCompressedStreamTools.a(nbt, stream);
}
}

View File

@ -1,48 +0,0 @@
/*
* Copyright (C) 2011-2014 lishid. All rights reserved.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, version 3.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.lishid.orebfuscator.internal.v1_6_R2;
import java.util.ArrayList;
import org.bukkit.entity.Player;
import com.lishid.orebfuscator.internal.IPacket51;
import com.lishid.orebfuscator.internal.InternalAccessor;
import com.lishid.orebfuscator.obfuscation.Calculations;
//Volatile
import net.minecraft.server.v1_6_R2.*;
public class NetworkQueue extends ArrayList<Packet> {
private static final long serialVersionUID = 4252847662044263527L;
private Player player;
public NetworkQueue(Player player) {
this.player = player;
}
@Override
public boolean add(Packet packet) {
if (packet.n() == 51) {
IPacket51 packet51 = InternalAccessor.Instance.newPacket51();
packet51.setPacket(packet);
Calculations.Obfuscate(packet51, this.player);
}
return super.add(packet);
}
}

View File

@ -1,18 +0,0 @@
package com.lishid.orebfuscator.internal.v1_6_R2;
import com.lishid.orebfuscator.hithack.BlockHitManager;
import net.minecraft.server.v1_6_R2.*;
public class Packet14Orebfuscator extends Packet14BlockDig {
@Override
public void handle(Connection handler) {
if (this.e == 1 && handler instanceof PlayerConnection) {
boolean canHit = BlockHitManager.hitBlock(((PlayerConnection) handler).getPlayer(), null);
if (!canHit) {
return;
}
}
super.handle(handler);
}
}

View File

@ -1,82 +0,0 @@
/*
* Copyright (C) 2011-2014 lishid. All rights reserved.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, version 3.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.lishid.orebfuscator.internal.v1_6_R2;
import java.util.zip.Deflater;
import com.lishid.orebfuscator.internal.IPacket51;
import com.lishid.orebfuscator.internal.InternalAccessor;
import com.lishid.orebfuscator.utils.ReflectionHelper;
//Volatile
import net.minecraft.server.v1_6_R2.*;
public class Packet51 implements IPacket51 {
private static Class<? extends Object> packetClass = Packet51MapChunk.class;
Packet51MapChunk packet;
@Override
public void setPacket(Object packet) {
if (packet instanceof Packet51MapChunk) {
this.packet = (Packet51MapChunk) packet;
}
else {
InternalAccessor.Instance.PrintError();
}
}
@Override
public int getX() {
return packet.a;
}
@Override
public int getZ() {
return packet.b;
}
@Override
public int getChunkMask() {
return packet.c;
}
@Override
public int getExtraMask() {
return packet.d;
}
@Override
public byte[] getBuffer() {
return (byte[]) ReflectionHelper.getPrivateField(packetClass, packet, "inflatedBuffer");
}
private byte[] getOutputBuffer() {
return (byte[]) ReflectionHelper.getPrivateField(packetClass, packet, "buffer");
}
@Override
public void compress(Deflater deflater) {
byte[] chunkInflatedBuffer = getBuffer();
byte[] chunkBuffer = getOutputBuffer();
deflater.reset();
deflater.setInput(chunkInflatedBuffer, 0, chunkInflatedBuffer.length);
deflater.finish();
ReflectionHelper.setPrivateField(packetClass, packet, "size", deflater.deflate(chunkBuffer));
}
}

View File

@ -1,115 +0,0 @@
/*
* Copyright (C) 2011-2014 lishid. All rights reserved.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, version 3.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.lishid.orebfuscator.internal.v1_6_R2;
import java.util.zip.Deflater;
import com.lishid.orebfuscator.commands.OrebfuscatorCommandExecutor;
import com.lishid.orebfuscator.internal.IPacket56;
import com.lishid.orebfuscator.internal.InternalAccessor;
import com.lishid.orebfuscator.utils.ReflectionHelper;
//Volatile
import net.minecraft.server.v1_6_R2.*;
public class Packet56 implements IPacket56 {
Packet56MapChunkBulk packet;
@Override
public void setPacket(Object packet) {
if (packet instanceof Packet56MapChunkBulk) {
this.packet = (Packet56MapChunkBulk) packet;
}
else {
InternalAccessor.Instance.PrintError();
}
}
@Override
public int getPacketChunkNumber() {
return packet.d();
}
@Override
public int[] getX() {
return (int[]) ReflectionHelper.getPrivateField(packet, "c");
}
@Override
public int[] getZ() {
return (int[]) ReflectionHelper.getPrivateField(packet, "d");
}
@Override
public int[] getChunkMask() {
return packet.a;
}
@Override
public int[] getExtraMask() {
return packet.b;
}
@Override
public Object getFieldData(String field) {
return ReflectionHelper.getPrivateField(Packet56MapChunkBulk.class, packet, field);
}
@Override
public void setFieldData(String field, Object data) {
ReflectionHelper.setPrivateField(Packet56MapChunkBulk.class, packet, field, data);
}
public String getInflatedBuffers() {
return "inflatedBuffers";
}
public String getBuildBuffer() {
return "buildBuffer";
}
public String getOutputBuffer() {
return "buffer";
}
@Override
public void compress(Deflater deflater) {
if (getFieldData(getOutputBuffer()) != null) {
return;
}
byte[] buildBuffer = (byte[]) getFieldData(getBuildBuffer());
deflater.reset();
deflater.setInput(buildBuffer);
deflater.finish();
byte[] buffer = new byte[buildBuffer.length + 100];
ReflectionHelper.setPrivateField(packet, "buffer", buffer);
int size = deflater.deflate(buffer);
ReflectionHelper.setPrivateField(packet, "size", size);
// Free memory
ReflectionHelper.setPrivateField(packet, "buildBuffer", null);
ReflectionHelper.setPrivateField(packet, "inflatedBuffers", null);
if (OrebfuscatorCommandExecutor.DebugMode) {
System.out.println("Packet size: " + size);
}
}
}

View File

@ -1,95 +0,0 @@
/*
* Copyright (C) 2011-2014 lishid. All rights reserved.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, version 3.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.lishid.orebfuscator.internal.v1_6_R2;
import java.lang.reflect.Field;
import java.util.Collections;
import java.util.Map;
import java.util.List;
import com.lishid.orebfuscator.Orebfuscator;
import com.lishid.orebfuscator.internal.IPlayerHook;
import com.lishid.orebfuscator.utils.ReflectionHelper;
import org.bukkit.entity.Player;
//Volatile
import net.minecraft.server.v1_6_R2.*;
import org.bukkit.craftbukkit.v1_6_R2.entity.*;
public class PlayerHook implements IPlayerHook {
@SuppressWarnings("unchecked")
public void HookNM(Player p) {
CraftPlayer player = (CraftPlayer) p;
// Update NetworkManager's lists
NetworkManager networkManager = (NetworkManager) player.getHandle().playerConnection.networkManager;
Field[] networkFields = networkManager.getClass().getDeclaredFields();
for (Field field : networkFields) {
try {
if (List.class.isAssignableFrom(field.getType())) {
List<Packet> list = new NetworkQueue(p);
field.setAccessible(true);
List<Packet> oldList = (List<Packet>) field.get(networkManager);
// Move packets to new list
synchronized (ReflectionHelper.getPrivateField(networkManager, "h")) {
list.addAll(oldList);
oldList.clear();
}
// Replace with new list
field.set(networkManager, Collections.synchronizedList(list));
}
}
catch (Exception e) {
Orebfuscator.log(e);
}
}
hookPacket();
}
static boolean hookPacket = false;
@SuppressWarnings("unchecked")
private void hookPacket() {
if (hookPacket)
return;
hookPacket = true;
Packet.l.a(14, Packet14Orebfuscator.class);
// Use reflection to add into a and c
Field[] packetFields = Packet.class.getDeclaredFields();
for (Field field : packetFields) {
try {
if (Map.class.isAssignableFrom(field.getType())) {
field.setAccessible(true);
@SuppressWarnings({ "rawtypes" })
Map packets = (Map) field.get(null);
packets.put(Packet14Orebfuscator.class, 14);
}
}
catch (Exception e) {
Orebfuscator.log(e);
}
}
}
public void HookChunkQueue(Player p) {
CraftPlayer player = (CraftPlayer) p;
ReflectionHelper.setPrivateFinal(player.getHandle(), "chunkCoordIntPairQueue", new ChunkQueue(player, player.getHandle().chunkCoordIntPairQueue));
}
}

View File

@ -1,46 +0,0 @@
/*
* Copyright (C) 2011-2014 lishid. All rights reserved.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, version 3.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.lishid.orebfuscator.internal.v1_6_R3;
import com.lishid.orebfuscator.internal.IBlockAccess;
import org.bukkit.entity.Player;
//Volatile
import net.minecraft.server.v1_6_R3.*;
import org.bukkit.craftbukkit.v1_6_R3.entity.*;
import org.bukkit.craftbukkit.v1_6_R3.*;
public class BlockAccess implements IBlockAccess {
@Override
public boolean isBlockTransparent(int id) {
return !Block.l(id);
}
@Override
public void updateBlockTileEntity(org.bukkit.block.Block block, Player player) {
CraftWorld world = (CraftWorld) block.getWorld();
TileEntity tileEntity = world.getTileEntityAt(block.getX(), block.getY(), block.getZ());
if (tileEntity == null) {
return;
}
Packet packet = tileEntity.getUpdatePacket();
if (packet != null) {
CraftPlayer player2 = (CraftPlayer) player;
player2.getHandle().playerConnection.sendPacket(packet);
}
}
}

View File

@ -1,92 +0,0 @@
/*
* Copyright (C) 2011-2014 lishid. All rights reserved.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, version 3.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.lishid.orebfuscator.internal.v1_6_R3;
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.File;
import java.util.HashMap;
import com.lishid.orebfuscator.Orebfuscator;
import com.lishid.orebfuscator.OrebfuscatorConfig;
import com.lishid.orebfuscator.internal.IChunkCache;
//Volatile
import net.minecraft.server.v1_6_R3.*;
public class ChunkCache implements IChunkCache {
private static final HashMap<File, RegionFile> cachedRegionFiles = new HashMap<File, RegionFile>();
private synchronized RegionFile getRegionFile(File folder, int x, int z) {
File path = new File(folder, "region");
File file = new File(path, "r." + (x >> 5) + "." + (z >> 5) + ".mcr");
try {
RegionFile regionFile = cachedRegionFiles.get(file);
if (regionFile != null) {
return regionFile;
}
if (!path.exists()) {
path.mkdirs();
}
if (cachedRegionFiles.size() >= OrebfuscatorConfig.MaxLoadedCacheFiles) {
clearCache();
}
regionFile = new RegionFile(file);
cachedRegionFiles.put(file, regionFile);
return regionFile;
}
catch (Exception e) {
try {
file.delete();
}
catch (Exception e2) {
Orebfuscator.log(e);
}
}
return null;
}
@Override
public DataInputStream getInputStream(File folder, int x, int z) {
RegionFile regionFile = getRegionFile(folder, x, z);
return regionFile.a(x & 0x1F, z & 0x1F);
}
@Override
public DataOutputStream getOutputStream(File folder, int x, int z) {
RegionFile regionFile = getRegionFile(folder, x, z);
return regionFile.b(x & 0x1F, z & 0x1F);
}
@Override
public synchronized void clearCache() {
for (RegionFile regionFile : cachedRegionFiles.values()) {
try {
if (regionFile != null)
regionFile.c();
}
catch (Exception e) {
e.printStackTrace();
}
}
cachedRegionFiles.clear();
}
}

View File

@ -1,318 +0,0 @@
/*
* Copyright (C) 2011-2014 lishid. All rights reserved.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, version 3.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.lishid.orebfuscator.internal.v1_6_R3;
import java.util.Collections;
import java.util.LinkedList;
import java.util.List;
import java.util.ListIterator;
import java.util.concurrent.atomic.AtomicBoolean;
import com.lishid.orebfuscator.Orebfuscator;
import com.lishid.orebfuscator.hook.ChunkProcessingThread;
import com.lishid.orebfuscator.internal.IChunkQueue;
import com.lishid.orebfuscator.internal.IPacket56;
import com.lishid.orebfuscator.internal.InternalAccessor;
import com.lishid.orebfuscator.utils.ReflectionHelper;
//Volatile
import net.minecraft.server.v1_6_R3.*;
import org.bukkit.craftbukkit.v1_6_R3.entity.*;
public class ChunkQueue extends LinkedList<ChunkCoordIntPair> implements IChunkQueue {
private static final long serialVersionUID = -1928681564741152336L;
List<ChunkCoordIntPair> internalQueue = Collections.synchronizedList(new LinkedList<ChunkCoordIntPair>());
List<ChunkCoordIntPair> outputQueue = Collections.synchronizedList(new LinkedList<ChunkCoordIntPair>());
List<ChunkCoordIntPair> processingQueue = Collections.synchronizedList(new LinkedList<ChunkCoordIntPair>());
Packet56MapChunkBulk lastPacket;
CraftPlayer player;
Thread thread;
AtomicBoolean kill = new AtomicBoolean(false);
@SuppressWarnings({ "unchecked", "rawtypes" })
public ChunkQueue(CraftPlayer player, List previousEntries) {
this.player = player;
internalQueue.addAll(previousEntries);
}
@Override
public boolean remove(Object arg0) {
return internalQueue.remove(arg0) || processingQueue.remove(arg0) || outputQueue.remove(arg0);
}
// Called when the queue should be cleared
@Override
public void clear() {
// Clear the internal queue
internalQueue.clear();
super.clear();
}
// Called when new chunks are queued
@Override
public boolean add(ChunkCoordIntPair e) {
boolean result;
synchronized (internalQueue) {
result = internalQueue.add(e);
}
// Move everything into the internal queue
return result;
// return super.add(e);
}
// Called when the list should be sorted
@Override
public Object[] toArray() {
sort();
// Return the old array to be sorted
return internalQueue.toArray();
}
// This checks for chunks in the queue
@Override
public boolean contains(Object o) {
// Checks whether the coords are actually in
return internalQueue.contains(o) || processingQueue.contains(o);
}
@Override
public boolean isEmpty() {
try {
// If the player is gone, then don't waste time
if (player.getHandle().playerConnection.disconnected) {
// Cleanup all queues
synchronized (internalQueue) {
internalQueue.clear();
}
processingQueue.clear();
outputQueue.clear();
lastPacket = null;
}
else {
// Process outputs and inputs
processOutput();
processInput();
}
}
catch (Exception e) {
Orebfuscator.log(e);
}
return true;
}
public void sort() {
// Sort the internal array according to CB - See PlayerChunkMap.movePlayer(EntityPlayer entityplayer)
synchronized (internalQueue) {
java.util.Collections.sort(internalQueue, new ChunkCoordComparator(player.getHandle()));
}
}
@Override
public void FinishedProcessing(IPacket56 packet) {
if (lastPacket != null) {
player.getHandle().playerConnection.sendPacket(lastPacket);
// Remove reference to the packet so it can be freed when possible
lastPacket = null;
}
outputQueue.addAll(processingQueue);
processingQueue.clear();
}
private void processOutput() {
// Chunk packet finished processing, output relevant packets
while (!outputQueue.isEmpty()) {
// Get the chunk coordinate
ChunkCoordIntPair chunk = outputQueue.remove(0);
// Check if the chunk is ready
if (chunk != null && ((WorldServer) player.getHandle().world).isLoaded(chunk.x << 4, 0, chunk.z << 4)) {
// Get all the TileEntities in the chunk
@SuppressWarnings("rawtypes")
List tileEntities = ((WorldServer) player.getHandle().world).getTileEntities(chunk.x * 16, 0, chunk.z * 16, chunk.x * 16 + 16, 256, chunk.z * 16 + 16);
for (Object o : tileEntities) {
// Send out packet for the tile entity data
this.updateTileEntity((TileEntity) o);
}
// Start tracking entities in the chunk
((WorldServer) player.getHandle().world).getTracker().a(player.getHandle(), player.getHandle().world.getChunkAt(chunk.x, chunk.z));
}
}
}
private void processInput() {
// Queue next chunk packet out
if (processingQueue.isEmpty() && !internalQueue.isEmpty()) {
// Check if player's output queue has a lot of stuff waiting to be sent. If so, don't process and wait.
// Network queue limit is 2097152 bytes
// Each chunk packet with 5 chunks is about 10000 - 25000 bytes
// We'll allow the size of 3 packets to be queued = 75000 bytes
// Try-catch so as to not disrupt chunk sending if something fails
if (!Orebfuscator.useSpigot) {
try {
NetworkManager networkManager = (NetworkManager) player.getHandle().playerConnection.networkManager;
if (((int) (Integer) ReflectionHelper.getPrivateField(NetworkManager.class, networkManager, "z")) > 75000) {
return;
}
}
catch (Exception e) {
// e.printStackTrace();
}
}
// A list to queue chunks
List<Chunk> chunks = new LinkedList<Chunk>();
// Queue up to 5 chunks
synchronized (internalQueue) {
while (!internalQueue.isEmpty() && chunks.size() < 5) {
// Dequeue a chunk from input
ChunkCoordIntPair chunkcoordintpair = internalQueue.remove(0);
// If the chunk is loaded and not null
if (chunkcoordintpair != null && player.getHandle().world.isLoaded(chunkcoordintpair.x << 4, 0, chunkcoordintpair.z << 4)) {
// Queue the chunk for processing
processingQueue.add(chunkcoordintpair);
// Add the chunk to the list to create a packet
chunks.add(player.getHandle().world.getChunkAt(chunkcoordintpair.x, chunkcoordintpair.z));
}
}
}
// If there are chunks to process
if (!chunks.isEmpty()) {
// Create a packet wrapper
IPacket56 packet = InternalAccessor.Instance.newPacket56();
// Create the actual packet
lastPacket = new Packet56MapChunkBulk(chunks);
// Put into wrapper
packet.setPacket(lastPacket);
// Send to Processing Thread
ChunkProcessingThread.Queue(packet, player, this);
}
}
}
private void updateTileEntity(TileEntity tileentity) {
if (tileentity != null) {
Packet packet = tileentity.getUpdatePacket();
if (packet != null) {
player.getHandle().playerConnection.sendPacket(packet);
}
}
}
@Override
public ListIterator<ChunkCoordIntPair> listIterator() {
return new FakeIterator();
}
private class FakeIterator implements ListIterator<ChunkCoordIntPair> {
@Override
public boolean hasNext() {
return false;
}
@Override
public ChunkCoordIntPair next() {
return null;
}
@Override
public boolean hasPrevious() {
return false;
}
@Override
public ChunkCoordIntPair previous() {
return null;
}
@Override
public int nextIndex() {
return 0;
}
@Override
public int previousIndex() {
return 0;
}
@Override
public void remove() {}
@Override
public void set(ChunkCoordIntPair e) {}
@Override
public void add(ChunkCoordIntPair e) {}
}
private static class ChunkCoordComparator implements java.util.Comparator<ChunkCoordIntPair> {
private int x;
private int z;
public ChunkCoordComparator(EntityPlayer entityplayer) {
x = (int) entityplayer.locX >> 4;
z = (int) entityplayer.locZ >> 4;
}
public int compare(ChunkCoordIntPair a, ChunkCoordIntPair b) {
if (a.equals(b)) {
return 0;
}
// Subtract current position to set center point
int ax = a.x - this.x;
int az = a.z - this.z;
int bx = b.x - this.x;
int bz = b.z - this.z;
int result = ((ax - bx) * (ax + bx)) + ((az - bz) * (az + bz));
if (result != 0) {
return result;
}
if (ax < 0) {
if (bx < 0) {
return bz - az;
}
else {
return -1;
}
}
else {
if (bx < 0) {
return 1;
}
else {
return az - bz;
}
}
}
}
}

View File

@ -1,36 +0,0 @@
/*
* Copyright (C) 2011-2014 lishid. All rights reserved.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, version 3.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.lishid.orebfuscator.internal.v1_6_R3;
import com.lishid.orebfuscator.internal.IMinecraftWorldServer;
import com.lishid.orebfuscator.internal.InternalAccessor;
//Volatile
import net.minecraft.server.v1_6_R3.*;
import org.bukkit.craftbukkit.v1_6_R3.*;
public class MinecraftWorldServer implements IMinecraftWorldServer {
public void Notify(Object world, int x, int y, int z) {
if (world instanceof CraftWorld) {
WorldServer server = (WorldServer) ((CraftWorld) world).getHandle();
server.notify(x, y, z);
}
else {
InternalAccessor.Instance.PrintError();
}
}
}

View File

@ -1,95 +0,0 @@
/*
* Copyright (C) 2011-2014 lishid. All rights reserved.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, version 3.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.lishid.orebfuscator.internal.v1_6_R3;
import java.io.DataInput;
import java.io.DataOutput;
import com.lishid.orebfuscator.internal.INBT;
//Volatile
import net.minecraft.server.v1_6_R3.*;
public class NBT implements INBT {
NBTTagCompound nbt = new NBTTagCompound();
@Override
public void reset() {
nbt = new NBTTagCompound();
}
@Override
public void setInt(String tag, int value) {
nbt.setInt(tag, value);
}
@Override
public void setLong(String tag, long value) {
nbt.setLong(tag, value);
}
@Override
public void setBoolean(String tag, boolean value) {
nbt.setBoolean(tag, value);
}
@Override
public void setByteArray(String tag, byte[] value) {
nbt.setByteArray(tag, value);
}
@Override
public void setIntArray(String tag, int[] value) {
nbt.setIntArray(tag, value);
}
@Override
public int getInt(String tag) {
return nbt.getInt(tag);
}
@Override
public long getLong(String tag) {
return nbt.getLong(tag);
}
@Override
public boolean getBoolean(String tag) {
return nbt.getBoolean(tag);
}
@Override
public byte[] getByteArray(String tag) {
return nbt.getByteArray(tag);
}
@Override
public int[] getIntArray(String tag) {
return nbt.getIntArray(tag);
}
@Override
public void Read(DataInput stream) {
nbt = NBTCompressedStreamTools.a(stream);
}
@Override
public void Write(DataOutput stream) {
NBTCompressedStreamTools.a(nbt, stream);
}
}

View File

@ -1,48 +0,0 @@
/*
* Copyright (C) 2011-2014 lishid. All rights reserved.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, version 3.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.lishid.orebfuscator.internal.v1_6_R3;
import java.util.ArrayList;
import org.bukkit.entity.Player;
import com.lishid.orebfuscator.internal.IPacket51;
import com.lishid.orebfuscator.internal.InternalAccessor;
import com.lishid.orebfuscator.obfuscation.Calculations;
//Volatile
import net.minecraft.server.v1_6_R3.*;
public class NetworkQueue extends ArrayList<Packet> {
private static final long serialVersionUID = 4252847662044263527L;
private Player player;
public NetworkQueue(Player player) {
this.player = player;
}
@Override
public boolean add(Packet packet) {
if (packet.n() == 51) {
IPacket51 packet51 = InternalAccessor.Instance.newPacket51();
packet51.setPacket(packet);
Calculations.Obfuscate(packet51, this.player);
}
return super.add(packet);
}
}

View File

@ -1,18 +0,0 @@
package com.lishid.orebfuscator.internal.v1_6_R3;
import com.lishid.orebfuscator.hithack.BlockHitManager;
import net.minecraft.server.v1_6_R3.*;
public class Packet14Orebfuscator extends Packet14BlockDig {
@Override
public void handle(Connection handler) {
if (this.e == 1 && handler instanceof PlayerConnection) {
boolean canHit = BlockHitManager.hitBlock(((PlayerConnection) handler).getPlayer(), null);
if (!canHit) {
return;
}
}
super.handle(handler);
}
}

View File

@ -1,82 +0,0 @@
/*
* Copyright (C) 2011-2014 lishid. All rights reserved.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, version 3.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.lishid.orebfuscator.internal.v1_6_R3;
import java.util.zip.Deflater;
import com.lishid.orebfuscator.internal.IPacket51;
import com.lishid.orebfuscator.internal.InternalAccessor;
import com.lishid.orebfuscator.utils.ReflectionHelper;
//Volatile
import net.minecraft.server.v1_6_R3.*;
public class Packet51 implements IPacket51 {
private static Class<? extends Object> packetClass = Packet51MapChunk.class;
Packet51MapChunk packet;
@Override
public void setPacket(Object packet) {
if (packet instanceof Packet51MapChunk) {
this.packet = (Packet51MapChunk) packet;
}
else {
InternalAccessor.Instance.PrintError();
}
}
@Override
public int getX() {
return packet.a;
}
@Override
public int getZ() {
return packet.b;
}
@Override
public int getChunkMask() {
return packet.c;
}
@Override
public int getExtraMask() {
return packet.d;
}
@Override
public byte[] getBuffer() {
return (byte[]) ReflectionHelper.getPrivateField(packetClass, packet, "inflatedBuffer");
}
private byte[] getOutputBuffer() {
return (byte[]) ReflectionHelper.getPrivateField(packetClass, packet, "buffer");
}
@Override
public void compress(Deflater deflater) {
byte[] chunkInflatedBuffer = getBuffer();
byte[] chunkBuffer = getOutputBuffer();
deflater.reset();
deflater.setInput(chunkInflatedBuffer, 0, chunkInflatedBuffer.length);
deflater.finish();
ReflectionHelper.setPrivateField(packetClass, packet, "size", deflater.deflate(chunkBuffer));
}
}

View File

@ -1,115 +0,0 @@
/*
* Copyright (C) 2011-2014 lishid. All rights reserved.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, version 3.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.lishid.orebfuscator.internal.v1_6_R3;
import java.util.zip.Deflater;
import com.lishid.orebfuscator.commands.OrebfuscatorCommandExecutor;
import com.lishid.orebfuscator.internal.IPacket56;
import com.lishid.orebfuscator.internal.InternalAccessor;
import com.lishid.orebfuscator.utils.ReflectionHelper;
//Volatile
import net.minecraft.server.v1_6_R3.*;
public class Packet56 implements IPacket56 {
Packet56MapChunkBulk packet;
@Override
public void setPacket(Object packet) {
if (packet instanceof Packet56MapChunkBulk) {
this.packet = (Packet56MapChunkBulk) packet;
}
else {
InternalAccessor.Instance.PrintError();
}
}
@Override
public int getPacketChunkNumber() {
return packet.d();
}
@Override
public int[] getX() {
return (int[]) ReflectionHelper.getPrivateField(packet, "c");
}
@Override
public int[] getZ() {
return (int[]) ReflectionHelper.getPrivateField(packet, "d");
}
@Override
public int[] getChunkMask() {
return packet.a;
}
@Override
public int[] getExtraMask() {
return packet.b;
}
@Override
public Object getFieldData(String field) {
return ReflectionHelper.getPrivateField(Packet56MapChunkBulk.class, packet, field);
}
@Override
public void setFieldData(String field, Object data) {
ReflectionHelper.setPrivateField(Packet56MapChunkBulk.class, packet, field, data);
}
public String getInflatedBuffers() {
return "inflatedBuffers";
}
public String getBuildBuffer() {
return "buildBuffer";
}
public String getOutputBuffer() {
return "buffer";
}
@Override
public void compress(Deflater deflater) {
if (getFieldData(getOutputBuffer()) != null) {
return;
}
byte[] buildBuffer = (byte[]) getFieldData(getBuildBuffer());
deflater.reset();
deflater.setInput(buildBuffer);
deflater.finish();
byte[] buffer = new byte[buildBuffer.length + 100];
ReflectionHelper.setPrivateField(packet, "buffer", buffer);
int size = deflater.deflate(buffer);
ReflectionHelper.setPrivateField(packet, "size", size);
// Free memory
ReflectionHelper.setPrivateField(packet, "buildBuffer", null);
ReflectionHelper.setPrivateField(packet, "inflatedBuffers", null);
if (OrebfuscatorCommandExecutor.DebugMode) {
System.out.println("Packet size: " + size);
}
}
}

View File

@ -1,95 +0,0 @@
/*
* Copyright (C) 2011-2014 lishid. All rights reserved.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, version 3.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.lishid.orebfuscator.internal.v1_6_R3;
import java.lang.reflect.Field;
import java.util.Collections;
import java.util.Map;
import java.util.List;
import com.lishid.orebfuscator.Orebfuscator;
import com.lishid.orebfuscator.internal.IPlayerHook;
import com.lishid.orebfuscator.utils.ReflectionHelper;
import org.bukkit.entity.Player;
//Volatile
import net.minecraft.server.v1_6_R3.*;
import org.bukkit.craftbukkit.v1_6_R3.entity.*;
public class PlayerHook implements IPlayerHook {
@SuppressWarnings("unchecked")
public void HookNM(Player p) {
CraftPlayer player = (CraftPlayer) p;
// Update NetworkManager's lists
NetworkManager networkManager = (NetworkManager) player.getHandle().playerConnection.networkManager;
Field[] networkFields = networkManager.getClass().getDeclaredFields();
for (Field field : networkFields) {
try {
if (List.class.isAssignableFrom(field.getType())) {
List<Packet> list = new NetworkQueue(p);
field.setAccessible(true);
List<Packet> oldList = (List<Packet>) field.get(networkManager);
// Move packets to new list
synchronized (ReflectionHelper.getPrivateField(networkManager, "h")) {
list.addAll(oldList);
oldList.clear();
}
// Replace with new list
field.set(networkManager, Collections.synchronizedList(list));
}
}
catch (Exception e) {
Orebfuscator.log(e);
}
}
hookPacket();
}
static boolean hookPacket = false;
@SuppressWarnings("unchecked")
private void hookPacket() {
if (hookPacket)
return;
hookPacket = true;
Packet.l.a(14, Packet14Orebfuscator.class);
// Use reflection to add into a and c
Field[] packetFields = Packet.class.getDeclaredFields();
for (Field field : packetFields) {
try {
if (Map.class.isAssignableFrom(field.getType())) {
field.setAccessible(true);
@SuppressWarnings({ "rawtypes" })
Map packets = (Map) field.get(null);
packets.put(Packet14Orebfuscator.class, 14);
}
}
catch (Exception e) {
Orebfuscator.log(e);
}
}
}
public void HookChunkQueue(Player p) {
CraftPlayer player = (CraftPlayer) p;
ReflectionHelper.setPrivateFinal(player.getHandle(), "chunkCoordIntPairQueue", new ChunkQueue(player, player.getHandle().chunkCoordIntPairQueue));
}
}

View File

@ -1,46 +0,0 @@
/*
* Copyright (C) 2011-2014 lishid. All rights reserved.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, version 3.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.lishid.orebfuscator.internal.v1_7_R1;
import com.lishid.orebfuscator.internal.IBlockAccess;
import org.bukkit.entity.Player;
//Volatile
import net.minecraft.server.v1_7_R1.*;
import org.bukkit.craftbukkit.v1_7_R1.entity.*;
import org.bukkit.craftbukkit.v1_7_R1.*;
public class BlockAccess implements IBlockAccess {
@Override
public boolean isBlockTransparent(int id) {
return !Block.e(id).r();
}
@Override
public void updateBlockTileEntity(org.bukkit.block.Block block, Player player) {
CraftWorld world = (CraftWorld) block.getWorld();
TileEntity tileEntity = world.getTileEntityAt(block.getX(), block.getY(), block.getZ());
if (tileEntity == null) {
return;
}
Packet packet = tileEntity.getUpdatePacket();
if (packet != null) {
CraftPlayer player2 = (CraftPlayer) player;
player2.getHandle().playerConnection.sendPacket(packet);
}
}
}

View File

@ -1,92 +0,0 @@
/*
* Copyright (C) 2011-2014 lishid. All rights reserved.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, version 3.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.lishid.orebfuscator.internal.v1_7_R1;
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.File;
import java.util.HashMap;
import com.lishid.orebfuscator.Orebfuscator;
import com.lishid.orebfuscator.OrebfuscatorConfig;
import com.lishid.orebfuscator.internal.IChunkCache;
//Volatile
import net.minecraft.server.v1_7_R1.*;
public class ChunkCache implements IChunkCache {
private static final HashMap<File, RegionFile> cachedRegionFiles = new HashMap<File, RegionFile>();
private synchronized RegionFile getRegionFile(File folder, int x, int z) {
File path = new File(folder, "region");
File file = new File(path, "r." + (x >> 5) + "." + (z >> 5) + ".mcr");
try {
RegionFile regionFile = cachedRegionFiles.get(file);
if (regionFile != null) {
return regionFile;
}
if (!path.exists()) {
path.mkdirs();
}
if (cachedRegionFiles.size() >= OrebfuscatorConfig.MaxLoadedCacheFiles) {
clearCache();
}
regionFile = new RegionFile(file);
cachedRegionFiles.put(file, regionFile);
return regionFile;
}
catch (Exception e) {
try {
file.delete();
}
catch (Exception e2) {
Orebfuscator.log(e);
}
}
return null;
}
@Override
public DataInputStream getInputStream(File folder, int x, int z) {
RegionFile regionFile = getRegionFile(folder, x, z);
return regionFile.a(x & 0x1F, z & 0x1F);
}
@Override
public DataOutputStream getOutputStream(File folder, int x, int z) {
RegionFile regionFile = getRegionFile(folder, x, z);
return regionFile.b(x & 0x1F, z & 0x1F);
}
@Override
public synchronized void clearCache() {
for (RegionFile regionFile : cachedRegionFiles.values()) {
try {
if (regionFile != null)
regionFile.c();
}
catch (Exception e) {
e.printStackTrace();
}
}
cachedRegionFiles.clear();
}
}

View File

@ -1,368 +0,0 @@
/*
* Copyright (C) 2011-2014 lishid. All rights reserved.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, version 3.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.lishid.orebfuscator.internal.v1_7_R1;
import java.util.Collections;
import java.util.LinkedList;
import java.util.List;
import java.util.ListIterator;
import java.util.Set;
import java.util.concurrent.atomic.AtomicBoolean;
import net.minecraft.server.v1_7_R1.Chunk;
//Volatile
import net.minecraft.server.v1_7_R1.ChunkCoordIntPair;
import net.minecraft.server.v1_7_R1.EntityPlayer;
import net.minecraft.server.v1_7_R1.Packet;
import net.minecraft.server.v1_7_R1.PacketPlayOutMapChunkBulk;
import net.minecraft.server.v1_7_R1.TileEntity;
import net.minecraft.server.v1_7_R1.TileEntitySign;
import net.minecraft.server.v1_7_R1.World;
import net.minecraft.server.v1_7_R1.WorldServer;
import net.minecraft.util.io.netty.channel.Channel;
import org.bukkit.craftbukkit.v1_7_R1.entity.CraftPlayer;
import com.lishid.orebfuscator.Orebfuscator;
import com.lishid.orebfuscator.OrebfuscatorConfig;
import com.lishid.orebfuscator.hook.ChunkProcessingThread;
import com.lishid.orebfuscator.internal.IChunkQueue;
import com.lishid.orebfuscator.internal.IPacket56;
import com.lishid.orebfuscator.internal.InternalAccessor;
import com.lishid.orebfuscator.obfuscation.Calculations;
import com.lishid.orebfuscator.obfuscation.MinecraftBlock;
import com.lishid.orebfuscator.obfuscation.ProximityHider;
public class ChunkQueue extends LinkedList<ChunkCoordIntPair> implements IChunkQueue {
private static final long serialVersionUID = -1928681564741152336L;
List<ChunkCoordIntPair> internalQueue = Collections.synchronizedList(new LinkedList<ChunkCoordIntPair>());
List<ChunkCoordIntPair> outputQueue = Collections.synchronizedList(new LinkedList<ChunkCoordIntPair>());
List<ChunkCoordIntPair> processingQueue = Collections.synchronizedList(new LinkedList<ChunkCoordIntPair>());
PacketPlayOutMapChunkBulk lastPacket;
CraftPlayer player;
Thread thread;
AtomicBoolean kill = new AtomicBoolean(false);
@SuppressWarnings({ "unchecked", "rawtypes" })
public ChunkQueue(CraftPlayer player, List previousEntries) {
this.player = player;
internalQueue.addAll(previousEntries);
}
@Override
public boolean remove(Object arg0) {
return internalQueue.remove(arg0) || processingQueue.remove(arg0) || outputQueue.remove(arg0);
}
// Called when the queue should be cleared
@Override
public void clear() {
// Clear the internal queue
internalQueue.clear();
super.clear();
}
// Called when new chunks are queued
@Override
public boolean add(ChunkCoordIntPair e) {
// Move everything into the internal queue
return internalQueue.add(e);
// return super.add(e);
}
// Called when the list should be sorted
@Override
public Object[] toArray() {
sort();
// Return the old array to be sorted
return internalQueue.toArray();
}
// This checks for chunks in the queue
@Override
public boolean contains(Object o) {
// Checks whether the coords are actually in
return internalQueue.contains(o) || processingQueue.contains(o);
}
@Override
public boolean isEmpty() {
try {
// If the player is gone, then don't waste time
if (player.getHandle().playerConnection.isDisconnected()) {
// Cleanup all queues
internalQueue.clear();
processingQueue.clear();
outputQueue.clear();
lastPacket = null;
}
else {
// Process outputs and inputs
processOutput();
processInput();
}
}
catch (Exception e) {
Orebfuscator.log(e);
}
return true;
}
public void sort() {
// Sort the internal array according to CB - See PlayerChunkMap.movePlayer(EntityPlayer entityplayer)
java.util.Collections.sort(internalQueue, new ChunkCoordComparator(player.getHandle()));
}
@Override
public void FinishedProcessing(IPacket56 packet) {
if (lastPacket != null) {
player.getHandle().playerConnection.sendPacket(lastPacket);
// Remove reference to the packet so it can be freed when possible
lastPacket = null;
}
outputQueue.addAll(processingQueue);
processingQueue.clear();
}
private void processOutput() {
// Chunk packet finished processing, output relevant packets
while (!outputQueue.isEmpty()) {
// Get the chunk coordinate
ChunkCoordIntPair chunk = outputQueue.remove(0);
// Check if the chunk is ready
if (chunk != null && ((WorldServer) player.getHandle().world).isLoaded(chunk.x << 4, 0, chunk.z << 4)) {
// Get all the TileEntities in the chunk
@SuppressWarnings("rawtypes")
List tileEntities = ((WorldServer) player.getHandle().world).getTileEntities(chunk.x * 16, 0, chunk.z * 16, chunk.x * 16 + 16, 256, chunk.z * 16 + 16);
Set<MinecraftBlock> signs = Calculations.getSignsList(player, chunk.x, chunk.z);
for (Object o : tileEntities) {
// Send out packet for the tile entity data
this.updateTileEntity(signs, (TileEntity) o);
}
// Start tracking entities in the chunk
((WorldServer) player.getHandle().world).getTracker().a(player.getHandle(), player.getHandle().world.getChunkAt(chunk.x, chunk.z));
}
// Force an update on ProximityHider
if (OrebfuscatorConfig.UseProximityHider) {
synchronized (ProximityHider.playersToCheck) {
if (!ProximityHider.playersToCheck.containsKey(player))
ProximityHider.playersToCheck.put(player, player.getLocation().add(1, 1, 1));
}
}
}
}
private void processInput() {
// Queue next chunk packet out
if (processingQueue.isEmpty() && !internalQueue.isEmpty()) {
// Check if player's output queue has a lot of stuff waiting to be sent. If so, don't process and wait.
// Each chunk packet with 5 chunks is about 10000 - 25000 bytes
// Try-catch so as to not disrupt chunk sending if something fails
try {
Channel channel = new PlayerHook().getChannel(player);
if (!channel.isWritable()) {
return;
}
}
catch (Exception e) {
Orebfuscator.log(e);
}
// A list to queue chunks
List<Chunk> chunks = new LinkedList<Chunk>();
World world = player.getHandle().world;
WorldServer worldServer = (WorldServer) world;
int i = 0;
// Queue up to 5 chunks
while (internalQueue.size() > i && chunks.size() < 5) {
// Dequeue a chunk from input
ChunkCoordIntPair chunkcoordintpair = internalQueue.get(i);
// Check not null
if (chunkcoordintpair == null) {
internalQueue.remove(i);
continue;
}
// Check if the chunk is loaded
if (world.chunkProvider.isChunkLoaded(chunkcoordintpair.x, chunkcoordintpair.z)) {
Chunk chunk = world.getChunkAt(chunkcoordintpair.x, chunkcoordintpair.z);
// Check if chunk is ready
if (chunk.k()) {
// Load nearby chunks
boolean waitLoad = false;
if (!checkAndLoadChunk(worldServer, chunkcoordintpair.x - 1, chunkcoordintpair.z)) {
waitLoad = true;
}
if (!checkAndLoadChunk(worldServer, chunkcoordintpair.x + 1, chunkcoordintpair.z)) {
waitLoad = true;
}
if (!checkAndLoadChunk(worldServer, chunkcoordintpair.x, chunkcoordintpair.z - 1)) {
waitLoad = true;
}
if (!checkAndLoadChunk(worldServer, chunkcoordintpair.x, chunkcoordintpair.z + 1)) {
waitLoad = true;
}
if (!waitLoad) {
// Queue the chunk for processing
processingQueue.add(chunkcoordintpair);
// Add the chunk to the list to create a packet
chunks.add(chunk);
internalQueue.remove(i);
continue;
}
}
}
i++;
}
// If there are chunks to process
if (!chunks.isEmpty()) {
// Create a packet wrapper
IPacket56 packet = InternalAccessor.Instance.newPacket56();
// Create the actual packet
lastPacket = new PacketPlayOutMapChunkBulk(chunks);
// Put into wrapper
packet.setPacket(lastPacket);
// Send to Processing Thread
ChunkProcessingThread.Queue(packet, player, this);
}
}
}
private void updateTileEntity(Set<MinecraftBlock> signs, TileEntity tileentity) {
if (tileentity != null) {
if (tileentity instanceof TileEntitySign) {
if (signs != null && signs.contains(new MinecraftBlock(tileentity.x, tileentity.y, tileentity.z))) {
return;
}
}
Packet packet = tileentity.getUpdatePacket();
if (packet != null) {
player.getHandle().playerConnection.sendPacket(packet);
}
}
}
private boolean checkAndLoadChunk(WorldServer worldServer, int x, int z) {
if (!worldServer.chunkProvider.isChunkLoaded(x, z)) {
worldServer.chunkProviderServer.getChunkAt(x, z);
return false;
}
return true;
}
@Override
public ListIterator<ChunkCoordIntPair> listIterator() {
return new FakeIterator();
}
private class FakeIterator implements ListIterator<ChunkCoordIntPair> {
@Override
public boolean hasNext() {
return false;
}
@Override
public ChunkCoordIntPair next() {
return null;
}
@Override
public boolean hasPrevious() {
return false;
}
@Override
public ChunkCoordIntPair previous() {
return null;
}
@Override
public int nextIndex() {
return 0;
}
@Override
public int previousIndex() {
return 0;
}
@Override
public void remove() {}
@Override
public void set(ChunkCoordIntPair e) {}
@Override
public void add(ChunkCoordIntPair e) {}
}
private static class ChunkCoordComparator implements java.util.Comparator<ChunkCoordIntPair> {
private int x;
private int z;
public ChunkCoordComparator(EntityPlayer entityplayer) {
x = (int) entityplayer.locX >> 4;
z = (int) entityplayer.locZ >> 4;
}
public int compare(ChunkCoordIntPair a, ChunkCoordIntPair b) {
if (a.equals(b)) {
return 0;
}
// Subtract current position to set center point
int ax = a.x - this.x;
int az = a.z - this.z;
int bx = b.x - this.x;
int bz = b.z - this.z;
int result = ((ax - bx) * (ax + bx)) + ((az - bz) * (az + bz));
if (result != 0) {
return result;
}
if (ax < 0) {
if (bx < 0) {
return bz - az;
}
else {
return -1;
}
}
else {
if (bx < 0) {
return 1;
}
else {
return az - bz;
}
}
}
}
}

View File

@ -1,36 +0,0 @@
/*
* Copyright (C) 2011-2014 lishid. All rights reserved.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, version 3.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.lishid.orebfuscator.internal.v1_7_R1;
import com.lishid.orebfuscator.internal.IMinecraftWorldServer;
import com.lishid.orebfuscator.internal.InternalAccessor;
//Volatile
import net.minecraft.server.v1_7_R1.*;
import org.bukkit.craftbukkit.v1_7_R1.*;
public class MinecraftWorldServer implements IMinecraftWorldServer {
public void Notify(Object world, int x, int y, int z) {
if (world instanceof CraftWorld) {
WorldServer server = (WorldServer) ((CraftWorld) world).getHandle();
server.notify(x, y, z);
}
else {
InternalAccessor.Instance.PrintError();
}
}
}

Some files were not shown because too many files have changed in this diff Show More