FORUMS
Remove All Ads from XDA

Introduction to Hexing, Programming, and General Game Modding

1,063 posts
Thanks Meter: 282
 
Post Reply Email Thread
I have posted this on a few other places so I figured I'd post it in the best site around. I think it fits here because the principles can be easily transferred over to other things since instead of teaching you a specific way to do something it will teach you a specific way to think and look at a problem. Now without further ado here it is.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
This will be an introductory guide for basic principles used to mod gamesaves and generally useful programming skills such as hex-editing, retrieving the gamesave, basic automation principles, concepts, and the like. Anyone with experience is welcome to post. This should be as comprehensive as possible. If you see an example of code in one language and know the equivalent in another language (you see c++ code and know the VB equivalent let's say) please quote the original code and post your port. Please post all code in code tags.

Example of ported code:
Quote:
Originally Posted by Example

Quote:
Originally Posted by dudeguy105

Here's how to read a file in c++

Code:
#include <stdio.h>
int main ()
{
  FILE * pFile;
  pFile = fopen ("myfile.txt","r");
  
  return 0;
}

Here's how you read one in autoit
Code:
#include <File.au3>
$sContents = FileOpen("myfile.txt",0)

 
 
19th March 2012, 08:20 PM |#2  
dbzfanatic's Avatar
OP Senior Member
Thanks Meter: 282
 
Donate to Me
More
What You'll Need

  • A hex editor - I recommend Hex Workshop but any will work.
  • A gamesave of the game you wish to modify (if making a SE)
  • A JTAGed 360 (if modifying core files)
  • A method to put your gamesaves back on your device (USB drive is easiest)
  • A good grasp of numbers or the ability to "wing-it"
  • A copy of the game or program you wish to modify (obviously)
  • Cheat Engine (for use with modifying non-online PC games)(reinforce basic concepts)
  • Large quantities of Caffeine


Legend:
360 Specific Requirement
Normal Requirement
Recommended but not required
19th March 2012, 08:21 PM |#3  
dbzfanatic's Avatar
OP Senior Member
Thanks Meter: 282
 
Donate to Me
More
Basic Concepts

  • Read the display of your hex-editor
  • Retrieve, modify, and replace gamesaves
  • Modify values in memory (either RAM or dump (aka gamesave)
  • Automation Fundamentals
  • Standard GUI Practices
  • Programming
  • More I can't think of at the moment :P
19th March 2012, 08:21 PM |#4  
dbzfanatic's Avatar
OP Senior Member
Thanks Meter: 282
 
Donate to Me
More
Basic Terminology

Gamesave - A game's save-data
JTAG - 1)A method of modifying an xbox360 or other JTAGable hardware to run unsigned code and send/receive serial data 2)A JTAGed xbox360/system
360 - an xbox360
RAM - Random Access Memory, your computer's memory.
Hex-editor - A program that opens and displays a file's binary content for editing.
GUI - Graphical User Interface, a "face" for a program with buttons sliders and the like.
UI - User Interface, how a program is displayed and interacted with.
Console - 1)A gaming console 2)Command prompt or shell/bash/terminal 3)A UI, normally a rectangle with white text on a black background to accept a user's input through typing.
Plain-text - refers to readable language. "This is plain text", "LZAK AK FGL" (this is not)

will add more as needed
19th March 2012, 08:22 PM |#5  
dbzfanatic's Avatar
OP Senior Member
Thanks Meter: 282
 
Donate to Me
More
Next question. "What do the values displayed in the editor mean/represent, how do you know if a displayed value is one you need, and how do you search for a specific value?" That's a question that brings up 3 good points.

What do the values displayed in the editor represent?:
The numbers you see are the hex contents of the file that you opened. Hex is a numerical system, and is often used to represent binary values. What you're seeing in the editor is actually the content of the file on the most basic level, binary, displayed in a more readable fashion.
Binary:
Code:
0,1,10,11,100,101,110,111,1000,1001,1010,1011,1100
Decimal:
Code:
0,1,2,3,4,5,6,7,8,9,10,11,12
Hex:
Code:
0,1,2,3,4,5,6,7,8,9,A,B,C,D,E,F
Most of us are used to decimal, not hex or binary. If most people saw a file's binary content displayed in binary their brains would explode :P. Hex shows us the binary content in a very clear,concise way, and it can represent number and letters. This makes it the perfect choice to display binary, which also represents numbers and letters.

How do I know if a displayed value is one I need?:
For the most part you will be beginning your search looking for numbers you already know. Say you have 10,000 gold in a game. You would search for "2710", which is 10,000 in hex. You may find more than one result, you may find none. If you find more than one change one, save the changes, test the save, and see if your gold changed. If not revert your save back to the original and change the next in the series until you find the one that works. If you do not find any results then there is some sort of encryption on the file. Many times it's simply a math operation. Your game may save your value as 80,000(13880) instead of 10,000(2710) because it's less obvious. If you find only one result, chances are that's the value you need to change.

