How I Built A Brotato Cheat Using Python And Cheat Engine

Cheat Engine is a great tool for figuring out how games store their data, and you can combine it with your favorite programming language. Gaming has always been a passion … Read more

Taylor Bell

Taylor Bell

Published on Apr 10, 2024

How I Built A Brotato Cheat Using Python And Cheat Engine

Cheat Engine is a great tool for figuring out how games store their data, and you can combine it with your favorite programming language.

Brotato home screen with a health bar showing infinite health, cheat engine, and Python

Gaming has always been a passion of mine, and I’m an avid competitor in games such as Counter-Strike and Valuing. How these games work under the hood has always been an interest of mine as well, and when I can, I love to poke around and see how things work. Games like those are protected by an anti-cheat, but plenty of indie games and single-player games are surprisingly easy to analyze with tools like x64dbg and Cheat Engine. One such game that’s easy to modify is Brotato.

Brotato is kind of a rogue-like bullet-hell-style indie game, and it’s a lot of fun. It’s a challenging game to boot, and I was curious just how easy it would be to play around with. I analyzed the game using Cheat Engine, figuring out where the health value was stored in the game’s memory, and then wrote a Python script to manually write to that memory space in order to maximize my in-game HP.

We don’t recommend playing around with programs like Cheat Engine with games such as Counter-Strike. Cheating will get you banned, and “cheating” often includes hooking up a debugger to the game or reading its memory space. It’s better to be safe than sorry, so only experiment using games that you know are single-player and safe to tamper with. Cheating in online play ruins those games for other people. Don’t do it.

How I created a basic Brotato cheat using Cheat Engine and Python

Step 1: Analyze the game’s address structure

For the uninitiated, Cheat Engine is a powerful, open-source software designed for modifying games running under Windows. Users can manipulate various aspects of games such as altering timers, health levels, and much more through memory modification. By accessing and editing the memory processes of a game, users can adjust a ton of values such as health points, inventory quantities, and game scores. Cheat Engine also includes tools for debugging games and even normal applications, alongside a built-in assembler/disassembler and a tool for creating cheat patches.

We first launch Brotato and start a run in the game. Immediately we then pause the game and note our health level. We started with 15 HP, so I used Cheat Engine to point toward the Brotato executable and scan for anything in the game’s memory that holds a value of 15. To scan, we do the following:

  1. Open our running-executable in Cheat Engine
  2. Click First Scan on the right-hand side

I then take damage and scan for anything that was previously 15 and is now 14. I do this by clicking Next Scan rather than first scan. I continue decreasing my health (or increasing) until there is only one addressable value in Cheat Engine left, and this value is where the health of our character is saved in the program’s memory.

In Cheat Engine, I note the memory address of the health value, and modifying it directly in Cheat Engine will increase the value of my health in-game, too. We’re going to create a very basic Python script that modifies this memory value for us. From the above, we found that the memory address we need to modify is at 0x287D8CCFCD8, though this will change every time the game is launched. You can predict where this will be based on calculating offsets for the particular game, but that requires building a pointer map and is significantly more advanced.

Step 2: Creating a Python script

cheat-engine-8

Using Python, we’re going to modify the memory value directly. We can use ctypes for this, which is a foreign function library in Python. With ctypes and the ReadWriteMemory library, we can directly interface and modify the addressable space of a running program. In this case, we’re increasing our health in Brotato.

To do this, we need to do the following:

  1. Open the process for reading and writing
  2. Target the address of the piece of memory we want to modify
  3. Select what we want to modify it to be
  4. Load kernel32.dll for calling Windows API functions and use the WriteProcessMemory function from it
  5. Set up the argument types that the WriteProcessMemory function expects
  6. Write the data to the process
  7. Close the process

The above is a high-level overview of the code that we are going to write to control the running Brotato process. In the above screenshot, we show how we can read the memory value and parse it, showing that our health is 11. I wrote the new health value to the process with the following line of code:

WriteProcessMemory(process_handle, ctypes.c_void_p(address), byref(value), ctypes.sizeof(value), byref(bytes_written))

This function call writes a specific value into the memory of the process at the specified address. The process_handle identifies the target process, while ctypes.c_void_p(address) and ctypes.sizeof(value) specify where and how much data to write. byref(value) and byref(bytes_written) are used to pass references to the data being written and a variable to capture the number of bytes successfully written, respectively.

With that, our basic cheat is complete. It will overwrite the health value to 100, and you can put that into a while loop to constantly refresh your health to 100 HP if you want.

Games all work differently under the hood

Some games are more complex than others

brotato-1

I chose Brotato because of its relative simplicity versus other games, but the concept is the same no matter what. Identify where information is stored and you can modify it externally using a program of your choice. Cheat Engine is a great tool to find where different values are stored in memory. There’s a lot of work involved, and if you want to make it more advanced with identifying offsets and all, there’s a lot of complexity, too.

If you just want to get started in the world of game modding and hacking, then this is a great way to begin. Find what you want to modify and write a basic program to modify it, and you can then expand it over time to add more features. This kind of tool in Brotato could be used to draw an overlay where you could control things like your health, as you could make it so the user can input the health value that they want to have. Health is just one thing that you can modify, and it’s just the most primitive form of live-game modding we can show. There’s so much more you can do if you dedicate more time to it.

It’s a lot of fun and very rewarding, but be careful with the games that you use. We recommend not using multi-player games or games that you can get banned from, and you shouldn’t ruin other players’ experiences in online games either. Have fun though, and happy hacking!

Partager cet article

Inscrivez-vous à notre newsletter