@carbonenginejs/runtime-resource 0.8.0 → 0.9.0
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.
- package/LICENSE +21 -21
- package/NOTICE +29 -29
- package/README.md +67 -548
- package/dist/CjsMotherLode.js +1271 -1271
- package/dist/CjsResMan.js +3005 -3005
- package/dist/CjsResManQueue.js +214 -214
- package/dist/CjsResource.js +566 -566
- package/dist/CjsResourceSource.js +59 -59
- package/dist/_virtual/_rollupPluginBabelHelpers.js +153 -153
- package/dist/format/CjsBlueReader.js +269 -269
- package/dist/format/CjsFormat.js +192 -192
- package/dist/format/CjsReader.js +18 -18
- package/dist/format/CjsResourceProbe.js +277 -277
- package/dist/format/payloadContract.js +173 -173
- package/dist/formats/black/CjsBlackFormat.js +278 -278
- package/dist/formats/black/core/CjsBlackBinaryReader.js +153 -153
- package/dist/formats/black/core/CjsBlackPropertyReaders.js +382 -382
- package/dist/formats/black/core/CjsBlackReader.js +639 -639
- package/dist/formats/black/core/CjsBlackSchemaRegistry.js +433 -433
- package/dist/formats/black/core/black-schema-v1-2026-07-11.json.js +4 -4
- package/dist/formats/black/core/blackConstants.js +7 -7
- package/dist/formats/black/core/blackDefinitions.js +10 -10
- package/dist/formats/black/core/blackEnums.js +6 -6
- package/dist/formats/black/core/blackSchema.js +3 -3
- package/dist/formats/black/core/blackVersion.js +22 -22
- package/dist/formats/black/core/helpers.js +182 -182
- package/dist/formats/black/core/schema.js +4 -4
- package/dist/formats/black/index.js +2 -2
- package/dist/formats/bnk/CjsBnkFormat.js +125 -125
- package/dist/formats/bnk/core/graph.js +140 -140
- package/dist/formats/bnk/core/helpers.js +409 -409
- package/dist/formats/bnk/core/musicNodes.js +489 -489
- package/dist/formats/bnk/core/soundbanksInfo.js +246 -246
- package/dist/formats/bnk/index.js +2 -2
- package/dist/formats/cmf/CjsCmfFormat.js +497 -497
- package/dist/formats/cmf/core/binary.js +118 -118
- package/dist/formats/cmf/core/buffers.js +233 -233
- package/dist/formats/cmf/core/constants.js +47 -47
- package/dist/formats/cmf/core/gr2Anim.js +453 -453
- package/dist/formats/cmf/core/helpers.js +287 -287
- package/dist/formats/cmf/core/pack.js +276 -276
- package/dist/formats/cmf/core/schema.js +364 -364
- package/dist/formats/cmf/core/shared.js +268 -268
- package/dist/formats/cmf/core/writer.js +517 -517
- package/dist/formats/cmf/index.js +2 -2
- package/dist/formats/dds/CjsDdsFormat.js +193 -193
- package/dist/formats/dds/core/bc6h.js +288 -288
- package/dist/formats/dds/core/bc7.js +251 -251
- package/dist/formats/dds/core/helpers.js +815 -815
- package/dist/formats/dds/index.js +2 -2
- package/dist/formats/fbx/CjsFbxFormat.js +266 -266
- package/dist/formats/fbx/core/helpers.js +3901 -3901
- package/dist/formats/fbx/index.js +2 -2
- package/dist/formats/flac/CjsFlacFormat.js +87 -87
- package/dist/formats/flac/core/helpers.js +295 -295
- package/dist/formats/flac/index.js +2 -2
- package/dist/formats/gif/CjsGifFormat.js +87 -87
- package/dist/formats/gif/core/helpers.js +360 -360
- package/dist/formats/gif/index.js +2 -2
- package/dist/formats/gltf/CjsGltfFormat.js +290 -290
- package/dist/formats/gltf/core/helpers.js +292 -292
- package/dist/formats/gltf/core/json.js +79 -79
- package/dist/formats/gltf/core/parser.js +666 -666
- package/dist/formats/gltf/core/targets.js +163 -163
- package/dist/formats/gltf/index.js +2 -2
- package/dist/formats/gr2/CjsGr2Format.js +46 -0
- package/dist/formats/gr2/CjsGr2Format.js.map +1 -0
- package/dist/formats/gr2/core/CjsFormatGr2.js +273 -0
- package/dist/formats/gr2/core/CjsFormatGr2.js.map +1 -0
- package/dist/formats/gr2/core/bitknit2.js +280 -0
- package/dist/formats/gr2/core/bitknit2.js.map +1 -0
- package/dist/formats/gr2/core/curves.js +1047 -0
- package/dist/formats/gr2/core/curves.js.map +1 -0
- package/dist/formats/gr2/core/gsf.js +72 -0
- package/dist/formats/gr2/core/gsf.js.map +1 -0
- package/dist/formats/gr2/core/helpers.js +332 -0
- package/dist/formats/gr2/core/helpers.js.map +1 -0
- package/dist/formats/gr2/core/json.js +622 -0
- package/dist/formats/gr2/core/json.js.map +1 -0
- package/dist/formats/gr2/core/oodle1.js +388 -0
- package/dist/formats/gr2/core/oodle1.js.map +1 -0
- package/dist/formats/gr2/core/reader.js +617 -0
- package/dist/formats/gr2/core/reader.js.map +1 -0
- package/dist/formats/gr2/core/tangents.js +48 -0
- package/dist/formats/gr2/core/tangents.js.map +1 -0
- package/dist/formats/gr2/core/targets.js +351 -0
- package/dist/formats/gr2/core/targets.js.map +1 -0
- package/dist/formats/gr2/index.js +3 -0
- package/dist/formats/gr2/index.js.map +1 -0
- package/dist/formats/index.js +30 -23
- package/dist/formats/index.js.map +1 -1
- package/dist/formats/jpeg/CjsJpegFormat.js +206 -206
- package/dist/formats/jpeg/core/helpers.js +350 -350
- package/dist/formats/jpeg/core/jpeg.js +377 -377
- package/dist/formats/jpeg/index.js +2 -2
- package/dist/formats/mp3/CjsMp3Format.js +192 -192
- package/dist/formats/mp3/core/helpers.js +338 -338
- package/dist/formats/mp3/index.js +2 -2
- package/dist/formats/mp4/CjsMp4Format.js +191 -191
- package/dist/formats/mp4/core/helpers.js +449 -449
- package/dist/formats/mp4/index.js +2 -2
- package/dist/formats/obj/CjsObjFormat.js +253 -253
- package/dist/formats/obj/core/helpers.js +573 -573
- package/dist/formats/obj/core/json.js +64 -64
- package/dist/formats/obj/core/parser.js +321 -321
- package/dist/formats/obj/index.js +2 -2
- package/dist/formats/ogg/CjsOggFormat.js +88 -88
- package/dist/formats/ogg/core/helpers.js +387 -387
- package/dist/formats/ogg/core/imdct.js +178 -178
- package/dist/formats/ogg/core/vorbis.js +999 -999
- package/dist/formats/ogg/index.js +2 -2
- package/dist/formats/png/CjsPngFormat.js +195 -195
- package/dist/formats/png/core/helpers.js +583 -583
- package/dist/formats/png/index.js +2 -2
- package/dist/formats/red/CjsRedFormat.js +261 -261
- package/dist/formats/red/core/CjsRedReader.js +194 -194
- package/dist/formats/red/core/blackDefinitions.js +3 -3
- package/dist/formats/red/core/helpers.js +139 -139
- package/dist/formats/red/core/redGraph.js +68 -68
- package/dist/formats/red/core/schema.js +4 -4
- package/dist/formats/red/index.js +2 -2
- package/dist/formats/stl/CjsStlFormat.js +365 -365
- package/dist/formats/stl/core/helpers.js +261 -261
- package/dist/formats/stl/core/json.js +51 -51
- package/dist/formats/stl/core/stl.js +629 -629
- package/dist/formats/stl/core/targets.js +163 -163
- package/dist/formats/stl/index.js +2 -2
- package/dist/formats/tga/CjsTgaFormat.js +192 -192
- package/dist/formats/tga/core/helpers.js +446 -446
- package/dist/formats/tga/index.js +2 -2
- package/dist/formats/wav/CjsWavFormat.js +192 -192
- package/dist/formats/wav/core/helpers.js +328 -328
- package/dist/formats/wav/index.js +2 -2
- package/dist/formats/webm/CjsWebmFormat.js +191 -191
- package/dist/formats/webm/core/helpers.js +537 -537
- package/dist/formats/webm/index.js +2 -2
- package/dist/formats/webp/CjsWebpFormat.js +86 -86
- package/dist/formats/webp/core/helpers.js +214 -214
- package/dist/formats/webp/index.js +2 -2
- package/dist/formats/wem/CjsWemFormat.js +241 -241
- package/dist/formats/wem/core/bitStream.js +259 -259
- package/dist/formats/wem/core/codebookLibrary.js +164 -164
- package/dist/formats/wem/core/helpers.js +417 -417
- package/dist/formats/wem/core/packedCodebooksAotuv603.js +30 -30
- package/dist/formats/wem/core/ptadpcm.js +77 -77
- package/dist/formats/wem/core/resolve.js +121 -121
- package/dist/formats/wem/core/wemToOgg.js +485 -485
- package/dist/formats/wem/index.js +2 -2
- package/dist/formats/yaml/CjsYamlFormat.js +83 -83
- package/dist/formats/yaml/core/CjsYamlReader.js +305 -305
- package/dist/formats/yaml/core/helpers.js +160 -160
- package/dist/formats/yaml/index.js +2 -2
- package/dist/index.js +49 -48
- package/dist/index.js.map +1 -1
- package/dist/resourcePath.js +18 -18
- package/dist/resourceStates.js +9 -9
- package/dist/resources/AudioGeometryResData.js +47 -47
- package/dist/resources/GStateBindingCallbackData.js +31 -31
- package/dist/resources/MeshDecalData.js +37 -37
- package/dist/resources/MeshDecalLodData.js +34 -34
- package/dist/resources/Tr2EffectRes.js +71 -71
- package/dist/resources/Tr2GrannyIntersectionResult.js +60 -60
- package/dist/resources/Tr2GrannyStateRes.js +44 -44
- package/dist/resources/Tr2ImageRes.js +114 -114
- package/dist/resources/Tr2LightProfileRes.js +40 -40
- package/dist/resources/Tr2MaterialArea.js +34 -34
- package/dist/resources/Tr2MaterialMesh.js +31 -31
- package/dist/resources/Tr2MaterialRes.js +34 -34
- package/dist/resources/Tr2ShaderPermutation.js +43 -43
- package/dist/resources/Tr2TextureLodManager.js +80 -80
- package/dist/resources/Tr2TextureLodUpdateRequest.js +37 -37
- package/dist/resources/Tr2TexturePackChannel.js +37 -37
- package/dist/resources/Tr2TexturePipeline.js +52 -52
- package/dist/resources/Tr2TexturePipelineParams.js +34 -34
- package/dist/resources/Tr2TexturePipelineStepCompress.js +40 -40
- package/dist/resources/Tr2TexturePipelineStepGenerateMips.js +22 -0
- package/dist/resources/Tr2TexturePipelineStepGenerateMips.js.map +1 -0
- package/dist/resources/Tr2TexturePipelineStepLimitSize.js +34 -34
- package/dist/resources/Tr2TexturePipelineStepLoad.js +31 -31
- package/dist/resources/Tr2TexturePipelineStepPack.js +43 -43
- package/dist/resources/TriGeometryRes.js +239 -239
- package/dist/resources/TriGeometryResAreaData.js +59 -59
- package/dist/resources/TriGeometryResJointData.js +38 -38
- package/dist/resources/TriGeometryResLodData.js +88 -88
- package/dist/resources/TriGeometryResMeshData.js +63 -63
- package/dist/resources/TriGeometryResSkeletonData.js +34 -34
- package/dist/resources/TriGrannyRes.js +43 -43
- package/dist/resources/TriJointBinding.js +38 -38
- package/dist/resources/TriMorphTargetGeometryConstants.js +46 -46
- package/dist/resources/TriRtGeometryConstants.js +88 -88
- package/dist/resources/TriTextureRes.js +304 -304
- package/dist/resources/enums.js +18 -18
- package/dist/resources/resourceBoundary.js +47 -47
- package/dist/resources/texturePipelineBehavior.js +308 -308
- package/dist/texture/CjsTextureArrayRes.js +406 -406
- package/dist/texture/CjsTextureParameterProxy.js +133 -133
- package/docs/README.md +69 -0
- package/docs/architecture.md +86 -0
- package/docs/concepts/resource-lifecycle.md +217 -0
- package/docs/formats/README.md +104 -0
- package/{FORMAT-PROVENANCE.md → docs/formats/provenance.md} +173 -155
- package/docs/formats/stl.md +37 -0
- package/docs/formats/wwise.md +44 -0
- package/docs/reference/events.md +92 -0
- package/docs/reference/motherlode-cache.md +244 -0
- package/docs/reference/queues.md +102 -0
- package/docs/reference/reload.md +107 -0
- package/docs/reference/texture-arrays.md +113 -0
- package/docs/reference/texture-pipeline.md +53 -0
- package/docs/roadmap.md +104 -0
- package/format-notices/black/LICENSE +21 -21
- package/format-notices/black/NOTICE +47 -47
- package/format-notices/bnk/LICENSE +21 -21
- package/format-notices/bnk/NOTICE +20 -20
- package/format-notices/cmf/LICENSE +21 -21
- package/format-notices/cmf/NOTICE +36 -36
- package/format-notices/dds/LICENSE +21 -21
- package/format-notices/dds/NOTICE +14 -14
- package/format-notices/fbx/LICENSE +21 -21
- package/format-notices/fbx/NOTICE +14 -14
- package/format-notices/flac/LICENSE +21 -21
- package/format-notices/flac/NOTICE +14 -14
- package/format-notices/gif/LICENSE +21 -21
- package/format-notices/gif/NOTICE +14 -14
- package/format-notices/gltf/LICENSE +21 -21
- package/format-notices/gltf/NOTICE +27 -27
- package/format-notices/gr2/LICENSE +21 -0
- package/format-notices/gr2/NOTICE +60 -0
- package/format-notices/gr2/THIRD-PARTY-NOTICES.md +93 -0
- package/format-notices/jpeg/LICENSE +21 -21
- package/format-notices/jpeg/NOTICE +14 -14
- package/format-notices/mp3/LICENSE +21 -21
- package/format-notices/mp3/NOTICE +14 -14
- package/format-notices/mp4/LICENSE +21 -21
- package/format-notices/mp4/NOTICE +14 -14
- package/format-notices/obj/LICENSE +21 -21
- package/format-notices/obj/NOTICE +26 -26
- package/format-notices/ogg/LICENSE +21 -21
- package/format-notices/ogg/NOTICE +28 -28
- package/format-notices/png/LICENSE +21 -21
- package/format-notices/png/NOTICE +14 -14
- package/format-notices/red/LICENSE +21 -21
- package/format-notices/red/NOTICE +31 -31
- package/format-notices/stl/LICENSE +21 -21
- package/format-notices/stl/NOTICE +21 -21
- package/format-notices/tga/LICENSE +21 -21
- package/format-notices/tga/NOTICE +14 -14
- package/format-notices/wav/LICENSE +21 -21
- package/format-notices/wav/NOTICE +14 -14
- package/format-notices/webm/LICENSE +21 -21
- package/format-notices/webm/NOTICE +14 -14
- package/format-notices/webp/LICENSE +21 -21
- package/format-notices/webp/NOTICE +14 -14
- package/format-notices/wem/LICENSE +57 -57
- package/format-notices/wem/NOTICE +33 -33
- package/format-notices/yaml/LICENSE +21 -21
- package/format-notices/yaml/NOTICE +44 -44
- package/package.json +52 -51
- package/resource-lifecycle.md +0 -679
|
@@ -1,196 +1,196 @@
|
|
|
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
|
+
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
|
+
|
|
194
194
|
/**
|
|
195
195
|
* Decode a music-segment (HIRC 10) payload: children, meter, stingers,
|
|
196
196
|
* duration, and entry/exit markers.
|
|
@@ -198,161 +198,161 @@ function readTransRules(cursor) {
|
|
|
198
198
|
* @param {Uint8Array} bytes Entry payload view from `inspect()`.
|
|
199
199
|
* @param {Set<number>} knownIds Every HIRC object id in the same bank.
|
|
200
200
|
* @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
|
-
|
|
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
|
+
|
|
233
233
|
/**
|
|
234
234
|
* Decode a music-track (HIRC 11) payload: sources, clips (play position and
|
|
235
235
|
* trims per subtrack), track type, and switch parameters for switch tracks.
|
|
236
236
|
*
|
|
237
237
|
* @param {Uint8Array} bytes Entry payload view from `inspect()`.
|
|
238
238
|
* @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
|
-
|
|
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
|
+
|
|
356
356
|
/**
|
|
357
357
|
* Decode a music-playlist-container (HIRC 13) payload: children, meter,
|
|
358
358
|
* stingers, transition rules, and the flat pre-order playlist tree.
|
|
@@ -360,45 +360,45 @@ function parseMusicTrack(bytes) {
|
|
|
360
360
|
* @param {Uint8Array} bytes Entry payload view from `inspect()`.
|
|
361
361
|
* @param {Set<number>} knownIds Every HIRC object id in the same bank.
|
|
362
362
|
* @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
|
-
|
|
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
|
+
|
|
402
402
|
/**
|
|
403
403
|
* Decode a music-switch-container (HIRC 12) payload: children, meter,
|
|
404
404
|
* stingers, transition rules, argument groups, and the decision tree.
|
|
@@ -406,116 +406,116 @@ function parseMusicPlaylist(bytes, knownIds) {
|
|
|
406
406
|
* @param {Uint8Array} bytes Entry payload view from `inspect()`.
|
|
407
407
|
* @param {Set<number>} knownIds Every HIRC object id in the same bank.
|
|
408
408
|
* @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
|
-
|
|
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
|
+
|
|
475
475
|
/**
|
|
476
476
|
* Decode every interactive-music node across one or more inspected banks.
|
|
477
477
|
*
|
|
478
478
|
* @param {Array<object>} inspections `CjsBnkFormat.inspect()` results for every related music bank.
|
|
479
479
|
* @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
|
|
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
|