Music (BGM/*.stx) and track selection
The music files were added to our dump on 11-09 from a second install of the same build (file list and sizes equal, checksums of three files equal). Container layout after the shared notes (credit: “Sources” of “Character table”), checked here with a struct reader on all 127 files; track selection is our own reading of the executable and the scripts.
Container: 0x800-byte blocks, each with a 0x20-byte header:
char magic[4]“STHD”,u16 data_offset,u16 channels(2),u32 date,u32 0,u16 block_count,u16 block_index,u16 data_skip,u16 bytes_per_channel(0x3F0 in a full block),u16 next_block,u16 loop_start,u16 loop_end(0xFFFF = no loop),u16 0. File size = block_count × 0x800 in every file. Block 0 holds eight 0x40-byte channel records from 0x20 (u32 sample_rate,u8 volume,u8 bins[8], ..) and the channel names; data blocks hold one 0x3F0-byte region per channel. 35 files loop (rate 44099), 70.stxand the 22.w10(tutorial voice) do not (44100). The PC payload is 16-bit PCM per the notes; the sizes agree (504 samples per channel per block gives track 1 about 152 s), not yet decoded to audio here.Track table 0x1403e8bf0, 16-byte entries
{char *file, u8 flags, u8 group, ..}, index = track number, usually the file name’s number prefix (audio run correction: not always: track 45 names the file with prefix 61; read the name from the entry, never build it from the number). Tracks 32, 36, 39, 40, 42–44 and 46–59 have no file; 0 = stop, valid up to 60 (0x14019cdf0 checks ≤ 0x3C), several entries have no file. flags: 9 on looping stage and menu tracks, 1 on the one-shot jingles 37, 38, 41, 45 (bit 0: apply the music volume option 0x14052dfb4 × 4096 / 100; bit 3 is set on exactly the tracks whose file has a loop, audio run). group: 0–6 on tracks 1–21 (three tracks per stage family), 0xFF elsewhere; with the plain play command a group whose slot in the seven-entry table 0x1403e8bd0 is not −1 plays that slot instead (all −1 in the file: an Xbox custom-soundtrack leftover, INFERRED).Play function 0x14019cdf0(track, force): returns at once when the track is already playing (0x14052acec), else stops the current one and queues the file
.\bgm\<name>. Only two script natives call it: 0x1010 (force 0, 0x140260ee0) and 0x1012 (force 1, 0x140260f00); natives 0x1011 and 0x1013(0x1000) run before them in the battle scripts (stop and volume, not followed). Native group table: 0x1402ddd00, function id = group << 12 | index.Menus name their track as a constant: versus menu and mode select 34, the online screens 35, arsenal editor 29, title/main menu 31, options 33, the result screen 37 (win) or 38 (lose).
Battles: every battle script that starts music (126 of the 137
quest*.ssbper language) carries the same 29-entry table and the same routine, run fromgamestart: track = table[stage number] (native 0x41a9 returns the stage number 0x1404c01d8), and when that is 16..19 a random 0..2 is added (native 0x4020(3) = rand × 3 >> 15). Audio run corrections: the test is “track = 16 or track = 19” (two compares joined by an or), not a range; the routine is stop (0x1011), volume (0x1013 with 0x1000), play (0x1010). The table has no stored length: the converter reads it from the push-code operand to the first word outside 0..60 (29 words, stages 0..28: index 0 and the x9 / x0 slots are 0 = no music); all 276 battle scripts of both language folders give the same table.Stage (ones digit) 1 2 3 4 5 6 7 8 st0N 24 5 1 8 14 11 16–18 19–21 st1N 24 6 2 7 15 10 16–18 19–21 st2N 24 4 3 9 13 12 16–18 19–21 A second routine in the same scripts switches track (native 0x1012) by a story value (native 0x7021(7)) through a key/track pair list; story only, not followed. Which script number a versus match loads (0x1401b9f40, number at 0x1404615d0) was not traced; the table is the same in all of them.