mirror of
https://github.com/brues-code/ClassicAPI.git
synced 2026-11-16 08:00:42 +00:00
Reports the handle of a finished sound, and only for sounds played with `runFinishCallback` — the documented contract, and what makes it affordable: without the opt-in every footstep and UI click would dispatch a Lua event. Detected on the world tick, NOT from FMOD's end callback. That callback (FUN_007A53C0) runs on the STREAMER thread — it opens with EnterCriticalSection and only moves the stream onto a deferred list — so firing an event there would call into the Lua VM off the main thread. The engine reclaims those streams in FUN_007A4B60, from the per-frame sound update that ends in FSOUND_Update, so noticing completion on the main thread is what the engine itself does. A tracked entry keeps the stream's path hash (+0x80, stamped at creation by FUN_007A51D0) beside the handle. Stream objects come from a pool and their addresses are reused, so "still in the live list" is not enough on its own — a later sound can land on the same address and the event would be deferred to the wrong one. Comparing the hash narrows that to the same file replaying at the same address, for one extra dword read of a node already found alive. C_Sound.PlaySound takes the remaining modern arguments: channel, forceNoDuplicates and runFinishCallback. forceNoDuplicates is accepted and ignored — the engine's by-path dedup is bit 0 of a flag word the row itself supplies, and the by-id player ORs in only bits 1, 2 and 4 from its arguments, so asking for it would mean bypassing that player and re-deriving its weighted file pick. The global PlaySound deliberately does NOT take those: it gains the SoundKitID form and nothing else, staying as close to the global it replaces as the extension allows.