acdream/src/AcDream.App/Audio/UiSoundTableResolver.cs
Erik 6eaa490bb3 feat(audio): Campaign A slice A4 — the interface sound bus
Retail's UI sound bank was absent, so three families of cue were silent:
the portal enter/exit stingers, the AdminEnvirons dungeon atmosphere
(chanting, drums, whispers, thunder — what players remember as dungeon
'music'), and every other interface slot.

The bank's DID is not a literal anywhere in retail: GetUISoundTable
@0x00563FB0 asks GetByEnum for enum slot 7, and DBCache::GetDIDFromEnum
@0x00413940 resolves it through two EnumIDMap hops off the portal dat
header's master map. UiSoundTableResolver walks that chain the way
RetailCursorResolver already walks it for cursors. Against the shipped
dats it resolves to 0x2000004B, and that table holds exactly the 32 UI_*
slots (UI_EnterPortal 0x6A .. UI_Thunder6 0x8A) — content that confirms
the walk independently of the decode. UiSoundTableResolutionTests pins
the walk, the DID, and the content, and skips when dats are absent.

Two corrections to the research along the way. The lane-5 note recorded
GetByEnum's arguments transposed: the 0x22 it called a fileType is the
CACHE type (CLOCache(cache, CSoundTable::Allocator, 0x22)) and the real
second-hop key is 0x10000003; walking it the other way finds nothing. And
its claim that the interface volume pref applies is wrong — GetAttenuation
with ambient=0 multiplies by the EFFECT knob, so retail's
interface_sound_volume stays the dead knob lane 1 byte-decoded it to be.

EnvironSoundCueMap is an explicit 21-case table read straight out of
Handle_Admin__Environs @0x0055DE20, not arithmetic: codes 0x65..0x72 sit
0x11 below their SoundType, but 0x73/0x74 have no case, so 0x75 lands on
UI_Squeal (0x84) where an offset gives 0x86, and the switch ends at 0x7B
with no 0x7C case. Verified case-by-case against the decomp rather than
from the lane note, whose tail table was ambiguous.

Cues are attached where retail plays them: the teleport-animation
boundary for the portal pair, and the AdminEnvirons handler for the
stingers. PlaySoundFromCenter's pan-0 / distance-0 shape is what
PlayUiWave already implements after A2.

Retires TS-54. Narrows AP-115 to its notice-presentation residual.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-08-08 22:22:09 +02:00

69 lines
2.6 KiB
C#

using AcDream.Content;
using DatReaderWriter;
using DatReaderWriter.DBObjs;
namespace AcDream.App.Audio;
/// <summary>
/// Resolves the DID of retail's interface sound bank by walking the dats, the
/// way retail does, instead of carrying a literal.
///
/// <para>
/// <c>ClientUISystem::GetUISoundTable</c> @ <c>0x00563FB0</c> calls
/// <c>DBObj::GetByEnum</c> @ <c>0x00415490</c>, and
/// <c>DBCache::GetDIDFromEnum</c> @ <c>0x00413940</c> resolves the answer with
/// two <c>EnumIDMap</c> hops off <c>m_MasterMapID</c>: keyed first by the enum
/// INDEX (7 for the UI bank), then by the type key. Same chain and same helper
/// shape as <see cref="AcDream.App.Rendering.RetailCursorResolver"/> and the
/// portal tunnel's setup/animation lookup — the master id comes from the portal
/// dat header rather than being searched for.
/// </para>
///
/// <para>
/// Against the shipped dats this resolves to <c>0x2000004B</c>, a table holding
/// exactly the 32 <c>UI_*</c> slots.
/// <c>UiSoundTableResolutionTests</c> pins the walk, the DID, and the content.
/// </para>
/// </summary>
public static class UiSoundTableResolver
{
/// <summary>The enum index the UI sound bank lives at.</summary>
public const uint UiSoundTableEnumSlot = 7u;
/// <summary>
/// The type key the second hop uses. <c>GetByEnum(type, idx, cache)</c> hands
/// <c>(type, idx)</c> to the enum chain and the resolved DID to
/// <c>DBCache::Get(did, cache)</c>; a SoundTable's CACHE type is <c>0x22</c>
/// (<c>CLOCache(cache, CSoundTable::Allocator, 0x22)</c>), which is not this
/// key. The lane-5 research note transposed the two arguments.
/// </summary>
public const uint UiSoundTableTypeKey = 0x10000003u;
/// <summary>
/// Resolve the bank's DID, or 0 when the dats carry no such chain (in which
/// case interface sounds stay silent rather than playing a guessed table).
/// </summary>
public static uint Resolve(IDatReaderWriter dats)
{
if (dats is null)
return 0u;
uint masterDid = (uint)dats.Portal.Db.Header.MasterMapId;
if (masterDid == 0)
return 0u;
if (!dats.Portal.TryGet<EnumIDMap>(masterDid, out var master) || master is null)
return 0u;
if (!master.ClientEnumToID.TryGetValue(UiSoundTableEnumSlot, out uint perSlotDid)
|| perSlotDid == 0)
{
return 0u;
}
if (!dats.Portal.TryGet<EnumIDMap>(perSlotDid, out var perSlot) || perSlot is null)
return 0u;
return perSlot.ClientEnumToID.TryGetValue(UiSoundTableTypeKey, out uint did) ? did : 0u;
}
}