From 3fd60df7d563309cc943f504426eb68a08199856 Mon Sep 17 00:00:00 2001 From: James Monger Date: Tue, 4 Jul 2023 14:54:51 +0100 Subject: [PATCH 1/5] refactor: convert "update reference position" packet to message system --- ...UpdateReferencePositionMessageHandler.java | 17 +++++++++++ ...UpdateReferencePositionInboundMessage.java | 28 +++++++++++++++++++ .../runejs/client/net/IncomingPackets.java | 6 ---- .../codec/runejs435/RuneJS435PacketCodec.java | 4 +++ ...UpdateReferencePositionMessageDecoder.java | 18 ++++++++++++ 5 files changed, 67 insertions(+), 6 deletions(-) create mode 100644 src/main/java/org/runejs/client/message/handler/rs435/region/UpdateReferencePositionMessageHandler.java create mode 100644 src/main/java/org/runejs/client/message/inbound/region/UpdateReferencePositionInboundMessage.java create mode 100644 src/main/java/org/runejs/client/net/codec/runejs435/decoder/region/UpdateReferencePositionMessageDecoder.java diff --git a/src/main/java/org/runejs/client/message/handler/rs435/region/UpdateReferencePositionMessageHandler.java b/src/main/java/org/runejs/client/message/handler/rs435/region/UpdateReferencePositionMessageHandler.java new file mode 100644 index 000000000..23063d805 --- /dev/null +++ b/src/main/java/org/runejs/client/message/handler/rs435/region/UpdateReferencePositionMessageHandler.java @@ -0,0 +1,17 @@ +package org.runejs.client.message.handler.rs435.region; + +import org.runejs.client.MovedStatics; +import org.runejs.client.cache.def.OverlayDefinition; +import org.runejs.client.message.handler.MessageHandler; +import org.runejs.client.message.inbound.region.UpdateReferencePositionInboundMessage; + +/** + * Updates the reference position of the client. + */ +public class UpdateReferencePositionMessageHandler implements MessageHandler { + @Override + public void handle(UpdateReferencePositionInboundMessage message) { + MovedStatics.placementX = message.x; + OverlayDefinition.placementY = message.y; + } +} diff --git a/src/main/java/org/runejs/client/message/inbound/region/UpdateReferencePositionInboundMessage.java b/src/main/java/org/runejs/client/message/inbound/region/UpdateReferencePositionInboundMessage.java new file mode 100644 index 000000000..c745b8ae1 --- /dev/null +++ b/src/main/java/org/runejs/client/message/inbound/region/UpdateReferencePositionInboundMessage.java @@ -0,0 +1,28 @@ +package org.runejs.client.message.inbound.region; + +import org.runejs.client.message.InboundMessage; + +/** + * An {@link InboundMessage} sent to update the reference position of the client. + */ +public class UpdateReferencePositionInboundMessage implements InboundMessage { + /** + * The new x coordinate of the reference position. + */ + public final int x; + + /** + * The new y coordinate of the reference position. + */ + public final int y; + + /** + * Creates a new {@link UpdateReferencePositionInboundMessage}. + * @param x The new x coordinate of the reference position. + * @param y The new y coordinate of the reference position. + */ + public UpdateReferencePositionInboundMessage(int x, int y) { + this.x = x; + this.y = y; + } +} diff --git a/src/main/java/org/runejs/client/net/IncomingPackets.java b/src/main/java/org/runejs/client/net/IncomingPackets.java index 8d3d76320..524c5f1fe 100644 --- a/src/main/java/org/runejs/client/net/IncomingPackets.java +++ b/src/main/java/org/runejs/client/net/IncomingPackets.java @@ -547,12 +547,6 @@ public static boolean parseIncomingPackets() { MovedStatics.lastContinueTextWidgetId = -1; return true; } - if(opcode == PacketType.UPDATE_REFERENCE_POSITION.getOpcode()) { - OverlayDefinition.placementY = incomingPacketBuffer.getUnsignedByte(); - MovedStatics.placementX = incomingPacketBuffer.getUnsignedByte(); - opcode = -1; - return true; - } if(opcode == 88) { Class51.anInt1205 = incomingPacketBuffer.getUnsignedByte(); if(Player.currentTabId == Class51.anInt1205) { 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 4de6b8ca7..8d9ed1b74 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 @@ -12,6 +12,7 @@ import org.runejs.client.net.codec.runejs435.decoder.console.ReceiveConsoleCommandMessageDecoder; import org.runejs.client.net.codec.runejs435.decoder.console.ReceiveConsoleLogMessageDecoder; import org.runejs.client.net.codec.runejs435.decoder.misc.*; +import org.runejs.client.net.codec.runejs435.decoder.region.*; import org.runejs.client.net.codec.runejs435.encoder.chat.*; import org.runejs.client.net.codec.runejs435.encoder.console.*; import org.runejs.client.net.codec.runejs435.encoder.interactions.*; @@ -85,5 +86,8 @@ private void registerDecoders() { register(PacketType.UPDATE_RUN_ENERGY.getOpcode(), new UpdateRunEnergyMessageDecoder()); register(PacketType.UPDATE_SKILL.getOpcode(), new UpdateSkillMessageDecoder()); register(PacketType.UPDATE_PLAYERS.getOpcode(), new UpdatePlayersMessageDecoder()); + + // region + register(PacketType.UPDATE_REFERENCE_POSITION.getOpcode(), new UpdateReferencePositionMessageDecoder()); } } diff --git a/src/main/java/org/runejs/client/net/codec/runejs435/decoder/region/UpdateReferencePositionMessageDecoder.java b/src/main/java/org/runejs/client/net/codec/runejs435/decoder/region/UpdateReferencePositionMessageDecoder.java new file mode 100644 index 000000000..7ed095651 --- /dev/null +++ b/src/main/java/org/runejs/client/net/codec/runejs435/decoder/region/UpdateReferencePositionMessageDecoder.java @@ -0,0 +1,18 @@ +package org.runejs.client.net.codec.runejs435.decoder.region; + +import org.runejs.client.message.inbound.region.UpdateReferencePositionInboundMessage; +import org.runejs.client.net.PacketBuffer; +import org.runejs.client.net.codec.MessageDecoder; + +/** + * Decodes an {@link UpdateReferencePositionInboundMessage} from a {@link PacketBuffer}. + */ +public class UpdateReferencePositionMessageDecoder implements MessageDecoder { + @Override + public UpdateReferencePositionInboundMessage decode(PacketBuffer buffer) { + int y = buffer.getUnsignedByte(); + int x = buffer.getUnsignedByte(); + + return new UpdateReferencePositionInboundMessage(x, y); + } +} From 12ea91ccd748094fcec695552fa3ad4233ed222f Mon Sep 17 00:00:00 2001 From: James Monger Date: Tue, 4 Jul 2023 14:58:21 +0100 Subject: [PATCH 2/5] refactor: convert "clear chunk" packet to message system --- .../region/ClearChunkMessageHandler.java | 34 +++++++++++++++++++ .../region/ClearChunkInboundMessage.java | 28 +++++++++++++++ .../runejs/client/net/IncomingPackets.java | 18 ---------- .../codec/runejs435/RuneJS435PacketCodec.java | 1 + .../region/ClearChunkMessageDecoder.java | 18 ++++++++++ 5 files changed, 81 insertions(+), 18 deletions(-) create mode 100644 src/main/java/org/runejs/client/message/handler/rs435/region/ClearChunkMessageHandler.java create mode 100644 src/main/java/org/runejs/client/message/inbound/region/ClearChunkInboundMessage.java create mode 100644 src/main/java/org/runejs/client/net/codec/runejs435/decoder/region/ClearChunkMessageDecoder.java diff --git a/src/main/java/org/runejs/client/message/handler/rs435/region/ClearChunkMessageHandler.java b/src/main/java/org/runejs/client/message/handler/rs435/region/ClearChunkMessageHandler.java new file mode 100644 index 000000000..cada6c542 --- /dev/null +++ b/src/main/java/org/runejs/client/message/handler/rs435/region/ClearChunkMessageHandler.java @@ -0,0 +1,34 @@ +package org.runejs.client.message.handler.rs435.region; + +import org.runejs.client.Class40_Sub3; +import org.runejs.client.LinkedList; +import org.runejs.client.MovedStatics; +import org.runejs.client.cache.def.FramemapDefinition; +import org.runejs.client.cache.def.OverlayDefinition; +import org.runejs.client.media.renderable.actor.Player; +import org.runejs.client.message.handler.MessageHandler; +import org.runejs.client.message.inbound.region.ClearChunkInboundMessage; +import org.runejs.client.scene.tile.Wall; + +/** + * Clears a chunk of the map. + */ +public class ClearChunkMessageHandler implements MessageHandler { + @Override + public void handle(ClearChunkInboundMessage message) { + MovedStatics.placementX = message.x; + OverlayDefinition.placementY = message.y; + for(int i_51_ = MovedStatics.placementX; i_51_ < 8 + MovedStatics.placementX; i_51_++) { + for(int i_52_ = OverlayDefinition.placementY; 8 + OverlayDefinition.placementY > i_52_; i_52_++) { + if(Wall.groundItems[Player.worldLevel][i_51_][i_52_] != null) { + Wall.groundItems[Player.worldLevel][i_51_][i_52_] = null; + FramemapDefinition.spawnGroundItem(i_52_, i_51_); + } + } + } + for(Class40_Sub3 class40_sub3 = (Class40_Sub3) LinkedList.aLinkedList_1064.peekFirst(); class40_sub3 != null; class40_sub3 = (Class40_Sub3) LinkedList.aLinkedList_1064.pollFirst()) { + if(class40_sub3.anInt2039 >= MovedStatics.placementX && MovedStatics.placementX + 8 > class40_sub3.anInt2039 && class40_sub3.anInt2038 >= OverlayDefinition.placementY && OverlayDefinition.placementY + 8 > class40_sub3.anInt2038 && Player.worldLevel == class40_sub3.anInt2018) + class40_sub3.anInt2031 = 0; + } + } +} diff --git a/src/main/java/org/runejs/client/message/inbound/region/ClearChunkInboundMessage.java b/src/main/java/org/runejs/client/message/inbound/region/ClearChunkInboundMessage.java new file mode 100644 index 000000000..e92dc4024 --- /dev/null +++ b/src/main/java/org/runejs/client/message/inbound/region/ClearChunkInboundMessage.java @@ -0,0 +1,28 @@ +package org.runejs.client.message.inbound.region; + +import org.runejs.client.message.InboundMessage; + +/** + * An {@link InboundMessage} sent to clear a chunk. + */ +public class ClearChunkInboundMessage implements InboundMessage { + /** + * The chunk x offset. + */ + public final int x; + + /** + * The chunk y offset. + */ + public final int y; + + /** + * Creates a new {@link ClearChunkInboundMessage}. + * @param x The chunk x offset. + * @param y The chunk y offset. + */ + public ClearChunkInboundMessage(int x, int y) { + this.x = x; + this.y = y; + } +} diff --git a/src/main/java/org/runejs/client/net/IncomingPackets.java b/src/main/java/org/runejs/client/net/IncomingPackets.java index 524c5f1fe..b451d5565 100644 --- a/src/main/java/org/runejs/client/net/IncomingPackets.java +++ b/src/main/java/org/runejs/client/net/IncomingPackets.java @@ -355,24 +355,6 @@ public static boolean parseIncomingPackets() { opcode = -1; return true; } - if(opcode == PacketType.CLEAR_MAP_CHUNK.getOpcode()) { - OverlayDefinition.placementY = incomingPacketBuffer.getUnsignedByte(); - MovedStatics.placementX = incomingPacketBuffer.getUnsignedByte(); - for(int i_51_ = MovedStatics.placementX; i_51_ < 8 + MovedStatics.placementX; i_51_++) { - for(int i_52_ = OverlayDefinition.placementY; 8 + OverlayDefinition.placementY > i_52_; i_52_++) { - if(Wall.groundItems[Player.worldLevel][i_51_][i_52_] != null) { - Wall.groundItems[Player.worldLevel][i_51_][i_52_] = null; - FramemapDefinition.spawnGroundItem(i_52_, i_51_); - } - } - } - for(Class40_Sub3 class40_sub3 = (Class40_Sub3) LinkedList.aLinkedList_1064.peekFirst(); class40_sub3 != null; class40_sub3 = (Class40_Sub3) LinkedList.aLinkedList_1064.pollFirst()) { - if(class40_sub3.anInt2039 >= MovedStatics.placementX && MovedStatics.placementX + 8 > class40_sub3.anInt2039 && class40_sub3.anInt2038 >= OverlayDefinition.placementY && OverlayDefinition.placementY + 8 > class40_sub3.anInt2038 && Player.worldLevel == class40_sub3.anInt2018) - class40_sub3.anInt2031 = 0; - } - opcode = -1; - return true; - } if(opcode == 223) { // set player options String class1 = incomingPacketBuffer.getString(); int i_53_ = 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 8d9ed1b74..0073d930b 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 @@ -88,6 +88,7 @@ private void registerDecoders() { register(PacketType.UPDATE_PLAYERS.getOpcode(), new UpdatePlayersMessageDecoder()); // region + register(PacketType.CLEAR_MAP_CHUNK.getOpcode(), new ClearChunkMessageDecoder()); register(PacketType.UPDATE_REFERENCE_POSITION.getOpcode(), new UpdateReferencePositionMessageDecoder()); } } diff --git a/src/main/java/org/runejs/client/net/codec/runejs435/decoder/region/ClearChunkMessageDecoder.java b/src/main/java/org/runejs/client/net/codec/runejs435/decoder/region/ClearChunkMessageDecoder.java new file mode 100644 index 000000000..464a047ed --- /dev/null +++ b/src/main/java/org/runejs/client/net/codec/runejs435/decoder/region/ClearChunkMessageDecoder.java @@ -0,0 +1,18 @@ +package org.runejs.client.net.codec.runejs435.decoder.region; + +import org.runejs.client.message.inbound.region.ClearChunkInboundMessage; +import org.runejs.client.net.PacketBuffer; +import org.runejs.client.net.codec.MessageDecoder; + +/** + * Decodes a {@link ClearChunkInboundMessage} from a {@link PacketBuffer}. + */ +public class ClearChunkMessageDecoder implements MessageDecoder { + @Override + public ClearChunkInboundMessage decode(PacketBuffer buffer) { + int y = buffer.getUnsignedByte(); + int x = buffer.getUnsignedByte(); + + return new ClearChunkInboundMessage(x, y); + } +} From dd84e0bfdde83766b36a532477a1dc128fe8f471 Mon Sep 17 00:00:00 2001 From: James Monger Date: Tue, 4 Jul 2023 15:16:59 +0100 Subject: [PATCH 3/5] refactor: convert "load map region" packet to message system --- .../handler/rs435/RS435HandlerRegistry.java | 7 +++ .../LoadStandardRegionMessageHandler.java | 60 +++++++++++++++++++ .../LoadStandardRegionInboundMessage.java | 51 ++++++++++++++++ .../runejs/client/net/IncomingPackets.java | 5 -- .../codec/runejs435/RuneJS435PacketCodec.java | 1 + .../LoadStandardRegionMessageDecoder.java | 36 +++++++++++ 6 files changed, 155 insertions(+), 5 deletions(-) create mode 100644 src/main/java/org/runejs/client/message/handler/rs435/region/LoadStandardRegionMessageHandler.java create mode 100644 src/main/java/org/runejs/client/message/inbound/region/LoadStandardRegionInboundMessage.java create mode 100644 src/main/java/org/runejs/client/net/codec/runejs435/decoder/region/LoadStandardRegionMessageDecoder.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 07f68aea8..695721d2a 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 @@ -2,6 +2,7 @@ import org.runejs.client.message.handler.MessageHandlerRegistry; import org.runejs.client.message.handler.rs435.audio.*; +import org.runejs.client.message.handler.rs435.region.*; import org.runejs.client.message.inbound.audio.*; import org.runejs.client.message.handler.rs435.chat.*; import org.runejs.client.message.handler.rs435.console.*; @@ -15,6 +16,7 @@ import org.runejs.client.message.inbound.audio.PlaySoundInboundMessage; import org.runejs.client.message.inbound.console.*; import org.runejs.client.message.inbound.misc.*; +import org.runejs.client.message.inbound.region.*; import org.runejs.client.message.inbound.updating.UpdatePlayersInboundMessage; /** @@ -45,5 +47,10 @@ public RS435HandlerRegistry() { register(UpdateRunEnergyMessage.class, new UpdateRunEnergyMessageHandler()); register(UpdateSkillMessage.class, new UpdateSkillMessageHandler()); register(UpdatePlayersInboundMessage.class, new UpdatePlayersMessageHandler()); + + // region + register(ClearChunkInboundMessage.class, new ClearChunkMessageHandler()); + register(LoadStandardRegionInboundMessage.class, new LoadStandardRegionMessageHandler()); + register(UpdateReferencePositionInboundMessage.class, new UpdateReferencePositionMessageHandler()); } } diff --git a/src/main/java/org/runejs/client/message/handler/rs435/region/LoadStandardRegionMessageHandler.java b/src/main/java/org/runejs/client/message/handler/rs435/region/LoadStandardRegionMessageHandler.java new file mode 100644 index 000000000..f648687b3 --- /dev/null +++ b/src/main/java/org/runejs/client/message/handler/rs435/region/LoadStandardRegionMessageHandler.java @@ -0,0 +1,60 @@ +package org.runejs.client.message.handler.rs435.region; + +import org.runejs.client.Class13; +import org.runejs.client.Class44; +import org.runejs.client.LinkedList; +import org.runejs.client.RSString; +import org.runejs.client.cache.CacheArchive; +import org.runejs.client.language.Native; +import org.runejs.client.media.renderable.actor.Actor; +import org.runejs.client.message.handler.MessageHandler; +import org.runejs.client.message.inbound.region.LoadStandardRegionInboundMessage; +import org.runejs.client.net.ISAAC; +import org.runejs.client.scene.tile.GenericTile; + +/** + * Loads a standard map region (i.e from terrain files) + */ +public class LoadStandardRegionMessageHandler implements MessageHandler { + @Override + public void handle(LoadStandardRegionInboundMessage message) { + int chunkLocalY = message.chunkLocalY; + int chunkX = message.chunkX; + int chunkLocalX = message.chunkLocalX; + int chunkY = message.chunkY; + int level = message.level; + int regionCount = message.regionCount; + Class44.xteaKeys = message.xteaKeys; + ISAAC.mapCoordinates = new int[regionCount]; + RSString.terrainData = new byte[regionCount][]; + boolean inTutorialIsland_maybe = false; + GenericTile.objectData = new byte[regionCount][]; + if((chunkX / 8 == 48 || chunkX / 8 == 49) && chunkY / 8 == 48) { + inTutorialIsland_maybe = true; + } + LinkedList.terrainDataIds = new int[regionCount]; + if(chunkX / 8 == 48 && chunkY / 8 == 148) { + inTutorialIsland_maybe = true; + } + Class13.objectDataIds = new int[regionCount]; + regionCount = 0; + for(int x = (-6 + chunkX) / 8; x <= (6 + chunkX) / 8; x++) { + for(int y = (-6 + chunkY) / 8; (6 + chunkY) / 8 >= y; y++) { + int coords = y + (x << 8); + if(!inTutorialIsland_maybe || y != 49 && y != 149 && y != 147 && x != 50 && (x != 49 || y != 47)) { + ISAAC.mapCoordinates[regionCount] = coords; + + String mapKey = x + Native.MAP_NAME_UNDERSCORE + y; + String mapKeyM = Native.MAP_NAME_PREFIX_M + mapKey; + String mapKeyL = Native.MAP_NAME_PREFIX_L + mapKey; + + LinkedList.terrainDataIds[regionCount] = CacheArchive.gameWorldMapCacheArchive.getHash(mapKeyM); + Class13.objectDataIds[regionCount] = CacheArchive.gameWorldMapCacheArchive.getHash(mapKeyL); + regionCount++; + } + } + } + + Actor.method789(chunkLocalX, chunkY, chunkX, chunkLocalY, level); + } +} diff --git a/src/main/java/org/runejs/client/message/inbound/region/LoadStandardRegionInboundMessage.java b/src/main/java/org/runejs/client/message/inbound/region/LoadStandardRegionInboundMessage.java new file mode 100644 index 000000000..345c2fbb2 --- /dev/null +++ b/src/main/java/org/runejs/client/message/inbound/region/LoadStandardRegionInboundMessage.java @@ -0,0 +1,51 @@ +package org.runejs.client.message.inbound.region; + +import org.runejs.client.message.InboundMessage; + +/** + * An {@link InboundMessage} sent to load a standard region. + */ +public class LoadStandardRegionInboundMessage implements InboundMessage { + public final int chunkX; + + public final int chunkY; + + public final int chunkLocalX; + + public final int chunkLocalY; + + /** + * The level of the region. + */ + public final int level; + + /** + * The number of regions being loaded. + */ + public final int regionCount; + + /** + * The xtea keys of the region. + */ + public final int[][] xteaKeys; + + /** + * Creates a new {@link LoadStandardRegionInboundMessage}. + * @param chunkX + * @param chunkY + * @param chunkLocalX + * @param chunkLocalY + * @param level The level of the region. + * @param regionCount The number of regions being loaded. + * @param xteaKeys The xtea keys of the regions. + */ + public LoadStandardRegionInboundMessage(int chunkX, int chunkY, int chunkLocalX, int chunkLocalY, int level, int regionCount, int[][] xteaKeys) { + this.chunkX = chunkX; + this.chunkY = chunkY; + this.chunkLocalX = chunkLocalX; + this.chunkLocalY = chunkLocalY; + this.level = level; + this.regionCount = regionCount; + this.xteaKeys = xteaKeys; + } +} diff --git a/src/main/java/org/runejs/client/net/IncomingPackets.java b/src/main/java/org/runejs/client/net/IncomingPackets.java index b451d5565..275ac5727 100644 --- a/src/main/java/org/runejs/client/net/IncomingPackets.java +++ b/src/main/java/org/runejs/client/net/IncomingPackets.java @@ -866,11 +866,6 @@ public static boolean parseIncomingPackets() { opcode = -1; return true; } - if(opcode == PacketType.SET_MAP_CHUNK.getOpcode()) { - FloorDecoration.constructMapRegion(false); - opcode = -1; - return true; - } if(opcode == PacketType.UPDATE_WIDGET_TEXT_COLOR.getOpcode()) { int i_113_ = incomingPacketBuffer.getUnsignedShortBE(); int i_114_ = incomingPacketBuffer.getIntLE(); 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 0073d930b..ef52d9e4f 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 @@ -89,6 +89,7 @@ private void registerDecoders() { // region register(PacketType.CLEAR_MAP_CHUNK.getOpcode(), new ClearChunkMessageDecoder()); + register(PacketType.SET_MAP_CHUNK.getOpcode(), new LoadStandardRegionMessageDecoder()); register(PacketType.UPDATE_REFERENCE_POSITION.getOpcode(), new UpdateReferencePositionMessageDecoder()); } } diff --git a/src/main/java/org/runejs/client/net/codec/runejs435/decoder/region/LoadStandardRegionMessageDecoder.java b/src/main/java/org/runejs/client/net/codec/runejs435/decoder/region/LoadStandardRegionMessageDecoder.java new file mode 100644 index 000000000..fa633d33a --- /dev/null +++ b/src/main/java/org/runejs/client/net/codec/runejs435/decoder/region/LoadStandardRegionMessageDecoder.java @@ -0,0 +1,36 @@ +package org.runejs.client.net.codec.runejs435.decoder.region; + +import org.runejs.client.message.inbound.region.LoadStandardRegionInboundMessage; +import org.runejs.client.net.PacketBuffer; +import org.runejs.client.net.codec.MessageDecoder; + +/** + * Decodes a {@link LoadStandardRegionInboundMessage} from a {@link PacketBuffer}. + */ +public class LoadStandardRegionMessageDecoder implements MessageDecoder { + @Override + public LoadStandardRegionInboundMessage decode(PacketBuffer buffer) { + int chunkLocalY = buffer.getUnsignedShortBE(); + int chunkX = buffer.getUnsignedShortLE(); + int chunkLocalX = buffer.getUnsignedShortBE(); + int chunkY = buffer.getUnsignedShortLE(); + int level = buffer.getUnsignedByte(); + int regionCount = (buffer.getSize() - buffer.currentPosition) / 16; + int[][] xteaKeys = new int[regionCount][4]; + for(int r = 0; regionCount > r; r++) { + for(int seed = 0; seed < 4; seed++) { + xteaKeys[r][seed] = buffer.getIntBE(); + } + } + + return new LoadStandardRegionInboundMessage( + chunkX, + chunkY, + chunkLocalX, + chunkLocalY, + level, + regionCount, + xteaKeys + ); + } +} From 18c30beb81d9e17956576b6ff9c7a8a2192fa2d4 Mon Sep 17 00:00:00 2001 From: James Monger Date: Tue, 4 Jul 2023 15:31:23 +0100 Subject: [PATCH 4/5] refactor: convert "load constructed map region" packet to message system --- .../handler/rs435/RS435HandlerRegistry.java | 1 + .../LoadConstructedRegionMessageHandler.java | 69 +++++++++++++++++++ .../LoadConstructedRegionInboundMessage.java | 56 +++++++++++++++ .../runejs/client/net/IncomingPackets.java | 5 -- .../org/runejs/client/net/PacketType.java | 1 + .../codec/runejs435/RuneJS435PacketCodec.java | 1 + .../LoadConstructedRegionMessageDecoder.java | 54 +++++++++++++++ 7 files changed, 182 insertions(+), 5 deletions(-) create mode 100644 src/main/java/org/runejs/client/message/handler/rs435/region/LoadConstructedRegionMessageHandler.java create mode 100644 src/main/java/org/runejs/client/message/inbound/region/LoadConstructedRegionInboundMessage.java create mode 100644 src/main/java/org/runejs/client/net/codec/runejs435/decoder/region/LoadConstructedRegionMessageDecoder.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 695721d2a..429e1fd93 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 @@ -51,6 +51,7 @@ public RS435HandlerRegistry() { // region register(ClearChunkInboundMessage.class, new ClearChunkMessageHandler()); register(LoadStandardRegionInboundMessage.class, new LoadStandardRegionMessageHandler()); + register(LoadConstructedRegionInboundMessage.class, new LoadConstructedRegionMessageHandler()); register(UpdateReferencePositionInboundMessage.class, new UpdateReferencePositionMessageHandler()); } } diff --git a/src/main/java/org/runejs/client/message/handler/rs435/region/LoadConstructedRegionMessageHandler.java b/src/main/java/org/runejs/client/message/handler/rs435/region/LoadConstructedRegionMessageHandler.java new file mode 100644 index 000000000..06f28018b --- /dev/null +++ b/src/main/java/org/runejs/client/message/handler/rs435/region/LoadConstructedRegionMessageHandler.java @@ -0,0 +1,69 @@ +package org.runejs.client.message.handler.rs435.region; + +import org.runejs.client.Class13; +import org.runejs.client.Class44; +import org.runejs.client.LinkedList; +import org.runejs.client.RSString; +import org.runejs.client.cache.CacheArchive; +import org.runejs.client.cache.def.OverlayDefinition; +import org.runejs.client.language.Native; +import org.runejs.client.media.renderable.actor.Actor; +import org.runejs.client.message.handler.MessageHandler; +import org.runejs.client.message.inbound.region.LoadConstructedRegionInboundMessage; +import org.runejs.client.net.ISAAC; +import org.runejs.client.scene.GroundItemTile; +import org.runejs.client.scene.tile.GenericTile; + +/** + * Loads a construction map region (i.e composed from chunks) + */ +public class LoadConstructedRegionMessageHandler implements MessageHandler { + @Override + public void handle(LoadConstructedRegionInboundMessage message) { + GroundItemTile.loadGeneratedMap = true; + + int chunkLocalY = message.chunkLocalY; + int chunkX = message.chunkX; + int chunkLocalX = message.chunkLocalX; + int chunkY = message.chunkY; + int level = message.level; + int regionCount = message.regionCount; + + Class44.xteaKeys = message.xteaKeys; + OverlayDefinition.constructMapTiles = message.mapTiles; + + LinkedList.terrainDataIds = new int[regionCount]; + RSString.terrainData = new byte[regionCount][]; + Class13.objectDataIds = new int[regionCount]; + GenericTile.objectData = new byte[regionCount][]; + ISAAC.mapCoordinates = new int[regionCount]; + regionCount = 0; + for(int i_11_ = 0; i_11_ < 4; i_11_++) { + for(int i_12_ = 0; i_12_ < 13; i_12_++) { + for(int i_13_ = 0; i_13_ < 13; i_13_++) { + int i_14_ = OverlayDefinition.constructMapTiles[i_11_][i_12_][i_13_]; + if(i_14_ != -1) { + int i_15_ = i_14_ >> 14 & 0x3ff; + int i_16_ = i_14_ >> 3 & 0x7ff; + int i_17_ = i_16_ / 8 + (i_15_ / 8 << 8); + for(int i_18_ = 0; regionCount > i_18_; i_18_++) { + if(ISAAC.mapCoordinates[i_18_] == i_17_) { + i_17_ = -1; + break; + } + } + if(i_17_ != -1) { + ISAAC.mapCoordinates[regionCount] = i_17_; + int i_19_ = i_17_ & 0xff; + int i_20_ = (0xffbe & i_17_) >> 8; + LinkedList.terrainDataIds[regionCount] = CacheArchive.gameWorldMapCacheArchive.getHash(Native.MAP_NAME_PREFIX_M +i_20_+ Native.MAP_NAME_UNDERSCORE +i_19_); + Class13.objectDataIds[regionCount] = CacheArchive.gameWorldMapCacheArchive.getHash(Native.MAP_NAME_PREFIX_L +i_20_+ Native.MAP_NAME_UNDERSCORE +i_19_); + regionCount++; + } + } + } + } + } + Actor.method789(chunkLocalX, chunkY, chunkX, chunkLocalY, level); + } +} diff --git a/src/main/java/org/runejs/client/message/inbound/region/LoadConstructedRegionInboundMessage.java b/src/main/java/org/runejs/client/message/inbound/region/LoadConstructedRegionInboundMessage.java new file mode 100644 index 000000000..ad21a020d --- /dev/null +++ b/src/main/java/org/runejs/client/message/inbound/region/LoadConstructedRegionInboundMessage.java @@ -0,0 +1,56 @@ +package org.runejs.client.message.inbound.region; + +import org.runejs.client.message.InboundMessage; + +/** + * An {@link InboundMessage} sent to load a region constructed from composite chunks. + */ +public class LoadConstructedRegionInboundMessage implements InboundMessage { + public final int chunkX; + + public final int chunkY; + + public final int chunkLocalX; + + public final int chunkLocalY; + + /** + * The level of the region. + */ + public final int level; + + public final int[][][] mapTiles; + + /** + * The number of regions being loaded. + */ + public final int regionCount; + + /** + * The xtea keys of the region. + */ + public final int[][] xteaKeys; + + /** + * Creates a new {@link LoadConstructedRegionInboundMessage}. + * + * @param chunkX + * @param chunkY + * @param chunkLocalX + * @param chunkLocalY + * @param level The level of the region. + * @param mapTiles + * @param regionCount The number of regions being loaded. + * @param xteaKeys The xtea keys of the regions. + */ + public LoadConstructedRegionInboundMessage(int chunkX, int chunkY, int chunkLocalX, int chunkLocalY, int level, int[][][] mapTiles, int regionCount, int[][] xteaKeys) { + this.chunkX = chunkX; + this.chunkY = chunkY; + this.chunkLocalX = chunkLocalX; + this.chunkLocalY = chunkLocalY; + this.level = level; + this.mapTiles = mapTiles; + this.regionCount = regionCount; + this.xteaKeys = xteaKeys; + } +} diff --git a/src/main/java/org/runejs/client/net/IncomingPackets.java b/src/main/java/org/runejs/client/net/IncomingPackets.java index 275ac5727..cbb5186ec 100644 --- a/src/main/java/org/runejs/client/net/IncomingPackets.java +++ b/src/main/java/org/runejs/client/net/IncomingPackets.java @@ -124,11 +124,6 @@ public static boolean parseIncomingPackets() { opcode = -1; return true; } - if(opcode == 23) { - FloorDecoration.constructMapRegion(true); - opcode = -1; - return true; - } if(opcode == 222) { int varPlayerValue = incomingPacketBuffer.getByte(); int varPlayerIndex = incomingPacketBuffer.getUnsignedShortBE(); diff --git a/src/main/java/org/runejs/client/net/PacketType.java b/src/main/java/org/runejs/client/net/PacketType.java index a954a97d0..1e06e61a7 100644 --- a/src/main/java/org/runejs/client/net/PacketType.java +++ b/src/main/java/org/runejs/client/net/PacketType.java @@ -11,6 +11,7 @@ public enum PacketType { CLOSE_CUTSCENE(7, 0), UPDATE_ALL_WIDGET_ITEMS(12, -2), UPDATE_RUN_ENERGY(18, 1), + LOAD_CONSTRUCTED_MAP_REGION(23, -2), PLAY_WIDGET_ANIMATION(24, 6), RESET_ACTOR_ANIMATIONS(27, 0), UPDATE_SKILL(34, 6), 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 ef52d9e4f..0cb8f584c 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 @@ -90,6 +90,7 @@ private void registerDecoders() { // region register(PacketType.CLEAR_MAP_CHUNK.getOpcode(), new ClearChunkMessageDecoder()); register(PacketType.SET_MAP_CHUNK.getOpcode(), new LoadStandardRegionMessageDecoder()); + register(PacketType.LOAD_CONSTRUCTED_MAP_REGION.getOpcode(), new LoadConstructedRegionMessageDecoder()); register(PacketType.UPDATE_REFERENCE_POSITION.getOpcode(), new UpdateReferencePositionMessageDecoder()); } } diff --git a/src/main/java/org/runejs/client/net/codec/runejs435/decoder/region/LoadConstructedRegionMessageDecoder.java b/src/main/java/org/runejs/client/net/codec/runejs435/decoder/region/LoadConstructedRegionMessageDecoder.java new file mode 100644 index 000000000..d298cf685 --- /dev/null +++ b/src/main/java/org/runejs/client/net/codec/runejs435/decoder/region/LoadConstructedRegionMessageDecoder.java @@ -0,0 +1,54 @@ +package org.runejs.client.net.codec.runejs435.decoder.region; + +import org.runejs.client.message.inbound.region.LoadConstructedRegionInboundMessage; +import org.runejs.client.net.PacketBuffer; +import org.runejs.client.net.codec.MessageDecoder; + +/** + * Decodes a {@link LoadConstructedRegionInboundMessage} from a {@link PacketBuffer}. + */ +public class LoadConstructedRegionMessageDecoder implements MessageDecoder { + @Override + public LoadConstructedRegionInboundMessage decode(PacketBuffer buffer) { + int chunkLocalY = buffer.getUnsignedShortBE(); + int chunkLocalX = buffer.getUnsignedShortLE(); + int chunkX = buffer.getUnsignedShortBE(); + int level = buffer.getUnsignedByte(); + int chunkY = buffer.getUnsignedShortBE(); + + int[][][] mapTiles = new int[4][13][13]; + buffer.initBitAccess(); + for(int _level = 0; _level < 4; _level++) { + for(int _x = 0; _x < 13; _x++) { + for(int _y = 0; _y < 13; _y++) { + int isConstructedChunk = buffer.getBits(1); + if(isConstructedChunk != 1) { + mapTiles[_level][_x][_y] = -1; + } else { + mapTiles[_level][_x][_y] = buffer.getBits(26); + } + } + } + } + buffer.finishBitAccess(); + + int regionCount = (buffer.getSize() - buffer.currentPosition) / 16; + int[][] xteaKeys = new int[regionCount][4]; + for(int r = 0; regionCount > r; r++) { + for(int seed = 0; seed < 4; seed++) { + xteaKeys[r][seed] = buffer.getIntBE(); + } + } + + return new LoadConstructedRegionInboundMessage( + chunkX, + chunkY, + chunkLocalX, + chunkLocalY, + level, + mapTiles, + regionCount, + xteaKeys + ); + } +} From 272b29c58bcef2605b1689d686b1241ab28610ea Mon Sep 17 00:00:00 2001 From: James Monger Date: Tue, 4 Jul 2023 15:31:36 +0100 Subject: [PATCH 5/5] fix: set loadGeneratedMap back to false in LoadStandardRegionMessageHandler --- .../handler/rs435/region/LoadStandardRegionMessageHandler.java | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/main/java/org/runejs/client/message/handler/rs435/region/LoadStandardRegionMessageHandler.java b/src/main/java/org/runejs/client/message/handler/rs435/region/LoadStandardRegionMessageHandler.java index f648687b3..85fc5d4ad 100644 --- a/src/main/java/org/runejs/client/message/handler/rs435/region/LoadStandardRegionMessageHandler.java +++ b/src/main/java/org/runejs/client/message/handler/rs435/region/LoadStandardRegionMessageHandler.java @@ -10,6 +10,7 @@ import org.runejs.client.message.handler.MessageHandler; import org.runejs.client.message.inbound.region.LoadStandardRegionInboundMessage; import org.runejs.client.net.ISAAC; +import org.runejs.client.scene.GroundItemTile; import org.runejs.client.scene.tile.GenericTile; /** @@ -18,6 +19,8 @@ public class LoadStandardRegionMessageHandler implements MessageHandler { @Override public void handle(LoadStandardRegionInboundMessage message) { + GroundItemTile.loadGeneratedMap = false; + int chunkLocalY = message.chunkLocalY; int chunkX = message.chunkX; int chunkLocalX = message.chunkLocalX;