UNPKG

unreal.js

Version:

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

110 lines (109 loc) 3.3 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.FArchiveWriter = void 0; const Exceptions_1 = require("../../exceptions/Exceptions"); const VersionContainer_1 = require("../versions/VersionContainer"); class FArchiveWriter { constructor() { this.versions = VersionContainer_1.VersionContainer.DEFAULT; } get game() { return this.versions.game; } set game(v) { this.versions.game = v; } get ver() { return this.versions.ver; } set ver(v) { this.versions.ver = v; } writeInt8(i) { const bf = Buffer.alloc(1); bf.writeInt8(i); this.write(bf); } writeUInt8(i) { const bf = Buffer.alloc(1); bf.writeUInt8(i); this.write(bf); } writeInt16(i) { const bf = Buffer.alloc(2); this.littleEndian ? bf.writeInt16LE(i) : bf.writeInt16BE(i); this.write(bf); } writeUInt16(i) { const bf = Buffer.alloc(2); this.littleEndian ? bf.writeUInt16LE(i) : bf.writeUInt16BE(i); this.write(bf); } writeInt32(i) { const bf = Buffer.alloc(4); this.littleEndian ? bf.writeInt32LE(i) : bf.writeInt32BE(i); this.write(bf); } writeUInt32(i) { const bf = Buffer.alloc(4); this.littleEndian ? bf.writeUInt32LE(i) : bf.writeUInt32BE(i); this.write(bf); } writeInt64(i) { const bf = Buffer.alloc(8); i = typeof i === "number" ? BigInt(i) : i; this.littleEndian ? bf.writeBigInt64LE(i) : bf.writeBigInt64BE(i); this.write(bf); } writeUInt64(i) { const bf = Buffer.alloc(8); i = typeof i === "number" ? BigInt(i) : i; this.littleEndian ? bf.writeBigUInt64LE(i) : bf.writeBigUInt64BE(i); this.write(bf); } writeFloat32(i) { const bf = Buffer.alloc(4); this.littleEndian ? bf.writeFloatLE(i) : bf.writeFloatBE(i); this.write(bf); } writeDouble(i) { const bf = Buffer.alloc(8); this.littleEndian ? bf.writeDoubleLE(i) : bf.writeDoubleBE(i); this.write(bf); } writeBoolean(i) { i ? this.writeInt32(1) : this.writeInt32(0); } writeFlag(i) { i ? this.writeInt8(1) : this.writeInt8(0); } writeString(i) { if (i.length < -65536 || i.length > 65536) throw new Exceptions_1.ParserException(`Invalid String length '${i.length}'`, this); if (i) { this.writeInt32(i.length + 1); this.write(Buffer.from(i)); this.writeInt8(0); } else { this.writeInt32(0); } } writeFName(name) { } writeTMapWithoutSize(map, write) { map.forEach((v, k) => write(k, v)); } writeTMap(map, write) { this.writeInt32(map.size); this.writeTMapWithoutSize(map, write); } writeTArrayWithoutSize(array, write) { array.forEach((v) => write(v)); } writeTArray(array, write) { this.writeInt32(array.length); this.writeTArrayWithoutSize(array, write); } } exports.FArchiveWriter = FArchiveWriter;