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 


Making your trainer the boopinest

 
Post new topic   Reply to topic    Cheat Engine Forum Index -> Cheat Engine Lua Scripting
View previous topic :: View next topic  
Author Message
gir489
Grandmaster Cheater
Reputation: 14

Joined: 03 Jan 2012
Posts: 835
Location: Maryland, United States

PostPosted: Wed Jun 12, 2013 6:41 pm    Post subject: Making your trainer the boopinest Reply with quote

Since I hate Lua with a passion, I don't like to write stuff in it, I try to find a C++ or ASM solution to my problems. One of the major problems I was having with my Fallout trainer was that it was playing the beep() function on both activate and deactivate. While this is fine in a perfect world, sometimes the trainer would fail to activate and I'd be half an hour in to a play through and have to stat shooting someone, and notice the ammo isn't going up when I shoot. So, naturally the first thing I did was looked at the auto generated Lua, which I dreaded the day I would have to.

I noticed that if a global var was set, it would call beep(). I looked at the source on the SVN, and it was just a wrapper function for SysUtils.Beep() which is a C++ helper class. I thought it was just doing something fancy in Lua. How silly of me, of course Lua can't do anything without C++'s help.

So, I didn't want to write a C++ module just to make some noise, especially since I wanted to just make a regular Windows noise. So, I looked up some WinAPI funcs that I could try to call with some ASM, and found a function called PlaySoundA. Takes a string, some HMODULE that is never passed, and a 32-bit flag var.'

So with some fancy Auto Assembling, I manged to write this script:

Code:
globalalloc(callplaysounda,64) //Create the thread space.
createthread(callplaysounda) //Inject the thread in to the queue.
alloc(wavelocation,64) //Create a location for our string in memory.
wavelocation: //Assign the bytes to the string address.
db 4D 65 64 69 61 5C 57 69 6E 64 6F 77 73 20 45 78 63 6C 61 6D 61 74 69 6F 6E 2E 77 61 76 00 77 61 76 //Media\Windows Exclamation.wav

callplaysounda:
push 1 //Push SND_ASYNC
push 0 //No HMODULE
push wavelocation //Push AddressOf(wavelocation)
call WINMM.PlaySoundA //Call PlaySoundA
ret //Return

dealloc(callplaysounda) //After the thread runs, deallocate the thread.
dealloc(wavelocation) //Deallocate the string.


I put that in my enable, and for the disable, I just have it do this in the Lua:
Code:
  if isActive == false then
    beep()
  end


I understand that the CETrainers were originally designed to just be a testing platform for actual trainer coders to just give to the test team, while he writes the actual trainer, but I can't be fucked to write a trainer each time in C++. It's so much easier to just make a table, hit auto generate, use the nice GUI'D GUI designer and then CTRL+S that shit.
Back to top
View user's profile Send private message
mgr.inz.Player
I post too much
Reputation: 218

Joined: 07 Nov 2008
Posts: 4438
Location: W kraju nad Wisla. UTC+01:00

PostPosted: Thu Jun 13, 2013 4:18 am    Post subject: Re: Making your trainer the boopinest Reply with quote

gir489 wrote:
of course Lua can't do anything without C++'s help.

95% of my Lua script (in CheatEngine) is:
registered functions created by DB. Rest of code are: loops, tables, string concatenations (and other operations), checking if nil, simple math like math.sqrt( (bx-ax)^2 + (by-ay)^2 + (bz-az)^2 )

Borderlands2 "spawn cheats" would be pain in ass, without Lua of course.







My fancy Auto Assembling and Lua scripting, for CETRAINER ( CE6.2 ):
http://forum.cheatengine.org/viewtopic.php?t=559298

Basically:
1) CE attaches to itself
2) injects DLL to itself (winmm.dll)
3) exports wave file added to table, it's saved in TEMP dir
4) loads this wave file into allocated memory
5) deletes wave file from TEMP dir
6) calling winmm.PlaySoundA works under 32bit and 64bit
7) waits for specific processname and attaches to this process

Works for games that do not use winmm, and I don't have to inject this DLL into game process. I can change script with ease and have few different sounds (enabling sound, disabling sound, error sound, etc)

Code:
function onPostHotkey0(Hotkey)
  local memrec=memoryrecordhotkey_getOwner(Hotkey)
  local isActive=memoryrecord_isActive(memrec) --get the state after the hotkey got triggered
  cheatcomponent_setActive(CETrainer_CHEAT0, isActive)
  if gBeepOnAction then
    if isActive then customSound.beepEnable() end
    if not isActive then customSound.beepDisable() end
  end
end




With new CE6.3, I would create slightly different AA and Lua script.


 

_________________
Back to top
View user's profile Send private message MSN Messenger
Display posts from previous:   
Post new topic   Reply to topic    Cheat Engine Forum Index -> Cheat Engine Lua Scripting 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