Register for your free account! | Forgot your password?

Go Back   elitepvpers > MMORPGs > Conquer Online 2 > CO2 Private Server
You last visited: Today at 02:01

  • Please register to post and access all features, it's quick, easy and FREE!

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.

Reply
 
Old   #1
 
elite*gold: 0
Join Date: Sep 2008
Posts: 1,683
Received Thanks: 506
[Opinion] Do you like how these Packet Structures work?

I got my answer, remove this thread.
Basser is offline  
Old 08/13/2010, 17:38   #2
 
elite*gold: 21
Join Date: Jul 2005
Posts: 9,193
Received Thanks: 5,379
It's def interesting.

Personally i'm a fan of older style packet builders like coemu/llots/immune's source where you can just setup the values and run w/o needing a whole slew of different things for one ppacket. It's sexeh how you have it... it's just not the way i tend to think and therefor becomes awkward to code.
pro4never is offline  
Old 08/13/2010, 17:54   #3
 
elite*gold: 0
Join Date: Sep 2008
Posts: 1,683
Received Thanks: 506
Immunes source used offsets right? So if 2 offsets changed, you would actually have to change all offsets affected, for this one, you dont.
Also I will not use this for very big packets with lots of gaps and strings without a fixed length.
Basser is offline  
Old 08/13/2010, 18:14   #4
 
bone-you's Avatar
 
elite*gold: 20
Join Date: Mar 2006
Posts: 1,491
Received Thanks: 536
I'm curious if my method I used for packets is able to work in C#. It is quite similar to yours minus the get accessors. It had a huge enum and all the structs made out but for packets with dynamic sizes (like strings) it did a little behind the scenes work like what you pasted to make it work right. Do you have this actually working on a large scale?
bone-you is offline  
Old 08/13/2010, 18:43   #5


 
Korvacs's Avatar
 
elite*gold: 20
Join Date: Mar 2006
Posts: 6,126
Received Thanks: 2,518
I use packets like this for my proxy, except that in C# theres no physical way of using structs for packets which contain dynamic length strings, unfortunately. So these work well for everything except for ChatPacket(1004) and CharInfo(1006).

They are really handy for unions, makes life alot easier.
Korvacs is offline  
Old 08/13/2010, 19:00   #6
 
bone-you's Avatar
 
elite*gold: 20
Join Date: Mar 2006
Posts: 1,491
Received Thanks: 536
Quote:
Originally Posted by Korvacs View Post
I use packets like this for my proxy, except that in C# theres no physical way of using structs for packets which contain dynamic length strings, unfortunately. So these work well for everything except for ChatPacket(1004) and CharInfo(1006).

They are really handy for unions, makes life alot easier.
Sure there is. You do it like he did it and like how I did it in C++. There will obviously be a function call required to "construct" the packet but it would indeed work very well.

