UNPKG

unreal.js

Version:

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

77 lines (76 loc) 2.6 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.FPackedRGBA16N = exports.FPackedNormal = void 0; const Game_1 = require("../../versions/Game"); const FVector_1 = require("../core/math/FVector"); /** A normal vector, quantized and packed into 32-bits. */ class FPackedNormal { constructor(Ar = null) { if (Ar != null) { this.data = Ar.readUInt32(); if (Ar.game >= Game_1.Game.GAME_UE4(20)) this.data = this.data ^ 0x80808080; } } serialize(Ar) { Ar.writeUInt32(Ar.game >= Game_1.Game.GAME_UE4(20) ? (this.data ^ 0x80808080) : this.data); } static fromVector(vector) { const packed = new FPackedNormal(); packed.data = (Math.floor((vector.x + 1) * 127.5) + (Math.floor((vector.y + 1) * 127.5) << 8) + (Math.floor((vector.z + 1) * 127.5)) << 16); return packed; } static fromNumber(data) { const packed = new FPackedNormal(); packed.data = data; return packed; } } exports.FPackedNormal = FPackedNormal; /** A vector, quantized and packed into 32-bits. */ class FPackedRGBA16N { constructor(Ar = null) { if (Ar != null) { this.x = Ar.readUInt16(); this.y = Ar.readUInt16(); this.z = Ar.readUInt16(); this.w = Ar.readUInt16(); if (Ar.game >= Game_1.Game.GAME_UE4(20)) { this.x = this.x ^ 0x8000; this.y = this.y ^ 0x8000; this.z = this.z ^ 0x8000; this.w = this.w ^ 0x8000; } } } serialize(Ar) { if (Ar.game >= Game_1.Game.GAME_UE4(20)) { Ar.writeUInt16(this.x ^ 0x8000); Ar.writeUInt16(this.y ^ 0x8000); Ar.writeUInt16(this.z ^ 0x8000); Ar.writeUInt16(this.w ^ 0x8000); } else { Ar.writeUInt16(this.x); Ar.writeUInt16(this.y); Ar.writeUInt16(this.z); Ar.writeUInt16(this.w); } } toPackedNormal() { return FPackedNormal.fromVector(new FVector_1.FVector((this.x - 32767.5) / 32767.5, (this.y - 32767.5) / 32767.5, (this.z - 32767.5) / 32767.5)); } static from(x, y, z, w) { const packed = new FPackedRGBA16N(); packed.x = x; packed.y = y; packed.z = z; packed.w = w; return packed; } } exports.FPackedRGBA16N = FPackedRGBA16N;