Code:
[StructLayou(LayoutKind = Sequential,Pack=1,Size = 18)]
public struct Character_Items
{
public short Armor;
public short Helm;
public short WeaponL;
public short WeaponR;
public short Pants;
public short Boots;
public short Gloves;
public short Levels;
public byte Glow;
public byte Guardian;
}
[StructLayou(LayoutKind = Sequential,Pack=1,Size = 34)]
public struct Character_Block
{
public byte Position;
[MarshalAs(UnmanagedType.ByValArray,SizeConst = 10)]
public short Level;
public byte Class;
public byte CtrlCode;
public Character_Items Items;
public byte GuildStatus;
}
So here I have a problem when deserealize
[StructLayou(LayoutKind = Sequential,Pack=1)]
public struct Character_List
{
public byte Head;
public byte Length;
public byte Code;
public byte OpCode;
public byte SubCode;
public byte Separator;
public byte Count;
//Here the problem i dont know how to set the MarshalAs
[MarshalAs(UnmanagedType.ByValArray)]
public Character_Block[] Characters
public explicit operator Character_List(byte[] Value)
{
return Deserialize<Character_List>(Value);
}
}
//I use it for Deserialize
public static T Deserialize<T>(byte[] Data)
{
IntPtr TmpData = Marshal.AllocHGlobal(Data.Length);
Marshal.Copy(Data, 0, TmpData, Data.Length);
T TmpStruct = Marshal.PtrToStructure(TmpData, typeof(T));
Marshal.FreeHGlobal(TmpData);
return TmpStruct;
}
Code:
OnCharListRecv((Character_List)Data));
because length of packet is set in Data[1]
But the number of characters is variable
its set on Count inside struct or same as Data[6]
Ill need set the max number of characters thats 5?
Or there is a way to set a variable array size?
Thanks, and sorry for bad english/code ;D hehe