Code:
char * CXSPackets::BuildPacket(int type)
{
	switch (type)
	{
	case 0x03E9:
		CreateCharacterPacket.type = type;
		CreateCharacterPacket.size = sizeof(CreateCharacterPacket);
		return (char *)&CreateCharacterPacket;
	case 0x03EC:
		ZeroMemory(&buffer, sizeof(buffer));
		*(WORD*)(buffer) = size;
		*(WORD*)(buffer+2) = packetid;
		*(int*)(buffer+4) = ChatPacket.color;
		*(int*)(buffer+8) = ChatPacket.chattype;
		memcpy(buffer+12, ChatPacket.time, 4);
		*(int*)(buffer+16) = ChatPacket.unknown1;
		*(int*)(buffer+20) = ChatPacket.display;
		*(char*)(buffer+24) = ChatPacket.unknown2;
		*(char*)(buffer+25) = ChatPacket.fromcount;
		memcpy(buffer+26, ChatPacket.from, ChatPacket.fromcount);
		*(char*)(buffer+26+ChatPacket.fromcount) = ChatPacket.tocount;
		memcpy(buffer+27+ChatPacket.fromcount, ChatPacket.to, ChatPacket.tocount);
		*(char*)(buffer+28+ChatPacket.fromcount+ChatPacket.tocount) = ChatPacket.stringcount;
		memcpy(buffer+29+ChatPacket.fromcount+ChatPacket.tocount, ChatPacket.string, ChatPacket.stringcount);
		*(WORD*)(buffer) = size = 29 + ChatPacket.fromcount + ChatPacket.tocount + ChatPacket.stringcount;
		return (char *)buffer;
	case 0x03ED:
		MovePacket.type = type;
		MovePacket.size = sizeof(MovePacket);
		return (char *)&MovePacket;
	case 0x041B:
		LoginPacket.type = type;
		LoginPacket.size = sizeof(LoginPacket);
		return (char *)&LoginPacket;
	case 0x041C:
		LanguagePacket.type = type;
		LanguagePacket.size = sizeof(LanguagePacket);
		return (char *)&LanguagePacket;
	case 0x03EE:
		ZeroMemory(&buffer, sizeof(buffer));
		CharacterDataPacket.type = type;
		CharacterDataPacket.size = sizeof(CharacterDataPacket);
		memcpy(buffer, &CharacterDataPacket, 68);
		*(char*)(buffer+68) = CharacterDataPacket.charnamecount;
		memcpy(buffer+69, CharacterDataPacket.charactername, CharacterDataPacket.charnamecount);
		*(char*)(buffer+69+CharacterDataPacket.charnamecount) = CharacterDataPacket.spousenamecount;
		memcpy(buffer+70+CharacterDataPacket.charnamecount, CharacterDataPacket.spousename, CharacterDataPacket.spousenamecount);
		*(WORD*)(buffer) = size = 67 + CharacterDataPacket.spousenamecount + CharacterDataPacket.charnamecount + 4;

		return (char *)buffer;
etc etc
bone-you is offline  
Old 08/13/2010, 19:05   #7


 
Korvacs's Avatar
 
elite*gold: 20
Join Date: Mar 2006
Posts: 6,126
Received Thanks: 2,518
Using a dynamic char[] in the struct for CharInfo, and then trying to do this:

Code:
CharacterInfo* Packet = (CharacterInfo*)Pointer;
Returns this compiler error:

Code:
Error	1	Cannot take the address of, get the size of, or declare a pointer to a managed type ('MiningBot.Networking.Packets.CharacterInfo')	C:\Users\Jack\Documents\Visual Studio 2010\Projects\MiningBot\MiningBot\Networking\PacketHandler.cs	60	25	MiningBot
So tell me again how i could get around that issue using a struct?
Korvacs is offline  
Old 08/13/2010, 19:22   #8
 
bone-you's Avatar
 
elite*gold: 20
Join Date: Mar 2006
Posts: 1,491
Received Thanks: 536
Quote:
Originally Posted by Korvacs View Post
Using a dynamic char[] in the struct for CharInfo, and then trying to do this:

Code:
CharacterInfo* Packet = (CharacterInfo*)Pointer;
Returns this compiler error:

Code:
Error	1	Cannot take the address of, get the size of, or declare a pointer to a managed type ('MiningBot.Networking.Packets.CharacterInfo')	C:\Users\Jack\Documents\Visual Studio 2010\Projects\MiningBot\MiningBot\Networking\PacketHandler.cs	60	25	MiningBot
So tell me again how i could get around that issue using a struct?
If you're asking me, ask Basser. He seems to have gotten it to work. As for your attitude of "impossible!", that is not the attitude of a true developer/programmer. Nothing is impossible. While I know it is not impossible to do it in C# entirely, if you absolutely desired to, you could even import these functions from a DLL of another language to accomplish it. It is not impossible to get the desired results in C#.


I think I get your question though. You can't have dynamic sizes in essence. In C++ you'd use pointers, create the memory, then memcpy to a temp buffer in order to return a full packet. You'd have to find a method of doing that in C#.
bone-you is offline  
Thanks
1 User
Old 08/13/2010, 19:32   #9


 
Korvacs's Avatar
 
elite*gold: 20
Join Date: Mar 2006
Posts: 6,126
Received Thanks: 2,518
My attitude isnt "Impossible!", my attitude is, ive spent months looking into this and ive found that you just cannot do it with dynamic values in a fixed struct, Basser has created a packet with no dynamic values, which i have also done:

Code:
ItemDataPacket* Packet = (ItemDataPacket*)Pointer;
Compiles with no issues. However you cannot have a dynamic value in a fixed struct, you just cant do it.

Google it, research it, contact microsoft about it, it cant be done in C#.
Korvacs is offline  
Old 08/13/2010, 19:49   #10
 
ImmuneOne's Avatar
 
elite*gold: 0
Join Date: Nov 2009
Posts: 754
Received Thanks: 544
Quote:
Originally Posted by Korvacs View Post
My attitude isnt "Impossible!", my attitude is, ive spent months looking into this and ive found that you just cannot do it with dynamic values in a fixed struct, Basser has created a packet with no dynamic values, which i have also done:

Code:
ItemDataPacket* Packet = (ItemDataPacket*)Pointer;
Compiles with no issues. However you cannot have a dynamic value in a fixed struct, you just cant do it.

Google it, research it, contact microsoft about it, it cant be done in C#.
Code:
        [StructLayout(LayoutKind.Sequential, CharSet=CharSet.Ansi)]
        struct MessagePacket
        {
            public PacketHeader Header;//0-4
            public UInt32 Msg_Color;//4-8
            public UInt32 Msg_Type;//8-12
            public UInt32 Msg_ID;//12-16
            public UInt64 Unknown;//16-24
            public Byte String_Count;//24-25
            public Byte String_From_Length;//25-26
            [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 16)]
            public String String_From;//26-27 + pos
            public Byte String_To_Length;//27 + pos - 28 + pos
            [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 16)]
            public String String_To;//28 + pos - 29 + pos
            public Byte Blank;//29 + pos - 30 + pos
            public Byte String_Message_Length;//30 + pos - 31 + pos
            [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 16)]
            public String String_Message;//31 + pos - 32 + pos
        }