How do I search for a specific value?:
That really depends on your specific hex-editor, but most you can simply press ctrl+f and it will open a search window.

You also don't need to know any programming to start this, we'll get into that later. Pick the language that best suits your needs and works for you. Some like C#, some like c++, some like VB, and I like autoit.
19th March 2012, 08:23 PM |#6  
dbzfanatic's Avatar
OP Senior Member
Thanks Meter: 282
 
Donate to Me
More
Decrypting is a real pain in the ass, at least for me. A good way to tell if something is encrypted is if you don't see any plain-text in the save file. If you do it's probably not encrypted, maybe it just has a checksum. Decryption isn't really my specialty but I do know a bit about basic ciphers. I'm assuming most people who read this will at least know what encryption is so I don't need to explain that or how it works. Maybe someone with more decryption experience than myself can post more info but for now I'll stick to examples that don't use any real encryption, just checksums or no security. If there is encryption on the save file the easiest way is to get 2 or 3 saves that have no difference but what you're looking to change (such as gold). Just load those into your hex editor and do a file compare, you should see the areas that are different. Normally values for most things in games (stats, gold, items, etc) won't be too large. If you see a large difference then there are 1 of 2 possibilities. 1) If the chunk is somewhat large but not the entire file that's probably a checksum area. 2) If the entire file is different even though only one value changed then the encryption uses something as a seed (probably the checksum) so the encryption algorithm is the same but the output is different every time.
19th March 2012, 08:24 PM |#7  
dbzfanatic's Avatar
OP Senior Member
Thanks Meter: 282
 
Donate to Me
More
Actually I thought I mentioned the file compare method on here already :P. That's a method, also the most common, to find the values you need if the straight "search for them" method doesn't work. If you could read team names at all that means there's no encryption, I posted a bit more info about that in a previous post with an example of plain-text and basic encryption. I'm glad this is what you were looking for. Ok on to the next topic.

How to Hex
Most people think hexing is a really daunting task. It isn't. I actually already explained most of what you need to know in post #9 but I'll go over the basics again. Once you open a file in your hex editor you should see something like this on one side (the left usually)
Code:
0D 0A 3C 21 2D 2D 20 2A 2A 2A 2A 2A 2A 2A 2A 2A 2A 2A 2A 2A 2A 2A 2A 2A 2A 2A 2A 2A 2A 2A 2A 2A 2A 2A 2A 2A 2A 2A 2A 2A 2A 2A 2A 2A 2A 2A 2A 2A 2A 2A 2A 2A 2A 2A 2A 2A 2A 2A 2A 2A 2A 2A 2A 2A 2A 2A 2A 2A 2A 2A 0D 0A 54 68 69 73 20 63 6F 64 65 20 73 68 6F 75 6C 64 20 62 65 20 70 6C 61 63 65 64 20 69 6E 20 74 68 65 20 68 65 61 64 65 72 20 6F 72 20 69 6E 20 61 20 43 53 53 20 66 69 6C 65 2E 0D 0A 49 74 20 63 61 6E 20 62 65 20 6D 6F 64 69 66 69 65 64 20 74 6F 20 6D 61 74 63 68 20 74 68 65 20 61 70 70 65 61 72 61 6E 63 65 20 6F 66 20 74 68 65 20 72 65 73 74 20 6F 66 20 74 68 65 20 73 69 74 65 2E 0D 0A 2A 2A 2A 2A 2A 2A 2A 2A 2A 2A 2A 2A 2A 2A 2A 2A 2A 2A 2A 2A 2A 2A 2A 2A 2A 2A 2A 2A 2A 2A 2A 2A 2A 2A 2A 2A 2A 2A 2A 2A 2A 2A 2A 2A 2A 2A 2A 2A 2A 2A 2A 2A 2A 2A 2A
and on the other you should see what that represents, in this case it's some html
Code:
..<!-- ***************************************************************..This code should be placed in the header or in a CSS file...It can be modified to match the appearance of the rest of the site...*******************************************************
If the right side is easily readable like it is here, there's no encryption. If it looks something like
Code:
A2e76f!_   #[email protected]      .........    emishUGLhvEEas~_
then it's probably encrypted. You need to look carefully though since some things may seem encrypted at first glance but really aren't like
Code:
sysSettings1sysSettings2sysSettings3.........weapon_023464........63
In this example you can see that system settings 1, 2, and 3 are unlocked and the player has 99 (which is 63 in hex ) of the item "weapon_023464". They won't always be this easy to read but this shows my point quite well. If we wanted to unlock system setting 4 in this example the first thing to try would be to change the right side (the "readable" side) to
Code:
sysSettings1sysSettings2sysSettings3sysSettings4.........weapon_023464........63
rehash/resign, load it back and see if it works. If it doesn't then the next method to try would be to find a savegame that already has it unlocked and compare the two. Let's say the save with it unlocked looks like this
Code:
sysSettings1sysSettings2sysSettings3sysSettings_04.........weapon_023593........03
We can clearly see that they changed the naming on menu 4. So all we need to do is change our modified file to
Code:
sysSettings1sysSettings2sysSettings3sysSettings_04.........weapon_023464........63
rehash/resign and load and all should be well.

