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 


Xbox Controller function help
Goto page 1, 2  Next
 
Post new topic   Reply to topic    Cheat Engine Forum Index -> Cheat Engine Lua Scripting
View previous topic :: View next topic  
Author Message
Flux.
Advanced Cheater
Reputation: 0

Joined: 10 Nov 2016
Posts: 88
Location: Another World - N5X2 106311411+2123518

PostPosted: Sat Nov 23, 2019 9:27 am    Post subject: Xbox Controller function help Reply with quote

Hello, Trying to add rapid fire to a button on an Xbox controller, but its not working properly and info is really scarce.
In the below table, i was assuming that X button was boolean and 1 means the key is pressed down.
But using 0 or 1 does the same thing, it constantly repeats even when the button is not pushed ?
Any ideas would be appreciated.
Code:
function fast(timer)
local tbl = getXBox360ControllerState()
  if tbl.GAMEPAD_X ~= 0 then
  keyDown(VK_LBUTTON)
  sleep(250)
  keyUp(VK_LBUTTON)
  end

t=createTimer(nil)
timer_setInterval(t, 300)
timer_onTimer(t, fast)
end
Back to top
View user's profile Send private message
mgr.inz.Player
I post too much
Reputation: 222

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

PostPosted: Sat Nov 23, 2019 9:41 am    Post subject: Reply with quote

GAMEPAD_X is a boolean value, not a number.
so, use only true or false.


Code:
if tbl.GAMEPAD_X==true then

end

_________________
Back to top
View user's profile Send private message MSN Messenger
Flux.
Advanced Cheater
Reputation: 0

Joined: 10 Nov 2016
Posts: 88
Location: Another World - N5X2 106311411+2123518

PostPosted: Sat Nov 23, 2019 9:59 am    Post subject: Reply with quote

Hello mgr.inz.Player, Its good to see you, it seemed liked you had dissapeared for a little while.
Thank you responding, i tried what you said, now the button just functions normally, any ideas ?
Code:
function fast(timer)
local tbl = getXBox360ControllerState()
  if tbl.GAMEPAD_X==true then
  keyDown(VK_LBUTTON)
  sleep(250)
  keyUp(VK_LBUTTON)
  end
end
Back to top
View user's profile Send private message
mgr.inz.Player
I post too much
Reputation: 222

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

PostPosted: Sat Nov 23, 2019 10:43 am    Post subject: Reply with quote

Did you test your idea without CE? Does clicking left mouse button while xbox controller X button is pressed works at all, your game allows that?

If yes, then maybe this will work for you, complete AA script:
Code:
[ENABLE]
{$Lua}
if syntaxcheck then return end

rapidFireToButtonOnAnXboxController_mouseup = false

function fast(t)
  if rapidFireToButtonOnAnXboxController_mouseup then
    mouse_event(MOUSEEVENTF_LEFTUP)
    rapidFireToButtonOnAnXboxController_mouseup = false
    return
  end

  local tbl = getXBox360ControllerState()
  if tbl and tbl.GAMEPAD_X then
    mouse_event(MOUSEEVENTF_LEFTDOWN)
    rapidFireToButtonOnAnXboxController_mouseup = true
  end
end

if rapidFireToButtonOnAnXboxController_timer==nil then
  rapidFireToButtonOnAnXboxController_timer=createTimer(nil)
end

rapidFireToButtonOnAnXboxController_timer.Interval=200
rapidFireToButtonOnAnXboxController_timer.setOnTimer(fast)
rapidFireToButtonOnAnXboxController_timer.Enabled = true
{$Asm}

[DISABLE]
{$Lua}
if syntaxcheck then return end

if rapidFireToButtonOnAnXboxController_timer then
  rapidFireToButtonOnAnXboxController_timer.Enabled = false
end
{$Asm}

_________________
Back to top
View user's profile Send private message MSN Messenger
Flux.
Advanced Cheater
Reputation: 0

Joined: 10 Nov 2016
Posts: 88
Location: Another World - N5X2 106311411+2123518

PostPosted: Sat Nov 23, 2019 11:04 am    Post subject: Reply with quote

Thank you again mgr.inz.Player for replying.
Unfortunately that does not work either.
With no scripts enabled if i hold down x on the controller mouse 1 does not work. they are the same function (attack button)
So i also tested the script below in a few variations, but that's not working either.
What i was trying to do is make the x button on the controller rapid fire,

Code:
{$lua}
[ENABLE]
function fast(timer)
local tbl = getXBox360ControllerState()
  if tbl.GAMEPAD_X == true then
  keyDown(GAMEPAD_X)
  sleep(250)
  keyUp(GAMEPAD_X)
  end
end

t=createTimer(nil)
timer_setInterval(t, 300)
timer_onTimer(t, fast)

[DISABLE]
timer_setEnabled(t, false)
Back to top
View user's profile Send private message
mgr.inz.Player
I post too much
Reputation: 222

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

PostPosted: Sat Nov 23, 2019 11:13 am    Post subject: Reply with quote

In that case you will have to find an address in game process memory which changes its value when you press buttons on your xbox controller.

Then do "find out what access this address". Then inject your code at those places. I think you do not need Lua script for this at all.

_________________
Back to top
View user's profile Send private message MSN Messenger
Flux.
Advanced Cheater
Reputation: 0

Joined: 10 Nov 2016
Posts: 88
Location: Another World - N5X2 106311411+2123518

