You are on page 1of 11

Cheat Engine :: View topic - Rydian's Guide To Custom Trainers

24/03/2015 1:35 PM

Cheat Engine
The Official Site of Cheat Engine
FAQ
Profile

Search

Memberlist

Usergroups

Register

Log in to check your private messages

Log in

Rydian's Guide To Custom Trainers


Cheat Engine Forum Index -> Cheat Engine Tutorials
View previous topic :: View next topic
Author
Rydian
Grandmaster Cheater

Message
Posted: Tue Feb 03, 2015 2:32 am

Post subject: Rydian's Guide To Custom Trainers

- Introduction
Tired of Cheat Engine's generic trainer style? Want better ability to edit a trainer that you've already made?
Want to make a trainer that uses more than just hotkeys and can read and write custom values for ease of use?
Follow this tutorial and you should be spitting out fancy trainers at the end!
Reputation: 16
Joined: 17 Sep 2012
Posts: 542

- Setup / Software / Downloads


This tutorial was written for Cheat Engine 6.4, though it should work on 6.3 or later(barring future UI changes).
We will be using the freeware game Cave Story as the target.
You can download it here, the translation patch is linked right below the main download.
This post has some attachments which include the table and resources we'll be working with.
So make sure to scroll down and download those now.

- Meet The Lua Script And Form Interface


The first thing you'll want to do once you have all the files set up is to attach CE to the game (Doukutsu.exe) and then load
the table. You'll see the various addresses and scripts in the table, but we'll barely be touching those. Instead, click the
"Table" menu at the top and click "Show Cheat Table Lua Script". This will bring up a new window where all the coding goes.

http://forum.cheatengine.org/viewtopic.php?p=5576412

Cheat Engine :: View topic - Rydian's Guide To Custom Trainers

24/03/2015 1:35 PM

It's important to remember that you should not click the "Execute" button at the bottom of this form until you are ready to
actually test the script/trainer's functionality. Changes are automatically saved into the table, so always click the X at
the upper-right to close this form when you want it out of your way.
Now go to "Table" again and click "Create Form". This will bring up three windows... the Form Designer, Object Inspector, and
the Trainer Form itself. However you can think of the three windows using the below labels as well if it makes more sense.

This form will be the actual visible trainer that the users will see and interact with, and it will interact with the Lua
script to actually do stuff. After you've created a form, it has a sub-menu for it added in the "Table" menu, so you can bring
it back up or go edit it some more later.

http://forum.cheatengine.org/viewtopic.php?p=5576412

Cheat Engine :: View topic - Rydian's Guide To Custom Trainers

24/03/2015 1:35 PM

- Basic Setup
The first goal will be to give the Lua script some basic working code and then set the trainer form up with a working "About"
button. To start, we'll copy-paste some basic code to the bottom of the Lua script window.
Code:
AboutText=[[Sample About Text Here]]
form_show(UDF1)
getAutoAttachList().add("doukutsu.exe")
function CloseClick()
closeCE()
return caFree
end
UDF1.OnClose = CloseClick
addresslist=getAddressList()

The first line sets some text for our "about" box, feel free to replace it with what you want (linebreaks work too).
The second line tells the script to show the form when the trainer runs. It uses the default name of "UDF1" for the main
form, if you rename the main form then make sure to change this line as well.
The third line tells CE which process name you want the trainer to automatically attach to. If, for some reason there's
more than one process name (DX/GL or DX9/11 installs) then you can copy-paste that line to add more process names the
trainer should look for.
The lines that involve closing tells the background processes and such to close when the user closes the trainer,
so leave these alone.
The final line loads the table's address list, for when we want to freeze values and such.

Now you'll want to look at the Trainer form (those three boxes). In the Object Inspector box (where you edit the properties
of things) click on the main form in the list at the top (UDF1, the default name for the trainer in general) and scroll down
to see the properties. You can click in the property boxes to edit them. You'll want to change the Width and Height of the
trainer to 300 each, and also change the Caption, because that's what determines what the Trainer window is named.

Now look at the Tool Box (Form Designer), click the second button and then click and drag in the trainer form somewhere to
make a simple button.

http://forum.cheatengine.org/viewtopic.php?p=5576412

Cheat Engine :: View topic - Rydian's Guide To Custom Trainers

24/03/2015 1:35 PM

Then select this button (either click it in the Form or click it's entry in the Properties / Object Inspector) and tweak
it as well. Make it have "About" for a caption, and then change the Width, Height, Top and Left properties to resize and move
it. The Top and Left properties are the distance in pixels from the upper-left corner. For this tutorial, you're going to want
to position the button in the bottom-right, and remember to change "Caption" for the display text, not "name"!
Once the button is positioned where you want and looks the way you want it to, it's time to make it do something. Make sure
the button is selected and then go to the "events" tab and check out the "OnClick" entry. It will have both a dropdown box and
a "..." button. The dropdown box will list various functions to be run when the button is clicked... but we don't have a
function for it yet, so clicking the "..." button will open the Lua form and insert a function for it at the bottom.

So when the user clicks the button, it will call this function. The function is just one blank line right now, so you'll
want to copy-paste "showMessage(AboutText)" into it, which is the function it should call. This is a function that shows a
message box containing the AboutText that was part of the first stuff we put into the script.

So overall the Lua script should look something like this right now.
Code:
AboutText=[[Sample About Text Here]]
form_show(UDF1)
getAutoAttachList().add("doukutsu.exe")
function CloseClick()
closeCE()
return caFree
end
UDF1.OnClose = CloseClick
addresslist=getAddressList()
function CEButton1Click(sender)
showMessage(AboutText)
end

http://forum.cheatengine.org/viewtopic.php?p=5576412

Cheat Engine :: View topic - Rydian's Guide To Custom Trainers

24/03/2015 1:35 PM

The next thing we'll be doing is adding a sidebar image. Click the picture button in the Form Designer and then click in
the Trainer form to insert the image.

Then with the image selected in the Object Inspector, go to the "Picture" attribute, click the "..." button, then browse to
and select the sidebar image I attached to this post.

Make sure to change the image object's size and location to 100x300 (the size of the included sidebar image) and position it
on the left (top 0 and left 0 will make it fit exactly on the lefthand side).

http://forum.cheatengine.org/viewtopic.php?p=5576412

Cheat Engine :: View topic - Rydian's Guide To Custom Trainers

24/03/2015 1:35 PM

When you're done resizing it and such, it's time to test it. Close the Form windows and leave just the main CE window and Lua
form open. Then in the Lua form, click the "Execute" button at the bottom. This should open the trainer and you should be able
to click the "About" button and have it show the info.

If so, move onto the next section. If not, make sure you didn't typo or accidentally misname something.

- Checkbox & Button Toggles


Well it's about time to actually add some cheat scripts and make the trainer do something useful, isn't it? The first thing
we're going to add is a checkbox that will toggle an address freeze. In The Form Designer click the checkbox tool and then
click in the Trainer Form to add the checkbox. Give it a nice Caption (not "name") and position it the way you want.

After that, just like we did for the About button, we're going to add a function to the "OnChange" event.

This time, we're going to need to make the script a little more involved. When the user clicks the checkbox, we want the
script to determine the new state (checked or unchecked) and act based on that. So we'll use this, sticking it inside the
blank function that CE inserted for us.
Code:
if (checkbox_getState(UDF1.CECheckBox1) == 1) then
else
end

Note the phrase "UDF1.CECheckbox1". This is made up of two parts. The "UDF1" part is the name of the trainer form, while
"CECheckbox1" is the name of the checkbox we added. If you've renamed anything or when you go to add more things, be sure
that the names match.
So now that the function checks the status of the checkbox and does two separate things based on that, let's actually tell it
to freeze or unfreeze the first address in the cheat table (which is index 0).
Code:

http://forum.cheatengine.org/viewtopic.php?p=5576412

Cheat Engine :: View topic - Rydian's Guide To Custom Trainers

24/03/2015 1:35 PM

if (checkbox_getState(UDF1.CECheckbox1) == 1) then
CheatEntry=addresslist_getMemoryRecordByID(addresslist,0)
memoryrecord_freeze(CheatEntry)
else
CheatEntry=addresslist_getMemoryRecordByID(addresslist,0)
memoryrecord_unfreeze(CheatEntry)
end

So the entire function should look like this.

And it's time to test it! Close the Trainer Form and related boxes, then click "Execute" on the Lua Script window, if
everything went well you should see the trainer, and checking the box should have the desired effect.
But simply freezing values isn't enough in a lot of cases. Cave Story in particular starts you out with 3 HP, but the
starting area has spikes that do more than 3 damage, so they'll still kill you. In this case, we want to take the
"No HP Loss" script from the table and use that.
This time we'll make a toggle box (button) for the script. Find the "Togglebox" icon on the Form Designer toolbar
and then click and drag in the Trainer Form to create a toggle box. Resize and position and name it the way you want.
After this, just like before you want to go to the Events tab, and click "..." on the OnChange event to add the
function like you've done twice now. Go ahead and add the "if / else /end" code from before too since we're working
with a toggleable object, and make sure to rename the object being checked. If you did it right, it'll be this.
Code:
function CEToggleBox1Change(sender)
if (checkbox_getState(UDF1.CEToggleBox1) == 1) then
else
end
end

Now, in those two blank spaces we want to run our script for "No HP Loss". For this we want to use the autoAssemble()
function which will let us run AA scripts. We'll want to copy everything in the [ENABLE] section of the "No HP Loss"
script into the first blank section, and everything under [DISABLE] into the second blank section, like below.
(Note that the script has [[ at the start and ]] at the end, this is used to denote multi-line scripts.)
Code:
function CEToggleBox1Change(sender)
if (checkbox_getState(UDF1.CEToggleBox1) == 1) then
autoAssemble([[
alloc(newmem,2048) //2kb should be enough
label(returnhere)
label(originalcode)
label(exit)
newmem:
originalcode:
exit:
jmp returnhere
"Doukutsu.exe"+1997A:
jmp newmem
nop
nop
returnhere:
]])
else
autoAssemble([[
dealloc(newmem)
"Doukutsu.exe"+1997A:
mov [Doukutsu.exe+9E6CC],cx
]])
end
end

Quite a bit to put in, eh? But once you have this, you can just copy-paste it for each code you want and then replace
the script with the one from the table (I just strip comments and empty lines when doing this for visual clarity).
Anyways like before, once you have this in there, close the Trainer Form and related windows, then click the "Execute"
button at the bottom of the Lua window to run your trainer script and make sure stuff works out.

- Read & Write Forms


Let's say that we want to add some basic teleport functions to the trainer. We have addresses for the X and Y
coordinates in the table, and we want to let the user edit those values in the trainer for controlled teleportation.

http://forum.cheatengine.org/viewtopic.php?p=5576412

Cheat Engine :: View topic - Rydian's Guide To Custom Trainers

24/03/2015 1:35 PM

In order to do this, we'll need two Edit boxes and two normal buttons. Add them, and this time we actually do want
to change the Names, not just the Captions. I'll name the boxes CEEditX and CEEditY, and the buttons will be
CEButtonRead and CEButtonWrite so that we don't get confused. You'll want to clear their "Text" properties as well
so you don't have the placeholder text that I left in the screenshot there...

Now in order to make this setup functional, we'll first add a script to the OnClick Event of the "Read" button we made.
Code:
function CEButtonReadClick(sender)
setProperty(UDF1.CEEditX,"Text", readInteger("Doukutsu.exe+9E654"))
setProperty(UDF1.CEEditY,"Text", readInteger("Doukutsu.exe+9E658"))
end

The setProperty() function changes the Trainer Form, editing a property of one of the objects. In this case we're
targeting (by Name) the X and Y edit boxes we made. We're editing their Text properties (their contents) and for the
value to put in there we're using the readInteger() function to pull the coordinates in from the addresses (in the table).
Now we want to make the Write button do something too, so as usual select it and give it an OnClick event, use this code.
It's basically the last stuff but in reverse, we give it an address and then a value to write to, reading from the form.
Code:
function CEButtonWriteClick(sender)
writeInteger("Doukutsu.exe+9E654", getProperty(UDF1.CEEditX,"Text"))
writeInteger("Doukutsu.exe+9E658", getProperty(UDF1.CEEditY,"Text"))
end

If everything went as planned, you should be able to Execute the script and get the controlled teleportation!

- Saving / Distributing
Now that you have a (relatively-)fancy trainer, it's time to share it with the world, right? Go to File -> Save As
and choose to save the table as a standalone trainer (.exe). I highly suggest renaming the trainer (even just
appending "_trainer" to the name), you don't want it to have the same name as the process you're targeting,
despite the default name in CE tending to be just that.

After you've selected the location and file name to save as, you get the final step of making the trainer. This is
where you can choose an icon file (32x32 or 48x48 .ico format, I unfortunately can't attach the one I used) and some
final technical details. In general the options are either self-explanatory or CE will choose the right default for
your trainer, the only suggestion I have is to set the compression to "None" because AVs tend to complain about it.

http://forum.cheatengine.org/viewtopic.php?p=5576412

Cheat Engine :: View topic - Rydian's Guide To Custom Trainers

24/03/2015 1:35 PM

Once you click the "Generate" button, you're done! There's your fancy-pants trainer, have fun with it.
If you need some software to make an image into a, .ico file, IcoFX's freeware version is here.

sidebar.png
Description:

Sidebar image.

Filesize:

1.34 KB

Viewed:

2054 Time(s)

Doukutsu.CT
Description:

Table to work from.

Filename:

Doukutsu.CT
Download

Filesize:

8.2 KB

Downloaded:

122 Time(s)

_________________
Custom Trainers
Code AOBs And Scripts
Modern Pointers + AOB To Data
Value/Address Finding Examples
Attaching To Browser Games
Last edited by Rydian on Tue Feb 03, 2015 1:16 pm; edited 3 times in total

Back to top
Attack

Posted: Tue Feb 03, 2015 3:45 am

Post subject:

Cheater
Reputation: 0
Joined: 21 Mar 2011
Posts: 46
Location: Canada

Nice guide, thank you!


You can also simply convert your image to an ico file online: http://www.icoconverter.com/

Back to top
Krampus
Cheater

Posted: Tue Feb 03, 2015 10:23 am

Post subject:

Reputation: 0
Joined: 22 Nov 2014

http://forum.cheatengine.org/viewtopic.php?p=5576412

Cheat Engine :: View topic - Rydian's Guide To Custom Trainers

Posts: 37

24/03/2015 1:35 PM

Thanks for sharing!


_________________
string H4X[] = {"Aimbot", "Triggerbot", "ESP"};
for (unsigned int i = 0; i < 2; i++)
{
cout << H4X[i] << endl;
}

Back to top
Attack

Posted: Thu Feb 05, 2015 1:13 am

Post subject:

Cheater
Reputation: 0
Joined: 21 Mar 2011
Posts: 46
Location: Canada

Your guides have helped me a great deal! But wouldn't it be easier to use the auto tool, do the customization stuff and then edit the LUA script manually for
what the auto tool cannot do?

Back to top
Rydian
Grandmaster Cheater

Posted: Thu Feb 05, 2015 2:35 am

Post subject:

Attack wrote:
Your guides have helped me a great deal! But wouldn't it be easier to use the auto tool, do the customization stuff and then edit the LUA script
manually for what the auto tool cannot do?

The auto tool actually edits the table entries by adding hotkeys on any entry you have added, so you'd need to go and delete those manually if you don't
want them there ('cause they function even outside the realm of the trainer).
Reputation: 16
Joined: 17 Sep 2012
Posts: 542

And for tables that had more than just a few entries...
http://forum.cheatengine.org/viewtopic.php?t=568669
That process was getting annoying as fuck 'cause it'd overwrite and reset them (though that may have been a bug at the time, the generic trainer generator
tends to throw errors if you try to edit some things).
_________________
Custom Trainers
Code AOBs And Scripts
Modern Pointers + AOB To Data
Value/Address Finding Examples
Attaching To Browser Games

Back to top
Darktarx
How do I cheat?
Reputation: 0
Joined: 27 Apr 2014
Posts: 2

Posted: Tue Feb 17, 2015 3:47 pm

Post subject:

Thanks for this awesome guide.


Also, can you explain how to use variables in asm script?
For example i have script like this:
Code:
[ENABLE]
//code from here to '[DISABLE]' will be used to enable the cheat
alloc(newmem,2048)
label(returnhere)
label(originalcode)
label(exit)
newmem: //this is allocated memory, you have read,write,execute access
mov [eax+000000CC],(int)3
originalcode:
mov ecx,[eax+000000CC]
exit:
jmp returnhere
"fifa11.exe"+DC0B04:
jmp newmem
nop
returnhere:

[DISABLE]
//code from here till the end of the code will be used to disable the cheat
dealloc(newmem)
"fifa11.exe"+DC0B04:
mov ecx,[eax+000000CC]

And I wonder if it is possible to read value from editbox and use it in my asm script insteand of "(int)3".
I hope you will understand.
Back to top
Zanzer
Master Cheater

Posted: Tue Feb 17, 2015 5:53 pm

Post subject:

Reputation: 10
Joined: 09 Jun 2013

http://forum.cheatengine.org/viewtopic.php?p=5576412

10

Cheat Engine :: View topic - Rydian's Guide To Custom Trainers

Posts: 361

24/03/2015 1:35 PM

You can declare your own variable inside that script and use it within your code.
Code:
[ENABLE]
alloc(myvar,4)
myvar:
db 03 00 00 00 // default to 3
registersymbol(myvar)
// ... other code ...
mov ecx,[myvar]
mov [eax+000000CC],ecx
[DISABLE]
dealloc(myvar)
unregistersymbol(myvar)
// ... other code ...

Then you can retrieve and edit that value using LUA.
Code:
addr = getAddress("myvar")
myvar = readInteger(addr)
myvar = myvar + 1
writeInteger(addr, myvar)
Back to top
Display posts from previous: All Posts

Oldest First

Cheat Engine Forum Index -> Cheat Engine Tutorials

Go
All times are GMT - 6 Hours

Page 1 of 1

http://forum.cheatengine.org/viewtopic.php?p=5576412

Jump to: Cheat Engine Tutorials


You cannot post new topics
You cannot reply to topics
You cannot edit your posts
You cannot delete your posts
You cannot vote in polls
You cannot attach files
You can download files

Go
in
in
in
in
in
in
in

this
this
this
this
this
this
this

forum
forum
forum
forum
forum
forum
forum

Powered by phpBB 2001, 2005 phpBB Group


CE Wiki IRC (#CEF) Twitter

11