From c2d81e6e9d24c2c2f7aba1857162c115b00c7dc3 Mon Sep 17 00:00:00 2001 From: KennyTV Date: Tue, 28 Apr 2020 11:23:56 +0200 Subject: [PATCH] Map the sound name in stop sound packets --- .../api/rewriters/SoundRewriter.java | 31 +++++++++++++++++++ .../packets/SoundPackets1_13.java | 11 ++++++- .../Protocol1_13_2To1_14.java | 1 - .../packets/SoundPackets1_14.java | 1 + .../Protocol1_14_4To1_15.java | 2 +- .../Protocol1_15_2To1_16.java | 1 + .../chat/TranslatableRewriter1_16.java | 2 ++ 7 files changed, 46 insertions(+), 3 deletions(-) diff --git a/core/src/main/java/nl/matsv/viabackwards/api/rewriters/SoundRewriter.java b/core/src/main/java/nl/matsv/viabackwards/api/rewriters/SoundRewriter.java index 19dec460..9c2a2586 100644 --- a/core/src/main/java/nl/matsv/viabackwards/api/rewriters/SoundRewriter.java +++ b/core/src/main/java/nl/matsv/viabackwards/api/rewriters/SoundRewriter.java @@ -60,4 +60,35 @@ public class SoundRewriter { } }); } + + public void registerStopSound(int oldId, int newId) { + protocol.registerOutgoing(State.PLAY, oldId, newId, new PacketRemapper() { + @Override + public void registerMap() { + handler(wrapper -> { + byte flags = wrapper.passthrough(Type.BYTE); + if ((flags & 0x02) == 0) return; // No sound specified + + if ((flags & 0x01) != 0) { + wrapper.passthrough(Type.STRING); // Source + } + + String soundId = wrapper.read(Type.STRING); + String mappedId = stringIdRewriter.apply(soundId); + if (mappedId == null) { + // No mapping found + wrapper.write(Type.STRING, soundId); + return; + } + + if (!mappedId.isEmpty()) { + wrapper.write(Type.STRING, mappedId); + } else { + // Cancel if set to empty + wrapper.cancel(); + } + }); + } + }); + } } diff --git a/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_12_2to1_13/packets/SoundPackets1_13.java b/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_12_2to1_13/packets/SoundPackets1_13.java index 22916973..5a1a8893 100644 --- a/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_12_2to1_13/packets/SoundPackets1_13.java +++ b/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_12_2to1_13/packets/SoundPackets1_13.java @@ -49,7 +49,16 @@ public class SoundPackets1_13 extends Rewriter { } else { source = ""; } - String sound = (flags & 0x02) != 0 ? wrapper.read(Type.STRING) : ""; + + String sound; + if ((flags & 0x02) != 0) { + sound = BackwardsMappings.soundMappings.getNewId(wrapper.read(Type.STRING)); + if (sound == null) { + sound = ""; + } + } else { + sound = ""; + } wrapper.write(Type.STRING, source); wrapper.write(Type.STRING, sound); diff --git a/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_13_2to1_14/Protocol1_13_2To1_14.java b/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_13_2to1_14/Protocol1_13_2To1_14.java index 8b653ef1..586300bd 100644 --- a/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_13_2to1_14/Protocol1_13_2To1_14.java +++ b/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_13_2to1_14/Protocol1_13_2To1_14.java @@ -76,7 +76,6 @@ public class Protocol1_13_2To1_14 extends BackwardsProtocol { registerOutgoing(State.PLAY, 0x4B, 0x47); registerOutgoing(State.PLAY, 0x4C, 0x48); registerOutgoing(State.PLAY, 0x4E, 0x4A); - registerOutgoing(State.PLAY, 0x52, 0x4C); registerOutgoing(State.PLAY, 0x55, 0x4F); // Update View Position diff --git a/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_13_2to1_14/packets/SoundPackets1_14.java b/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_13_2to1_14/packets/SoundPackets1_14.java index 7ac3902c..16b1642a 100644 --- a/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_13_2to1_14/packets/SoundPackets1_14.java +++ b/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_13_2to1_14/packets/SoundPackets1_14.java @@ -24,6 +24,7 @@ public class SoundPackets1_14 extends Rewriter { id -> BackwardsMappings.soundMappings.getNewId(id), stringId -> BackwardsMappings.soundMappings.getNewId(stringId)); soundRewriter.registerSound(0x51, 0x4D); soundRewriter.registerNamedSound(0x19, 0x1A); + soundRewriter.registerStopSound(0x52, 0x4C); // Entity Sound Effect protocol.registerOutgoing(State.PLAY, 0x50, -1, new PacketRemapper() { diff --git a/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_14_4to1_15/Protocol1_14_4To1_15.java b/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_14_4to1_15/Protocol1_14_4To1_15.java index aac16e70..a9a50b70 100644 --- a/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_14_4to1_15/Protocol1_14_4To1_15.java +++ b/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_14_4to1_15/Protocol1_14_4To1_15.java @@ -46,6 +46,7 @@ public class Protocol1_14_4To1_15 extends BackwardsProtocol { soundRewriter.registerSound(0x52, 0x51); soundRewriter.registerSound(0x51, 0x50); soundRewriter.registerNamedSound(0x1A, 0x19); + soundRewriter.registerStopSound(0x53, 0x52); // Explosion - manually send an explosion sound registerOutgoing(State.PLAY, 0x1D, 0x1C, new PacketRemapper() { @@ -205,7 +206,6 @@ public class Protocol1_14_4To1_15 extends BackwardsProtocol { registerOutgoing(State.PLAY, 0x4D, 0x4C); registerOutgoing(State.PLAY, 0x4E, 0x4D); registerOutgoing(State.PLAY, 0x4F, 0x4E); - registerOutgoing(State.PLAY, 0x53, 0x52); registerOutgoing(State.PLAY, 0x55, 0x54); registerOutgoing(State.PLAY, 0x56, 0x55); registerOutgoing(State.PLAY, 0x57, 0x56); diff --git a/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_15_2to1_16/Protocol1_15_2To1_16.java b/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_15_2to1_16/Protocol1_15_2To1_16.java index 42e5e918..255944ec 100644 --- a/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_15_2to1_16/Protocol1_15_2To1_16.java +++ b/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_15_2to1_16/Protocol1_15_2To1_16.java @@ -47,6 +47,7 @@ public class Protocol1_15_2To1_16 extends BackwardsProtocol { soundRewriter.registerSound(0x51, 0x51); soundRewriter.registerSound(0x52, 0x52); soundRewriter.registerNamedSound(0x1A, 0x1A); + soundRewriter.registerStopSound(0x53, 0x53); // Login success registerOutgoing(State.LOGIN, 0x02, 0x02, new PacketRemapper() { diff --git a/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_15_2to1_16/chat/TranslatableRewriter1_16.java b/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_15_2to1_16/chat/TranslatableRewriter1_16.java index 883413f4..c2737a08 100644 --- a/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_15_2to1_16/chat/TranslatableRewriter1_16.java +++ b/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_15_2to1_16/chat/TranslatableRewriter1_16.java @@ -80,6 +80,8 @@ public class TranslatableRewriter1_16 extends TranslatableRewriter { hoverEvent.addProperty("value", contentsElement.toString()); } else { + //TODO escape/fix? + // the server sends the json as a string hoverEvent.addProperty("value", contentsElement.toString()); } }