Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: convert region-related inbound packets to message system #118

Merged
merged 5 commits into from
Jul 5, 2023
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
refactor: convert "load constructed map region" packet to message system
Jameskmonger committed Jul 4, 2023
commit 18c30beb81d9e17956576b6ff9c7a8a2192fa2d4
Original file line number Diff line number Diff line change
@@ -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());
}
}
Original file line number Diff line number Diff line change
@@ -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<LoadConstructedRegionInboundMessage> {
@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);
}
}
Original file line number Diff line number Diff line change
@@ -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;
}
}
5 changes: 0 additions & 5 deletions src/main/java/org/runejs/client/net/IncomingPackets.java
Original file line number Diff line number Diff line change
@@ -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();
1 change: 1 addition & 0 deletions src/main/java/org/runejs/client/net/PacketType.java
Original file line number Diff line number Diff line change
@@ -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),
Original file line number Diff line number Diff line change
@@ -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());
}
}
Original file line number Diff line number Diff line change
@@ -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<LoadConstructedRegionInboundMessage> {
@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
);
}
}