Register for your free account! | Forgot your password?

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

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

Advertisement



Hybrids packet builder

Discussion on Hybrids packet builder within the CO2 Private Server forum part of the Conquer Online 2 category.

Reply
 
Old   #1
 
Arco.'s Avatar
 
elite*gold: 0
Join Date: Feb 2011
Posts: 335
Received Thanks: 170
Hybrids packet builder

Alright so hybrids packet builder;
It has 5 functions, each doing these:

Writing a UInt16
Writing a UInt32
Writing a UInt64
Writing a String
Writing a String with Length

Now I made this function, and I'm wanting it to be universal, used to do all of the above. Would this work?

Code:
 public static void WriteObject(Object Arg, Byte[] Buffer, UInt16 Offset, Boolean stringLength = false)
        {
            #region String function
            if (Arg.GetType() == typeof(String))
            {
                #region Write string to array of data
                if (!stringLength)
                {
                    ushort i = 0;
                    while (i < Convert.ToString(Arg).Length)
                    {
                        Buffer[(ushort)(i + Offset)] = (byte)Convert.ToString(Arg)[i];
                        i = (ushort)(i + 1);
                    }
                }
                #endregion

                #region Write string with length
                else
                {
                    Buffer[Offset] = (byte)Convert.ToString(Arg).Length;
                    Offset++;
                    ushort x = 0;
                    while (x < Convert.ToString(Arg).Length)
                    {
                        Buffer[(ushort)(x + Offset)] = (byte)Convert.ToString(Arg)[x];
                        x = (ushort)(x + 1);
                    }
                }
                #endregion
            } 
            #endregion

            #region Writing 2 bytes of data
            if (Arg.GetType() == typeof(UInt16))
            {
                Buffer[Offset] = (byte)(Arg);
                Buffer[Offset + 1] = (byte)(Convert.ToUInt16(Arg) >> 8);
            }
            if (Arg.GetType() == typeof(Int16))
            {
                Buffer[Offset] = (byte)(Arg);
                Buffer[Offset + 1] = (byte)(Convert.ToUInt16(Arg) >> 8);
            }
            #endregion

            #region Writing 4 bytes of data
            if (Arg.GetType() == typeof(Int32))
            {
                Buffer[Offset] = (byte)(Arg);
                Buffer[Offset + 1] = (byte)(Convert.ToInt32(Arg) >> 8);
                Buffer[Offset + 2] = (byte)(Convert.ToInt32(Arg) >> 16);
                Buffer[Offset + 3] = (byte)(Convert.ToInt32(Arg) >> 24);
            }
            if (Arg.GetType() == typeof(UInt32))
            {
                Buffer[Offset] = (byte)(Arg);
                Buffer[Offset + 1] = (byte)(Convert.ToUInt32(Arg) >> 8);
                Buffer[Offset + 2] = (byte)(Convert.ToUInt32(Arg) >> 16);
                Buffer[Offset + 3] = (byte)(Convert.ToUInt32(Arg) >> 24);
            } 
            #endregion

            #region Writing 8 bytes of data
            if (Arg.GetType() == typeof(Int64))
            {
                Buffer[Offset] = (byte)(Arg);
                Buffer[Offset + 1] = (byte)(Convert.ToInt64(Arg) >> 8);
                Buffer[Offset + 2] = (byte)(Convert.ToInt64(Arg) >> 16);
                Buffer[Offset + 3] = (byte)(Convert.ToInt64(Arg) >> 24);
                Buffer[Offset + 4] = (byte)(Convert.ToInt64(Arg) >> 32);
                Buffer[Offset + 5] = (byte)(Convert.ToInt64(Arg) >> 40);
                Buffer[Offset + 6] = (byte)(Convert.ToInt64(Arg) >> 48);
                Buffer[Offset + 7] = (byte)(Convert.ToInt64(Arg) >> 56);
            }
            if (Arg.GetType() == typeof(UInt64))
            {
                Buffer[Offset] = (byte)(Arg);
                Buffer[Offset + 1] = (byte)(Convert.ToUInt64(Arg) >> 8);
                Buffer[Offset + 2] = (byte)(Convert.ToUInt64(Arg) >> 16);
                Buffer[Offset + 3] = (byte)(Convert.ToUInt64(Arg) >> 24);
                Buffer[Offset + 4] = (byte)(Convert.ToUInt64(Arg) >> 32);
                Buffer[Offset + 5] = (byte)(Convert.ToUInt64(Arg) >> 40);
                Buffer[Offset + 6] = (byte)(Convert.ToUInt64(Arg) >> 48);
                Buffer[Offset + 7] = (byte)(Convert.ToUInt64(Arg) >> 56);
            } 
            #endregion
        }
Arco. is offline  
Thanks
3 Users
Old 02/16/2011, 01:03   #2
 
.Beatz's Avatar
 
elite*gold: 0
Join Date: May 2006
Posts: 1,190
Received Thanks: 516
Looks **** sexy!
.Beatz is offline  
Old 02/16/2011, 01:03   #3
 
Ian*'s Avatar
 
elite*gold: 0
Join Date: Nov 2006
Posts: 805
Received Thanks: 464
hi arco
Ian* is offline  
Old 02/16/2011, 01:25   #4


 
Korvacs's Avatar
 
elite*gold: 20
Join Date: Mar 2006
Posts: 6,126
Received Thanks: 2,518
It would, but using pointers you could do that in like 1/8th of the code...
Korvacs is offline  
Old 02/16/2011, 01:37   #5
 
Arco.'s Avatar
 
elite*gold: 0
Join Date: Feb 2011
Posts: 335
Received Thanks: 170
Quote:
Originally Posted by Korvacs View Post
It would, but using pointers you could do that in like 1/8th of the code...
I've NEVER used pointers, so mind elaborating on that please
Arco. is offline  
Old 02/16/2011, 02:26   #6
 
.Beatz's Avatar
 
elite*gold: 0
Join Date: May 2006
Posts: 1,190
Received Thanks: 516
Quote:
Originally Posted by Yup Arco View Post
I've NEVER used pointers, so mind elaborating on that please
Don't know if this helps

I used google

.Beatz is offline  
Thanks
1 User
Old 02/16/2011, 02:50   #7
 
elite*gold: 0
Join Date: Aug 2009
Posts: 930
Received Thanks: 448
use c++ you rat
.Guru is offline  
Thanks
2 Users
Old 02/16/2011, 04:39   #8


 
CptSky's Avatar
 
elite*gold: 0
Join Date: Jan 2008
Posts: 1,444
Received Thanks: 1,176
Quote:
Originally Posted by Yup Arco View Post
Alright so hybrids packet builder;
It has 5 functions, each doing these:

Writing a UInt16
Writing a UInt32
Writing a UInt64
Writing a String
Writing a String with Length

Now I made this function, and I'm wanting it to be universal, used to do all of the above. Would this work?

Can be optimized... Here a rapid version. It should works, but I can't test.

Code:
        public static void WriteObject(Object Arg, Byte[] Buffer, UInt16 Offset, Boolean stringLength)
        {
            Type Type = Arg.GetType();
            Int32 Length = 0;

            if (Type == typeof(String))
                Length = (Arg as String).Length;
            else if (Type == typeof(Byte[]))
                Length = (Arg as Byte[]).Length;
            else if (Type == typeof(SByte) || Type == typeof(Byte))
                Length = 1;
            else if (Type == typeof(Int16) || Type == typeof(UInt16))
                Length = 2;
            else if (Type == typeof(Int32) || Type == typeof(UInt32))
                Length = 4;
            else if (Type == typeof(Int64) || Type == typeof(UInt64))
                Length = 8;

            if (Length < 1)
                return;

            Int32 Pos = Offset;
            if (Type == typeof(String) && stringLength)
            {
                Buffer[Pos] = (Byte)Length;
                Pos++;
            }

                if (Type == typeof(String))
                {
                    String Value = (Arg as String);
                    for (Int32 i = 0; i < Length; i++)
                    {
                        Buffer[Pos] = (Byte)Value[i];
                        Pos++;
                    }
                }
                else if (Type == typeof(Byte[]))
                {
                    Byte[] Value = (Arg as Byte[]);
                    for (Int32 i = 0; i < Length; i++)
                    {
                        Buffer[Pos] = (Byte)Value[i];
                        Pos++;
                    }
                }
                else
                {
                    UInt64 Value = Convert.ToUInt64(Arg);
                    for (Int32 i = 0; i < Length; i++)
                    {
                        Buffer[Pos] = (Byte)(Value >> (8 * i));
                        Pos++;
                    }
                }
        }
CptSky is offline  
Old 02/16/2011, 05:12   #9
 
elite*gold: 0
Join Date: Jun 2009
Posts: 787
Received Thanks: 314
Code:
public struct PasswordSeedPacket
{
    public ushort Size;
    public ushort Type;
    public uint Seed;
    public PasswordSeedPacket(uint s)
    {
        Seed = s;
        Size = 8;
        Type = 0x423;
    }
}

// ...
{
    // ...
    PasswordSeedPacket seed = new PasswordSeedPacket(rand(..));
    socket.send(&seed, seed.Size [,...]);
}
_tao4229_ is offline  
Old 02/16/2011, 11:28   #10
 
elite*gold: 0
Join Date: Oct 2009
Posts: 768
Received Thanks: 550
Quote:
Originally Posted by Korvacs View Post
It would, but using pointers you could do that in like 1/8th of the code...
Code:
        public static unsafe void WriteObject(Object Arg, Byte[] Buffer, UInt16 Offset, Boolean stringLength = false)
        {
            fixed (byte* buffer = Buffer)
            {
                #region String function
                if (Arg is String)
                {
                    #region Write string to array of data
                    if (!stringLength)
                    {
                        ushort i = 0;
                        string Argument = Convert.ToString(Arg);
                        while (i < Argument.Length)
                        {
                            *((byte*)(buffer + Offset + i)) = (byte)Argument[i];
                            i++;
                        }
                    }
                    #endregion

                    #region Write string with length
                    else
                    {
                        string Argument = Convert.ToString(Arg);
                        *((byte*)(buffer + Offset)) = (byte)Argument.Length;
                        ushort i = 1;
                        while (i < Argument.Length)
                        {
                            *((byte*)(buffer + Offset + i)) = (byte)Argument[i];
                            i++;
                        }
                    }
                    #endregion
                }
                #endregion

                #region Writing 1 byte of data
                if (Arg is Byte)
                    *((Byte*)(buffer + Offset)) = Arg;
                if (Arg is SByte)
                    *((SByte*)(buffer + Offset)) = Arg;
                #endregion

                #region Writing 2 bytes of data
                if (Arg is Int16)
                    *((Int16*)(buffer + Offset)) = Arg;
                if (Arg is UInt16)
                    *((UInt16*)(buffer + Offset)) = Arg;
                #endregion

                #region Writing 4 bytes of data
                if (Arg is Int32)
                    *((Int32*)(buffer + Offset)) = Arg;
                if (Arg is UInt32)
                    *((UInt32*)(buffer + Offset)) = Arg;
                #endregion

                #region Writing 8 bytes of data
                if (Arg is Int64)
                    *((Int64*)(buffer + Offset)) = Arg;
                if (Arg is UInt64)
                    *((UInt64*)(buffer + Offset)) = Arg;
                #endregion
            }
        }
-impulse- is offline  
Old 02/16/2011, 11:34   #11


 
Korvacs's Avatar
 
elite*gold: 20
Join Date: Mar 2006
Posts: 6,126
Received Thanks: 2,518
Put some returns in there, otherwise all of the cpu time you save by using pointers is wasted by performing all of those if statements. *nods*
Korvacs is offline  
Old 02/16/2011, 17:22   #12
 
elite*gold: 20
Join Date: Aug 2005
Posts: 1,734
Received Thanks: 1,001
I suppose this would work also.

PHP Code:
static void Write<T>(byte[] Bufferint OffsetT Valuebool IncludeLength true)
        {
            if (
typeof(T) == typeof(string))
            {
                
string StringRepresentation Convert.ToString(Value);
                
byte Size = (byte)StringRepresentation.Length;
                if (
IncludeLength)
                {
                    
Buffer[Offset++] = Size;
                }
                for (
byte i 0Sizei++)
                {
                    
Buffer[Offset i] = (byte)StringRepresentation[i];
                }
            }
            else
            {
                
int Size Marshal.SizeOf(Value);
                
IntPtr Pointer Marshal.AllocHGlobal(Size);
                try
                {
                    
Marshal.StructureToPtr(ValuePointerfalse);
                    
Marshal.Copy(PointerBufferOffsetSize);
                }
                
finally
                
{
                    
Marshal.FreeHGlobal(Pointer);
                }
            }
        } 
tanelipe is offline  
Reply


Similar Threads Similar Threads
Composition Hybrids Source
12/21/2010 - CO2 PServer Guides & Releases - 2 Replies
For Hybrids 5017 Source!!! Handler: class Composition { public Composition(GameClient Client, byte Data) { uint MainUID = BitConverter.ToUInt32(Data, 8); uint Minor1UID = BitConverter.ToUInt32(Data, 12);
[Release]Hybrids Source v5(my way)
08/22/2010 - CO2 PServer Guides & Releases - 19 Replies
Ok guys this was my very first project i ever worked on. Its 5017 server built up. Since I coded my source from scratch i stopped working on this project and started a new 5017. This project was in the middle of converting over to Structured packets using the method that saint used but different if you ever looked at his source. Its far from bugles and far from clean was my test project. The main one that was not being used to test new things out on i'm not going to release because...
Hybrids Source
05/15/2010 - CO2 Private Server - 11 Replies
HeLLo , elitepvpers.com members I Need Link Hybrids Source ; #C Learning 5017 Source
[RELEASE] My first packet builder.
05/08/2010 - CO2 PServer Guides & Releases - 3 Replies
This is a release of my first, packet builder I've ever made. It is very old, and I doubt there aren't any better around here, this one is just pretty logical to my opinion, where others failed. This will be a part of the things I will be dumping after I formatted my PC without being prepared. I'm sorry for all other info I still had on the CO2 PServer development, it is not available for my any more. I was going to release it all though, but not just yet. public class PacketCreate { ...
hybrids source
02/24/2009 - CO2 Private Server - 8 Replies
i need link for download hybrids source + hybrids source acpet start for Client 5017?



All times are GMT +1. The time now is 21:30.


Powered by vBulletin®
Copyright ©2000 - 2026, 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 ©2026 elitepvpers All Rights Reserved.