//Get the size; Marshal.SizeOf(Instance);
//Set the length of each string to 16.
You gotta thank Nullable for the constant length fix though, I personally thought the client would not trim these.
ImmuneOne is offline  
Old 08/13/2010, 19:50   #11
 
ImFlamedCOD's Avatar
 
elite*gold: 0
Join Date: Jun 2009
Posts: 378
Received Thanks: 141
Basser that is a good method to do you packets with. Used it before and use a variation of it now. So in my opinion yea it is a good method.
ImFlamedCOD is offline  
Old 08/13/2010, 19:53   #12
 
bone-you's Avatar
 
elite*gold: 20
Join Date: Mar 2006
Posts: 1,491
Received Thanks: 536
Quote:
Originally Posted by Korvacs View Post
My attitude isnt "Impossible!", my attitude is, ive spent months looking into this and ive found that you just cannot do it with dynamic values in a fixed struct, Basser has created a packet with no dynamic values, which i have also done:

Code:
ItemDataPacket* Packet = (ItemDataPacket*)Pointer;
Compiles with no issues. However you cannot have a dynamic value in a fixed struct, you just cant do it.

Google it, research it, contact microsoft about it, it cant be done in C#.
Ok Mr Hostility. My first reply was explaining in general that it was possible. You came back with a "it's not possible to do X, tell me how to do it!" trying to pick a fight as if I said you could do it the way you're trying lol.

I'm not saying you can do it with dynamic values. Maybe in the future you can with a high-level language like C#, but for now no. You have to do it with fixed-size structs like you always have... hence the need for a "construct" function to build the packet of a "variable-size" struct into a buffer.
bone-you is offline  
Old 08/13/2010, 20:03   #13


 
Korvacs's Avatar
 
elite*gold: 20
Join Date: Mar 2006
Posts: 6,126
Received Thanks: 2,518
Quote:
Originally Posted by ImmuneOne View Post
Code:
        [StructLayout(LayoutKind.Sequential, CharSet=CharSet.Ansi)]
        struct MessagePacket
        {
            public PacketHeader Header;//0-4
            public UInt32 Msg_Color;//4-8
            public UInt32 Msg_Type;//8-12
            public UInt32 Msg_ID;//12-16
            public UInt64 Unknown;//16-24
            public Byte String_Count;//24-25
            public Byte String_From_Length;//25-26
            [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 16)]
            public String String_From;//26-27 + pos
            public Byte String_To_Length;//27 + pos - 28 + pos
            [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 16)]
            public String String_To;//28 + pos - 29 + pos
            public Byte Blank;//29 + pos - 30 + pos
            public Byte String_Message_Length;//30 + pos - 31 + pos
            [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 16)]
            public String String_Message;//31 + pos - 32 + pos
        }

//Get the size; Marshal.SizeOf(Instance);
//Set the length of each string to 16.
You gotta thank Nullable for the constant length fix though, I personally thought the client would not trim these.
Again, that doesnt work for dynamic length strings, i explored that but what your doing there is assigning the string a fixed length in memory, so if the string is say 4 bytes long, then when you assign the data from the pointer to the struct you read a further 12 bytes into invalid memory, because the packet you assigned only have 4 bytes of data at that location.

Honestly, i explored every option for this, it cannot be done.

@Bone, actually in my original post i said that it works well for everything except to packets which dont work because of the need for variable sized arrays, and you came back with of course it can be done with dynamic values, so im not being hostile, im just being correct, you cannot do it thats the end of it. You can work around it using constructs which of course can be done, sadly its alot less elegant and requires more processing and cpu time. But that is a work around to something that they should have more sense about when designing the language.
Korvacs is offline  
Old 08/13/2010, 20:09   #14
 
elite*gold: 0
Join Date: Sep 2008
Posts: 1,683
Received Thanks: 506
@Bone, well Korvacs is right, and I did know this. It is not impossible, but I have no idea how to make it possible though. =/
@Korvacs, Yes, unfortunately this is the case, however for the other structures, I do like this, glad you do too. I didnt know other people used this method already =P
I came up with it when I was trying to learn more about pointer usage in my source.
Basser is offline  
Old 08/13/2010, 20:14   #15
 
ImmuneOne's Avatar
 
elite*gold: 0
Join Date: Nov 2009
Posts: 754
Received Thanks: 544
Quote:
Originally Posted by Korvacs View Post
...
This method works very well for every auth/game packet I use.
ImmuneOne is offline  
Reply


Similar Threads 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 +1. The time now is 02:01.


Powered by vBulletin®
Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
SEO by vBSEO ©2011, Crawlability, Inc.
This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

Support | Contact Us | FAQ | Advertising | Privacy Policy | Terms of Service | Abuse
Copyright ©2025 elitepvpers All Rights Reserved.