It is because you are assuming the names will always be 16 bytes long. There is no effective way to just throw it into a struct. You have to build it into one manually.
My C++ packet class. You need to do something similar for dynamic sized packets.
It is because you are assuming the names will always be 16 bytes long. There is no effective way to just throw it into a struct. You have to build it into one manually.
Thats my point, you cannot just define a fixed array for strings, therefore dynamic arrays are required and therefore you cannot use a struct in that way (Sadly) in C# for anything that requires a dynamic length string.
Thats my point, you cannot just define a fixed array for strings, therefore dynamic arrays are required and therefore you cannot use a struct in that way (Sadly) in C# for anything that requires a dynamic length string.
I think that just about clears up everything =x
You cannot do what you were trying to do which was point to a managed struct with a dynamic var IN the struct. You CAN on the other hand use a DYNAMIC sized struct to COPY the data into effectively achieving the same result which is what I was saying this entire time lol. The same process would go for constructing the packet when trying to send data. You'd copy FROM the dynamic sized struct into a buffer instead of using the struct itself as one.
Just decided to have a go with your packet and this:
Code:
MessagePacket* Packet = (MessagePacket*)Pointer;
Does not compile, go figure.
So i went ahead and modified it so that it would atleast compile using fixed sbyte buffers:
Code:
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi)]
public unsafe struct MessagePacket
{
public ushort Lenght;
public ushort Type;//0-4
public uint Msg_Color;//4-8
public uint Msg_Type;//8-12
public uint Msg_ID;//12-16
public ulong Unknown;//16-24
public byte String_Count;//24-25
public byte String_From_Length;//25-26
public fixed sbyte String_From[16];//26-27 + pos
public byte String_To_Length;//27 + pos - 28 + pos
public fixed sbyte String_To[16];//28 + pos - 29 + pos
public byte Blank;//29 + pos - 30 + pos
public byte String_Message_Length;//30 + pos - 31 + pos
public fixed sbyte String_Message[16];//31 + pos - 32 + pos
}
And then i sent a chat packet and used this method to demonstrate the issues with it, its not exactly clean but its a valid way of doing it:
Code:
MessagePacket* Packet = (MessagePacket*)Pointer;
Console.WriteLine("[ChatPacket] From {0} To {1} : {2}", new string(Packet->String_From), new string(Packet->String_To), new string(Packet->String_Message));
And this is the outcome:
Now honestly, i dont pretend to be an expert, but that doesnt work does it. As far as i can tell theres nothing especially wrong with my implementation of it unless someone else can suggest a more appropriate method?
[RELEASE] 5298 EntitySpawn Packet Structures 09/13/2010 - CO2 PServer Guides & Releases - 12 Replies Entity Spawn: (10014)
Spoiler:
Offset| Type | Value
0 | Short | Size
2 | Short | Type
75 | Byte | Level
78 | Short | HairStyle
80 | Short | CharX
82 | Short | CharY
123 | int | QuizPoints
[RELEASE] 5293 Packet Structures 09/06/2010 - CO2 PServer Guides & Releases - 47 Replies Hello :awesome:.
Do NOT flame me for releasing this, saying noobs can now get the latest patch to work, because 'noobs' as we like to call them, need more than simple packet structures. Please if you use these packet structures, do not use them for ready to use sources, that would really, really mess up the private servers gain.
From this moment on I am going to release Packet Structures for the Conquer Client patch 5293.
These might be missing, or incorrect, but work for me, or...
[Q]Packet Structures 06/18/2010 - Kal Online - 10 Replies any1 can help me with packet structures..? like
When I have packet like 0x11 or any other type.
Data is for example: 11 00 00 00 4A 58 9A 4A 32 ...
Where 4A 58 represents some WORD (coord, playerid, whatever)
etc.
thanks......
[Request] Packet Structures 04/12/2009 - CO2 Private Server - 0 Replies Hello,
Could anyone provide me with an adequet resource for looking up packet structures, or provide me on information about where I could find them?
I have searched through about 3 CO server sources - they have been a great help but I need more..
Thanks,
Leo (null)