AHK Veteran Puzzled by Mouse in Inquisitor Game

Ask gaming related questions (AHK v1.1 and older)
Maxol
Posts: 8
Joined: 25 Apr 2019, 05:36

AHK Veteran Puzzled by Mouse in Inquisitor Game

23 Aug 2019, 05:54

Yes, I'm an AutoHotkey veteran and I love to use it to improve playbility of games! Remapping keys of course, autosaves, taking screenshots and showing these directly on the 2nd monitor, finding images, scanning pixels, better scrolling through shop items, move items from one character to another, and then there's clicking, a lot of clicking, on frequently used buttons that I map with a hotkey to avoid using the mouse...

You know the problem: there is no hotkey in the game to press a button, for example close a frequently used dialog. With AutoHotkey you can easily have ESC close your dialog: you find out if the dialog is open with PixelGetColor or ImageSearch. If not you just send ESC. But if you find it then you send a click to the close button on your dialog. To do that you use the coordinates you find with ImageSearch or you simply use hardcoded coodinates because the dialog is always in the same position.

This usually works as a charm :D but now I'm playing this game Inquisitor and despite my efforts I AM COMPLETY LOST!.

I cannot get a grip on the position of the Mouse in this game!

This is a fullscreen game and I play this game at 1280x720 (A_ScreenWidth / A_ScreenHeight) on a 1920x1080 monitor. My second monitor (to the left) is also 1920x1080.

Testcase 1: Mouse Coordinates
Let's get the mouse coordinates with a simple hotkey

Code: Select all

f1::
    MouseGetPos x,y
    SetTooltip(x . "," . y,3000)
    return
Note: The SetTooltip function shows the result on the second monitor while the game is running fullscreen

We Alt-Tab to the game and see the cursor in the center of the screen.
Press F1 -> 640,360 This looks good! :P
Move the mouse to the left a little -> 613,360 still good :P
Move the mouse up a little -> 613,340 still good :P
Move the mouse down a little -> 611,430 still good :P
Move the mouse to the right -> 834,363 still good :P

No problems here, right!? :P

Let's continue:
Move the mouse to the left edge -> 36,340 still good :P
Now we bump the edge with the mouse -> -50,340 BANG! What's this? :crazy: There you see my problem...
The cursor is stuck at the left but we move the mouse further left -> -130,340 The x decreases :?:
Further left -> -530,340
The cursor is still at the left edge, we move the mouse to the right so the cursor is not touching the edge -> -350,340 Still negative!

We Alt-Tab out of the game and then into the game again. The cursor is in the center again and the x,y values are good.
This time we test the right side but we cannot get the x to exceed 1079. We also test the top and the bottom but y is always between 0 and 719. But it's not perfect because when we move the mouse to the bottom, reaching 719 and then all the way up again just a few pixels before the top edge, the y reads 63 instead of 2 or 3.

There is one thing left to test. How far can we move the mouse to the left? How negative can we get the number? Well, that's -1920. :idea: That's interesting so apparantly the game is moving the mouse into the secondary monitor!

Testcase 2: MouseMove

Let's try moving the mouse:

Code: Select all

F2::MouseMove, 640, 360, 0
We Alt-Tab out of the game and then into the game again. The cursor is in the center again and the x,y values are good.

Move the mouse to the left and press F1 -> 613,360
We press F2 -> Nothing happens! :!:
We press F1 again -> 640,360 :?:

That's weird....

Let's try relative moving, 1 pixel to the right:

Code: Select all

F3::MouseMove, 1, 0, 0, R
We Alt-Tab out of the game and then into the game again. The cursor is in the center again and the x,y values are good.

We press F1 -> 640,360
We press F3 -> Nothing happens! :!:
We press F1 -> 641,360 :?:
We press F3 -> The mouse moves! But it's not one pixel, it moved appx. 210 pixels to the right
We press F1 -> 642,360 :?:
We press F3 -> The mouse moves 210 pixels to the right again
We press F1 -> 643,360 :?:

I can show more testcases that show weird behavior but let's stop for now.

