agrippa1994 / DX9-Overlay-API

Overlay API for DirectX 9 based games.
MIT License
127 stars 26 forks source link

Suggested improvement to sample AHK code #9

Closed evilC closed 10 years ago

evilC commented 10 years ago

The current hello world.ahk leaves the overlays in place if you quit the script.

Suggest changing the script a little, like this:

#SingleInstance, force
#NoEnv

OnExit, GuiClose

#include overlay.ahk

; http://www.unknowncheats.me/forum/general-programming-and-reversing/105528-gfxtest-lightweight-graphics-testing-application.html
; Thanks to evolution536 and learn_more for this test application :)
SetParam("process", "GFXTest.exe")
;SetParam("process", "MWOClient.exe")

TextCreate("Arial", 25, false, false, 100, 100, 0xFFFFFFFF, "Hello {ffff00}World", true, true)
BoxCreate(200, 200, 200, 200, 0x10FFFFFF, true)
return

~1::
GuiClose:
DestroyAllVisual()
ExitApp
return

These changes will make the script remove all injections when it exits / is restarted.

evilC commented 10 years ago

Actually, here is a further improvement - this code will allow the script to be run BEFORE the DX application is run. It will also re-add the overlays if the DX app is killed and restarted.

#SingleInstance, force
#NoEnv

OnExit, GuiClose

#include overlay.ahk

PROC_NAME := "GFXTest.exe"

; http://www.unknowncheats.me/forum/general-programming-and-reversing/105528-gfxtest-lightweight-graphics-testing-application.html
; Thanks to evolution536 and learn_more for this test application :)
SetParam("process", PROC_NAME)

WatchProcess(PROC_NAME)

return

~1::
GuiClose:
DestroyOverlays()
ExitApp
return

WatchProcess(name){
    static proc_running := 0

    Loop {
        ifwinexist, ahk_exe %name%
        {
            if (!proc_running){
                proc_running := 1
                CreateOverlays()
            }
        } else {
            if (proc_running){
                proc_running := 0
            }
        }
        Sleep 100
    }
}

CreateOverlays(){
    TextCreate("Arial", 25, false, false, 100, 100, 0xFFFFFFFF, "Hello {ffff00}World", true, true)
    BoxCreate(200, 200, 200, 200, 0x10FFFFFF, true)
}

DestroyOverlays(){
    DestroyAllVisual()
}
evilC commented 10 years ago

And this one further improves the example by adding a key (2) to toggle the text on and off.

#SingleInstance, force
#NoEnv

OnExit, GuiClose

#include overlay.ahk

PROC_NAME := "GFXTest.exe"

overlay_ids := {}
text_visible := 1

; http://www.unknowncheats.me/forum/general-programming-and-reversing/105528-gfxtest-lightweight-graphics-testing-application.html
; Thanks to evolution536 and learn_more for this test application :)
SetParam("process", PROC_NAME)
;SetParam("process", "MWOClient.exe")

WatchProcess(PROC_NAME)

return

~1::
GuiClose:
    DestroyOverlays()
    ExitApp
    return

~2::
    text_visible := 1 - text_visible
    TextSetShown(overlay_ids.text,text_visible)
    return

WatchProcess(name){
    global overlay_ids
    static proc_running := 0

    Loop {
        ifwinexist, ahk_exe %name%
        {
            if (!proc_running){
                proc_running := 1
                overlay_ids := CreateOverlays()
            }
        } else {
            if (proc_running){
                proc_running := 0
                overlay_ids := {}
            }
        }
        Sleep 100
    }
}

CreateOverlays(){
    ret := {}
    ret.text := TextCreate("Arial", 25, false, false, 100, 100, 0xFFFFFFFF, "Hello {ffff00}World", true, true)
    ret.box := BoxCreate(200, 200, 200, 200, 0x10FFFFFF, true)
    return ret
}

DestroyOverlays(){
    DestroyAllVisual()
}
JohnnyCrazy commented 10 years ago

Please create a Pull-Request and I will look over it! :)

evilC commented 10 years ago

Done