Mlp logo.png Congratulations /mlp/! Mlp logo.png
Winners of the 2025 4chan Winter Cup

User:Tomato/PES AI

From Rigged Wiki
Jump to navigation Jump to search

This page tries to map and document the PES17 AI all the way from extracting the AI data from the right files to actually modifying the behaviour of the game. It's an eternal work in progress as new discoveries happen, but right now it's in a state where the theory behind it all is usable in practice.

I'll also say this right here. This is a nice little theory and it's got possibilities, but it'll very likely never be used in the cup. It's just so easy to completely break the game while trying to ""fix"" a problem. It's better to live with the existing problem than create new unexpected ones in its place. Unless someone manages to actually create a set of sensible changes that improve the game. But I wouldn't bet on that. Invitationals might benefit from this though, especially if someone manages to break PES in some very unexpected way.

It should also be noted that this is just one part of the AI. It's 100% certain the .exe or some other files in some other CPK also control some aspects of the AI and might even override some of the values documented here. Information about these different places where AI is handled will be added here if ever discovered.

Anyway, here's the theory behind the whole thing, and at the end a short and hopefully simple guide on how to break PES. If you don't enjoy several paragraphs of technical jargon, skip right to Modifying the AI.

Resources

You'll probably need some resources before getting started, especially if you plan to modify the AI files. Here's some pointers.

  • The AI Pack that contains the AI binaries as well as a ton of other files that make the AI data structure easier to understand and help make editing the binaries much much easier.
  • Knowledge of hex editing and a sane hex editor. The PES16 wikipage on the topic is a good start.
  • Sites like BinaryHex Converter and IEEE-754 Converter can be very helpful, especially when dealing with more exotic float DEC-HEX conversions.
  • A clean dt18_win.cpk. Just in case.

Locating the AI

The main PES AI files are located in dt18_win.cpk, one of the game's default data files. The CPK contains mostly easily readable .json files that contain parameters related to game and player behaviour. There are also several .bin files that at a first glance contain only jumbled data and some cleartext bits here and there.

The major issue with modifying the PES AI is that the easily readable .json files don't actually do anything. This is easily proven. First off, the files have not changed at all since PES15, even though the PES AI itself has seen some major changes. Secondly, we can delete all the AI .json files, re-build the dt18_win.cpk, replace the original in your PES data folder, and the game will run without a hitch. Normally removing files from the data CPKs is a surefire way to crash PES before even making it to the main menu.

So the .json files are useless. That leaves the random .bin files. The most important of the .bin files are the ones located in the constant folder. If we unzlib and open any one of them we'll notice that near the beginning of each file there is a block of cleartext data that looks like a list of filenames. That's exactly what it is. The .bin files in the constant folder are actually a bunch of simple .json files much like the cleartext ones mentioned before packed into a single .bin file, probably to conserve space and make breaking the AI that much more difficult.

The problem is, this information is pretty much useless without any clues on how to extract that packed .json data from the .bin files. This is where things get a bit nifty.

Extracting the AI

Studying the .bin Files

After some inspection it's pretty clear that the AI .bin files are split into three different datablocks. I've talked about the second one, the "index" already. It's the list of filenames contained in the file. The third block's purpose is also pretty clear. It contains the packed .json data, we just don't know how yet. That leaves us with the first block, the "header". This is where things get a bit more interesting.

The first block, starting from the beginning of the file and ending in the "index" block, is split into smaller blocks of 3x4 bytes, or 3 INT values, and is very closely related to both other blocks. The first INT is the length of the data of the corresponding filename in the "index" block. The second INT is still unknown, but it doesn't appear to be very important since cracking and modifying the AI is possible without even knowing what the value does. The third INT is the offset where the next .json file's data begins. Thus the first block combined with the index of the second block forms a map of the .bin file.

With this information we can break the third block into smaller pieces of data. The problem is that we don't know what any of that data means. It's possible to convert it into decimal values and make vague guesses based on the plaintext .json files in the data CPK and the filenames listed in the "index" block, but without a proper map of each included file it's impossible to reliably modify the AI files.

Mapping the AI data

