Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Experimental obfuscation engine #393

Draft
wants to merge 4 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public interface WorldConfigBundle {

int maxSectionIndex();

boolean shouldObfuscate(int y);
boolean shouldProcessBlock(int y);

int nextRandomObfuscationBlock(int y);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public static void initialize(Config config) {
}

String nmsVersion = MinecraftVersion.nmsVersion();
if (ServerVersion.isMojangMapped()) {
if (ServerVersion.isMojangMapped() && !ServerVersion.isPaper()) {
nmsVersion += "_mojang";
}

Expand Down Expand Up @@ -58,6 +58,10 @@ public static int getMaxBitsPerBlockState() {
return instance.getMaxBitsPerBlockState();
}

public static int getMaxBitsPerBiome() {
return instance.getMaxBitsPerBiome();
}

public static BlockProperties getBlockByName(String key) {
return instance.getBlockByName(NamespacedKey.fromString(key));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,19 @@ public abstract class AbstractNmsManager implements NmsManager {
private final int uniqueBlockStateCount;
private final int maxBitsPerBlockState;

private final int maxBitsPerBiome;

private final BlockStateProperties[] blockStates;
private final Map<NamespacedKey, BlockProperties> blocks = new HashMap<>();

public AbstractNmsManager(int uniqueBlockStateCount, AbstractRegionFileCache<?> regionFileCache) {
public AbstractNmsManager(int uniqueBlockStateCount, int uniqueBiomesCount, AbstractRegionFileCache<?> regionFileCache) {
this.regionFileCache = regionFileCache;

this.uniqueBlockStateCount = uniqueBlockStateCount;
this.maxBitsPerBlockState = MathUtil.ceilLog2(uniqueBlockStateCount);

this.maxBitsPerBiome = MathUtil.ceilLog2(uniqueBiomesCount);

this.blockStates = new BlockStateProperties[uniqueBlockStateCount];
}

Expand All @@ -50,6 +54,11 @@ public final int getMaxBitsPerBlockState() {
return this.maxBitsPerBlockState;
}

@Override
public int getMaxBitsPerBiome() {
return this.maxBitsPerBiome;
}

@Override
public final BlockProperties getBlockByName(NamespacedKey key) {
return this.blocks.get(key);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ public interface NmsManager {

int getMaxBitsPerBlockState();

int getMaxBitsPerBiome();

BlockProperties getBlockByName(NamespacedKey key);

boolean isAir(int blockId);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,10 @@ private static EntityPlayer player(Player player) {
}

public NmsManager(Config config) {
super(Block.REGISTRY_ID.a(), new RegionFileCache(config.cache()));
super(
Block.REGISTRY_ID.a(),
IRegistry.h.get(IRegistry.u.a()).keySet().size(),
new RegionFileCache(config.cache()));

for (Map.Entry<ResourceKey<Block>, Block> entry : IRegistry.BLOCK.c()) {
NamespacedKey namespacedKey = NamespacedKey.fromString(entry.getKey().a().toString());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,10 @@ private static EntityPlayer player(Player player) {
}

public NmsManager(Config config) {
super(Block.REGISTRY_ID.a(), new RegionFileCache(config.cache()));
super(
Block.REGISTRY_ID.a(),
IRegistry.f.get(IRegistry.ay.a()).keySet().size(),
new RegionFileCache(config.cache()));

for (Map.Entry<ResourceKey<Block>, Block> entry : IRegistry.BLOCK.d()) {
NamespacedKey namespacedKey = NamespacedKey.fromString(entry.getKey().a().toString());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,10 @@ private static EntityPlayer player(Player player) {
}

public NmsManager(Config config) {
super(Block.REGISTRY_ID.a(), new RegionFileCache(config.cache()));
super(
Block.REGISTRY_ID.a(),
IRegistry.f.get(IRegistry.ay.a()).keySet().size(),
new RegionFileCache(config.cache()));

for (Map.Entry<ResourceKey<Block>, Block> entry : IRegistry.BLOCK.d()) {
NamespacedKey namespacedKey = NamespacedKey.fromString(entry.getKey().a().toString());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,10 @@ private static ServerPlayer player(Player player) {
}

public NmsManager(Config config) {
super(Block.BLOCK_STATE_REGISTRY.size(), new RegionFileCache(config.cache()));
super(
Block.BLOCK_STATE_REGISTRY.size(),
Registry.REGISTRY.get(Registry.BIOME_REGISTRY.location()).keySet().size(),
new RegionFileCache(config.cache()));

for (Map.Entry<ResourceKey<Block>, Block> entry : Registry.BLOCK.entrySet()) {
NamespacedKey namespacedKey = NamespacedKey.fromString(entry.getKey().location().toString());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,10 @@ private static ServerPlayer player(Player player) {
}

public NmsManager(Config config) {
super(Block.BLOCK_STATE_REGISTRY.size(), new RegionFileCache(config.cache()));
super(
Block.BLOCK_STATE_REGISTRY.size(),
Registry.REGISTRY.get(Registry.BIOME_REGISTRY.location()).size(),
new RegionFileCache(config.cache()));

for (Map.Entry<ResourceKey<Block>, Block> entry : Registry.BLOCK.entrySet()) {
NamespacedKey namespacedKey = NamespacedKey.fromString(entry.getKey().location().toString());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,10 @@ private static ServerPlayer player(Player player) {
}

public NmsManager(Config config) {
super(Block.BLOCK_STATE_REGISTRY.size(), new RegionFileCache(config.cache()));
super(
Block.BLOCK_STATE_REGISTRY.size(),
Registry.REGISTRY.get(Registry.BIOME_REGISTRY.location()).size(),
new RegionFileCache(config.cache()));

for (Map.Entry<ResourceKey<Block>, Block> entry : Registry.BLOCK.entrySet()) {
NamespacedKey namespacedKey = NamespacedKey.fromString(entry.getKey().location().toString());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,10 @@ private static ServerPlayer player(Player player) {
}

public NmsManager(Config config) {
super(Block.BLOCK_STATE_REGISTRY.size(), new RegionFileCache(config.cache()));
super(
Block.BLOCK_STATE_REGISTRY.size(),
Registry.REGISTRY.get(Registry.BIOME_REGISTRY.location()).size(),
new RegionFileCache(config.cache()));

for (Map.Entry<ResourceKey<Block>, Block> entry : Registry.BLOCK.entrySet()) {
NamespacedKey namespacedKey = NamespacedKey.fromString(entry.getKey().location().toString());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import net.minecraft.core.BlockPos;
import net.minecraft.core.SectionPos;
import net.minecraft.core.registries.BuiltInRegistries;
import net.minecraft.core.registries.Registries;
import net.minecraft.network.protocol.Packet;
import net.minecraft.network.protocol.game.ClientGamePacketListener;
import net.minecraft.network.protocol.game.ClientboundBlockUpdatePacket;
Expand Down Expand Up @@ -68,7 +69,10 @@ private static ServerPlayer player(Player player) {
}

public NmsManager(Config config) {
super(Block.BLOCK_STATE_REGISTRY.size(), new RegionFileCache(config.cache()));
super(
Block.BLOCK_STATE_REGISTRY.size(),
BuiltInRegistries.REGISTRY.get(Registries.BIOME.location()).size(),
new RegionFileCache(config.cache()));

for (Map.Entry<ResourceKey<Block>, Block> entry : BuiltInRegistries.BLOCK.entrySet()) {
NamespacedKey namespacedKey = NamespacedKey.fromString(entry.getKey().location().toString());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import net.minecraft.core.BlockPos;
import net.minecraft.core.SectionPos;
import net.minecraft.core.registries.BuiltInRegistries;
import net.minecraft.core.registries.Registries;
import net.minecraft.network.protocol.Packet;
import net.minecraft.network.protocol.game.ClientGamePacketListener;
import net.minecraft.network.protocol.game.ClientboundBlockUpdatePacket;
Expand Down Expand Up @@ -68,7 +69,10 @@ private static ServerPlayer player(Player player) {
}

public NmsManager(Config config) {
super(Block.BLOCK_STATE_REGISTRY.size(), new RegionFileCache(config.cache()));
super(
Block.BLOCK_STATE_REGISTRY.size(),
BuiltInRegistries.REGISTRY.get(Registries.BIOME.location()).size(),
new RegionFileCache(config.cache()));

for (Map.Entry<ResourceKey<Block>, Block> entry : BuiltInRegistries.BLOCK.entrySet()) {
NamespacedKey namespacedKey = NamespacedKey.fromString(entry.getKey().location().toString());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import net.minecraft.core.BlockPos;
import net.minecraft.core.SectionPos;
import net.minecraft.core.registries.BuiltInRegistries;
import net.minecraft.core.registries.Registries;
import net.minecraft.network.protocol.Packet;
import net.minecraft.network.protocol.game.ClientGamePacketListener;
import net.minecraft.network.protocol.game.ClientboundBlockUpdatePacket;
Expand Down Expand Up @@ -68,7 +69,10 @@ private static ServerPlayer player(Player player) {
}

public NmsManager(Config config) {
super(Block.BLOCK_STATE_REGISTRY.size(), new RegionFileCache(config.cache()));
super(
Block.BLOCK_STATE_REGISTRY.size(),
BuiltInRegistries.REGISTRY.get(Registries.BIOME.location()).size(),
new RegionFileCache(config.cache()));

for (Map.Entry<ResourceKey<Block>, Block> entry : BuiltInRegistries.BLOCK.entrySet()) {
NamespacedKey namespacedKey = NamespacedKey.fromString(entry.getKey().location().toString());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import net.minecraft.core.BlockPos;
import net.minecraft.core.SectionPos;
import net.minecraft.core.registries.BuiltInRegistries;
import net.minecraft.core.registries.Registries;
import net.minecraft.network.protocol.Packet;
import net.minecraft.network.protocol.game.ClientGamePacketListener;
import net.minecraft.network.protocol.game.ClientboundBlockUpdatePacket;
Expand Down Expand Up @@ -68,7 +69,10 @@ private static ServerPlayer player(Player player) {
}

public NmsManager(Config config) {
super(Block.BLOCK_STATE_REGISTRY.size(), new RegionFileCache(config.cache()));
super(
Block.BLOCK_STATE_REGISTRY.size(),
BuiltInRegistries.REGISTRY.get(Registries.BIOME.location()).size(),
new RegionFileCache(config.cache()));

for (Map.Entry<ResourceKey<Block>, Block> entry : BuiltInRegistries.BLOCK.entrySet()) {
NamespacedKey namespacedKey = NamespacedKey.fromString(entry.getKey().location().toString());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import net.minecraft.core.BlockPos;
import net.minecraft.core.SectionPos;
import net.minecraft.core.registries.BuiltInRegistries;
import net.minecraft.core.registries.Registries;
import net.minecraft.network.protocol.Packet;
import net.minecraft.network.protocol.game.ClientGamePacketListener;
import net.minecraft.network.protocol.game.ClientboundBlockUpdatePacket;
Expand Down Expand Up @@ -68,7 +69,10 @@ private static ServerPlayer player(Player player) {
}

public NmsManager(Config config) {
super(Block.BLOCK_STATE_REGISTRY.size(), new RegionFileCache(config.cache()));
super(
Block.BLOCK_STATE_REGISTRY.size(),
BuiltInRegistries.REGISTRY.get(Registries.BIOME.location()).size(),
new RegionFileCache(config.cache()));

for (Map.Entry<ResourceKey<Block>, Block> entry : BuiltInRegistries.BLOCK.entrySet()) {
NamespacedKey namespacedKey = NamespacedKey.fromString(entry.getKey().location().toString());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import net.minecraft.core.BlockPos;
import net.minecraft.core.SectionPos;
import net.minecraft.core.registries.BuiltInRegistries;
import net.minecraft.core.registries.Registries;
import net.minecraft.network.protocol.Packet;
import net.minecraft.network.protocol.game.ClientGamePacketListener;
import net.minecraft.network.protocol.game.ClientboundBlockUpdatePacket;
Expand Down Expand Up @@ -68,7 +69,10 @@ private static ServerPlayer player(Player player) {
}

public NmsManager(Config config) {
super(Block.BLOCK_STATE_REGISTRY.size(), new RegionFileCache(config.cache()));
super(
Block.BLOCK_STATE_REGISTRY.size(),
BuiltInRegistries.REGISTRY.get(Registries.BIOME.location()).size(),
new RegionFileCache(config.cache()));

for (Map.Entry<ResourceKey<Block>, Block> entry : BuiltInRegistries.BLOCK.entrySet()) {
NamespacedKey namespacedKey = NamespacedKey.fromString(entry.getKey().location().toString());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

import org.bukkit.Material;
import org.bukkit.World;
import org.bukkit.craftbukkit.v1_21_R1.CraftRegistry;
import org.bukkit.craftbukkit.v1_21_R1.CraftWorld;
import org.bukkit.craftbukkit.v1_21_R1.block.data.CraftBlockData;
import org.bukkit.craftbukkit.v1_21_R1.entity.CraftPlayer;
Expand All @@ -26,6 +27,7 @@
import net.minecraft.core.BlockPos;
import net.minecraft.core.SectionPos;
import net.minecraft.core.registries.BuiltInRegistries;
import net.minecraft.core.registries.Registries;
import net.minecraft.network.protocol.Packet;
import net.minecraft.network.protocol.game.ClientGamePacketListener;
import net.minecraft.network.protocol.game.ClientboundBlockUpdatePacket;
Expand Down Expand Up @@ -68,7 +70,10 @@ private static ServerPlayer player(Player player) {
}

public NmsManager(Config config) {
super(Block.BLOCK_STATE_REGISTRY.size(), new RegionFileCache(config.cache()));
super(
Block.BLOCK_STATE_REGISTRY.size(),
CraftRegistry.getMinecraftRegistry(Registries.BIOME).size(),
new RegionFileCache(config.cache()));

for (Map.Entry<ResourceKey<Block>, Block> entry : BuiltInRegistries.BLOCK.entrySet()) {
NamespacedKey namespacedKey = NamespacedKey.fromString(entry.getKey().location().toString());
Expand Down Expand Up @@ -99,6 +104,10 @@ public NmsManager(Config config) {
public ReadOnlyChunk getReadOnlyChunk(World world, int chunkX, int chunkZ) {
ServerChunkCache serverChunkCache = level(world).getChunkSource();
LevelChunk chunk = serverChunkCache.getChunk(chunkX, chunkZ, true);
/**
* LevelChunkSection
* PalettedContainer
*/
return new ReadOnlyChunkWrapper(chunk);
}

Expand Down
4 changes: 2 additions & 2 deletions orebfuscator-plugin/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@
<version>${revision}</version>
<scope>compile</scope>
</dependency>
<dependency>
<!--<dependency>
<groupId>net.imprex</groupId>
<artifactId>orebfuscator-nms-v1_16_R1</artifactId>
<version>${revision}</version>
Expand Down Expand Up @@ -275,7 +275,7 @@
<artifactId>orebfuscator-nms-v1_20_R4</artifactId>
<version>${revision}</version>
<scope>compile</scope>
</dependency>
</dependency>-->
<dependency>
<groupId>net.imprex</groupId>
<artifactId>orebfuscator-nms-v1_21_R1</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ public void onLoad() {
@Override
public void onEnable() {
try {
// GZIPOutputStream
// Check for valid minecraft version
if (MinecraftVersion.isBelow("1.16")) {
throw new RuntimeException("Orebfuscator only supports minecraft 1.16 and above");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,14 +88,14 @@ private void skipBiomePalettedContainer() {
int bitsPerValue = this.inputBuffer.readUnsignedByte();

if (bitsPerValue == 0) {
ByteBufUtil.readVarInt(this.inputBuffer);
VarInt.read(this.inputBuffer);
} else if (bitsPerValue <= 3) {
for (int i = ByteBufUtil.readVarInt(this.inputBuffer); i > 0; i--) {
ByteBufUtil.readVarInt(this.inputBuffer);
for (int i = VarInt.read(this.inputBuffer); i > 0; i--) {
VarInt.read(this.inputBuffer);
}
}

int dataLength = ByteBufUtil.readVarInt(this.inputBuffer);
int dataLength = VarInt.read(this.inputBuffer);
if (SimpleVarBitBuffer.calculateArraySize(bitsPerValue, 64) != dataLength) {
throw new IndexOutOfBoundsException("data.length != VarBitBuffer::size " + dataLength + " " +
SimpleVarBitBuffer.calculateArraySize(bitsPerValue, 64));
Expand Down
Loading