Speed is now stored in the actor. Redid actor speed packet to use float. Added GameMessagePacket which can use all 20 msg packets. Added functions for lua side to call in player obj.

This commit is contained in:
Filip Maj 2016-02-02 00:02:06 -05:00
parent fe69f069ea
commit cfb29b912f
7 changed files with 445 additions and 21 deletions

View file

@ -0,0 +1,346 @@
using FFXIVClassic_Lobby_Server.packets;
using FFXIVClassic_Map_Server.lua;
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
{
class GameMessagePacket
{
public const ushort OPCODE_GAMEMESSAGE_WITH_ACTOR1 = 0x157;
public const ushort OPCODE_GAMEMESSAGE_WITH_ACTOR2 = 0x158;
public const ushort OPCODE_GAMEMESSAGE_WITH_ACTOR3 = 0x159;
public const ushort OPCODE_GAMEMESSAGE_WITH_ACTOR4 = 0x15a;
public const ushort OPCODE_GAMEMESSAGE_WITH_ACTOR5 = 0x15b;
public const ushort OPCODE_GAMEMESSAGE_WITH_CUSTOM_SENDER1 = 0x15c;
public const ushort OPCODE_GAMEMESSAGE_WITH_CUSTOM_SENDER2 = 0x15d;
public const ushort OPCODE_GAMEMESSAGE_WITH_CUSTOM_SENDER3 = 0x15e;
public const ushort OPCODE_GAMEMESSAGE_WITH_CUSTOM_SENDER4 = 0x15f;
public const ushort OPCODE_GAMEMESSAGE_WITH_CUSTOM_SENDER5 = 0x160;
public const ushort OPCODE_GAMEMESSAGE_WITH_DISPID_SENDER1 = 0x161;
public const ushort OPCODE_GAMEMESSAGE_WITH_DISPID_SENDER2 = 0x162;
public const ushort OPCODE_GAMEMESSAGE_WITH_DISPID_SENDER3 = 0x163;
public const ushort OPCODE_GAMEMESSAGE_WITH_DISPID_SENDER4 = 0x164;
public const ushort OPCODE_GAMEMESSAGE_WITH_DISPID_SENDER5 = 0x165;
public const ushort OPCODE_GAMEMESSAGE_WITHOUT_ACTOR1 = 0x166;
public const ushort OPCODE_GAMEMESSAGE_WITHOUT_ACTOR2 = 0x167;
public const ushort OPCODE_GAMEMESSAGE_WITHOUT_ACTOR3 = 0x168;
public const ushort OPCODE_GAMEMESSAGE_WITHOUT_ACTOR4 = 0x169;
public const ushort OPCODE_GAMEMESSAGE_WITHOUT_ACTOR5 = 0x16a;
public const ushort SIZE_GAMEMESSAGE_WITH_ACTOR1 = 0x30;
public const ushort SIZE_GAMEMESSAGE_WITH_ACTOR2 = 0x38;
public const ushort SIZE_GAMEMESSAGE_WITH_ACTOR3 = 0x40;
public const ushort SIZE_GAMEMESSAGE_WITH_ACTOR4 = 0x50;
public const ushort SIZE_GAMEMESSAGE_WITH_ACTOR5 = 0x70;
public const ushort SIZE_GAMEMESSAGE_WITH_CUSTOM_SENDER1 = 0x48;
public const ushort SIZE_GAMEMESSAGE_WITH_CUSTOM_SENDER2 = 0x58;
public const ushort SIZE_GAMEMESSAGE_WITH_CUSTOM_SENDER3 = 0x68;
public const ushort SIZE_GAMEMESSAGE_WITH_CUSTOM_SENDER4 = 0x78;
public const ushort SIZE_GAMEMESSAGE_WITH_CUSTOM_SENDER5 = 0x98;
public const ushort SIZE_GAMEMESSAGE_WITH_DISPID_SENDER1 = 0x30;
public const ushort SIZE_GAMEMESSAGE_WITH_DISPID_SENDER2 = 0x38;
public const ushort SIZE_GAMEMESSAGE_WITH_DISPID_SENDER3 = 0x40;
public const ushort SIZE_GAMEMESSAGE_WITH_DISPID_SENDER4 = 0x50;
public const ushort SIZE_GAMEMESSAGE_WITH_DISPID_SENDER5 = 0x60;
public const ushort SIZE_GAMEMESSAGE_WITHOUT_ACTOR1 = 0x28;
public const ushort SIZE_GAMEMESSAGE_WITHOUT_ACTOR2 = 0x38;
public const ushort SIZE_GAMEMESSAGE_WITHOUT_ACTOR3 = 0x38;
public const ushort SIZE_GAMEMESSAGE_WITHOUT_ACTOR4 = 0x48;
public const ushort SIZE_GAMEMESSAGE_WITHOUT_ACTOR5 = 0x68;
public static SubPacket buildPacket(uint sourceId, uint targetId, uint actorId, uint textOwnerActorId, ushort textId, byte log)
{
byte[] data = new byte[SIZE_GAMEMESSAGE_WITH_ACTOR1 - 0x20];
using (MemoryStream mem = new MemoryStream(data))
{
using (BinaryWriter binWriter = new BinaryWriter(mem))
{
binWriter.Write((UInt32)actorId);
binWriter.Write((UInt32)textOwnerActorId);
binWriter.Write((UInt16)textId);
binWriter.Write((UInt16)log);
}
}
return new SubPacket(OPCODE_GAMEMESSAGE_WITH_ACTOR1, sourceId, targetId, data);
}
public static SubPacket buildPacket(uint sourceId, uint targetId, uint actorId, uint textOwnerActorId, ushort textId, byte log, List<LuaParam> lParams)
{
int lParamsSize = findSizeOfParams(lParams);
byte[] data;
ushort opcode;
if (lParamsSize <= 0x8)
{
data = new byte[SIZE_GAMEMESSAGE_WITH_ACTOR2 - 0x20];
opcode = OPCODE_GAMEMESSAGE_WITH_ACTOR2;
}
else if (lParamsSize <= 0x10)
{
data = new byte[SIZE_GAMEMESSAGE_WITH_ACTOR3 - 0x20];
opcode = OPCODE_GAMEMESSAGE_WITH_ACTOR3;
}
else if (lParamsSize <= 0x20)
{
data = new byte[SIZE_GAMEMESSAGE_WITH_ACTOR4 - 0x20];
opcode = OPCODE_GAMEMESSAGE_WITH_ACTOR4;
}
else
{
data = new byte[SIZE_GAMEMESSAGE_WITH_ACTOR5 - 0x20];
opcode = OPCODE_GAMEMESSAGE_WITH_ACTOR5;
}
using (MemoryStream mem = new MemoryStream(data))
{
using (BinaryWriter binWriter = new BinaryWriter(mem))
{
binWriter.Write((UInt32)actorId);
binWriter.Write((UInt32)textOwnerActorId);
binWriter.Write((UInt16)textId);
binWriter.Write((UInt16)log);
LuaUtils.writeLuaParams(binWriter, lParams);
if (lParamsSize <= 0x14-12)
{
binWriter.Seek(0x14, SeekOrigin.Begin);
binWriter.Write((UInt32)8);
}
}
}
return new SubPacket(opcode, sourceId, targetId, data);
}
public static SubPacket buildPacket(uint sourceId, uint targetId, uint textOwnerActorId, ushort textId, string sender, byte log)
{
byte[] data = new byte[SIZE_GAMEMESSAGE_WITH_CUSTOM_SENDER1 - 0x20];
using (MemoryStream mem = new MemoryStream(data))
{
using (BinaryWriter binWriter = new BinaryWriter(mem))
{
binWriter.Write((UInt32)textOwnerActorId);
binWriter.Write((UInt16)textId);
binWriter.Write((UInt16)log);
binWriter.Write(Encoding.ASCII.GetBytes(sender), 0, Encoding.ASCII.GetByteCount(sender) >= 0x20 ? 0x20 : Encoding.ASCII.GetByteCount(sender));
}
}
return new SubPacket(OPCODE_GAMEMESSAGE_WITH_CUSTOM_SENDER1, sourceId, targetId, data);
}
public static SubPacket buildPacket(uint sourceId, uint targetId, uint textOwnerActorId, ushort textId, string sender, byte log, List<LuaParam> lParams)
{
int lParamsSize = findSizeOfParams(lParams);
byte[] data;
ushort opcode;
if (lParamsSize <= 0x8)
{
data = new byte[SIZE_GAMEMESSAGE_WITH_CUSTOM_SENDER2 - 0x20];
opcode = OPCODE_GAMEMESSAGE_WITH_CUSTOM_SENDER2;
}
else if (lParamsSize <= 0x10)
{
data = new byte[SIZE_GAMEMESSAGE_WITH_CUSTOM_SENDER3 - 0x20];
opcode = OPCODE_GAMEMESSAGE_WITH_CUSTOM_SENDER3;
}
else if (lParamsSize <= 0x20)
{
data = new byte[SIZE_GAMEMESSAGE_WITH_CUSTOM_SENDER4 - 0x20];
opcode = OPCODE_GAMEMESSAGE_WITH_CUSTOM_SENDER4;
}
else
{
data = new byte[SIZE_GAMEMESSAGE_WITH_CUSTOM_SENDER5 - 0x20];
opcode = OPCODE_GAMEMESSAGE_WITH_CUSTOM_SENDER5;
}
using (MemoryStream mem = new MemoryStream(data))
{
using (BinaryWriter binWriter = new BinaryWriter(mem))
{
binWriter.Write((UInt32)textOwnerActorId);
binWriter.Write((UInt16)textId);
binWriter.Write((UInt16)log);
binWriter.Write(Encoding.ASCII.GetBytes(sender), 0, Encoding.ASCII.GetByteCount(sender) >= 0x20 ? 0x20 : Encoding.ASCII.GetByteCount(sender));
LuaUtils.writeLuaParams(binWriter, lParams);
if (lParamsSize <= 0x14 - 12)
{
binWriter.Seek(0x30, SeekOrigin.Begin);
binWriter.Write((UInt32)8);
}
}
}
return new SubPacket(opcode, sourceId, targetId, data);
}
public static SubPacket buildPacket(uint sourceId, uint targetId, uint textOwnerActorId, ushort textId, uint senderDisplayNameId, byte log)
{
byte[] data = new byte[SIZE_GAMEMESSAGE_WITH_DISPID_SENDER1 - 0x20];
using (MemoryStream mem = new MemoryStream(data))
{
using (BinaryWriter binWriter = new BinaryWriter(mem))
{
binWriter.Write((UInt32)senderDisplayNameId);
binWriter.Write((UInt32)textOwnerActorId);
binWriter.Write((UInt16)textId);
binWriter.Write((UInt16)log);
}
}
return new SubPacket(OPCODE_GAMEMESSAGE_WITH_DISPID_SENDER1, sourceId, targetId, data);
}
public static SubPacket buildPacket(uint sourceId, uint targetId, uint textOwnerActorId, ushort textId, uint senderDisplayNameId, byte log, List<LuaParam> lParams)
{
int lParamsSize = findSizeOfParams(lParams);
byte[] data;
ushort opcode;
if (lParamsSize <= 0x8)
{
data = new byte[SIZE_GAMEMESSAGE_WITH_DISPID_SENDER2 - 0x20];
opcode = OPCODE_GAMEMESSAGE_WITH_DISPID_SENDER2;
}
else if (lParamsSize <= 0x10)
{
data = new byte[SIZE_GAMEMESSAGE_WITH_DISPID_SENDER3 - 0x20];
opcode = OPCODE_GAMEMESSAGE_WITH_DISPID_SENDER3;
}
else if (lParamsSize <= 0x20)
{
data = new byte[SIZE_GAMEMESSAGE_WITH_DISPID_SENDER4 - 0x20];
opcode = OPCODE_GAMEMESSAGE_WITH_DISPID_SENDER4;
}
else
{
data = new byte[SIZE_GAMEMESSAGE_WITH_DISPID_SENDER5 - 0x20];
opcode = OPCODE_GAMEMESSAGE_WITH_DISPID_SENDER5;
}
using (MemoryStream mem = new MemoryStream(data))
{
using (BinaryWriter binWriter = new BinaryWriter(mem))
{
binWriter.Write((UInt32)senderDisplayNameId);
binWriter.Write((UInt32)textOwnerActorId);
binWriter.Write((UInt16)textId);
binWriter.Write((UInt16)log);
LuaUtils.writeLuaParams(binWriter, lParams);
if (lParamsSize <= 0x14 - 12)
{
binWriter.Seek(0x14, SeekOrigin.Begin);
binWriter.Write((UInt32)8);
}
}
}
return new SubPacket(opcode, sourceId, targetId, data);
}
public static SubPacket buildPacket(uint sourceId, uint targetId, uint textOwnerActorId, ushort textId, byte log)
{
byte[] data = new byte[SIZE_GAMEMESSAGE_WITHOUT_ACTOR1 - 0x20];
using (MemoryStream mem = new MemoryStream(data))
{
using (BinaryWriter binWriter = new BinaryWriter(mem))
{
binWriter.Write((UInt32)textOwnerActorId);
binWriter.Write((UInt16)textId);
binWriter.Write((UInt16)log);
}
}
return new SubPacket(OPCODE_GAMEMESSAGE_WITHOUT_ACTOR1, sourceId, targetId, data);
}
public static SubPacket buildPacket(uint sourceId, uint targetId, uint textOwnerActorId, ushort textId, byte log, List<LuaParam> lParams)
{
int lParamsSize = findSizeOfParams(lParams);
byte[] data;
ushort opcode;
if (lParamsSize <= 0x8)
{
data = new byte[SIZE_GAMEMESSAGE_WITHOUT_ACTOR2 - 0x20];
opcode = OPCODE_GAMEMESSAGE_WITHOUT_ACTOR2;
}
else if (lParamsSize <= 0x10)
{
data = new byte[SIZE_GAMEMESSAGE_WITHOUT_ACTOR3 - 0x20];
opcode = OPCODE_GAMEMESSAGE_WITHOUT_ACTOR3;
}
else if (lParamsSize <= 0x20)
{
data = new byte[SIZE_GAMEMESSAGE_WITHOUT_ACTOR4 - 0x20];
opcode = OPCODE_GAMEMESSAGE_WITHOUT_ACTOR4;
}
else
{
data = new byte[SIZE_GAMEMESSAGE_WITHOUT_ACTOR5 - 0x20];
opcode = OPCODE_GAMEMESSAGE_WITHOUT_ACTOR5;
}
using (MemoryStream mem = new MemoryStream(data))
{
using (BinaryWriter binWriter = new BinaryWriter(mem))
{
binWriter.Write((UInt32)textOwnerActorId);
binWriter.Write((UInt16)textId);
binWriter.Write((UInt16)log);
LuaUtils.writeLuaParams(binWriter, lParams);
if (lParamsSize <= 0x14 - 12)
{
binWriter.Seek(0x30, SeekOrigin.Begin);
binWriter.Write((UInt32)8);
}
}
}
return new SubPacket(opcode, sourceId, targetId, data);
}
private static int findSizeOfParams(List<LuaParam> lParams)
{
int total = 0;
foreach (LuaParam l in lParams)
{
switch (l.typeID)
{
case 0:
case 1:
case 6:
total += 5;
break;
case 3:
case 4:
case 5:
total += 1;
break;
}
}
return total + 1;
}
}
}