PSO2SERVER/Server/Protocol/Packets/08-SpawnPacket/08-04-CharacterSpawnPacket.cs

99 lines
3.3 KiB
C#
Raw Normal View History

2024-09-10 01:13:20 +08:00
using PSO2SERVER.Models;
2024-11-29 10:01:28 +08:00
using System.Runtime.InteropServices;
using static PSO2SERVER.Protocol.Packets.CharacterSpawnPacket;
2024-09-10 00:31:40 +08:00
namespace PSO2SERVER.Protocol.Packets
2024-09-10 00:31:40 +08:00
{
public class CharacterSpawnPacket : Packet
{
2024-11-30 16:18:27 +08:00
public enum CharacterSpawnType : byte
{
/// Spawned character is not related to the receiver.
Other = 0x27,
/// Spawned character is related to the receiver.
Myself = 0x2F,
Undefined = 0xFF,
}
2024-09-10 00:31:40 +08:00
private readonly Character _character;
2024-11-30 16:18:27 +08:00
public byte IsItMe = (byte)CharacterSpawnType.Myself;
2024-11-30 02:58:35 +08:00
public uint IsGM = 0;
2024-09-10 00:31:40 +08:00
public PSOLocation Position;
public CharacterSpawnPacket(Character character, PSOLocation locatiion)
{
_character = character;
Position = locatiion;
}
2024-11-30 02:58:35 +08:00
public CharacterSpawnPacket(Character character, PSOLocation locatiion, bool isme, uint isgm)
2024-09-10 00:31:40 +08:00
{
_character = character;
2024-11-30 16:18:27 +08:00
IsItMe = isme ? (byte)CharacterSpawnType.Myself : (byte)CharacterSpawnType.Other;
2024-09-10 00:31:40 +08:00
Position = locatiion;
2024-11-30 02:58:35 +08:00
IsGM = isgm;
2024-09-10 00:31:40 +08:00
}
#region implemented abstract members of Packet
public override byte[] Build()
{
var writer = new PacketWriter();
2024-09-20 21:58:37 +08:00
// Account header
2024-09-20 23:11:17 +08:00
writer.WriteAccountHeader((uint)_character.Account.AccountId);
2024-09-10 00:31:40 +08:00
// Spawn position
2024-09-21 09:23:14 +08:00
writer.WritePosition(Position);
2024-09-10 00:31:40 +08:00
2024-09-20 11:48:27 +08:00
writer.Write((ushort)0); // padding?
2024-09-10 00:31:40 +08:00
writer.WriteFixedLengthASCII("Character", 32);
2024-09-20 11:48:27 +08:00
writer.Write((ushort)1); // 0x44
writer.Write((ushort)0); // 0x46
writer.Write((uint)602); // 0x48
writer.Write((uint)1); // 0x4C
writer.Write((uint)53); // 0x50
2024-11-29 10:01:41 +08:00
writer.Write((uint)0); // 0x54
2024-11-29 10:01:28 +08:00
2024-11-30 16:18:27 +08:00
// Character spawn type.
writer.Write(IsItMe); // 0x58
writer.Write((byte)0x00);
writer.Write((ushort)0x00);
2024-11-30 17:01:09 +08:00
////writer.write((ushort)0x022f); // 0x5c
//writer.write((byte)0x2f); // 0x5c
//writer.write((byte)0x02);
////writer.write((ushort)0x0132); // 0x5e
//writer.write((byte)0x32);
//writer.write((byte)0x01);
2024-11-30 16:18:27 +08:00
// Character data.
2024-11-29 10:01:28 +08:00
writer.Write((uint)_character.AccountID); // player ID copy
writer.Write((uint)_character.CharacterID); // "char array ugggghhhhh" according to PolarisLegacy
2024-11-30 16:18:27 +08:00
writer.Write(_character.Unk1);//4
writer.Write(_character.VoiceType);//4
writer.Write(_character.Unk2);//2
writer.Write(_character.VoicePitch);//2
2024-09-10 00:31:40 +08:00
writer.WriteFixedLengthUtf16(_character.Name, 16);
writer.Write((uint)0); // 0x90
2024-09-10 00:31:40 +08:00
writer.WriteStruct(_character.Looks);
writer.WriteStruct(_character.Jobs);
2024-11-30 17:01:09 +08:00
writer.WriteFixedLengthUtf16(_character.Account.Nickname, 16); // Nickname, maybe not 16 chars?
2024-11-29 10:01:28 +08:00
2024-11-30 17:01:09 +08:00
writer.Write((uint)0); // 0x204
writer.Write(IsGM); // gmflag?
for (var i = 0; i < 60; i++)
writer.Write((byte)0);
2024-09-10 00:31:40 +08:00
return writer.ToArray();
}
public override PacketHeader GetHeader()
{
2024-09-21 12:35:09 +08:00
return new PacketHeader(0x08, 0x04, PacketFlags.None);
2024-09-10 00:31:40 +08:00
}
#endregion
}
}