Does anyone knows what is going on with this game? Any ideas? A very low level way of moving the mouse? A tool to hook into the coordinate system of a game? Poke/cheat for the x,y values in memory? Anything... :(
John
Posts: 78
Joined: 10 Apr 2014, 08:59

Re: AHK Veteran Puzzled by Mouse in Inquisitor Game

23 Aug 2019, 07:40

Is it possible that the game writes to what AHK's mousegetpos get's it's info from? I.e., for some inexplicable reason, the game overwrites the memory address that holds the cursor location? I think it could be worth trying to get the position with this https://rosettacode.org/wiki/Mouse_position#AutoHotkey will give you different results.
If that doesn't work then you could detect when the mouse is in a position where it's panning and offset the location of received position by however much was panned.
As for the tabbing behavior, perhaps the game 'rehooks' whenever the game get's focus? You could test that by having your script restart with each alt-tab and if it responds as it did prior to tabbing.
Just some ideas :thumbup:
Maxol
Posts: 8
Joined: 25 Apr 2019, 05:36

Re: AHK Veteran Puzzled by Mouse in Inquisitor Game

23 Aug 2019, 08:09

Thanks for the help, appreciate any help! :P
John wrote:
23 Aug 2019, 07:40
As for the tabbing behavior, perhaps the game 'rehooks' whenever the game get's focus? You could test that by having your script restart with each alt-tab and if it responds as it did prior to tabbing.
The game definitely rehooks/resets after focus gain/lost. Doesn't bother me, if anything, it helps me get a fresh starting point for testing this issue... ;)
John wrote:
23 Aug 2019, 07:40
Is it possible that the game writes to what AHK's mousegetpos get's it's info from? I.e., for some inexplicable reason, the game overwrites the memory address that holds the cursor location?
That's what I suspect too, this game is doing something on a very low level, obscuring memory locations
John wrote:
23 Aug 2019, 07:40
I think it could be worth trying to get the position with this https rosettacode.org /wiki/Mouse_position#AutoHotkey Broken Link for safety will give you different results.
I tried them but no.... :thumbdown: I was hopefull when I noticed the GetPhysicalCursorPos function but the result is exactly the same as the basic AHK version and the GetCursorPos() function
John wrote:
23 Aug 2019, 07:40
If that doesn't work then you could detect when the mouse is in a position where it's panning and offset the location of received position by however much was panned.
Thought about that too but the behavior is much more erratic then the testcases I presented. If I move the cursor one pixel with mousemove, the cursor frequently jumps into a corner and it is very, very unpredictable
John
Posts: 78
Joined: 10 Apr 2014, 08:59

Re: AHK Veteran Puzzled by Mouse in Inquisitor Game

27 Aug 2019, 02:49

Given the cursor doesn't go berserk in the game itself then it's keeping track of the position properly within the game's memory so, I'd suggest giving a go at it with Cheat Engine or if VAC goes bananas from it then there's quite a few new CE alternatives that have been released that don't get you instabanned. Still if that works then everything else becomes progressively more trivial.
Maxol
Posts: 8
Joined: 25 Apr 2019, 05:36

Re: AHK Veteran Puzzled by Mouse in Inquisitor Game

27 Aug 2019, 04:44

John wrote:
27 Aug 2019, 02:49
I'd suggest giving a go at it with Cheat Engine or if VAC goes bananas[...]
I don't play online so VAC is not an issue. The Cheat Engine seems the way to go then...<big sigh>...never really used it but I found tutorials, that's a little project that will take some time :D

There is something else I found though, you know about the reposition cursor after Alt-Tabbing out en into the game? Well, I always have these hotkeys running to Minimize, Maximize and Restore the Active Window:

Code: Select all

#Down::WinMinimize, A
#up::    
    WinGet MX, MinMax, A
    If MX
        WinRestore A
    Else 
        WinMaximize A
It turns out that pressing #up in the game centers the cursor! :!: WinMaximize A does that, interesting...
John
Posts: 78
Joined: 10 Apr 2014, 08:59

Re: AHK Veteran Puzzled by Mouse in Inquisitor Game

02 Oct 2019, 07:17

Could be worth a try to look at what get's sent to the window with winspector spy when you send "winminimize, a" since if it does indeed do something sensible in response to it then you could just spam "wm_activateapp" (or some other message) to it to achieve predictable behavior.
Though if you go with CE I'm pretty sure it'll be easy since older games tend to be really really nice about their offsets and after the detective work you just plop everything into AHK and forget about CE.
nitrofenix
Posts: 18
Joined: 20 Sep 2019, 03:26

Re: AHK Veteran Puzzled by Mouse in Inquisitor Game

03 Oct 2019, 04:00

Have you tried setting CoordMode? As far as I understand it, MouseGetPos should return coordinates relative to the active window without setting it, but setting it explicitly might be worth experimenting with.

Something like:

Code: Select all

CoordMode, Mouse, Client
Maxol
Posts: 8
Joined: 25 Apr 2019, 05:36

Re: AHK Veteran Puzzled by Mouse in Inquisitor Game

14 Oct 2019, 11:24

John wrote:
02 Oct 2019, 07:17
Though if you go with CE I'm pretty sure it'll be easy since older games tend to be really really nice about their offsets and after the detective work you just plop everything into AHK and forget about CE.
I went with CE! Never used it before so I tried the Tutorials. Looks like a very powerful program, unfortunately there is a high learning curve :(

BUT there is a some success to report!

I managed to find the memory addresses that hold the x and the y positions of the mouse. So that's a starting point.

Furthermore changing the addresses using CE made the mouse move in the game, double bonus! :dance:

After restarting the game the addresses I found didn't work anymore. That is expected of course, because they're pointers. I'm working on the CE pointer tutorials now....I'll update this topic later to let people that are interested know.

UPDATE 16 OCT 2019 - 00:12

The pointers were found with CE! I found good examples here on the forum to read the memory using classMemory.ahk

Code: Select all

#include %A_ScriptDir%\classMemory.ahk

if (_ClassMemory.__Class != "_ClassMemory")
    msgbox class memory not correctly installed. Or the (global class) variable "_ClassMemory" has been overwritten
 
; *** put the exe name here! ****
mem := new _ClassMemory("ahk_exe Inquisitor.exe", "", hProcessCopy) 
if !isObject(mem)
{
    msgbox failed to open a handle
    if (hProcessCopy = "")
        msgbox OpenProcess failed. If the target process has admin rights, then the script also needs to be ran as admin. Consult A_LastError for more information.
    else if (hProcessCopy = 0)
        msgbox The program isn't running (not found) or you passed an incorrect program identifier parameter. 
    else msgbox opened a handle but something went wrong... ; Should never occur.
    ExitApp
}

; the mem object can now be used to read/write data

debugPrint( "############################")

; In CE's pointer Dialog the values and offsets are (from bottom to top): "Inquisitor.exe"+0045E0DC, 4, 198, 54, 344, 644
; You can see how I translated these in the mem.read statement
baseAddress := mem.getModuleBaseAddress()
result := mem.read(baseAddress + 0x0045E0DC, "UInt", 0x4, 0x198, 0x54, 0x344, 0x644)
debugPrint(  "x: " . result)

baseAddress := mem.getModuleBaseAddress()
result := mem.read(baseAddress + 0x0045E0DC, "UInt", 0x4, 0x198, 0x54, 0x344, 0x648)
debugPrint(  "y: " . result)

; reading only the first level of the pointer
pointer := mem.read(baseAddress + 0x0018C7D8, "UInt")
debugPrint( "pointer: " . pointer )

exitapp
Now I can use this to retreive the coordinates in the game!

Next thing is moving the mouse cursor....
Maxol
Posts: 8
Joined: 25 Apr 2019, 05:36

Re: AHK Veteran Puzzled by Mouse in Inquisitor Game

21 Oct 2019, 05:45

Moving the mouse turned out to be easy: just write to memory using the same pointers.

I love this Cheat Engine, it opened up a lot of possibilities, used it to create an adjustable speedhack for my game:

Code: Select all

space::inqSpeed(0)
^0::inqSpeed(0.5)
^1::inqSpeed(1)
^2::inqSpeed(2)
^3::inqSpeed(3)
^4::inqSpeed(4)
^5::inqSpeed(5)
^6::inqSpeed(6)
^7::inqSpeed(7)
^8::inqSpeed(10)
^9::inqSpeed(50)

; ------------------------------------------------------------------------------
inqSpeed(Speed)
; ------------------------------------------------------------------------------
{
    Global lastSpeed, togglePause
    
    IF !ProcessExist("InquisitorSpeedhack.exe")
        Run C:\GOG Games\Inquisitor\GameData\InquisitorSpeedhack.exe
    
    
    if Speed=0
    {
        ; Pause (Zero) will Toggle between the Last Used Speed and Pause
        if togglePause
            FileAppend, %lastSpeed%, C:\Games\Inquisitor.cmd
        else
            FileAppend, 0, C:\Games\Inquisitor.cmd        

        ; Toggle the Flag        
        togglePause := nextNr(togglePause,1,0,1)
        
    } else {

        ; Set new Speed    
        FileAppend, %Speed%, C:\Games\Inquisitor.cmd
        lastSpeed := Speed
        
        ; Reset Pause Flag (this will Pause Game if the Pause Key is Used Next) 
        togglePause := False
    }
}
John
Posts: 78
Joined: 10 Apr 2014, 08:59

Re: AHK Veteran Puzzled by Mouse in Inquisitor Game

28 Jan 2020, 08:20

Maxol wrote:
14 Oct 2019, 11:24
John wrote:
02 Oct 2019, 07:17
Though if you go with CE I'm pretty sure it'll be easy since older games tend to be really really nice about their offsets and after the detective work you just plop everything into AHK and forget about CE.
I went with CE! Never used it before so I tried the Tutorials. Looks like a very powerful program, unfortunately there is a high learning curve :(

BUT there is a some success to report!

I managed to find the memory addresses that hold the x and the y positions of the mouse. So that's a starting point.

Furthermore changing the addresses using CE made the mouse move in the game, double bonus! :dance:

After restarting the game the addresses I found didn't work anymore. That is expected of course, because they're pointers. I'm working on the CE pointer tutorials now....I'll update this topic later to let people that are interested know.

UPDATE 16 OCT 2019 - 00:12

The pointers were found with CE! I found good examples here on the forum to read the memory using classMemory.ahk

Code: Select all

#include %A_ScriptDir%\classMemory.ahk

if (_ClassMemory.__Class != "_ClassMemory")
    msgbox class memory not correctly installed. Or the (global class) variable "_ClassMemory" has been overwritten
 
; *** put the exe name here! ****
mem := new _ClassMemory("ahk_exe Inquisitor.exe", "", hProcessCopy) 
if !isObject(mem)
{
    msgbox failed to open a handle
    if (hProcessCopy = "")
        msgbox OpenProcess failed. If the target process has admin rights, then the script also needs to be ran as admin. Consult A_LastError for more information.
    else if (hProcessCopy = 0)
        msgbox The program isn't running (not found) or you passed an incorrect program identifier parameter. 
    else msgbox opened a handle but something went wrong... ; Should never occur.
    ExitApp
}

; the mem object can now be used to read/write data

debugPrint( "############################")

; In CE's pointer Dialog the values and offsets are (from bottom to top): "Inquisitor.exe"+0045E0DC, 4, 198, 54, 344, 644
; You can see how I translated these in the mem.read statement
baseAddress := mem.getModuleBaseAddress()
result := mem.read(baseAddress + 0x0045E0DC, "UInt", 0x4, 0x198, 0x54, 0x344, 0x644)
debugPrint(  "x: " . result)

baseAddress := mem.getModuleBaseAddress()
result := mem.read(baseAddress + 0x0045E0DC, "UInt", 0x4, 0x198, 0x54, 0x344, 0x648)
debugPrint(  "y: " . result)

; reading only the first level of the pointer
pointer := mem.read(baseAddress + 0x0018C7D8, "UInt")
debugPrint( "pointer: " . pointer )

exitapp
Now I can use this to retreive the coordinates in the game!

Next thing is moving the mouse cursor....
CE is a gamechanger to interfacing with games and well worth the learning curve especially if you're proficient with AHK.
Even many online games that otherwise go bonkers about AHK scripts will play ball when you're just doing memory shenanigans :)

Return to “Gaming Help (v1)”

Who is online

Users browsing this forum: No registered users and 59 guests