![]() |
Packetbuilder
I have a simple packetbuilder right now, but is there any way that this can be optimized for efficiency?
Spoiler:
|
Why you making Offset ushort? Just make it an int instead from ushort -> int, because index of an array is int.
buffer[int], even it doesn't say anything, it still uses time converting from ushort to int. I could be wrong, but it's how I look at it. And this: Code:
public void WriteStringWithLength(string Arg, ushort Offset)Code:
public void WriteStringWithLength(string Arg, ushort Offset)Code:
public void WriteString(string Arg, ushort Offset)Code:
|
Thanks beautiful.
|
Few things..
Pointers. I don't see much reason not to use them here Structs. Maybe its just me who's fond if it but I'd rather just use a memory structure that's organized the same as my packet then marshal it to send. |
Quote:
I've never been a fan of using structs though, mainly because I'm often too lazy to completely structure a packet |
Pointers, a way to write a byte to the buffer would come in handy aswell, i assume you forgot about that..
|
So how do all of you write/structure packets?
|
Packet class with buffer and pointer, then a series of methods to write to the buffer using the pointer etc.
|
Sorta long the lines of this?
Code:
public static void WriteUInt32(uint arg, int offset, byte[] buffer)Spoiler:
|
I'd strongly recommend looking into tq's net string packer...
It's sexy as hell imo. You can reverse it from the eudemons binary leaked source. It's what we use in my source instead of a method like your WriteStringList method there. |
Mine doesn't require the unsafe or fixed declarations in every method, but yeah something like that.
|
Quote:
Code:
byte* m_ptrI don't know if it could help anything, but this is my packet-builder. Code:
using System; |
Quote:
Code:
ptr = (byte*)(void*)Marshal.AllocHGlobal(size); |
Quote:
|
Quote:
|
Quote:
Moral of the story, constantly/repetitively fixing down an array is expensive in contrast to doing it once (or not at all). |
Infamous, How do you structure your packets and whats your fav way of doing it?(curious)
|
I generally stick to the C/C++ way of doing it first demonstrated by bone-you.
i.e. Code:
typedef packet0x420 struct {Code:
struct MsgTradeCode:
var msg = new MsgTrade();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. |
Quote:
|
| All times are GMT +2. The time now is 23:19. |
Powered by vBulletin®
Copyright ©2000 - 2026, Jelsoft Enterprises Ltd.
SEO by vBSEO ©2011, Crawlability, Inc.