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

119 lines
4.0 KiB
C#
Raw Normal View History

2024-12-08 11:33:06 +08:00
using Newtonsoft.Json;
using PSO2SERVER.Database;
2024-12-02 20:43:28 +08:00
using PSO2SERVER.Models;
2024-12-03 18:17:43 +08:00
using PSO2SERVER.Zone;
2024-12-07 17:14:04 +08:00
using System.IO;
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-12-06 23:40:36 +08:00
//private readonly Character _character;
//public byte IsItMe = (byte)CharacterSpawnType.Myself;
//public uint IsGM = 0;
/// <summary>
/// CharacterSpawnPacket Struct
/// </summary>
/// Spawned character's player object.
2024-12-08 11:33:06 +08:00
[JsonProperty("object")]
2024-12-07 14:55:20 +08:00
public ObjectHeader ObjHeader { get; set; } = new ObjectHeader();
2024-12-08 11:33:06 +08:00
[JsonProperty("position")]
2024-12-07 14:55:20 +08:00
public PSOLocation ObjPosition { get; set; } = new PSOLocation();
2024-12-08 11:33:06 +08:00
[JsonProperty("unk1")]
2024-12-07 14:55:20 +08:00
public ushort Unk1 { get; set; } = 0;
2024-12-08 11:33:06 +08:00
/// Enemy name.
[JsonProperty("name")]
2024-12-07 17:14:04 +08:00
public string ObjName { get; set; } = "Character";//Ascii 0x20
2024-12-07 14:55:20 +08:00
public ushort Unk3 { get; set; } = 1;
public ushort Unk4 { get; set; }
public uint Unk5 { get; set; }
public uint Unk6 { get; set; }
public uint Unk7 { get; set; }
public uint Unk8 { get; set; }
2024-12-07 17:14:04 +08:00
/// Character spawn type.
2024-12-07 14:55:20 +08:00
public CharacterSpawnType SpawnType { get; set; }
public byte Unk9 { get; set; }
public ushort Unk10 { get; set; }
2024-12-07 17:14:04 +08:00
/// Character data.
2024-12-07 14:55:20 +08:00
public Character Character { get; set; }
public uint Unk11 { get; set; }
2024-12-06 23:40:36 +08:00
/// Set to `1` if the player is a GM.
2024-12-07 14:55:20 +08:00
public uint GmFlag { get; set; }
2024-12-07 17:14:04 +08:00
/// Player's nickname.
public string Nickname { get; set; }//0x10
2024-12-06 23:40:36 +08:00
//#[SeekAfter(0x60)]
2024-12-07 14:55:20 +08:00
public byte[] Unk12 { get; set; } = new byte[0x40];
2024-09-10 00:31:40 +08:00
2024-12-08 11:33:06 +08:00
public CharacterSpawnPacket()
{
}
2024-09-10 00:31:40 +08:00
public CharacterSpawnPacket(Character character, PSOLocation locatiion)
{
2024-12-07 14:55:20 +08:00
ObjHeader = new ObjectHeader((uint)character.Account.AccountId, ObjectType.Player);
ObjPosition = locatiion;
2024-12-07 17:14:04 +08:00
Character = character;
2024-09-10 00:31:40 +08:00
}
2024-12-06 21:49:29 +08:00
public CharacterSpawnPacket(Character character, PSOLocation locatiion, bool isme, bool isgm)
2024-09-10 00:31:40 +08:00
{
2024-12-07 14:55:20 +08:00
ObjHeader = new ObjectHeader((uint)character.Account.AccountId, ObjectType.Player);
2024-12-07 17:14:04 +08:00
ObjPosition = locatiion;
2024-12-07 14:55:20 +08:00
Character = character;
SpawnType = isme ? CharacterSpawnType.Myself : CharacterSpawnType.Other;
GmFlag = isgm ? (uint)1 : 0;
2024-09-10 00:31:40 +08:00
}
#region implemented abstract members of Packet
public override byte[] Build()
{
2024-12-06 23:40:36 +08:00
var pkt = new PacketWriter();
// Accounts header
pkt.WriteObjectHeader(ObjHeader);
2024-09-10 00:31:40 +08:00
// Spawn position
2024-12-07 14:55:20 +08:00
pkt.WritePosition(ObjPosition);
pkt.Write(Unk1);
pkt.WriteFixedLengthASCII(ObjName, 0x20);
pkt.Write(Unk3); // 0x44
pkt.Write(Unk4);
pkt.Write(Unk5);
pkt.Write(Unk6);
pkt.Write(Unk7);
pkt.Write(Unk8);
pkt.Write((byte)SpawnType);
pkt.Write(Unk9);
pkt.Write(Unk10);
2024-11-30 16:18:27 +08:00
// Character data.
2024-12-07 14:55:20 +08:00
pkt.Write(Character.BuildCharacterByteArray());
pkt.Write(Unk11);
pkt.Write(GmFlag);
pkt.WriteFixedLengthUtf16(Character.Account.Nickname, 0x10);
2024-12-07 17:14:04 +08:00
pkt.BaseStream.Seek(0x60, SeekOrigin.Current);
pkt.Write(Unk12);
2024-12-02 20:43:28 +08:00
2024-12-06 23:40:36 +08:00
return pkt.ToArray();
2024-09-10 00:31:40 +08:00
}
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
}
}