Files
blitzkit/packages/core/src/streams/sc2.ts
T

323 lines
7.4 KiB
TypeScript
Raw Normal View History

2025-10-13 23:15:32 -05:00
import type { Vector3Tuple, Vector4Tuple } from "three";
2025-10-11 21:22:48 -05:00
import { ScpgReadStream } from "./scpg";
2023-12-18 17:49:07 -06:00
2023-12-18 16:28:15 -06:00
export interface SC2 {
2025-10-11 21:22:48 -05:00
"#dataNodes": DataNode[];
"#hierarchy": Hierarchy[];
"#sceneComponents": SceneComponents;
2023-12-18 16:28:15 -06:00
}
type DataNode = {
2025-10-11 21:22:48 -05:00
"##name": "NMaterial";
"#id": ArrayBuffer;
2023-12-18 16:28:15 -06:00
materialName: string;
2023-12-19 20:11:37 -06:00
parentMaterialKey?: bigint;
2023-12-18 16:28:15 -06:00
qualityGroup?: string;
fxName?: string;
2023-12-22 15:59:06 -06:00
textures?: Textures;
2026-04-14 11:31:16 -05:00
customCullMode?: number;
enabledPresets?: EnabledPresets;
properties?: Properties;
2023-12-19 14:32:08 -06:00
} & (
| ({
configCount: number;
} & Record<`configArchive_${number}`, ConfigArchive>)
| {
configCount: undefined;
}
);
2023-12-18 16:28:15 -06:00
2026-04-14 11:31:16 -05:00
export interface ConfigArchive {
2023-12-18 16:28:15 -06:00
configName: string;
fxName: string;
properties: Properties;
textureSampleStates: TextureSampleStates;
textures: Textures;
customCullMode?: number;
enabledPresets?: EnabledPresets;
flags?: Flags;
}
interface EnabledPresets {
AlphaTest: boolean;
}
interface Flags {
AMBIENT_ATTENUATION_BOX: number;
2024-01-08 18:34:04 -06:00
BLENDING: number;
2023-12-18 16:28:15 -06:00
}
interface Properties {
2024-02-18 16:17:00 -06:00
alphatestThreshold: ArrayBuffer;
attenuationBoxHalfSize: ArrayBuffer;
attenuationBoxSmoothness: ArrayBuffer;
baseColorFactor?: ArrayBuffer;
decalTileCoordScale?: ArrayBuffer;
inGlossiness: ArrayBuffer;
inSpecularity: ArrayBuffer;
metalFresnelReflectance: ArrayBuffer;
metallicRoughnessFactor?: ArrayBuffer;
2023-12-18 16:28:15 -06:00
}
interface TextureSampleStates {
albedo: number;
baseColorMap: number;
baseNormalMap: number;
baseRMMap: number;
decalmask?: number;
maskMap: number;
miscMap: number;
normalmap: number;
}
2023-12-22 15:59:06 -06:00
export interface Textures {
2023-12-18 16:28:15 -06:00
albedo: string;
2023-12-22 15:59:06 -06:00
baseColorMap?: string;
baseNormalMap?: string;
baseRMMap?: string;
2023-12-18 16:28:15 -06:00
decalmask?: string;
2023-12-22 15:59:06 -06:00
maskMap?: string;
miscMap?: string;
normalmap?: string;
2023-12-18 16:28:15 -06:00
}
2023-12-18 17:49:07 -06:00
export interface Hierarchy {
2025-10-11 21:22:48 -05:00
"##name": "Entity";
"#hierarchy"?: Hierarchy[];
2023-12-18 16:28:15 -06:00
components: Components;
flags: number;
2023-12-18 17:49:07 -06:00
id: bigint;
2023-12-18 16:28:15 -06:00
name: string;
}
// 0001, 0002, 0003...: Component
type Components = {
count: number;
} & Record<string, Component>;
// 0001, 0002, 0003...
type RoBatches = Record<
string,
{
2025-10-11 21:22:48 -05:00
"##name": "RenderBatch";
"rb.aabbox": RbAabbox;
"rb.classname": "RenderBatch";
"rb.datasource": bigint;
"rb.nmatname": bigint;
"rb.sortingKey": number;
2023-12-18 16:28:15 -06:00
}
>;
interface RbAabbox {
minimum: number[];
maximum: number[];
}
2023-12-19 14:32:08 -06:00
export type Component =
2023-12-18 16:28:15 -06:00
| {
2025-10-11 21:22:48 -05:00
"comp.typename": "TransformComponent";
"tc.localRotation": Vector4Tuple;
"tc.localScale": Vector3Tuple;
"tc.localTranslation": Vector3Tuple;
"tc.worldRotation": Vector4Tuple;
"tc.worldScale": Vector3Tuple;
"tc.worldTranslation": Vector3Tuple;
2023-12-18 16:28:15 -06:00
}
| {
2025-10-11 21:22:48 -05:00
"comp.typename": "RenderComponent";
"rc.renderObj": {
"##name": "Mesh";
"ro.batchCount": number;
"ro.batches": RoBatches;
"ro.debugflags": number;
"ro.flags": number;
"ro.notShadowOnly": boolean;
"ro.sOclCull": boolean;
"ro.sOclIndex": number;
} & Record<`rb${number}.${"lodIndex" | "switchIndex"}`, number>;
2023-12-18 16:28:15 -06:00
}
| {
2025-10-11 21:22:48 -05:00
"comp.typename": "SlotComponent";
"sc.attachmentRotation": number[];
"sc.attachmentScale": number[];
"sc.attachmentTranslation": number[];
"sc.configFilePath": string;
"sc.slotName": string;
"sc.template": string;
"sc.typeFiltersCount": number;
2023-12-18 16:28:15 -06:00
}
| {
2025-10-11 21:22:48 -05:00
"comp.typename": "LodComponent";
"lc.loddist": Record<`distance${number}`, number>;
2023-12-25 11:21:39 -06:00
}
| {
2025-10-11 21:22:48 -05:00
"comp.typename": "DecorItemComponent";
2023-12-25 11:21:39 -06:00
drawOrder: number;
shouldApplyCamo: boolean;
vanishTargetAlpha: number;
vanishWhenArmorShown: boolean;
}
| {
2025-10-11 21:22:48 -05:00
"comp.typename": "NewSlotComponent";
2023-12-25 11:21:39 -06:00
slotItemsCount: number;
slots: {
[key: string]: {
configFilePath: string;
name: string;
transform: {
position: Vector3Tuple;
scale: Vector3Tuple;
rotation: Vector4Tuple;
};
};
};
2023-12-29 13:01:45 -06:00
}
| {
2025-10-11 21:22:48 -05:00
"comp.typename": "ScenarioComponent";
"scenario.scriptId": string;
2023-12-29 13:01:45 -06:00
}
| ({
2025-10-11 21:22:48 -05:00
"comp.typename": "StateSwitcherComponent";
"ssc.activeState": number;
"ssc.statesCount": number;
2023-12-29 19:56:50 -06:00
} & Record<`ssc.state${number}`, string>)
| {
2025-10-11 21:22:48 -05:00
"comp.typename": "CustomPropertiesComponent";
"cpc.properties.archive": {
"editor.donotremove": number;
2023-12-29 19:56:50 -06:00
};
2024-01-02 13:31:34 -06:00
}
| ({
2025-10-11 21:22:48 -05:00
"comp.typename": "ActionComponent";
"ac.actionCount": number;
2024-01-02 13:31:34 -06:00
} & Record<
string, // 0000, 0001, ...
{
2025-10-11 21:22:48 -05:00
"act.delay": number;
"act.delayVariation": number;
"act.entityName": string;
"act.event": number;
"act.eventToTrigger": string;
"act.motionFrameTime": number;
"act.motionSpeed": number;
"act.stateActivated": number;
"act.stopAfterNRepeats": number;
"act.stopWhenEmpty": boolean;
"act.switchIndex": number;
"act.type": number;
"act.userEventId": string;
2024-01-02 13:31:34 -06:00
}
>)
| {
2025-10-11 21:22:48 -05:00
"comp.typename": "ParticleEffectComponent";
"pe.clearOnRestart": boolean;
"pe.effectDuration": number;
"pe.emitters": {
"##name": string;
"emitter.data": {
"emitter.id": `${number}`;
"emitter.quality": string;
2024-01-02 13:31:34 -06:00
}[];
2025-10-11 21:22:48 -05:00
"emitter.position": Vector3Tuple;
"emitter.rotation": Vector4Tuple;
"emitter.scale": Vector3Tuple;
2024-01-02 13:31:34 -06:00
}[];
2025-10-11 21:22:48 -05:00
"pe.inheritScale": boolean;
"pe.nestedEmitters": boolean;
"pe.repeatsCount": number;
"pe.startFromTime": number;
"pe.stopWhenEmpty": boolean;
"pe.version": number;
"ro.flags": number;
2024-01-02 13:31:34 -06:00
}
| {
2025-10-11 21:22:48 -05:00
"comp.typename": "TankElementComponent";
2024-01-02 13:31:34 -06:00
isDestructible: boolean;
shouldCastShadow: boolean;
shouldGenerateSilhouette: boolean;
2024-01-02 14:50:46 -06:00
}
| {
2025-10-11 21:22:48 -05:00
"comp.typename": "MotionComponent";
"motion.filepath": string;
"motion.playbackRate": number;
"simpleMotion.repeatsCount": number;
2024-01-02 14:50:46 -06:00
}
| {
2025-10-11 21:22:48 -05:00
"comp.typename": "SkeletonComponent";
2024-01-02 14:50:46 -06:00
joints: Record<
string, // 0000, 0001, ...
{
2025-10-11 21:22:48 -05:00
"joint.bbox.max": Vector3Tuple;
"joint.bbox.min": Vector3Tuple;
"joint.bindPose": [
2024-01-02 14:50:46 -06:00
Vector4Tuple,
Vector4Tuple,
Vector4Tuple,
Vector4Tuple,
];
2025-10-11 21:22:48 -05:00
"joint.invBindPose": [
2024-01-02 14:50:46 -06:00
Vector4Tuple,
Vector4Tuple,
Vector4Tuple,
Vector4Tuple,
];
2025-10-11 21:22:48 -05:00
"joint.name": string;
"joint.parentIndex": number;
"joint.uid": string;
2024-01-02 14:50:46 -06:00
}
>;
jointsCount: number;
2024-01-19 23:33:27 -06:00
}
| {
2025-10-11 21:22:48 -05:00
"comp.typename": "AnimationComponent";
2024-01-19 23:33:27 -06:00
animation: bigint;
animationTimeScale: number;
repeatsCount: number;
2024-01-20 23:20:00 -06:00
}
| {
2025-10-11 21:22:48 -05:00
"comp.typename": "SkeletonJointBindingComponent";
2024-01-20 23:20:00 -06:00
count: number;
map: Record<
string, // 0000, 0001, ...
{
Uid: string;
jointUid: string;
}
>;
2023-12-29 19:56:50 -06:00
};
2023-12-18 16:28:15 -06:00
interface SceneComponents {
count: number;
}
2023-12-25 12:37:37 -06:00
2024-02-04 17:55:48 -06:00
export class Sc2ReadStream extends ScpgReadStream {
2023-12-25 12:37:37 -06:00
header() {
return {
2023-12-25 16:49:40 -06:00
name: this.ascii(4),
2023-12-25 12:37:37 -06:00
version: this.uint32(),
nodeCount: this.uint32(),
};
}
versionTags() {
return this.ka();
}
descriptor() {
const size = this.uint32();
const fileType = this.uint32();
// other felids that we don't have any info about
2024-02-07 10:34:13 -06:00
this.seek(size - 4);
2023-12-25 12:37:37 -06:00
return { size, fileType };
}
sc2() {
this.header();
this.versionTags();
this.descriptor();
return this.ka() as SC2;
}
}