Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
5 changes: 5 additions & 0 deletions client/game/OsrsClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8325,6 +8325,11 @@ export class OsrsClient {
if (block.faceTile) {
applyNpcFaceTile(this.npcEcs, ecsId, block.faceTile);
}
if (block.faceAngle) {
// Instant sets the drawn angle too: the only way to turn an NPC whose turn speed is 0.
this.npcEcs.setTargetRot(ecsId, block.faceAngle.angle);
if (block.faceAngle.instant) this.npcEcs.setRotation(ecsId, block.faceAngle.angle);
}
if (typeof block.faceEntity === "number") {
this.npcEcs.setInteractionIndex(ecsId, block.faceEntity | 0);
}
Expand Down
6 changes: 3 additions & 3 deletions client/game/scene/SceneRaycaster.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { mat4, vec3 } from "gl-matrix";

import { LocModelLoader } from "../../rs/config/loctype/LocModelLoader";
import { LocModelType } from "../../rs/config/loctype/LocModelType";
import type { NpcType } from "../../rs/config/npctype/NpcType";
import { type NpcType, npcTypeHasModel } from "../../rs/config/npctype/NpcType";
import type { LocType } from "../../rs/config/loctype/LocType";
import type { Model } from "../../rs/model/Model";
import { Scene } from "../../rs/scene/Scene";
Expand Down Expand Up @@ -730,7 +730,7 @@ export class SceneRaycaster {
npcType = npcType.transform(this.osrsClient.varManager, this.osrsClient.npcTypeLoader);
}
// Model-less NPC spawns must not intercept objects behind their bounding box.
if (!npcType?.modelIds?.length) continue;
if (!npcTypeHasModel(npcType)) continue;
isFishingSpot = String(npcType.name ?? "").toLowerCase().includes("fishing spot");
// The scaled model's height; size is already the scaled footprint in tiles.
heightTiles = (this.npcHeightProvider?.(npcType.id) ?? 200) / 128;
Expand Down Expand Up @@ -849,7 +849,7 @@ export class SceneRaycaster {
while (npcType?.transforms) {
npcType = npcType.transform(this.osrsClient.varManager, this.osrsClient.npcTypeLoader);
}
if (!npcType?.modelIds?.length) return;
if (!npcTypeHasModel(npcType)) return;
heightTiles = (this.npcHeightProvider?.(npcType.id) ?? 200) / 128;
} catch {
return;
Expand Down
14 changes: 13 additions & 1 deletion client/game/sync/NpcUpdateDecoder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ export type NpcUpdateBlock = {
exactMove?: ForcedMovementUpdate;
/** A world tile to turn to once (OSRS npc face coord). */
faceTile?: { x: number; y: number };
/** A held facing (OSRS npc face angle); instant snaps to it, even an NPC that never turns. */
faceAngle?: { angle: number; instant: boolean };
/** Body-model slot overrides (OSRS npc model customisation); an empty list resets them. */
modelCustomisation?: Array<{ slot: number; modelId: number }>;
/**
Expand Down Expand Up @@ -465,7 +467,11 @@ export class NpcUpdateDecoder {
if ((flags & TYPE_MODELS) !== 0) {
const count = stream.readUnsignedByte() | 0;
custom.models = [];
for (let i = 0; i < count; i++) custom.models.push(stream.readUnsignedShortBE() | 0);
for (let i = 0; i < count; i++) {
// 0xffff is -1: no model, so the NPC is drawn as nothing (the Hueycoatl's sunk tail).
const model = stream.readUnsignedShortBE() | 0;
custom.models.push(model === 0xffff ? -1 : model);
}
}
if ((flags & TYPE_RECOLOURS) !== 0) {
const count = stream.readUnsignedByte() | 0;
Expand All @@ -481,6 +487,12 @@ export class NpcUpdateDecoder {
block.typeCustomisation = custom;
}

// FACE_ANGLE (0x80000): an angle (0 south, 512 west, 1024 north, 1536 east) and whether to snap to it.
if ((mask & 0x80000) !== 0) {
const angle = stream.readUnsignedShortBE() & 2047;
block.faceAngle = { angle, instant: (stream.readUnsignedByte() | 0) !== 0 };
}

if (Object.keys(block).length > 0) {
updateBlocks.set(npcId | 0, block);
}
Expand Down
1 change: 1 addition & 0 deletions client/render/render/overlays.ts
Original file line number Diff line number Diff line change
Expand Up @@ -330,6 +330,7 @@ export function getNpcDefaultHeight(host: WebGLOsrsRendererHost, npcTypeId: numb
// Load and merge model data
const models: ModelData[] = [];
for (const modelId of npcType.modelIds) {
if (modelId < 0) continue;
const modelData = host.osrsClient.modelLoader.getModel(modelId);
if (modelData) {
models.push(modelData);
Expand Down
6 changes: 3 additions & 3 deletions client/rs/config/npctype/NpcModelLoader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { TextureLoader } from "../../texture/TextureLoader";
import { SeqType } from "../seqtype/SeqType";
import { SeqTypeLoader } from "../seqtype/SeqTypeLoader";
import { VarManager } from "../vartype/VarManager";
import { NpcType } from "./NpcType";
import { NpcType, npcTypeHasModel } from "./NpcType";
import { NpcTypeLoader } from "./NpcTypeLoader";

export class NpcModelLoader {
Expand Down Expand Up @@ -49,8 +49,8 @@ export class NpcModelLoader {
);
}

// NPC has no model IDs defined (opcode 1 was never decoded)
if (!npcType.modelIds || npcType.modelIds.length === 0) {
// NPC has no model IDs defined (opcode 1 was never decoded), or one of them is -1
if (!npcTypeHasModel(npcType)) {
return undefined;
}

Expand Down
9 changes: 9 additions & 0 deletions client/rs/config/npctype/NpcType.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,15 @@ export enum NpcDrawPriority {
DRAW_PRIORITY_LAST = 2,
}

/**
* Whether the type has a model to draw. A model id of -1 (the server's body customisation, e.g.
* the Hueycoatl's sunk tail) loads nothing, so the whole NPC is drawn as nothing and can't be clicked.
*/
export function npcTypeHasModel<T extends { modelIds?: number[] }>(type: T | undefined): type is T {
const ids = type?.modelIds;
return !!ids && ids.length > 0 && ids.every((id) => id >= 0);
}

export class NpcType extends Type {
name: string;
desc?: string;
Expand Down
65 changes: 65 additions & 0 deletions client/tests/npc-face-angle-hidden-models.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
import assert from "node:assert/strict";

import { NpcUpdateDecoder } from "../game/sync/NpcUpdateDecoder";
import { npcTypeHasModel } from "../rs/config/npctype/NpcType";
import {
createNpcSyncState,
encodeNpcSync,
} from "../../server/src/main/typescript/elvarg/net/protocol/ClientProtocol";

/**
* The Hueycoatl's tail (rsprox.net 4052, 4054): it never turns, so live holds it with npc
* face_angle (instant) at 512 out of the east cave and 1536 out of the west one, and while it is
* sunk its body customisation replaces every model with -1, so it is drawn as nothing.
*/
function decodeNpcs(packet: Buffer, decoder: NpcUpdateDecoder) {
const body = packet.subarray(3);
const length = body.readUInt16BE(9);
return decoder.decode(body.subarray(11, 11 + length), {
large: body[4] === 1,
loopCycle: 0,
clientCycle: 100,
localTileX: 3200,
localTileY: 3200,
level: 0,
});
}

function roundTrip(): void {
const state = createNpcSyncState();
const decoder = new NpcUpdateDecoder();
const local = { x: 3200, y: 3200, level: 0 };
const view = (extra: object) => ({
index: 9, typeId: 14014, x: 3204, y: 3204, level: 0,
rotation: 0, walkDirection: -1, runDirection: -1, forcedChat: "before", ...extra,
});
let decoded = decodeNpcs(encodeNpcSync(1, local, [view({}) as any], state), decoder);
assert.equal(decoded.updateBlocks.get(9)?.faceAngle, undefined, "none unless sent");

decoded = decodeNpcs(encodeNpcSync(2, local, [view({
faceAngle: { angle: 512, instant: true },
typeCustomisation: { models: [-1] },
}) as any], state), decoder);
const block = decoded.updateBlocks.get(9);
assert.deepEqual(block?.faceAngle, { angle: 512, instant: true });
assert.deepEqual(block?.typeCustomisation, { models: [-1] }, "-1 survives the wire");
assert.equal(block?.say, "before", "the blocks before it stay aligned");

decoded = decodeNpcs(encodeNpcSync(3, local, [view({ faceAngle: { angle: 1536, instant: false } }) as any], state), decoder);
assert.deepEqual(decoded.updateBlocks.get(9)?.faceAngle, { angle: 1536, instant: false });

decoded = decodeNpcs(encodeNpcSync(4, local, [view({ typeCustomisation: { models: [-1, -1, -1] } }) as any], state), decoder);
assert.deepEqual(decoded.updateBlocks.get(9)?.typeCustomisation, { models: [-1, -1, -1] }, "the broken tail's three models");
}

function hiddenModelsDrawNothing(): void {
assert.equal(npcTypeHasModel({ modelIds: [50311] }), true);
assert.equal(npcTypeHasModel({ modelIds: [-1] }), false, "a -1 model is drawn as nothing");
assert.equal(npcTypeHasModel({ modelIds: [50311, -1, 50312] }), false, "one -1 hides the whole NPC");
assert.equal(npcTypeHasModel({ modelIds: [] }), false);
assert.equal(npcTypeHasModel(undefined), false);
}

roundTrip();
hiddenModelsDrawNothing();
console.log("NPC face angle and hidden model tests passed");
6 changes: 4 additions & 2 deletions docs/hueycoatl.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ All ticks below are from rsprox 3399 (a solo fight, two kills) and agree with 32
### Phase 3: the tail

- The tail plays `npc_huey_tail_appear_01` (11720) and slams 2 ticks later; it stays 36 ticks, plays `npc_huey_tail_disappear_01` (11721) and shows on the other side 2 ticks later. While it rises and sinks it takes no damage (Wiki).
- The tail never turns (turn speed 0), so every show sets npc `face_angle` (instant) for its side: 512 (facing west) in the east cave, 1536 (facing east) in the west one; it is added with 512. It is added drawn as nothing (body customisation model -1) and the customisation is reset as it shows. 2 ticks after a sink that is not followed by a show on that tick, it is hidden again: model -1 for the whole tail; for the broken one live sent three -1s (rev 237; our cache's 14015 has two models, and any -1 hides the NPC). A player who comes into view while it is sunk gets the hidden state with the add, so sees no tail (rsprox recording 4052: added at tick 80, shows at 81, 119; broken sinks at 159 and 189, hidden at 161 and 191).
- Its hits are capped at 4, or 9 when the attacker's crush attack bonus is their highest; a miss still deals 1 (Wiki; the captured hits were 1, 4, 5 and 9).
- The shielded head attacks every 15 ticks (`huey_shield_attack_*`, 11673-11675).
- The tail broken: `npc_huey_tail_break_01` (11723) and the change to 14015 (`huey_tail_broken`), sound 9678, the head's `huey_screech` (11677). A tick later "The Hueycoatl's shield falls!"; 3 ticks after the break `huey_screech_reset` (11678) and the head is 14009 again. The broken tail sinks 4 ticks after it broke.
Expand All @@ -75,7 +76,7 @@ All ticks below are from rsprox 3399 (a solo fight, two kills) and agree with 32

## Attacks

- **Rain Fire:** the head rears with `huey_attack_<style>` (11669 melee, 11670 ranged, 11671 magic) and its charge spotanim (2968, 2971, 2974). 4 ticks later a feather falls on every player in the arena, each seeing their own: from the tile above them, start height 900, end height 200, angle 80, landing 150 cycles later on the summit and 210 on the mountainside (2969, 2972, 2975), with the impact (2970, 2973, 2976). Launch sounds 9652 / 9671 / 9607, impact sounds 9655 / 9608 / 9642 (melee / ranged / magic). The matching protection prayer holds it to 0-2 damage, else up to 14 (Wiki). One style per volley for everyone is ours; the capture only shows each player their own. Capture 3399 sends the shared NPC sequence 11669 followed by viewer-specific style sequences (11670/11671, and 11673-11675 while shielded). Those specific packets replace the viewer's animation; the aggregate NPC-animation inventory alone is not evidence that every rendered volley uses 11669.
- **Rain Fire:** the head plays `huey_attack_melee` (11669) in the shared NPC update for every volley, shielded or not, with no shared spotanim. On the same tick each target is sent its own `npc_anim_specific` `huey_attack_<style>` (11669 melee, 11670 ranged, 11671 magic; `huey_shield_attack_*` 11673-11675 while shielded) and `npc_spotanim_specific` charge spotanim in slot 0 (2968, 2971, 2974) (recordings 4052, 4054, 3399). 4 ticks later a feather falls on every player in the arena, each seeing their own: from the tile above them, start height 900, end height 200, angle 80, landing 150 cycles later on the summit and 210 on the mountainside (2969, 2972, 2975), with the impact (2970, 2973, 2976). Launch sounds 9652 / 9671 / 9607, impact sounds 9655 / 9608 / 9642 (melee / ranged / magic). The matching protection prayer holds it to 0-2 damage, else up to 14 (Wiki). One style per volley for everyone is ours; the captures only show each player their own.
- **Glowing symbols** every 26 ticks (body and head), 36 (tail) and 24 (final): `huey_attack_tiles_loc` (55209) with `vfx_hueycoatl_prayer_02` (3001, delay 120) on each tile, removed 4 ticks later with lightning (sound 9612) striking whoever still stands on one, up to 16 (Wiki). A cast lights the fixed tiles of each part of the mountain with players on it, and enough others from its pool to make 15 on the mountainside and 22 on the summit (the captured medians; the fixed tiles were in every one of 53 and 130 casts). The tiles are in the data file.
- **The tail's slam:** two waves, identical every time (82 of 82 recorded): 195 tiles from the west side, 190 from the east, each tile's spotanim (the wave's direction, 2977-2984) delayed 15 cycles per tile of distance from the tail (30-270). Whoever stands on a tile as the wave arrives (delay / 30 ticks after the slam) takes 20-25 (Wiki) with the impact spotanim (2993-3000); moving through it dodges it. Sounds 9568 and 9573. The waves are in the data file.

Expand Down Expand Up @@ -104,6 +105,7 @@ Champion, Adept and Veteran finish from the kill count. The fight decides the re
- The glowing symbol's circle (loc 55209, model 54454, animation 11730) lies at ground level (model y 0 to +3). The OSRS client paints scenery over the terrain without a depth test; our GPU client depth-tests it, so on sloped ground the circle sinks under the terrain and only its rising parts show. A client fix, not this plugin's.

- Where the chain's climb back lands and the private fight's fee messages remain estimated; running Peek lines now use the Wiki Strategies source.
- Issue #3558's missing/misplaced skeletal body cave models and tail orientation, first-frame and late-view sunk-state reports remain unresolved. This repair changes their Peek text and pet penalty only; it does not alter loc rendering or the tail lifecycle.
- Issue #3558's report of missing or misplaced body cave models was checked side by side with live (2026-11-23): the five caves look the same, so nothing changed there. The tail's angles are from April 2026 recordings; the 30 September 2026 update "Fixed Hueycoatl's tail spawning in the wrong orientation" postdates every recording.
- Live turns off the tail's menu ops while it sinks and is hidden (npc `enabled_ops` 0, Attack only while shown); tsps has no NPC ops packet, so the hidden tail is protected by the fight's own checks only.
- The seer's body- and tail-phase lines play on segment deaths and tail swaps; live's exact cadence was not worked out.
- Tome of Earth, the dragon hunter wand and the hide armour are items of their own; this covers only dropping them.
6 changes: 6 additions & 0 deletions runelite-gateway/src/main/kotlin/gateway/down/ActorBlocks.kt
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ class ActorBlock {
var transparency: Transparency? = null
var typeCustomisation: TypeCustomisation? = null

/** A held NPC facing (OSRS npc face angle): the angle, and whether to snap to it. */
var faceAngle: Pair<Int, Boolean>? = null

class Hit(val type: Int, val damage: Int, val delay: Int)

class Headbar(val id: Int, val remove: Boolean, val duration: Int, val delay: Int, val fill: Int, val endFill: Int)
Expand Down Expand Up @@ -96,6 +99,7 @@ object ActorBlocks {
private const val NPC_TRANSPARENCY = 0x8000
private const val NPC_SPOT_ANIM = 0x20000
private const val NPC_TYPE_CUSTOMISATION = 0x40000
private const val NPC_FACE_ANGLE = 0x80000

/** NPC_TYPE_CUSTOMISATION's leading flags: which fields follow. */
private const val TYPE_MODELS = 0x1
Expand Down Expand Up @@ -174,6 +178,8 @@ object ActorBlocks {
block.transparency = ActorBlock.Transparency(reader.u16(), reader.u16(), reader.u16().noneAsMinusOne(), reader.u8())
}
if (mask and NPC_TYPE_CUSTOMISATION != 0) block.typeCustomisation = typeCustomisation(reader)
// A short angle, then whether the client snaps to it (written after the type customisation).
if (mask and NPC_FACE_ANGLE != 0) block.faceAngle = reader.u16() to (reader.u8() != 0)
return block
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,7 @@ class EntityMirror(
block.forcedChat?.let(info::setSay)
block.faceEntity?.let(info::setFacePathingEntity)
block.faceTile?.let { (x, z) -> info.setFaceCoordGrid(x, z, instant = false, walkMode = 0) }
block.faceAngle?.let { (angle, instant) -> info.setFaceAngle(angle, instant) }
block.animation?.let { (id, delay) -> info.setSequence(id, delay) }
for (hit in block.hits) info.addHitMark(-1, hit.type, hit.type, hit.damage, hit.delay)
for (bar in block.headbars) {
Expand Down
17 changes: 17 additions & 0 deletions runelite-gateway/src/test/kotlin/gateway/down/ActorBlocksTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,23 @@ class ActorBlocksTest {
assertEquals(true, ActorBlocks.typeCustomisation(BlockReader(byteArrayOf(0))).isReset, "no flags resets")
}

@Test
fun `an npc face angle after a type customisation is read and leaves the stream aligned`() {
// tsps writeNpcUpdateBlock for the Hueycoatl's hidden tail: mask 0x40000 | 0x80000 (three
// mask bytes), the type customisation (models flag, one model 0xffff), then the face angle
// (u16 512, instant 1). A trailing byte stands for the next NPC's block.
val bytes = listOf(0x80, 0x40, 0x0C, 0x01, 1, 0xFF, 0xFF, 512 shr 8, 512 and 0xFF, 1, 0x7A)
.map { it.toByte() }.toByteArray()
val reader = BlockReader(bytes)
val block = ActorBlocks.npc(reader)
assertEquals(listOf(0xFFFF), block.typeCustomisation?.models)
assertEquals(512 to true, block.faceAngle)
assertEquals(0x7A, reader.u8(), "the next block starts right after the face angle")

val turning = ActorBlocks.npc(BlockReader(listOf(0x80, 0x40, 0x08, 1536 shr 8, 1536 and 0xFF, 0).map { it.toByte() }.toByteArray()))
assertEquals(1536 to false, turning.faceAngle)
}

@Test
fun `a chat style reads its pattern colours`() {
val style = ChatStyle.read(gateway.tsps.TspsReader(byteArrayOf(14, 2, 3, 4)))!!
Expand Down
Loading
Loading