PostPosted: Sat Nov 23, 2019 11:36 am    Post subject: Reply with quote

Thank you again mgr.inz.Player.
Could you tell me why the script is not working, just trying to understand it a little better.
i cant simply have a key or controller button repeat by holding down the button, without finding some memory that changes the value associated ?
Code:

{$lua}
[ENABLE]
function fast(timer)
local tbl = getXBox360ControllerState()
  if tbl.GAMEPAD_X == true then          -- if the x button is pushed
  keyDown(GAMEPAD_X)                      -- virtual key down of the same x button
  sleep(250)                                       -- wait
  keyUp(GAMEPAD_X)                          -- virtual key release of the same x button
  end
end

t=createTimer(nil)                               -- timer loops the instruction
timer_setInterval(t, 300)
timer_onTimer(t, fast)

[DISABLE]
timer_setEnabled(t, false)
Back to top
View user's profile Send private message
mgr.inz.Player
I post too much
Reputation: 222

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

PostPosted: Sat Nov 23, 2019 11:54 am    Post subject: Reply with quote

GAMEPAD_X, the one you used inside keyDown, is nil. You can check it with "return GAMEPAD_X" executed inside "Lua Engine" window.

There is only GAMEPAD_X entry inside state table (result of getXBox360ControllerState function is a table)

Anyway, It will not work. If you can not use left mouse button and controller X button at the same time, methods with keyDown, keyUp, doKeyPress, mouse_event will just not work.

You have to find how the game gets controller states, be it XInput or DirectInput. Then inject code there.

_________________
Back to top
View user's profile Send private message MSN Messenger
Flux.
Advanced Cheater
Reputation: 0

Joined: 10 Nov 2016
Posts: 88
Location: Another World - N5X2 106311411+2123518

PostPosted: Sat Nov 23, 2019 12:04 pm    Post subject: Reply with quote

OK thank you mgr.inz.Player.
When i started looking into this rapid fire button, i thought it was going to be something simple to do, was i wrong.
Thank you for taking the time mgr.inz.Player it is very appreciated.
Back to top
View user's profile Send private message
mgr.inz.Player
I post too much
Reputation: 222

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

PostPosted: Sat Nov 23, 2019 1:17 pm    Post subject: Reply with quote

It's tricky do to it when you want to play with controller. It is much easier when you only use mouse+keyboard.

Anyway, lets find out what it is using. Probably both: dinput8.dll and XInput1_4.dll

What result you get when you execute this Lua script inside "Lua Engine" window, of course after opening game process:
Code:

tab = enumModules()
for i=1,#tab do
  if tab[i].Name:lower():match"xinput" then
    print("game uses xinput: "..tab[i].PathToFile)
  end
  if tab[i].Name:lower():match"dinput" then
    print("game uses dinput: "..tab[i].PathToFile)
  end
end

_________________
Back to top
View user's profile Send private message MSN Messenger
Flux.
Advanced Cheater
Reputation: 0

Joined: 10 Nov 2016
Posts: 88
Location: Another World - N5X2 106311411+2123518

PostPosted: Sat Nov 23, 2019 2:20 pm    Post subject: Reply with quote

Hello mgr.inz.Player.
The result of that script is -
game uses xinput: C:\Windows\SYSTEM32\XINPUT1_3.dll
Back to top
View user's profile Send private message
mgr.inz.Player
I post too much
Reputation: 222

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

PostPosted: Sat Nov 23, 2019 2:54 pm    Post subject: Reply with quote

I think you can hook XInputGetState function. And do the magic there.
_________________
Back to top
View user's profile Send private message MSN Messenger
Flux.
Advanced Cheater
Reputation: 0

Joined: 10 Nov 2016
Posts: 88
Location: Another World - N5X2 106311411+2123518

PostPosted: Sat Nov 23, 2019 3:44 pm    Post subject: Reply with quote

Hello mgr.inz.Player, struggling on this, have gone to enumerate dll's and symbols, and found XInputGetState function, and added a script to my cheat table, but not exactly sure what to put in the table, currently trying a few variations.
Back to top
View user's profile Send private message
mgr.inz.Player
I post too much
Reputation: 222

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

PostPosted: Sat Nov 23, 2019 5:30 pm    Post subject: Reply with quote

you have to alter XINPUT_STATE structure the one passed to the XInputGetState function.

https://docs.microsoft.com/pl-pl/windows/win32/api/xinput/nf-xinput-xinputgetstate

https://docs.microsoft.com/pl-pl/windows/win32/api/xinput/ns-xinput-xinput_state

Maybe I will find some free time to make "simple" AA script for XInputGetState from XINPUT1_3.dll

_________________
Back to top
View user's profile Send private message MSN Messenger
Flux.
Advanced Cheater
Reputation: 0

Joined: 10 Nov 2016
Posts: 88
Location: Another World - N5X2 106311411+2123518

PostPosted: Sun Nov 24, 2019 6:21 am    Post subject: Reply with quote

Hello mgr.inz.Player, that will be to difficult for me, but thank you for taking the time to help and explain things.
On a positive note, by unbinding the X button, and then using your above script, it works perfectly.
Its a bit of a work around and the button requires a script enabled to function, but it works none the less.
Thanks for your help mgr.inz.Player i wouldn't have got it working without you.
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 Lua Scripting All times are GMT - 6 Hours
Goto page 1, 2  Next
Page 1 of 2

 
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