Added all the inventory packets, and implemented add and get inventory from the db to the server. Inventory at login is now connected to the db!

This commit is contained in:
Filip Maj 2016-02-11 22:14:40 -05:00
parent c4dea467e3
commit df2ac1fb32
23 changed files with 1227 additions and 160 deletions

View file

@ -8,7 +8,7 @@ using System.Threading.Tasks;
namespace FFXIVClassic_Map_Server.packets.send.Actor.inventory
{
class EquipmentChangePacket
class EquipmentListX01Packet
{
public const ushort OPCODE = 0x014D;
public const uint PACKET_SIZE = 0x28;

View file

@ -8,9 +8,9 @@ using System.Threading.Tasks;
namespace FFXIVClassic_Map_Server.packets.send.Actor.inventory
{
class EquipmentSetupPacket
class EquipmentListX08Packet
{
public const ushort OPCODE = 0x014E;
public const ushort OPCODE = 0x14E;
public const uint PACKET_SIZE = 0x58;
public const uint UNEQUIPPED = 0xFFFFFFFF;
@ -36,7 +36,7 @@ namespace FFXIVClassic_Map_Server.packets.send.Actor.inventory
private uint[] equipment = new uint[0x17];
public EquipmentSetupPacket()
public EquipmentListX08Packet()
{
for (int i = 0; i < equipment.Length; i++)
equipment[i] = UNEQUIPPED; //We will use this as "Unequipped"

View file

@ -0,0 +1,98 @@
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.inventory
{
class EquipmentListX16Packet
{
public const ushort OPCODE = 0x14F;
public const uint PACKET_SIZE = 0x80;
public const uint UNEQUIPPED = 0xFFFFFFFF;
public const int SLOT_MAINHAND = 0x00;
public const int SLOT_OFFHAND = 0x01;
public const int SLOT_THROWINGWEAPON = 0x04;
public const int SLOT_PACK = 0x05;
public const int SLOT_POUCH = 0x06;
public const int SLOT_HEAD = 0x08;
public const int SLOT_UNDERSHIRT = 0x09;
public const int SLOT_BODY = 0x0A;
public const int SLOT_UNDERGARMENT = 0x0B;
public const int SLOT_LEGS = 0x0C;
public const int SLOT_HANDS = 0x0D;
public const int SLOT_BOOTS = 0x0E;
public const int SLOT_WAIST = 0x0F;
public const int SLOT_NECK = 0x10;
public const int SLOT_EARS = 0x11;
public const int SLOT_WRISTS = 0x13;
public const int SLOT_RIGHTFINGER = 0x15;
public const int SLOT_LEFTFINGER = 0x16;
private uint[] equipment = new uint[0x17];
public EquipmentListX16Packet()
{
for (int i = 0; i < equipment.Length; i++)
equipment[i] = UNEQUIPPED; //We will use this as "Unequipped"
}
public void setItem(int slot, uint itemSlot)
{
if (slot >= equipment.Length)
return;
equipment[slot] = itemSlot;
}
public List<SubPacket> buildPackets(uint playerActorID)
{
List<SubPacket> packets = new List<SubPacket>();
int packetCount = 0;
int runningCount = 0;
byte[] data = new byte[PACKET_SIZE - 0x20];
MemoryStream mem = new MemoryStream(data);
BinaryWriter binWriter = new BinaryWriter(mem);
for (int i = 0; i < equipment.Length; i++)
{
if (equipment[i] == UNEQUIPPED)
continue;
binWriter.Write((UInt16)i);
binWriter.Write((UInt32)equipment[i]);
packetCount++;
runningCount++;
//Create another packet
if (runningCount >= 16)
{
packetCount = 0;
binWriter.Write((UInt32)8);
binWriter.Dispose();
mem.Dispose();
packets.Add(new SubPacket(OPCODE, playerActorID, playerActorID, data));
data = new byte[PACKET_SIZE - 0x20];
mem = new MemoryStream(data);
binWriter = new BinaryWriter(mem);
}
}
//Create any leftover subpacket
binWriter.BaseStream.Seek(0x30, SeekOrigin.Begin);
binWriter.Write((UInt32)packetCount);
binWriter.Dispose();
mem.Dispose();
packets.Add(new SubPacket(OPCODE, playerActorID, playerActorID, data));
return packets;
}
}
}

View file

@ -0,0 +1,98 @@
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.inventory
{
class EquipmentListX32Packet
{
public const ushort OPCODE = 0x150;
public const uint PACKET_SIZE = 0xE0;
public const uint UNEQUIPPED = 0xFFFFFFFF;
public const int SLOT_MAINHAND = 0x00;
public const int SLOT_OFFHAND = 0x01;
public const int SLOT_THROWINGWEAPON = 0x04;
public const int SLOT_PACK = 0x05;
public const int SLOT_POUCH = 0x06;
public const int SLOT_HEAD = 0x08;
public const int SLOT_UNDERSHIRT = 0x09;
public const int SLOT_BODY = 0x0A;
public const int SLOT_UNDERGARMENT = 0x0B;
public const int SLOT_LEGS = 0x0C;
public const int SLOT_HANDS = 0x0D;
public const int SLOT_BOOTS = 0x0E;
public const int SLOT_WAIST = 0x0F;
public const int SLOT_NECK = 0x10;
public const int SLOT_EARS = 0x11;
public const int SLOT_WRISTS = 0x13;
public const int SLOT_RIGHTFINGER = 0x15;
public const int SLOT_LEFTFINGER = 0x16;
private uint[] equipment = new uint[0x17];
public EquipmentListX32Packet()
{
for (int i = 0; i < equipment.Length; i++)
equipment[i] = UNEQUIPPED; //We will use this as "Unequipped"
}
public void setItem(int slot, uint itemSlot)
{
if (slot >= equipment.Length)
return;
equipment[slot] = itemSlot;
}
public List<SubPacket> buildPackets(uint playerActorID)
{
List<SubPacket> packets = new List<SubPacket>();
int packetCount = 0;
int runningCount = 0;
byte[] data = new byte[PACKET_SIZE - 0x20];
MemoryStream mem = new MemoryStream(data);
BinaryWriter binWriter = new BinaryWriter(mem);
for (int i = 0; i < equipment.Length; i++)
{
if (equipment[i] == UNEQUIPPED)
continue;
binWriter.Write((UInt16)i);
binWriter.Write((UInt32)equipment[i]);
packetCount++;
runningCount++;
//Create another packet
if (runningCount >= 32)
{
packetCount = 0;
binWriter.Write((UInt32)8);
binWriter.Dispose();
mem.Dispose();
packets.Add(new SubPacket(OPCODE, playerActorID, playerActorID, data));
data = new byte[PACKET_SIZE - 0x20];
mem = new MemoryStream(data);
binWriter = new BinaryWriter(mem);
}
}
//Create any leftover subpacket
binWriter.BaseStream.Seek(0x30, SeekOrigin.Begin);
binWriter.Write((UInt32)packetCount);
binWriter.Dispose();
mem.Dispose();
packets.Add(new SubPacket(OPCODE, playerActorID, playerActorID, data));
return packets;
}
}
}

View file

@ -0,0 +1,98 @@
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.inventory
{
class EquipmentListX64Packet
{
public const ushort OPCODE = 0x151;
public const uint PACKET_SIZE = 0x194;
public const uint UNEQUIPPED = 0xFFFFFFFF;
public const int SLOT_MAINHAND = 0x00;
public const int SLOT_OFFHAND = 0x01;
public const int SLOT_THROWINGWEAPON = 0x04;
public const int SLOT_PACK = 0x05;
public const int SLOT_POUCH = 0x06;
public const int SLOT_HEAD = 0x08;
public const int SLOT_UNDERSHIRT = 0x09;
public const int SLOT_BODY = 0x0A;
public const int SLOT_UNDERGARMENT = 0x0B;
public const int SLOT_LEGS = 0x0C;
public const int SLOT_HANDS = 0x0D;
public const int SLOT_BOOTS = 0x0E;
public const int SLOT_WAIST = 0x0F;
public const int SLOT_NECK = 0x10;
public const int SLOT_EARS = 0x11;
public const int SLOT_WRISTS = 0x13;
public const int SLOT_RIGHTFINGER = 0x15;
public const int SLOT_LEFTFINGER = 0x16;
private uint[] equipment = new uint[0x17];
public EquipmentListX64Packet()
{
for (int i = 0; i < equipment.Length; i++)
equipment[i] = UNEQUIPPED; //We will use this as "Unequipped"
}
public void setItem(int slot, uint itemSlot)
{
if (slot >= equipment.Length)
return;
equipment[slot] = itemSlot;
}
public List<SubPacket> buildPackets(uint playerActorID)
{
List<SubPacket> packets = new List<SubPacket>();
int packetCount = 0;
int runningCount = 0;
byte[] data = new byte[PACKET_SIZE - 0x20];
MemoryStream mem = new MemoryStream(data);
BinaryWriter binWriter = new BinaryWriter(mem);
for (int i = 0; i < equipment.Length; i++)
{
if (equipment[i] == UNEQUIPPED)
continue;
binWriter.Write((UInt16)i);
binWriter.Write((UInt32)equipment[i]);
packetCount++;
runningCount++;
//Create another packet
if (runningCount >= 64)
{
packetCount = 0;
binWriter.Write((UInt32)8);
binWriter.Dispose();
mem.Dispose();
packets.Add(new SubPacket(OPCODE, playerActorID, playerActorID, data));
data = new byte[PACKET_SIZE - 0x20];
mem = new MemoryStream(data);
binWriter = new BinaryWriter(mem);
}
}
//Create any leftover subpacket
binWriter.BaseStream.Seek(0x30, SeekOrigin.Begin);
binWriter.Write((UInt32)packetCount);
binWriter.Dispose();
mem.Dispose();
packets.Add(new SubPacket(OPCODE, playerActorID, playerActorID, data));
return packets;
}
}
}

View file

@ -12,7 +12,7 @@ namespace FFXIVClassic_Map_Server.packets.send.Actor.inventory
class InventoryItemPacket
{
public const ushort OPCODE = 0x014B;
public const ushort OPCODE = 0x014A;
public const uint PACKET_SIZE = 0x90;
public static SubPacket buildPacket(uint playerActorID, List<Item> items, ref int listOffset)

View file

@ -0,0 +1,33 @@
using FFXIVClassic_Lobby_Server.packets;
using FFXIVClassic_Map_Server.dataobjects;
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.inventory
{
class InventoryListX01Packet
{
public const ushort OPCODE = 0x0148;
public const uint PACKET_SIZE = 0x90;
public static SubPacket buildPacket(uint playerActorID, Item item)
{
byte[] data = new byte[PACKET_SIZE - 0x20];
using (MemoryStream mem = new MemoryStream(data))
{
using (BinaryWriter binWriter = new BinaryWriter(mem))
{
binWriter.Write(item.toPacketBytes());
}
}
return new SubPacket(OPCODE, playerActorID, playerActorID, data);
}
}
}

View file

@ -0,0 +1,45 @@
using FFXIVClassic_Lobby_Server.packets;
using FFXIVClassic_Map_Server.dataobjects;
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.inventory
{
class InventoryListX08Packet
{
public const ushort OPCODE = 0x0149;
public const uint PACKET_SIZE = 0x3A8;
public static SubPacket buildPacket(uint playerActorID, List<Item> items, ref int listOffset)
{
byte[] data = new byte[PACKET_SIZE - 0x20];
using (MemoryStream mem = new MemoryStream(data))
{
using (BinaryWriter binWriter = new BinaryWriter(mem))
{
int max;
if (items.Count - listOffset <= 8)
max = items.Count - listOffset;
else
max = 8;
for (int i = listOffset; i < max; i++)
{
binWriter.Write(items[i].toPacketBytes());
listOffset++;
}
binWriter.Seek(0x380, SeekOrigin.Begin);
binWriter.Write((UInt32)max);
}
}
return new SubPacket(OPCODE, playerActorID, playerActorID, data);
}
}
}

View file

@ -0,0 +1,42 @@
using FFXIVClassic_Lobby_Server.packets;
using FFXIVClassic_Map_Server.dataobjects;
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.inventory
{
class InventoryListX16Packet
{
public const ushort OPCODE = 0x014A;
public const uint PACKET_SIZE = 0x720;
public static SubPacket buildPacket(uint playerActorID, List<Item> items, ref int listOffset)
{
byte[] data = new byte[PACKET_SIZE - 0x20];
using (MemoryStream mem = new MemoryStream(data))
{
using (BinaryWriter binWriter = new BinaryWriter(mem))
{
int max;
if (items.Count - listOffset <= 16)
max = items.Count - listOffset;
else
max = 16;
for (int i = listOffset; i < items.Count; i++)
{
binWriter.Write(items[i].toPacketBytes());
listOffset++;
}
}
}
return new SubPacket(OPCODE, playerActorID, playerActorID, data);
}
}
}

View file

@ -0,0 +1,42 @@
using FFXIVClassic_Lobby_Server.packets;
using FFXIVClassic_Map_Server.dataobjects;
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.inventory
{
class InventoryListX32Packet
{
public const ushort OPCODE = 0x014B;
public const uint PACKET_SIZE = 0xE20;
public static SubPacket buildPacket(uint playerActorID, List<Item> items, ref int listOffset)
{
byte[] data = new byte[PACKET_SIZE - 0x20];
using (MemoryStream mem = new MemoryStream(data))
{
using (BinaryWriter binWriter = new BinaryWriter(mem))
{
int max;
if (items.Count - listOffset <= 32)
max = items.Count - listOffset;
else
max = 32;
for (int i = listOffset; i < items.Count; i++)
{
binWriter.Write(items[i].toPacketBytes());
listOffset++;
}
}
}
return new SubPacket(OPCODE, playerActorID, playerActorID, data);
}
}
}

View file

@ -0,0 +1,42 @@
using FFXIVClassic_Lobby_Server.packets;
using FFXIVClassic_Map_Server.dataobjects;
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.inventory
{
class InventoryListX64Packet
{
public const ushort OPCODE = 0x014C;
public const uint PACKET_SIZE = 0x1C20;
public static SubPacket buildPacket(uint playerActorID, List<Item> items, ref int listOffset)
{
byte[] data = new byte[PACKET_SIZE - 0x20];
using (MemoryStream mem = new MemoryStream(data))
{
using (BinaryWriter binWriter = new BinaryWriter(mem))
{
int max;
if (items.Count - listOffset <= 64)
max = items.Count - listOffset;
else
max = 64;
for (int i = listOffset; i < max; i++)
{
binWriter.Write(items[i].toPacketBytes());
listOffset++;
}
}
}
return new SubPacket(OPCODE, playerActorID, playerActorID, 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.inventory
{
class InventoryRemoveX01Packet
{
public const ushort OPCODE = 0x0152;
public const uint PACKET_SIZE = 0x28;
public static SubPacket buildPacket(uint playerActorID, ushort slot)
{
byte[] data = new byte[PACKET_SIZE - 0x20];
using (MemoryStream mem = new MemoryStream(data))
{
using (BinaryWriter binWriter = new BinaryWriter(mem))
{
binWriter.Write((UInt16)slot);
}
}
return new SubPacket(OPCODE, playerActorID, playerActorID, data);
}
}
}

View file

@ -0,0 +1,44 @@
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.inventory
{
class InventoryRemoveX08Packet
{
public const ushort OPCODE = 0x0153;
public const uint PACKET_SIZE = 0x38;
public static SubPacket buildPacket(uint playerActorID, List<ushort> slots, ref int listOffset)
{
byte[] data = new byte[PACKET_SIZE - 0x20];
using (MemoryStream mem = new MemoryStream(data))
{
using (BinaryWriter binWriter = new BinaryWriter(mem))
{
int max;
if (slots.Count - listOffset <= 8)
max = slots.Count - listOffset;
else
max = 8;
for (int i = listOffset; i < max; i++)
{
binWriter.Write((UInt16)slots[i]);
listOffset++;
}
binWriter.Seek(0x10, SeekOrigin.Begin);
binWriter.Write((Byte)max);
}
}
return new SubPacket(OPCODE, playerActorID, playerActorID, data);
}
}
}

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.Actor.inventory
{
class InventoryRemoveX16Packet
{
public const ushort OPCODE = 0x154;
public const uint PACKET_SIZE = 0x40;
public static SubPacket buildPacket(uint playerActorID, List<ushort> slots, ref int listOffset)
{
byte[] data = new byte[PACKET_SIZE - 0x20];
using (MemoryStream mem = new MemoryStream(data))
{
using (BinaryWriter binWriter = new BinaryWriter(mem))
{
int max;
if (slots.Count - listOffset <= 16)
max = slots.Count - listOffset;
else
max = 16;
for (int i = listOffset; i < 16; i++)
{
binWriter.Write((UInt16)slots[i]);
listOffset++;
}
}
}
return new SubPacket(OPCODE, playerActorID, playerActorID, data);
}
}
}

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.Actor.inventory
{
class InventoryRemoveX32Packet
{
public const ushort OPCODE = 0x0155;
public const uint PACKET_SIZE = 0x60;
public static SubPacket buildPacket(uint playerActorID, List<ushort> slots, ref int listOffset)
{
byte[] data = new byte[PACKET_SIZE - 0x20];
using (MemoryStream mem = new MemoryStream(data))
{
using (BinaryWriter binWriter = new BinaryWriter(mem))
{
int max;
if (slots.Count - listOffset <= 32)
max = slots.Count - listOffset;
else
max = 32;
for (int i = listOffset; i < max; i++)
{
binWriter.Write((UInt16)slots[i]);
listOffset++;
}
}
}
return new SubPacket(OPCODE, playerActorID, playerActorID, data);
}
}
}

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.Actor.inventory
{
class InventoryRemoveX64Packet
{
public const ushort OPCODE = 0x156;
public const uint PACKET_SIZE = 0xA0;
public static SubPacket buildPacket(uint playerActorID, List<ushort> slots, ref int listOffset)
{
byte[] data = new byte[PACKET_SIZE - 0x20];
using (MemoryStream mem = new MemoryStream(data))
{
using (BinaryWriter binWriter = new BinaryWriter(mem))
{
int max;
if (slots.Count - listOffset <= 64)
max = slots.Count - listOffset;
else
max = 64;
for (int i = listOffset; i < max; i++)
{
binWriter.Write((UInt16)slots[i]);
listOffset++;
}
}
}
return new SubPacket(OPCODE, playerActorID, playerActorID, data);
}
}
}

View file

@ -13,10 +13,13 @@ namespace FFXIVClassic_Map_Server.packets.send.Actor.inventory
public const ushort OPCODE = 0x0146;
public const uint PACKET_SIZE = 0x28;
public const ushort CODE_ITEMS = 0x0000;
public const ushort CODE_CURRANCYITEMS = 0x0063;
public const ushort CODE_KEYITEMS = 0x0064;
public const ushort CODE_EQUIPMENT = 0x00FE;
public const ushort CODE_INVENTORY = 0x0000; //Max 0xC8
public const ushort CODE_LOOT = 0x0004; //Max 0xA
public const ushort CODE_MELDREQUEST = 0x0005; //Max 0x04
public const ushort CODE_BAZAAR = 0x0007; //Max 0x0A
public const ushort CODE_CURRANCY = 0x0063; //Max 0x140
public const ushort CODE_KEYITEMS = 0x0064; //Max 0x500
public const ushort CODE_EQUIPMENT = 0x00FE; //Max 0x23
public static SubPacket buildPacket(uint playerActorID, ushort size, ushort code)
{