Skip to content

Commit

Permalink
update npc update packet handling to include new worldIndex byte; add…
Browse files Browse the repository at this point in the history
… resizable and renderFlames config options
  • Loading branch information
charles-m-knox committed Sep 4, 2024
1 parent 96a520c commit 0159ac2
Show file tree
Hide file tree
Showing 6 changed files with 157 additions and 42 deletions.
2 changes: 2 additions & 0 deletions config/client-435.conf.example.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,6 @@ game:
roofsEnabled: true
freeTeleports: false
debugContextMenu: true
renderFlames: true
resizable: false
serverDisplayName: Build 435
28 changes: 21 additions & 7 deletions src/main/java/org/runejs/Configuration.java
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ public static void read() {
SOUND_MUTED = (boolean) game.get("soundMuted");
FREE_TELEPORTS = (boolean) game.get("freeTeleports");
DEBUG_CONTEXT = (boolean) game.get("debugContextMenu");
RESIZABLE = (boolean) game.get("resizable");
RENDER_FLAMES = (boolean) game.get("renderFlames");
SERVER_DISPLAY_NAME = (String) obj.get("serverDisplayName");

if (USERNAME == null) {
Expand All @@ -51,7 +53,7 @@ public static void read() {
if (PASSWORD == null) {
PASSWORD = "";
}

if (SERVER_DISPLAY_NAME == null) {
SERVER_DISPLAY_NAME = "Build 435";
}
Expand Down Expand Up @@ -81,7 +83,8 @@ public static void read() {
game.put("freeTeleports", FREE_TELEPORTS);
game.put("debugContextMenu", DEBUG_CONTEXT);
game.put("soundMuted", SOUND_MUTED);

game.put("resizable", RESIZABLE);
game.put("renderFlames", RENDER_FLAMES);

Map<String, Object> clientConfig = new HashMap<String, Object>();
clientConfig.put("serverDisplayName", SERVER_DISPLAY_NAME);
Expand Down Expand Up @@ -177,6 +180,17 @@ public static void read() {
*/
public static boolean FREE_TELEPORTS = true;

/**
* Enable resizable mode
*/
public static boolean RESIZABLE = false;

/**
* Toggle rendering frames to reduce wasted processing power on the login
* screen
*/
public static boolean RENDER_FLAMES = true;

/**
* When rightclicking objects show id and location
*/
Expand Down Expand Up @@ -213,7 +227,7 @@ public static void setSoundMuted(boolean soundMuted) {
final Map<String, Object> obj = yaml.load(inputStream);
final Map<String, Object> game = (Map<String, Object>) obj.get("game");
game.put("soundMuted", SOUND_MUTED);
obj.put("game",game);
obj.put("game", game);
FileWriter writer = new FileWriter(configFile);
yaml.dump(obj, writer);

Expand All @@ -225,18 +239,18 @@ public static void setSoundMuted(boolean soundMuted) {
}

public static RSString getUsername() {
if(USE_STATIC_DETAILS) {
if (USE_STATIC_DETAILS) {
return RSString.CreateString(USERNAME);
} else{
} else {
return Native.string_blank;
}
}


public static RSString getPassword() {
if(USE_STATIC_DETAILS) {
if (USE_STATIC_DETAILS) {
return RSString.CreateString(PASSWORD);
} else{
} else {
return Native.string_blank;
}
}
Expand Down
9 changes: 7 additions & 2 deletions src/main/java/org/runejs/client/GameShell.java
Original file line number Diff line number Diff line change
Expand Up @@ -241,9 +241,14 @@ public void openClientApplet(String cacheFolder, int cacheIndexes, int fileStore
currentGameShell = this;
clientFrame = new Frame();
clientFrame.setTitle(Configuration.SERVER_DISPLAY_NAME);
ScreenController.frameMode(ScreenMode.FIXED);
if (Configuration.RESIZABLE == true) {
ScreenController.frameMode(ScreenMode.RESIZABLE);
clientFrame.setResizable(true);
} else {
ScreenController.frameMode(ScreenMode.FIXED);
clientFrame.setResizable(false);
}
clientFrame.setPreferredSize(new Dimension(width, height));
clientFrame.setResizable(ScreenController.frameMode == ScreenMode.RESIZABLE);
clientFrame.addWindowListener(this);
clientFrame.setVisible(true);
clientFrame.toFront();
Expand Down
4 changes: 3 additions & 1 deletion src/main/java/org/runejs/client/LoginScreen.java
Original file line number Diff line number Diff line change
Expand Up @@ -313,7 +313,9 @@ public static void drawLoadingScreen(TypeFace fontBold, TypeFace fontSmall) {
Rasterizer.drawDiagonalLine(0,0, 42,42, 0xFF0000);
}

renderFlames();
if (Configuration.RENDER_FLAMES) {
renderFlames();
}

try {
int offsetX = 0;
Expand Down
152 changes: 122 additions & 30 deletions src/main/java/org/runejs/client/media/renderable/actor/Npc.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,49 +11,117 @@ public class Npc extends Actor {
public ActorDefinition actorDefinition;

public static void parseNpcUpdateMasks(PacketBuffer buffer) {
for(int i = 0; i < actorUpdatingIndex; i++) {
int npcIndex = Player.actorUpdatingIndices[i];
Npc npc = Player.npcs[npcIndex];
for (int i = 0; i < actorUpdatingIndex; i++) {
int npcIndex = -1;
Npc npc = null;

boolean alreadyGotWorldIndex = false;

int mask = buffer.getUnsignedByte();
if((0x1 & mask) != 0) {
if ((0x1 & mask) != 0) {
int i_3_ = buffer.getUnsignedByte();
int i_4_ = buffer.getUnsignedByte();
int remainingHitpoints = buffer.getUnsignedByte();
int maximumHitpoints = buffer.getUnsignedByte();

// the NPC's worldIndex byte won't be included if it was already
// sent earlier
if (!alreadyGotWorldIndex) {
npcIndex = buffer.getUnsignedShortBE();
npc = Player.npcs[npcIndex];
alreadyGotWorldIndex = true;
}

npc.method785(i_4_, MovedStatics.pulseCycle, i_3_);
npc.anInt3139 = MovedStatics.pulseCycle + 300;
npc.remainingHitpoints = buffer.getUnsignedByte();
npc.maximumHitpoints = buffer.getUnsignedByte();
npc.remainingHitpoints = remainingHitpoints;
npc.maximumHitpoints = maximumHitpoints;
}
if((0x20 & mask) != 0) {
npc.graphicId = buffer.getUnsignedShortLE();
if ((0x20 & mask) != 0) {
int graphicId = buffer.getUnsignedShortLE();
int i_5_ = buffer.getIntBE();

// the NPC's worldIndex byte won't be included if it was already
// sent earlier
if (!alreadyGotWorldIndex) {
npcIndex = buffer.getUnsignedShortBE();
npc = Player.npcs[npcIndex];
alreadyGotWorldIndex = true;
}
npc.graphicId = graphicId;
npc.anInt3129 = 0;
npc.graphicDelay = MovedStatics.pulseCycle + (0xffff & i_5_);
npc.graphicHeight = i_5_ >> 16;
npc.anInt3140 = 0;
if(npc.graphicDelay > MovedStatics.pulseCycle)
if (npc.graphicDelay > MovedStatics.pulseCycle)
npc.anInt3140 = -1;
if(npc.graphicId == 65535)
if (npc.graphicId == 65535)
npc.graphicId = -1;
}
if((mask & 0x4) != 0) {
npc.facingActorIndex = buffer.getUnsignedShortBE();
if(npc.facingActorIndex == 65535)
if ((mask & 0x4) != 0) {
int facingActorIndex = buffer.getUnsignedShortBE();

// the NPC's worldIndex byte won't be included if it was already
// sent earlier
if (!alreadyGotWorldIndex) {
npcIndex = buffer.getUnsignedShortBE();
npc = Player.npcs[npcIndex];
alreadyGotWorldIndex = true;
}

npc.facingActorIndex = facingActorIndex;

if (npc.facingActorIndex == 65535)
npc.facingActorIndex = -1;
}
if((0x2 & mask) != 0) {
if ((0x2 & mask) != 0) {
int i_6_ = buffer.getUnsignedByte();
int i_7_ = buffer.getUnsignedByte();

int remainingHitpoints = buffer.getUnsignedByte();
int maximumHitpoints = buffer.getUnsignedByte();

// the NPC's worldIndex byte won't be included if it was already
// sent earlier
if (!alreadyGotWorldIndex) {
npcIndex = buffer.getUnsignedShortBE();
npc = Player.npcs[npcIndex];
alreadyGotWorldIndex = true;
}

npc.method785(i_7_, MovedStatics.pulseCycle, i_6_);
npc.anInt3139 = MovedStatics.pulseCycle + 300;
npc.remainingHitpoints = buffer.getUnsignedByte();
npc.maximumHitpoints = buffer.getUnsignedByte();

npc.remainingHitpoints = remainingHitpoints;
npc.maximumHitpoints = maximumHitpoints;
}
if((0x40 & mask) != 0) {
npc.forcedChatMessage = buffer.getString();
if ((0x40 & mask) != 0) {
String forcedChatMessage = buffer.getString();

// the NPC's worldIndex byte won't be included if it was already
// sent earlier
if (!alreadyGotWorldIndex) {
npcIndex = buffer.getUnsignedShortBE();
npc = Player.npcs[npcIndex];
alreadyGotWorldIndex = true;
}

npc.forcedChatMessage = forcedChatMessage;

npc.chatTimer = 100;
}
if((mask & 0x80) != 0) {
npc.actorDefinition = ActorDefinition.getDefinition(buffer.getUnsignedShortBE());
if ((mask & 0x80) != 0) {
int actorDefinition = buffer.getUnsignedShortBE();

// the NPC's worldIndex byte won't be included if it was already
// sent earlier
if (!alreadyGotWorldIndex) {
npcIndex = buffer.getUnsignedShortBE();
npc = Player.npcs[npcIndex];
alreadyGotWorldIndex = true;
}

npc.actorDefinition = ActorDefinition.getDefinition(actorDefinition);
npc.anInt3083 = npc.actorDefinition.rotateRightAnimation;
npc.anInt3113 = npc.actorDefinition.degreesToTurn;
npc.turnRightAnimationId = npc.actorDefinition.rotate90RightAnimation;
Expand All @@ -64,26 +132,50 @@ public static void parseNpcUpdateMasks(PacketBuffer buffer) {
npc.turnLeftAnimationId = npc.actorDefinition.rotate90LeftAnimation;
npc.turnAroundAnimationId = npc.actorDefinition.rotate180Animation;
}
if((mask & 0x8) != 0) {
npc.facePositionX = buffer.getUnsignedShortBE();
npc.facePositionY = buffer.getUnsignedShortLE();
if ((mask & 0x8) != 0) {
int facePositionX = buffer.getUnsignedShortBE();
int facePositionY = buffer.getUnsignedShortLE();

// the NPC's worldIndex byte won't be included if it was already
// sent earlier
if (!alreadyGotWorldIndex) {
npcIndex = buffer.getUnsignedShortBE();
npc = Player.npcs[npcIndex];
alreadyGotWorldIndex = true;
}

npc.facePositionX = facePositionX;
npc.facePositionY = facePositionY;
}
if((0x10 & mask) != 0) {
if ((0x10 & mask) != 0) {
int animationId = buffer.getUnsignedShortBE();
if(animationId == 65535)
animationId = -1;
int animationDelay = buffer.getUnsignedByte();
if(animationId == npc.playingAnimation && animationId != -1) {

// the NPC's worldIndex byte won't be included if it was already
// sent earlier
if (!alreadyGotWorldIndex) {
npcIndex = buffer.getUnsignedShortBE();
npc = Player.npcs[npcIndex];
alreadyGotWorldIndex = true;
}

if (animationId == 65535) {
animationId = -1;
}

if (animationId == npc.playingAnimation && animationId != -1) {
int i_10_ = AnimationSequence.getAnimationSequence(animationId).replyMode;
if(i_10_ == 1) {
if (i_10_ == 1) {
npc.anInt3115 = 0;
npc.anInt3095 = 0;
npc.anInt3104 = 0;
npc.playingAnimationDelay = animationDelay;
}
if(i_10_ == 2)
if (i_10_ == 2)
npc.anInt3095 = 0;
} else if(animationId == -1 || npc.playingAnimation == -1 || AnimationSequence.getAnimationSequence(animationId).forcedPriority >= AnimationSequence.getAnimationSequence(npc.playingAnimation).forcedPriority) {
} else if (animationId == -1 || npc.playingAnimation == -1
|| AnimationSequence.getAnimationSequence(animationId).forcedPriority >= AnimationSequence
.getAnimationSequence(npc.playingAnimation).forcedPriority) {
npc.playingAnimation = animationId;
npc.anInt3115 = 0;
npc.playingAnimationDelay = animationDelay;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@ public void handle(UpdateNPCsInboundMessage message) {

Npc.parseNpcUpdateMasks(message.appearanceUpdates);

for(int i = 0; i < MovedStatics.deregisterActorCount; i++) {
for (int i = 0; i < MovedStatics.deregisterActorCount; i++) {
int trackedNpcIndex = Player.deregisterActorIndices[i];
if(MovedStatics.pulseCycle != Player.npcs[trackedNpcIndex].anInt3134) {
if (Player.npcs[trackedNpcIndex] != null && MovedStatics.pulseCycle != Player.npcs[trackedNpcIndex].anInt3134) {
Player.npcs[trackedNpcIndex].actorDefinition = null;
Player.npcs[trackedNpcIndex] = null;
}
Expand Down

0 comments on commit 0159ac2

Please sign in to comment.