@carbonenginejs/runtime-resource 0.8.0 → 0.9.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (297) hide show
  1. package/LICENSE +21 -21
  2. package/NOTICE +31 -29
  3. package/README.md +67 -548
  4. package/dist/CjsMotherLode.js +1271 -1271
  5. package/dist/CjsResMan.js +3005 -3005
  6. package/dist/CjsResManQueue.js +214 -214
  7. package/dist/CjsResource.js +566 -566
  8. package/dist/CjsResourceSource.js +68 -59
  9. package/dist/CjsResourceSource.js.map +1 -1
  10. package/dist/_virtual/_rollupPluginBabelHelpers.js +153 -153
  11. package/dist/format/CjsBlueReader.js +269 -269
  12. package/dist/format/CjsFormat.js +197 -192
  13. package/dist/format/CjsFormat.js.map +1 -1
  14. package/dist/format/CjsReader.js +18 -18
  15. package/dist/format/CjsResourceProbe.js +277 -277
  16. package/dist/format/payloadContract.js +173 -173
  17. package/dist/formats/black/CjsBlackFormat.js +278 -278
  18. package/dist/formats/black/core/CjsBlackBinaryReader.js +157 -153
  19. package/dist/formats/black/core/CjsBlackBinaryReader.js.map +1 -1
  20. package/dist/formats/black/core/CjsBlackPropertyReaders.js +387 -382
  21. package/dist/formats/black/core/CjsBlackPropertyReaders.js.map +1 -1
  22. package/dist/formats/black/core/CjsBlackReader.js +639 -639
  23. package/dist/formats/black/core/CjsBlackSchemaRegistry.js +437 -433
  24. package/dist/formats/black/core/CjsBlackSchemaRegistry.js.map +1 -1
  25. package/dist/formats/black/core/black-schema-v1-2026-07-23.json.js +4 -0
  26. package/dist/formats/black/core/black-schema-v1-2026-07-23.json.js.map +1 -0
  27. package/dist/formats/black/core/blackConstants.js +7 -7
  28. package/dist/formats/black/core/blackDefinitions.js +10 -10
  29. package/dist/formats/black/core/blackDefinitions.js.map +1 -1
  30. package/dist/formats/black/core/blackEnums.js +6 -6
  31. package/dist/formats/black/core/blackSchema.js +3 -3
  32. package/dist/formats/black/core/blackVersion.js +22 -22
  33. package/dist/formats/black/core/helpers.js +182 -182
  34. package/dist/formats/black/core/schema.js +4 -4
  35. package/dist/formats/black/index.js +2 -2
  36. package/dist/formats/bnk/CjsBnkFormat.js +125 -125
  37. package/dist/formats/bnk/core/graph.js +140 -140
  38. package/dist/formats/bnk/core/helpers.js +409 -409
  39. package/dist/formats/bnk/core/musicNodes.js +493 -489
  40. package/dist/formats/bnk/core/musicNodes.js.map +1 -1
  41. package/dist/formats/bnk/core/soundbanksInfo.js +246 -246
  42. package/dist/formats/bnk/index.js +2 -2
  43. package/dist/formats/cmf/CjsCmfFormat.js +497 -497
  44. package/dist/formats/cmf/core/binary.js +123 -118
  45. package/dist/formats/cmf/core/binary.js.map +1 -1
  46. package/dist/formats/cmf/core/buffers.js +233 -233
  47. package/dist/formats/cmf/core/constants.js +47 -47
  48. package/dist/formats/cmf/core/gr2Anim.js +453 -453
  49. package/dist/formats/cmf/core/helpers.js +287 -287
  50. package/dist/formats/cmf/core/pack.js +276 -276
  51. package/dist/formats/cmf/core/schema.js +364 -364
  52. package/dist/formats/cmf/core/shared.js +268 -268
  53. package/dist/formats/cmf/core/writer.js +517 -517
  54. package/dist/formats/cmf/index.js +2 -2
  55. package/dist/formats/dds/CjsDdsFormat.js +200 -193
  56. package/dist/formats/dds/CjsDdsFormat.js.map +1 -1
  57. package/dist/formats/dds/core/bc6h.js +288 -288
  58. package/dist/formats/dds/core/bc7.js +256 -251
  59. package/dist/formats/dds/core/bc7.js.map +1 -1
  60. package/dist/formats/dds/core/helpers.js +815 -815
  61. package/dist/formats/dds/index.js +2 -2
  62. package/dist/formats/fbx/CjsFbxFormat.js +266 -266
  63. package/dist/formats/fbx/core/helpers.js +3911 -3901
  64. package/dist/formats/fbx/core/helpers.js.map +1 -1
  65. package/dist/formats/fbx/index.js +2 -2
  66. package/dist/formats/flac/CjsFlacFormat.js +93 -87
  67. package/dist/formats/flac/CjsFlacFormat.js.map +1 -1
  68. package/dist/formats/flac/core/helpers.js +295 -295
  69. package/dist/formats/flac/index.js +2 -2
  70. package/dist/formats/gif/CjsGifFormat.js +92 -87
  71. package/dist/formats/gif/CjsGifFormat.js.map +1 -1
  72. package/dist/formats/gif/core/helpers.js +360 -360
  73. package/dist/formats/gif/index.js +2 -2
  74. package/dist/formats/gltf/CjsGltfFormat.js +290 -290
  75. package/dist/formats/gltf/core/helpers.js +292 -292
  76. package/dist/formats/gltf/core/json.js +79 -79
  77. package/dist/formats/gltf/core/parser.js +666 -666
  78. package/dist/formats/gltf/core/targets.js +163 -163
  79. package/dist/formats/gltf/index.js +2 -2
  80. package/dist/formats/gr2/CjsGr2Format.js +46 -0
  81. package/dist/formats/gr2/CjsGr2Format.js.map +1 -0
  82. package/dist/formats/gr2/core/CjsFormatGr2.js +273 -0
  83. package/dist/formats/gr2/core/CjsFormatGr2.js.map +1 -0
  84. package/dist/formats/gr2/core/bitknit2.js +280 -0
  85. package/dist/formats/gr2/core/bitknit2.js.map +1 -0
  86. package/dist/formats/gr2/core/curves.js +1047 -0
  87. package/dist/formats/gr2/core/curves.js.map +1 -0
  88. package/dist/formats/gr2/core/gsf.js +72 -0
  89. package/dist/formats/gr2/core/gsf.js.map +1 -0
  90. package/dist/formats/gr2/core/helpers.js +332 -0
  91. package/dist/formats/gr2/core/helpers.js.map +1 -0
  92. package/dist/formats/gr2/core/json.js +622 -0
  93. package/dist/formats/gr2/core/json.js.map +1 -0
  94. package/dist/formats/gr2/core/oodle1.js +388 -0
  95. package/dist/formats/gr2/core/oodle1.js.map +1 -0
  96. package/dist/formats/gr2/core/reader.js +617 -0
  97. package/dist/formats/gr2/core/reader.js.map +1 -0
  98. package/dist/formats/gr2/core/tangents.js +48 -0
  99. package/dist/formats/gr2/core/tangents.js.map +1 -0
  100. package/dist/formats/gr2/core/targets.js +351 -0
  101. package/dist/formats/gr2/core/targets.js.map +1 -0
  102. package/dist/formats/gr2/index.js +3 -0
  103. package/dist/formats/gr2/index.js.map +1 -0
  104. package/dist/formats/index.js +30 -23
  105. package/dist/formats/index.js.map +1 -1
  106. package/dist/formats/jpeg/CjsJpegFormat.js +212 -206
  107. package/dist/formats/jpeg/CjsJpegFormat.js.map +1 -1
  108. package/dist/formats/jpeg/core/helpers.js +350 -350
  109. package/dist/formats/jpeg/core/jpeg.js +387 -377
  110. package/dist/formats/jpeg/core/jpeg.js.map +1 -1
  111. package/dist/formats/jpeg/index.js +2 -2
  112. package/dist/formats/mp3/CjsMp3Format.js +197 -192
  113. package/dist/formats/mp3/CjsMp3Format.js.map +1 -1
  114. package/dist/formats/mp3/core/helpers.js +338 -338
  115. package/dist/formats/mp3/index.js +2 -2
  116. package/dist/formats/mp4/CjsMp4Format.js +197 -191
  117. package/dist/formats/mp4/CjsMp4Format.js.map +1 -1
  118. package/dist/formats/mp4/core/helpers.js +449 -449
  119. package/dist/formats/mp4/index.js +2 -2
  120. package/dist/formats/obj/CjsObjFormat.js +253 -253
  121. package/dist/formats/obj/core/helpers.js +573 -573
  122. package/dist/formats/obj/core/json.js +64 -64
  123. package/dist/formats/obj/core/parser.js +321 -321
  124. package/dist/formats/obj/index.js +2 -2
  125. package/dist/formats/ogg/CjsOggFormat.js +94 -88
  126. package/dist/formats/ogg/CjsOggFormat.js.map +1 -1
  127. package/dist/formats/ogg/core/helpers.js +387 -387
  128. package/dist/formats/ogg/core/imdct.js +178 -178
  129. package/dist/formats/ogg/core/vorbis.js +1004 -999
  130. package/dist/formats/ogg/core/vorbis.js.map +1 -1
  131. package/dist/formats/ogg/index.js +2 -2
  132. package/dist/formats/png/CjsPngFormat.js +201 -195
  133. package/dist/formats/png/CjsPngFormat.js.map +1 -1
  134. package/dist/formats/png/core/helpers.js +583 -583
  135. package/dist/formats/png/index.js +2 -2
  136. package/dist/formats/red/CjsRedFormat.js +261 -261
  137. package/dist/formats/red/core/CjsRedReader.js +194 -194
  138. package/dist/formats/red/core/blackDefinitions.js +3 -3
  139. package/dist/formats/red/core/helpers.js +139 -139
  140. package/dist/formats/red/core/redGraph.js +68 -68
  141. package/dist/formats/red/core/schema.js +4 -4
  142. package/dist/formats/red/index.js +2 -2
  143. package/dist/formats/stl/CjsStlFormat.js +365 -365
  144. package/dist/formats/stl/core/helpers.js +261 -261
  145. package/dist/formats/stl/core/json.js +51 -51
  146. package/dist/formats/stl/core/stl.js +634 -629
  147. package/dist/formats/stl/core/stl.js.map +1 -1
  148. package/dist/formats/stl/core/targets.js +163 -163
  149. package/dist/formats/stl/index.js +2 -2
  150. package/dist/formats/tga/CjsTgaFormat.js +197 -192
  151. package/dist/formats/tga/CjsTgaFormat.js.map +1 -1
  152. package/dist/formats/tga/core/helpers.js +446 -446
  153. package/dist/formats/tga/index.js +2 -2
  154. package/dist/formats/wav/CjsWavFormat.js +198 -192
  155. package/dist/formats/wav/CjsWavFormat.js.map +1 -1
  156. package/dist/formats/wav/core/helpers.js +328 -328
  157. package/dist/formats/wav/index.js +2 -2
  158. package/dist/formats/webm/CjsWebmFormat.js +197 -191
  159. package/dist/formats/webm/CjsWebmFormat.js.map +1 -1
  160. package/dist/formats/webm/core/helpers.js +537 -537
  161. package/dist/formats/webm/index.js +2 -2
  162. package/dist/formats/webp/CjsWebpFormat.js +91 -86
  163. package/dist/formats/webp/CjsWebpFormat.js.map +1 -1
  164. package/dist/formats/webp/core/helpers.js +214 -214
  165. package/dist/formats/webp/index.js +2 -2
  166. package/dist/formats/wem/CjsWemFormat.js +242 -241
  167. package/dist/formats/wem/CjsWemFormat.js.map +1 -1
  168. package/dist/formats/wem/core/bitStream.js +259 -259
  169. package/dist/formats/wem/core/codebookLibrary.js +164 -164
  170. package/dist/formats/wem/core/helpers.js +417 -417
  171. package/dist/formats/wem/core/packedCodebooksAotuv603.js +30 -30
  172. package/dist/formats/wem/core/ptadpcm.js +77 -77
  173. package/dist/formats/wem/core/resolve.js +121 -121
  174. package/dist/formats/wem/core/wemToOgg.js +485 -485
  175. package/dist/formats/wem/index.js +2 -2
  176. package/dist/formats/yaml/CjsYamlFormat.js +89 -83
  177. package/dist/formats/yaml/CjsYamlFormat.js.map +1 -1
  178. package/dist/formats/yaml/core/CjsYamlReader.js +311 -305
  179. package/dist/formats/yaml/core/CjsYamlReader.js.map +1 -1
  180. package/dist/formats/yaml/core/helpers.js +160 -160
  181. package/dist/formats/yaml/index.js +2 -2
  182. package/dist/index.js +49 -48
  183. package/dist/index.js.map +1 -1
  184. package/dist/resourcePath.js +18 -18
  185. package/dist/resourceStates.js +9 -9
  186. package/dist/resources/AudioGeometryResData.js +47 -47
  187. package/dist/resources/GStateBindingCallbackData.js +31 -31
  188. package/dist/resources/MeshDecalData.js +37 -37
  189. package/dist/resources/MeshDecalLodData.js +34 -34
  190. package/dist/resources/Tr2EffectRes.js +71 -71
  191. package/dist/resources/Tr2GrannyIntersectionResult.js +60 -60
  192. package/dist/resources/Tr2GrannyStateRes.js +44 -44
  193. package/dist/resources/Tr2ImageRes.js +114 -114
  194. package/dist/resources/Tr2LightProfileRes.js +40 -40
  195. package/dist/resources/Tr2MaterialArea.js +34 -34
  196. package/dist/resources/Tr2MaterialMesh.js +31 -31
  197. package/dist/resources/Tr2MaterialRes.js +34 -34
  198. package/dist/resources/Tr2ShaderPermutation.js +43 -43
  199. package/dist/resources/Tr2TextureLodManager.js +80 -80
  200. package/dist/resources/Tr2TextureLodUpdateRequest.js +37 -37
  201. package/dist/resources/Tr2TexturePackChannel.js +37 -37
  202. package/dist/resources/Tr2TexturePipeline.js +52 -52
  203. package/dist/resources/Tr2TexturePipelineParams.js +34 -34
  204. package/dist/resources/Tr2TexturePipelineStepCompress.js +40 -40
  205. package/dist/resources/Tr2TexturePipelineStepGenerateMips.js +22 -0
  206. package/dist/resources/Tr2TexturePipelineStepGenerateMips.js.map +1 -0
  207. package/dist/resources/Tr2TexturePipelineStepLimitSize.js +34 -34
  208. package/dist/resources/Tr2TexturePipelineStepLoad.js +31 -31
  209. package/dist/resources/Tr2TexturePipelineStepPack.js +43 -43
  210. package/dist/resources/TriGeometryRes.js +239 -239
  211. package/dist/resources/TriGeometryResAreaData.js +59 -59
  212. package/dist/resources/TriGeometryResJointData.js +38 -38
  213. package/dist/resources/TriGeometryResLodData.js +88 -88
  214. package/dist/resources/TriGeometryResMeshData.js +63 -63
  215. package/dist/resources/TriGeometryResSkeletonData.js +34 -34
  216. package/dist/resources/TriGrannyRes.js +43 -43
  217. package/dist/resources/TriJointBinding.js +38 -38
  218. package/dist/resources/TriMorphTargetGeometryConstants.js +46 -46
  219. package/dist/resources/TriRtGeometryConstants.js +88 -88
  220. package/dist/resources/TriTextureRes.js +304 -304
  221. package/dist/resources/enums.js +18 -18
  222. package/dist/resources/resourceBoundary.js +47 -47
  223. package/dist/resources/texturePipelineBehavior.js +308 -308
  224. package/dist/texture/CjsTextureArrayRes.js +406 -406
  225. package/dist/texture/CjsTextureParameterProxy.js +133 -133
  226. package/docs/README.md +73 -0
  227. package/docs/architecture.md +86 -0
  228. package/docs/concepts/resource-lifecycle.md +217 -0
  229. package/docs/formats/README.md +105 -0
  230. package/docs/formats/gr2.md +161 -0
  231. package/{FORMAT-PROVENANCE.md → docs/formats/provenance.md} +173 -155
  232. package/docs/formats/stl.md +37 -0
  233. package/docs/formats/wwise.md +44 -0
  234. package/docs/reference/classes/README.md +33 -0
  235. package/docs/reference/classes/core.md +106 -0
  236. package/docs/reference/classes/dropped.md +46 -0
  237. package/docs/reference/classes/formats.md +522 -0
  238. package/docs/reference/classes/resources.md +346 -0
  239. package/docs/reference/classes/texture.md +26 -0
  240. package/docs/reference/events.md +92 -0
  241. package/docs/reference/motherlode-cache.md +244 -0
  242. package/docs/reference/queues.md +102 -0
  243. package/docs/reference/reload.md +107 -0
  244. package/docs/reference/texture-arrays.md +113 -0
  245. package/docs/reference/texture-pipeline.md +53 -0
  246. package/docs/roadmap.md +104 -0
  247. package/format-notices/black/LICENSE +21 -21
  248. package/format-notices/black/NOTICE +47 -47
  249. package/format-notices/bnk/LICENSE +21 -21
  250. package/format-notices/bnk/NOTICE +20 -20
  251. package/format-notices/cmf/LICENSE +21 -21
  252. package/format-notices/cmf/NOTICE +36 -36
  253. package/format-notices/dds/LICENSE +21 -21
  254. package/format-notices/dds/NOTICE +14 -14
  255. package/format-notices/fbx/LICENSE +21 -21
  256. package/format-notices/fbx/NOTICE +14 -14
  257. package/format-notices/flac/LICENSE +21 -21
  258. package/format-notices/flac/NOTICE +14 -14
  259. package/format-notices/gif/LICENSE +21 -21
  260. package/format-notices/gif/NOTICE +14 -14
  261. package/format-notices/gltf/LICENSE +21 -21
  262. package/format-notices/gltf/NOTICE +27 -27
  263. package/format-notices/gr2/LICENSE +21 -0
  264. package/format-notices/gr2/NOTICE +60 -0
  265. package/format-notices/gr2/THIRD-PARTY-NOTICES.md +93 -0
  266. package/format-notices/jpeg/LICENSE +21 -21
  267. package/format-notices/jpeg/NOTICE +14 -14
  268. package/format-notices/mp3/LICENSE +21 -21
  269. package/format-notices/mp3/NOTICE +14 -14
  270. package/format-notices/mp4/LICENSE +21 -21
  271. package/format-notices/mp4/NOTICE +14 -14
  272. package/format-notices/obj/LICENSE +21 -21
  273. package/format-notices/obj/NOTICE +26 -26
  274. package/format-notices/ogg/LICENSE +21 -21
  275. package/format-notices/ogg/NOTICE +28 -28
  276. package/format-notices/png/LICENSE +21 -21
  277. package/format-notices/png/NOTICE +14 -14
  278. package/format-notices/red/LICENSE +21 -21
  279. package/format-notices/red/NOTICE +31 -31
  280. package/format-notices/stl/LICENSE +21 -21
  281. package/format-notices/stl/NOTICE +21 -21
  282. package/format-notices/tga/LICENSE +21 -21
  283. package/format-notices/tga/NOTICE +14 -14
  284. package/format-notices/wav/LICENSE +21 -21
  285. package/format-notices/wav/NOTICE +14 -14
  286. package/format-notices/webm/LICENSE +21 -21
  287. package/format-notices/webm/NOTICE +14 -14
  288. package/format-notices/webp/LICENSE +21 -21
  289. package/format-notices/webp/NOTICE +14 -14
  290. package/format-notices/wem/LICENSE +57 -57
  291. package/format-notices/wem/NOTICE +33 -33
  292. package/format-notices/yaml/LICENSE +21 -21
  293. package/format-notices/yaml/NOTICE +44 -44
  294. package/package.json +52 -51
  295. package/dist/formats/black/core/black-schema-v1-2026-07-11.json.js +0 -4
  296. package/dist/formats/black/core/black-schema-v1-2026-07-11.json.js.map +0 -1
  297. package/resource-lifecycle.md +0 -679
