support BuildCraft servers
This commit is contained in:
parent
7238761ce1
commit
495c15d287
|
@ -34,7 +34,7 @@ public class ChunkObfuscator
|
||||||
public int len;
|
public int len;
|
||||||
public byte[] data;
|
public byte[] data;
|
||||||
|
|
||||||
public void obfuscate(World world, int chunkX, int chunkZ, int sectionLSB, int sectionMSB, byte[] data)
|
public int obfuscate(World world, int chunkX, int chunkZ, boolean hasSky, int sectionLSB, int sectionMSB, byte[] data, int pos)
|
||||||
{
|
{
|
||||||
this.startX = chunkX << 4;
|
this.startX = chunkX << 4;
|
||||||
this.startZ = chunkZ << 4;
|
this.startZ = chunkZ << 4;
|
||||||
|
@ -43,7 +43,6 @@ public class ChunkObfuscator
|
||||||
int countLSB = 0;
|
int countLSB = 0;
|
||||||
len = 0;
|
len = 0;
|
||||||
int l;
|
int l;
|
||||||
int pos = 0;
|
|
||||||
int i;
|
int i;
|
||||||
for (i = 0; i < 16; ++i)
|
for (i = 0; i < 16; ++i)
|
||||||
{
|
{
|
||||||
|
@ -81,7 +80,8 @@ public class ChunkObfuscator
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
if (!world.provider.hasNoSky)
|
//if (!world.provider.hasNoSky)
|
||||||
|
if (hasSky)
|
||||||
{
|
{
|
||||||
// åñëè åñòü íåáî, òî â áóôåðå áóäåò ìàññèâ ExtendedBlockStorage.skylightArray
|
// åñëè åñòü íåáî, òî â áóôåðå áóäåò ìàññèâ ExtendedBlockStorage.skylightArray
|
||||||
pos += countLSB * 2048;
|
pos += countLSB * 2048;
|
||||||
|
@ -101,7 +101,9 @@ public class ChunkObfuscator
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Options.worldOptions = Options.getWorldOptions(world);
|
// biome info
|
||||||
|
pos += 256;
|
||||||
|
|
||||||
for (i = 0; i < len; i++)
|
for (i = 0; i < len; i++)
|
||||||
{
|
{
|
||||||
if (offsetsLSB[i] > -1)
|
if (offsetsLSB[i] > -1)
|
||||||
|
@ -122,6 +124,8 @@ public class ChunkObfuscator
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return pos;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -72,6 +72,19 @@ public class Fields
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static void setValue(Object instance, Field field, Object value)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
field.setAccessible(true);
|
||||||
|
field.set(instance, value);
|
||||||
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public static class NetworkManager
|
public static class NetworkManager
|
||||||
{
|
{
|
||||||
public static String getOutboundPacketsQueueName()
|
public static String getOutboundPacketsQueueName()
|
||||||
|
|
|
@ -1,16 +1,20 @@
|
||||||
package Orebfuscator;
|
package Orebfuscator;
|
||||||
|
|
||||||
import java.lang.reflect.Field;
|
import java.lang.reflect.Field;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
|
||||||
|
import net.minecraft.network.EnumConnectionState;
|
||||||
import net.minecraft.network.play.server.S26PacketMapChunkBulk;
|
import net.minecraft.network.play.server.S26PacketMapChunkBulk;
|
||||||
import net.minecraft.server.MinecraftServer;
|
import net.minecraft.server.MinecraftServer;
|
||||||
import net.minecraft.world.World;
|
import net.minecraft.world.World;
|
||||||
|
import net.minecraft.world.chunk.Chunk;
|
||||||
|
|
||||||
public class MapChunkBulkObfuscator
|
public class MapChunkBulkObfuscator
|
||||||
{
|
{
|
||||||
public static Field fieldChunkX;
|
public static Field fieldChunkX;
|
||||||
public static Field fieldChunkZ;
|
public static Field fieldChunkZ;
|
||||||
|
|
||||||
|
public static Field fieldHasSky;
|
||||||
|
|
||||||
// 1110011 - íàáîð áëîêîâ (ExtendedBlockStorage.blockLSBArray) ïî âûñîòå (1 - åñòü áëîê, 0 - íåò áëîêà)
|
// 1110011 - íàáîð áëîêîâ (ExtendedBlockStorage.blockLSBArray) ïî âûñîòå (1 - åñòü áëîê, 0 - íåò áëîêà)
|
||||||
public static Field fieldStatusLSB = null;
|
public static Field fieldStatusLSB = null;
|
||||||
|
@ -20,19 +24,26 @@ public class MapChunkBulkObfuscator
|
||||||
|
|
||||||
// -- ìàññèâ äàííûõ
|
// -- ìàññèâ äàííûõ
|
||||||
public static Field fieldData;
|
public static Field fieldData;
|
||||||
|
public static Field field_149268_i;
|
||||||
|
|
||||||
public static ChunkObfuscator info;
|
public static ChunkObfuscator info;
|
||||||
|
|
||||||
public static void obfuscate(World world, S26PacketMapChunkBulk packet)
|
public static S26PacketMapChunkBulk obfuscate(World world, S26PacketMapChunkBulk packet)
|
||||||
{
|
{
|
||||||
if (fieldStatusLSB == null)
|
if (fieldStatusLSB == null)
|
||||||
{
|
{
|
||||||
fieldChunkX = Fields.getField(packet, "field_149266_a");
|
fieldChunkX = Fields.getField(packet, "field_149266_a");
|
||||||
fieldChunkZ = Fields.getField(packet, "field_149264_b");
|
fieldChunkZ = Fields.getField(packet, "field_149264_b");
|
||||||
|
|
||||||
|
fieldHasSky = Fields.getField(packet, "field_149267_h");
|
||||||
|
|
||||||
fieldStatusLSB = Fields.getField(packet, "field_149265_c");
|
fieldStatusLSB = Fields.getField(packet, "field_149265_c");
|
||||||
fieldStatusMSB = Fields.getField(packet, "field_149262_d");
|
fieldStatusMSB = Fields.getField(packet, "field_149262_d");
|
||||||
fieldData = Fields.getField(packet, "field_149260_f");
|
fieldData = Fields.getField(packet, "field_149260_f");
|
||||||
|
field_149268_i = Fields.getField(packet, "field_149268_i");
|
||||||
|
|
||||||
|
byte[] data = (byte[]) Fields.getValue(packet, field_149268_i);
|
||||||
|
Options.isBuildCraft = data.length > 0; // Forge keep this array empty
|
||||||
|
|
||||||
info = new ChunkObfuscator();
|
info = new ChunkObfuscator();
|
||||||
}
|
}
|
||||||
|
@ -40,13 +51,30 @@ public class MapChunkBulkObfuscator
|
||||||
|
|
||||||
int[] chunkX = (int[]) Fields.getValue(packet, fieldChunkX);
|
int[] chunkX = (int[]) Fields.getValue(packet, fieldChunkX);
|
||||||
int[] chunkZ = (int[]) Fields.getValue(packet, fieldChunkZ);
|
int[] chunkZ = (int[]) Fields.getValue(packet, fieldChunkZ);
|
||||||
|
boolean hasSky = (Boolean) Fields.getValue(packet, fieldHasSky);
|
||||||
int[] statusLSB = (int[]) Fields.getValue(packet, fieldStatusLSB);
|
int[] statusLSB = (int[]) Fields.getValue(packet, fieldStatusLSB);
|
||||||
int[] statusMSB = (int[]) Fields.getValue(packet, fieldStatusMSB);
|
int[] statusMSB = (int[]) Fields.getValue(packet, fieldStatusMSB);
|
||||||
byte[][] dataArray = (byte[][]) Fields.getValue(packet, fieldData);
|
|
||||||
|
|
||||||
|
Options.worldOptions = Options.getWorldOptions(world);
|
||||||
|
|
||||||
|
if (Options.isBuildCraft)
|
||||||
|
{
|
||||||
|
byte[] data = (byte[]) Fields.getValue(packet, field_149268_i);
|
||||||
|
int pos = 0;
|
||||||
for (int i = 0; i < statusLSB.length; i++)
|
for (int i = 0; i < statusLSB.length; i++)
|
||||||
{
|
{
|
||||||
info.obfuscate(world, chunkX[i], chunkZ[i], statusLSB[i], statusMSB[i], dataArray[i]);
|
pos = info.obfuscate(world, chunkX[i], chunkZ[i], hasSky, statusLSB[i], statusMSB[i], data, pos);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
byte[][] dataArray = (byte[][]) Fields.getValue(packet, fieldData);
|
||||||
|
for (int i = 0; i < statusLSB.length; i++)
|
||||||
|
{
|
||||||
|
info.obfuscate(world, chunkX[i], chunkZ[i], hasSky, statusLSB[i], statusMSB[i], dataArray[i], 0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return packet;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
package Orebfuscator;
|
package Orebfuscator;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
|
import java.net.URLClassLoader;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
|
@ -134,47 +135,52 @@ public class Options
|
||||||
if (world.provider instanceof WorldProviderSurface)
|
if (world.provider instanceof WorldProviderSurface)
|
||||||
{
|
{
|
||||||
options.load(config, new String[] {
|
options.load(config, new String[] {
|
||||||
getID(Blocks.gold_ore, 1),
|
getID(Blocks.air, 1),
|
||||||
getID(Blocks.iron_ore, 1),
|
getID(Blocks.gold_ore, 16),
|
||||||
getID(Blocks.coal_ore, 1),
|
getID(Blocks.iron_ore, 16),
|
||||||
getID(Blocks.lapis_ore, 1),
|
getID(Blocks.coal_ore, 16),
|
||||||
getID(Blocks.diamond_ore, 1),
|
getID(Blocks.lapis_ore, 16),
|
||||||
getID(Blocks.redstone_ore, 1),
|
getID(Blocks.diamond_ore, 16),
|
||||||
getID(Blocks.emerald_ore, 1),
|
getID(Blocks.redstone_ore, 16),
|
||||||
getID(Blocks.mossy_cobblestone, 1),
|
getID(Blocks.emerald_ore, 16),
|
||||||
getID(Blocks.mob_spawner, 100),
|
getID(Blocks.mossy_cobblestone, 16),
|
||||||
|
getID(Blocks.mob_spawner, 1000),
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
if (world.provider instanceof WorldProviderHell)
|
if (world.provider instanceof WorldProviderHell)
|
||||||
{
|
{
|
||||||
options.load(config, new String[] {
|
options.load(config, new String[] {
|
||||||
getID(Blocks.glowstone, 1),
|
getID(Blocks.air, 1),
|
||||||
getID(Blocks.netherrack, 1),
|
getID(Blocks.glowstone, 16),
|
||||||
getID(Blocks.nether_brick, 1),
|
getID(Blocks.netherrack, 16),
|
||||||
getID(Blocks.nether_brick_fence, 1),
|
getID(Blocks.nether_brick, 16),
|
||||||
getID(Blocks.nether_brick_stairs, 1),
|
getID(Blocks.nether_brick_fence, 16),
|
||||||
getID(Blocks.nether_wart, 1),
|
getID(Blocks.nether_brick_stairs, 16),
|
||||||
getID(Blocks.quartz_ore, 1),
|
getID(Blocks.nether_wart, 16),
|
||||||
|
getID(Blocks.quartz_ore, 16),
|
||||||
|
getID(Blocks.mob_spawner, 1000),
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
if (world.provider instanceof WorldProviderEnd)
|
if (world.provider instanceof WorldProviderEnd)
|
||||||
{
|
{
|
||||||
options.load(config, new String[] {
|
options.load(config, new String[] {
|
||||||
getID(Blocks.end_stone, 1),
|
getID(Blocks.air, 1),
|
||||||
|
getID(Blocks.end_stone, 16),
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
options.load(config, new String[] {
|
options.load(config, new String[] {
|
||||||
getID(Blocks.gold_ore, 1),
|
getID(Blocks.air, 1),
|
||||||
getID(Blocks.iron_ore, 1),
|
getID(Blocks.gold_ore, 16),
|
||||||
getID(Blocks.coal_ore, 1),
|
getID(Blocks.iron_ore, 16),
|
||||||
getID(Blocks.lapis_ore, 1),
|
getID(Blocks.coal_ore, 16),
|
||||||
getID(Blocks.diamond_ore, 1),
|
getID(Blocks.lapis_ore, 16),
|
||||||
getID(Blocks.redstone_ore, 1),
|
getID(Blocks.diamond_ore, 16),
|
||||||
getID(Blocks.emerald_ore, 1),
|
getID(Blocks.redstone_ore, 16),
|
||||||
getID(Blocks.mossy_cobblestone, 1),
|
getID(Blocks.emerald_ore, 16),
|
||||||
|
getID(Blocks.mossy_cobblestone, 16),
|
||||||
getID(Blocks.mob_spawner, 1000),
|
getID(Blocks.mob_spawner, 1000),
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -191,6 +197,8 @@ public class Options
|
||||||
|
|
||||||
public static boolean[] transparentBlocks = new boolean[4096];
|
public static boolean[] transparentBlocks = new boolean[4096];
|
||||||
|
|
||||||
|
public static boolean isBuildCraft = false;
|
||||||
|
|
||||||
public static class Offset
|
public static class Offset
|
||||||
{
|
{
|
||||||
public int x;
|
public int x;
|
||||||
|
@ -207,6 +215,20 @@ public class Options
|
||||||
configFile = new File(modDir, Orebfuscator.MODID + ".cfg");
|
configFile = new File(modDir, Orebfuscator.MODID + ".cfg");
|
||||||
Configuration config = new Configuration(configFile, false);
|
Configuration config = new Configuration(configFile, false);
|
||||||
|
|
||||||
|
/*
|
||||||
|
ClassLoader loader = (ClassLoader)Thread.currentThread().getContextClassLoader();
|
||||||
|
try
|
||||||
|
{
|
||||||
|
loader.loadClass("org.bukkit.craftbukkit.CraftWorld");
|
||||||
|
isBuildCraft = true;
|
||||||
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
isBuildCraft = false;
|
||||||
|
}
|
||||||
|
isBuildCraft = config.getBoolean("isBuildCraft", "Options", isBuildCraft, "BuildCraft and Forge have different algorithms update chunks");
|
||||||
|
*/
|
||||||
|
|
||||||
int updateRadius = config.getInt("updateRadius", "Options", 2, 1, 5, "How much blocks update after block break");
|
int updateRadius = config.getInt("updateRadius", "Options", 2, 1, 5, "How much blocks update after block break");
|
||||||
for (int x = -updateRadius; x <= updateRadius; x++)
|
for (int x = -updateRadius; x <= updateRadius; x++)
|
||||||
{
|
{
|
||||||
|
|
|
@ -1,11 +1,14 @@
|
||||||
package Orebfuscator;
|
package Orebfuscator;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
|
import java.lang.reflect.Method;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
|
|
||||||
import net.minecraft.block.Block;
|
import net.minecraft.block.Block;
|
||||||
import net.minecraft.entity.player.EntityPlayerMP;
|
import net.minecraft.entity.player.EntityPlayerMP;
|
||||||
|
import net.minecraft.network.EnumConnectionState;
|
||||||
import net.minecraft.network.NetHandlerPlayServer;
|
import net.minecraft.network.NetHandlerPlayServer;
|
||||||
|
import net.minecraft.world.World;
|
||||||
import net.minecraftforge.common.MinecraftForge;
|
import net.minecraftforge.common.MinecraftForge;
|
||||||
import net.minecraftforge.common.config.Configuration;
|
import net.minecraftforge.common.config.Configuration;
|
||||||
import cpw.mods.fml.common.FMLCommonHandler;
|
import cpw.mods.fml.common.FMLCommonHandler;
|
||||||
|
@ -23,7 +26,7 @@ import cpw.mods.fml.relauncher.ReflectionHelper;
|
||||||
public class Orebfuscator
|
public class Orebfuscator
|
||||||
{
|
{
|
||||||
public static final String MODID = "Orebfuscator";
|
public static final String MODID = "Orebfuscator";
|
||||||
public static final String VERSION = "0.3";
|
public static final String VERSION = "0.4";
|
||||||
|
|
||||||
@EventHandler
|
@EventHandler
|
||||||
public void init(FMLInitializationEvent event)
|
public void init(FMLInitializationEvent event)
|
||||||
|
|
|
@ -28,14 +28,14 @@ public class ProxyChannel implements Channel
|
||||||
this.player = player;
|
this.player = player;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void updateMsg(Object msg)
|
public Object updateMsg(Object msg)
|
||||||
{
|
{
|
||||||
if (msg instanceof S26PacketMapChunkBulk)
|
if (msg instanceof S26PacketMapChunkBulk)
|
||||||
{
|
{
|
||||||
S26PacketMapChunkBulk packet = (S26PacketMapChunkBulk)msg;
|
S26PacketMapChunkBulk packet = (S26PacketMapChunkBulk)msg;
|
||||||
MapChunkBulkObfuscator.obfuscate(player.worldObj, packet);
|
return MapChunkBulkObfuscator.obfuscate(player.worldObj, packet);
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
return msg;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -121,7 +121,7 @@ public class ProxyChannel implements Channel
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ChannelFuture writeAndFlush(Object msg) {
|
public ChannelFuture writeAndFlush(Object msg) {
|
||||||
this.updateMsg(msg);
|
msg = this.updateMsg(msg);
|
||||||
return this.channel.writeAndFlush(msg);
|
return this.channel.writeAndFlush(msg);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue