kennyhml / pyinterception

Modern Python port & wrapper for the interception device driver
MIT License
124 stars 26 forks source link

interception.dll #2

Closed dvdco closed 1 year ago

dvdco commented 1 year ago

where should i place the interceptiondll?

kennyhml commented 1 year ago

Hey @dvdco,

it doesnt really matter too much, I personally have it in C:\Program Files\Interception, thats where I usually put this stuff.

Note that you have to add it to your PATH environment variable after installing it, you can use python to do it automatically like this:

import winreg
import os

dir_path = "C:\Program Files\Interception\command line installer"

key = winreg.OpenKey(
    winreg.HKEY_CURRENT_USER, "Environment", 0, winreg.KEY_ALL_ACCESS
)

# Get the current value of the PATH variable
path = winreg.QueryValueEx(key, "PATH")[0]

# Add the directory to the path if it's not already there
if dir_path not in path:
    new_path = f"{path};{dir_path}"
    winreg.SetValueEx(key, "PATH", 0, winreg.REG_EXPAND_SZ, new_path)
    os.environ["PATH"] = new_path

winreg.CloseKey(key)
kennyhml commented 1 year ago

If interest in this project continues to grow I may add an interception install feature in the future.

dvdco commented 1 year ago

Why do i have to set the install-interception in to path not the interception.dll? And btw, i have a problem using the move_relative function. I'm designing a aimbot for an fps, it works well on using the win32api to move mouse relatively. But when using your lib, move_relative(1,0) will throw the crosshair over half of the screen.

Ps: it also occored when using the pydirectinput.move_rel(1,0), but actually using the pydirectinput.move_rel(1,0, relative=True) will do the trick. Though the four methods of moving mouse all works well outside the game in windows.

kennyhml commented 1 year ago

Why do i have to set the install-interception in to path not the interception.dll?

Honestly I couldnt tell you lol, thats the install instructions to follow and I know thats been working fine for me.

And btw, i have a problem using the move_relative function. I'm designing a aimbot for an fps

Theres nothing magical about the move_relative function, if you pass move_relative(1, 0) your cursor will be moved one pixel to the right on the x-axis, how this is interpreted depends on the game.

dvdco commented 1 year ago

But when i use win32api or pydirectinput(relative=true) to move one pixel right, it just works fine. Even interception's click will move the fov A LOT, can you help me to fix that?

kennyhml commented 1 year ago

So lets have a look at pydirectinputs moveRel (I removed some useless parameters)

def moveRel(xOffset=None, yOffset=None, duration=None):
    if not relative:
        x, y = position()
        if xOffset is None:
            xOffset = 0
        if yOffset is None:
            yOffset = 0
        moveTo(x + xOffset, y + yOffset)
    else:
        # When using MOUSEEVENTF_MOVE for relative movement the results may be inconsistent.
        # "Relative mouse motion is subject to the effects of the mouse speed and the two-mouse threshold values. A user
        # sets these three values with the Pointer Speed slider of the Control Panel's Mouse Properties sheet. You can 
        # obtain and set these values using the SystemParametersInfo function." 
        # https://docs.microsoft.com/en-us/windows/win32/api/winuser/ns-winuser-mouseinput
        # https://stackoverflow.com/questions/50601200/pyhon-directinput-mouse-relative-moving-act-not-as-expected
        extra = ctypes.c_ulong(0)
        ii_ = Input_I()
        ii_.mi = MouseInput(xOffset, yOffset, 0, MOUSEEVENTF_MOVE, 0, ctypes.pointer(extra))
        command = Input(ctypes.c_ulong(0), ii_)
        SendInput(1, ctypes.pointer(command), ctypes.sizeof(command))

So right away we can see if you pass relative=True it uses an entirely different method of moving the mouse, as opposted to the same method pyinterception uses. Im not surprised youre seeing this for win32api and pydirectinput as, well, pydirectinput just calls the same win api functionality win32api does. I dont think I have these options with the interception driver, you can double check some of the MouseFlag options here to see whether you can get the intended result

dvdco commented 1 year ago

there is a similar function in it class MouseFlag(IntEnum): MOUSE_MOVE_RELATIVE = 0x000F but i 've already tried to modify your move_relative function by changing it to send this flag but the mouse didn't move.

dvdco commented 1 year ago

I still can't undetstand why using the current method in pyinterception would work well in win but seems to be broken in the game i tested. And plus, when i changed the sensetivity in gamto 0.01, when using move_relative the crosshair seems to be going left and up, maybe while imgame, the driver accidently moved the cursor to 0,0? Though i'm sure for now that the problem is not caused by getting the wrong cursur position, i've tested that

dvdco commented 1 year ago

Btw, there is also a github project using interception in the same game it is now working well(kind of), at least moving the cursor. https://github.com/Jire/Overwatcheat

