Pro Evolution Soccer 2016/Working with a hex editor
Pro Evolution Soccer 2016
A hex editor is a program that displays files in hexadecimal notation. This is useful for files that are not meant to be read by a human, but a program instead - like savegames.
Recommended hex editors
There are thousands of hex editors out there, yet only a few are actually usable. These are some of those:
To understand how a hex editor works, we first have to get a fundamental understanding of how computers deal with numbers.
In binary, a number is represented using only ones (1) and zeroes (0). The easiest way to understand binary is to understand what happens when we count in decimal:
000, 001, 002, ..., 009, 010, 011, ...
When adding 1 to 9, our notation follows a simple rule: the rightmost digit starts over, and next digit to the left is incremented.
The same concept can be applied to any different number of symbols. In case of binary with only two symbols, counting looks like this:
000, 001, 010, 011, 100, 101, 110, 111
In other words, it takes 3 digits in binary to represent the numbers 0 to 7.
In computer science, a single binary digit is called a bit. Eight bits form a byte.
In hexadecimal (or hex for short), we don't have 2 or 10 different symbols for a single digit, but 16. After 9, the letters A-F are used. Applying the same principle from before, counting in hexadecimal looks like this:
000, 001, 002, ..., 009, 00A, 00B, 00C, 00D, 00E, 00F, 010, 011, ...
This means we can count from 0 to 15 with a single digit. Using two digits, we can count up to 255 (FF). Including 0, this makes 256 different numbers, which in turn is exactly the size of a byte.
To avoid confusion, hexadecimal numbers are often written with a 0x prefix, e.g. 0x00FA6607.
Beyond a single byte
Since a single byte can only hold a number between 0 and 255, we need multiple bytes to store values greater than 255. In PES we usually encounter groups of 4 bytes for larger values, which are commonly referred to as integers (int). As a result, an (unsigned) integer can hold any value between 0 and 4,294,967,295. This is the same integer value in different notations:
16410119 0000 0000 1111 1010 0110 0110 0000 0111 0x00FA6607 00 FA 66 07
Notice how nicely a group of 4 bits corresponds to a single hex digit.
Note: to keep things simple, we ignored floating point numbers as well as negative values.
To make things worse, there are two ways to write down numbers: from left to right and from right to left. In computer science, these conventions are called big-endian and little-endian. Big-endian is the convention we are used to: the most significant digit is on the very left.
With little-endian, the opposite is the case. Unfortunately, this doesn't mean we simply reverse the digits. Instead, endianness is applied on a per-byte basis. This means 1101 1001 becomes 1001 1101 and not 1001 1011 as one might expect.
In hex notation, this means 00 FA 66 07 becomes 07 66 FA 00.
And since this is so terribly confusing, this is exactly what PES uses (for numbers, at least). So before you copy a number from the hex editor into a conversion tool, make sure to reverse it correctly.
When it comes to actual text, endianness does not apply. In ASCII, the most common encoding, each character is expressed by exactly one byte.
Changing strings is a bit more complicated than changing a few numbers. Since strings can have varying lengths, several methods are used to deal with this aspect. These are the most common ones:
- fixed length. Remaining bytes are set to 00.
- null-terminated. The last character is followed by a zero byte.
- length byte. The byte left of the first character specifies the string length.
Keep in mind however that inserting or removing bytes might still break the file as checksums or references offsets might not be correct anymore. So without understanding the file format, only fixed length strings can be edited safely (unless there is a checksum, that is).
- an offset column (also called address) which specifies the position inside the file (usually in hex, too)
- the values stored at this given offset
- those values encoded into something readable like ASCII
Clicking a byte (as in a pair of hexadecimal digits) will usually highlight the corresponding encoded character and vice versa. The Offset on the very left applies only to the first byte and must be incremented by one for each following byte in the same line. It is usually possible to change the encoding, the offset steps, or even a bit offset that completely changes how all values are interpreted.