1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
|
From 935843a587ceb77ad93fe57a272c39f2d2dc029b Mon Sep 17 00:00:00 2001
From: md_5 <md_5@live.com.au>
Date: Thu, 16 May 2013 18:51:05 +1000
Subject: [PATCH] Orebfuscator
diff --git a/src/main/java/net/minecraft/server/EntityFallingBlock.java b/src/main/java/net/minecraft/server/EntityFallingBlock.java
index 5576f15..df602bd 100644
--- a/src/main/java/net/minecraft/server/EntityFallingBlock.java
+++ b/src/main/java/net/minecraft/server/EntityFallingBlock.java
@@ -83,6 +83,7 @@ public class EntityFallingBlock extends Entity {
}
this.world.setAir(i, j, k);
+ world.spigotConfig.antiXrayInstance.updateNearbyBlocks(world, i, j, k); // Spigot
}
if (this.onGround) {
@@ -98,6 +99,7 @@ public class EntityFallingBlock extends Entity {
}
this.world.setTypeAndData(i, j, k, this.id, this.data, 3);
// CraftBukkit end
+ world.spigotConfig.antiXrayInstance.updateNearbyBlocks(world, i, j, k); // Spigot
if (this.id instanceof BlockFalling) {
((BlockFalling) this.id).a(this.world, i, j, k, this.data);
diff --git a/src/main/java/net/minecraft/server/Explosion.java b/src/main/java/net/minecraft/server/Explosion.java
index 56fa999..4502f68 100644
--- a/src/main/java/net/minecraft/server/Explosion.java
+++ b/src/main/java/net/minecraft/server/Explosion.java
@@ -203,6 +203,7 @@ public class Explosion {
j = chunkposition.y;
k = chunkposition.z;
block = this.world.getType(i, j, k);
+ world.spigotConfig.antiXrayInstance.updateNearbyBlocks(world, i, j, k); // Spigot
if (flag) {
double d0 = (double) ((float) i + this.world.random.nextFloat());
double d1 = (double) ((float) j + this.world.random.nextFloat());
diff --git a/src/main/java/net/minecraft/server/PacketPlayOutMapChunk.java b/src/main/java/net/minecraft/server/PacketPlayOutMapChunk.java
index 613c1f1..7479600 100644
--- a/src/main/java/net/minecraft/server/PacketPlayOutMapChunk.java
+++ b/src/main/java/net/minecraft/server/PacketPlayOutMapChunk.java
@@ -28,6 +28,7 @@ public class PacketPlayOutMapChunk extends Packet {
this.d = chunkmap.c;
this.c = chunkmap.b;
+ chunk.world.spigotConfig.antiXrayInstance.obfuscateSync(chunk.locX, chunk.locZ, i, chunkmap.a, chunk.world); // Spigot
try {
this.f = chunkmap.a;
diff --git a/src/main/java/net/minecraft/server/PacketPlayOutMapChunkBulk.java b/src/main/java/net/minecraft/server/PacketPlayOutMapChunkBulk.java
index bf3a139..30bf8a7 100644
--- a/src/main/java/net/minecraft/server/PacketPlayOutMapChunkBulk.java
+++ b/src/main/java/net/minecraft/server/PacketPlayOutMapChunkBulk.java
@@ -26,6 +26,7 @@ public class PacketPlayOutMapChunkBulk extends Packet {
}
};
// CraftBukkit end
+ private World world; // Spigot
public PacketPlayOutMapChunkBulk() {}
@@ -44,6 +45,9 @@ public class PacketPlayOutMapChunkBulk extends Packet {
Chunk chunk = (Chunk) list.get(k);
ChunkMap chunkmap = PacketPlayOutMapChunk.a(chunk, true, '\uffff');
+ // Spigot start
+ world = chunk.world;
+ /*
if (buildBuffer.length < j + chunkmap.a.length) {
byte[] abyte = new byte[j + chunkmap.a.length];
@@ -52,6 +56,8 @@ public class PacketPlayOutMapChunkBulk extends Packet {
}
System.arraycopy(chunkmap.a, 0, buildBuffer, j, chunkmap.a.length);
+ */
+ // Spigot end
j += chunkmap.a.length;
this.a[k] = chunk.locX;
this.b[k] = chunk.locZ;
@@ -79,6 +85,22 @@ public class PacketPlayOutMapChunkBulk extends Packet {
if (this.buffer != null) {
return;
}
+ // Spigot start
+ int finalBufferSize = 0;
+ // Obfuscate all sections
+ for (int i = 0; i < a.length; i++) {
+ world.spigotConfig.antiXrayInstance.obfuscate(a[i], b[i], c[i], inflatedBuffers[i], world);
+ finalBufferSize += inflatedBuffers[i].length;
+ }
+
+ // Now it's time to efficiently copy the chunk to the build buffer
+ buildBuffer = new byte[finalBufferSize];
+ int bufferLocation = 0;
+ for (int i = 0; i < a.length; i++) {
+ System.arraycopy(inflatedBuffers[i], 0, buildBuffer, bufferLocation, inflatedBuffers[i].length);
+ bufferLocation += inflatedBuffers[i].length;
+ }
+ // Spigot end
Deflater deflater = localDeflater.get();
deflater.reset();
diff --git a/src/main/java/net/minecraft/server/PlayerInteractManager.java b/src/main/java/net/minecraft/server/PlayerInteractManager.java
index 7607155..b4461b9 100644
--- a/src/main/java/net/minecraft/server/PlayerInteractManager.java
+++ b/src/main/java/net/minecraft/server/PlayerInteractManager.java
@@ -173,6 +173,7 @@ public class PlayerInteractManager {
this.o = i1;
}
}
+ world.spigotConfig.antiXrayInstance.updateNearbyBlocks(world, i, j, k); // Spigot
}
}
diff --git a/src/main/java/net/minecraft/server/World.java b/src/main/java/net/minecraft/server/World.java
index 3806f7f..c7c33b0 100644
--- a/src/main/java/net/minecraft/server/World.java
+++ b/src/main/java/net/minecraft/server/World.java
@@ -237,9 +237,16 @@ public abstract class World implements IBlockAccess {
return this.getType(i, k, j);
}
- public Block getType(int i, int j, int k) {
+ // Spigot start
+ public Block getType(int i, int j, int k)
+ {
+ return getType( i, j, k, true );
+ }
+
+ public Block getType(int i, int j, int k, boolean useCaptured) {
// CraftBukkit start - tree generation
- if (captureTreeGeneration) {
+ if (captureTreeGeneration && useCaptured) {
+ // Spigot end
Iterator<BlockState> it = capturedBlockStates.iterator();
while (it.hasNext()) {
BlockState previous = it.next();
@@ -551,6 +558,7 @@ public abstract class World implements IBlockAccess {
this.e(i, j + 1, k, block);
this.e(i, j, k - 1, block);
this.e(i, j, k + 1, block);
+ spigotConfig.antiXrayInstance.updateNearbyBlocks(this, i, j, k); // Spigot
}
public void b(int i, int j, int k, Block block, int l) {
diff --git a/src/main/java/org/spigotmc/AntiXray.java b/src/main/java/org/spigotmc/AntiXray.java
new file mode 100644
index 0000000..fad22e2
--- /dev/null
+++ b/src/main/java/org/spigotmc/AntiXray.java
@@ -0,0 +1,227 @@
+package org.spigotmc;
+
+import net.minecraft.util.gnu.trove.set.TByteSet;
+import net.minecraft.util.gnu.trove.set.hash.TByteHashSet;
+import net.minecraft.server.Block;
+import net.minecraft.server.Blocks;
+import net.minecraft.server.World;
+import org.bukkit.craftbukkit.util.CraftMagicNumbers;
+
+public class AntiXray
+{
+
+ private static final CustomTimingsHandler update = new CustomTimingsHandler( "xray - update" );
+ private static final CustomTimingsHandler obfuscate = new CustomTimingsHandler( "xray - obfuscate" );
+ /*========================================================================*/
+ // Used to keep track of which blocks to obfuscate
+ private final boolean[] obfuscateBlocks = new boolean[ Short.MAX_VALUE ];
+ // Used to select a random replacement ore
+ private final byte[] replacementOres;
+
+ public AntiXray(SpigotWorldConfig config)
+ {
+ // Set all listed blocks as true to be obfuscated
+ for ( int id : ( config.engineMode == 1 ) ? config.hiddenBlocks : config.replaceBlocks )
+ {
+ obfuscateBlocks[id] = true;
+ }
+
+ // For every block
+ TByteSet blocks = new TByteHashSet();
+ for ( Integer i : config.hiddenBlocks )
+ {
+ Block block = Block.getById( i );
+ // Check it exists and is not a tile entity
+ if ( block != null && !block.isTileEntity() )
+ {
+ // Add it to the set of replacement blocks
+ blocks.add( (byte) (int) i );
+ }
+ }
+ // Bake it to a flat array of replacements
+ replacementOres = blocks.toArray();
+ }
+
+ /**
+ * Starts the timings handler, then updates all blocks within the set radius
+ * of the given coordinate, revealing them if they are hidden ores.
+ */
+ public void updateNearbyBlocks(World world, int x, int y, int z)
+ {
+ if ( world.spigotConfig.antiXray )
+ {
+ update.startTiming();
+ updateNearbyBlocks( world, x, y, z, 2, false ); // 2 is the radius, we shouldn't change it as that would make it exponentially slower
+ update.stopTiming();
+ }
+ }
+
+ /**
+ * Starts the timings handler, and then removes all non exposed ores from
+ * the chunk buffer.
+ */
+ public void obfuscateSync(int chunkX, int chunkY, int bitmask, byte[] buffer, World world)
+ {
+ if ( world.spigotConfig.antiXray )
+ {
+ obfuscate.startTiming();
+ obfuscate( chunkX, chunkY, bitmask, buffer, world );
+ obfuscate.stopTiming();
+ }
+ }
+
+ /**
+ * Removes all non exposed ores from the chunk buffer.
+ */
+ public void obfuscate(int chunkX, int chunkY, int bitmask, byte[] buffer, World world)
+ {
+ // If the world is marked as obfuscated
+ if ( world.spigotConfig.antiXray )
+ {
+ // Initial radius to search around for air
+ int initialRadius = 1;
+ // Which block in the buffer we are looking at, anywhere from 0 to 16^4
+ int index = 0;
+ // The iterator marking which random ore we should use next
+ int randomOre = 0;
+
+ // Chunk corner X and Z blocks
+ int startX = chunkX << 4;
+ int startZ = chunkY << 4;
+
+ byte replaceWithTypeId;
+ switch ( world.getWorld().getEnvironment() )
+ {
+ case NETHER:
+ replaceWithTypeId = (byte) CraftMagicNumbers.getId(Blocks.NETHERRACK);
+ break;
+ case THE_END:
+ replaceWithTypeId = (byte) CraftMagicNumbers.getId(Blocks.WHITESTONE);
+ break;
+ default:
+ replaceWithTypeId = (byte) CraftMagicNumbers.getId(Blocks.STONE);
+ break;
+ }
+
+ // Chunks can have up to 16 sections
+ for ( int i = 0; i < 16; i++ )
+ {
+ // If the bitmask indicates this chunk is sent...
+ if ( ( bitmask & 1 << i ) != 0 )
+ {
+ // Work through all blocks in the chunk, y,z,x
+ for ( int y = 0; y < 16; y++ )
+ {
+ for ( int z = 0; z < 16; z++ )
+ {
+ for ( int x = 0; x < 16; x++ )
+ {
+ // For some reason we can get too far ahead of ourselves (concurrent modification on bulk chunks?) so if we do, just abort and move on
+ if ( index >= buffer.length )
+ {
+ index++;
+ continue;
+ }
+ // Grab the block ID in the buffer.
+ // TODO: extended IDs are not yet supported
+ int blockId = buffer[index] & 0xFF;
+ // Check if the block should be obfuscated
+ if ( obfuscateBlocks[blockId] )
+ {
+ // The world isn't loaded, bail out
+ if ( !isLoaded( world, startX + x, ( i << 4 ) + y, startZ + z, initialRadius ) )
+ {
+ index++;
+ continue;
+ }
+ // On the otherhand, if radius is 0, or the nearby blocks are all non air, we can obfuscate
+ if ( !hasTransparentBlockAdjacent( world, startX + x, ( i << 4 ) + y, startZ + z, initialRadius ) )
+ {
+ switch ( world.spigotConfig.engineMode )
+ {
+ case 1:
+ // Replace with replacement material
+ buffer[index] = replaceWithTypeId;
+ break;
+ case 2:
+ // Replace with random ore.
+ if ( randomOre >= replacementOres.length )
+ {
+ randomOre = 0;
+ }
+ buffer[index] = replacementOres[randomOre++];
+ break;
+ }
+ }
+ }
+
+ index++;
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+
+ private void updateNearbyBlocks(World world, int x, int y, int z, int radius, boolean updateSelf)
+ {
+ // If the block in question is loaded
+ if ( world.isLoaded( x, y, z ) )
+ {
+ // Get block id
+ Block block = world.getType(x, y, z);
+
+ // See if it needs update
+ if ( updateSelf && obfuscateBlocks[Block.getId( block )] )
+ {
+ // Send the update
+ world.notify( x, y, z );
+ }
+
+ // Check other blocks for updates
+ if ( radius > 0 )
+ {
+ updateNearbyBlocks( world, x + 1, y, z, radius - 1, true );
+ updateNearbyBlocks( world, x - 1, y, z, radius - 1, true );
+ updateNearbyBlocks( world, x, y + 1, z, radius - 1, true );
+ updateNearbyBlocks( world, x, y - 1, z, radius - 1, true );
+ updateNearbyBlocks( world, x, y, z + 1, radius - 1, true );
+ updateNearbyBlocks( world, x, y, z - 1, radius - 1, true );
+ }
+ }
+ }
+
+ private static boolean isLoaded(World world, int x, int y, int z, int radius)
+ {
+ return world.isLoaded( x, y, z )
+ && ( radius == 0 ||
+ ( isLoaded( world, x + 1, y, z, radius - 1 )
+ && isLoaded( world, x - 1, y, z, radius - 1 )
+ && isLoaded( world, x, y + 1, z, radius - 1 )
+ && isLoaded( world, x, y - 1, z, radius - 1 )
+ && isLoaded( world, x, y, z + 1, radius - 1 )
+ && isLoaded( world, x, y, z - 1, radius - 1 ) ) );
+ }
+
+ private static boolean hasTransparentBlockAdjacent(World world, int x, int y, int z, int radius)
+ {
+ return !isSolidBlock(world.getType(x, y, z, false)) /* isSolidBlock */
+ || ( radius > 0
+ && ( hasTransparentBlockAdjacent( world, x + 1, y, z, radius - 1 )
+ || hasTransparentBlockAdjacent( world, x - 1, y, z, radius - 1 )
+ || hasTransparentBlockAdjacent( world, x, y + 1, z, radius - 1 )
+ || hasTransparentBlockAdjacent( world, x, y - 1, z, radius - 1 )
+ || hasTransparentBlockAdjacent( world, x, y, z + 1, radius - 1 )
+ || hasTransparentBlockAdjacent( world, x, y, z - 1, radius - 1 ) ) );
+ }
+
+ private static boolean isSolidBlock(Block block) {
+ // Mob spawners are treated as solid blocks as far as the
+ // game is concerned for lighting and other tasks but for
+ // rendering they can be seen through therefor we special
+ // case them so that the antixray doesn't show the fake
+ // blocks around them.
+ return block.r() && block != Blocks.MOB_SPAWNER;
+ }
+}
diff --git a/src/main/java/org/spigotmc/SpigotWorldConfig.java b/src/main/java/org/spigotmc/SpigotWorldConfig.java
index 1814b4f..45b2aae 100644
--- a/src/main/java/org/spigotmc/SpigotWorldConfig.java
+++ b/src/main/java/org/spigotmc/SpigotWorldConfig.java
@@ -1,5 +1,6 @@
package org.spigotmc;
+import java.util.Arrays;
import java.util.List;
import org.bukkit.Bukkit;
import org.bukkit.configuration.file.YamlConfiguration;
@@ -212,4 +213,36 @@ public class SpigotWorldConfig
arrowDespawnRate = getInt( "arrow-despawn-rate", 1200 );
log( "Arrow Despawn Rate: " + arrowDespawnRate );
}
+
+ public boolean antiXray;
+ public int engineMode;
+ public List<Integer> hiddenBlocks;
+ public List<Integer> replaceBlocks;
+ public AntiXray antiXrayInstance;
+ private void antiXray()
+ {
+ antiXray = getBoolean( "anti-xray.enabled", true );
+ log( "Anti X-Ray: " + antiXray );
+
+ engineMode = getInt( "anti-xray.engine-mode", 1 );
+ log( "\tEngine Mode: " + engineMode );
+
+ if ( SpigotConfig.version < 5 )
+ {
+ set( "anti-xray.blocks", null );
+ }
+ hiddenBlocks = getList( "anti-xray.hide-blocks", Arrays.asList( new Integer[]
+ {
+ 14, 15, 16, 21, 48, 49, 54, 56, 73, 74, 82, 129, 130
+ } ) );
+ log( "\tHidden Blocks: " + hiddenBlocks );
+
+ replaceBlocks = getList( "anti-xray.replace-blocks", Arrays.asList( new Integer[]
+ {
+ 1, 5
+ } ) );
+ log( "\tReplace Blocks: " + replaceBlocks );
+
+ antiXrayInstance = new AntiXray( this );
+ }
}
--
1.9.1
|