Register for your free account! | Forgot your password?

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

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

Advertisement



Most efficient way to write packets?

Discussion on Most efficient way to write packets? within the CO2 Private Server forum part of the Conquer Online 2 category.

Reply
 
Old   #1
 
elite*gold: 0
Join Date: Apr 2011
Posts: 73
Received Thanks: 12
Most efficient way to write packets?

What is more efficient to use?
Pointers or MemoryStream?
Secured is offline  
Old 04/14/2011, 21:01   #2


 
KraHen's Avatar
 
elite*gold: 0
Join Date: Jul 2006
Posts: 2,216
Received Thanks: 794
Or serializing structs or classes...
KraHen is offline  
Old 04/14/2011, 21:07   #3
 
elite*gold: 0
Join Date: Apr 2011
Posts: 73
Received Thanks: 12
Quote:
Originally Posted by KraHen View Post
Or serializing structs or classes...
Oh yea that's right. Just want to know which one would be most efficient to use.
Secured is offline  
Old 04/15/2011, 00:15   #4
 
elite*gold: 0
Join Date: Jun 2009
Posts: 787
Received Thanks: 314
Writing them on paper takes the least amount of computational resources.


obv
_tao4229_ is offline  
Thanks
2 Users
Old 04/17/2011, 21:23   #5
 
kill_acvc's Avatar
 
elite*gold: 0
Join Date: Dec 2007
Posts: 63
Received Thanks: 0
Quote:
Originally Posted by Secured View Post
What is more efficient to use?
Pointers or MemoryStream?
I use a safe writer in my source, which takes 2 args : the value and the offset. It's pretty simple.
kill_acvc is offline  
Old 04/17/2011, 21:57   #6


 
KraHen's Avatar
 
elite*gold: 0
Join Date: Jul 2006
Posts: 2,216
Received Thanks: 794
Simple!=efficient

Though you can send structs without any extra stuff needed.
KraHen is offline  
Old 04/18/2011, 00:32   #7
 
elite*gold: 0
Join Date: Apr 2011
Posts: 73
Received Thanks: 12
Quote:
Originally Posted by kill_acvc View Post
I use a safe writer in my source, which takes 2 args : the value and the offset. It's pretty simple.
I'm not asking for what's most simple, but what's most efficient.
Secured is offline  
Old 04/18/2011, 01:35   #8
 
kill_acvc's Avatar
 
elite*gold: 0
Join Date: Dec 2007
Posts: 63
Received Thanks: 0
Quote:
Originally Posted by Secured View Post
I'm not asking for what's most simple, but what's most efficient.
Well if you're looking for eficiency then I suggest you to use pointers. But be careful, you may get "AcessViolationException" sometimes and your server will be more vulnerable to hackers attacks.
kill_acvc is offline  
Old 04/18/2011, 02:47   #9
 
elite*gold: 21
Join Date: Jul 2005
Posts: 9,193
Received Thanks: 5,380
Pointers are a lovely thing to use but just make sure you double check all information properly. Don't just blindly accept a packet as being true...

For example if you receive a packet that has a string in it... don't just blindly assume that the string length byte is correct. You could easily run past the end of the actual packet being received and end up reading or even modifying important areas of your memory.

That being said... I personally like using unsafe structures + implicit operators or just using memory marshaling to send the end result.

Personally I'm using unsafe structures + implicit operators for almost all my packets in my new source (thanks to Dev for the suggestion :P) and it's working great. My source also supports just using memory marshaling but maybe it's just me... so far I've liked doing it separately.

Example...

Code:
public unsafe struct WalkPacket
    {
        public uint Direction;
        public uint Id;
        public uint Mode;
        public SystemTime Timestamp;
        public uint Unknown1;

        public static WalkPacket Create(uint id, uint direction, uint mode)
        {
            var packet = new WalkPacket();
            packet.Direction = direction;
            packet.Id = id;
            packet.Mode = mode;
            packet.Timestamp = SystemTime.Now;
            return packet;
        }

        public static implicit operator WalkPacket(byte* ptr)
        {
            var packet = new WalkPacket();
            packet.Direction = *((uint*) (ptr + 4));
            packet.Id = *((uint*) (ptr + 8));
            packet.Mode = *((uint*) (ptr + 12));
            packet.Timestamp = *((SystemTime*) (ptr + 16));
            packet.Unknown1 = *((uint*) (ptr + 20));
            return packet;
        }

        public static implicit operator byte[](WalkPacket packet)
        {
            var buffer = new byte[24 + 8];
            fixed (byte* ptr = buffer)
            {
                PacketBuilder.AppendHeader(ptr, buffer.Length, 10005);
                *((uint*) (ptr + 4)) = packet.Direction;
                *((uint*) (ptr + 8)) = packet.Id;
                *((uint*) (ptr + 12)) = packet.Mode;
                *((SystemTime*) (ptr + 16)) = packet.Timestamp;
                *((uint*) (ptr + 20)) = packet.Unknown1;
            }
            return buffer;
        }
    }
pro4never is offline  
Old 04/18/2011, 04:58   #10
 
elite*gold: 0
Join Date: Jun 2009
Posts: 787
Received Thanks: 314
WalkPacket* walk = (WalkPacket*)ptr; ??
_tao4229_ is offline  
Old 04/18/2011, 05:07   #11
 
Lateralus's Avatar
 
elite*gold: 0
Join Date: May 2005
Posts: 1,892
Received Thanks: 920
Quote:
Originally Posted by _tao4229_ View Post
Writing them on paper takes the least amount of computational resources.


obv
HILARIOUS! A+++!
Lateralus is offline  
Reply


Similar Threads Similar Threads
Efficient NFS World Hacks!
10/25/2010 - General Gaming Discussion - 12 Replies
I try to collect efficient NFW World hacks in 1 thred ! These are not my !!! But i think its good to Collect them in 1 Thred, and in 1 Download ! The Hack´s come with Video ! Ich veruche hier die funktionierenden Hacks zusammen zu fassen ! Diese Hacks sind nicht meine Arbeit, sondern (die meisten) sind auch mit etwas suche hier zu finden ! Aber ich denke es ist eine gute Idee die Hack´s hier zusammen zu fassen ! Die Hack´s kommen mit Video !
What about coding an efficient socket system?
08/10/2010 - CO2 Private Server - 22 Replies
I want to start a new project from scratch, and I thought about using my sockets from my last unfinished projects until I saw the .NET 3.5 methods. What do you guys think about the methods used in the sample which was released by MS? I`m talking about the BufferManager approach, and the pool for the SocketAsyncEventArgs. It seems nice to me, I implemented this in my project, with some modifications to fit my needs, what do you guys think about it? #edit : Also, would it be better if I coded...
Efficient farming
06/07/2006 - Lineage 2 - 2 Replies
As I just got another account, I ask myself how to farm efficiently with just one toon, using walker or superman. Would a scavenger be a good idea? Or any other class? Which level should the toon be and at which location should it hunt? Thanks in advance.
Efficient Grinding
10/13/2005 - WoW Guides & Templates - 9 Replies
Learning to efficiently grind in world of warcraft can lead to better understand of the game, and, more importantly, more money and better experiance in a solo environment. Everyone grinds, whether we like it or not, so i will help you be able to make it more fun, and more efficient. Firstly, what you grind is INCREDIBLY important. You should probably grind humanoids exclusively, they tend to have mobs that go down faster, and drop cloth for first aid and/or auctioning. There are a few...



All times are GMT +1. The time now is 03:32.


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.