Latest packet handling, parsing, enums, generators, etc..
This commit is contained in:
@@ -41,4 +41,102 @@ export class ScriptDialogPacket implements Packet
|
||||
return size;
|
||||
}
|
||||
|
||||
writeToBuffer(buf: Buffer, pos: number): number
|
||||
{
|
||||
const startPos = pos;
|
||||
this.Data['ObjectID'].writeToBuffer(buf, pos);
|
||||
pos += 16;
|
||||
buf.write(this.Data['FirstName'], pos);
|
||||
pos += this.Data['FirstName'].length;
|
||||
buf.write(this.Data['LastName'], pos);
|
||||
pos += this.Data['LastName'].length;
|
||||
buf.write(this.Data['ObjectName'], pos);
|
||||
pos += this.Data['ObjectName'].length;
|
||||
buf.write(this.Data['Message'], pos);
|
||||
pos += this.Data['Message'].length;
|
||||
buf.writeInt32LE(this.Data['ChatChannel'], pos);
|
||||
pos += 4;
|
||||
this.Data['ImageID'].writeToBuffer(buf, pos);
|
||||
pos += 16;
|
||||
let count = this.Buttons.length;
|
||||
buf.writeUInt8(this.Buttons.length, pos++);
|
||||
for (let i = 0; i < count; i++)
|
||||
{
|
||||
buf.write(this.Buttons[i]['ButtonLabel'], pos);
|
||||
pos += this.Buttons[i]['ButtonLabel'].length;
|
||||
}
|
||||
count = this.OwnerData.length;
|
||||
buf.writeUInt8(this.OwnerData.length, pos++);
|
||||
for (let i = 0; i < count; i++)
|
||||
{
|
||||
this.OwnerData[i]['OwnerID'].writeToBuffer(buf, pos);
|
||||
pos += 16;
|
||||
}
|
||||
return pos - startPos;
|
||||
}
|
||||
|
||||
readFromBuffer(buf: Buffer, pos: number): number
|
||||
{
|
||||
const startPos = pos;
|
||||
const newObjData: {
|
||||
ObjectID: UUID,
|
||||
FirstName: string,
|
||||
LastName: string,
|
||||
ObjectName: string,
|
||||
Message: string,
|
||||
ChatChannel: number,
|
||||
ImageID: UUID
|
||||
} = {
|
||||
ObjectID: UUID.zero(),
|
||||
FirstName: '',
|
||||
LastName: '',
|
||||
ObjectName: '',
|
||||
Message: '',
|
||||
ChatChannel: 0,
|
||||
ImageID: UUID.zero()
|
||||
};
|
||||
newObjData['ObjectID'] = new UUID(buf, pos);
|
||||
pos += 16;
|
||||
newObjData['FirstName'] = buf.toString('utf8', pos, length);
|
||||
pos += length;
|
||||
newObjData['LastName'] = buf.toString('utf8', pos, length);
|
||||
pos += length;
|
||||
newObjData['ObjectName'] = buf.toString('utf8', pos, length);
|
||||
pos += length;
|
||||
newObjData['Message'] = buf.toString('utf8', pos, length);
|
||||
pos += length;
|
||||
newObjData['ChatChannel'] = buf.readInt32LE(pos);
|
||||
pos += 4;
|
||||
newObjData['ImageID'] = new UUID(buf, pos);
|
||||
pos += 16;
|
||||
this.Data = newObjData;
|
||||
let count = buf.readUInt8(pos++);
|
||||
this.Buttons = [];
|
||||
for (let i = 0; i < count; i++)
|
||||
{
|
||||
const newObjButtons: {
|
||||
ButtonLabel: string
|
||||
} = {
|
||||
ButtonLabel: ''
|
||||
};
|
||||
newObjButtons['ButtonLabel'] = buf.toString('utf8', pos, length);
|
||||
pos += length;
|
||||
this.Buttons.push(newObjButtons);
|
||||
}
|
||||
count = buf.readUInt8(pos++);
|
||||
this.OwnerData = [];
|
||||
for (let i = 0; i < count; i++)
|
||||
{
|
||||
const newObjOwnerData: {
|
||||
OwnerID: UUID
|
||||
} = {
|
||||
OwnerID: UUID.zero()
|
||||
};
|
||||
newObjOwnerData['OwnerID'] = new UUID(buf, pos);
|
||||
pos += 16;
|
||||
this.OwnerData.push(newObjOwnerData);
|
||||
}
|
||||
return pos - startPos;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user