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

111 lines
3.6 KiB
C#
Raw Normal View History

2024-12-02 20:43:28 +08:00
using PSO2SERVER.Database;
using PSO2SERVER.Models;
2024-11-29 10:01:28 +08:00
using System.Runtime.InteropServices;
2024-12-02 20:43:28 +08:00
using static PSO2SERVER.Models.CharacterStruct;
2024-11-29 10:01:28 +08:00
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();
// Accounts 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-12-02 20:43:28 +08:00
writer.Write((ushort)0);
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-12-02 20:43:28 +08:00
writer.Write((uint)_character.AccountID);
writer.Write((uint)_character.CharacterID);
writer.Write((uint)_character.Unk1);//4
writer.Write((uint)_character.VoiceType);//4
writer.Write((ushort)_character.Unk2);//2
2024-11-30 16:18:27 +08:00
writer.Write(_character.VoicePitch);//2
2024-09-10 00:31:40 +08:00
writer.WriteFixedLengthUtf16(_character.Name, 16);
2024-12-02 20:43:28 +08:00
writer.Write((uint)_character.Unk3); // 0x90
2024-09-10 00:31:40 +08:00
writer.WriteStruct(_character.Looks);
2024-12-02 20:43:28 +08:00
JobParam jobParam = _character.Jobs;
jobParam.mainClass = ClassType.Luster;
jobParam.subClass = ClassType.Phantom;
jobParam.entries.Luster.level = 100;
writer.WriteStruct(jobParam);
writer.WriteFixedLengthUtf16(_character.Account.Nickname, 16);
writer.WriteBytes(0, 116);
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?
2024-12-02 20:43:28 +08:00
for (var i = 0; i < 0x60; i++)
2024-11-30 17:01:09 +08:00
writer.Write((byte)0);
2024-09-10 00:31:40 +08:00
2024-12-02 20:43:28 +08:00
//for (var i = 0; i < 0x40; 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
}
}