Basics and a little introduction to Netty
Quote:
You ever felt like coding something harder than 4.1? Or maybe well less complicated (For me ;p). Well I'm here to help you out about learning to read netty classes and coding an emulator to handle all the requests and responses =).
Starting from the bottom - How to read
Quote:
Well the real base is to get a swf and a decompiler. In this tutorial I will use the 7.5.3 SWF & FFDec.
*This tutorial isn't limited just to 7.5.3, it's valid for all the swfs except the newest ones with netty folder changed*
You probably have just opened the swf and asked yourself, what am I doing with my life? Well it's not that hard as it may seem, it's even easier than you thought. As of this part you gotta choose if to read the classes from the decompiler or from n++. I personally prefer to decompile all the files to flash and just read everything using notepad++.
So now we're going into the real part, reading the classes.
Head to the folder called net -> bigpoint -> darkorbit -> net -> netty -> commands.
As for today's tutorial I won't jump into handlers or encryptions so just use meanwhile a premade swf (from private server).
Well here is the beginning of reading the commands and parsing them. I already made a tool to do the job for me but I didn't have enough time to fully complete it. (You may find the download under the Downloads section.)
First thing you would like to do is take your emulator and get the first command you've received from the connection. As for me and everyone else on this world it is 666.
So what you do is simply press CTRL+F and jump into Find in files menu.
It should look something like this.
[Only registered and activated users can see links. Click Here To Register...]
(Instead of 666 put the command ID.)
And the result you get should be the following:
[Only registered and activated users can see links. Click Here To Register...]
The next thing you should look is the command's ID.
That is always sent first in case you want to send the command.Code:public static const ID:int = 666;
But as of today we're only reading it.Code:writeShort(ID); -- everything else --
Take a look at the last few lines,
It should look something like this.Code:protected function writeInternal(param1:IDataOutput) : void { param1.writeInt(this.major); param1.writeUTF(this.minor); param1.writeInt(this.build); }
Now when you read the command you should get int,string,int.
So for example you are using a basic parser.
Use that to output all the params received.Code:Debug.WriteLine(p.Id + " " + p.ReadInt() + " " p.ReadUTF() " " + p.ReadInt());
And that is the base of how to read the netty commands.
Converting classes to C#
Quote:
For this example I will use the NettyBase source as example, link is down below.
So you've got to the point of converting / creating your own commands?
Well now we gotta identify if the commands we're converting is a subcommand or not.
How do we do that?
In this example we will use VisualModifierCommand.
First thing we do is on Notepad++ [CTRL + F] -> Find in Files
*Make sure you've located the search into the netty/commands folder*
[Only registered and activated users can see links. Click Here To Register...]
and click 'Find All'.
If you see to it's called in class with name other than "VisualModifierCommand" you can know to this command is a sub.
So how do I convert a normal command?
So how do I convert a sub?
Normal Command
Sub CommandsQuote:
You can use the following template for creating a normal command:
So how can I get the command params?Code:namespace NettyBase.Net.netty.commands { class TestCommand { public const short ID = 0; // Command ID, Replace it. public static byte[] write() { var cmd = new ByteArray(ID); // Command params goes here // return cmd.ToByteArray(); } } }
At the bottom of the class there is
In this command for example we have 2 params, uid & newLevel and both of them are int.Code:protected function writeInternal(param1:IDataOutput) : void { param1.writeInt(this.uid); param1.writeInt(this.newLevel); }
That is how they should look in C#:
And the final command should look like that:Code:cmd.Integer(uid); cmd.Integer(newLevel);
Code:namespace NettyBase.Net.netty.commands { class LevelUpCommand { public const short ID = 32247; public static byte[] write(int uid, int newLevel) { var cmd = new ByteArray(ID); cmd.Integer(uid); cmd.Integer(newLevel); return cmd.ToByteArray(); } } }
Quote:
* To be continued *
Downloads & Others
NettyBase EmulatorQuote:
- [Only registered and activated users can see links. Click Here To Register...]
* I will add all the info needed to create a server, just give me some time.Quote:
So as you saw from above there is the NettyBase emulator. It is emulator that I created for helping everyone who wants to build his own 7.5.3 client emu.
I've also setup place to test your emulator instead of downloading xampp and htdocs and messing with all that stuff.
You can test your emulator here: [Only registered and activated users can see links. Click Here To Register...]
So to the main part of what this emulator does,
* It dumps all the packets that are not defined into a file called
* I've cleaned up some codes here and there and also added Parser & ByteArray so you won't have to deal with this when you code your server.Quote:
UndefinedCommands.dump
* I've made also login so you won't mess with the settings because they usually take tons of time to setup and much headache.
* I've coded also the LegacyModule (Old packets)
All you need to do in order to send an old packet ("0|asdasd") is
Atm I also started doing another tool that will help you order all the commands that you didn't define (NettyHelper) but as of now it's just a form so don't expect it to function.Code:client.Send(LegacyModule.write("0|asdasd"));
* If anyone would like to add something feel free to PM me and I will provide you with credit and add it into the post =).