Latest packet handling, parsing, enums, generators, etc..
This commit is contained in:
@@ -80,4 +80,286 @@ export class ObjectUpdatePacket implements Packet
|
||||
return size;
|
||||
}
|
||||
|
||||
writeToBuffer(buf: Buffer, pos: number): number
|
||||
{
|
||||
const startPos = pos;
|
||||
buf.writeInt32LE(this.RegionData['RegionHandle'].low, pos);
|
||||
pos += 4;
|
||||
buf.writeInt32LE(this.RegionData['RegionHandle'].high, pos);
|
||||
pos += 4;
|
||||
buf.writeUInt16LE(this.RegionData['TimeDilation'], pos);
|
||||
pos += 2;
|
||||
const count = this.ObjectData.length;
|
||||
buf.writeUInt8(this.ObjectData.length, pos++);
|
||||
for (let i = 0; i < count; i++)
|
||||
{
|
||||
buf.writeUInt32LE(this.ObjectData[i]['ID'], pos);
|
||||
pos += 4;
|
||||
buf.writeUInt8(this.ObjectData[i]['State'], pos++);
|
||||
this.ObjectData[i]['FullID'].writeToBuffer(buf, pos);
|
||||
pos += 16;
|
||||
buf.writeUInt32LE(this.ObjectData[i]['CRC'], pos);
|
||||
pos += 4;
|
||||
buf.writeUInt8(this.ObjectData[i]['PCode'], pos++);
|
||||
buf.writeUInt8(this.ObjectData[i]['Material'], pos++);
|
||||
buf.writeUInt8(this.ObjectData[i]['ClickAction'], pos++);
|
||||
this.ObjectData[i]['Scale'].writeToBuffer(buf, pos, false);
|
||||
pos += 12;
|
||||
buf.write(this.ObjectData[i]['ObjectData'], pos);
|
||||
pos += this.ObjectData[i]['ObjectData'].length;
|
||||
buf.writeUInt32LE(this.ObjectData[i]['ParentID'], pos);
|
||||
pos += 4;
|
||||
buf.writeUInt32LE(this.ObjectData[i]['UpdateFlags'], pos);
|
||||
pos += 4;
|
||||
buf.writeUInt8(this.ObjectData[i]['PathCurve'], pos++);
|
||||
buf.writeUInt8(this.ObjectData[i]['ProfileCurve'], pos++);
|
||||
buf.writeUInt16LE(this.ObjectData[i]['PathBegin'], pos);
|
||||
pos += 2;
|
||||
buf.writeUInt16LE(this.ObjectData[i]['PathEnd'], pos);
|
||||
pos += 2;
|
||||
buf.writeUInt8(this.ObjectData[i]['PathScaleX'], pos++);
|
||||
buf.writeUInt8(this.ObjectData[i]['PathScaleY'], pos++);
|
||||
buf.writeUInt8(this.ObjectData[i]['PathShearX'], pos++);
|
||||
buf.writeUInt8(this.ObjectData[i]['PathShearY'], pos++);
|
||||
buf.writeInt8(this.ObjectData[i]['PathTwist'], pos++);
|
||||
buf.writeInt8(this.ObjectData[i]['PathTwistBegin'], pos++);
|
||||
buf.writeInt8(this.ObjectData[i]['PathRadiusOffset'], pos++);
|
||||
buf.writeInt8(this.ObjectData[i]['PathTaperX'], pos++);
|
||||
buf.writeInt8(this.ObjectData[i]['PathTaperY'], pos++);
|
||||
buf.writeUInt8(this.ObjectData[i]['PathRevolutions'], pos++);
|
||||
buf.writeInt8(this.ObjectData[i]['PathSkew'], pos++);
|
||||
buf.writeUInt16LE(this.ObjectData[i]['ProfileBegin'], pos);
|
||||
pos += 2;
|
||||
buf.writeUInt16LE(this.ObjectData[i]['ProfileEnd'], pos);
|
||||
pos += 2;
|
||||
buf.writeUInt16LE(this.ObjectData[i]['ProfileHollow'], pos);
|
||||
pos += 2;
|
||||
buf.write(this.ObjectData[i]['TextureEntry'], pos);
|
||||
pos += this.ObjectData[i]['TextureEntry'].length;
|
||||
buf.write(this.ObjectData[i]['TextureAnim'], pos);
|
||||
pos += this.ObjectData[i]['TextureAnim'].length;
|
||||
buf.write(this.ObjectData[i]['NameValue'], pos);
|
||||
pos += this.ObjectData[i]['NameValue'].length;
|
||||
buf.write(this.ObjectData[i]['Data'], pos);
|
||||
pos += this.ObjectData[i]['Data'].length;
|
||||
buf.write(this.ObjectData[i]['Text'], pos);
|
||||
pos += this.ObjectData[i]['Text'].length;
|
||||
this.ObjectData[i]['TextColor'].copy(buf, pos);
|
||||
pos += 4;
|
||||
buf.write(this.ObjectData[i]['MediaURL'], pos);
|
||||
pos += this.ObjectData[i]['MediaURL'].length;
|
||||
buf.write(this.ObjectData[i]['PSBlock'], pos);
|
||||
pos += this.ObjectData[i]['PSBlock'].length;
|
||||
buf.write(this.ObjectData[i]['ExtraParams'], pos);
|
||||
pos += this.ObjectData[i]['ExtraParams'].length;
|
||||
this.ObjectData[i]['Sound'].writeToBuffer(buf, pos);
|
||||
pos += 16;
|
||||
this.ObjectData[i]['OwnerID'].writeToBuffer(buf, pos);
|
||||
pos += 16;
|
||||
buf.writeFloatLE(this.ObjectData[i]['Gain'], pos);
|
||||
pos += 4;
|
||||
buf.writeUInt8(this.ObjectData[i]['Flags'], pos++);
|
||||
buf.writeFloatLE(this.ObjectData[i]['Radius'], pos);
|
||||
pos += 4;
|
||||
buf.writeUInt8(this.ObjectData[i]['JointType'], pos++);
|
||||
this.ObjectData[i]['JointPivot'].writeToBuffer(buf, pos, false);
|
||||
pos += 12;
|
||||
this.ObjectData[i]['JointAxisOrAnchor'].writeToBuffer(buf, pos, false);
|
||||
pos += 12;
|
||||
}
|
||||
return pos - startPos;
|
||||
}
|
||||
|
||||
readFromBuffer(buf: Buffer, pos: number): number
|
||||
{
|
||||
const startPos = pos;
|
||||
const newObjRegionData: {
|
||||
RegionHandle: Long,
|
||||
TimeDilation: number
|
||||
} = {
|
||||
RegionHandle: Long.ZERO,
|
||||
TimeDilation: 0
|
||||
};
|
||||
newObjRegionData['RegionHandle'] = new Long(buf.readInt32LE(pos), buf.readInt32LE(pos+4));
|
||||
pos += 8;
|
||||
newObjRegionData['TimeDilation'] = buf.readUInt16LE(pos);
|
||||
pos += 2;
|
||||
this.RegionData = newObjRegionData;
|
||||
const count = buf.readUInt8(pos++);
|
||||
this.ObjectData = [];
|
||||
for (let i = 0; i < count; i++)
|
||||
{
|
||||
const newObjObjectData: {
|
||||
ID: number,
|
||||
State: number,
|
||||
FullID: UUID,
|
||||
CRC: number,
|
||||
PCode: number,
|
||||
Material: number,
|
||||
ClickAction: number,
|
||||
Scale: Vector3,
|
||||
ObjectData: string,
|
||||
ParentID: number,
|
||||
UpdateFlags: number,
|
||||
PathCurve: number,
|
||||
ProfileCurve: number,
|
||||
PathBegin: number,
|
||||
PathEnd: number,
|
||||
PathScaleX: number,
|
||||
PathScaleY: number,
|
||||
PathShearX: number,
|
||||
PathShearY: number,
|
||||
PathTwist: number,
|
||||
PathTwistBegin: number,
|
||||
PathRadiusOffset: number,
|
||||
PathTaperX: number,
|
||||
PathTaperY: number,
|
||||
PathRevolutions: number,
|
||||
PathSkew: number,
|
||||
ProfileBegin: number,
|
||||
ProfileEnd: number,
|
||||
ProfileHollow: number,
|
||||
TextureEntry: string,
|
||||
TextureAnim: string,
|
||||
NameValue: string,
|
||||
Data: string,
|
||||
Text: string,
|
||||
TextColor: Buffer,
|
||||
MediaURL: string,
|
||||
PSBlock: string,
|
||||
ExtraParams: string,
|
||||
Sound: UUID,
|
||||
OwnerID: UUID,
|
||||
Gain: number,
|
||||
Flags: number,
|
||||
Radius: number,
|
||||
JointType: number,
|
||||
JointPivot: Vector3,
|
||||
JointAxisOrAnchor: Vector3
|
||||
} = {
|
||||
ID: 0,
|
||||
State: 0,
|
||||
FullID: UUID.zero(),
|
||||
CRC: 0,
|
||||
PCode: 0,
|
||||
Material: 0,
|
||||
ClickAction: 0,
|
||||
Scale: Vector3.getZero(),
|
||||
ObjectData: '',
|
||||
ParentID: 0,
|
||||
UpdateFlags: 0,
|
||||
PathCurve: 0,
|
||||
ProfileCurve: 0,
|
||||
PathBegin: 0,
|
||||
PathEnd: 0,
|
||||
PathScaleX: 0,
|
||||
PathScaleY: 0,
|
||||
PathShearX: 0,
|
||||
PathShearY: 0,
|
||||
PathTwist: 0,
|
||||
PathTwistBegin: 0,
|
||||
PathRadiusOffset: 0,
|
||||
PathTaperX: 0,
|
||||
PathTaperY: 0,
|
||||
PathRevolutions: 0,
|
||||
PathSkew: 0,
|
||||
ProfileBegin: 0,
|
||||
ProfileEnd: 0,
|
||||
ProfileHollow: 0,
|
||||
TextureEntry: '',
|
||||
TextureAnim: '',
|
||||
NameValue: '',
|
||||
Data: '',
|
||||
Text: '',
|
||||
TextColor: Buffer.allocUnsafe(0),
|
||||
MediaURL: '',
|
||||
PSBlock: '',
|
||||
ExtraParams: '',
|
||||
Sound: UUID.zero(),
|
||||
OwnerID: UUID.zero(),
|
||||
Gain: 0,
|
||||
Flags: 0,
|
||||
Radius: 0,
|
||||
JointType: 0,
|
||||
JointPivot: Vector3.getZero(),
|
||||
JointAxisOrAnchor: Vector3.getZero()
|
||||
};
|
||||
newObjObjectData['ID'] = buf.readUInt32LE(pos);
|
||||
pos += 4;
|
||||
newObjObjectData['State'] = buf.readUInt8(pos++);
|
||||
newObjObjectData['FullID'] = new UUID(buf, pos);
|
||||
pos += 16;
|
||||
newObjObjectData['CRC'] = buf.readUInt32LE(pos);
|
||||
pos += 4;
|
||||
newObjObjectData['PCode'] = buf.readUInt8(pos++);
|
||||
newObjObjectData['Material'] = buf.readUInt8(pos++);
|
||||
newObjObjectData['ClickAction'] = buf.readUInt8(pos++);
|
||||
newObjObjectData['Scale'] = new Vector3(buf, pos, false);
|
||||
pos += 12;
|
||||
newObjObjectData['ObjectData'] = buf.toString('utf8', pos, length);
|
||||
pos += length;
|
||||
newObjObjectData['ParentID'] = buf.readUInt32LE(pos);
|
||||
pos += 4;
|
||||
newObjObjectData['UpdateFlags'] = buf.readUInt32LE(pos);
|
||||
pos += 4;
|
||||
newObjObjectData['PathCurve'] = buf.readUInt8(pos++);
|
||||
newObjObjectData['ProfileCurve'] = buf.readUInt8(pos++);
|
||||
newObjObjectData['PathBegin'] = buf.readUInt16LE(pos);
|
||||
pos += 2;
|
||||
newObjObjectData['PathEnd'] = buf.readUInt16LE(pos);
|
||||
pos += 2;
|
||||
newObjObjectData['PathScaleX'] = buf.readUInt8(pos++);
|
||||
newObjObjectData['PathScaleY'] = buf.readUInt8(pos++);
|
||||
newObjObjectData['PathShearX'] = buf.readUInt8(pos++);
|
||||
newObjObjectData['PathShearY'] = buf.readUInt8(pos++);
|
||||
newObjObjectData['PathTwist'] = buf.readInt8(pos++);
|
||||
newObjObjectData['PathTwistBegin'] = buf.readInt8(pos++);
|
||||
newObjObjectData['PathRadiusOffset'] = buf.readInt8(pos++);
|
||||
newObjObjectData['PathTaperX'] = buf.readInt8(pos++);
|
||||
newObjObjectData['PathTaperY'] = buf.readInt8(pos++);
|
||||
newObjObjectData['PathRevolutions'] = buf.readUInt8(pos++);
|
||||
newObjObjectData['PathSkew'] = buf.readInt8(pos++);
|
||||
newObjObjectData['ProfileBegin'] = buf.readUInt16LE(pos);
|
||||
pos += 2;
|
||||
newObjObjectData['ProfileEnd'] = buf.readUInt16LE(pos);
|
||||
pos += 2;
|
||||
newObjObjectData['ProfileHollow'] = buf.readUInt16LE(pos);
|
||||
pos += 2;
|
||||
newObjObjectData['TextureEntry'] = buf.toString('utf8', pos, length);
|
||||
pos += length;
|
||||
newObjObjectData['TextureAnim'] = buf.toString('utf8', pos, length);
|
||||
pos += length;
|
||||
newObjObjectData['NameValue'] = buf.toString('utf8', pos, length);
|
||||
pos += length;
|
||||
newObjObjectData['Data'] = buf.toString('utf8', pos, length);
|
||||
pos += length;
|
||||
newObjObjectData['Text'] = buf.toString('utf8', pos, length);
|
||||
pos += length;
|
||||
newObjObjectData['TextColor'] = buf.slice(pos, pos + 4);
|
||||
pos += 4;
|
||||
newObjObjectData['MediaURL'] = buf.toString('utf8', pos, length);
|
||||
pos += length;
|
||||
newObjObjectData['PSBlock'] = buf.toString('utf8', pos, length);
|
||||
pos += length;
|
||||
newObjObjectData['ExtraParams'] = buf.toString('utf8', pos, length);
|
||||
pos += length;
|
||||
newObjObjectData['Sound'] = new UUID(buf, pos);
|
||||
pos += 16;
|
||||
newObjObjectData['OwnerID'] = new UUID(buf, pos);
|
||||
pos += 16;
|
||||
newObjObjectData['Gain'] = buf.readFloatLE(pos);
|
||||
pos += 4;
|
||||
newObjObjectData['Flags'] = buf.readUInt8(pos++);
|
||||
newObjObjectData['Radius'] = buf.readFloatLE(pos);
|
||||
pos += 4;
|
||||
newObjObjectData['JointType'] = buf.readUInt8(pos++);
|
||||
newObjObjectData['JointPivot'] = new Vector3(buf, pos, false);
|
||||
pos += 12;
|
||||
newObjObjectData['JointAxisOrAnchor'] = new Vector3(buf, pos, false);
|
||||
pos += 12;
|
||||
this.ObjectData.push(newObjObjectData);
|
||||
}
|
||||
return pos - startPos;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user