cheat engine lua ΡΠΊΡΠΈΠΏΡΡ
Lua Basics
Lua interaction is done a few ways in Cheat Engine.
Contents
Lua Engine [ edit ]
The Lua Engine form contains a text box for lua’s standard output (print calls use the standard output) as well as an interactive script box that you can directly execute lua script. You can open or save scripts from here.
Cheat table lua script [ edit ]
From the Cheat Engine main form press Ctrl+Alt+L, to open the cheat table lua script form.
This script is associated with the cheat table. By default when opening a cheat table file Cheat Engine will prompt you that the table has a table lua script and asking you if you want to execute it.
Note: You can change what Cheat Engine does with the cheat table Lua script in the Cheat Engine general settings.
From the cheat table lua script form menu you can select file then select new window to open new script windows.
Script windows [ edit ]
You can debug the scripts written here by setting a breakpoint by clicking next to the line numbers.
You can have as many script windows open as you want, simply click File then New Window. If you save these scripts as lua files in the same directory as your cheat table or any directory included in the
string. You can run them from other scripts using lua’s require, which will only run a script the first time it’s required (or if package.loaded.filename is set to nil), and dofile, which will run a script every time you call it. Note that you do not use the extension with require, «.lua» is assumed, but you do need it with dofile.
require ( ‘Script1’ ) dofile ( ‘Script1.lua’ ) require ( ‘Script1’ )
Cheat engine lua ΡΠΊΡΠΈΠΏΡΡ
Introduction to Lua using Cheat Engine: Beginner to Basic Script Writer! May 25, 2017
So you want to get started learning Lua and creating scripts, huh? Well youβve come to the right place, so LETβS DO IT! =)
To note, this article will soon take the form of a video, so if thatβs your preferred medium, then just know thatβs coming soon and Iβll populate this article with it once itβs done.
Iβll spare you the details about what Lua is and how to generically learn the language in 0.013 seconds, and instead weβll learn by doing. In Cheat Engine (aka CE). Which is an incredibly powerful toolβnot only for purposes of hacking games and reversing software, but also for learning everything from Assembly, to reverse engineering concepts, to Lua, and much more.
If you donβt have Cheat Engine, go install it now (I wonβt be blamed if you install bundled offers, so READ THE INSTALLATION PROMPTS CAREFULLY) so you can follow along. You can run all of the code examples I provide directly in Cheat Engine, but donβt just copy them over because CE wonβt recognize some of the copied characters! If you do copy/paste, look for the characters you have to fill in.
Hello, World
You knew it was coming, but we have to do it! Letβs make CEβs Lua Engine output βHello, Worldβ. First, open Cheat Engine. Then, click on Table, then Show Cheat Table Lua Script. You should now see this window:
Now, enter the following:
Then click the Execute script button. You should now see the Lua Engine window open with βHello, Worldβ in the output section, like so:
Success! You just ran one of Luaβs native functions, print(). If you want exact text to be printed, use quotes (double β or single β quotes work). You can also print numbers and all kinds of other stuff like the results of calculations (e.g. print(1 + 2)) and so on. Try playing around with print() to see what else you can do! Can you figure out what this does? (Donβt worry if not; Iβll fully explain it in a little bit.)
print(string.upper(string.format(β%xβ, 1 + 0xA)))
As an aside, for those of you who want to dive in a bit deeper right off the bat, click here to check out other native Lua functions.
For those of you who are beginners, functions are just blocks of code that do something for you. Sometimes, a function will just perform a task where you donβt expect anything as a result. Other times, a function needs some data with which to perform its task(s). The print() function takes arguments you provide, then does its magic. If you just ran print(), it wouldnβt do anything because print() is like, βI meanβ¦you didnβt tell me WHAT to print, so I canβt do anything, dawgs.β
More on that in a bit, but letβs shift gears and talk about variables.
Variables
Put simply, variables are just things you store values in (numbers, characters, words, functions, other variables, etc., etc.). First, you think of a name for your variable, then you typically assign it a value. There are rules for how you can name your variables, so you might want to check them out to prevent making a naming error that might confuse you later.
Using our βHello, Worldβ example from above, letβs modify it slightly to print the same result to the screen, except from a variable instead of directly:
theNameOfYourVariable = βHello, Worldβ
print(theNameOfYourVariable)
Notice that I didnβt put quotes around the variable name I passed through print(). If I did, then you would have seen that exact variable name printed to the screen as a string of text. Try it for yourself and see:
theNameOfYourVariable = βHello, Worldβ
print(βtheNameOfYourVariableβ)
Now, if you were to really want this as part of a program or script, youβd probably want to make your variable name more reflective of what itβs storing. Take these examples for instance. Can you figure out what each of them do?
Example 1: String
helloWorld = βHello, Worldβ
print(helloWorld)
Example 2: Math
addTwoNumbers = 2 + 2
print(addTwoNumbers)
Example 3: More Math and More Variable Names
numberOne = 1000
numberTwo = 1674
numberThree = 2
threeNumberMath = (numberOne + numberTwo) / numberThree
print(threeNumberMath)
Example 4: Tables
(Donβt worry if you donβt know what tables are; however, if you want to look into them, here you go!)
Example 5: Functions
(Weβre diving into functions next, so come back to this example after that and see if you can figure out whatβs going on.)
Example 6: Nil
local emptyVariable
print(emptyVariable)
(Not assigning a value to a variable means that its value will be βnilβ, basically meaning thereβs nothing in it. Prefixing a variable name with βlocalβ has to do with something called βscope.β Donβt worry about it for the time being, but just be aware that youβll likely see it used. For those who DO want to worry about it now, here you go.)
The point of those examples is to show that you can store just about anything you want in variables. You might decide to make significantly shorter variable names, or find more elegant ways to write a function, etc., etc., etc. In Lua, there are many ways to achieve the same thing, so just have fun!
Functions
Up to this point, weβve used a function (print()) and weβve written our own function (example 5 above). For this section, weβre only going to focus on using functions, so if you want to delve deeper into creating your own functions, take a look at this tutorial.
Again, functions are just blocks of code that do something. Just like Lua has a bunch of its own functions (like print()), so does Cheat Engine! You can find most of them here on the CE wiki; however, it isnβt updated as frequently as CEβs development pace, so you can check out celua.txt on the official CE Github repository for ALL the goodies (like executeCode()).
Remember a little bit ago when I asked if you could figure out what this does?
print(string.upper(string.format(β%xβ, 1 + 0xA)))
Thereβs a lot going on there, so let me break it down another way.
numOne = 1
numTwo = 0xA
toHex = string.format(β%xβ, numOne + numTwo)
toUpperCase = string.upper(toHex)
print(toUpperCase)
There, Iβve assigned 4 variables:
numOne contains the number 1.
numTwo contains the hexadecimal number A (the 0x prefix lets Lua know that you intend for that number to be treated as a hexadecimal number).
toHex makes use of another Lua function called string.format() through which weβre passing two arguments: β%xβ, which tells Lua to treat your other arguments as hexadecimal values (you can read about other formats here), and the variables numOne + numTwo.
toUpperCase is using yet another Lua function called string.upper(), which converts lower-case characters to upper-case. For our use, weβre passing it the variable toHex, which is taking the result of our string.format() statement and upper-casing the result if itβs A-F. This is just a matter of personal preference; I hate seeing hexadecimal values represented in lower-case. 😉
Finally, we take all of that and print the result to the screen. Now, remember when I said there are multiple ways to do things in Lua? Those are two different representations of making the same thing happen. But thereβs a shorthand way to get the same results still by making one little change to toHex and removing the toUpperCase variable and its assignment altogether! See if you can spot the difference:
print(string.format(β%Xβ, 1 + 0xA))
numOne = 1
numTwo = 0xA
toHex = string.format(β%Xβ, numOne + numTwo)
print(toHex)
Thereβs no right way here, but there are more readable and sometimes performant ways. Itβs just whatever you choose to do. Sometimes, less code means less time spent writing that code, but more time trying to go back two months later and figure out what exactly that code does. Other times, a little more time spent writing or refactoring your code can spare you a headache later. That, or just add a comment about what your code is doing. Hereβs how you make comments in Lua, which are essentially lines that are ignored by Lua, but that you can read (copying/pasting single-line comments from here into Cheat Engine wonβt work, so Iβll only be using the multi-line format for code examples from here, forward):
ββThis is a one-line comment. Write whatever you want on this line!
ββYou can do this for as many lines as you like; however, thereβs the next option.
ββ[[
This is a multi-line comment, so we can do this all day and
itβs just one comment. This keeps us from having to keep adding
the ββ to the beginning of every line we want to specify as a
comment. w00t!
]]
Weβve learned a lot here so far!
A. How to print a string. For those of you who are new to this concept, the reason itβs called a string is because itβs a string, or a strand, of individual characters grouped together. Imagine youβre making a necklace for your mother thatβs going to have her name on it. The necklace is like a string that youβll slide individual letters onto. So a string is just a collection of characters. Thereβs more to it all, but thatβs the basic gist.
B. How to create variables and assign values to them.
C. How to do math with Lua, how to specify a valueβs format, and how to print that result.
D. How to write comments.
E. How to use functions: print(), string.upper(), and string.format().
F. How to write in camelCase!
This is great, because it means we can now start using Lua functions that are native to Cheat Engineβfunctions like readByte(), writeInteger(), playSound(), pause(), unpause(), and tons more. So with that said, letβs dive into Cheat Engine and roll through an example of how you could use what you now know about Lua to create a script!
Creating a Lua Script in CE
Everyone should be able to follow along from here regardless of their exposure to CE, but if you have no idea how to use Cheat Engine in even the most basic of ways (like how to scan for values), then you might want check out my Cheat Engine Tutorial Series on YouTube!
First, letβs consider a scenario in game where we have a player that has health. The playerβs maximum health value is 100. Letβs say that player isnβt at full health, so their current health is at 43. Itβs not uncommon that these two values are stored in two memory addresses close in distance.
So, one memory address would have the playerβs maximum health value, and another address would have their current health value. Then, you have instructions that look at the values in both addresses so that it knows what to do in various situations. For instance, say you pick up a health vial that gives you 20 points of health. Well, if youβre at 99 of 100, then the game will know not to take your health up to 119. It knows this by saying something like, βWell, I see the player has 99 health in that memory address, and I see the max health that player should be capable of having is 100 in that other memory address, so Iβll only give the player 1 point of health from that vial.β
With that in mind, a very common cheat to create is to find those two memory addresses, then the instruction that updates the playerβs health when they lose health, and finally make it to where instead of taking away health, you make the playerβs current health equal maximum health. Weβre not going to worry about finding that instruction for the time being, though. Thatβll be in a future tutorial.
What we want to do now is create a Lua script that will make the playerβs current health equal their max health value. Letβs loosely visualize this by creating those variables, assigning values, and simulating the cheat (this is all part of something called βpseudocode,β which is noting small bits of what you want your code to do, then writing actual code to realize those bits).
ββ[[Get current health and maximum health values]]
maxHealth = 100
currentHealth = 43
ββ[[Print the value of current health so we can see it before itβs changed]]
print(currentHealth)
ββ[[Make current health equal maximum health]]
currentHealth = maxHealth
ββ[[Print current health with its new value so we can verify]]
print(currentHealth)
If you run that in CE, your results should look as follows (I used single-comment lines initially, as youβll note):
Letβs now apply this to a game! Iβll use Terraria as an example. If youβre following along, go ahead and open Terrariaβs process with CE.
First, letβs find current player health. Iβm starting with current health being full, then scanning for exact value changes after taking damage. Hereβs the result:
Then, view that memory region to see if something resembling other values like max health are anywhere nearby (using the data/structure dissector is another option, but Iβll cover that in another tutorial). To do that, right-click on the value you found, then click Browse this memory region. Once that window pops up, right-click on any of the bytes in the bottom pane of the memory viewer (the top pane is the disassembler), hover over Display Type, then click 4 Byte decimal. Now scroll up a tiny bit to see values above and below the current health value.
Because Iβm familiar with the game, I know certain numbers Iβm looking for. As you can see, the max health value Iβm interested in is in very close proximity to my current health value.
Now letβs make note of the memory addresses those values are in. You can right-click on any value there in the memory viewer and select Add this address to the list. Itβs also sometimes worth bearing in mind the distance (aka the offset) between the current health and max health addresses. In the right scenario, itβs a great way to reference one memory address from another that you find.
We now have what we need to create our script! Weβll be using a couple of CEβs Lua functions as well. Letβs start by looking at the value type of our values.
As you can see, theyβre 4 bytes, so we can use CEβs functions that are related to integers. (Technically speaking, a float is a 4-byte value as well, but thatβs part of a lesson for another day.) Click here to see some of CEβs memory-related functions. Weβre going to use readInteger() and writeInteger(). Iβm going to use comments in the script below to explain whatβs going on throughout it.
ββ[[
Store the memory address for current health, which is 0x4 bytes
away from the max health address. That means we can specify
current health as being maxHealthAddress β 0x4 (resulting in
0x004587C0 being the value in currentHealthAddress)
Note: 0x4 is the same as saying 0x00000004 in this case
]]
currentHealthAddress = maxHealthAddress + 0x4
ββ[[
Store the value found inside the max health memory address
]]
maxHealthValue = readInteger(maxHealthAddress)
ββ[[
Store the value found inside the current health memory address
]]
currentHealthValue = readInteger(currentHealthAddress)
ββ[[
Write the value from the max health memory address
to the current health memory address
]]
writeInteger(currentHealthAddress, maxHealthValue)
ββ[[
Refresh the value of health stored in the currentHealthValue variable
]]
currentHealthValue = readInteger(currentHealthAddress)
After running that script, voila! The playerβs current health is now the same value as max health, and the Lua Engine output reflects our change (click/tap the image for full size).
Now, unfortunately, this isnβt really a reusable script due to the fact that the memory addresses will change after the game is restarted (and if you followed along, your memory addresses were most likely different from mine). Thatβs something Iβll focus on in another tutorial, but for the time being, this script touches on most of the points I wanted to touch on.
You now know just enough to be somewhat dangerous. Go looking through other CE Lua scripts out there, and donβt freak out if you donβt know something you see! It takes time.
Also of note, you may run across people saying that, comparatively, a Lua script is slower than an Assembly script; however, donβt worry about that. Technically, itβs true, but most of you will never, ever, ever get to a point where you need to worry about eeking out performance on that level. So play around, have fun, and get your learn on! =)
Stephen Chapman
Hi! I’m Stephen. I’m a developer, reverse engineer, and former investigative journalist. DSASMBLR is my outlet for each of those facets—everything from video game exclusives, to reverse engineering and programming tutorials, to security-related articles and much more. Feel free to reach out and say hello via any of the avenues above!
Jason Blount β’ May 26, 2017
Awesome Stephen, i am looking forward to more on this subject Reply
Panda β’ June 1, 2017
Wow, thank you for making this througly explained, Stephen! You are always exceeding my expectations Reply
Yaseen Ahmad β’ June 29, 2017
You were always my favorite one, You are my favorite one and You will be! But the most amazing thing is that I never knew you’re a hacker too. Now I’m your fan Sir (I don’t provide cooling, though) You’re UNbeatable! π Reply
Meizhi Qi β’ August 21, 2017
Karan β’ November 8, 2017
Awesome. ty very much Reply
Kerem β’ August 24, 2018
wofwof β’ August 22, 2019
Thank you for this tutorial. I found a little typo in here «Try playing around with print() to see what else you can you can do! » Reply
ΠΠ»ΠΎΠ³ MasterGH
Cheat Engine 6.7 ΠΈ Lua. Π§Π°ΡΡΡ 1
ΠΠ°ΠΏΠΈΡΡ ΠΎΠΏΡΠ±Π»ΠΈΠΊΠΎΠ²Π°Π» MasterGH Β· 28 ΡΠ΅Π²ΡΠ°Π»Ρ, 2018
ΠΠ΄Π΅ ΠΏΠΈΡΠ°ΡΡ Lua ΠΊΠΎΠ΄?
Lua Engine ΠΎΠΊΠ½ΠΎ, ΠΊΠΎΡΠΎΡΠΎΠ΅ Π²ΡΠ·ΡΠ²Π°Π΅ΡΡΡ ΠΈΠ· Π³Π»Π°Π²Π½ΠΎΠ³ΠΎ ΠΎΠΊΠ½Π° CE.
Lua Console ΠΎΠΊΠ½ΠΎ, ΠΊΠΎΡΠΎΡΠΎΠ΅ Π²ΡΠ·ΡΠ²Π°Π΅ΡΡΡ ΠΈΠ· ΠΎΠΊΠ½Π° ΠΎΡΠ»Π°Π΄ΠΊΠΈ CE.
ΠΠΊΠ½ΠΎ Autoassembler ΡΠΊΡΠΈΠΏΡΠ° Ρ Π²ΡΡΠ°Π²ΠΊΠΈ <$lua>,
Lua Engine ΠΎΠΊΠ½ΠΎ ΠΈ Autoassembler-Π½ΡΠ΅ ΡΠΊΡΠΈΠΏΡΡ ΠΌΠΎΠ³ΡΡ ΡΠΎΡ
ΡΠ°Π½ΡΡΡΡΡ Π² ΡΠ°ΠΉΠ»Π°Ρ
Cheat Engine *.CT. *.CETRAINER, *.EXE
Lua Console Π΄Π»Ρ ΠΏΠΎΡΠ°Π³ΠΎΠ²ΠΎΠΉ ΠΎΡΠ»Π°Π΄ΠΊΠΈ Lua ΠΊΠΎΠ΄Π° ΠΈ ΠΏΡΠΎΡΠΌΠΎΡΡΠΎΠ² ΡΠ΅Π·ΡΠ»ΡΡΠ°ΡΠΎΠ² ΠΎΡΠΈΠ±ΠΎΠΊ ΠΈ ΡΡΠ½ΠΊΡΠΈΠΈ print()
ΠΠΎΡ ΠΏΠ΅ΡΠ²Π°Ρ ΠΏΡΠΎΠ³ΡΠ°ΠΌΠΌΠ°
Π‘Π½Π°ΡΠ°Π»Π° ΡΠ·Π½Π°Π΅ΠΌ Π²Π΅ΡΡΠΈΡ Π΄Π»Ρ CE 6.7 ΠΈ ΡΡΠΎ Π±ΡΠ΄Π΅Ρ ΠΏΠ΅ΡΠ²Π°Ρ ΠΏΡΠΎΠ³ΡΠ°ΠΌΠΌΠ°
ΠΠ°ΠΏΡΡΠΊΠ°Π΅ΠΌ CE ΠΈ ΠΆΠΌΠ΅ΠΌ ctrl+alt+L ΠΈ Lua Engine, Π²Π²ΠΎΠ΄ΠΈΠΌ
Π‘Π»Π΅Π΄ΡΡΡΠΈΠΉ ΡΠ°Π³ β ΡΠΎΠ±ΡΠ°ΡΡ ΡΠΏΡΠ°Π²ΠΎΡΠ½ΡΠ΅ ΠΌΠ°ΡΠ΅ΡΠΈΠ°Π»Ρ ΠΈ ΠΏΡΠ°ΠΊΡΠΈΡΠ΅ΡΠΊΠΈΠ΅ ΡΡΠΊΠΎΠ²ΠΎΠ΄ΡΡΠ²Π°.
ΠΠ΅Π²Π°ΠΆΠ½ΠΎ ΠΊΠ°ΠΊΠΈΠΌΠΈ ΠΎΠ½ΠΈ Π±ΡΠ΄ΡΡ ΠΏΠΎ ΡΠ»ΠΎΠΆΠ½ΠΎΡΡΠΈ ΠΈ ΠΎΠ±ΡΠ΅ΠΌΡ. ΠΡΠ΅Π³Π΄Π° ΠΌΠΎΠΆΠ½ΠΎ Π±ΡΠ΄Π΅Ρ ΠΎΠ±ΡΠ°ΡΠΈΡΡΡΡ ΠΊ Π½ΠΈΠΌ ΠΏΠΎΠ·ΠΆΠ΅, ΠΊΠΎΠ³Π΄Π° ΠΏΠΎΡΡΠ΅Π±ΡΠ΅ΡΡΡ ΡΡΠΎ-ΡΠΎ Π½Π°ΠΉΡΠΈ.
Π‘ΠΏΡΠ°Π²ΠΎΡΠ½ΡΠ΅ ΠΌΠ°ΡΠ΅ΡΠΈΠ°Π»Ρ
ΠΡΠ»ΠΈ CE ΠΈΡΠΏΠΎΠ»ΡΠ·ΡΠ΅Ρ Π²Π΅ΡΡΠΈΡ Lua 5.3, ΡΠΎ Π½ΡΠΆΠ΅Π½ ΠΎΡΠΈΡΠΈΠ°Π»ΡΠ½ΡΠΉ ΡΠΏΡΠ°Π²ΠΎΡΠ½ΠΈΠΊ ΠΏΠΎ ΡΡΠΎΠΉ Π²Π΅ΡΡΠΈΠΈ.
Π― ΠΎΠ±ΡΠ°ΡΠ°ΡΡΡ ΠΊ celua.txt ΠΈ defines.lua. ΠΠ°Ρ ΠΎΠ΄ΡΡΡΡ Π² Π΄ΠΈΡΠ΅ΠΊΡΠΎΡΠΈΠΈ Cheat Engine. Π ΡΡΠΈΡ ΡΠ°ΠΉΠ»Π°Ρ ΠΊΡΠ°ΡΠΊΠΎΠ΅ ΡΠΏΡΠ°Π²ΠΎΡΠ½ΠΎΠ΅ ΡΡΠΊΠΎΠ²ΠΎΠ΄ΡΡΠ²ΠΎ.
Π‘ΡΠΎΠΈΡ ΡΠ°ΠΊΠΆΠ΅ ΠΎΡΠΌΠ΅ΡΠΈΡΡ, ΡΡΠΎ Cheat Engine 6.7 Π½Π°ΠΏΠΈΡΠ°Π½Π° Π½Π° Lazarus. ΠΠ°ΠΏΠΈΡΠ°Π², Π½Π°ΠΏΡΠΈΠΌΠ΅Ρ ΠΏΡΠΎΠ³ΡΠ°ΠΌΠΌΡ ΠΏΠΎ ΡΠΈΡΠΎΠ²Π°Π½ΠΈΡ ΡΠΈΠ³ΡΡ, Π»ΠΈΠ½ΠΈΠΉ Π½Π° ΡΠΎΡΠΌΠ΅ Π½Π° Lazarus ΠΈΠ»ΠΈ Delphi ΠΌΠΎΠΆΠ½ΠΎ Π±ΡΠ΄Π΅Ρ ΠΏΠΎΠ½ΡΡΡ, ΠΊΠ°ΠΊ ΡΠ΄Π΅Π»Π°ΡΡ ΡΠ°ΠΊΠΆΠ΅ ΠΊΠ»Π°ΡΡΠ°ΠΌΠΈ ΠΈ ΡΡΠ½ΠΊΡΠΈΡΠΌΠΈ Π½Π° CE Lua. Π ΡΡΠΎ Π½Π΅Π»ΡΠ·Ρ ΡΠ΄Π΅Π»Π°ΡΡ CE Lua, ΡΠΎ ΡΠ΅ΡΠ°Π΅ΡΡΡ Π²Π½Π΅Π΄ΡΠ΅Π½ΠΈΠ΅ΠΌ ΠΈ ΠΈΡΠΏΠΎΠ»Π½Π΅Π½ΠΈΡ ΠΊΠΎΠ΄Π° Π² ΡΠ°ΠΌΡ Cheat Engine.
ΠΡΠΎΠ΄ΠΎΠ»ΠΆΠ΅Π½ΠΈΠ΅ ΡΠ»Π΅Π΄ΡΠ΅Ρ.
upd: Π΄ΠΎΠ±Π°Π²ΠΈΠ» ΡΡΡΠ»ΠΊΡ Category:Assembler
VCL Bro Ordinary Fun’s World
Overview
Not every computer or video game supports cheats upon release. These games make cheating a little trickier. If youβre a hacker, you may be familiar enough with computer programming languages to take a close look at the video gameβs code and find ways to tweak it to create cheats. But for the rest of us, we have to rely on the skills of knowledgeable hackers to create shortcuts for us and make them available somehow.
What you need to create your own trainers
In order to be able to create your own trainers for a PC game, you will need to get cheat engine and learn some very basic techniques to find values. If you do not yet have the skills required, then you might want to check out this tutorial on basic cheat engine handling. You will also have to be patient. The bigger the game is, the harder to actually get a trainer working. You will have to start, scan, restart for quite some time in order to get multiple pointers running and it will require a lot of patience.
Two ways to making your own game hack trainer using Cheat Engine
Game trainers are programs made to modify memory of a computer game thereby modifying its behavior using addresses and values, in order to allow cheating. It can βfreezeβ a memory address disallowing the game from lowering or changing the information stored at that memory address (e.g. health meter, ammo counter, etc.) or manipulate the data at the memory addresses specified to suit the needs of the person cheating at the game.
By using Cheat Engine you will have 2 ways to making your own trainer. First use Cheat Engine Form Designer and second is use Cheat Engine Lua scripting.
Making your own game hack trainer using Cheat Engine Lua scripting
We assume you already know a lot about the cheat engine (game process and so on), here I am just going to show you how to make a βsimple trainerβ using CE lua scripting.
In this tutorial, we will make a very simple game trainer with properties (let we hack a online 8 ball pool game 3.3.4 by miniclip for example is to get long guide line for all tier rooms). So here :
Our trainer form properties will need :
By default CE with give name to our properties as :
We will change our form trainer properties name later in scripting.
Script Code for Main Form :
β creating Main Form
local f = createForm( true );
β Give title to Main Form
control_setCaption( f, βMy First Trainerβ );
β Set size of Main form Width=290, High=200
control_setSize( f, 290, 200 );
β Set Main Form position display at center screen
form_centerScreen( f );
You can try to click βExecuteβ button and find out what is your trainer look like by displaying it into your computer screen. You can do this many time, but donβt forget to close your βtrainerβ after you have finish to looking it.
Remember, make sure you make a copy of your script to a notepad page and save it to your computer. This will avoid you loss your script. So, if you want to finish your work at a time, you can close CE and still have a copy of your script and can use if you want to continue writing your script next time. Just copy your script from notepad file to CE Lua Engine or CE > Table > Show CE Table Lua Script.
Or, when you finish your work in CE Lua Engine, just copy your script to CE Show Table Lua Script and save your trainer as a CE Trainer file. Now we continue our script :
Script code for Button Open Process, Label for process identifier with functions connecting to it :
β Make a function for btn_01 (Button Open Process)
β This function below use for read all process in comp. memory
function pidDialog(doPid)
local plugname = <βiexploreβ,βflashplayerpluginβ,βplugin-containerβ,βoperaβ,βchromeβ,βawesomium_processβ,βtorchβ,βdragonβ,βmaxthonβ,βpalemoonβ,βsafariβ >
local function tmerge(t,o,β¦) for k,v in pairs(o) do t[k]=v end if select(β#β,β¦)>0 then return tmerge(t,β¦) else return t end end
local function callLater(f,β¦)
local t = createTimer()
local a,n = <β¦>,select(β#β,β¦)
t.Interval = 100
t.OnTimer = function(sender) sender.Enabled=false sender.Destroy() f(unpack(a,1,n)) end
t.Enabled = true
return t
end
local function parseProc(s)
local p,n
for pid,name in string.gmatch(s,'([0-9A-F]+)-(.*)β) do
p = pid ; n = name
end
return p,n
end
local function prec(i,p,n)
local weight = 0
for _,v in ipairs(plugname) do
if string.find(string.lower(n),string.lower(v),1,true) then weight = weight + 1 end
end
return
LB.OnDblClick = function()
local idx,PID,NAME = LB.ItemIndex,nil,β
if idx >= 0 then
for pid,pID,name in string.gmatch(LB.Items[idx],'(9+)-\s*([0-9A-F]+)-(.*)β) do
PID = tonumber(pid,10)
NAME = name
end
end
if PID
= nil then callLater(doPid,PID,NAME) end
FP.close()
end β LB.OnDblClick
FP.OnClose = function() FP.destroy(); FP = nil end
getProcesslist(LB.Items)
local plist = <>
for i=1,LB.Items.getCount() do
local p,n = parseProc(LB.Items[i-1])
p = tonumber(p,16)
table.insert(plist,prec(i,p,n))
end
table.sort(plist,function(a,b) return a.w > b.w end)
local currProcId = getOpenedProcessID()
for i=1,LB.Items.getCount() do
LB.Items.setString(i-1,plist[i].desc)
if plist[i].pid == currProcId then LB.setItemIndex(i-1) end
end
β Make a function which executing by button click
β in this case is for button = btn_01
β function name is scanBrowser()
function scanBrowser()
pidDialog(function(pid,name)
OpenProcess(pid)
label_01.Caption = string.format(β%4X-%sβ,pid,name)
end)
end
β Creating a button for Open Process name=btn_01
local btn_01 = createButton( f );
β Set caption for the button
control_setCaption( btn_01, βOpen Processβ );
β Set button size
control_setSize( btn_01, 90,30)
β Set button position left=10, top=20
control_setPosition( btn_01, 10, 20 );
β Set a function work if button click by user
β This is executing function scanBrowser()
control_onClick(btn_01, scanBrowser)
Script code for button for long guide line hack with all function connecting to the button :
Code AOB for long guideline 8 ball pool game 3.3.4 is :
AOB to scan : 24 01 62 08 12 05
AOB for replace : 24 16 62 08 12 05
β Make a function which executing by button click
β in this case is for button = btn_02
β function name is longline()
β This function will execute by btn_02 clicked
function longline()
β put our AOB into a variable βscan_aobβ an scan
result = AOBScan(β24 01 62 08 12 05β, β+W*X-Cβ)
β put a condition if scan found or not
β if scan found
if (result) then
β replace all AOB found with our code
β our code should writing with β0x..β in front of
lngt = result.getCount()
for x=0, lngt-1, 1 do
writeBytes(result[x], 0x24, 0x26, 0x62, 0x08, 0x12, 0x05)
end
β show message hack success and make beep sound
beep()
showMessage(βLongline Activatedβ)
β clear memory from scan result
result.Destroy()
result = nil
β if scan our AOB not found
else
β give message to user hack failed and make beep sound
beep()
showMessage(βHack Failedβ)
end
end
β Creating a button for Longline name=btn_02
local btn_02 = createButton( f );
β Set caption for the button
control_setCaption( btn_02, βLong Lineβ );
β Set button size
control_setSize( btn_02, 130,60)
β Set button position left=10, top=70
control_setPosition( btn_02, 10, 70 );
β Set a function work if button click by user
β This is executing function longline()
control_onClick(btn_02, longline)
Script code for button for exit the trainer and all the function connecting to the button :.
β Make a function which executing by button click
β in this case is for button = btn_03
β function name is exit_trainer()
β This function will execute by btn_03 clicked
function exit_trainer()
β close out trainer
closeCE();
β clear all process CE in memory
return caFree
end
β Creating a button for exit trainer name=btn_03
local btn_03 = createButton( f );
β Set caption for the button
control_setCaption( btn_03, βExitβ );
β Set button size
control_setSize( btn_03, 130,60)
β Set button position left=150, top=70
control_setPosition( btn_03, 150, 70 );
β Set a function work if button click by user
β This is executing function longline()
control_onClick(btn_03, exit_trainer)
Script code for copyright label / creator :
β Creating Label Copyright
β This is to show out trademark
local label_02 = createLabel( f )
β Set caption for the button
control_setCaption( label_02, βCopyright Hacker β 2015β );
β Set label position left=100, top=20
control_setPosition( label_02, 80, 160 );
Well, we have done with our script. Next if you think everything is okay and tested result in Lua engine give work properly result, now doing next step.
Congratulation, you have been done made with your first CE trainer by using lua script.
You can download source code here : sourcecode
After downloaded open it (text file) copy all code and put it into your CE > Table > Show Cheat Table Lua Script.