"Oh but that's easy, what if the file is encrypted then what do I do?" I know some of you are thinking this. Well that's where the file-compare method comes into play again. Say we have 2 saves that look like this.
Quote:
Originally Posted by save1

Hex:

Code:
61 6f 66 66 6f 69 68 39 68 28 2A 47 48 28 4F 48 28 51 32 6f 39 68 79 39 20 20 20 20 20 20 2e 2e 2e 2e 2e 2e 2e 2e 2e 2e 20 20 20 66 32 30 6A 66 6A 61 66 30 71 39 33 32 77 40 30 39 31 30 31 20 20 20 30 31 32 33 34 35 36 37 38 39 30 31 32 33 34 35 36 37 38 39 20 20 20 20 20 20 20 6A 61 68 44 26 40 6E 66 64 69 77 5F 44 5F 7E 6A 66 75 77 68 21 2e 2e 2e 2e
Text:
Code:
aoffoih9h(*GH(OH(Q2o9hy9      ..........   [email protected]   01234567890123456789       

jahD&@nfdiw_D_~jfuwh!....

Quote:
Originally Posted by save2

Hex:

Code:
39 37 66 32 30 61 76 4E 68 28 2A 47 48 28 4F 48 28 51 32 6f 39 68 79 39 20 20 20 20 20 20 2e 2e 2e 2e 2e 2e 2e 2e 2e 2e 20 20 20 66 32 30 6A 66 6A 61 66 30 71 39 33 32 77 40 30 39 31 30 31 20 20 20 30 31 32 33 34 35 36 37 38 39 30 31 32 33 34 35 36 37 38 39 20 20 20 20 20 20 20 6A 61 68 44 26 40 6E 6A 44 46 45 64 20 20 6B 24 61 75 44 6E 7A 21 2e 2e 2e 2e
Text:
Code:
97f20avNh(*GH(OH(Q2o9hy9      ..........   [email protected]   01234567890123456789       jahD&njDFEd  k

$auDnz!....

We can see some similarities and some differences. Notice they both have "01234567890123456789" in them in the same place and they both end with "!....". The first 8 letters are different though and some of the middle is different. A safe assumption is usually if something changes at the very beginning of the file or at the very end it's a potential checksum. I'll explain more about those later. Say we only changed our stat for gold in the game between the two saves we have. Since we think the first change is a checksum that means the second change must be our gold number. Now we have no idea what the encryption method is at the moment but we do know how much our gold was and is and where in the file it's saved now. So we keep that information handy and build up our gold to an ungodly amount through work or cheats, save, and open the file. It now looks like this.
Quote:
Originally Posted by save3

Hex:

Code:
38 61 66 6A 77 21 5F 20 68 28 2A 47 48 28 4F 48 28 51 32 6f 39 68 79 39 20 20 20 20 20 20 2e 2e 2e 2e 2e 2e 2e 2e 2e 2e 20 20 20 66 32 30 6A 66 6A 61 66 30 71 39 33 32 77 40 30 39 31 30 31 20 20 20 30 31 32 33 34 35 36 37 38 39 30 31 32 33 34 35 36 37 38 39 20 20 20 20 20 20 20 6A 61 68 44 26 31 64 75 76 6E 20 41 45 46 6E 20 20 5F 2E 2E 32 21 2e 2e 2e 2e
Text:
Code:
8afjw!_ h(*GH(OH(Q2o9hy9      ..........   [email protected]   01234567890123456789       jahD&1duvn AEFn  

_..2!....

We can clearly see that the same two places have changed. First thing to try (shot in the dark) is take the area we think is gold and put it in our first save. That would make it look like this
Quote:
Originally Posted by Modded_save

Hex:

Code:
61 6F 66 66 6F 69 68 39 68 28 2A 47 48 28 4F 48 28 51 32 6f 39 68 79 39 20 20 20 20 20 20 2e 2e 2e 2e 2e 2e 2e 2e 2e 2e 20 20 20 66 32 30 6A 66 6A 61 66 30 71 39 33 32 77 40 30 39 31 30 31 20 20 20 30 31 32 33 34 35 36 37 38 39 30 31 32 33 34 35 36 37 38 39 20 20 20 20 20 20 20 6A 61 68 44 26 31 64 75 76 6E 20 41 45 46 6E 20 20 0D 0A 0D 0A 5F 2E 2E 32 21 2E 2E 2E 2E
Text:
Code:
aoffoih9h(*GH(OH(Q2o9hy9      ..........   [email protected]   01234567890123456789       jahD&1duvn AEFn  

_..2!....

We ignore the possible checksum for now, rehash/resign and load it up to see if it works. To our shock it does! Our gold has jumped but everything else is exactly the same as the first save so we think to ourselves "what else could have changed between those two saves I had first?" The answer is simple. The time. The first few bytes of our file are our gameplay time. There are games that use checksums and if the edited save doesn't load up then that game probably does. This example was just to get you into basic hexing, not bypassing game security. If this made your head explode, please get a bucket and try again :P. It gets easier, I promise. Just re-read this a few times, eventually it will "click" and you'll understand.


Edit: Just in case my way was a bit difficult to understand I found another explanation posted by Emerald Lance, it's the same info just worded a bit differently. Maybe you can understand this one if you can't understand mine.
Quote:
Originally Posted by Emerald Lance

Hex editing can indeed be a daunting task for beginners. When I first started, I remember that it just looked like a swirl of coded nonsense. But there are only two things you need to get started: a hex editor, and knowledge on how to count in hex.

If you're talking about modding 360 game saves, programs like Modio and Horizon have a hex editor built in, so we'll skip that part. Assuming you don't know how to count in hex, this is the general basic concept. When you normally count, you go 0-9, and then it starts again as the zero of the next series of numbers, in this case 10-19, then 20-29, and so on. In hex, you count from 0-F; instead of going on to 10 after 9, you go from 9 to A. In hex, A means 10, and F means 15, so in hex 10 means 16, and so on. A lot of people starting off have a bit of trouble understanding at first, but you'll get it sooner or later; I learned by trying to count in hex in my everyday life, and by studying how color sliders that went up to 255 were different than the ones that went to FF (there is no difference, just decimal vs hex). Of course, this is assuming you don't already know how to count in hex.

While much of the hexing process is just changing values, you gotta know where those values are in in order to change them. Every game is different, so this is important. There are two methods you should be familiar with: Ctrl+F, and comparison. Let's say you want to edit a character's HP stat. While playing the game, take note of what it is. Let's say it's 590. Right it down and use a hex calculator (Windows has one that comes with it) to find out what it is n hex; in this case, 590 = 024E. Remember to add a 0 at the beginning of values that have an odd number of digits, since hex is in bytes (two digit values) and it helps make sure you don't get a bunch of values you don't want. Now, in your hex editor, hold the Ctrl key and press F, then type in the hex value you want to search for.

It isn't uncommon for the search to turn up multiple hit, especially when searching for lower (and by proxy, more common) values. When this happens, you need a comparison. Play the game normally and do something to change the value you want to edit, in HP's case I guess level up once. Take note of the new HP value in hex, and repeat the Ctrl+F process with this new save. Let's assume you're new hex number is 02D6. Since the only instance of 024E that changed was HP, then that should be the only instance that is now 02D6. Look for 02D6 now, and find the place where it sits that 024E used to sit. It's easiest to do this when you have both old save and new save open at once; you can also write down each address if there aren't a lot of instances. Once you find the value (and know that it's HP) change it to whatever you like. It can be sometimes risky to edit games with a maximum value of 9999 (270F in hex) to higher than their maximum, but in most games it works fine. Now just remember to resign/rehash the save (again, programs like Modio and Horizon do this) and inject it into your drive.

There are a few things that can go wrong with just simple hexing. While most older games can just be edited easy, newer or more popular games often have some measures put in place by the developer just to make sure it isn't hacked. The game save could be compressed or encrypted (will essentially show gibberish until decompressed or decrypted) or could have a checksum (a little line of encrypted code that changes every time values change during gameplay; if the values don't match the checksum, you get a corrupt save). Just remember that not everything can be edited with just hex knowledge alone.

Believe it or not, this is all there is to know (that can be taught) about hexing. Everything else is just picked up as you go, including better understanding of hex as a language (as opposed to just a number system). I hope this helps, and I hope it gets you started on your hacking way.

19th March 2012, 08:24 PM |#8  
dbzfanatic's Avatar
OP Senior Member
Thanks Meter: 282
 
Donate to Me
More
Basic Game Security

As has been said before, many games have some sort of security be it encryption, a checksum, some mathematical manipulation, or a combination of these. The easiest (and the one I will be discussing first) is mathematical manipulation.

Mathematical Manipulation:
Even the name sounds imposing huh? :P Well it isn't as scary as it sounds. All it means is that the value we're looking for has had some math done to it. Say we're looking for our gold which is 100. We look through our saves but don't find any values of 100 but we know that it isn't encrypted because we can read it. Well we go through the file compare method and find a value that changed when we got another gold. The values that were changed are 800 and 808. We know that our gold values are 100 and 101 and this is the only thing that changed so they must correspond. This allows us to realize "hey, all they did was multiply our value by 8". That's mathematical manipulation and is quite easy to implement. For the more code-savy of you I will give an example code that could be found in-game.

Autoit:
Code:
$iVal = 800
$iGold = $iVal/8
GUICtrlSetData($txtGoldVal,$iGold)
C++:
Code:
int iVal = 800;
int iGold = iVal/8;
printf(iGold)
All this code does is take the value (800) and divide it by 8 to show you your real gold value. Since the game would add in increments of 8 for every gold piece we wouldn't find the display value (100) but only the real value of 800. Now onto checksums ^_^.

Checksums:
Checksums are bits of data that the game reads before the save is loaded to verify that it hasn't been tampered with. Some common checksums are the SHA1 or MD5 value of the data (not including the checksum itself of course), a proprietary key (such as the PSV header of a PSP's PS1 savegame), or sometimes even something as simple as your profileID. Most checksums are found at or close to the beginning of the file. Since it's the first thing read to verify security it makes sense that it would be there, but sometimes it's at the end of the file in an attempt to throw us off. Going back to our original example of "sysSettings1sysSettings2sysSettings3.........weap on_023464........63" we know the hex is
Code:
73 79 73 53 65 74 74 69 6E 67 73 31 73 79 73 53 65 74 74 69 6E 67 73 32 73 79 73 53 65 74 74 69 6E 67 73 33 2E 2E 2E 2E 2E 2E 2E 2E 2E 77 65 61 70 6F 6E 5F 30 32 33 34 36 34 2E 2E 2E 2E 2E 2E 2E 2E 36 33
but in our savegame we see
Code:
6d ed b1 c4 ff 91 39 9c 75 b4 bc fe fe 0e 69 63 73 79 73 53 65 74 74 69 6E 67 73 31 73 79 73 53 65 74 74 69 6E 67 73 32 73 79 73 53 65 74 74 69 6E 67 73 33 2E 2E 2E 2E 2E 2E 2E 2E 2E 77 65 61 70 6F 6E 5F 30 32 33 34 36 34 2E 2E 2E 2E 2E 2E 2E 2E 36 33
We can clearly see that "6d ed b1 c4 ff 91 39 9c 75 b4 bc fe fe 0e 69 63" is before the actual data we want but we don't know that that is because on the "readable" side of our editor it looks like this "m.....9.u.....ic". What do we do in this situation? Well first we swear, then we see if it matches up with any of the "common" checksums. We try the SHA1 of our data which is "fbce6651fad6a8461c9bc0751cf153dd044addb". Nope, not that one. We try the MD5 which is "6dedb1c4ff91399c75b4bcfefe0e6963", hmm...let's spread that out. "6d ed b1 c4 ff 91 39 9c 75 b4 bc fe fe 0e 69 63", bingo exact match. Now we know that it uses an MD5 hash of the data as its checksum. All we need to do if we change something is recalculate the MD5 value. There are several ways to do this an I won't go into specifics (google is your friend). Following our old example let's say we wanted to unlock menu 4. We would set our data to "sysSettings1sysSettings2sysSettings3sysSettings_0 4.........weapon_023464........63" and get the MD5 which is "388ff38b741b00fbbd1fc84f69362002". Now all we do is insert our new checksum in place of the old one to make our hex data look like this
Code:
38 8f f3 8b 74 1b 00 fb bd 1f c8 4f 69 36 20 02 73 79 73 53 65 74 74 69 6E 67 73 31 73 79 73 53 65 74 74 69 6E 67 73 32 73 79 73 53 65 74 74 69 6E 67 73 33 73 79 73 53 65 74 74 69 6E 67 73 5F 30 34 2E 2E 2E 2E 2E 2E 2E 2E 2E 77 65 61 70 6F 6E 5F 30 32 33 34 36 34 2E 2E 2E 2E 2E 2E 2E 2E 36 33
Notice how our checksum is at the very beginning? It's the same place as the original checksum we found. We never want to put it in another location. We always want to keep the data as close to the original as possible so we don't break our game or get a corrupted save.

Proprietary Checksums:
These are a bitch. I'll be honest I don't know how to crack stuff like this so the best bet is to wait until someone figures it out or get help if you don't already know how. I'll give an example anyway. Using the same example we see our hex data as
Code:
fd fc 0c f4 4d b7 cf 1b 87 e6 78 46 58 ea 3b 04 73 79 73 53 65 74 74 69 6E 67 73 31 73 79 73 53 65 74 74 69 6E 67 73 32 73 79 73 53 65 74 74 69 6E 67 73 33 2E 2E 2E 2E 2E 2E 2E 2E 2E 77 65 61 70 6F 6E 5F 30 32 33 34 36 34 2E 2E 2E 2E 2E 2E 2E 2E 36 33
which means our checksum is "fd fc 0c f4 4d b7 cf 1b 87 e6 78 46 58 ea 3b 04". We run our data through the more common checksums and even some others we find out about through searching but we don't find any publicly available method of making the same checksum. First thing to try is leave the checksum alone and still change your data, then load it up and see if it runs. If it does then it's probably just an identifier, if it doesn't then it really is a checksum and we need help.

Encryption:
I've already talked about encryption :P. It's basically a type of mathematical manipulation but on a larger scale than just our data (for the techies more than just on variables/userdata). Normally they have an algorithm, a mathematical formula, that they run the entire save file through to make it totally confusing and unreadable. Well, if the game can read it so can we right? It's just a matter of figuring out how it works. Using our standard example I'll show you some very basic encryption. We already know what the hex of the file should be, but under encryption it looks like this
Code:
88 94 88 68 80 89 89 84 21 82 88 46 88 94 88 68 80 89 89 84 21 82 88 47 88 94 88 68 80 89 89 84 21 82 88 48 88 94 88 68 80 89 89 84 21 82 88 20 45 49 17 17 17 17 17 17 17 17 17 92 80 76 85 21 21 20 45 47 48 49 51 49 17 17 17 17 17 17 17 17 51 48
which translates on the "readable" side to
Code:
X^XDPYYTRX.X^XDPYYTRX/X^XDPYYTRX0X^XDPYYTRX-1\PLU-/013130
.
Gibberish right? Well we don't know the encryption algorithm so we're stuck with using the filecompare method and hoping they don't also have a checksum.


In all of these examples when data would be loaded onto your 360 you would need to rehash/resign your save somehow (Modio, Horizon, etc) to make sure the 360 recognizes it as proper data, even if the game won't. These are the basic concepts behind checksums. Simple(ish) right? :P

P.S. For those of you interested here's the basic encryption program I whipped up for this example. It just reads the binary values one-by-one and adds F to them but hey it works. It's written in AutoIt.
Code:
#include <file.au3>

Dim $i, $string, $hex
$file = FileOpen("test.txt",16)

$num = FileRead($file)
$num = @extended
While $i < $num
    FileSetPos($file,$i,0)
    $data = FileRead($file,1)
    $data = StringReplace($data,"0x","")
    $new_data = $data + 0xf
    $hex &= $new_data & " "
    $string = $string & ChrW($new_data)
    $i += 1
WEnd
MsgBox(0,"",$hex)
MsgBox(0,"",$string)
19th March 2012, 08:25 PM |#9  
dbzfanatic's Avatar
OP Senior Member
Thanks Meter: 282
 
Donate to Me
More
Basic Programming Ideas and Principles

Ok first a bit of terminology so people don't get too confused.
Variable - A variable is a storage device for data. Variables have certain types. They are:
  • Char - a single character or number (0-9,a-z,etc)(1 byte)
  • Integer - A whole number (2-4 bytes)
  • String - Text. Words. You know, language :P
  • Array - A variable containing other variables or multiple data sets/types.
  • Vector - Expanding/contracting array
  • Double - Can have decimals (8 bytes)
  • Float - Can have decimals (4 bytes)
Function - A piece of code that performs a single, specific task.
Data - information
Code - ...duh...
Parameter - A function-specific variable. Takes input to use in the function.
Loop - a piece of code that continues until certain conditions are met
Infinite Loop - never stops
Event - notifies the program and the OS that something happened.
Control - Something a user interacts with, such as a button, radiobutton, checkbox, etc


Now that that's out of the way lets get into the basics. "What is programming?" It's making a machine do what you tell it :P. There are different programming languages just like there are different spoken languages. Different ways of expressing the same idea. My preferred language is AutoIt (as I've stated before...I think) since I'm more familiar with it than anything else right now. "Which language is the best to use?" Well they all have merit, find the one you like the best and go for it. "Are you going to teach us a language?" No, I want you to find the language that you like best and learn it for yourselves. The ideas will carry over regardless of what the language is as long as you have a good grasp of what's going on.

Hello World
This is the most basic program for any language (at least any I've seen). Normally all it does is open a console/terminal window with the words "Hello World". Even in this basic example you're already learning valuable lessons. How to structure the code, how to open a console window, how to output text. These will all be used quite a bit at first, then the only one that will fade will be the console window as you move into GUIs.

Ok now onto something more advanced/useful, Loops. "When would I use a loop?" You would use a loop when you need something to happen over and over again, such as the main body of your program or a check for something (different value, specific value, button press event, etc). Loops are very common and make things much easier. If some data changes all you need to do is call your function again using the new data. Instead of doing this manually a loop could be set up. In this loop we would want to check for a change in the data (so as not to call the function needlessly and waste time) and if something changed then call the function with the new data. Loops also keep our program running, you don't want your program to just flash for 1/10th of a second do you? :P
There are a few basic types of loops. The For loop, the Do loop, and the While loop.
  • The For loop is usually used to do things a set number of times. Each time the loop goes through it adds a specific value to a variable (usually 1 but sometimes more. It can also be a negative number effectively counting down). After the loop has gone through the number of times its supposed to it then moves on to the next chunk of code.
  • The Do loop runs until certain conditions are met. These conditions could be any number of things, just use your imagination.
  • The While loop runs while something is happening. It's similar to the Do loop in that it runs until a condition is met, but that condition is always "until *condition* stops". You will see "While 1" a lot, that simply says "while the program is running" (effectively). It actually means "While 1=1" which will never change. This is an infinite loop, a loop that will never stop on its own. If we want it to stop we have to stop it explicitly.


Now that you know what functions and loops are it's time to explain events in a bit more detail. Events are pieces of code that run when something specific happens. Your OS (operating system, windows linux mac etc) has events built-in that it executes all the time. As an example whenever your mouse is clicked an event is sent to the main OS telling it a button was clicked, where it was clicked, and what button it was. Sometimes we want to capture these events and have our own code executed as well as or sometimes instead of the main OS code. Sometimes the main OS event is just a notification, it tells everything that something happened and doesn't do anything else. If we make a program with a button but don't have any functions tied to it then an event will still be triggered but it will simply tell the OS and other programs a button was clicked. When we tie code into our controls all we're really doing is setting a specific event as the trigger for our code, the condition for it.

Well that's pretty much it for basic principles. This should get you started and at least able to do pseudo-code (stuff that looks like code but really isn't). Here's an example of some pseudo-code.
Code:
if *something happens* then *send an alert*
19th March 2012, 08:25 PM |#10  
dbzfanatic's Avatar
OP Senior Member
Thanks Meter: 282
 
Donate to Me
More
Writing Code

Before we get into the actual code writing I want to discuss a few things. Most of them are just tips to make things easier and more readable, especially if you're not the only one working on it.

Naming Conventions
This is simply how you name things. Function names should be pretty obvious and easy to read. If a function reads hex data call it something like ReadHex or HexRead. Variable names should be just as obvious and should tell you what type of variable it is just by the name.
  • Arrays - start with a (aArray)
  • Strings - start with s (sString)
  • Integer - start with i (iInteger)
  • File - start with f(no floats) or fi(floats)(fFile, fiFile)
  • Pointers - start with p (pPointer)
  • Double - start with d (dDouble)
  • Edit Boxes - start with edt (edtEdit)
  • Text boxes/Inputs - start with txt (txtInput)
  • Buttons - start with btn (btnButton)
  • Sliders - start with sld (sldSlider)
  • Combo box(dropdown menu) - start with cmb (cbmCombo)
  • Menu - start with mnu (mnuMenu)
  • List boxes/TreeViews - start with lst (lstTreeview)
  • Checkboxes - start with chk (chkCheckbox)
  • Radio button - start with rdo (rdoRadio)
  • Labels - start with lbl (lblLabel)
  • Groups - start with grp (grpGroup)

This will make your code more readable to an extent, and if you break things apart properly that will make it even easier.

Readability:
You always want your code to be readable, if for no other reason than you don't want to forget what something does. If you are working with another coder you definitely want to have readable code, otherwise there will be a lot of time wasted trying to figure out what portions of code do when it would be obvious if it were more readable.

Comments are a good way to improve readability of code, as is breaking code into chunks. Breaking code up should have a negligible effect on speed, if any at all. Here's an example to illustrate my point.
Quote:
Originally Posted by bunched

Autoit:

Code:
$sData = Bin(Hex(Asc("a")))
C++:
Code:
binaryWriter->Write(binaryReader->ReadByte());

Quote:
Originally Posted by readable

Autoit:

Code:
$sData = Asc("a")
$sData = Hex($sData)
$sData = Bin($sData)
C++:
Code:
sByte = binaryReader->ReadByte();
binaryWriter->Write(sByte);

I know these examples aren't great but they do illustrate my point. In the first it's a bit jumbled and somewhat hard to understand what's going on immediately. In the readable version it's clear as to what is happening in the code and in what order. Order does play a key role in coding so it's important to always know what order things happen in. In the autoit example we are taking the ascii value of "a", converting that to hex, then converting that to binary. The example is fairly easy to read but there will be times when things are nested (get to that in a moment) in such a way that it's almost impossible to read. That's why you want to break the code apart, so as to avoid confusion for yourself and anyone else reading your code.

Nested Statements:
Nested statements are basically just statements within other statements. A for loop inside a while loop, a function calling another function (this one happens a lot), etc. More than likely you will use nested statements at some point. This is fine as long as you maintain readability. Always make sure you keep your indentations consistent, a nested statement should be indented one place more than the previous statement. If you have a statement that has 3 parts, 2 nested, there should be 2 indentations. This (broken record :P) maintains readability and makes it simpler to find the portion of code you're looking for. Most compilers/editors do this for you but sometimes not, just make sure everything is there.

Writing Functions:
As I've said before you want your functions to do only one thing, and do it well. Sometimes it's a bit difficult to separate different portions of code into functions but it helps. If you just need part of the code later on it's much better to have it in its own function than to have to run through an entire other function to get to the part you need. This improves speed and efficiency. Take your time, plan out how you want things to flow, and if nothing else wing it. Try different ideas and see what works and what doesn't. I know there are others out there who do their best work when semi-conscious or fully asleep (yes I dream about coding sometimes -_-) but that allows you to think of solutions you normally never would. If you can't get past a roadblock try taking a nap or just plain sleeping. A fresh set of eyes will help with projects, sometimes you need to ask a new coder to look over it and sometimes you need a veteran. Since new coders don't know much yet they often only find obvious errors that we overlook such as an error in syntax or a typo. Veteran coders know a lot and they can help us think of new solutions as well as possibly tell us why what we try doesn't work. When you finally get a function working, look it over. See if there's a way to break it down into even smaller functions.

more soon
19th March 2012, 08:26 PM |#11  
dbzfanatic's Avatar
OP Senior Member
Thanks Meter: 282
 
Donate to Me
More
Tying Code and GUI Together

Ok now that we have our code working it's time to make it look pretty. Some people can use a console fairly well,some can barely click a button lol. We want our programs to be as user-friendly as possible, thus we need a GUI. This should actually be the easiest part of the project since we already have our code. As I said before the code should be in functions so it's just a matter of tying those functions into events. Whenever a user does anything and I mean anything it triggers an event, be it clicking or moving a mouse, pressing a key, or sometimes even just sneezing on the screen (or maybe that's just me lol). We only need to capture certain events such as a button being clicked or a slider being moved usually so that's what I'll focus in terms of controls.

Designing the GUI
First thing we do is open up our favorite form designer. There are designers for most languages so if you don't have one just google, you're bound to find one. Design your GUI in this (place buttons, sliders, text boxes, labels, etc) then get the code for it. Make sure when you're designing your GUI anything that needs to be interacted with (buttons, sliders, etc) have an event set off when they're clicked/changed. Most form designers have an option to import the code directly into your editor/compiler so just do that if you can.

Integrating Functions and Events
Ok now that we have our code and our GUI code we can put the two together. Since all our important stuff is in functions and we can call it whenever we need all we need to do is put our function calls inside our event triggers. Here's an example in autoit of code that calls our custom function, called "HexEdit" when a button named "$btnChange" is clicked. Now it's named $btnChange but it will show Change on the button itself, don't get those confused it'll screw you up.
Code:
$nMsg = GUIGetMsg()
    Switch $nMsg
        Case $btnChange
            HexEdit($data)
    EndSwitch
$data is just a variable passed as a parameter to the function. Ok whose head just exploded, be honest. Raise your hand. Ok now go get a towel then talk to me after it grows back. For those of you still able to think all this code does is say "when a user clicks a button named $btnChange call the function HexEdit and send $data to that function."
Our function "HexEdit" should take the data it gets from $data and use that to do whatever it needs to do. Say it edits our gold, $data should be the value we want our gold at. We send $data (which has a value of, say, 10k) and in turn HexEdit() automatically edits our save file to give us 10k gold. Simple in principle yeah?


The most time-consuming portion of the GUI phase is designing the GUI. We all want our programs to look good so we'll probably spend a fair amount of time designing. I've found that doing a rough draft in the form designer then editing values in the code is a good way to make things look neat. I like to do things in increments of 5. If something has a value of 173 I'll make it 175, if it's 289 I'll make it 290, etc. Things line up well and it seems more professional, plus it's easier than trying to get it perfect in the form designer. Try to have an idea of how you want it to look before you start designing, that way you're not making it up and it looks even better. Really integration of the code and GUI is simple, once both portions are done. If you plan on adding features later you might want to add the appropriate controls to the editor and just disable them until their functions are working. It gives users a bit of a teaser of what's to come.
Post Reply Subscribe to Thread

Guest Quick Reply (no urls or BBcode)
Message:
Previous Thread Next Thread
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes