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
9 changes: 9 additions & 0 deletions rust/LIVE-TESTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,15 @@ corpse (`/despawn npc <objId>`) 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
Expand Down
18 changes: 18 additions & 0 deletions rust/crates/aaemu-game/PORTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
193 changes: 193 additions & 0 deletions rust/crates/aaemu-game/src/systems/skills/music_started_tests.rs
Original file line number Diff line number Diff line change
@@ -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<u8>)], skill: u32) -> (Vec<usize>, Vec<usize>) {
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::<Vec<_>>()
};
(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
));
}
50 changes: 50 additions & 0 deletions rust/crates/aaemu-game/src/systems/skills/skill.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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();
Expand Down
3 changes: 3 additions & 0 deletions rust/crates/aaemu-game/src/systems/skills/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,9 @@ pub struct SkillRunState {
pub auto_attack_index: i32,
/// `ActivePlotState`.
pub active_plot: Option<Arc<PlotState>>,
/// 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.
Expand Down
3 changes: 3 additions & 0 deletions rust/crates/aaemu-game/src/systems/skills/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
1 change: 1 addition & 0 deletions rust/crates/aaemu-testclient/src/scenario.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ use crate::stream::StreamClient;
mod cometsboon;
mod doodad;
mod fixes;
mod music;
mod plant;
mod portal;
mod questitem;
Expand Down
Loading
Loading