From e2bad3c45c4c8062bf3347396036d25a5472fd11 Mon Sep 17 00:00:00 2001 From: Sam Sung <51686767+samwhosung@users.noreply.github.com> Date: Sun, 22 Nov 2026 13:47:58 +0700 Subject: [PATCH] A self-flagged create of a new guid becomes our player (#3046) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit A create block's update flag 0x01 marks the receiver's own player, and benilla never read it: `SelfGuid` stayed the login guid. On a server that streams us under another guid, such as cross-realm battlegrounds, the client had no player at all. Reference: on the path for a guid the object lookup does not find (`0x46623b`), flag 1 stores the block's guid as the active player before the object exists (`0x466245`, `0x466254`), which `0x468550` returns. The path for a held object (`0x466350`) stores nothing. The parser reads the flag, a new event goes ahead of its create, and its handler moves `SelfGuid` and the `SelfPlayer` tag unless the guid is live or released. On a stock server the flagged guid is the login one and nothing changes. Tests: a byte-exact create golden, a new guid becoming ours, and a held guid moving nothing. Found in grom/benilla-octo@ab01ff2b. Fixes #3044 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 5.5 --- crates/benilla-app/src/lanes/guard_tests.rs | 3 + crates/benilla-app/src/net/handlers.rs | 1 + crates/benilla-app/src/net/objects/update.rs | 31 +++++++ .../src/net/objects/update_tests.rs | 84 +++++++++++++++++++ crates/benilla-protocol/src/events.rs | 4 + crates/benilla-protocol/src/events/decode.rs | 6 ++ .../src/messages/update_object/movement.rs | 6 ++ .../benilla-protocol/tests/update_object.rs | 54 ++++++++++++ docs/DEVIATIONS.md | 8 +- 9 files changed, 193 insertions(+), 4 deletions(-) diff --git a/crates/benilla-app/src/lanes/guard_tests.rs b/crates/benilla-app/src/lanes/guard_tests.rs index 00ec0e8e9..5bb5522ca 100644 --- a/crates/benilla-app/src/lanes/guard_tests.rs +++ b/crates/benilla-app/src/lanes/guard_tests.rs @@ -635,6 +635,9 @@ pub(super) const READ_ONLY_TO_HANDLERS: &[&str] = &[ "::run_mode::CaptureMode", "::net::game_time::ServerTime", "::net::GuidIndex", + // The released table, which a self-flagged create's lookup reads (`0x46623b`); the update + // packet's handlers write it through their own `ResMut`. + "::net::objects::update::Released", // The bag cache the open-container handler numbers its `BAG_OPEN`s from. "::item_watch::BagCache", "::net::NetCommands", diff --git a/crates/benilla-app/src/net/handlers.rs b/crates/benilla-app/src/net/handlers.rs index 1b72acbe7..53a7c7d9e 100644 --- a/crates/benilla-app/src/net/handlers.rs +++ b/crates/benilla-app/src/net/handlers.rs @@ -244,6 +244,7 @@ pub(crate) fn ends_its_packet(ev: &SessionEvent) -> bool { !matches!( ev, SessionEvent::SavedAnswer { .. } + | SessionEvent::ActivePlayerCreate(_) | SessionEvent::ObjectCreate { .. } | SessionEvent::ItemCreate { .. } | SessionEvent::ObjectValues { .. } diff --git a/crates/benilla-app/src/net/objects/update.rs b/crates/benilla-app/src/net/objects/update.rs index 3ddc5e73e..8f5769e69 100644 --- a/crates/benilla-app/src/net/objects/update.rs +++ b/crates/benilla-app/src/net/objects/update.rs @@ -41,6 +41,7 @@ pub(super) fn register(app: &mut App) { .init_resource::() .init_resource::() .init_resource::() + .net_handler(K::ActivePlayerCreate, on_active_player_create) .net_handler(K::ObjectCreate, on_object_create) .net_handler(K::ItemCreate, on_item_create) .net_handler(K::ObjectValues, on_object_values) @@ -226,6 +227,11 @@ impl Released { self.stale = 0; } + /// Whether `guid` is in the table: a block's lookup finds it (`0x464530`). + fn holds(&self, guid: u64) -> bool { + self.objects.contains_key(&guid) + } + /// Frees every released object, as leaving the world does (`0x467700`). pub(crate) fn clear(&mut self) { self.objects.clear(); @@ -267,6 +273,31 @@ fn item_type(container: bool) -> ObjectType { } } +/// A create block's self flag, ahead of its create: a guid the lookup does not find, live or +/// released, becomes the active player before its object exists (`0x46623b`, `0x466245`, +/// `0x466254`); a held one's update (`0x466350`) stores nothing. A body tagged ours under another +/// guid stops being ours. The new guid's name is the name cache's, asked as any other's. +fn on_active_player_create( + In(ev): In, + mut commands: Commands, + index: Res, + released: Res, + mut self_guid: ResMut, +) { + let SessionEvent::ActivePlayerCreate(guid) = ev else { + return; + }; + if index.0.contains_key(&guid) || released.holds(guid) || self_guid.0 == Some(guid) { + return; + } + let Some(old) = self_guid.0.replace(guid) else { + return; + }; + if let Some(&e) = index.0.get(&old) { + commands.entity(e).remove::(); + } +} + /// A placed object's create block (types 2 and 3, `0x4660a0`). fn on_object_create(In(ev): In, mut sc: Scene) { let SessionEvent::ObjectCreate { diff --git a/crates/benilla-app/src/net/objects/update_tests.rs b/crates/benilla-app/src/net/objects/update_tests.rs index 2b0d2376d..707f7559d 100644 --- a/crates/benilla-app/src/net/objects/update_tests.rs +++ b/crates/benilla-app/src/net/objects/update_tests.rs @@ -1481,3 +1481,87 @@ fn a_leaving_unit_and_a_freed_object_release_their_effects() { super::super::handlers::dispatch(world, vec![SessionEvent::ObjectDestroyed(CHEST)]); assert_eq!(released(world), [chest], "a freed object's destructor"); } + +/// The guid a battleground realm streams us under instead of the login one. +const BG_ME: u64 = 0xF921_0000_0000_0007; + +/// Our name as the login seeds it, and a world entry's body under `ME`, tagged ours. +fn logged_in(world: &mut World) -> Entity { + world.resource_mut::().0 = Some(ME); + world + .resource_mut::() + .insert_player(ME, "Probeseven".into(), None); + super::super::handlers::dispatch( + world, + super::wire(vec![SessionEvent::ActivePlayerCreate(ME), player(ME, &[])]), + ); + world.resource::().0[&ME] +} + +fn ours(world: &mut World) -> Vec { + let mut q = world.query_filtered::<&Guid, With>(); + q.iter(world).map(|g| g.0).collect() +} + +/// A self-flagged create of a guid the lookup does not find makes it the active player before +/// its object exists (`0x46623b`, `0x466245`): the body is ours, the login one is not, and the +/// name follows. On a stock server the flagged guid is the login one, and nothing moves. +#[test] +fn a_self_flagged_create_of_a_new_guid_becomes_our_player() { + let mut app = client(); + let world = app.world_mut(); + let login = logged_in(world); + assert_eq!( + world.resource::().0, + Some(ME), + "stock: the login guid" + ); + assert_eq!(ours(world), [ME], "stock: the login body is ours"); + + super::super::handlers::dispatch( + world, + super::wire(vec![ + SessionEvent::ActivePlayerCreate(BG_ME), + player(BG_ME, &[]), + ]), + ); + + assert_eq!(world.resource::().0, Some(BG_ME)); + assert_eq!( + ours(world), + [BG_ME], + "the new body is ours, the login one not" + ); + assert!(world.get::(login).is_none()); +} + +/// A guid the lookup finds, live or released, goes to the known object's update (`0x466350`), +/// which reads the flag and stores nothing. +#[test] +fn a_self_flagged_create_of_a_held_guid_moves_nothing() { + let mut app = client(); + let world = app.world_mut(); + logged_in(world); + super::super::handlers::dispatch( + world, + super::wire(vec![player(MATE, &[]), player(BG_ME, &[])]), + ); + // MATE released, BG_ME live. + super::super::handlers::dispatch( + world, + super::wire(vec![SessionEvent::ObjectsRemoved(vec![MATE])]), + ); + + super::super::handlers::dispatch( + world, + super::wire(vec![ + SessionEvent::ActivePlayerCreate(BG_ME), + player(BG_ME, &[]), + SessionEvent::ActivePlayerCreate(MATE), + player(MATE, &[]), + ]), + ); + + assert_eq!(world.resource::().0, Some(ME)); + assert_eq!(ours(world), [ME]); +} diff --git a/crates/benilla-protocol/src/events.rs b/crates/benilla-protocol/src/events.rs index aaa8ca6b5..1e3c07c80 100644 --- a/crates/benilla-protocol/src/events.rs +++ b/crates/benilla-protocol/src/events.rs @@ -279,6 +279,10 @@ pub enum SessionEvent { /// its key the first dword (`0x556e5b`): emitted by the IO thread ahead of the answer's /// decoded events, never wire-decoded, for the app's on-disk template caches. SavedAnswer { opcode: u16, body: Vec }, + /// A create block flagged as the receiver's own player (update flag `0x01`), just ahead of + /// its create: the reference takes its guid as the active player before the object exists, + /// for a guid its lookup does not hold (`0x46623b`, `0x466245`, `0x466254`). + ActivePlayerCreate(u64), /// A placed object entered view, its spawn identity decoded per object type. ObjectCreate { guid: u64, diff --git a/crates/benilla-protocol/src/events/decode.rs b/crates/benilla-protocol/src/events/decode.rs index b9cdab33e..0839d94cf 100644 --- a/crates/benilla-protocol/src/events/decode.rs +++ b/crates/benilla-protocol/src/events/decode.rs @@ -1204,6 +1204,10 @@ fn decode_objects(first_pass: bool, objects: Vec) -> Vec { movement, mask, } => { + // The self flag travels just ahead of its create, in whichever pass writes it. + let active = movement + .active_player + .then_some(SessionEvent::ActivePlayerCreate(guid)); let Some(create) = create_event(guid, object_type, movement, mask) else { continue; }; @@ -1213,10 +1217,12 @@ fn decode_objects(first_pass: bool, objects: Vec) -> Vec { _ => NotifyBlock::ItemCreate, }; if first_pass { + first.extend(active); first.push(create); } second.push(SessionEvent::ObjectNotify { guid, block }); } else { + second.extend(active); second.push(create); } } diff --git a/crates/benilla-protocol/src/messages/update_object/movement.rs b/crates/benilla-protocol/src/messages/update_object/movement.rs index ab46571ee..5f086bc74 100644 --- a/crates/benilla-protocol/src/messages/update_object/movement.rs +++ b/crates/benilla-protocol/src/messages/update_object/movement.rs @@ -37,6 +37,8 @@ impl ObjectType { } } +/// `UPDATEFLAG_SELF`: the block is the receiver's own player; no field rides it. +const UPDATE_FLAG_SELF: u8 = 0x01; const UPDATE_FLAG_TRANSPORT: u8 = 0x02; const UPDATE_FLAG_MELEE_ATTACKING: u8 = 0x04; const UPDATE_FLAG_HIGH_GUID: u8 = 0x08; @@ -112,6 +114,9 @@ pub struct MovementBlock { pub transport: Option, /// The path this unit is already walking at create (`MOVEFLAG_SPLINE_ENABLED`). pub spline: Option, + /// Flag `0x01`: the receiver's own player, which only a create of a new object acts on + /// (`0x466237`). + pub active_player: bool, } impl MovementBlock { @@ -235,6 +240,7 @@ impl MovementBlock { transport_progress, transport, spline, + active_player: update_flag & UPDATE_FLAG_SELF != 0, }) } } diff --git a/crates/benilla-protocol/tests/update_object.rs b/crates/benilla-protocol/tests/update_object.rs index 727e9ee09..9231e1242 100644 --- a/crates/benilla-protocol/tests/update_object.rs +++ b/crates/benilla-protocol/tests/update_object.rs @@ -971,3 +971,57 @@ fn an_out_of_range_list_decodes_only_as_the_first_block() { ] ); } + +/// A player create block with `flags`, as vmangos writes the receiver's own (`UPDATEFLAG_SELF | +/// ALL | LIVING | HAS_POSITION`, 0x71) or another's (0x70): a level `LIVING` block, the `ALL` +/// u32, no values. +fn player_create(guid: u64, flags: u8) -> Vec { + let mut block = vec![3]; // CREATE_OBJECT2 + write_packed_guid(guid, &mut block).unwrap(); + block.push(4); // TypeId::Player + block.push(flags); + block.extend_from_slice(&0u32.to_le_bytes()); // movement flags + block.extend_from_slice(&1u32.to_le_bytes()); // time + for v in [10.0f32, 20.0, 30.0, 0.5] { + block.extend_from_slice(&v.to_le_bytes()); + } + block.extend_from_slice(&0u32.to_le_bytes()); // fall time + for v in [2.5f32, 7.0, 4.5, 4.722_222_3, 2.5, std::f32::consts::PI] { + block.extend_from_slice(&v.to_le_bytes()); + } + block.extend_from_slice(&1u32.to_le_bytes()); // UPDATEFLAG_ALL + block.push(0); // no mask words + block +} + +/// Update flag 0x01 names the receiver's own player (`0x466237`): its create goes out just behind +/// the block's guid as the active player, ahead of the create; a create without it carries none. +#[test] +fn a_self_flagged_create_names_the_active_player_ahead_of_it() { + let own = 0xF921_0000_0000_0007; + let mut body = hx("0200000000"); + body.extend_from_slice(&player_create(own, 0x71)); + body.extend_from_slice(&player_create(0x2A, 0x70)); + assert_eq!( + player_create(own, 0x71), + hx(&[ + "03c10721f90471", // create2, packed guid, player, flags + "0000000001000000", // movement flags, time + "000020410000a0410000f0410000003f", // x, y, z, facing + "00000000", // fall time + "000020400000e04000009040721c974000002040db0f4940", // speeds + "0100000000", // ALL, no mask words + ] + .concat()), + "the block as vmangos writes it" + ); + assert_eq!( + update_shapes(&body), + [ + format!("ActivePlayerCreate({own})"), + format!("create {own:#x}"), + "create 0x2a".into(), + "end".into(), + ] + ); +} diff --git a/docs/DEVIATIONS.md b/docs/DEVIATIONS.md index cf03884d4..2cd7c08f7 100644 --- a/docs/DEVIATIONS.md +++ b/docs/DEVIATIONS.md @@ -117,7 +117,7 @@ Each entry is the first sentence of a `Deviation:` comment, linking to where it - A mounted draw is refused at the setter, because our rider track never replays the reference's per-play force-stow (`0x5fdf80`); the result is the same. ([`src/creature_anim/driver.rs:792`](../crates/benilla-app/src/creature_anim/driver.rs#L792)) - The reference writes bone 0's rate blindly; we scope it to the swing's own node, because a moving attacker's gait would otherwise slow too. The id is re-checked, as `Mode::Swing` also holds non-swing one-shots. ([`src/creature_anim/driver.rs:1111`](../crates/benilla-app/src/creature_anim/driver.rs#L1111)) - A time-based rate, because the reference's per-frame step changes with the frame rate. ([`src/creature_anim/select.rs:137`](../crates/benilla-app/src/creature_anim/select.rs#L137)) -- A spell's state kit and body procs are reaped only once no slot holds the spell because the reference's removal of one slot (`0x612320` → `0x5ff290`) stops every effect of that spell on the unit (`0x614150(spell, 1)` at `0x5ff2d2`, and its procs through `0x60d150` and `0x5ff320`), even while another slot holds the same spell, which drops a visual the server says still holds. ([`src/creature_anim/spell_visual.rs:1367`](../crates/benilla-app/src/creature_anim/spell_visual.rs#L1367)) +- A spell's state kit and body procs are reaped only once no slot holds the spell because the reference's removal of one slot (`0x612320` → `0x5ff290`) stops every effect of that spell on the unit (`0x614150(spell, 1)` at `0x5ff2d2`, and its procs through `0x60d150` and `0x5ff320`), even while another slot holds the same spell, which drops a visual the server says still holds. ([`src/creature_anim/spell_visual.rs:1376`](../crates/benilla-app/src/creature_anim/spell_visual.rs#L1376)) #### cvars @@ -189,8 +189,8 @@ Each entry is the first sentence of a `Deviation:` comment, linking to where it - The reference places collision and culling by the raw facing, ours follow the display facing, because a capsule and a sphere barely change under rotation. ([`src/net/motion/facing.rs:10`](../crates/benilla-app/src/net/motion/facing.rs#L10)) - The reference paces a self move through the same replay chain as a remote's; benilla hands it over at arrival because pacing it would only delay a correction to our own pose. ([`src/net/motion/remote.rs:110`](../crates/benilla-app/src/net/motion/remote.rs#L110)) - Its rate-limited hover climb (`0x636fa1`, 7 yd/s) is not reproduced, because the cache gate needs a pure function; it converges to this answer. ([`src/net/motion/spline.rs:794`](../crates/benilla-app/src/net/motion/spline.rs#L794)) -- A first-pass values block the clear header byte left unwritten re-fires, for a live object, its last write's edges against the watch copy (`0x465570`, `0x466686`); benilla compares against this packet's copies, which hold none for it, because that way a stale edge never fires twice. ([`src/net/objects/update.rs:1123`](../crates/benilla-app/src/net/objects/update.rs#L1123)) -- The create notify uses its lookup's result untested (`0x465c97`, `0x465d79`). For a first-pass create the clear header byte left unwritten, an object not live crashes the reference, and a live one runs the all-fields watch (`0x465d8e`) against its stale watch copy, re-firing its last write's edges as the values block above does; benilla's `notify` fires nothing for either, because the faults the reference's passes have on malformed packets are recorded, not copied. ([`src/net/objects/update.rs:1135`](../crates/benilla-app/src/net/objects/update.rs#L1135)) +- A first-pass values block the clear header byte left unwritten re-fires, for a live object, its last write's edges against the watch copy (`0x465570`, `0x466686`); benilla compares against this packet's copies, which hold none for it, because that way a stale edge never fires twice. ([`src/net/objects/update.rs:1154`](../crates/benilla-app/src/net/objects/update.rs#L1154)) +- The create notify uses its lookup's result untested (`0x465c97`, `0x465d79`). For a first-pass create the clear header byte left unwritten, an object not live crashes the reference, and a live one runs the all-fields watch (`0x465d8e`) against its stale watch copy, re-firing its last write's edges as the values block above does; benilla's `notify` fires nothing for either, because the faults the reference's passes have on malformed packets are recorded, not copied. ([`src/net/objects/update.rs:1166`](../crates/benilla-app/src/net/objects/update.rs#L1166)) - On benilla's unattended reconnect, which the reference lacks, the world's VM survives the loss; because of that the clear signals its `PLAYER_TARGET_CHANGED` and usable refresh as a release's teardown does (`0x493a69`, `0x493a73`), still sending nothing, and the surviving target frame lets the lost unit go. ([`src/net/session.rs:319`](../crates/benilla-app/src/net/session.rs#L319)) #### no_install @@ -664,7 +664,7 @@ Each entry is the first sentence of a `Deviation:` comment, linking to where it #### events -- `benilla::spell_mods` refuses an out-of-range pair, because the reference would overrun it. ([`src/events.rs:792`](../crates/benilla-protocol/src/events.rs#L792)) +- `benilla::spell_mods` refuses an out-of-range pair, because the reference would overrun it. ([`src/events.rs:796`](../crates/benilla-protocol/src/events.rs#L796)) - An out-of-range list past the first block reads no body in the write passes (`0x466076`), which misread every block behind it, while the notify pass reads past it (`0x465fd0`) and stays in step; benilla reads the list and drops it, keeping the blocks behind it whole, because the faults the reference's passes have on malformed packets are recorded, not copied. ([`src/events/decode.rs:1154`](../crates/benilla-protocol/src/events/decode.rs#L1154)) - The flagged pass reads a movement block's guid as 8 raw bytes (`0x467140`, `0x46714d`) where the wire packs it, so unless the packed guid happens to be 8 bytes the reference misreads the rest of that pass; benilla reads the block once, packed, as pass 0 does (`0x467080`), because of the misreading just described. ([`src/events/decode.rs:1172`](../crates/benilla-protocol/src/events/decode.rs#L1172))