Luckily, the AI data is mapped inside PES2017.exe. This was as big of a shot in the dark as it sounds, but if we search the .exe with a sane hex editor and look for "ball.json" we'll find cpk_dat/common/match/constant/match/ball.json. This matches constant_match.bin and its "ball.o" entry. And if we scroll down the list we'll notice it contains all the .json files included in the AI binaries. Lucky.

But that's not all. If we scroll down past the list of .json files we'll start to see what look very much like variable names. This is where the missing piece of the puzzle is. If we copy the entire block all the way until topSpinRiseDecRate, clean it up, split by the blocks of ScriptBind and finally take a good look, we'll notice the variables match the filenames in reverse order. So the first file in the "index" block of the first AI binary is "ball.json", and the very last block of variables in the list extracted from the .exe corresponds to the ball.json values in constant_match.bin. Complicated, but we have all the parts of the puzzle. Now it's time to assemble the files.

I'm going to make this part brief since it's mostly tedious manual work and cosmetics. In order to make the AI data more readable I used a Python script to read the JSON datablocks from the AI binaries, convert that HEX data into decimal for readability and finally write it into text files to try to represent the data in a simpler format. Then I did my best to combine the data values with the variable names extracted from PES itself, and ended up with a messy format that holds the variables and values in one place. These finalized data files can be found in the pack linked at the beginning of this writeup.

Now that the AI is finally cracked open and mapped, it's time to start breaking PES.

Modifying the AI

It's greatly recommended that you download the AI pack linked at the beginning of this page. It makes everything simpler and easier since all the hard work of mapping and extracting and checking is already done. This part is written in a way that expects you have the pack and all the files included in it.

Compared to the previous sections, modifying the AI is a walk in the park. All we need is the text files containing the value-variable pairs and a sane hex editor. The only real problem is that the file format is a bit clumsy since it's basically just a slightly polished research note. But with a little trouble getting used to it is easy.

All we need to do to modify the AI is find a value we want to modify in the text files, open the correct .bin file in a hex editor, locate the value in the .bin file and change it. After that just save the .bin file, use your preferred method to re-pack the dt18_win.cpk with the modified .bin file included and install it as custom DLC. This should override the default dt18_win.

Example

The values we want to edit, highlighted

This is a simple example on how to modify the AI. Let's say we want to make the ball not bounce at all. Since it's a ball-related change, we need to find the ball AI data. That's mapped under match\ball.txt. In ball.txt there are several values related to bouncing, but the safest bet is the simplest one, so boundRate, which is an array. We can find the actual values further below in the file, under the boundRate header. These values are undocumented, but it's not hard to guess what they do, so changing them all to 0.0 is worth a shot. Now we need to find out the location of these exact values in constant_match.bin, and this is where the limitations of the current file format come into effect. We'll have to count some lines, but after that small effort we'll have the positions down. In this case the values we want to change are 81st through 85th blocks in the ball.json entry, so bytes 320-339 from the beginning of the entry. From index_match.txt we can see that the ball.json entry is the first real entry in the file, ends at DEC 1248, and is 608 bytes long. From this we can find the correct values and set them all to 0x00000000. After that we simply re-compile dt18_win.cpk with the modified binary included, install it as DLC, and run PES. When we try out a game we'll notice the ball moves very differently, almost as if it were heavier than before. That means the changes we made were effective.

Conclusion

And that's it. The PES AI can be modded. It's just very very tedious and will probably not have a major impact at all because there are about 3,000 variables and I have not tried them all to find out which ones have major effects and which ones don't do anything.

This project has gotten to the point where a good majority of the work is done. There are plans for the future, like putting together a better file format for the AI data text files and maybe creating an editor based on that new format to make editing much easier and quicker, but right now, this project goes back to the pile of kind of finished stuff that still needs more work. Any new discoveries will be added, of course, but it's not a priority right now.

If you have any questions or want to know something not covered here or simply want a better explanation on something feel free to contact me. This stuff is surprisingly fun once you get used to it.

Finally, some tips and tricks that might help cut some corners or overcome some problems.

Tips and Tricks

  • Download the AI Pack. It's a massive help.
  • Read the readme files in the AI Pack. They're more compact than this abomination and might have some information that didn't make it here.
  • Take a backup of your dt18_win.cpk if you replace it. You really don't want to test on modified AI, even though the impact should be minimal.