From 5399dd8cca5d8a68e9f18ebe65411fc483fa4cef Mon Sep 17 00:00:00 2001 From: James Monger Date: Fri, 24 Feb 2023 03:18:30 +0000 Subject: [PATCH 1/3] refactor: create `PlaySongInboundMessage` (opcode `217`) --- .../handler/rs435/RS435HandlerRegistry.java | 3 +++ .../rs435/audio/PlaySongMessageHandler.java | 12 +++++++++++ .../inbound/audio/PlaySongInboundMessage.java | 20 +++++++++++++++++++ .../runejs/client/net/IncomingPackets.java | 8 -------- .../codec/runejs435/RuneJS435PacketCodec.java | 2 ++ .../decoder/audio/PlaySongMessageDecoder.java | 16 +++++++++++++++ 6 files changed, 53 insertions(+), 8 deletions(-) create mode 100644 src/main/java/org/runejs/client/message/handler/rs435/audio/PlaySongMessageHandler.java create mode 100644 src/main/java/org/runejs/client/message/inbound/audio/PlaySongInboundMessage.java create mode 100644 src/main/java/org/runejs/client/net/codec/runejs435/decoder/audio/PlaySongMessageDecoder.java diff --git a/src/main/java/org/runejs/client/message/handler/rs435/RS435HandlerRegistry.java b/src/main/java/org/runejs/client/message/handler/rs435/RS435HandlerRegistry.java index f3ad8bc0d..434a7f7bc 100644 --- a/src/main/java/org/runejs/client/message/handler/rs435/RS435HandlerRegistry.java +++ b/src/main/java/org/runejs/client/message/handler/rs435/RS435HandlerRegistry.java @@ -1,8 +1,11 @@ package org.runejs.client.message.handler.rs435; import org.runejs.client.message.handler.MessageHandlerRegistry; +import org.runejs.client.message.handler.rs435.audio.PlaySongMessageHandler; +import org.runejs.client.message.inbound.audio.PlaySongInboundMessage; public class RS435HandlerRegistry extends MessageHandlerRegistry { public RS435HandlerRegistry() { + register(PlaySongInboundMessage.class, new PlaySongMessageHandler()); } } diff --git a/src/main/java/org/runejs/client/message/handler/rs435/audio/PlaySongMessageHandler.java b/src/main/java/org/runejs/client/message/handler/rs435/audio/PlaySongMessageHandler.java new file mode 100644 index 000000000..76750f786 --- /dev/null +++ b/src/main/java/org/runejs/client/message/handler/rs435/audio/PlaySongMessageHandler.java @@ -0,0 +1,12 @@ +package org.runejs.client.message.handler.rs435.audio; + +import org.runejs.client.message.handler.MessageHandler; +import org.runejs.client.message.inbound.audio.PlaySongInboundMessage; +import org.runejs.client.sound.MusicSystem; + +public class PlaySongMessageHandler implements MessageHandler { + @Override + public void handle(PlaySongInboundMessage message) { + MusicSystem.playSong(message.songId); + } +} diff --git a/src/main/java/org/runejs/client/message/inbound/audio/PlaySongInboundMessage.java b/src/main/java/org/runejs/client/message/inbound/audio/PlaySongInboundMessage.java new file mode 100644 index 000000000..1663f82ae --- /dev/null +++ b/src/main/java/org/runejs/client/message/inbound/audio/PlaySongInboundMessage.java @@ -0,0 +1,20 @@ +package org.runejs.client.message.inbound.audio; + +import org.runejs.client.message.InboundMessage; + +/** + * A message sent from the client to the server to play a song + */ +public class PlaySongInboundMessage implements InboundMessage { + /** + * The song id to play + */ + public final int songId; + + /** + * Creates a new PlaySongInboundMessage + */ + public PlaySongInboundMessage(int songId) { + this.songId = songId; + } +} diff --git a/src/main/java/org/runejs/client/net/IncomingPackets.java b/src/main/java/org/runejs/client/net/IncomingPackets.java index 47812efc3..db04839f4 100644 --- a/src/main/java/org/runejs/client/net/IncomingPackets.java +++ b/src/main/java/org/runejs/client/net/IncomingPackets.java @@ -675,14 +675,6 @@ public static boolean parseIncomingPackets() { MovedStatics.lastContinueTextWidgetId = -1; return true; } - if(opcode == PacketType.PLAY_SONG.getOpcode()) { - int songId = incomingPacketBuffer.getUnsignedShortLE(); - if(songId == 65535) - songId = -1; - MusicSystem.playSong(songId); - opcode = -1; - return true; - } if(opcode == PacketType.PLAY_QUICK_SONG.getOpcode()) { int songTimeout = incomingPacketBuffer.getMediumBE(); int songId = incomingPacketBuffer.getUnsignedShortBE(); diff --git a/src/main/java/org/runejs/client/net/codec/runejs435/RuneJS435PacketCodec.java b/src/main/java/org/runejs/client/net/codec/runejs435/RuneJS435PacketCodec.java index 5b36e1164..60e77208a 100644 --- a/src/main/java/org/runejs/client/net/codec/runejs435/RuneJS435PacketCodec.java +++ b/src/main/java/org/runejs/client/net/codec/runejs435/RuneJS435PacketCodec.java @@ -2,6 +2,7 @@ import org.runejs.client.net.PacketType; import org.runejs.client.net.codec.MessagePacketCodec; +import org.runejs.client.net.codec.runejs435.decoder.audio.PlaySongMessageDecoder; /** * A {@link MessagePacketCodec} for the RuneJS customised 435 protocol. @@ -18,5 +19,6 @@ private void registerEncoders() { } private void registerDecoders() { + register(PacketType.PLAY_SONG.getOpcode(), new PlaySongMessageDecoder()); } } diff --git a/src/main/java/org/runejs/client/net/codec/runejs435/decoder/audio/PlaySongMessageDecoder.java b/src/main/java/org/runejs/client/net/codec/runejs435/decoder/audio/PlaySongMessageDecoder.java new file mode 100644 index 000000000..8024563da --- /dev/null +++ b/src/main/java/org/runejs/client/net/codec/runejs435/decoder/audio/PlaySongMessageDecoder.java @@ -0,0 +1,16 @@ +package org.runejs.client.net.codec.runejs435.decoder.audio; + +import org.runejs.client.message.inbound.audio.PlaySongInboundMessage; +import org.runejs.client.net.PacketBuffer; +import org.runejs.client.net.codec.MessageDecoder; + +public class PlaySongMessageDecoder implements MessageDecoder { + @Override + public PlaySongInboundMessage decode(PacketBuffer buffer) { + int songId = buffer.getUnsignedShortLE(); + if(songId == 65535) + songId = -1; + + return new PlaySongInboundMessage(songId); + } +} From a2786305a94e53a94556329467cbef0203494a8c Mon Sep 17 00:00:00 2001 From: James Monger Date: Fri, 24 Feb 2023 03:21:18 +0000 Subject: [PATCH 2/3] refactor: create `PlayQuickSongInboundMessage` (opcode `40`) --- .../handler/rs435/RS435HandlerRegistry.java | 3 +++ .../audio/PlayQuickSongMessageHandler.java | 12 +++++++++ .../audio/PlayQuickSongInboundMessage.java | 26 +++++++++++++++++++ .../runejs/client/net/IncomingPackets.java | 9 ------- .../codec/runejs435/RuneJS435PacketCodec.java | 2 ++ .../audio/PlayQuickSongMessageDecoder.java | 19 ++++++++++++++ 6 files changed, 62 insertions(+), 9 deletions(-) create mode 100644 src/main/java/org/runejs/client/message/handler/rs435/audio/PlayQuickSongMessageHandler.java create mode 100644 src/main/java/org/runejs/client/message/inbound/audio/PlayQuickSongInboundMessage.java create mode 100644 src/main/java/org/runejs/client/net/codec/runejs435/decoder/audio/PlayQuickSongMessageDecoder.java diff --git a/src/main/java/org/runejs/client/message/handler/rs435/RS435HandlerRegistry.java b/src/main/java/org/runejs/client/message/handler/rs435/RS435HandlerRegistry.java index 434a7f7bc..85b82e641 100644 --- a/src/main/java/org/runejs/client/message/handler/rs435/RS435HandlerRegistry.java +++ b/src/main/java/org/runejs/client/message/handler/rs435/RS435HandlerRegistry.java @@ -1,11 +1,14 @@ package org.runejs.client.message.handler.rs435; import org.runejs.client.message.handler.MessageHandlerRegistry; +import org.runejs.client.message.handler.rs435.audio.PlayQuickSongMessageHandler; import org.runejs.client.message.handler.rs435.audio.PlaySongMessageHandler; +import org.runejs.client.message.inbound.audio.PlayQuickSongInboundMessage; import org.runejs.client.message.inbound.audio.PlaySongInboundMessage; public class RS435HandlerRegistry extends MessageHandlerRegistry { public RS435HandlerRegistry() { register(PlaySongInboundMessage.class, new PlaySongMessageHandler()); + register(PlayQuickSongInboundMessage.class, new PlayQuickSongMessageHandler()); } } diff --git a/src/main/java/org/runejs/client/message/handler/rs435/audio/PlayQuickSongMessageHandler.java b/src/main/java/org/runejs/client/message/handler/rs435/audio/PlayQuickSongMessageHandler.java new file mode 100644 index 000000000..cc14b8c59 --- /dev/null +++ b/src/main/java/org/runejs/client/message/handler/rs435/audio/PlayQuickSongMessageHandler.java @@ -0,0 +1,12 @@ +package org.runejs.client.message.handler.rs435.audio; + +import org.runejs.client.message.handler.MessageHandler; +import org.runejs.client.message.inbound.audio.PlayQuickSongInboundMessage; +import org.runejs.client.sound.MusicSystem; + +public class PlayQuickSongMessageHandler implements MessageHandler { + @Override + public void handle(PlayQuickSongInboundMessage message) { + MusicSystem.playSoundJingle(message.songTimeout, message.songId); + } +} diff --git a/src/main/java/org/runejs/client/message/inbound/audio/PlayQuickSongInboundMessage.java b/src/main/java/org/runejs/client/message/inbound/audio/PlayQuickSongInboundMessage.java new file mode 100644 index 000000000..d54f1551d --- /dev/null +++ b/src/main/java/org/runejs/client/message/inbound/audio/PlayQuickSongInboundMessage.java @@ -0,0 +1,26 @@ +package org.runejs.client.message.inbound.audio; + +import org.runejs.client.message.InboundMessage; + +/** + * A message sent from the client to the server to play a song + */ +public class PlayQuickSongInboundMessage implements InboundMessage { + /** + * The song id to play + */ + public final int songId; + + /** + * The song timeout. + */ + public final int songTimeout; + + /** + * Creates a new PlaySongInboundMessage + */ + public PlayQuickSongInboundMessage(int songId, int songTimeout) { + this.songId = songId; + this.songTimeout = songTimeout; + } +} diff --git a/src/main/java/org/runejs/client/net/IncomingPackets.java b/src/main/java/org/runejs/client/net/IncomingPackets.java index db04839f4..95d1df55e 100644 --- a/src/main/java/org/runejs/client/net/IncomingPackets.java +++ b/src/main/java/org/runejs/client/net/IncomingPackets.java @@ -675,15 +675,6 @@ public static boolean parseIncomingPackets() { MovedStatics.lastContinueTextWidgetId = -1; return true; } - if(opcode == PacketType.PLAY_QUICK_SONG.getOpcode()) { - int songTimeout = incomingPacketBuffer.getMediumBE(); - int songId = incomingPacketBuffer.getUnsignedShortBE(); - if(songId == 65535) - songId = -1; - MusicSystem.playSoundJingle(songTimeout, songId); - opcode = -1; - return true; - } if(opcode == PacketType.UPDATE_REFERENCE_POSITION.getOpcode()) { OverlayDefinition.placementY = incomingPacketBuffer.getUnsignedByte(); MovedStatics.placementX = incomingPacketBuffer.getUnsignedByte(); diff --git a/src/main/java/org/runejs/client/net/codec/runejs435/RuneJS435PacketCodec.java b/src/main/java/org/runejs/client/net/codec/runejs435/RuneJS435PacketCodec.java index 60e77208a..30bef48b2 100644 --- a/src/main/java/org/runejs/client/net/codec/runejs435/RuneJS435PacketCodec.java +++ b/src/main/java/org/runejs/client/net/codec/runejs435/RuneJS435PacketCodec.java @@ -2,6 +2,7 @@ import org.runejs.client.net.PacketType; import org.runejs.client.net.codec.MessagePacketCodec; +import org.runejs.client.net.codec.runejs435.decoder.audio.PlayQuickSongMessageDecoder; import org.runejs.client.net.codec.runejs435.decoder.audio.PlaySongMessageDecoder; /** @@ -20,5 +21,6 @@ private void registerEncoders() { private void registerDecoders() { register(PacketType.PLAY_SONG.getOpcode(), new PlaySongMessageDecoder()); + register(PacketType.PLAY_QUICK_SONG.getOpcode(), new PlayQuickSongMessageDecoder()); } } diff --git a/src/main/java/org/runejs/client/net/codec/runejs435/decoder/audio/PlayQuickSongMessageDecoder.java b/src/main/java/org/runejs/client/net/codec/runejs435/decoder/audio/PlayQuickSongMessageDecoder.java new file mode 100644 index 000000000..d6b164503 --- /dev/null +++ b/src/main/java/org/runejs/client/net/codec/runejs435/decoder/audio/PlayQuickSongMessageDecoder.java @@ -0,0 +1,19 @@ +package org.runejs.client.net.codec.runejs435.decoder.audio; + +import org.runejs.client.message.inbound.audio.PlaySongInboundMessage; +import org.runejs.client.net.PacketBuffer; +import org.runejs.client.net.codec.MessageDecoder; + +/** + * Decodes the PlayQuickSong message + */ +public class PlayQuickSongMessageDecoder implements MessageDecoder { + @Override + public PlaySongInboundMessage decode(PacketBuffer buffer) { + int songId = buffer.getUnsignedShortLE(); + if(songId == 65535) + songId = -1; + + return new PlaySongInboundMessage(songId); + } +} From 62adeac0caa93608ea82dd033912eb6195dfc9e1 Mon Sep 17 00:00:00 2001 From: James Monger Date: Fri, 24 Feb 2023 03:25:12 +0000 Subject: [PATCH 3/3] refactor: create `PlaySoundInboundMessage` (opcode `131`) --- .../handler/rs435/RS435HandlerRegistry.java | 3 ++ .../rs435/audio/PlaySoundMessageHandler.java | 13 ++++++++ .../audio/PlaySoundInboundMessage.java | 32 +++++++++++++++++++ .../runejs/client/net/IncomingPackets.java | 15 ++------- .../codec/runejs435/RuneJS435PacketCodec.java | 2 ++ .../audio/PlaySoundMessageDecoder.java | 19 +++++++++++ 6 files changed, 72 insertions(+), 12 deletions(-) create mode 100644 src/main/java/org/runejs/client/message/handler/rs435/audio/PlaySoundMessageHandler.java create mode 100644 src/main/java/org/runejs/client/message/inbound/audio/PlaySoundInboundMessage.java create mode 100644 src/main/java/org/runejs/client/net/codec/runejs435/decoder/audio/PlaySoundMessageDecoder.java diff --git a/src/main/java/org/runejs/client/message/handler/rs435/RS435HandlerRegistry.java b/src/main/java/org/runejs/client/message/handler/rs435/RS435HandlerRegistry.java index 85b82e641..16ab7d912 100644 --- a/src/main/java/org/runejs/client/message/handler/rs435/RS435HandlerRegistry.java +++ b/src/main/java/org/runejs/client/message/handler/rs435/RS435HandlerRegistry.java @@ -3,12 +3,15 @@ import org.runejs.client.message.handler.MessageHandlerRegistry; import org.runejs.client.message.handler.rs435.audio.PlayQuickSongMessageHandler; import org.runejs.client.message.handler.rs435.audio.PlaySongMessageHandler; +import org.runejs.client.message.handler.rs435.audio.PlaySoundMessageHandler; import org.runejs.client.message.inbound.audio.PlayQuickSongInboundMessage; import org.runejs.client.message.inbound.audio.PlaySongInboundMessage; +import org.runejs.client.message.inbound.audio.PlaySoundInboundMessage; public class RS435HandlerRegistry extends MessageHandlerRegistry { public RS435HandlerRegistry() { register(PlaySongInboundMessage.class, new PlaySongMessageHandler()); register(PlayQuickSongInboundMessage.class, new PlayQuickSongMessageHandler()); + register(PlaySoundInboundMessage.class, new PlaySoundMessageHandler()); } } diff --git a/src/main/java/org/runejs/client/message/handler/rs435/audio/PlaySoundMessageHandler.java b/src/main/java/org/runejs/client/message/handler/rs435/audio/PlaySoundMessageHandler.java new file mode 100644 index 000000000..fba2b7d45 --- /dev/null +++ b/src/main/java/org/runejs/client/message/handler/rs435/audio/PlaySoundMessageHandler.java @@ -0,0 +1,13 @@ +package org.runejs.client.message.handler.rs435.audio; + +import org.runejs.client.message.handler.MessageHandler; +import org.runejs.client.message.inbound.audio.PlaySoundInboundMessage; +import org.runejs.client.sound.SoundSystem; + +public class PlaySoundMessageHandler implements MessageHandler { + @Override + public void handle(PlaySoundInboundMessage message) { + + SoundSystem.play(message.soundId, message.volume, message.delay); + } +} diff --git a/src/main/java/org/runejs/client/message/inbound/audio/PlaySoundInboundMessage.java b/src/main/java/org/runejs/client/message/inbound/audio/PlaySoundInboundMessage.java new file mode 100644 index 000000000..7bcafad43 --- /dev/null +++ b/src/main/java/org/runejs/client/message/inbound/audio/PlaySoundInboundMessage.java @@ -0,0 +1,32 @@ +package org.runejs.client.message.inbound.audio; + +import org.runejs.client.message.InboundMessage; + +/** + * A message sent from the client to the server to play a sound effect + */ +public class PlaySoundInboundMessage implements InboundMessage { + /** + * The sound id to play + */ + public final int soundId; + + /** + * The volume to play the sound at + */ + public final int volume; + + /** + * The delay to play the sound at + */ + public final int delay; + + /** + * Creates a new PlaySoundInboundMessage + */ + public PlaySoundInboundMessage(int soundId, int volume, int delay) { + this.soundId = soundId; + this.volume = volume; + this.delay = delay; + } +} diff --git a/src/main/java/org/runejs/client/net/IncomingPackets.java b/src/main/java/org/runejs/client/net/IncomingPackets.java index 95d1df55e..e55e4fec7 100644 --- a/src/main/java/org/runejs/client/net/IncomingPackets.java +++ b/src/main/java/org/runejs/client/net/IncomingPackets.java @@ -1,8 +1,10 @@ package org.runejs.client.net; +import org.runejs.client.*; +import org.runejs.client.cache.def.*; import org.runejs.client.cache.media.gameInterface.GameInterface; -import org.runejs.client.cache.media.gameInterface.InterfaceModelType; import org.runejs.client.cache.media.gameInterface.GameInterfaceType; +import org.runejs.client.cache.media.gameInterface.InterfaceModelType; import org.runejs.client.frame.ChatBox; import org.runejs.client.frame.console.Console; import org.runejs.client.input.KeyFocusListener; @@ -26,11 +28,8 @@ import org.runejs.client.scene.tile.GenericTile; import org.runejs.client.scene.tile.Wall; import org.runejs.client.scene.tile.WallDecoration; -import org.runejs.client.sound.MusicSystem; import org.runejs.client.sound.SoundSystem; import org.runejs.client.util.TextUtils; -import org.runejs.client.*; -import org.runejs.client.cache.def.*; public class IncomingPackets { public static int incomingPacketSize = 0; @@ -741,14 +740,6 @@ public static boolean parseIncomingPackets() { opcode = -1; return true; } - if(opcode == PacketType.PLAY_SOUND.getOpcode()) { - int soundId = incomingPacketBuffer.getUnsignedShortBE(); - int volume = incomingPacketBuffer.getUnsignedByte(); - int delay = incomingPacketBuffer.getUnsignedShortBE(); - SoundSystem.play(soundId, volume, delay); - opcode = -1; - return true; - } if(opcode == 237) { // show tab overlay widget int i_68_ = incomingPacketBuffer.getUnsignedShortBE(); GameInterface.resetInterfaceAnimations(i_68_); diff --git a/src/main/java/org/runejs/client/net/codec/runejs435/RuneJS435PacketCodec.java b/src/main/java/org/runejs/client/net/codec/runejs435/RuneJS435PacketCodec.java index 30bef48b2..facfeed95 100644 --- a/src/main/java/org/runejs/client/net/codec/runejs435/RuneJS435PacketCodec.java +++ b/src/main/java/org/runejs/client/net/codec/runejs435/RuneJS435PacketCodec.java @@ -4,6 +4,7 @@ import org.runejs.client.net.codec.MessagePacketCodec; import org.runejs.client.net.codec.runejs435.decoder.audio.PlayQuickSongMessageDecoder; import org.runejs.client.net.codec.runejs435.decoder.audio.PlaySongMessageDecoder; +import org.runejs.client.net.codec.runejs435.decoder.audio.PlaySoundMessageDecoder; /** * A {@link MessagePacketCodec} for the RuneJS customised 435 protocol. @@ -22,5 +23,6 @@ private void registerEncoders() { private void registerDecoders() { register(PacketType.PLAY_SONG.getOpcode(), new PlaySongMessageDecoder()); register(PacketType.PLAY_QUICK_SONG.getOpcode(), new PlayQuickSongMessageDecoder()); + register(PacketType.PLAY_SOUND.getOpcode(), new PlaySoundMessageDecoder()); } } diff --git a/src/main/java/org/runejs/client/net/codec/runejs435/decoder/audio/PlaySoundMessageDecoder.java b/src/main/java/org/runejs/client/net/codec/runejs435/decoder/audio/PlaySoundMessageDecoder.java new file mode 100644 index 000000000..c713996cc --- /dev/null +++ b/src/main/java/org/runejs/client/net/codec/runejs435/decoder/audio/PlaySoundMessageDecoder.java @@ -0,0 +1,19 @@ +package org.runejs.client.net.codec.runejs435.decoder.audio; + +import org.runejs.client.message.inbound.audio.PlaySoundInboundMessage; +import org.runejs.client.net.PacketBuffer; +import org.runejs.client.net.codec.MessageDecoder; + +/** + * Decodes the PlaySoundInboundMessage + */ +public class PlaySoundMessageDecoder implements MessageDecoder { + @Override + public PlaySoundInboundMessage decode(PacketBuffer buffer) { + int soundId = buffer.getUnsignedShortBE(); + int volume = buffer.getUnsignedByte(); + int delay = buffer.getUnsignedShortBE(); + + return new PlaySoundInboundMessage(soundId, volume, delay); + } +}