You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
|
|
|
|
class Advancablebuffer {
|
|
|
|
|
readPos = 0;
|
|
|
|
|
internalBuffer;
|
|
|
|
|
littleEndian = true
|
|
|
|
|
|
|
|
|
|
constructor(buffer, useBigEndian)
|
|
|
|
|
{
|
|
|
|
|
this.internalBuffer = buffer;
|
|
|
|
|
this.readPos = 0;
|
|
|
|
|
this.littleEndian = !useBigEndian;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
seek(seekPos)
|
|
|
|
|
{
|
|
|
|
|
this.readPos = seekPos
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
readString(numBytes)
|
|
|
|
|
{
|
|
|
|
|
let t = this.internalBuffer.subarray(this.readPos, this.readPos+=numBytes);
|
|
|
|
|
return t.toString();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
readInt8()
|
|
|
|
|
{
|
|
|
|
|
let value = this.internalBuffer.readInt8(this.readPos);
|
|
|
|
|
this.readPos += 1;
|
|
|
|
|
return value;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
readUInt16()
|
|
|
|
|
{
|
|
|
|
|
let value = this.littleEndian ? this.internalBuffer.readUInt16LE(this.readPos) : this.internalBuffer.readUInt16BE(this.readPos);
|
|
|
|
|
this.readPos += 2;
|
|
|
|
|
return value;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
readUInt32()
|
|
|
|
|
{
|
|
|
|
|
let value = this.littleEndian ? this.internalBuffer.readUInt32LE(this.readPos) : this.internalBuffer.readUInt32BE(this.readPos);
|
|
|
|
|
this.readPos += 4;
|
|
|
|
|
return value;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
readBytes()
|
|
|
|
|
{
|
|
|
|
|
let length = this.readUInt32()
|
|
|
|
|
let sub = this.internalBuffer.subarray(this.readPos, this.readPos+=length);
|
|
|
|
|
return sub;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
readNadeoString()
|
|
|
|
|
{
|
|
|
|
|
let length = this.readUInt32()
|
|
|
|
|
if(length >= 0xFFFF)
|
|
|
|
|
{
|
|
|
|
|
return {read:-1, str:""};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (length == 0)
|
|
|
|
|
{
|
|
|
|
|
return {read:0, str:""};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
let outString = this.readString(length);
|
|
|
|
|
return {read:outString.length, str:outString};
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
module.exports = Advancablebuffer;
|