dvdco commented 1 year ago

Btw, there is also a github project using interception in the same game it is now working well(kind of), at least moving the cursor. https://github.com/Jire/Overwatcheat

But i don't know how to read or use kt so u kinda can't really find where the mouse moving function is ;(

kennyhml commented 1 year ago
object InterceptionMouseFlag {

    const val INTERCEPTION_MOUSE_MOVE_RELATIVE = 0x000
    const val INTERCEPTION_MOUSE_MOVE_ABSOLUTE = 0x001
    const val INTERCEPTION_MOUSE_VIRTUAL_DESKTOP = 0x002
    const val INTERCEPTION_MOUSE_ATTRIBUTES_CHANGED = 0x004
    const val INTERCEPTION_MOUSE_MOVE_NOCOALESCE = 0x008
    const val INTERCEPTION_MOUSE_TERMSRV_SRC_SHADOW = 0x100
    const val INTERCEPTION_MOUSE_CUSTOM = 0x200
class MouseFlag(IntEnum):
    MOUSE_MOVE_RELATIVE = 0x000F
    MOUSE_MOVE_ABSOLUTE = 0x001
    MOUSE_VIRTUAL_DESKTOP = 0x002
    MOUSE_ATTRIBUTES_CHANGED = 0x004
    MOUSE_MOVE_NOCOALESCE = 0x008
    MOUSE_TERMSRV_SRC_SHADOW = 0x100

Based on this, it looks like my MOUSE_MOVE_RELATIVE flag may be wrong? Though thats weird because 0x000 is 0 which is essentially the absence of a flag in interception 🤔

dvdco commented 1 year ago

cool maybe you can use the MOUSE_MOVE_RELATIVE to rewrite the move_relative function and push it in 😉

kennyhml commented 1 year ago

In the linked projects mouse manager:

val mouseStroke =
        MemorySegment.allocateNative(interceptionMouseStrokeLayout, MemorySession.global()).apply {
            ...
            set(ValueLayout.JAVA_INT, 8, 0) // x
            set(ValueLayout.JAVA_INT, 12, 0) // y
            set(
                ValueLayout.JAVA_SHORT, 14,
                (InterceptionMouseFlag.INTERCEPTION_MOUSE_MOVE_RELATIVE or
                        InterceptionMouseFlag.INTERCEPTION_MOUSE_CUSTOM).toShort()
            ) // information
        }

Im not familiar with kotlin, but assuming or has the same functionality here as it does in python,

(InterceptionMouseFlag.INTERCEPTION_MOUSE_MOVE_RELATIVE or InterceptionMouseFlag.INTERCEPTION_MOUSE_CUSTOM)

would evaluate to InterceptionMouseFlag.INTERCEPTION_MOUSE_CUSTOM as the former is equivalent to 0 and thus continues to the MOUSE_CUSTOM.

dvdco commented 1 year ago

So how can i modefy the move_relative function in pyoiterception? So that it can directly relatively move the mouse?

kennyhml commented 1 year ago

Well its not really that simple and likely mainly comes down to the game.

@requires_driver
def move_to(x: int | tuple[int, int], y: Optional[int] = None) -> None:
    """Moves to a given position."""
    x, y = _utils.normalize(x, y)
    x, y = _utils.to_interception_coordinate(x, y)

    stroke = MouseStroke(0, MouseFlag.MOUSE_MOVE_ABSOLUTE, 0, x, y, 0)
    interception.send(mouse, stroke)

You could try to alter the MouseFlag here and see if you can get the desired results.

Note that I dont have that INTERCEPTION_MOUSE_CUSTOM so if yo uwant to try it you can add it yourself in the _consts.py file

dvdco commented 1 year ago

Thank you so much for your patient help and understanding my rusty english. I will test it out as soon as i get access to my pc again.

kennyhml commented 1 year ago

Np, let me know if you find anything interesting.

kennyhml commented 1 year ago

Closing as complete for now as this isnt really an issue with the package. If you discover the functionality that makes move_relative work as expected for you though, feel free to open a pull request with the changes.

dvdco commented 1 year ago

Ohhh made it. now it successfully move the mouse relatively in game @requires_driver `@requires_driver def move_relative(x: int | tuple[int, int], y: Optional[int] = None) -> None: """Moves to a given position.""" x, y = _utils.normalize(x, y)

x, y = _utils.to_interception_coordinate(x, y)

stroke = MouseStroke(0, MouseFlag.MOUSE_MOVE_RELATIVE, 0, x, y, 0)
interception.send(mouse, stroke)`

MOUSE_MOVE_RELATIVE is MOUSE_MOVE_RELATIVE = 0x000 I will send a pull request as soon as i learn how to do that.