Gamepad event

Fruitpunch

Novice Cheater
Sep 9, 2017
19
0
1
#1
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}
Do you think this is possible?
 

FreeER

RCE Fanatics
Talents
Mar 10, 2017
101
7
18
#2
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.

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()
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 https://github.com/cheat-engine/cheat-engine/blob/c193fa2c20b5c3cdf037fab4e8e270b2f20823c1/Cheat Engine/LuaHandler.pas#L8513-L8581 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 https://forum.cheatengine.org/viewtopic.php?t=607828 which is meant to make calling lua functions from assembly easier (I haven't tried it myself), because {$lua} blocks actually run before 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 :)
 

Fruitpunch

Novice Cheater
Sep 9, 2017
19
0
1
#3
That would run once, most likely you won't be pressing A at the exact moment that you enable the script :)
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}
Since the lua part is actually run first the address would have to be actually saved in lua.
 

FreeER

RCE Fanatics
Talents
Mar 10, 2017
101
7
18
#4
Or does the lua part only run when the script is enabled?
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.

Is it not possible to save the address in the register to memory?
Yeah, you can do an injection copy and then use the name of the symbol in writeFloat eg if getAddressSafe('symbol') then writeFloat('[symbol]+20', 50) end
 
Last edited:
Top Bottom