@@ -1,196 +1,200 @@
1
- // Wwise interactive-music node decoding: typed payloads for music-segment
2
- // (10), music-track (11), music-switch-container (12), and
3
- // music-playlist-container (13) HIRC entries. Exposed through
4
- // `CjsBnkFormat.wwise` next to the event graph walk - interpretation over
5
- // `inspect()` results, never part of the format read path.
6
- //
7
- // Verified against EVE soundbanks (bank generator version 150 / Wwise
8
- // 2022.1): 2,484 tracks, 1,326 segments, 214 playlists, and 54 switch
9
- // containers across music.bnk + music_essential.bnk all decode with the
10
- // exact-end validation below (2026-07-19 corpus run).
11
- //
12
- // Approach: consumers of these nodes (music schedulers) only need the fields
13
- // AFTER the variable-length NodeBaseParams block - children, meter, stingers,
14
- // and each type's tail - so segment/playlist/switch payloads are parsed from
15
- // a children+meter ANCHOR (a u32 child count and child ids that exist in the
16
- // bank, followed by a plausible AkMeterInfo) and the parse is accepted only
17
- // when it consumes the payload EXACTLY to its end. Track clips live at the
18
- // head (before NodeBaseParams) and the track's type block is tail-validated
19
- // the same way.
20
-
21
- class MusicCursor {
22
- constructor(bytes, offset = 0) {
23
- this.view = new DataView(bytes.buffer, bytes.byteOffset, bytes.byteLength);
24
- this.bytes = bytes;
25
- this.at = offset;
26
- }
27
- get remaining() {
28
- return this.bytes.byteLength - this.at;
29
- }
30
- u8() {
31
- return this.view.getUint8(this.at++);
32
- }
33
- u16() {
34
- const value = this.view.getUint16(this.at, true);
35
- this.at += 2;
36
- return value;
37
- }
38
- s16() {
39
- const value = this.view.getInt16(this.at, true);
40
- this.at += 2;
41
- return value;
42
- }
43
- u32() {
44
- const value = this.view.getUint32(this.at, true);
45
- this.at += 4;
46
- return value;
47
- }
48
- s32() {
49
- const value = this.view.getInt32(this.at, true);
50
- this.at += 4;
51
- return value;
52
- }
53
- f32() {
54
- const value = this.view.getFloat32(this.at, true);
55
- this.at += 4;
56
- return value;
57
- }
58
- f64() {
59
- const value = this.view.getFloat64(this.at, true);
60
- this.at += 8;
61
- return value;
62
- }
63
- stringZ() {
64
- let end = this.at;
65
- while (end < this.bytes.byteLength && this.bytes[end] !== 0) end++;
66
- let value = "";
67
- for (let i = this.at; i < end; i++) value += String.fromCharCode(this.bytes[i]);
68
- this.at = end + 1;
69
- return value;
70
- }
71
- }
72
- function plausibleMeter(view, at, byteLength) {
73
- if (at + 22 > byteLength) return false;
74
- const grid = view.getFloat64(at, true);
75
- const offset = view.getFloat64(at + 8, true);
76
- const tempo = view.getFloat32(at + 16, true);
77
- const beats = view.getUint8(at + 20);
78
- const beatValue = view.getUint8(at + 21);
79
- return Number.isFinite(grid) && grid >= 0 && grid < 600000 && Number.isFinite(offset) && offset >= 0 && offset < 600000 && Number.isFinite(tempo) && tempo > 0 && tempo < 1000 && beats >= 1 && beats <= 64 && [1, 2, 4, 8, 16, 32].includes(beatValue);
80
- }
81
- function findAnchors(bytes, knownIds) {
82
- const view = new DataView(bytes.buffer, bytes.byteOffset, bytes.byteLength);
83
- const anchors = [];
84
- for (let at = 1; at + 4 <= bytes.byteLength; at++) {
85
- const count = view.getUint32(at, true);
86
- if (count > 256 || at + 4 + count * 4 + 22 > bytes.byteLength) continue;
87
- let valid = true;
88
- for (let i = 0; i < count; i++) {
89
- if (!knownIds.has(view.getUint32(at + 4 + i * 4, true))) {
90
- valid = false;
91
- break;
92
- }
93
- }
94
- if (valid && plausibleMeter(view, at + 4 + count * 4, bytes.byteLength)) {
95
- anchors.push(at);
96
- }
97
- }
98
- return anchors;
99
- }
100
- function readMusicNodeTail(cursor) {
101
- const childCount = cursor.u32();
102
- const children = [];
103
- for (let i = 0; i < childCount; i++) children.push(cursor.u32());
104
- const meter = {
105
- gridPeriod: cursor.f64(),
106
- gridOffset: cursor.f64(),
107
- tempo: cursor.f32(),
108
- beatsPerBar: cursor.u8(),
109
- beatValue: cursor.u8()
110
- };
111
- const meterOverride = cursor.u8() !== 0;
112
- const stingerCount = cursor.u32();
113
- const stingers = [];
114
- for (let i = 0; i < stingerCount; i++) {
115
- stingers.push({
116
- triggerId: cursor.u32(),
117
- segmentId: cursor.u32(),
118
- syncPlayAt: cursor.u32(),
119
- cueFilterHash: cursor.u32(),
120
- dontRepeatTime: cursor.s32(),
121
- numSegmentLookAhead: cursor.u32()
122
- });
123
- }
124
- return {
125
- children,
126
- meter,
127
- meterOverride,
128
- stingers
129
- };
130
- }
131
-
132
- /** AkMusicTransNodeParams: transition rules shared by playlist + switch containers. */
133
- function readTransRules(cursor) {
134
- const ruleCount = cursor.u32();
135
- if (ruleCount > 4096) throw new RangeError("rule count");
136
- const rules = [];
137
- for (let i = 0; i < ruleCount; i++) {
138
- const srcCount = cursor.u32();
139
- if (srcCount > 1024) throw new RangeError("src count");
140
- const srcIds = [];
141
- for (let j = 0; j < srcCount; j++) srcIds.push(cursor.s32());
142
- const dstCount = cursor.u32();
143
- if (dstCount > 1024) throw new RangeError("dst count");
144
- const dstIds = [];
145
- for (let j = 0; j < dstCount; j++) dstIds.push(cursor.s32());
146
- const src = {
147
- transitionTime: cursor.s32(),
148
- fadeCurve: cursor.u32(),
149
- fadeOffset: cursor.s32(),
150
- syncType: cursor.u32(),
151
- cueFilterHash: cursor.u32(),
152
- playPostExit: cursor.u8() !== 0
153
- };
154
- const dst = {
155
- transitionTime: cursor.s32(),
156
- fadeCurve: cursor.u32(),
157
- fadeOffset: cursor.s32(),
158
- cueFilterHash: cursor.u32(),
159
- jumpToId: cursor.u32(),
160
- jumpToType: cursor.u16(),
161
- entryType: cursor.u16(),
162
- playPreEntry: cursor.u8() !== 0,
163
- matchSourceCueName: cursor.u8() !== 0
164
- };
165
- let transitionSegment = null;
166
- if (cursor.u8() !== 0) {
167
- transitionSegment = {
168
- segmentId: cursor.u32(),
169
- fadeIn: {
170
- transitionTime: cursor.s32(),
171
- fadeCurve: cursor.u32(),
172
- fadeOffset: cursor.s32()
173
- },
174
- fadeOut: {
175
- transitionTime: cursor.s32(),
176
- fadeCurve: cursor.u32(),
177
- fadeOffset: cursor.s32()
178
- },
179
- playPreEntry: cursor.u8() !== 0,
180
- playPostExit: cursor.u8() !== 0
181
- };
182
- }
183
- rules.push({
184
- srcIds,
185
- dstIds,
186
- src,
187
- dst,
188
- transitionSegment
189
- });
190
- }
191
- return rules;
192
- }
193
-
1
+ // Wwise interactive-music node decoding: typed payloads for music-segment
2
+ // (10), music-track (11), music-switch-container (12), and
3
+ // music-playlist-container (13) HIRC entries. Exposed through
4
+ // `CjsBnkFormat.wwise` next to the event graph walk - interpretation over
5
+ // `inspect()` results, never part of the format read path.
6
+ //
7
+ // Verified against EVE soundbanks (bank generator version 150 / Wwise
8
+ // 2022.1): 2,484 tracks, 1,326 segments, 214 playlists, and 54 switch
9
+ // containers across music.bnk + music_essential.bnk all decode with the
10
+ // exact-end validation below (2026-07-19 corpus run).
11
+ //
12
+ // Approach: consumers of these nodes (music schedulers) only need the fields
13
+ // AFTER the variable-length NodeBaseParams block - children, meter, stingers,
14
+ // and each type's tail - so segment/playlist/switch payloads are parsed from
15
+ // a children+meter ANCHOR (a u32 child count and child ids that exist in the
16
+ // bank, followed by a plausible AkMeterInfo) and the parse is accepted only
17
+ // when it consumes the payload EXACTLY to its end. Track clips live at the
18
+ // head (before NodeBaseParams) and the track's type block is tail-validated
19
+ // the same way.
20
+
21
+ /**
22
+ * Little-endian byte cursor over HIRC payload bytes used to decode Wwise
23
+ * interactive-music node payloads with exact-end validation.
24
+ */
25
+ class MusicCursor {
26
+ constructor(bytes, offset = 0) {
27
+ this.view = new DataView(bytes.buffer, bytes.byteOffset, bytes.byteLength);
28
+ this.bytes = bytes;
29
+ this.at = offset;
30
+ }
31
+ get remaining() {
32
+ return this.bytes.byteLength - this.at;
33
+ }
34
+ u8() {
35
+ return this.view.getUint8(this.at++);
36
+ }
37
+ u16() {
38
+ const value = this.view.getUint16(this.at, true);
39
+ this.at += 2;
40
+ return value;
41
+ }
42
+ s16() {
43
+ const value = this.view.getInt16(this.at, true);
44
+ this.at += 2;
45
+ return value;
46
+ }
47
+ u32() {
48
+ const value = this.view.getUint32(this.at, true);
49
+ this.at += 4;
50
+ return value;
51
+ }
52
+ s32() {
53
+ const value = this.view.getInt32(this.at, true);
54
+ this.at += 4;
55
+ return value;
56
+ }
57
+ f32() {
58
+ const value = this.view.getFloat32(this.at, true);
59
+ this.at += 4;
60
+ return value;
61
+ }
62
+ f64() {
63
+ const value = this.view.getFloat64(this.at, true);
64
+ this.at += 8;
65
+ return value;
66
+ }
67
+ stringZ() {
68
+ let end = this.at;
69
+ while (end < this.bytes.byteLength && this.bytes[end] !== 0) end++;
70
+ let value = "";
71
+ for (let i = this.at; i < end; i++) value += String.fromCharCode(this.bytes[i]);
72
+ this.at = end + 1;
73
+ return value;
74
+ }
75
+ }
76
+ function plausibleMeter(view, at, byteLength) {
77
+ if (at + 22 > byteLength) return false;
78
+ const grid = view.getFloat64(at, true);
79
+ const offset = view.getFloat64(at + 8, true);
80
+ const tempo = view.getFloat32(at + 16, true);
81
+ const beats = view.getUint8(at + 20);
82
+ const beatValue = view.getUint8(at + 21);
83
+ return Number.isFinite(grid) && grid >= 0 && grid < 600000 && Number.isFinite(offset) && offset >= 0 && offset < 600000 && Number.isFinite(tempo) && tempo > 0 && tempo < 1000 && beats >= 1 && beats <= 64 && [1, 2, 4, 8, 16, 32].includes(beatValue);
84
+ }
85
+ function findAnchors(bytes, knownIds) {
86
+ const view = new DataView(bytes.buffer, bytes.byteOffset, bytes.byteLength);
87
+ const anchors = [];
88
+ for (let at = 1; at + 4 <= bytes.byteLength; at++) {
89
+ const count = view.getUint32(at, true);
90
+ if (count > 256 || at + 4 + count * 4 + 22 > bytes.byteLength) continue;
91
+ let valid = true;
92
+ for (let i = 0; i < count; i++) {
93
+ if (!knownIds.has(view.getUint32(at + 4 + i * 4, true))) {
94
+ valid = false;
95
+ break;
96
+ }
97
+ }
98
+ if (valid && plausibleMeter(view, at + 4 + count * 4, bytes.byteLength)) {
99
+ anchors.push(at);
100
+ }
101
+ }
102
+ return anchors;
103
+ }
104
+ function readMusicNodeTail(cursor) {
105
+ const childCount = cursor.u32();
106
+ const children = [];
107
+ for (let i = 0; i < childCount; i++) children.push(cursor.u32());
108
+ const meter = {
109
+ gridPeriod: cursor.f64(),
110
+ gridOffset: cursor.f64(),
111
+ tempo: cursor.f32(),
112
+ beatsPerBar: cursor.u8(),
113
+ beatValue: cursor.u8()
114
+ };
115
+ const meterOverride = cursor.u8() !== 0;
116
+ const stingerCount = cursor.u32();
117
+ const stingers = [];
118
+ for (let i = 0; i < stingerCount; i++) {
119
+ stingers.push({
120
+ triggerId: cursor.u32(),
121
+ segmentId: cursor.u32(),
122
+ syncPlayAt: cursor.u32(),
123
+ cueFilterHash: cursor.u32(),
124
+ dontRepeatTime: cursor.s32(),
125
+ numSegmentLookAhead: cursor.u32()
126
+ });
127
+ }
128
+ return {
129
+ children,
130
+ meter,
131
+ meterOverride,
132
+ stingers
133
+ };
134
+ }
135
+
136
+ /** AkMusicTransNodeParams: transition rules shared by playlist + switch containers. */
137
+ function readTransRules(cursor) {
138
+ const ruleCount = cursor.u32();
139
+ if (ruleCount > 4096) throw new RangeError("rule count");
140
+ const rules = [];
141
+ for (let i = 0; i < ruleCount; i++) {
142
+ const srcCount = cursor.u32();
143
+ if (srcCount > 1024) throw new RangeError("src count");
144
+ const srcIds = [];
145
+ for (let j = 0; j < srcCount; j++) srcIds.push(cursor.s32());
146
+ const dstCount = cursor.u32();
147
+ if (dstCount > 1024) throw new RangeError("dst count");
148
+ const dstIds = [];
149
+ for (let j = 0; j < dstCount; j++) dstIds.push(cursor.s32());
150
+ const src = {
151
+ transitionTime: cursor.s32(),
152
+ fadeCurve: cursor.u32(),
153
+ fadeOffset: cursor.s32(),
154
+ syncType: cursor.u32(),
155
+ cueFilterHash: cursor.u32(),
156
+ playPostExit: cursor.u8() !== 0
157
+ };
158
+ const dst = {
159
+ transitionTime: cursor.s32(),
160
+ fadeCurve: cursor.u32(),
161
+ fadeOffset: cursor.s32(),
162
+ cueFilterHash: cursor.u32(),
163
+ jumpToId: cursor.u32(),
164
+ jumpToType: cursor.u16(),
165
+ entryType: cursor.u16(),
166
+ playPreEntry: cursor.u8() !== 0,
167
+ matchSourceCueName: cursor.u8() !== 0
168
+ };
169
+ let transitionSegment = null;
170
+ if (cursor.u8() !== 0) {
171
+ transitionSegment = {
172
+ segmentId: cursor.u32(),
173
+ fadeIn: {
174
+ transitionTime: cursor.s32(),
175
+ fadeCurve: cursor.u32(),
176
+ fadeOffset: cursor.s32()
177
+ },
178
+ fadeOut: {
179
+ transitionTime: cursor.s32(),
180
+ fadeCurve: cursor.u32(),
181
+ fadeOffset: cursor.s32()
182
+ },
183
+ playPreEntry: cursor.u8() !== 0,
184
+ playPostExit: cursor.u8() !== 0
185
+ };
186
+ }
187
+ rules.push({
188
+ srcIds,
189
+ dstIds,
190
+ src,
191
+ dst,
192
+ transitionSegment
193
+ });
194
+ }
195
+ return rules;
196
+ }
197
+
194
198
  /**
195
199
  * Decode a music-segment (HIRC 10) payload: children, meter, stingers,
196
200
  * duration, and entry/exit markers.
@@ -198,161 +202,161 @@ function readTransRules(cursor) {
198
202
  * @param {Uint8Array} bytes Entry payload view from `inspect()`.
199
203
  * @param {Set<number>} knownIds Every HIRC object id in the same bank.
200
204
  * @returns {object|null} Decoded segment, or null when no anchored parse consumes the payload exactly.
201
- */
202
- function parseMusicSegment(bytes, knownIds) {
203
- for (const anchor of findAnchors(bytes, knownIds)) {
204
- try {
205
- const cursor = new MusicCursor(bytes, anchor);
206
- const node = readMusicNodeTail(cursor);
207
- const duration = cursor.f64();
208
- if (!Number.isFinite(duration) || duration < 0 || duration > 36000000) continue;
209
- const markerCount = cursor.u32();
210
- if (markerCount > 1024) continue;
211
- const markers = [];
212
- for (let i = 0; i < markerCount; i++) {
213
- markers.push({
214
- id: cursor.u32(),
215
- position: cursor.f64(),
216
- name: cursor.stringZ()
217
- });
218
- }
219
- if (cursor.at !== bytes.byteLength) continue;
220
- if (markers.some(marker => !Number.isFinite(marker.position) || marker.position < 0)) continue;
221
- return {
222
- ...node,
223
- duration,
224
- markers
225
- };
226
- } catch {
227
- continue;
228
- }
229
- }
230
- return null;
231
- }
232
-
205
+ */
206
+ function parseMusicSegment(bytes, knownIds) {
207
+ for (const anchor of findAnchors(bytes, knownIds)) {
208
+ try {
209
+ const cursor = new MusicCursor(bytes, anchor);
210
+ const node = readMusicNodeTail(cursor);
211
+ const duration = cursor.f64();
212
+ if (!Number.isFinite(duration) || duration < 0 || duration > 36000000) continue;
213
+ const markerCount = cursor.u32();
214
+ if (markerCount > 1024) continue;
215
+ const markers = [];
216
+ for (let i = 0; i < markerCount; i++) {
217
+ markers.push({
218
+ id: cursor.u32(),
219
+ position: cursor.f64(),
220
+ name: cursor.stringZ()
221
+ });
222
+ }
223
+ if (cursor.at !== bytes.byteLength) continue;
224
+ if (markers.some(marker => !Number.isFinite(marker.position) || marker.position < 0)) continue;
225
+ return {
226
+ ...node,
227
+ duration,
228
+ markers
229
+ };
230
+ } catch {
231
+ continue;
232
+ }
233
+ }
234
+ return null;
235
+ }
236
+
233
237
  /**
234
238
  * Decode a music-track (HIRC 11) payload: sources, clips (play position and
235
239
  * trims per subtrack), track type, and switch parameters for switch tracks.
236
240
  *
237
241
  * @param {Uint8Array} bytes Entry payload view from `inspect()`.
238
242
  * @returns {object|null} Decoded track, or null when neither tail layout validates.
239
- */
240
- function parseMusicTrack(bytes) {
241
- const cursor = new MusicCursor(bytes, 0);
242
- cursor.u8(); // uFlags (midi/override bits)
243
- const sourceCount = cursor.u32();
244
- if (sourceCount > 512) return null;
245
- const sources = [];
246
- for (let i = 0; i < sourceCount; i++) {
247
- const pluginId = cursor.u32();
248
- const streamType = cursor.u8();
249
- const sourceId = cursor.u32();
250
- const inMemoryMediaSize = cursor.u32();
251
- const sourceBits = cursor.u8();
252
- if ((pluginId & 0x0f) === 0x02) {
253
- const size = cursor.u32();
254
- cursor.at += size;
255
- }
256
- sources.push({
257
- pluginId,
258
- streamType,
259
- sourceId,
260
- inMemoryMediaSize,
261
- sourceBits
262
- });
263
- }
264
- const clipCount = cursor.u32();
265
- if (clipCount > 4096) return null;
266
- const clips = [];
267
- for (let i = 0; i < clipCount; i++) {
268
- clips.push({
269
- trackId: cursor.u32(),
270
- sourceId: cursor.u32(),
271
- eventId: cursor.u32(),
272
- playAt: cursor.f64(),
273
- beginTrimOffset: cursor.f64(),
274
- endTrimOffset: cursor.f64(),
275
- srcDuration: cursor.f64()
276
- });
277
- }
278
- const subTrackCount = clipCount > 0 ? cursor.u32() : 0;
279
- const autoCount = cursor.u32();
280
- if (autoCount > 4096) return null;
281
- for (let i = 0; i < autoCount; i++) {
282
- cursor.u32(); // clip index
283
- cursor.u32(); // automation type
284
- const points = cursor.u32();
285
- if (points > 65536) return null;
286
- cursor.at += points * 12;
287
- }
288
- const headEnd = cursor.at;
289
-
290
- // Tail: [NodeBaseParams...] u8 trackType, [switch+trans params when the
291
- // type is 3], f32 lookAheadTime. The switch layout is tried FIRST because
292
- // it validates every field to the exact payload end - the simple layout
293
- // only checks one byte, and a switch tail ending in zero bytes would
294
- // satisfy it falsely.
295
- const view = new DataView(bytes.buffer, bytes.byteOffset, bytes.byteLength);
296
- const end = bytes.byteLength;
297
- for (let typeAt = headEnd; typeAt <= end - 5; typeAt++) {
298
- if (view.getUint8(typeAt) !== 3) continue;
299
- const tail = new MusicCursor(bytes, typeAt + 1);
300
- try {
301
- const groupType = tail.u8();
302
- if (groupType > 1) continue;
303
- const groupId = tail.u32();
304
- const defaultSwitch = tail.u32();
305
- const assocCount = tail.u32();
306
- if (assocCount > 1024) continue;
307
- const assoc = [];
308
- for (let i = 0; i < assocCount; i++) assoc.push(tail.u32());
309
- const trans = {
310
- srcTransitionTime: tail.s32(),
311
- srcFadeCurve: tail.u32(),
312
- srcFadeOffset: tail.s32(),
313
- syncType: tail.u32(),
314
- cueFilterHash: tail.u32(),
315
- dstTransitionTime: tail.s32(),
316
- dstFadeCurve: tail.u32(),
317
- dstFadeOffset: tail.s32()
318
- };
319
- const lookAheadTime = tail.f32();
320
- if (tail.at !== end) continue;
321
- return {
322
- sources,
323
- clips,
324
- subTrackCount,
325
- trackType: 3,
326
- lookAheadTime,
327
- switchParams: {
328
- groupType,
329
- groupId,
330
- defaultSwitch,
331
- assoc,
332
- trans
333
- }
334
- };
335
- } catch {
336
- continue;
337
- }
338
- }
339
- const simpleAt = end - 5;
340
- if (simpleAt >= headEnd) {
341
- const type = view.getUint8(simpleAt);
342
- if (type <= 2) {
343
- return {
344
- sources,
345
- clips,
346
- subTrackCount,
347
- trackType: type,
348
- lookAheadTime: view.getFloat32(end - 4, true),
349
- switchParams: null
350
- };
351
- }
352
- }
353
- return null;
354
- }
355
-
243
+ */
244
+ function parseMusicTrack(bytes) {
245
+ const cursor = new MusicCursor(bytes, 0);
246
+ cursor.u8(); // uFlags (midi/override bits)
247
+ const sourceCount = cursor.u32();
248
+ if (sourceCount > 512) return null;
249
+ const sources = [];
250
+ for (let i = 0; i < sourceCount; i++) {
251
+ const pluginId = cursor.u32();
252
+ const streamType = cursor.u8();
253
+ const sourceId = cursor.u32();
254
+ const inMemoryMediaSize = cursor.u32();
255
+ const sourceBits = cursor.u8();
256
+ if ((pluginId & 0x0f) === 0x02) {
257
+ const size = cursor.u32();
258
+ cursor.at += size;
259
+ }
260
+ sources.push({
261
+ pluginId,
262
+ streamType,
263
+ sourceId,
264
+ inMemoryMediaSize,
265
+ sourceBits
266
+ });
267
+ }
268
+ const clipCount = cursor.u32();
269
+ if (clipCount > 4096) return null;
270
+ const clips = [];
271
+ for (let i = 0; i < clipCount; i++) {
272
+ clips.push({
273
+ trackId: cursor.u32(),
274
+ sourceId: cursor.u32(),
275
+ eventId: cursor.u32(),
276
+ playAt: cursor.f64(),
277
+ beginTrimOffset: cursor.f64(),
278
+ endTrimOffset: cursor.f64(),
279
+ srcDuration: cursor.f64()
280
+ });
281
+ }
282
+ const subTrackCount = clipCount > 0 ? cursor.u32() : 0;
283
+ const autoCount = cursor.u32();
284
+ if (autoCount > 4096) return null;
285
+ for (let i = 0; i < autoCount; i++) {
286
+ cursor.u32(); // clip index
287
+ cursor.u32(); // automation type
288
+ const points = cursor.u32();
289
+ if (points > 65536) return null;
290
+ cursor.at += points * 12;
291
+ }
292
+ const headEnd = cursor.at;
293
+
294
+ // Tail: [NodeBaseParams...] u8 trackType, [switch+trans params when the
295
+ // type is 3], f32 lookAheadTime. The switch layout is tried FIRST because
296
+ // it validates every field to the exact payload end - the simple layout
297
+ // only checks one byte, and a switch tail ending in zero bytes would
298
+ // satisfy it falsely.
299
+ const view = new DataView(bytes.buffer, bytes.byteOffset, bytes.byteLength);
300
+ const end = bytes.byteLength;
301
+ for (let typeAt = headEnd; typeAt <= end - 5; typeAt++) {
302
+ if (view.getUint8(typeAt) !== 3) continue;
303
+ const tail = new MusicCursor(bytes, typeAt + 1);
304
+ try {
305
+ const groupType = tail.u8();
306
+ if (groupType > 1) continue;
307
+ const groupId = tail.u32();
308
+ const defaultSwitch = tail.u32();
309
+ const assocCount = tail.u32();
310
+ if (assocCount > 1024) continue;
311
+ const assoc = [];
312
+ for (let i = 0; i < assocCount; i++) assoc.push(tail.u32());
313
+ const trans = {
314
+ srcTransitionTime: tail.s32(),
315
+ srcFadeCurve: tail.u32(),
316
+ srcFadeOffset: tail.s32(),
317
+ syncType: tail.u32(),
318
+ cueFilterHash: tail.u32(),
319
+ dstTransitionTime: tail.s32(),
320
+ dstFadeCurve: tail.u32(),
321
+ dstFadeOffset: tail.s32()
322
+ };
323
+ const lookAheadTime = tail.f32();
324
+ if (tail.at !== end) continue;
325
+ return {
326
+ sources,
327
+ clips,
328
+ subTrackCount,
329
+ trackType: 3,
330
+ lookAheadTime,
331
+ switchParams: {
332
+ groupType,
333
+ groupId,
334
+ defaultSwitch,
335
+ assoc,
336
+ trans
337
+ }
338
+ };
339
+ } catch {
340
+ continue;
341
+ }
342
+ }
343
+ const simpleAt = end - 5;
344
+ if (simpleAt >= headEnd) {
345
+ const type = view.getUint8(simpleAt);
346
+ if (type <= 2) {
347
+ return {
348
+ sources,
349
+ clips,
350
+ subTrackCount,
351
+ trackType: type,
352
+ lookAheadTime: view.getFloat32(end - 4, true),
353
+ switchParams: null
354
+ };
355
+ }
356
+ }
357
+ return null;
358
+ }
359
+
356
360
  /**
357
361
  * Decode a music-playlist-container (HIRC 13) payload: children, meter,
358
362
  * stingers, transition rules, and the flat pre-order playlist tree.
@@ -360,45 +364,45 @@ function parseMusicTrack(bytes) {
360
364
  * @param {Uint8Array} bytes Entry payload view from `inspect()`.
361
365
  * @param {Set<number>} knownIds Every HIRC object id in the same bank.
362
366
  * @returns {object|null} Decoded playlist container, or null when no anchored parse validates.
363
- */
364
- function parseMusicPlaylist(bytes, knownIds) {
365
- for (const anchor of findAnchors(bytes, knownIds)) {
366
- try {
367
- const cursor = new MusicCursor(bytes, anchor);
368
- const node = readMusicNodeTail(cursor);
369
- const rules = readTransRules(cursor);
370
- const itemCount = cursor.u32();
371
- if (itemCount > 8192) continue;
372
- if (cursor.remaining !== itemCount * 30) continue;
373
- const items = [];
374
- for (let i = 0; i < itemCount; i++) {
375
- items.push({
376
- segmentId: cursor.u32(),
377
- playlistItemId: cursor.u32(),
378
- childCount: cursor.u32(),
379
- rsType: cursor.s32(),
380
- loop: cursor.s16(),
381
- loopMin: cursor.s16(),
382
- loopMax: cursor.s16(),
383
- weight: cursor.u32(),
384
- avoidRepeatCount: cursor.u16(),
385
- usingWeight: cursor.u8() !== 0,
386
- shuffle: cursor.u8() !== 0
387
- });
388
- }
389
- if (cursor.at !== bytes.byteLength) continue;
390
- return {
391
- ...node,
392
- rules,
393
- playlist: items
394
- };
395
- } catch {
396
- continue;
397
- }
398
- }
399
- return null;
400
- }
401
-
367
+ */
368
+ function parseMusicPlaylist(bytes, knownIds) {
369
+ for (const anchor of findAnchors(bytes, knownIds)) {
370
+ try {
371
+ const cursor = new MusicCursor(bytes, anchor);
372
+ const node = readMusicNodeTail(cursor);
373
+ const rules = readTransRules(cursor);
374
+ const itemCount = cursor.u32();
375
+ if (itemCount > 8192) continue;
376
+ if (cursor.remaining !== itemCount * 30) continue;
377
+ const items = [];
378
+ for (let i = 0; i < itemCount; i++) {
379
+ items.push({
380
+ segmentId: cursor.u32(),
381
+ playlistItemId: cursor.u32(),
382
+ childCount: cursor.u32(),
383
+ rsType: cursor.s32(),
384
+ loop: cursor.s16(),
385
+ loopMin: cursor.s16(),
386
+ loopMax: cursor.s16(),
387
+ weight: cursor.u32(),
388
+ avoidRepeatCount: cursor.u16(),
389
+ usingWeight: cursor.u8() !== 0,
390
+ shuffle: cursor.u8() !== 0
391
+ });
392
+ }
393
+ if (cursor.at !== bytes.byteLength) continue;
394
+ return {
395
+ ...node,
396
+ rules,
397
+ playlist: items
398
+ };
399
+ } catch {
400
+ continue;
401
+ }
402
+ }
403
+ return null;
404
+ }
405
+
402
406
  /**
403
407
  * Decode a music-switch-container (HIRC 12) payload: children, meter,
404
408
  * stingers, transition rules, argument groups, and the decision tree.
@@ -406,116 +410,116 @@ function parseMusicPlaylist(bytes, knownIds) {
406
410
  * @param {Uint8Array} bytes Entry payload view from `inspect()`.
407
411
  * @param {Set<number>} knownIds Every HIRC object id in the same bank.
408
412
  * @returns {object|null} Decoded switch container, or null when no anchored parse validates.
409
- */
410
- function parseMusicSwitch(bytes, knownIds) {
411
- for (const anchor of findAnchors(bytes, knownIds)) {
412
- try {
413
- const cursor = new MusicCursor(bytes, anchor);
414
- const node = readMusicNodeTail(cursor);
415
- const rules = readTransRules(cursor);
416
- const continuePlayback = cursor.u8() !== 0;
417
- const treeDepth = cursor.u32();
418
- if (treeDepth > 16) continue;
419
- const argumentGroups = [];
420
- for (let i = 0; i < treeDepth; i++) argumentGroups.push({
421
- groupId: cursor.u32()
422
- });
423
- for (let i = 0; i < treeDepth; i++) argumentGroups[i].groupType = cursor.u8();
424
- const treeDataSize = cursor.u32();
425
- const mode = cursor.u8();
426
- if (cursor.remaining !== treeDataSize) continue;
427
- if (treeDataSize % 12 !== 0) continue;
428
- const treeNodes = [];
429
- const nodeCount = treeDataSize / 12;
430
- for (let i = 0; i < nodeCount; i++) {
431
- const key = cursor.u32();
432
- // 4-byte union: leaf = audioNodeId, internal = childrenIdx + count.
433
- const audioNodeId = cursor.view.getUint32(cursor.at, true);
434
- const childrenIdx = cursor.u16();
435
- const childrenCount = cursor.u16();
436
- const weight = cursor.u16();
437
- const probability = cursor.u16();
438
- treeNodes.push({
439
- key,
440
- audioNodeId,
441
- childrenIdx,
442
- childrenCount,
443
- weight,
444
- probability
445
- });
446
- }
447
- if (cursor.at !== bytes.byteLength) continue;
448
- return {
449
- ...node,
450
- rules,
451
- continuePlayback,
452
- argumentGroups,
453
- mode,
454
- treeNodes
455
- };
456
- } catch {
457
- continue;
458
- }
459
- }
460
- return null;
461
- }
462
- const MUSIC_PARSERS = Object.freeze({
463
- 10: (payload, knownIds) => parseMusicSegment(payload, knownIds),
464
- 11: payload => parseMusicTrack(payload),
465
- 12: (payload, knownIds) => parseMusicSwitch(payload, knownIds),
466
- 13: (payload, knownIds) => parseMusicPlaylist(payload, knownIds)
467
- });
468
- const MUSIC_TYPE_NAMES = Object.freeze({
469
- 10: "music-segment",
470
- 11: "music-track",
471
- 12: "music-switch-container",
472
- 13: "music-playlist-container"
473
- });
474
-
413
+ */
414
+ function parseMusicSwitch(bytes, knownIds) {
415
+ for (const anchor of findAnchors(bytes, knownIds)) {
416
+ try {
417
+ const cursor = new MusicCursor(bytes, anchor);
418
+ const node = readMusicNodeTail(cursor);
419
+ const rules = readTransRules(cursor);
420
+ const continuePlayback = cursor.u8() !== 0;
421
+ const treeDepth = cursor.u32();
422
+ if (treeDepth > 16) continue;
423
+ const argumentGroups = [];
424
+ for (let i = 0; i < treeDepth; i++) argumentGroups.push({
425
+ groupId: cursor.u32()
426
+ });
427
+ for (let i = 0; i < treeDepth; i++) argumentGroups[i].groupType = cursor.u8();
428
+ const treeDataSize = cursor.u32();
429
+ const mode = cursor.u8();
430
+ if (cursor.remaining !== treeDataSize) continue;
431
+ if (treeDataSize % 12 !== 0) continue;
432
+ const treeNodes = [];
433
+ const nodeCount = treeDataSize / 12;
434
+ for (let i = 0; i < nodeCount; i++) {
435
+ const key = cursor.u32();
436
+ // 4-byte union: leaf = audioNodeId, internal = childrenIdx + count.
437
+ const audioNodeId = cursor.view.getUint32(cursor.at, true);
438
+ const childrenIdx = cursor.u16();
439
+ const childrenCount = cursor.u16();
440
+ const weight = cursor.u16();
441
+ const probability = cursor.u16();
442
+ treeNodes.push({
443
+ key,
444
+ audioNodeId,
445
+ childrenIdx,
446
+ childrenCount,
447
+ weight,
448
+ probability
449
+ });
450
+ }
451
+ if (cursor.at !== bytes.byteLength) continue;
452
+ return {
453
+ ...node,
454
+ rules,
455
+ continuePlayback,
456
+ argumentGroups,
457
+ mode,
458
+ treeNodes
459
+ };
460
+ } catch {
461
+ continue;
462
+ }
463
+ }
464
+ return null;
465
+ }
466
+ const MUSIC_PARSERS = Object.freeze({
467
+ 10: (payload, knownIds) => parseMusicSegment(payload, knownIds),
468
+ 11: payload => parseMusicTrack(payload),
469
+ 12: (payload, knownIds) => parseMusicSwitch(payload, knownIds),
470
+ 13: (payload, knownIds) => parseMusicPlaylist(payload, knownIds)
471
+ });
472
+ const MUSIC_TYPE_NAMES = Object.freeze({
473
+ 10: "music-segment",
474
+ 11: "music-track",
475
+ 12: "music-switch-container",
476
+ 13: "music-playlist-container"
477
+ });
478
+
475
479
  /**
476
480
  * Decode every interactive-music node across one or more inspected banks.
477
481
  *
478
482
  * @param {Array<object>} inspections `CjsBnkFormat.inspect()` results for every related music bank.
479
483
  * @returns {{nodes: Map<number, object>, diagnostics: {parsed: number, failed: Array<{bank: string, type: string, id: number}>}}} Decoded nodes keyed by object id plus per-entry failures.
480
- */
481
- function musicNodesFromBanks(inspections) {
482
- const banks = Array.isArray(inspections) ? inspections : [inspections];
483
- const nodes = new Map();
484
- const failed = [];
485
- let parsed = 0;
486
- for (const inspection of banks) {
487
- const knownIds = new Set();
488
- for (const entry of inspection.hirc ?? []) knownIds.add(entry.id);
489
- for (const entry of inspection.hirc ?? []) {
490
- const parser = MUSIC_PARSERS[entry.type];
491
- if (!parser) continue;
492
- const payload = entry.payload instanceof Uint8Array ? entry.payload : null;
493
- const decoded = payload ? parser(payload, knownIds) : null;
494
- if (!decoded) {
495
- failed.push({
496
- bank: inspection.source || "",
497
- type: MUSIC_TYPE_NAMES[entry.type],
498
- id: entry.id
499
- });
500
- continue;
501
- }
502
- parsed++;
503
- nodes.set(entry.id, {
504
- id: entry.id,
505
- type: MUSIC_TYPE_NAMES[entry.type],
506
- bank: inspection.source || "",
507
- ...decoded
508
- });
509
- }
510
- }
511
- return {
512
- nodes,
513
- diagnostics: {
514
- parsed,
515
- failed
516
- }
517
- };
518
- }
519
-
520
- export { musicNodesFromBanks, parseMusicPlaylist, parseMusicSegment, parseMusicSwitch, parseMusicTrack };
521
- //# sourceMappingURL=musicNodes.js.map
484
+ */
485
+ function musicNodesFromBanks(inspections) {
486
+ const banks = Array.isArray(inspections) ? inspections : [inspections];
487
+ const nodes = new Map();
488
+ const failed = [];
489
+ let parsed = 0;
490
+ for (const inspection of banks) {
491
+ const knownIds = new Set();
492
+ for (const entry of inspection.hirc ?? []) knownIds.add(entry.id);
493
+ for (const entry of inspection.hirc ?? []) {
494
+ const parser = MUSIC_PARSERS[entry.type];
495
+ if (!parser) continue;
496
+ const payload = entry.payload instanceof Uint8Array ? entry.payload : null;
497
+ const decoded = payload ? parser(payload, knownIds) : null;
498
+ if (!decoded) {
499
+ failed.push({
500
+ bank: inspection.source || "",
501
+ type: MUSIC_TYPE_NAMES[entry.type],
502
+ id: entry.id
503
+ });
504
+ continue;
505
+ }
506
+ parsed++;
507
+ nodes.set(entry.id, {
508
+ id: entry.id,
509
+ type: MUSIC_TYPE_NAMES[entry.type],
510
+ bank: inspection.source || "",
511
+ ...decoded
512
+ });
513
+ }
514
+ }
515
+ return {
516
+ nodes,
517
+ diagnostics: {
518
+ parsed,
519
+ failed
520
+ }
521
+ };
522
+ }
523
+
524
+ export { musicNodesFromBanks, parseMusicPlaylist, parseMusicSegment, parseMusicSwitch, parseMusicTrack };
525
+ //# sourceMappingURL=musicNodes.js.map