base version
This commit is contained in:
parent
bdce41d9a6
commit
c307ff5387
110
java/Orebfuscator/BlockChange.java
Normal file
110
java/Orebfuscator/BlockChange.java
Normal file
|
@ -0,0 +1,110 @@
|
|||
package Orebfuscator;
|
||||
|
||||
import io.netty.channel.Channel;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
import java.util.HashSet;
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.entity.player.EntityPlayerMP;
|
||||
import net.minecraft.init.Blocks;
|
||||
import net.minecraft.network.play.server.S23PacketBlockChange;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
public class BlockChange
|
||||
{
|
||||
public static Field fieldPositionX = null;
|
||||
public static Field fieldPositionY = null;
|
||||
public static Field fieldPositionZ = null;
|
||||
public static HashSet<Integer> list = new HashSet();
|
||||
|
||||
public static int baseX;
|
||||
public static int baseY;
|
||||
public static int baseZ;
|
||||
|
||||
public static byte offset = 2;
|
||||
public static int startPos;
|
||||
|
||||
public static void parse(World world, Channel channel, S23PacketBlockChange packet)
|
||||
{
|
||||
if (fieldPositionX == null)
|
||||
{
|
||||
fieldPositionX = Fields.getField(packet, "field_148887_a");
|
||||
fieldPositionY = Fields.getField(packet, "field_148885_b");
|
||||
fieldPositionZ = Fields.getField(packet, "field_148886_c");
|
||||
}
|
||||
|
||||
int x = (Integer) Fields.getValue(packet, fieldPositionX);
|
||||
int y = (Integer) Fields.getValue(packet, fieldPositionY);
|
||||
int z = (Integer) Fields.getValue(packet, fieldPositionZ);
|
||||
|
||||
// èñïîëüçóåì áàçîâóþ òî÷êó, ÷òîáû â äàëüíåéøåì âûñ÷èòûâàòü ñìåùåíèÿ îáíîâëÿåìûõ áëîêîâ
|
||||
// ñìåùåíèÿ áóäåì ñâîäèòü â îäèí int è õðàíèòü â HashSet
|
||||
baseX = x - offset;
|
||||
baseY = y - offset;
|
||||
baseZ = z - offset;
|
||||
|
||||
x = offset;
|
||||
y = offset;
|
||||
z = offset;
|
||||
|
||||
startPos = (offset << 16) | (offset << 8) | offset;
|
||||
|
||||
list.clear();
|
||||
updateAjacentBlocks(world, offset, offset, offset, offset + 1);
|
||||
for (int pos : list)
|
||||
{
|
||||
x = baseX + (pos >> 16 & 255);
|
||||
y = baseY + (pos >> 8 & 255);
|
||||
z = baseZ + (pos & 255);
|
||||
|
||||
world.markBlockForUpdate(x, y, z);
|
||||
}
|
||||
}
|
||||
|
||||
public static boolean isTransparent(World world, int x, int y, int z)
|
||||
{
|
||||
int pos = (x << 16) | (y << 8) | z;
|
||||
if (pos == startPos)
|
||||
return false;
|
||||
|
||||
Block block = world.getBlock(baseX + x, baseY + y, baseZ + z);
|
||||
return Orebfuscator.isBlockTransparent(Block.getIdFromBlock(block));
|
||||
}
|
||||
|
||||
public static boolean needUpdate(World world, int x, int y, int z)
|
||||
{
|
||||
int pos = (x << 16) | (y << 8) | z;
|
||||
if (pos == startPos)
|
||||
return false;
|
||||
|
||||
return !(
|
||||
isTransparent(world, x - 1, y, z) || isTransparent(world, x + 1, y, z) ||
|
||||
isTransparent(world, x, y - 1, z) || isTransparent(world, x, y + 1, z) ||
|
||||
isTransparent(world, x, y, z - 1) || isTransparent(world, x, y, z + 1)
|
||||
);
|
||||
}
|
||||
|
||||
public static boolean updateAjacentBlocks(World world, int x, int y, int z, int step)
|
||||
{
|
||||
if (step == 0)
|
||||
return false;
|
||||
|
||||
int pos = (x << 16) | (y << 8) | z;
|
||||
if (list.contains(pos))
|
||||
return false;
|
||||
|
||||
if (needUpdate(world, x, y, z))
|
||||
list.add(pos);
|
||||
|
||||
step--;
|
||||
updateAjacentBlocks(world, x - 1, y, z, step);
|
||||
updateAjacentBlocks(world, x + 1, y, z, step);
|
||||
updateAjacentBlocks(world, x, y - 1, z, step);
|
||||
updateAjacentBlocks(world, x, y + 1, z, step);
|
||||
updateAjacentBlocks(world, x, y, z - 1, step);
|
||||
updateAjacentBlocks(world, x, y, z + 1, step);
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
|
@ -1,7 +1,9 @@
|
|||
package Orebfuscator;
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.network.play.server.S26PacketMapChunkBulk;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraft.world.chunk.Chunk;
|
||||
|
||||
public class ChunkInfo
|
||||
{
|
||||
|
@ -10,7 +12,7 @@ public class ChunkInfo
|
|||
//public boolean[] listLSB = new boolean[16];
|
||||
//public boolean[] listMSB = new boolean[16];
|
||||
|
||||
// offsetsLSB[] - ñîäåðæèò ñïèñîê ïîçèöèé, ñ êîòîðûõ íà÷èíàþòñÿ áëîêè ðàçìåðîì 16x16x16 ñîäåðæàùèå ïåðâûå 8 áèò BlockID
|
||||
// offsetsLSB[] - ñîäåðæèò ñïèñîê ñåêöèé, ñ êîòîðûõ íà÷èíàþòñÿ áëîêè ðàçìåðîì 16x16x16 ñîäåðæàùèå ïåðâûå 8 áèò BlockID
|
||||
// ðàçìåð ñåêöèè 16*16*16 = 4096 áàéò
|
||||
public int[] offsetsLSB = new int[16];
|
||||
|
||||
|
@ -24,11 +26,18 @@ public class ChunkInfo
|
|||
// NibbleArray ExtendedBlockStorage.blockMSBArray
|
||||
public int[] offsetsMSB = new int[16];
|
||||
|
||||
public int chunkX;
|
||||
public int chunkZ;
|
||||
|
||||
// Ìàêñèìàëüíûé èíäåêñ+1 ñåêöèè
|
||||
public int len;
|
||||
public byte[] data;
|
||||
|
||||
public void parse(World world, byte[] data, int sectionLSB, int sectionMSB)
|
||||
public void parse(World world, int chunkX, int chunkZ, int sectionLSB, int sectionMSB, byte[] data)
|
||||
{
|
||||
this.chunkX = chunkX;
|
||||
this.chunkZ = chunkZ;
|
||||
|
||||
this.data = data;
|
||||
int countLSB = 0;
|
||||
len = 0;
|
||||
|
@ -61,15 +70,6 @@ public class ChunkInfo
|
|||
}
|
||||
}
|
||||
|
||||
for (i = 0; i < len; i++)
|
||||
{
|
||||
if (offsetsLSB[i] > -1)
|
||||
{
|
||||
offsetsMetadata[i] = pos;
|
||||
pos += 2048;
|
||||
}
|
||||
}
|
||||
|
||||
for (i = 0; i < len; i++)
|
||||
{
|
||||
if (offsetsLSB[i] > -1)
|
||||
|
@ -110,16 +110,17 @@ public class ChunkInfo
|
|||
{
|
||||
for (int z = 0; z < 16; z++)
|
||||
{
|
||||
/*
|
||||
if ((x > 0 && x < 16) && (y == 0 || y == 15) && (z == 0 || z == 15))
|
||||
setBlockID(x, y, z, 1);
|
||||
if ((x == 0 || x == 15) && (y > 0 || y < 16) && (z == 0 || z == 15))
|
||||
setBlockID(x, y, z, 1);
|
||||
if ((x == 0 || x == 15) && (y == 0 || y == 15) && (z > 0 || z < 16))
|
||||
setBlockID(x, y, z, 1);
|
||||
|
||||
if (!Orebfuscator.isBlockTransparent(getBlockID(x, y, z)))
|
||||
*/
|
||||
if (neetObfuscate(world, x, i << 4 | y, z))
|
||||
{
|
||||
//data[pos + n] = 1;
|
||||
setBlockID(x, i << 4 | y, z, 57);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -131,14 +132,14 @@ public class ChunkInfo
|
|||
/**
|
||||
* Returns the block corresponding to the given coordinates inside a chunk.
|
||||
*/
|
||||
public int getBlockID(int x, int y, int z)
|
||||
public int getBlockID(World world, int x, int y, int z)
|
||||
{
|
||||
int section = y >> 4;
|
||||
if (this.offsetsLSB[section] > -1)
|
||||
{
|
||||
y = y & 15;
|
||||
|
||||
int id = this.data[this.offsetsLSB[section] + y << 8 | z << 4 | x] & 255;
|
||||
int id = this.data[this.offsetsLSB[section] + (y << 8 | z << 4 | x)] & 255;
|
||||
if (this.offsetsMSB[section] > -1)
|
||||
{
|
||||
int l = y << 4 | z << 4 | x;
|
||||
|
@ -146,6 +147,8 @@ public class ChunkInfo
|
|||
int j1 = l & 1;
|
||||
id |= j1 == 0 ? this.data[this.offsetsMSB[section] + i1] & 15 : this.data[this.offsetsMSB[section] + i1] >> 4 & 15;
|
||||
}
|
||||
|
||||
return id;
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
@ -158,7 +161,7 @@ public class ChunkInfo
|
|||
{
|
||||
y = y & 15;
|
||||
|
||||
this.data[this.offsetsLSB[section] + y << 8 | z << 4 | x] = (byte) (blockID & 255);
|
||||
this.data[this.offsetsLSB[section] + (y << 8 | z << 4 | x)] = (byte) (blockID & 255);
|
||||
if (this.offsetsMSB[section] > -1)
|
||||
{
|
||||
int l = y << 4 | z << 4 | x;
|
||||
|
@ -176,4 +179,39 @@ public class ChunkInfo
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
public boolean isTransparent(World world, int x, int y, int z)
|
||||
{
|
||||
if (y < 0 || y > 255)
|
||||
return true;
|
||||
|
||||
if (x < 0 || x > 15 || z < 0 || z > 15)
|
||||
{
|
||||
/*
|
||||
Block block = world.getBlock((this.chunkX << 4) | x, y, (this.chunkZ << 4) | z);
|
||||
return Orebfuscator.isBlockTransparent(Block.getIdFromBlock(block));
|
||||
*/
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
return Orebfuscator.isBlockTransparent(getBlockID(world, x, y, z));
|
||||
}
|
||||
|
||||
public boolean neetObfuscate(World world, int x, int y, int z)
|
||||
{
|
||||
if (isTransparent(world, x, y, z))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
return !(
|
||||
isTransparent(world, x - 1, y, z) ||
|
||||
isTransparent(world, x + 1, y, z) ||
|
||||
isTransparent(world, x, y - 1, z) ||
|
||||
isTransparent(world, x, y + 1, z) ||
|
||||
isTransparent(world, x, y, z - 1) ||
|
||||
isTransparent(world, x, y, z + 1)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -39,6 +39,28 @@ public class Fields
|
|||
return null;
|
||||
}
|
||||
|
||||
public static Object getValue(Object instance, Field field)
|
||||
{
|
||||
try {
|
||||
return field.get(instance);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static Field getField(Object instance, String name)
|
||||
{
|
||||
try {
|
||||
Field field = instance.getClass().getDeclaredField(name);
|
||||
field.setAccessible(true);
|
||||
return field;
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static void setValue(Object instance, int index, Object value)
|
||||
{
|
||||
try {
|
||||
|
|
|
@ -1,42 +1,52 @@
|
|||
package Orebfuscator;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
|
||||
import net.minecraft.network.play.server.S26PacketMapChunkBulk;
|
||||
import net.minecraft.server.MinecraftServer;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
public class MapChunkBulk
|
||||
{
|
||||
public int offsetLSB;
|
||||
public int offsetMSB;
|
||||
public int offsetMetadata;
|
||||
public int offsetBlocklight;
|
||||
public int len;
|
||||
public int lenLSB;
|
||||
public int lenMSB;
|
||||
public int[] bufLSB;
|
||||
public int[] bufMSB;
|
||||
public byte[][] dataArray;
|
||||
public byte[] data;
|
||||
public static Field fieldChunkX;
|
||||
public static Field fieldChunkZ;
|
||||
|
||||
public MapChunkBulk(S26PacketMapChunkBulk packet, World world)
|
||||
|
||||
// 1110011 - íàáîð áëîêîâ (ExtendedBlockStorage.blockLSBArray) ïî âûñîòå (1 - åñòü áëîê, 0 - íåò áëîêà)
|
||||
public static Field fieldStatusLSB = null;
|
||||
|
||||
// 0001110 - íàáîð áëîêîâ (ExtendedBlockStorage.blockMSBArray) ïî âûñîòå (1 - åñòü áëîê, 0 - íåò áëîêà)
|
||||
public static Field fieldStatusMSB;
|
||||
|
||||
// -- ìàññèâ äàííûõ
|
||||
public static Field fieldData;
|
||||
|
||||
public static ChunkInfo info;
|
||||
|
||||
public static void parse(World world, S26PacketMapChunkBulk packet)
|
||||
{
|
||||
int k = 0;
|
||||
int l;
|
||||
|
||||
bufLSB = (int[]) Fields.getValue(packet, "field_149265_c"); // 1110011 - íàáîð áëîêîâ (ExtendedBlockStorage.blockLSBArray) ïî âûñîòå (1 - åñòü áëîê, 0 - íåò áëîêà)
|
||||
bufMSB = (int[]) Fields.getValue(packet, "field_149262_d"); // 0001110 - íàáîð áëîêîâ (ExtendedBlockStorage.blockMSBArray) ïî âûñîòå (1 - åñòü áëîê, 0 - íåò áëîêà)
|
||||
dataArray = (byte[][]) Fields.getValue(packet, "field_149260_f"); // -- ìàññèâ äàííûõ
|
||||
|
||||
ChunkInfo info = new ChunkInfo();
|
||||
|
||||
int lsb;
|
||||
int msb;
|
||||
int pos;
|
||||
int len;
|
||||
|
||||
for (int i = 0; i < bufLSB.length; i++)
|
||||
if (fieldStatusLSB == null)
|
||||
{
|
||||
info.parse(world, dataArray[i], bufLSB[i], bufMSB[i]);
|
||||
fieldChunkX = Fields.getField(packet, "field_149266_a");
|
||||
fieldChunkZ = Fields.getField(packet, "field_149264_b");
|
||||
|
||||
fieldStatusLSB = Fields.getField(packet, "field_149265_c");
|
||||
fieldStatusMSB = Fields.getField(packet, "field_149262_d");
|
||||
fieldData = Fields.getField(packet, "field_149260_f");
|
||||
|
||||
info = new ChunkInfo();
|
||||
}
|
||||
|
||||
|
||||
int[] chunkX = (int[]) Fields.getValue(packet, fieldChunkX);
|
||||
int[] chunkZ = (int[]) Fields.getValue(packet, fieldChunkZ);
|
||||
int[] statusLSB = (int[]) Fields.getValue(packet, fieldStatusLSB);
|
||||
int[] statusMSB = (int[]) Fields.getValue(packet, fieldStatusMSB);
|
||||
byte[][] dataArray = (byte[][]) Fields.getValue(packet, fieldData);
|
||||
|
||||
for (int i = 0; i < statusLSB.length; i++)
|
||||
{
|
||||
info.parse(world, chunkX[i], chunkZ[i], statusLSB[i], statusMSB[i], dataArray[i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -3,6 +3,7 @@ package Orebfuscator;
|
|||
import java.net.SocketAddress;
|
||||
|
||||
import net.minecraft.entity.player.EntityPlayerMP;
|
||||
import net.minecraft.network.play.server.S23PacketBlockChange;
|
||||
import net.minecraft.network.play.server.S26PacketMapChunkBulk;
|
||||
import io.netty.buffer.ByteBufAllocator;
|
||||
import io.netty.channel.Channel;
|
||||
|
@ -32,11 +33,21 @@ public class ProxyChannel implements Channel
|
|||
if (msg instanceof S26PacketMapChunkBulk)
|
||||
{
|
||||
S26PacketMapChunkBulk packet = (S26PacketMapChunkBulk)msg;
|
||||
MapChunkBulk chunk = new MapChunkBulk(packet, player.worldObj);
|
||||
|
||||
//Log.msg("%d", field_149260_f[0].length);
|
||||
MapChunkBulk.parse(player.worldObj, packet);
|
||||
return;
|
||||
}
|
||||
if (msg instanceof MyPacketBlockChange)
|
||||
{
|
||||
return;
|
||||
}
|
||||
if (msg instanceof S23PacketBlockChange)
|
||||
{
|
||||
S23PacketBlockChange packet = (S23PacketBlockChange)msg;
|
||||
BlockChange.parse(player.worldObj, channel, packet);
|
||||
return;
|
||||
}
|
||||
|
||||
//world.scheduleBlockUpdate(x, y, z, this, tickRate);
|
||||
//Log.msg("%s", msg.getClass().getName());
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue