Register for your free account! | Forgot your password?

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

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

Advertisement



include image bytes into packet c#

Discussion on include image bytes into packet c# within the CO2 Private Server forum part of the Conquer Online 2 category.

Reply
 
Old 01/15/2015, 16:54   #16
 
abdeen's Avatar
 
elite*gold: 0
Join Date: Mar 2010
Posts: 475
Received Thanks: 15
Quote:
Originally Posted by Super Aids View Post
Well a 16 bit int length will only work with relative small images. If you want to use regular sized / a little big images you have to use a 32 bit int for the length of it.

Which means an uint for the length.

But I give up....
thanks any way for your help...

.................................................. .............................

i am working on client server app all and i need to send image from client to server so i made a packet class with the packet id, packet length and image bytes ... then i can send the class packet to server ... its fine and i receive the packet with the packet id but i need to get the image bytes from the packet to convert it back again to an image ..that i need to send image packet class from client to server and here is the code for client :

PHP Code:
public class Image WriterInterfaces.IPacket
{
public 
byte[] Buffer;
public 
byte[] ImageBytes;

public 
Image()
{
}

public 
void Deserialize(byte[] buffer)
{
  
Buffer buffer;
}

public 
byte[] ToArray()
{
  
Buffer = new byte[(ImageBytes) + 6];
  
Writer.WriteUInt16(10030 Buffer);
  
Writer.WriteUint16((ushort)(Buffer.Length), 2Buffer);
  
Writer.WriteBytes(ImageBytes4Buffer);
  return 
Buffer;
}

and here is writer class :

PHP Code:
public class Writer
{
    public static 
void WriteStringWithLength(string argint offsetbyte[] buffer)
    {
        if (
buffer == null)
            return;
        if (
offset buffer.Length 1)
            return;
        
int till buffer.Length offset;
        
till Math.Min(arg.Lengthtill);
        
buffer[offset] = (byte)arg.Length;
        
offset++;
        
ushort i 0;
        while (
till)
        {
            
buffer[(ushort)(offset)] = (byte)arg[i];
            
= (ushort)(1);
        }
    }
    public static 
void WriteString(string argint offsetbyte[] buffer)
    {
        if (
buffer == null)
            return;
        if (
offset buffer.Length 1)
            return;
        if (
buffer.Length >= offset arg.Length)
        {
            
unsafe
            
{
 
#if UNSAFE
                
fixed (byteBuffer buffer)
                {
                    
ushort i 0;
                    while (
arg.Length)
                    {
                        *((
byte*)(Buffer offset i)) = (byte)arg[i];
                        
i++;
                    }
                }
 
#else
                
ushort i 0;
                while (
arg.Length)
                {
                    
buffer[(ushort)(offset)] = (byte)arg[i];
                    
= (ushort)(1);
                }
  
#endif
            
}
        }
    }
    public static 
void WriteByte(byte argint offsetbyte[] buffer)
    {
        if (
buffer == null)
            return;
        if (
offset buffer.Length 1)
            return;
        
buffer[offset] = arg;
    }
    public static 
void WriteBytes(byte[] argint offsetbyte[] buffer)
    {
        foreach (
byte arg2 in arg)
        {
            if (
buffer == null)
                return;
            if (
offset buffer.Length 1)
                return;
            
buffer[offset] = arg2;
        }
    }
    public static 
void WriteBoolean(bool argint offsetbyte[] buffer)
    {
        if (
buffer == null)
            return;
        if (
offset buffer.Length 1)
            return;
        
WriteByte(arg == true ? (byte): (byte)0offsetbuffer);
    }
    public static 
void WriteUInt16(ushort argint offsetbyte[] buffer)
    {
        if (
buffer == null)
            return;
        if (
offset buffer.Length 1)
            return;
        if (
buffer.Length >= offset sizeof(ushort))
        {
            
unsafe
            
{
  
#if UNSAFE
                
fixed (byteBuffer buffer)
                {
                    *((
ushort*)(Buffer offset)) = arg;
                }
 
#else
                
buffer[offset] = (byte)arg;
                
buffer[offset 1] = (byte)(arg >> 8);
 
#endif
            
}
        }
    }
    public static 
void WriteUInt32(uint argint offsetbyte[] buffer)
    {
        if (
buffer == null)
            return;
        if (
offset buffer.Length 1)
            return;
        if (
buffer.Length >= offset sizeof(uint))
        {
            
unsafe
            
{
 
#if UNSAFE
                
fixed (byteBuffer buffer)
                {
                    *((
uint*)(Buffer offset)) = arg;
                }
 
#else
                
buffer[offset] = (byte)arg;
                
buffer[offset 1] = (byte)(arg >> 8);
                
buffer[offset 2] = (byte)(arg >> 16);
                
buffer[offset 3] = (byte)(arg >> 24);
 
#endif
            
}
        }
    }
    public static 
void WriteInt32(int argint offsetbyte[] buffer)
    {
        if (
buffer == null)
            return;
        if (
offset buffer.Length 1)
            return;
        if (
buffer.Length >= offset sizeof(uint))
        {
            
unsafe
            
{
 
#if UNSAFE
                
fixed (byteBuffer buffer)
                {
                    *((
int*)(Buffer offset)) = arg;
                }
#else
                
buffer[offset] = (byte)(arg);
                
buffer[offset 1] = (byte)(arg >> 8);
                
buffer[offset 2] = (byte)(arg >> 16);
                
buffer[offset 3] = (byte)(arg >> 24);
#endif
            
}
        }
    }
    public static 
void WriteUInt64(ulong argint offsetbyte[] buffer)
    {
        if (
buffer == null)
            return;
        if (
offset buffer.Length 1)
            return;
        if (
buffer.Length >= offset sizeof(ulong))
        {
            
unsafe
            
{
#if UNSAFE
                
fixed (byteBuffer buffer)
                {
                    *((
ulong*)(Buffer offset)) = arg;
                }
#else
                
buffer[offset] = (byte)(arg);
                
buffer[offset 1] = (byte)(arg >> 8);
                
buffer[offset 2] = (byte)(arg >> 16);
                
buffer[offset 3] = (byte)(arg >> 24);
                
buffer[offset 4] = (byte)(arg >> 32);
                
buffer[offset 5] = (byte)(arg >> 40);
                
buffer[offset 6] = (byte)(arg >> 48);
                
buffer[offset 7] = (byte)(arg >> 56);
#endif
            
}
        }
    }
    public static 
void WriteStringList(List<stringargint offsetbyte[] buffer)
    {
        if (
arg == null)
            return;
        if (
buffer == null)
            return;
        if (
offset buffer.Length 1)
            return;
        
buffer[offset] = (byte)arg.Count;
        
offset++;
        foreach (
string str in arg)
        {
            
buffer[offset] = (byte)str.Length;
            
WriteString(stroffset 1buffer);
            
offset += str.Length 1;
        
}
}

and i am using this to get packet id and length in server :

PHP Code:
ushort PacketID BitConverter.UInt16(packet0);
ushort Length BitConverter.UInt16(packet2); 
PHP Code:
so i want to know how is the image packet class will go in server side ??

i am not sure of writeBites void in writer class ... and how to make it read specific image bytes to use this bytes to convert it to an image 
PHP Code:
        public static void WriteBytes(byte[] argint offsetbyte[] buffer)
    {
        foreach (
byte arg2 in arg)
        {
            if (
buffer == null)
                return;
            if (
offset buffer.Length 1)
                return;
            
buffer[offset] = arg2;
        }
    } 
abdeen is offline  
Old 01/15/2015, 18:27   #17
 
Super Aids's Avatar
 
elite*gold: 0
Join Date: Dec 2012
Posts: 1,761
Received Thanks: 950
Unfortunately C# arrays aren't dynamic and cannot change size or append by default. You have to allocate a new array and copy the old data into it long with the new.

Look into Buffer.BlockCopy or memcpy.
Super Aids is offline  
Thanks
1 User
Old 01/15/2015, 18:52   #18
 
abdeen's Avatar
 
elite*gold: 0
Join Date: Mar 2010
Posts: 475
Received Thanks: 15
Quote:
Originally Posted by Super Aids View Post
Unfortunately C# arrays aren't dynamic and cannot change size or append by default. You have to allocate a new array and copy the old data into it long with the new.

Look into Buffer.BlockCopy or memcpy.

any sample code ?

is the writeBytes void is valid ?
abdeen is offline  
Old 01/15/2015, 19:07   #19
 
Super Aids's Avatar
 
elite*gold: 0
Join Date: Dec 2012
Posts: 1,761
Received Thanks: 950
No it's not and msdn.
Super Aids is offline  
Thanks
1 User
Old 01/15/2015, 19:46   #20
 
elite*gold: 0
Join Date: Jul 2014
Posts: 402
Received Thanks: 540
Quote:
Originally Posted by Super Aids View Post
Unfortunately C# arrays aren't dynamic and cannot change size or append by default. You have to allocate a new array and copy the old data into it long with the new.
You could always use the
Best Coder 2014 is offline  
Thanks
1 User
Old 01/15/2015, 20:14   #21
 
Super Aids's Avatar
 
elite*gold: 0
Join Date: Dec 2012
Posts: 1,761
Received Thanks: 950
Quote:
Originally Posted by Best Coder 2014 View Post
You could always use the
Resize just allocates a new array and calls Array.Copy(), which is essentially the same as what I said. I don't know about the performance of Array.Copy() vs Buffer.BlockCopy() vs memcpy().
Super Aids is offline  
Thanks
1 User
Old 01/15/2015, 20:19   #22
 
abdeen's Avatar
 
elite*gold: 0
Join Date: Mar 2010
Posts: 475
Received Thanks: 15
i edited the write bytes to become like :

PHP Code:
public static void WriteBytes(byte[] argint offsetbyte[] buffer)
    {
        foreach (
byte arg2 in arg)
        {
            if (
buffer == null)
                return;
            if (
offset buffer.Length 1)
                return;
            
buffer[offset++] = arg2;
        }
    } 
is it valid ?

if so ... how to split packet in server when receive it and get only image bytes ?
abdeen is offline  
Old 01/15/2015, 20:36   #23
 
Super Aids's Avatar
 
elite*gold: 0
Join Date: Dec 2012
Posts: 1,761
Received Thanks: 950
Jfc.
Super Aids is offline  
Thanks
1 User
Old 01/15/2015, 20:53   #24
 
abdeen's Avatar
 
elite*gold: 0
Join Date: Mar 2010
Posts: 475
Received Thanks: 15
Quote:
Originally Posted by Super Aids View Post
Jfc.
Thanks
abdeen is offline  
Reply


Similar Threads Similar Threads
[VB] TCP Packet als Bytes senden
04/25/2014 - .NET Languages - 3 Replies
Guten Abend, ich versuche einem Server per TCP ein Packet für einen Request von meinen Accountdaten zu schicken, die benötigten Packets habe ich bereits gefiltert, analysiert und nachgebaut, einziges Problem ist, der Header des Packets, welches ich an den Server schicke ist ein Kauderwelsch wenn ich ihn als Ascii oder Dezimalzahl darstelle, das heißt er muss als ein Bytearray verschickt werden. Mein Problem ist jetzt, dass die anderen Daten als String gespeichert werden und ich zwar die...
How to parse Image Code Packet?
03/17/2012 - SRO Coding Corner - 2 Replies
My clientless get (opcode=2322) image code packet after login~ Does anyone know how to parse it and make it show on screen? Searched through the forum but lacking of such information~
(Winsock hook) replace/filter packet bytes
11/18/2010 - General Coding - 3 Replies
Hi guys Please, can someone explain me or help me about my winsock hook?! I need to change the first and second bytes of the packet I've received... example: I'm receiving the packet:
2 Bytes oder 4 Bytes ?
02/13/2010 - Kal Online - 3 Replies
Erm wenn ich nach cooldowns schaue für Mockery mit der UCE such ich dann mit 2 Bytes oder 4 Bytes ??
Interlude 11 bytes init packet wtf??
02/07/2008 - Lineage 2 - 0 Replies
Hello! in some interlude servers, first packet(init) length is about 11 bytes, when im expecting a more huge packet(about 186 bytes) containing: protocolVersion (Integer) sessionId(Integer) rsaPublicKey (byte) blowfishKey (byte) gg1 (byte) gg2 (byte) gg3 (byte)



All times are GMT +1. The time now is 22:11.


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.