Update for 1.4.6

master
lishid 2012-12-23 17:41:57 -05:00
parent 3cac667eb7
commit 850fbc9a92
15 changed files with 979 additions and 59 deletions

View File

@ -36,6 +36,7 @@ public class OrebfuscatorConfig
private static final int CONFIG_VERSION = 9;
private static boolean[] ObfuscateBlocks = new boolean[256];
private static boolean[] DarknessBlocks = new boolean[256];
private static Integer[] RandomBlocks = new Integer[] { 1, 4, 5, 14, 15, 16, 21, 46, 48, 49, 56, 73, 82, 129 };
private static Integer[] RandomBlocks2 = RandomBlocks;
private static List<String> DisabledWorlds = new ArrayList<String>();
@ -47,7 +48,7 @@ public class OrebfuscatorConfig
private static int AirGeneratorMaxChance = 43;
private static int OrebfuscatorPriority = 0;
private static boolean UpdateOnDamage = true;
private static boolean DarknessHideBlocks = true;
private static boolean DarknessHideBlocks = false;
private static boolean NoObfuscationForOps = false;
private static boolean NoObfuscationForPermission = false;
private static boolean LoginNotification = true;
@ -223,7 +224,7 @@ public class OrebfuscatorConfig
public static boolean isBlockTransparent(short id)
{
if(blockTransparencyChecker == null)
if (blockTransparencyChecker == null)
{
blockTransparencyChecker = InternalAccessor.Instance.newBlockTransparency();
}
@ -245,11 +246,11 @@ public class OrebfuscatorConfig
return ObfuscateBlocks[id];
}
public static boolean isDarknessObfuscated(byte id)
public static boolean isDarknessObfuscated(short id)
{
if (id == 52 || id == 54)
return true;
return false;
if (id < 0)
id += 256;
return DarknessBlocks[id];
}
public static boolean isWorldDisabled(String name)
@ -469,17 +470,18 @@ public class OrebfuscatorConfig
}
}
private static void setBlockValues(boolean[] boolArray, List<Integer> blocks)// , boolean removeTransparent)
private static void setBlockValues(boolean[] boolArray, List<Integer> blocks, boolean transparent)
{
for (int i = 0; i < boolArray.length; i++)
{
boolArray[i] = blocks.contains(i);
/*
* if (removeTransparent && boolArray[i] && isBlockTransparent((short) i))
* {
* boolArray[i] = false;
* }
*/
// If block is transparent while we don't want them to, or the other way around
if (transparent != isBlockTransparent((short) i))
{
// Remove it
boolArray[i] = false;
}
}
}
@ -541,8 +543,15 @@ public class OrebfuscatorConfig
AntiTexturePackAndFreecam = getBoolean("Booleans.AntiTexturePackAndFreecam", AntiTexturePackAndFreecam);
Enabled = getBoolean("Booleans.Enabled", Enabled);
CheckForUpdates = getBoolean("Booleans.CheckForUpdates", CheckForUpdates);
setBlockValues(ObfuscateBlocks, getIntList("Lists.ObfuscateBlocks", Arrays.asList(new Integer[] { 14, 15, 16, 21, 54, 56, 73, 74, 129, 130 })));// , true);
//Read block lists
setBlockValues(ObfuscateBlocks, getIntList("Lists.ObfuscateBlocks", Arrays.asList(new Integer[] { 14, 15, 16, 21, 54, 56, 73, 74, 129, 130 })), false);
setBlockValues(DarknessBlocks, getIntList("Lists.DarknessBlocks", Arrays.asList(new Integer[] { 52, 54 })), true);
//Disable worlds
DisabledWorlds = getStringList("Lists.DisabledWorlds", DisabledWorlds);
//Read the cache location
CacheLocation = getString("Strings.CacheLocation", CacheLocation);
CacheFolder = new File(CacheLocation);

View File

