From 260177494692f99f27d9303f42259e05322b3234 Mon Sep 17 00:00:00 2001 From: Nick Messer Date: Fri, 23 Oct 2026 18:48:32 -0400 Subject: [PATCH 1/2] feat(skills): announce instant player music casts with SCSkillStarted The 1.2 client reacts to its own SCSkillStarted of the play / pause score skills (special effects 93 / 94) with CS121 (MIDI) / CS124 (End). Those skills are instant, so the cast-time-only SCSkillStarted never came and the play effect broadcast an empty MIDI cache. A validated player cast whose catalog join skill_effects -> SpecialEffect -> special_effects has type 93 or 94 now sends SCSkillStarted right before its SCSkillFired; other instant skills, NPC casters, rejected casts and the item-caster refusal are unchanged. Adds goldens, the testclient music commands (m*) and the strict live suites musicrun1 / musicrun2. Co-Authored-By: Claude Sonnet 5.5 --- rust/LIVE-TESTING.md | 9 + rust/crates/aaemu-game/PORTING.md | 18 + .../src/systems/skills/music_started_tests.rs | 193 ++++ .../aaemu-game/src/systems/skills/skill.rs | 50 + .../aaemu-game/src/systems/skills/state.rs | 3 + .../aaemu-game/src/systems/skills/tests.rs | 3 + rust/crates/aaemu-testclient/src/scenario.rs | 1 + .../aaemu-testclient/src/scenario/music.rs | 885 ++++++++++++++++++ .../aaemu-testclient/src/scenario/script.rs | 9 +- rust/verify/musicrun1.vtest | 52 + rust/verify/musicrun2.vtest | 18 + 11 files changed, 1239 insertions(+), 2 deletions(-) create mode 100644 rust/crates/aaemu-game/src/systems/skills/music_started_tests.rs create mode 100644 rust/crates/aaemu-testclient/src/scenario/music.rs create mode 100644 rust/verify/musicrun1.vtest create mode 100644 rust/verify/musicrun2.vtest diff --git a/rust/LIVE-TESTING.md b/rust/LIVE-TESTING.md index 77e6323f82..c604468c3f 100644 --- a/rust/LIVE-TESTING.md +++ b/rust/LIVE-TESTING.md @@ -257,6 +257,15 @@ corpse (`/despawn npc `) and watches 130 s for exactly one respawn (serve `RUST_LOG=info,aaemu_game::systems::skills::plots=debug,aaemu_game::systems::npcs=debug` to see the debug lines. +`m*` script commands (`aaemu-testclient/src/scenario/music.rs`, used by `rust/verify/musicrun1.vtest` / +`musicrun2.vtest`) replay the 1.2 client's music wire sequence and fail on a missing callback: +`mcompose` (item cast 22215, CS122 only after the received own `SCSkillFired`), `mrequest` (CS123 cold / +tooltip / unknown / buff-only with reply checks), `mskill` (Unit cast; CS121 after the own +`SCSkillStarted` of the play skill, CS124 after that of pause / close; checks the own broadcast, the game +log receipt and `+buff:N` / `-buff:N` / `=buff:N` buff tokens), `mend`, `mwatch` (listener side: the +received MIDI must hash like the one the composer sent). GM access is used only to seed paper 27902, +instrument 6177 and labor. + The combat step selects its NPC through `CSChangeTargetPacket` and faces it in movement packets so auto attacks and angle restrictions use the intended target. It matches skill responses to the player's object and skill IDs and reads the 1.2 `SkillResult` extra field before optional integer data. Missing combat NPCs and diff --git a/rust/crates/aaemu-game/PORTING.md b/rust/crates/aaemu-game/PORTING.md index 854bd45a83..03987fce82 100644 --- a/rust/crates/aaemu-game/PORTING.md +++ b/rust/crates/aaemu-game/PORTING.md @@ -698,6 +698,24 @@ is no longer mirrored (see "Known deviations", dead NPC returned and healed). branch. Missing-song empty replies and existing read/ownership behavior remain. Request u64 / lookup u32 / response 32-bit widths are unchanged: native SC1e0 sign-extends its signed32 note ID at `391e1691` before callback `391e169b`. + +* systems::skills (music): the C# (and this port) send `SCSkillStarted` only for casts with a + cast time. The play (22213), pause (22214) and close-the-score (22217) skills are instant + (`casting_time` 0, `effect_delay` 200 ms), so the 1.2 client never received the own + `SCSkillStarted` it reacts to with CS121 (MIDI) / CS124 (End): the play effect then + broadcast an empty MIDI cache. A validated player cast of a skill whose catalog join + `skill_effects -> effects(SpecialEffect) -> special_effects` contains type 93 (`PlayUserMusic`) + or 94 (`PauseUserMusic`) now sends `SCSkillStarted` (same timeline id as the fire, cast times + 0, no extra data) directly before its `SCSkillFired` (`skill::schedule_effects`, + `SkillRunState::music_started_pending`). No id list, no `application_method` filter, no change + for other instant skills, NPC casters, rejected casts (they keep the failure `SCSkillStarted`) + or the item-caster refusal of 22213 (sheet 28051 has no `use_skill_id`). Not a retail capture: + derived from the client contract. The authored 200 ms `effect_delay` is unchanged, so the + client's CS121 / CS122 must reach the server within `200 ms - one-way latency` of the fire + (compose relies on the same window for CS122); the live lane measured the CS121 arriving + ~0 ms after the Started on loopback. CS124 (`CSEndMusicPacket`) matches the C#: it is a no-op + while the 30 s ScoreMemorized (6010) buff is active and otherwise removes the tag-1155 play + buffs (6176 / 6177); pause (dispel tag 1202) keeps 6010, close (dispel tag 1155) removes it. Arbitrary high request bits still alias the low32 song key; IDs >= 2^31 can differ between zero-extended sheet IDs and sign-extended native cache keys. No evidence establishes a safe ID-width or ownership-policy change here. diff --git a/rust/crates/aaemu-game/src/systems/skills/music_started_tests.rs b/rust/crates/aaemu-game/src/systems/skills/music_started_tests.rs new file mode 100644 index 0000000000..1ef1516fc6 --- /dev/null +++ b/rust/crates/aaemu-game/src/systems/skills/music_started_tests.rs @@ -0,0 +1,193 @@ +//! Instant player play / pause score skills (special effects 93 / 94) announce themselves with +//! the player's own `SCSkillStarted` immediately before their `SCSkillFired`; other instant +//! skills, rejected casts and non-player casters do not. + +use aaemu_commons::PacketStream; + +use super::super::types::skill_result; +use super::*; +use crate::systems::skills::skill::is_player_music_skill; + +const PLAY: u32 = 10_093; +const PAUSE: u32 = 10_094; +const CLIENT_ONLY: u32 = 10_037; +const COSTLY_PLAY: u32 = 10_095; + +fn special(id: u32, type_id: i32) -> EffectTemplate { + EffectTemplate::Special(super::super::data::effects::SpecialEffect { + id, + special_effect_type_id: type_id, + value1: 0, + value2: 0, + value3: 0, + value4: 0, + }) +} + +fn music_data() -> GameData { + let mut d = data(); + let s = &mut d.systems.skills; + s.add_effect(EffectKind::SpecialEffect, special(9_301, 93), 931); + s.add_effect(EffectKind::SpecialEffect, special(9_302, 94), 932); + s.add_effect(EffectKind::SpecialEffect, special(9_303, 37), 933); + for (id, effect, actual) in [ + (PLAY, 931, 9_301), + (PAUSE, 932, 9_302), + (CLIENT_ONLY, 933, 9_303), + ] { + let mut t = skill_template(id); + t.target_type = 0; // Self + t.damage_type_id = 0; + t.casting_time = 0; + t.effect_delay = 200; + t.effects + .push(skill_effect(effect, EffectKind::SpecialEffect, actual)); + s.add_skill(t); + } + let mut costly = (**s.skill(PLAY).unwrap()).clone(); + costly.id = COSTLY_PLAY; + costly.mana_cost = 5_000; + s.add_skill(costly); + d +} + +fn started_and_fired(frames: &[(u16, Vec)], skill: u32) -> (Vec, Vec) { + let id = skill.to_le_bytes(); + let pick = |op: u16| { + frames + .iter() + .enumerate() + .filter(|(_, (o, b))| *o == op && b.starts_with(&id)) + .map(|(i, _)| i) + .collect::>() + }; + (pick(sc::SCSkillStartedPacket), pick(sc::SCSkillFiredPacket)) +} + +#[tokio::test] +async fn play_and_pause_announce_started_right_before_fired() { + for (skill, effect_op) in [ + (PLAY, sc::SCSendUserMusicPacket), + (PAUSE, sc::SCPauseUserMusicPacket), + ] { + let mut f = fixture_with(music_data()); + start_skill( + &f.server, + &mut f.client.conn, + cast_packet(skill, SkillCastTarget::Unit(PLAYER_OBJ)), + ); + let got = frames(&mut f.client); + let (started, fired) = started_and_fired(&got, skill); + assert_eq!((started.len(), fired.len()), (1, 1), "{skill}: {got:x?}"); + assert_eq!( + started[0] + 1, + fired[0], + "{skill}: Started directly before Fired" + ); + // Timeline: the same non-zero id as the fire; zero cast-time fields, no result extras. + let fire_body = &got[fired[0]].1; + let tl = u16::from_le_bytes([fire_body[4], fire_body[5]]); + assert_ne!(tl, 0); + let mut expected = PacketStream::new(); + expected + .write_u32(skill) + .write_u16(tl) + .write_u8(0) + .write_bc(PLAYER_OBJ) // own unit caster + .write_u8(0) + .write_bc(PLAYER_OBJ) // unit target + .write_u8(0) // no skill object + .write_u16(0) // real cast time + .write_u16(0) // base cast time + .write_u8(0) // cast synergy + .write_u8(0); // no extra data + assert_eq!(got[started[0]].1, expected.as_bytes(), "{skill}"); + // The authored 200 ms effect delay is untouched: the effect arrives after the fire. + assert!(!got.iter().any(|(op, _)| *op == effect_op)); + tokio::time::sleep(std::time::Duration::from_millis(450)).await; + let later = frames(&mut f.client); + assert!( + later.iter().any(|(op, _)| *op == effect_op), + "{skill}: {later:x?}" + ); + assert!(!later.iter().any(|(op, _)| *op == sc::SCSkillStartedPacket)); + } +} + +#[tokio::test] +async fn other_instant_skills_get_no_started() { + let mut f = fixture_with(music_data()); + for skill in [HEAL_SKILL, CLIENT_ONLY] { + start_skill( + &f.server, + &mut f.client.conn, + cast_packet(skill, SkillCastTarget::Unit(PLAYER_OBJ)), + ); + let got = frames(&mut f.client); + let (started, fired) = started_and_fired(&got, skill); + assert!(started.is_empty(), "{skill}: {got:x?}"); + assert_eq!(fired.len(), 1, "{skill}"); + age_gcd_for_next_cast(&f); + } +} + +fn age_gcd_for_next_cast(f: &Fixture) { + f.player.data().unit.global_cooldown_ms = 0; + f.player.data().unit.skill_last_used_ms = 0; +} + +#[tokio::test] +async fn rejected_play_sends_only_the_failure_started() { + let mut f = fixture_with(music_data()); + start_skill( + &f.server, + &mut f.client.conn, + cast_packet(COSTLY_PLAY, SkillCastTarget::Unit(PLAYER_OBJ)), + ); + let got = frames(&mut f.client); + let (started, fired) = started_and_fired(&got, COSTLY_PLAY); + assert!(fired.is_empty(), "{got:x?}"); + assert_eq!(started.len(), 1, "{got:x?}"); + let body = &got[started[0]].1; + // The failure carries extra data (flag byte after the cast fields) and a zero timeline. + assert_eq!(u16::from_le_bytes([body[4], body[5]]), 0); + // Extra-data flag 1 (byte result) and the LACK_MANA result. + assert_eq!( + &body[body.len() - 2..], + &[1, skill_result::LACK_MANA], + "{body:x?}" + ); +} + +#[tokio::test] +async fn only_player_casters_with_a_music_special_effect_qualify() { + let f = fixture_with(music_data()); + let skills = &f.server.game_data.systems.skills; + let me = WorldObject::from(&f.player); + let npc = WorldObject::from(&f.npc); + assert!(is_player_music_skill( + &f.server, + skills.skill(PLAY).unwrap(), + &me + )); + assert!(is_player_music_skill( + &f.server, + skills.skill(PAUSE).unwrap(), + &me + )); + assert!(!is_player_music_skill( + &f.server, + skills.skill(CLIENT_ONLY).unwrap(), + &me + )); + assert!(!is_player_music_skill( + &f.server, + skills.skill(HEAL_SKILL).unwrap(), + &me + )); + assert!(!is_player_music_skill( + &f.server, + skills.skill(PLAY).unwrap(), + &npc + )); +} diff --git a/rust/crates/aaemu-game/src/systems/skills/skill.rs b/rust/crates/aaemu-game/src/systems/skills/skill.rs index f2f09d5b52..d6c52eb242 100644 --- a/rust/crates/aaemu-game/src/systems/skills/skill.rs +++ b/rust/crates/aaemu-game/src/systems/skills/skill.rs @@ -559,6 +559,7 @@ pub fn use_skill( let mut state = skill.state(); state.generation = state.generation.wrapping_add(1); state.cancelled = false; + state.music_started_pending = false; state.hit_types.clear(); } caster.with_unit(|u| u.unit_mut().skill_state.condition_chance = true); @@ -696,6 +697,9 @@ pub fn use_skill( cast(server, skill, &ctx2); } } else { + if is_player_music_skill(server, &template, caster) { + skill.state().music_started_pending = true; + } cast(server, skill, &ctx); } (skill_result::SUCCESS, 0) @@ -1122,6 +1126,35 @@ pub fn end_channeling( } } +/// Special effect types of `PlayUserMusic` / `PauseUserMusic`. +const SPECIAL_PLAY_USER_MUSIC: i32 = 93; +const SPECIAL_PAUSE_USER_MUSIC: i32 = 94; + +/// Whether a player's skill carries a play / pause score special effect in the static catalog +/// (`skill_effects` -> `SpecialEffect` -> `special_effects.special_effect_type_id` 93 / 94). +pub(super) fn is_player_music_skill( + server: &GameServer, + template: &SkillTemplate, + caster: &WorldObject, +) -> bool { + if caster.as_player().is_none() { + return false; + } + let data = &server.game_data.systems.skills; + template.effects.iter().any(|e| { + e.template.is_some_and(|(kind, id)| { + matches!( + data.effect(kind, id), + Some(EffectTemplate::Special(s)) + if matches!( + s.special_effect_type_id, + SPECIAL_PLAY_USER_MUSIC | SPECIAL_PAUSE_USER_MUSIC + ) + ) + }) + }) +} + /// `Skill.ScheduleEffects`. pub fn schedule_effects(server: &GameServer, skill: &SkillRef, ctx: &CastCtx) { let caster = &ctx.caster; @@ -1168,6 +1201,23 @@ pub fn schedule_effects(server: &GameServer, skill: &SkillRef, ctx: &CastCtx) { if weapon_anim > 0 { fired.fire_anim_id = weapon_anim; } + // The 1.2 client reacts to its own `SCSkillStarted` of a play / pause score skill (special + // effects 93 / 94) by sending the MIDI cache / the end of the music. An instant cast has no + // cast-time `SCSkillStarted`, so the validated cast announces itself right before its fire. + if std::mem::take(&mut skill.state().music_started_pending) { + broadcast( + server, + caster, + &SCSkillStartedPacket::new( + skill.id, + fired.tl, + ctx.caster_caster, + ctx.target_caster, + ctx.skill_object.clone(), + ), + true, + ); + } broadcast(server, caster, &fired, true); if total_delay > 0 { let skill2 = skill.clone(); diff --git a/rust/crates/aaemu-game/src/systems/skills/state.rs b/rust/crates/aaemu-game/src/systems/skills/state.rs index c333afcab6..2f3042b0cf 100644 --- a/rust/crates/aaemu-game/src/systems/skills/state.rs +++ b/rust/crates/aaemu-game/src/systems/skills/state.rs @@ -56,6 +56,9 @@ pub struct SkillRunState { pub auto_attack_index: i32, /// `ActivePlotState`. pub active_plot: Option>, + /// An instant player music skill (special effect 93 / 94) still owes its `SCSkillStarted`, + /// sent right before its `SCSkillFired` (see `skill::schedule_effects`). + pub music_started_pending: bool, } /// `Skill`: a template + level and the per-use state, shared by the cast and its tasks. diff --git a/rust/crates/aaemu-game/src/systems/skills/tests.rs b/rust/crates/aaemu-game/src/systems/skills/tests.rs index 1b83d8f3a6..8d62563f38 100644 --- a/rust/crates/aaemu-game/src/systems/skills/tests.rs +++ b/rust/crates/aaemu-game/src/systems/skills/tests.rs @@ -1206,3 +1206,6 @@ async fn pvp_kill_advances_a_conflict_zone_that_returned_to_tension() { // No honor outside Conflict / War (the C#/1.2 rule is unchanged). assert_eq!(killer.data().honor_gained_in_combat, 0); } + +#[path = "music_started_tests.rs"] +mod music_started_tests; diff --git a/rust/crates/aaemu-testclient/src/scenario.rs b/rust/crates/aaemu-testclient/src/scenario.rs index 71c7ae029e..c87a1ba43c 100644 --- a/rust/crates/aaemu-testclient/src/scenario.rs +++ b/rust/crates/aaemu-testclient/src/scenario.rs @@ -19,6 +19,7 @@ use crate::stream::StreamClient; mod cometsboon; mod doodad; mod fixes; +mod music; mod plant; mod portal; mod questitem; diff --git a/rust/crates/aaemu-testclient/src/scenario/music.rs b/rust/crates/aaemu-testclient/src/scenario/music.rs new file mode 100644 index 0000000000..60dde36df6 --- /dev/null +++ b/rust/crates/aaemu-testclient/src/scenario/music.rs @@ -0,0 +1,885 @@ +//! Music lifecycle commands of the `script` scenario / `.vtest` suites (`m*`), driving the same +//! wire sequence as the 1.2 client: Compose item cast -> received own `SCSkillFired` -> +//! `CSSaveUserMusicNotes`; play skill -> own `SCSkillStarted` -> `CSSendUserMusic`; pause / +//! close skill -> own `SCSkillStarted` -> `CSEndMusic`; cold / hit `CSRequestMusicNotes`. +//! Everything is sent only in reaction to packets actually received. +//! +//! ```text +//! mitem