[C#] DarkOrbit Encoding/Decoding from Netty

05/18/2013 13:39 Xdr1#1

Hello, today i bring you how to encode and decode the packets of the new darkorbit(which uses netty).

Dictionary:
Short - 2 bytes
Int - 4 bytes
Bool - 1 byte
Str or UTF - Short Length of String + String

The structure of the packets are:
1 - Short Length of all packet
2 - Short Packet ID
3 - Short version (normally 0)
4 - PACKET with shorts, ints, bools and strings (utf)


To encode/decode the bytes, you must use this functions:

And to read the packets or encode, you must use this 2 classes:

Example to use packetParser:
the first packet you receive from the client, apart from the policy, is id: 666.
To read:
Code:
int bytesRead = handler.EndReceive(ar);
if(bytesRead > 0)
{
    byte[] Body = new byte[bytesRead];
    Array.Copy(buffer, Body, bytesRead);

    packetParser packet = new packetParser(Body);
    if (packet.Id == 666)
    {
        Console.WriteLine(packet.ReadInt()); //Version Major
        Console.WriteLine(packet.ReadInt()); //Version Minor
        Console.WriteLine(packet.ReadInt()); //Version Build
    }
}
Example to use packetBuilder:
To respond to the version request (ID:666), you must build a packet like this:
Code:
packetBuilder enc = new packetBuilder(667);
enc.writeShort(0); // version
enc.writeBool(true);
enc.writeInt(0); //Version Major
enc.writeInt(0); //Version Minor
enc.writeInt(27); //Version Build

this.handler.Send(enc.GetBytes());
The Version Major, Minor and Build must be equal to which the client sent

SOMETHING INTERESTING:
To operate an upgraded server darkorbit is not necessary to start encryptions as ARC4 and IOW (InjectedObfuscationWrapper) because it are optional.

Credits
Me.
LittleJ.
05/18/2013 13:59 general_lolichdissdich#2
Also note the bitshifting and other obfuscations.
Also note that these functions are not just "these functions" but that "these functions" actually perform endianess conversion. That should help to understand it better.
Also note that using a "List<byte>" as a buffer for the "packetBuilder" class is inappropriate. For the sake of performance and correctness please use a different data structure or operate on streams for final victory and confirming to the .NET Framework programming style.
That being said "packetBuilder" becomes obselete, since you can simply create a endianness converting stream, conforming to the as3 spec of IDataOut-/Input.

Other than that, nice to see someone sharing code and thus information ;)
05/18/2013 15:26 V.I.R.U.S.#3
kapitan
05/18/2013 16:12 By-Soul#4
What is this?
What is the purpose?
05/18/2013 16:26 bestbots_support#5
the purpose is you must remove the line under your name
"C# Html Css Asp JavaScpt"
05/18/2013 17:28 Requi#6
Thanks, that you joined epvp :D