@ -35,6 +35,16 @@ public class ChunkProcessingThread extends Thread
private static LinkedList<ChunkProcessingThread> threads = new LinkedList<ChunkProcessingThread>();
static ThreadLocal<Deflater> localDeflater = new ThreadLocal<Deflater>()
{
@Override
protected Deflater initialValue()
{
// Use higher compression level!!
return new Deflater(Deflater.BEST_COMPRESSION);
}
};
static class ChunkProcessingOrder
{
IPacket56 packet;
@ -91,16 +101,6 @@ public class ChunkProcessingThread extends Thread
}
}
static ThreadLocal<Deflater> localDeflater = new ThreadLocal<Deflater>()
{
@Override
protected Deflater initialValue()
{
// Use higher compression level!!
return new Deflater(Deflater.BEST_COMPRESSION);
}
};
AtomicBoolean kill = new AtomicBoolean(false);
@Override

View File

@ -28,11 +28,6 @@ public class NBT implements INBT
{
NBTTagCompound nbt = new NBTTagCompound();
public NBT()
{
}
@Override
public void setInt(String tag, int value)
{
@ -72,7 +67,7 @@ public class NBT implements INBT
@Override
public void Read(DataInput stream)
{
NBTCompressedStreamTools.a(stream);
nbt = NBTCompressedStreamTools.a(stream);
}
@Override

View File

@ -28,11 +28,6 @@ public class NBT implements INBT
{
NBTTagCompound nbt = new NBTTagCompound();
public NBT()
{
}
@Override
public void setInt(String tag, int value)
{
@ -72,7 +67,7 @@ public class NBT implements INBT
@Override
public void Read(DataInput stream)
{
NBTCompressedStreamTools.a(stream);
nbt = NBTCompressedStreamTools.a(stream);
}
@Override

View File

@ -0,0 +1,31 @@
/*
* Copyright (C) 2011-2012 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.IBlockTransparency;
//Volatile
import net.minecraft.server.v1_4_6.*;
public class BlockTransparency implements IBlockTransparency
{
@Override
public boolean isBlockTransparent(int id)
{
return !Block.i(id);
}
}

View File

@ -0,0 +1,114 @@
/*
* Copyright (C) 2011-2012 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.lang.ref.Reference;
import java.lang.ref.SoftReference;
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, Reference<RegionFile>> cachedRegionFiles = new HashMap<File, Reference<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
{
Reference<RegionFile> reference = cachedRegionFiles.get(file);
if (reference != null)
{
RegionFile regionFile = (RegionFile) reference.get();
if (regionFile != null)
{
return regionFile;
}
}
if (!path.exists())
{
path.mkdirs();
}
if (cachedRegionFiles.size() >= OrebfuscatorConfig.getMaxLoadedCacheFiles())
{
clearCache();
}
RegionFile regionFile = new RegionFile(file);
cachedRegionFiles.put(file, new SoftReference<RegionFile>(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 (Reference<RegionFile> reference : cachedRegionFiles.values())
{
try
{
RegionFile regionFile = (RegionFile) reference.get();
if (regionFile != null)
regionFile.c();
}
catch (Exception e)
{
e.printStackTrace();
}
}
cachedRegionFiles.clear();
}
}

View File

@ -0,0 +1,269 @@
/*
* Copyright (C) 2011-2012 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;
//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);
}
// Called when the queue should be cleared
@Override
public void clear()
{
// Clear the internal queue
internalQueue.clear();
// Cancel processing of any queue'd packets
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 the internal array according to CB - See PlayerManager.movePlayer(EntityPlayer entityplayer)
final int x = player.getLocation().getChunk().getX();
final int z = player.getLocation().getChunk().getZ();
java.util.Collections.sort(internalQueue, new java.util.Comparator<ChunkCoordIntPair>()
{
public int compare(ChunkCoordIntPair a, ChunkCoordIntPair b)
{
return Math.max(Math.abs(a.x - x), Math.abs(a.z - z)) - Math.max(Math.abs(b.x - x), Math.abs(b.z - z));
}
});
// 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;
}
@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);
// 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())
{
// 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)
{
}
}
}

View File

@ -0,0 +1,40 @@
/*
* Copyright (C) 2011-2012 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

@ -0,0 +1,79 @@
/*
* Copyright (C) 2011-2012 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 setInt(String tag, int value)
{
nbt.setInt(tag, value);
}
@Override
public void setLong(String tag, long value)
{
nbt.setLong(tag, value);
}
@Override
public void setByteArray(String tag, byte[] value)
{
nbt.setByteArray(tag, value);
}
@Override
public int getInt(String tag)
{
return nbt.getInt(tag);
}
@Override
public long getLong(String tag)
{
return nbt.getLong(tag);
}
@Override
public byte[] getByteArray(String tag)
{
return nbt.getByteArray(tag);
}
@Override
public void Read(DataInput stream)
{
nbt = NBTCompressedStreamTools.a(stream);
}
@Override
public void Write(DataOutput stream)
{
NBTCompressedStreamTools.a(nbt, stream);
}
}

View File

@ -0,0 +1,52 @@
/*
* Copyright (C) 2011-2012 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

@ -0,0 +1,93 @@
/*
* Copyright (C) 2011-2012 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

@ -0,0 +1,112 @@
/*
* Copyright (C) 2011-2012 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.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 byte[][] getInflatedBuffers()
{
return (byte[][]) ReflectionHelper.getPrivateField(packet, "inflatedBuffers");
}
@Override
public byte[] getBuildBuffer()
{
return (byte[]) ReflectionHelper.getPrivateField(Packet56MapChunkBulk.class, packet, "buildBuffer");
}
@Override
public byte[] getOutputBuffer()
{
return (byte[]) ReflectionHelper.getPrivateField(Packet56MapChunkBulk.class, packet, "buffer");
}
@Override
public void compress(Deflater deflater)
{
if (getOutputBuffer() != null)
{
return;
}
byte[] buildBuffer = getBuildBuffer();
deflater.reset();
deflater.setInput(buildBuffer);
deflater.finish();
byte[] buffer = new byte[buildBuffer.length + 100];
ReflectionHelper.setPrivateField(packet, "buffer", buffer);
ReflectionHelper.setPrivateField(packet, "size", deflater.deflate(buffer));
}
}

View File

@ -0,0 +1,74 @@
/*
* Copyright (C) 2011-2012 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.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
{
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);
@SuppressWarnings("unchecked")
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);
}
}
}
public void HookChunkQueue(Player p)
{
CraftPlayer player = (CraftPlayer) p;
ReflectionHelper.setPrivateFinal(player.getHandle(), "chunkCoordIntPairQueue", new ChunkQueue(player, player.getHandle().chunkCoordIntPairQueue));
}
}

View File

@ -26,6 +26,7 @@ import com.lishid.orebfuscator.OrebfuscatorConfig;
import com.lishid.orebfuscator.cache.ObfuscatedCachedChunk;
import com.lishid.orebfuscator.internal.IPacket51;
import com.lishid.orebfuscator.internal.IPacket56;
import com.lishid.orebfuscator.internal.InternalAccessor;
public class Calculations
{
@ -42,11 +43,19 @@ public class Calculations
@Override
protected Deflater initialValue()
{
// Use higher compression level!!
// Not used from orebfuscator thread, normal compression instead
return new Deflater(Deflater.DEFAULT_COMPRESSION);
}
};
public static void Obfuscate(Object packet, Player player)
{
// Assuming that NoLagg will pass a Packet51
IPacket51 packet51 = InternalAccessor.Instance.newPacket51();
packet51.setPacket(packet);
Calculations.Obfuscate(packet51, player);
}
public static void Obfuscate(IPacket56 packet, Player player)
{
if (packet.getOutputBuffer() != null)
@ -179,6 +188,9 @@ public class Calculations
}
}
static int chunks = 0;
static int cached = 0;
public static byte[] Obfuscate(ChunkInfo info, byte[] original)
{
// Used for caching
@ -200,9 +212,13 @@ public class Calculations
// Copy data into buffer
System.arraycopy(info.data, info.startIndex, info.buffer, 0, info.blockSize);
chunks++;
// Caching
if (OrebfuscatorConfig.getUseCache())
{
// Sanitize buffer for caching
PrepareBufferForCaching(info.buffer, info.blockSize);
// Get cache folder
File cacheFolder = new File(OrebfuscatorConfig.getCacheFolder(), info.world.getName());
// Create cache objects
@ -215,15 +231,15 @@ public class Calculations
cache.Read();
long storedHash = cache.getHash();
if (storedHash == hash)
if (storedHash == hash && cache.data != null)
{
// Get data
byte[] data = cache.data;
if (data != null)
{
// Hash match, use the cached data instead and skip calculations
return data;
}
cached++;
// Caching done, de-sanitize buffer
RepaintChunkToBuffer(cache.data, info.data, info.startIndex, info.blockSize);
// Hash match, use the cached data instead and skip calculations
return cache.data;
}
}
@ -301,19 +317,6 @@ public class Calculations
}
}
// Check if the block should be obfuscated because of the darkness
if (!obfuscate && OrebfuscatorConfig.getDarknessHideBlocks() && OrebfuscatorConfig.isDarknessObfuscated(data))
{
if (initialRadius == 0)
{
obfuscate = true;
}
else if (!areAjacentBlocksBright(info, startX + x, (i << 4) + y, startZ + z, initialRadius))
{
obfuscate = true;
}
}
// Check if the block is obfuscated
if (obfuscate)
{
@ -341,6 +344,16 @@ public class Calculations
}
}
// Check if the block should be obfuscated because of the darkness
if (!obfuscate && OrebfuscatorConfig.getDarknessHideBlocks() && OrebfuscatorConfig.isDarknessObfuscated(data))
{
if (!areAjacentBlocksBright(info, startX + x, (i << 4) + y, startZ + z, 1))
{
// Hide block, setting it to air
info.buffer[index] = 0;
}
}
tempIndex++;
}
}
@ -368,9 +381,53 @@ public class Calculations
cache.free();
}
// Caching done, de-sanitize buffer
if (OrebfuscatorConfig.getUseCache())
{
RepaintChunkToBuffer(info.buffer, info.data, info.startIndex, info.blockSize);
}
return info.buffer;
}
private static byte[] cacheMap = new byte[256];
static
{
for (int i = 0; i < 256; i++)
{
cacheMap[i] = (byte) i;
if (OrebfuscatorConfig.isBlockTransparent((short) i))
{
cacheMap[i] = 0;
}
}
}
private static void PrepareBufferForCaching(byte[] data, int length)
{
for (int i = 0; i < length; i++)
{
if (!OrebfuscatorConfig.getDarknessHideBlocks() || !OrebfuscatorConfig.isDarknessObfuscated(data[i]))
{
data[i] = cacheMap[((int) data[i] + 256) % 256];
}
}
}
private static void RepaintChunkToBuffer(byte[] data, byte[] original, int start, int length)
{
for (int i = 0; i < length; i++)
{
if (data[i] == 0 && original[start + i] != 0)
{
if (OrebfuscatorConfig.isBlockTransparent(original[start + i]))
{
data[i] = original[start + i];
}
}
}
}
public static boolean areAjacentBlocksTransparent(ChunkInfo info, int x, int y, int z, int countdown)
{
byte id = 0;

View File

@ -1,6 +1,6 @@
name: Orebfuscator
main: com.lishid.orebfuscator.Orebfuscator
version: 1.7.8
version: 1.8.1
author: lishid
softdepend: [Spout, ProtocolLib]
load: startup