Can queue subpackets now (automatically creates basepacket). List packets implemented. Base packets fully figured out and implemented. Login has been stablized and no longer crashes. Implemented the following packets: List Packets, Set Job packet, chat message receive packet, SetActorIcon, SetActorIsZoning, SetActorSingleStatus, AchievementRate and some unknown packets.

This commit is contained in:
Filip Maj 2015-12-29 01:20:46 -05:00
parent 3a8d7a43e5
commit aeef4f5616
23 changed files with 581 additions and 223 deletions

View file

@ -18,8 +18,7 @@ namespace FFXIVClassic_Lobby_Server.packets
public ushort reserved;
public ushort packetSize;
public ushort numSubpackets;
public uint unknown1; //Id?
public uint unknown2; //Usually 0x13B
public ulong timestamp; //Miliseconds
}
public class BasePacket{
@ -46,8 +45,13 @@ namespace FFXIVClassic_Lobby_Server.packets
int packetSize = header.packetSize;
data = new byte[packetSize - BASEPACKET_SIZE];
Array.Copy(bytes, BASEPACKET_SIZE, data, 0, packetSize - BASEPACKET_SIZE);
if (packetSize - BASEPACKET_SIZE != 0)
{
data = new byte[packetSize - BASEPACKET_SIZE];
Array.Copy(bytes, BASEPACKET_SIZE, data, 0, packetSize - BASEPACKET_SIZE);
}
else
data = new byte[0];
}
//Loads a sniffed packet from a byte array
@ -155,7 +159,7 @@ namespace FFXIVClassic_Lobby_Server.packets
while (binreader.BaseStream.Position + 4 < data.Length)
{
uint read = binreader.ReadUInt32();
if (read == 0x029B2941) //Original ID
if (read == 0x029B2941 || read == 0x02977DC7 || read == 0x0297D2C8 || read == 0x0230d573 || read == 0x23317df || read == 0x23344a3) //Original ID
{
binWriter.BaseStream.Seek(binreader.BaseStream.Position - 0x4, SeekOrigin.Begin);
binWriter.Write(actorID);
@ -200,6 +204,7 @@ namespace FFXIVClassic_Lobby_Server.packets
header.isEncrypted = isEncrypted?(byte)1:(byte)0;
header.numSubpackets = (ushort)subpackets.Count;
header.packetSize = BASEPACKET_SIZE;
header.timestamp = Utils.MilisUnixTimeStampUTC();
//Get packet size
foreach (SubPacket subpacket in subpackets)
@ -232,6 +237,7 @@ namespace FFXIVClassic_Lobby_Server.packets
header.isEncrypted = isEncrypted ? (byte)1 : (byte)0;
header.numSubpackets = (ushort)1;
header.packetSize = BASEPACKET_SIZE;
header.timestamp = Utils.MilisUnixTimeStampUTC();
//Get packet size
header.packetSize += subpacket.header.subpacketSize;
@ -260,6 +266,7 @@ namespace FFXIVClassic_Lobby_Server.packets
header.isEncrypted = isEncrypted ? (byte)1 : (byte)0;
header.numSubpackets = (ushort)1;
header.packetSize = BASEPACKET_SIZE;
header.timestamp = Utils.MilisUnixTimeStampUTC();
//Get packet size
header.packetSize += (ushort)data.Length;

View file

@ -0,0 +1,45 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace FFXIVClassic_Map_Server.packets.receive
{
class ChatMessagePacket
{
public float posX;
public float posY;
public float posZ;
public float posRot;
public uint logType;
public string message;
public bool invalidPacket = false;
public ChatMessagePacket(byte[] data)
{
using (MemoryStream mem = new MemoryStream(data))
{
using (BinaryReader binReader = new BinaryReader(mem))
{
try{
binReader.ReadUInt64();
posX = binReader.ReadSingle();
posY = binReader.ReadSingle();
posZ = binReader.ReadSingle();
posRot = binReader.ReadSingle();
logType = binReader.ReadUInt32();
message = Encoding.ASCII.GetString(binReader.ReadBytes(0x200)).Trim(new [] { '\0' });
}
catch (Exception){
invalidPacket = true;
}
}
}
}
}
}

View file

@ -0,0 +1,35 @@
using FFXIVClassic_Lobby_Server.packets;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace FFXIVClassic_Map_Server.packets.send.actor
{
class SetActorIconPacket
{
public const uint DISCONNECTING = 0x00010000;
public const uint ISGM = 0x00020000;
public const uint ISAFK = 0x00000100;
public const ushort OPCODE = 0x0145;
public const uint PACKET_SIZE = 0x28;
public static SubPacket buildPacket(uint playerActorID, uint targetActorID, uint iconCode)
{
byte[] data = new byte[PACKET_SIZE - 0x20];
using (MemoryStream mem = new MemoryStream(data))
{
using (BinaryWriter binWriter = new BinaryWriter(mem))
{
binWriter.Write((UInt32)iconCode);
}
}
return new SubPacket(OPCODE, playerActorID, targetActorID, data);
}
}
}

View file

@ -0,0 +1,22 @@
using FFXIVClassic_Lobby_Server.packets;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace FFXIVClassic_Map_Server.packets.send.actor
{
class SetActorIsZoningPacket
{
public const ushort OPCODE = 0x017B;
public const uint PACKET_SIZE = 0x28;
public static SubPacket buildPacket(uint playerActorID, uint targetActorID, bool isDimmed)
{
byte[] data = new byte[PACKET_SIZE - 0x20];
data[0] = (byte)(isDimmed ? 1 : 0);
return new SubPacket(OPCODE, playerActorID, targetActorID, data);
}
}
}

View file

@ -36,7 +36,7 @@ namespace FFXIVClassic_Map_Server.packets.send.actor
using (BinaryWriter binWriter = new BinaryWriter(mem))
{
binWriter.Write((Int32)0);
binWriter.Write((Int32)sourceActorID);
binWriter.Write((Int32)0);
binWriter.Write((Single)x);
binWriter.Write((Single)y);
binWriter.Write((Single)z);

View file

@ -8,7 +8,7 @@ using System.Threading.Tasks;
namespace FFXIVClassic_Map_Server.packets.send.actor
{
class SetStatusPacket
class SetActorStatusAllPacket
{
public const ushort OPCODE = 0x0179;
public const uint PACKET_SIZE = 0x48;

View file

@ -0,0 +1,32 @@
using FFXIVClassic_Lobby_Server.packets;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace FFXIVClassic_Map_Server.packets.send.actor
{
class SetActorStatusPacket
{
public const ushort OPCODE = 0x0177;
public const uint PACKET_SIZE = 0x28;
public static SubPacket buildPacket(uint playerActorID, uint targetActorID, ushort index, ushort statusCode)
{
byte[] data = new byte[PACKET_SIZE - 0x20];
using (MemoryStream mem = new MemoryStream(data))
{
using (BinaryWriter binWriter = new BinaryWriter(mem))
{
binWriter.Write((UInt16)index);
binWriter.Write((UInt16)statusCode);
}
}
return new SubPacket(OPCODE, playerActorID, targetActorID, data);
}
}
}

View file

@ -0,0 +1,31 @@
using FFXIVClassic_Lobby_Server.packets;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace FFXIVClassic_Map_Server.packets.send.actor
{
class _0xFPacket
{
public const ushort OPCODE = 0x000F;
public const uint PACKET_SIZE = 0x38;
public static SubPacket buildPacket(uint playerActorID, uint targetActorID)
{
byte[] data = new byte[PACKET_SIZE - 0x20];
using (MemoryStream mem = new MemoryStream(data))
{
using (BinaryWriter binWriter = new BinaryWriter(mem))
{
}
}
return new SubPacket(OPCODE, playerActorID, targetActorID, data);
}
}
}

View file

@ -13,7 +13,7 @@ namespace FFXIVClassic_Map_Server.packets.send.list
public const ushort OPCODE = 0x017D;
public const uint PACKET_SIZE = 0x40;
public static SubPacket buildPacket(uint playerActorID, uint locationCode, ulong id, ulong listId, uint numEntries)
public static SubPacket buildPacket(uint playerActorID, uint locationCode, ulong sequenceId, ulong listId, int numEntries)
{
byte[] data = new byte[PACKET_SIZE - 0x20];
@ -23,7 +23,7 @@ namespace FFXIVClassic_Map_Server.packets.send.list
{
//Write List Header
binWriter.Write((UInt64)locationCode);
binWriter.Write((UInt64)id);
binWriter.Write((UInt64)sequenceId);
//Write List Info
binWriter.Write((UInt64)listId);
binWriter.Write((UInt32)numEntries);

View file

@ -1,6 +1,7 @@
using FFXIVClassic_Lobby_Server.packets;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
@ -10,11 +11,25 @@ namespace FFXIVClassic_Map_Server.packets.send.list
class ListEndPacket
{
public const ushort OPCODE = 0x017E;
public const uint PACKET_SIZE = 0x28;
public const uint PACKET_SIZE = 0x38;
public static SubPacket buildPacket(uint playerActorID, ulong listId)
public static SubPacket buildPacket(uint playerActorID, uint locationCode, ulong sequenceId, ulong listId)
{
return new SubPacket(OPCODE, 0, playerActorID, BitConverter.GetBytes(listId));
byte[] data = new byte[PACKET_SIZE - 0x20];
using (MemoryStream mem = new MemoryStream(data))
{
using (BinaryWriter binWriter = new BinaryWriter(mem))
{
//Write List Header
binWriter.Write((UInt64)locationCode);
binWriter.Write((UInt64)sequenceId);
//Write List Info
binWriter.Write((UInt64)listId);
}
}
return new SubPacket(OPCODE, playerActorID, playerActorID, data);
}
}

View file

@ -13,7 +13,7 @@ namespace FFXIVClassic_Map_Server.packets.send.list
public const ushort OPCODE = 0x017F;
public const uint PACKET_SIZE = 0x1B8;
public static SubPacket buildPacket(uint playerActorID, uint locationCode, uint id, uint numInPacket)
public static SubPacket buildPacket(uint playerActorID, uint locationCode, ulong sequenceId, List<ListEntry> entries, int offset)
{
byte[] data = new byte[PACKET_SIZE - 0x20];
@ -23,17 +23,25 @@ namespace FFXIVClassic_Map_Server.packets.send.list
{
//Write List Header
binWriter.Write((UInt64)locationCode);
binWriter.Write((UInt64)id);
binWriter.Write((UInt64)sequenceId);
//Write Entries
uint max = 8;
if (numInPacket < 8)
max = numInPacket;
int max = 8;
if (entries.Count-offset < 8)
max = entries.Count - offset;
for (int i = 0; i < max; i++)
{
binWriter.Seek(0x10 + (0x30 * i), SeekOrigin.Begin);
ListEntry entry = entries[i];
binWriter.Write((UInt32)entry.actorId);
binWriter.Write((UInt32)entry.unknown1);
binWriter.Write((UInt32)entry.unknown2);
binWriter.Write((Byte)(entry.flag1? 1 : 0));
binWriter.Write((Byte)(entry.isOnline? 1 : 0));
binWriter.Write(Encoding.ASCII.GetBytes(entry.name), 0, Encoding.ASCII.GetByteCount(entry.name) >= 0x20 ? 0x20 : Encoding.ASCII.GetByteCount(entry.name));
}
//Write Count
binWriter.Seek(0x30 * 8, SeekOrigin.Begin);
binWriter.Seek(0x10 + (0x30 * 8), SeekOrigin.Begin);
binWriter.Write(max);
}
}

View file

@ -0,0 +1,28 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace FFXIVClassic_Map_Server.packets.send.list
{
class ListEntry
{
public uint actorId;
public uint unknown1;
public uint unknown2;
public bool flag1;
public bool isOnline;
public string name;
public ListEntry(uint actorId, uint unknown1, uint unknown2, bool flag1, bool isOnline, string name)
{
this.actorId = actorId;
this.unknown1 = unknown1;
this.unknown2 = unknown2;
this.flag1 = flag1;
this.isOnline = isOnline;
this.name = name;
}
}
}

View file

@ -17,7 +17,7 @@ namespace FFXIVClassic_Map_Server.packets.send.list
public const ushort OPCODE = 0x017C;
public const uint PACKET_SIZE = 0x98;
public static SubPacket buildPacket(uint playerActorID, uint locationCode, ulong id, ulong listId, uint numEntries)
public static SubPacket buildPacket(uint playerActorID, uint locationCode, ulong sequenceId, ulong listId, uint listTypeId, int numEntries)
{
byte[] data = new byte[PACKET_SIZE - 0x20];
@ -27,11 +27,10 @@ namespace FFXIVClassic_Map_Server.packets.send.list
{
//Temp stuff
string name = "";
uint listTypeId = 0x4E22;
//Write list header
binWriter.Write((UInt64)locationCode);
binWriter.Write((UInt64)id);
binWriter.Write((UInt64)sequenceId);
//Write list id
binWriter.Write((UInt64)3);
@ -47,6 +46,8 @@ namespace FFXIVClassic_Map_Server.packets.send.list
binWriter.Write((UInt32)0xFFFFFFFF);
binWriter.Write(Encoding.ASCII.GetBytes(name), 0, Encoding.ASCII.GetByteCount(name) >= 0x20 ? 0x20 : Encoding.ASCII.GetByteCount(name));
binWriter.Seek(0x64, SeekOrigin.Begin);
binWriter.Write((UInt32)0x6D);
binWriter.Write((UInt32)0x6D);
binWriter.Write((UInt32)0x6D);

View file

@ -0,0 +1,44 @@
using FFXIVClassic_Lobby_Server.packets;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace FFXIVClassic_Map_Server.packets.send.list
{
class ListUtils
{
public static List<SubPacket> createList(uint actorId, uint locationCode, ulong sequenceId, ulong listId, uint listTypeId, List<ListEntry> listEntries)
{
List<SubPacket> subpacketList = new List<SubPacket>();
subpacketList.Add(ListStartPacket.buildPacket(actorId, locationCode, sequenceId, listId, listTypeId, listEntries.Count));
subpacketList.Add(ListBeginPacket.buildPacket(actorId, locationCode, sequenceId, listId, listEntries.Count));
subpacketList.Add(ListEntriesEndPacket.buildPacket(actorId, locationCode, sequenceId, listEntries, 0));
subpacketList.Add(ListEndPacket.buildPacket(actorId, locationCode, sequenceId, listId));
return subpacketList;
}
public static List<SubPacket> createRetainerList(uint actorId, uint locationCode, ulong sequenceId, ulong listId, List<ListEntry> listEntries)
{
List<SubPacket> subpacketList = new List<SubPacket>();
subpacketList.Add(ListStartPacket.buildPacket(actorId, locationCode, sequenceId, listId, ListStartPacket.TYPEID_RETAINER, listEntries.Count));
subpacketList.Add(ListBeginPacket.buildPacket(actorId, locationCode, sequenceId, listId, listEntries.Count));
subpacketList.Add(ListEntriesEndPacket.buildPacket(actorId, locationCode, sequenceId, listEntries, 0));
subpacketList.Add(ListEndPacket.buildPacket(actorId, locationCode, sequenceId, listId));
return subpacketList;
}
public static List<SubPacket> createPartyList(uint actorId, uint locationCode, ulong sequenceId, ulong listId, List<ListEntry> listEntries)
{
List<SubPacket> subpacketList = new List<SubPacket>();
subpacketList.Add(ListStartPacket.buildPacket(actorId, locationCode, sequenceId, listId, ListStartPacket.TYPEID_PARTY, listEntries.Count));
subpacketList.Add(ListBeginPacket.buildPacket(actorId, locationCode, sequenceId, listId, listEntries.Count));
subpacketList.Add(ListEntriesEndPacket.buildPacket(actorId, locationCode, sequenceId, listEntries, 0));
subpacketList.Add(ListEndPacket.buildPacket(actorId, locationCode, sequenceId, listId));
return subpacketList;
}
}
}

View file

@ -0,0 +1,41 @@
using FFXIVClassic_Lobby_Server.packets;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace FFXIVClassic_Map_Server.packets.send.login
{
class Login0x7ResponsePacket
{
public static BasePacket buildPacket(uint actorID, uint time)
{
byte[] data = new byte[0x18];
using (MemoryStream mem = new MemoryStream(data))
{
using (BinaryWriter binWriter = new BinaryWriter(mem))
{
try
{
binWriter.Write((short)0x18);
binWriter.Write((short)0x8);
binWriter.Write((uint)0);
binWriter.Write((uint)0);
binWriter.Write((uint)0xFFFFFD7F);
binWriter.Write((uint)actorID);
binWriter.Write((uint)time);
}
catch (Exception)
{
}
}
}
return BasePacket.createPacket(data, false, false);
}
}
}

View file

@ -0,0 +1,33 @@
using FFXIVClassic_Lobby_Server.packets;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace FFXIVClassic_Map_Server.packets.send.player
{
class SendAchievementRatePacket
{
public const ushort OPCODE = 0x019F;
public const uint PACKET_SIZE = 0x30;
public static SubPacket buildPacket(uint playerActorID, uint achievementId, uint progressCount, uint progressFlags)
{
byte[] data = new byte[PACKET_SIZE - 0x20];
using (MemoryStream mem = new MemoryStream(data))
{
using (BinaryWriter binWriter = new BinaryWriter(mem))
{
binWriter.Write((UInt32)achievementId);
binWriter.Write((UInt32)progressCount);
binWriter.Write((UInt32)progressFlags);
}
}
return new SubPacket(OPCODE, playerActorID, playerActorID, data);
}
}
}

View file

@ -0,0 +1,20 @@
using FFXIVClassic_Lobby_Server.packets;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace FFXIVClassic_Map_Server.packets.send.player
{
class SetCurrentJobPacket
{
public const ushort OPCODE = 0x01A4;
public const uint PACKET_SIZE = 0x28;
public static SubPacket buildPacket(uint sourceActorID, uint targetActorID, uint jobId)
{
return new SubPacket(OPCODE, sourceActorID, targetActorID, BitConverter.GetBytes((uint)jobId));
}
}
}

View file

@ -0,0 +1,32 @@
using FFXIVClassic_Lobby_Server.packets;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace FFXIVClassic_Map_Server.packets.send.player
{
class _0x196Packet
{
public const ushort OPCODE = 0x0196;
public const uint PACKET_SIZE = 0x38;
public static SubPacket buildPacket(uint playerActorID, uint targetActorID)
{
byte[] data = new byte[PACKET_SIZE - 0x20];
using (MemoryStream mem = new MemoryStream(data))
{
using (BinaryWriter binWriter = new BinaryWriter(mem))
{
binWriter.Seek(0xE, SeekOrigin.Begin);
binWriter.Write((Byte)0x01);
}
}
return new SubPacket(OPCODE, playerActorID, targetActorID, data);
}
}
}