Programming is the future, and if I can even get some of your interest because it happens to be related to a game you play, then that's just bonus points.
I'm thinking of doing this as a series of sorts, and I'll try to cover stuff that will be both generally useful in programming, as well as stuff that's specific to openkore and of course, ragnarok. If anyone wants to help out by suggesting topics they want covered (serious suggestions only please. you all know i have a short fuse) please do so. And if anyone wants to answer questions feel free to do so as well.
So first lesson would be the network packets. If you've played around with Wireshark or WPE Pro, you've probably seen something like this:
Code: Select all
00000000 76 0a 18 00 00 00 75 73 65 72 6e 61 6d 65 00 00 |v.....username..| 00000010 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................| 00000020 00 00 00 00 00 00 00 00 00 00 00 00 00 00 b9 2a |...............*| 00000030 20 24 a9 31 59 db f6 77 fa b7 35 66 a3 a2 06 81 | $.1Y..w..5f....| 00000040 e9 a5 16 63 9f dc 6d 7e 73 d7 55 d8 f8 00 0f 00 |...c..m~s.U.....|
But why do we call it 0x0A76 ? Why not call it 76 0a (the way it shows up in the network sniffer)? Why do we write it in reverse?
This is called Endianeness and most microporcessor code (stuff used by programming languages like C) come in the Little Endian format. See https://en.wikipedia.org/wiki/Endianness for a good explanation.
So there, we have packet 0x0A76 which is two bytes, packed in VAX byte order (aka Little Endian). https://apidock.com/ruby/Array/pack is a good reference for the various packing "formats" you can use. I know that OpenKore is in Perl, but Ruby gets a lot of inspiration from Perl so it has most of the powerful stuff that Perl has.
Another advantage of Ruby is that it's a bit easier to learn than Perl, so I'll be using Ruby for examples. Programming skills are transferable no matter the language, so don't get worried that you're wasting your time. You'll find that concepts are generally the same everywhere.
If you're feeling up to it, read up on http://openkore.com/index.php/Network_subsystem then come back here.
Okay, from that wiki article you'll know that the ragnarok network protocol (at least the older ones) came in "packets."
What's a packet?
Ask a Brazillian and they'll tell you the correct answer. It's basically a package of bytes. Bytes are just characters (like this wall of text). So they're like sentences in a language that only computers understand.
We have what we call internally in OpenKore as a "packet switch" although Message ID is a more appropriate name for it. The Message ID identifies a packet so the receiver knows what the package should contain. It's like the title of a book, or a label in a container.
There's a big problem though. TCP is a streaming protocol, meaning you never really disconnect from your partner. So if there are packets heading your way, how do you know when a packet ends and when a packet starts?
That's where `recvpackets.txt` comes in. This file is a table of packet lengths; it basically acts as a measuring type to find out where to cut the stream so we know we have a complete packet. If the lengths are wrong, then we won't be able to cut the stream in the correct place, and kore will get confused.
Next time we'll talk about AES-128, Rijndael, symmetric encryption, and why you shouldn't play ragnarok using free wifi hotspots.