-
Notifications
You must be signed in to change notification settings - Fork 193
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
120 additions
and
2 deletions.
There are no files selected for viewing
4 changes: 4 additions & 0 deletions
4
common/src/main/java/net/caffeinemc/mods/lithium/mixin/debug/package-info.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
@MixinConfigOption(description = "Debug features", enabled = false) | ||
package net.caffeinemc.mods.lithium.mixin.debug; | ||
|
||
import net.caffeinemc.gradle.MixinConfigOption; |
13 changes: 13 additions & 0 deletions
13
.../caffeinemc/mods/lithium/mixin/debug/palette/ClientBoundLevelChunkPacketDataAccessor.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package net.caffeinemc.mods.lithium.mixin.debug.palette; | ||
|
||
import net.minecraft.network.protocol.game.ClientboundLevelChunkPacketData; | ||
import org.spongepowered.asm.mixin.Mixin; | ||
import org.spongepowered.asm.mixin.gen.Accessor; | ||
|
||
@Mixin(ClientboundLevelChunkPacketData.class) | ||
public interface ClientBoundLevelChunkPacketDataAccessor { | ||
|
||
@Accessor("buffer") | ||
byte[] getBuffer(); | ||
|
||
} |
30 changes: 30 additions & 0 deletions
30
.../main/java/net/caffeinemc/mods/lithium/mixin/debug/palette/ClientPacketListenerMixin.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
package net.caffeinemc.mods.lithium.mixin.debug.palette; | ||
|
||
import com.llamalad7.mixinextras.injector.wrapmethod.WrapMethod; | ||
import com.llamalad7.mixinextras.injector.wrapoperation.Operation; | ||
import net.minecraft.client.multiplayer.ClientPacketListener; | ||
import net.minecraft.network.protocol.game.ClientboundLevelChunkPacketData; | ||
import org.spongepowered.asm.mixin.Mixin; | ||
|
||
import java.util.Arrays; | ||
|
||
@Mixin(ClientPacketListener.class) | ||
public class ClientPacketListenerMixin { | ||
|
||
@WrapMethod( | ||
method = "updateLevelChunk(IILnet/minecraft/network/protocol/game/ClientboundLevelChunkPacketData;)V" | ||
) | ||
private void addExceptionInfo(int i, int j, ClientboundLevelChunkPacketData clientboundLevelChunkPacketData, Operation<Void> original) { | ||
try { | ||
original.call(i, j, clientboundLevelChunkPacketData); | ||
} catch (IllegalStateException e) { | ||
String message = "Exception occurred while receiving data for chunk at " + i + ", " + j + ".\n" + | ||
"**The following may include sensitive data, e.g. text that is written with blocks or built \n" + | ||
"structures. Make sure the chunk with chunk coordinates " + i + ", " + j + " does not contain block\n" + | ||
"or biome structures (e.g. your non-pseudonym name written with blocks) that you do not want\n" + | ||
"published. This does not include block entities or items.**\n" + | ||
"Possible sensitive chunk biome and blockstate data: " + Arrays.toString(((ClientBoundLevelChunkPacketDataAccessor) clientboundLevelChunkPacketData).getBuffer()); | ||
throw new IllegalStateException(message, e); | ||
} | ||
} | ||
} |
44 changes: 44 additions & 0 deletions
44
...src/main/java/net/caffeinemc/mods/lithium/mixin/debug/palette/PalettedContainerMixin.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
package net.caffeinemc.mods.lithium.mixin.debug.palette; | ||
|
||
import net.minecraft.network.FriendlyByteBuf; | ||
import net.minecraft.util.BitStorage; | ||
import net.minecraft.world.level.chunk.MissingPaletteEntryException; | ||
import net.minecraft.world.level.chunk.Palette; | ||
import net.minecraft.world.level.chunk.PalettedContainer; | ||
import org.spongepowered.asm.mixin.Mixin; | ||
import org.spongepowered.asm.mixin.Shadow; | ||
import org.spongepowered.asm.mixin.injection.At; | ||
import org.spongepowered.asm.mixin.injection.Inject; | ||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; | ||
|
||
@Mixin(PalettedContainer.class) | ||
public class PalettedContainerMixin<T> { | ||
|
||
@Shadow | ||
private volatile PalettedContainer.Data<T> data; | ||
|
||
@Inject( | ||
method = "read", at = @At("RETURN") | ||
) | ||
private void checkConsistency(FriendlyByteBuf friendlyByteBuf, CallbackInfo ci) { | ||
BitStorage storage = this.data.storage(); | ||
Palette<T> palette = this.data.palette(); | ||
int i = -1; | ||
int index = -1; | ||
try { | ||
for (i = 0; i < storage.getSize(); i++) { | ||
index = storage.get(i); | ||
T t = palette.valueFor(index); | ||
//noinspection ConstantValue | ||
if (t == null) { | ||
throw new MissingPaletteEntryException(index); | ||
} | ||
} | ||
} catch (Exception e) { | ||
String builder = "Received invalid paletted container data!\n" + | ||
"Entry at index " + i + " has palette index " + index + ".\n" + | ||
"Palette: " + palette + " Size: " + palette.getSize() + "\n"; | ||
throw new IllegalStateException(builder, e); | ||
} | ||
} | ||
} |
4 changes: 4 additions & 0 deletions
4
common/src/main/java/net/caffeinemc/mods/lithium/mixin/debug/palette/package-info.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
@MixinConfigOption(description = "Clients check the chunk section data when receiving a chunk data packet.") | ||
package net.caffeinemc.mods.lithium.mixin.debug.palette; | ||
|
||
import net.caffeinemc.gradle.MixinConfigOption; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters