Gamepad event

Want Cheat Engine to do something specific and no idea how to do that, ask here. (From simple scripts to full trainers and extensions)
Post Reply
Fruitpunch
Novice Cheater
Novice Cheater
Posts: 23
Joined: Sat Sep 09, 2017 1:07 pm
Reputation: 0

Gamepad event

Post by Fruitpunch » Fri Jun 29, 2018 6:10 pm

Hello,



I was hoping to create a filter inside asm script using a controller event e.g. if a certain button is pressed then something happens.

I found that there is a lua function for a xbox controller but I have never used lua.



I pieced this together from various sources and it obviously does not work.



[CODE]

{$lua}

local tbl = getXbox360ControllerState()



if tbl.GAMEPAD_A then

writeFloat('[rbx+00000100]', 50)

end

{$asm}

[/CODE]



Do you think this is possible?

User avatar
FreeER
Expert Cheater
Expert Cheater
Posts: 142
Joined: Fri Mar 10, 2017 7:11 pm
Reputation: 12
Contact:

Gamepad event

Post by FreeER » Fri Jun 29, 2018 6:32 pm

That would run once, most likely you won't be pressing A at the exact moment that you enable the script :)



To have it constantly check you'd use a timer eg.



[code=lua]{$lua}

[ENABLE]

globalXboxATimer = createTimer()

globalXboxATimer.Interval = 10 -- eh poll every 10 milliseconds

globalXboxATimer.OnTimer = function()

local tbl = getXbox360ControllerState()

if tbl.GAMEPAD_A then

writeFloat('address rbx+100 refers to because registers don't exist as global variables every thread has a full set of registers that are constantly changing as assembly instructions are executed', 50)

end

end



[DISABLE]

-- destroy and stop the timer when disabled

globalXboxATimer.destroy()[/code]



To actually use a register like rbx you'd have to either set a breakpoint in lua and run the code when that breakpoint is hit... probably slow if it happens often (break, switch to debugger, check if it should run lua code, maybe run lua code, return to debugger, resume, multiple times a second) and unreliable if it doesn't (you'd have to be holding A at exactly the right time when it checks).



Or do the check in asm with by calling the actual C function... something like this [URL='https://github.com/cheat-engine/cheat-engine/blob/c193fa2c20b5c3cdf037fab4e8e270b2f20823c1/Cheat%20Engine/LuaHandler.pas#L8513-L8581']https://github.com/cheat-engine/cheat-engine/blob/c193fa2c20b5c3cdf037fab4e8e270b2f20823c1/Cheat Engine/LuaHandler.pas#L8513-L8581[/URL] but translated to asm and having to look up what all the defines and sizes and determining offsets are because it's asm not a high level language (though iirc CE does allow struct definitions which may make using the offsets slightly easier than just plain asm and hardcoded offsets).



Alternatively you could try using this extension [URL]https://forum.cheatengine.org/viewtopic.php?t=607828[/URL] which is meant to make calling lua functions from assembly easier (I haven't tried it myself), because {$lua} blocks actually run [I]before[/I] any assembly code is actually assembled, and if it returns a string then that gets treated as AA code, actually calling a lua function from asm code requires setting up a lua server connection and stuff like that, there's an AA template for it but it's a bit annoying.



However if you find a pointer to the actual address eg. ["game.exe"+150]+20 then you can use that in the writeFloat call eg writeFloat('["game.exe"+150]+20', 50) and then you may not need any of the above since you no longer need to use a register that's associated with a thread executing a specific point in the code, but it won't necessary run at exactly that point in time, however it will run fairly often which may be good enough to eg. set your health to max.



Doing what you want is probably possible, but it's not quite that simple :)
Last edited by FreeER on Thu Jan 01, 1970 12:00 am, edited 2 times in total.

Fruitpunch
Novice Cheater
Novice Cheater
Posts: 23
Joined: Sat Sep 09, 2017 1:07 pm
Reputation: 0

Gamepad event

Post by Fruitpunch » Sat Jun 30, 2018 5:47 am

[QUOTE]That would run once, most likely you won't be pressing A at the exact moment that you enable the script :) [/QUOTE]

The opcode that I found is constantly run and that's where I would do the injection so I don't quite see how it would only run once. Or does the lua part only run when the script is enabled? But yes, the timer would most likely be needed anyway.



The part about the register. Is it not possible to save the address in the register to memory? I don't know if the writeFloat command works for that though.



Something like this:

[CODE]mov [address],rbx

{$lua}

...

writeFloat('[address]+20',50)

{$asm}

[/CODE]



Since the lua part is actually run first the address would have to be actually saved in lua.

User avatar
FreeER
Expert Cheater
Expert Cheater
Posts: 142
Joined: Fri Mar 10, 2017 7:11 pm
Reputation: 12
Contact:

Gamepad event

Post by FreeER » Sat Jun 30, 2018 3:57 pm

[QUOTE="Fruitpunch, post: 50629, member: 8443"]Or does the lua part only run when the script is enabled?[/QUOTE]this though if it's in the disable section it only runs when it's disabled but it still runs before any asm code in the disable section. :) If you're used to programming think of {$lua} as a meta-programming technique.



[QUOTE="Fruitpunch, post: 50629, member: 8443"]Is it not possible to save the address in the register to memory?[/QUOTE]Yeah, you can do an injection copy and then use the name of the symbol in writeFloat eg [icode]if getAddressSafe('symbol') then writeFloat('[symbol]+20', 50) end[/icode]
Last edited by FreeER on Sat Jun 30, 2018 5:05 pm, edited 3 times in total.

Post Reply