Register for your free account! | Forgot your password?

You last visited: Today at 19:16

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

Advertisement



Packetbuilder

Discussion on Packetbuilder within the CO2 Programming forum part of the Conquer Online 2 category.

Reply
 
Old 10/19/2011, 19:20   #16
 
InfamousNoone's Avatar
 
elite*gold: 20
Join Date: Jan 2008
Posts: 2,012
Received Thanks: 2,885
Quote:
Originally Posted by IAmHawtness View Post
What would the benefit be using AllocHGlobal instead of just "new byte[1024]"? They both allocate memory on the heap, but with AllocHGlobal you have to manually deallocate the memory when you're done using it.
Using the 'new' operator in C# means you're allocating managed memory. Which means, everytime you want to write to it using pointer logic, you have to fix it down. Fixing it down means your forcibly preventing the GC from moving the data to some other location in the memory.

Moral of the story, constantly/repetitively fixing down an array is expensive in contrast to doing it once (or not at all).
InfamousNoone is offline  
Thanks
1 User
Old 10/19/2011, 21:36   #17
 
_DreadNought_'s Avatar
 
elite*gold: 28
Join Date: Jun 2010
Posts: 2,225
Received Thanks: 868
Infamous, How do you structure your packets and whats your fav way of doing it?(curious)
_DreadNought_ is offline  
Old 10/20/2011, 07:09   #18
 
InfamousNoone's Avatar
 
elite*gold: 20
Join Date: Jan 2008
Posts: 2,012
Received Thanks: 2,885
I generally stick to the C/C++ way of doing it first demonstrated by bone-you.
i.e.
Code:
typedef packet0x420 struct {
	PACKETHEADER Header;
	DWORD Argument;
} MSG_TRADE;
So in C#, my code would look like,
Code:
struct MsgTrade
{
	public short Size;
	public short Type;
	public int Argument;
}
Code:
var msg = new MsgTrade();
msg.Size = sizeof(MsgTrade);
msg.Type = PacketTypes.Trade;
msg.Argument = ivar;
Client.Send(&msg);
And then for any packets that have non-static sizes (for instance, the synchronization, message, etc packet) I implement an interface that a GetBytes() function, and a FromBytes() function.

ConquerAI however uses a packet builder for everything, this system was already set up when I joined the project so I decided to just follow suite instead of changing it to work to my liking.
InfamousNoone is offline  
Thanks
1 User
Old 10/21/2011, 01:14   #19


 
Korvacs's Avatar
 
elite*gold: 20
Join Date: Mar 2006
Posts: 6,126
Received Thanks: 2,518
Quote:
Originally Posted by Korvacs View Post
Mine doesn't require the unsafe or fixed declarations in every method, but yeah something like that.
Ironically just dropped this method all together today on my current project lol.
Korvacs is offline  
Reply


Similar Threads Similar Threads
Packetbuilder
10/13/2011 - General Coding - 0 Replies
I have a simple packetbuilder right now, but is there any way that this can be optimized for efficiency? class PacketBuilder { private byte buffer; public PacketBuilder(byte Buffer) { buffer = Buffer; } public void ZeroFill(byte Buffer, ushort Offset, ushort Count) {



All times are GMT +1. The time now is 19:17.


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.