Let’s start out simple. Whatever you do or store is written into your RAM (Random Access Memory). E.g. you want to store your monthly salary into a variable, that you can use later on, you will find this salaryvariable in your RAM.
Lets say you have 4GB of RAM than you can store 2^32 = 4,294,967,296 bytes theoretically. When you want to store a number like your salary, generally you need 4 bytes to store that number into your memory. So, when you declare and initialize something like:
Code:
int salary = 2000; (1) <- this ”(1)“is not part of the code, it is to refer to this line / equation later on
"int" means, that "salary" will be an integer. There is a variable called "salary" and moreover it has the value of 2000 until you change it somehow. Generally you have to tell your computer, whether your "salary" is an integer or a decimal like 2013.21. Later you cannot set your "salary" to a decimal, after you have decided, that salary is an integer. You would have to declare something like "float anotherSalary = 2345.67". There are languages, where you can do so, but in C, C++, C# you cannot. An overview of other types of numbers can be found in Step 2. Note: C# is case sensitive. That means, that salaray and Salary are two different variables.
Okay, when you write the code (1), then Visual Studio writes this value into an arbitrary address of memory. E.g. if every part of your RAM was empty (which is impossible, due to your running Operating System and other things), Visual Studio / Your program could have taken the memory addresses 0x0000000001 to 0x0000000004. The 0x… just means, that the number is written as a hexadecimal. So 0xABCFDEF would be a valid address, too. So whenever your program asks “what is my salary”, it reads the 4 bytes at the address from 0x0000000001 to 0x0000000004. This kind of “detailed explanation” is useful for later memory manipulation, yet it is still incomplete.
Let's move on to our first problem. How can I switch the values of two integers?
Code:
int mySalary = 2000; (1)
int bossSalary = 6000; (2)
int temporary; (3)
temporary = mySalary; (4)
mySalary = bossSalary; (5)
bossSalary = mySalary; (6)
Here, I will go through every line, but later i wil preferably comment things on code. Comments can be made in c++ and c# by the following:
- Single lined comments are introduced with a double slash
- Multi linied comments begin with /* and end with */
Code:
// This is a single line comment
/* This comment here
takes two rows */
Although this section is about programming in general, I will try to stick to the syntax of C#. So some part of this section actually is about the fundamentals of the language. In (1) I initialized the variable "mySalary" to the value of 2000. Moreover it is an integer and can only be treated like this kind of number. We can never add 0.1323 to the salary. In (2) we do almost the same. (3) declares a new variable called temporary, which will help us to solve the problem of switching the values of "mySalary" and "bossSalary". It is very important to write
Code:
int mySalary = 2000;
and not:
Code:
2000 = int mySalary;
You always put what is on the right side, into what stands on the left. Not vice versa. Oh and by the way, at the end of each operation there is generally a “;”. That’s the syntax of C++ and C#. So with the “what stands right, goes to the left rule”, we hopefully can understand what happens in (4) to (6). In (4) we copy the value of 2000 into an auxiliary variable "temporary". So at this point "temporary" equals 2000, "mySalary" equals 2000, and "bossSalary" still equals 6000. In (5) we override the value "mySalary" to the value which is stored in "bossSalary". So at the end of (5) mySalary equals 6000. The value of 2000 would be lost, if we didn’t save it into "temporary". So we can use "temporary" in (6) to set the "bossSalary" to 2000. At the end of the code "mySalary" equals 6000 and "bossSalary" 2000. First problem solved!
Since we know how to switch variables, we can do many other operations, too, like increasing the value of a number by 2:
Code:
int I = 99;
I = I +2;
The following chart (taken by a presentation made for my students) shows how this will be done. Maybe this would be a good time to explain the words “stack” and “heap”? No. I think my kind of tutorial is very hard in comparison to others. So if you read until here, you can wait until I explain the difference between "call by value" and "call by reference" (Don’t worry, you don’t need to know what I just said by now).
Well, although this is a tutorial about C#, I have to talk about the assembler language. While C# is a very user friendly programming language, assembler or assembly has been used for decades and is also known as symbolic machine code. This language syntax is heavily linked to the computer architecture and its code instructions. What does that mean? A computer only knows of zeros and ones (bits). Eight of them together form a byte. This bytes are stored in memory as shown in the figure above and mentioned at the beginning of this chapter. The image below shows how this could be done in assembly. First you would move what is stored at the memory address 50 (assuming, that there is our variable I) to an auxiliary variable. Second you add to this variable the value 2, and last you overwrite the content of the variable A to the memory address 50. For creating cheats, writing in assembly is not necessarily needed. But if you want to understand, how other codes work (or maybe VAC) you can disassembly (reversing machine code to assembly code) an executable or any kind of windows program library with third party software, and with a lot of patience and experience you can understand the way how the investigated program works. This is called reversed engineering. Nowadays, third party program are able to translate the machine code inte pseudo code, where you can “easily” read through the code, as if you had the source in front of you. Everyone who has at least a minimal skill in reverse engineering knows, what a terrible liar I am at the moment. One thing you have to keep in mind: If you create your cheats in Visual C# and publish it, even you would be able to reverse engineer your own code at the end of this tutorial, without me describing how to do so. Luckily there is another kind of third party programs which “protects” your executables from being disassemblied. Mostly, your new “pimped” executable will be recognized as a virus, due to the fact, that this “protection” is mostly used by those bad people who create software to harm other people. If you take your time to google this topic you will get the basic idea of how to protect your code, but you'll see a lot of bullshit like “If you rename your variable “HealthPoints” to “as5ddas1dsd12s” nobody can reverse engineere your code. And it has another signature” (whatever a signature might be)… this naivety always makes me smile. Ok, lets go on. You will recognize during this tutorial, that I like to give additional information here and there, which potentially will confuse you more than it helps you, but I always want to remind you, that there is a lot more out there, than I could write in one file.