Cheat Engine Forum Index Cheat Engine
The Official Site of Cheat Engine
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 


Rydian's Guide To Custom Trainers

 
Post new topic   Reply to topic    Cheat Engine Forum Index -> Cheat Engine Tutorials
View previous topic :: View next topic  
Author Message
Rydian
Grandmaster Cheater Supreme
Reputation: 31

Joined: 17 Sep 2012
Posts: 1358

PostPosted: Tue Feb 03, 2015 2:32 am    Post subject: Rydian's Guide To Custom Trainers This post has 1 review(s) Reply with quote

- 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!




- 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.



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.




- 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.



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


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).



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:
  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.
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.



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:  95569 Time(s)

sidebar.png



Doukutsu.CT
 Description:
Table to work from.

Download
 Filename:  Doukutsu.CT
 Filesize:  8.2 KB
 Downloaded:  3229 Time(s)


_________________


Last edited by Rydian on Tue Feb 03, 2015 1:16 pm; edited 3 times in total
Back to top
View user's profile Send private message
Attack
Cheater
Reputation: 0

Joined: 21 Mar 2011
Posts: 46
Location: Canada

PostPosted: Tue Feb 03, 2015 3:45 am    Post subject: Reply with quote

Nice guide, thank you!

You can also simply convert your image to an ico file online: http://www.icoconverter.com/
Back to top
View user's profile Send private message
Krampus
Cheater
Reputation: 0

Joined: 22 Nov 2014
Posts: 41

PostPosted: Tue Feb 03, 2015 10:23 am    Post subject: Reply with quote

Thanks for sharing!
_________________
There is no spoon.
Back to top
View user's profile Send private message
Attack
Cheater
Reputation: 0

Joined: 21 Mar 2011
Posts: 46
Location: Canada

PostPosted: Thu Feb 05, 2015 1:13 am    Post subject: Reply with quote

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
View user's profile Send private message
Rydian
Grandmaster Cheater Supreme
Reputation: 31

Joined: 17 Sep 2012
Posts: 1358

PostPosted: Thu Feb 05, 2015 2:35 am    Post subject: Reply with quote

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).

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).

_________________
Back to top
View user's profile Send private message
Darktarx
How do I cheat?
Reputation: 0

Joined: 27 Apr 2014
Posts: 3

PostPosted: Tue Feb 17, 2015 3:47 pm    Post subject: Reply with quote

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. Very Happy
Back to top
View user's profile Send private message
Zanzer
I post too much
Reputation: 126

Joined: 09 Jun 2013
Posts: 3278

PostPosted: Tue Feb 17, 2015 5:53 pm    Post subject: Reply with quote

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
View user's profile Send private message
Vidit
How do I cheat?
Reputation: 0

Joined: 29 Mar 2015
Posts: 6
Location: India

PostPosted: Sun Apr 05, 2015 1:42 am    Post subject: Reply with quote

Cheat Table not coming .I am using online game.8 ball pool
Back to top
View user's profile Send private message
Bl00dWolf
Advanced Cheater
Reputation: 0

Joined: 04 Jan 2010
Posts: 79
Location: Russia, Moscow

PostPosted: Fri Sep 11, 2015 6:34 am    Post subject: Reply with quote

Is it possible to add music to trainer? Like mp3 or xm.
_________________
Sry for my english, Hitler.
Back to top
View user's profile Send private message
Rydian
Grandmaster Cheater Supreme
Reputation: 31

Joined: 17 Sep 2012
Posts: 1358

PostPosted: Fri Sep 11, 2015 12:40 pm    Post subject: Reply with quote

CE does have XM playback support but I never bothered with it.

MP3 is just going to inflate the trainer's size too much and I believe trainers should be silent anyways because they're for games and you want to hear the game most of the time.

_________________
Back to top
View user's profile Send private message
ZeroServer
How do I cheat?
Reputation: 0

Joined: 21 Sep 2015
Posts: 3

PostPosted: Wed Sep 23, 2015 8:57 am    Post subject: Reply with quote

I am lost lol
Back to top
View user's profile Send private message
D1g1Byt3
Cheater
Reputation: 0

Joined: 02 Dec 2015
Posts: 40

PostPosted: Thu Dec 03, 2015 1:13 am    Post subject: Just Curious Reply with quote

Is there a way you can Freeze the value of a Pointer? I can't seem to get it to work with a Pointer I found.

At this part:
Quote:

function CECheckbox1Change(sender)
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
end


I made sure its the first Address in My list, if I change the value at:(addresslist,0) from 0 to 1. It just Freezes the Script for the NOP Patch. I'm probably doing something wrong, but would appreciate some help. Thanks in Advance.



Trainer Prob.png
 Description:
 Filesize:  24.69 KB
 Viewed:  81415 Time(s)

Trainer Prob.png


Back to top
View user's profile Send private message
sti228
Newbie cheater
Reputation: 0

Joined: 24 Jan 2015
Posts: 14
Location: Georgia/Tbilisi

PostPosted: Wed Feb 17, 2016 2:55 pm    Post subject: Reply with quote

Great tutorial but can you explain how to make buttons ? Rolling Eyes

Something like this but with new CE 6.5 Smile This is old tutorial.

https :// www . youtube . com / watch?v = Xtro9 _ bMoa0
Back to top
View user's profile Send private message
Rydian
Grandmaster Cheater Supreme
Reputation: 31

Joined: 17 Sep 2012
Posts: 1358

PostPosted: Thu Feb 18, 2016 12:57 am    Post subject: Re: Just Curious Reply with quote

D1g1Byt3 wrote:
Is there a way you can Freeze the value of a Pointer? I can't seem to get it to work with a Pointer I found.

At this part:
Quote:

function CECheckbox1Change(sender)
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
end


I made sure its the first Address in My list, if I change the value at:(addresslist,0) from 0 to 1. It just Freezes the Script for the NOP Patch. I'm probably doing something wrong, but would appreciate some help. Thanks in Advance.
The way you have it set up right now, when it's clicked if it's already checked then it will freeze it, if it's not checked and you check it it will unfreeze it? So you'll want to invert the check or swap the freeze/unfreeze.


sti228 wrote:
Great tutorial but can you explain how to make buttons ? Rolling Eyes

Something like this but with new CE 6.5 Smile This is old tutorial.

https :// www . youtube . com / watch?v = Xtro9 _ bMoa0
This guide is where you start.

If you want to do fancier custom things, then you will need to learn Lua and how to do fancier custom things.

_________________
Back to top
View user's profile Send private message
HolyGODZ
How do I cheat?
Reputation: 0

Joined: 28 Feb 2016
Posts: 3

PostPosted: Sun Feb 28, 2016 2:17 am    Post subject: Reply with quote

I have the same problem as D1g1Byt3. When I click on the checkbox it look to work but when I unchek it I get a message like in my attachment.
Thanks.



error.jpg
 Description:
 Filesize:  32.04 KB
 Viewed:  74368 Time(s)

error.jpg



_________________
A guy who like to create cheat!
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    Cheat Engine Forum Index -> Cheat Engine Tutorials All times are GMT - 6 Hours
Page 1 of 1

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


Powered by phpBB © 2001, 2005 phpBB Group

CE Wiki   IRC (#CEF)   Twitter
Third party websites