UNPKG

unreal.js

Version:

A pak reader for games like VALORANT & Fortnite written in Node.JS

49 lines (48 loc) 2.21 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.UScriptMap = void 0; const FProperty_1 = require("../../assets/objects/FProperty"); const FAssetArchive_1 = require("../../assets/reader/FAssetArchive"); const Exceptions_1 = require("../../../exceptions/Exceptions"); const UnrealMap_1 = require("../../../util/UnrealMap"); class UScriptMap { constructor(x, y) { if (x instanceof FAssetArchive_1.FAssetArchive) { const numKeysToRemove = x.readInt32(); this.numKeysToRemove = new Array(numKeysToRemove); for (let i = 0; i < numKeysToRemove; ++i) { this.numKeysToRemove[i] = FProperty_1.FProperty.readPropertyValue(x, y.innerType, FProperty_1.ReadType.MAP); } const length = x.readInt32(); this.mapData = new UnrealMap_1.UnrealMap(); for (let i = 0; i < length; ++i) { let isReadingValue = false; try { const key = FProperty_1.FProperty.readPropertyValue(x, y.innerType, FProperty_1.ReadType.MAP); isReadingValue = true; const value = FProperty_1.FProperty.readPropertyValue(x, y.valueType, FProperty_1.ReadType.MAP); this.mapData.set(key, value); } catch (e) { throw new Exceptions_1.ParserException(`Failed to read ${isReadingValue ? "value" : "key"} for index ${i} in map`, x); } } } else { this.numKeysToRemove = x; this.mapData = y; } } serialize(Ar) { Ar.writeInt32(this.numKeysToRemove.length); this.numKeysToRemove.forEach((k) => { FProperty_1.FProperty.writePropertyValue(Ar, k, FProperty_1.ReadType.MAP); }); Ar.writeInt32(this.mapData.size); this.mapData.forEach((v, k) => { FProperty_1.FProperty.writePropertyValue(Ar, k, FProperty_1.ReadType.MAP); FProperty_1.FProperty.writePropertyValue(Ar, v, FProperty_1.ReadType.MAP); }); } } exports.UScriptMap = UScriptMap;