|
You last visited: Today at 23:52
Advertisement
[Opinion] Do you like how these Packet Structures work?
Discussion on [Opinion] Do you like how these Packet Structures work? within the CO2 Private Server forum part of the Conquer Online 2 category.
08/13/2010, 23:17
|
#31
|
elite*gold: 0
Join Date: Sep 2008
Posts: 1,683
Received Thanks: 505
|
Justice smells good, doesn't it?
|
|
|
08/13/2010, 23:21
|
#32
|
elite*gold: 20
Join Date: Mar 2006
Posts: 1,491
Received Thanks: 536
|
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.
Code:
PacketType CXSPackets::ParsePacket(char * packet)
{
packetid = *((WORD*)(packet+2));
size = *((WORD*)(packet));
switch (*((WORD*)(packet+2)))
{
case 0x03E9:
ZeroMemory(&CreateCharacterPacket, sizeof(CreateCharacterPacket));
memcpy(&CreateCharacterPacket, packet, size);
return PacketType(packetid);
case 0x03EC:
ZeroMemory(&ChatPacket, sizeof(ChatPacket));
ChatPacket.size = *(WORD*)(packet);
ChatPacket.type = *((WORD*)(packet+2));
ChatPacket.color = *((int*)(packet+4));
ChatPacket.chattype = *((int*)(packet+8));
memcpy(ChatPacket.time, packet+12, 4);
ChatPacket.unknown1 = *((int*)(packet+16));
ChatPacket.display = *((int*)(packet+20));
ChatPacket.unknown2 = *((char*)(packet+24));
ChatPacket.fromcount = *((char*)(packet+25));
memcpy(ChatPacket.from, packet+26, ChatPacket.fromcount);
ChatPacket.tocount = *((char*)(packet+26+ChatPacket.fromcount));
memcpy(ChatPacket.to, packet+27+ChatPacket.fromcount, ChatPacket.tocount);
ChatPacket.stringcount = *((char*)(packet+28+ChatPacket.fromcount+ChatPacket.tocount));
memcpy(ChatPacket.string, packet+29+ChatPacket.fromcount+ChatPacket.tocount, ChatPacket.stringcount);
return PacketType(packetid);
case 0x03ED:
ZeroMemory(&MovePacket, sizeof(MovePacket));
memcpy(&MovePacket, packet, size);
return PacketType(packetid);
case 0x041B:
ZeroMemory(&LoginPacket, sizeof(LoginPacket));
memcpy(&LoginPacket, packet, size);
return PacketType(packetid);
|
|
|
08/13/2010, 23:23
|
#33
|
elite*gold: 20
Join Date: Mar 2006
Posts: 6,125
Received Thanks: 2,518
|
Quote:
Originally Posted by bone-you
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.
I think that just about clears up everything =x
|
|
|
08/13/2010, 23:25
|
#34
|
elite*gold: 20
Join Date: Mar 2006
Posts: 1,491
Received Thanks: 536
|
Quote:
Originally Posted by Korvacs
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.
|
|
|
08/13/2010, 23:27
|
#35
|
elite*gold: 0
Join Date: Nov 2009
Posts: 754
Received Thanks: 544
|
Quote:
Originally Posted by Korvacs
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?
|
Write method:
Code:
IntPtr Ptr = Marshal.AllocHGlobal(Packet.Length);
Marshal.StructureToPtr(Struct, Ptr, false);
fixed (byte* pckt = this.Packet)
{
Native.memcpy(pckt, Ptr.ToPointer(), Packet.Length);
}
On de-serializing:
Code:
public void Deserialize(IConquerPacket ConquerPacket)
{
fixed (byte* Packet = ConquerPacket.ToArray())
{
MsgPacket = *((MessagePacket*)(Packet));
fixed (MessagePacket* Msg = &MsgPacket)
{
this.Msg_From = new string(Msg->String_From);
this.Msg_To = new string(Msg->String_To);
this.Msg_Data = new string(Msg->String_Message);
}
}
}
|
|
|
08/14/2010, 00:30
|
#36
|
elite*gold: 20
Join Date: Mar 2006
Posts: 6,125
Received Thanks: 2,518
|
Well, thanks for clarifying that aspect of it, wish you could have done that 2 pages ago instead of me doing all of that >.<!
|
|
|
08/14/2010, 00:33
|
#37
|
elite*gold: 0
Join Date: Nov 2009
Posts: 754
Received Thanks: 544
|
Quote:
Originally Posted by Korvacs
Well, thanks for clarifying that aspect of it, wish you could have done that 2 pages ago instead of me doing all of that >.<!
|
Haha forgive me
|
|
|
08/14/2010, 05:05
|
#38
|
elite*gold: 0
Join Date: Jun 2009
Posts: 787
Received Thanks: 314
|
You guys are doing it wrong. Don't assume TQ will send null terminators.
ie: new string ((sbyte*)addr->Offset, offset, addr->Length);
Just saying.
|
|
|
08/14/2010, 12:55
|
#39
|
elite*gold: 0
Join Date: Nov 2009
Posts: 754
Received Thanks: 544
|
Quote:
Originally Posted by _tao4229_
You guys are doing it wrong. Don't assume TQ will send null terminators.
ie: new string ((sbyte*)addr->Offset, offset, addr->Length);
Just saying.
|
He was using fixed sbyte in his struct, that's why I showed him that method. And it works perfectly fine if you just trim the string.
|
|
|
|
|
Similar Threads
|
[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)
|
All times are GMT +2. The time now is 23:52.
|
|