DX9-Overlay-API: Inject overlays into fullscreen games!

Post your working scripts, libraries and tools for AHK v1.1 and older
User avatar
evilC
Posts: 4823
Joined: 27 Feb 2014, 12:30

DX9-Overlay-API: Inject overlays into fullscreen games!

30 Jun 2014, 12:35

Finally someone has released an API to allow AHK scripts to inject text / graphics into fullscreen games.

See here: http://overlay-api.net/

The author has expressed a wish to not be a one-man-band, so if you know C++ / DirectX coding and are willing to help, then please let him know!
tmplinshi
Posts: 1604
Joined: 01 Oct 2013, 14:57

Re: DX9-Overlay-API: Inject overlays into fullscreen games!

01 Jul 2014, 01:46

Interesting! Anyone can give an AutoHotkey example? It's already in the samples dir :lol:
User avatar
jNizM
Posts: 3183
Joined: 30 Sep 2013, 01:33
Contact:

Re: DX9-Overlay-API: Inject overlays into fullscreen games!

01 Jul 2014, 02:12

hmm.. I get everytime MsgBox, 48, Error, The dll-file couldn't be found!
[AHK] v2.0.5 | [WIN] 11 Pro (Version 22H2) | [GitHub] Profile
guest3456
Posts: 3463
Joined: 09 Oct 2013, 10:31

Re: DX9-Overlay-API: Inject overlays into fullscreen games!

01 Jul 2014, 09:26

did you download the .dll ?

so strange to see ahk examples provided ha

User avatar
evilC
Posts: 4823
Joined: 27 Feb 2014, 12:30

Re: DX9-Overlay-API: Inject overlays into fullscreen games!

01 Jul 2014, 10:26

Works fine for me.
Be aware that the way it searches for libs and such is maybe a bit clunky - there are some include statements that point to relative paths and such.
I just forked the GitHub repo and starting working on the sample files where they were.

And yeah, after years of searching and waiting for such a project, one pops up and includes AHK libs - wonderful!
guest3456
Posts: 3463
Joined: 09 Oct 2013, 10:31

Re: DX9-Overlay-API: Inject overlays into fullscreen games!

01 Jul 2014, 11:33

I mean as long as the .dll and the api is available, you could easily write an AHK wrapper yourself. You don't need him to include the lib. I thought thats what was gonna be needed.

User avatar
evilC
Posts: 4823
Joined: 27 Feb 2014, 12:30

Re: DX9-Overlay-API: Inject overlays into fullscreen games!

01 Jul 2014, 11:52

Oh, you mean you were thinking of contributing but thought what they needed was a lib written to call the DLLs?

What they need in coding terms is people to help improve the DLL.

Areas that need improving at the moment:
No DX11 support.
Bitmaps from files only, should be able to use from memory.
Overlay area restricted to 800x600, which is then stretched to fill the screen.
When games load levels etc, you can see some funky stuff on the screen.

The big one IMHO is the DX11 support. Without that, then this project is possibly doomed in the long-term.
I certainly cannot really consider integrating this code into all my projects until DX11 support is added.
User avatar
xZomBie
Posts: 256
Joined: 02 Oct 2013, 02:57

Re: DX9-Overlay-API: Inject overlays into fullscreen games!

18 Jul 2014, 10:38

jNizM wrote:hmm.. I get everytime MsgBox, 48, Error, The dll-file couldn't be found!
I'm getting the same result as jNizM.
I've just downloaded: Tried to run framerate.ahk but getting the same MsgBox as jNizM.
guest3456
Posts: 3463
Joined: 09 Oct 2013, 10:31

Re: DX9-Overlay-API: Inject overlays into fullscreen games!

18 Jul 2014, 11:06

its not hard to debug. the code for loading the dll is directly at the top.

User avatar
xZomBie
Posts: 256
Joined: 02 Oct 2013, 02:57

Re: DX9-Overlay-API: Inject overlays into fullscreen games!

18 Jul 2014, 11:34

I put all the files I needed in the same directory and I know that I need to change something in overlay.ahk but don't know where... please help!
guest3456
Posts: 3463
Joined: 09 Oct 2013, 10:31

Re: DX9-Overlay-API: Inject overlays into fullscreen games!

18 Jul 2014, 11:47

i just told you where: right at the top. why don't you debug and see what the PATH_OVERLAY variable is reporting

User avatar
xZomBie
Posts: 256
Joined: 02 Oct 2013, 02:57

Re: DX9-Overlay-API: Inject overlays into fullscreen games!

26 Jul 2014, 07:49

guest3456 wrote:i just told you where: right at the top. why don't you debug and see what the PATH_OVERLAY variable is reporting
I tried everything but still can't get it to work. I know it's reporting the dir of where the dx9_overlay.dll should be and placed the dll file there but keep getting The dll-file couldn't be found!.
@guest3456 If you know how to get it to work then why don't you help me out...
User avatar
LinearSpoon
Posts: 156
Joined: 29 Sep 2013, 22:55

Re: DX9-Overlay-API: Inject overlays into fullscreen games!

27 Jul 2014, 00:29

The error message is sort of misleading here. Any number of things could be going wrong, that have nothing to do with the script being unable to find the dll. Here are some potential issues:
1. The dll is 32 bit. It will not work with 64 bit AHK, unless someone recompiles a 64 bit dll for it.
2. The wrapper assumes ANSI AHK. You need to sprinkle AStr around a few dllcalls to make it Unicode compatible.
3. You might need to run the script as administrator.
4. You might have another program hooking DX. In my case, I had a program running in the background that shows FPS on a hotkey that prevented my script from working, even while inactive.

Here is a hastily modified version of overlay.ahk (Read: It could be improved further). It should be Unicode compatible, and eliminates all of the global variables.

Code: Select all

;Take note, you need to set PATH_OVERLAY to your dx9_overlay.dll in GetProcAddress function (below the comment wall)
#NoEnv 

;If we allow a configurable PATH_OVERLAY, Autohotkey will not be able to preload our functions before runtime.
;For performance, the original author finds the function addresses of everything at the start of the script
;To match this behavior without globals means ideally all of the function addresses will be made static
;But static expressions are evaluated before runtime/autoexec section, so the business of loading dx9_overlay.dll
;must be done in a function, including resolving PATH_OVERLAY, to ensure it is ready for GetProcAddress.
;An alternative is to declare each function address static, and check if it needs to be looked up at runtime, but this adds
;an if-then branch to every function call...
;A final option is to just let AHK look up function addresses, while we preload dx_overlay.dll. (LoadLibrary being the long call
;we'd like to avoid having AHK do, since it will pair it with FreeLibrary after each DllCall)

;I chose the first option as it took minimal code changes, and keeps similar performance compared to the original.
;Which leads to this somewhat awkward situation, where you need to set PATH_OVERLAY in the body of this function...
GetProcAddress(fn)
{
	static PATH_OVERLAY := RelToAbs(A_ScriptDir, "..\..\bin\dx9_overlay.dll")
	static hModule 
	if (!hModule)
	{
		hModule := DllCall("LoadLibrary", Str, PATH_OVERLAY)
		if(hModule == -1 || hModule == 0)
		{
			MsgBox, 48, Error, The dll-file couldn't be found!
			ExitApp
		}
	}
	return DllCall("GetProcAddress", UInt, hModule, AStr, fn)	
}

Init()
{ ;What are the chances of this being called more than once?
	static Init_func := GetProcAddress("Init")
	res := DllCall(Init_func)
	return res
}

SetParam(str_Name, str_Value)
{
	static SetParam_func := GetProcAddress("SetParam")
	res := DllCall(SetParam_func, AStr, str_Name, AStr, str_Value)
	;return res  SetParam returns void
}

;Cool note: Seems you can change the text color inline with {RRGGBB}
;Ex: "This is {FF0000}red"
TextCreate(Font, fontsize, bold, italic, x, y, color, text, shadow, show)
{
	static TextCreate_func := GetProcAddress("TextCreate")
	res := DllCall(TextCreate_func,AStr,Font,Int,fontsize,UChar,bold,UChar,italic,Int,x,Int,y,UInt,color,AStr,text,UChar,shadow,UChar,show)
	return res
}

TextDestroy(id)
{
	static TextDestroy_func := GetProcAddress("TextDestroy")
	res := DllCall(TextDestroy_func,Int,id)
	return res
}

TextSetShadow(id, shadow)
{
	static TextSetShadow_func := GetProcAddress("TextSetShadow")
	res := DllCall(TextSetShadow_func,Int,id,UChar,shadow)
	return res
}

TextSetShown(id, show)
{
	static TextSetShown_func := GetProcAddress("TextSetShown")
	res := DllCall(TextSetShown_func,Int,id,UChar,show)
	return res
}

TextSetColor(id,color)
{
	static TextSetColor_func := GetProcAddress("TextSetColor")
	res := DllCall(TextSetColor_func,Int,id,UInt,color)
	return res
}

TextSetPos(id,x,y)
{
	static TextSetPos_func := GetProcAddress("TextSetPos")
	res := DllCall(TextSetPos_func,Int,id,Int,x,Int,y)
	return res
}

TextSetString(id,Text)
{
	static TextSetString_func := GetProcAddress("TextSetString")
	res := DllCall(TextSetString_func,Int,id,AStr,Text)
	return res
}

TextUpdate(id,Font,Fontsize,bold,italic)
{
	static TextUpdate_func := GetProcAddress("TextUpdate")
	res := DllCall(TextUpdate_func,Int,id,AStr,Font,int,Fontsize,UChar,bold,UChar,italic)
	return res
}	

BoxCreate(x,y,width,height,Color,show)
{
	static BoxCreate_func := GetProcAddress("BoxCreate")
	res := DllCall(BoxCreate_func,Int,x,Int,y,Int,width,Int,height,UInt,Color,UChar,show)
	return res
}

BoxDestroy(id)
{
	static BoxDestroy_func := GetProcAddress("BoxDestroy")
	res := DllCall(BoxDestroy_func,Int,id)
	return res
}

BoxSetShown(id,Show)
{
	static BoxSetShown_func := GetProcAddress("BoxSetShown")
	res := DllCall(BoxSetShown_func,Int,id,UChar,Show)
	return res
}

BoxSetBorder(id,height,Show)
{
	static BoxSetBorder_func := GetProcAddress("BoxSetBorder")
	res := DllCall(BoxSetBorder_func,Int,id,Int,height,Int,Show)
	return res
}


BoxSetBorderColor(id,Color)
{
	static BoxSetBorderColor_func := GetProcAddress("BoxSetBorderColor")
	res := DllCall(BoxSetBorderColor_func,Int,id,UInt,Color)
	return res
}

BoxSetColor(id,Color)
{
	static BoxSetColor_func := GetProcAddress("BoxSetColor")
	res := DllCall(BoxSetColor_func,Int,id,UInt,Color)
	return res
}

BoxSetHeight(id,height)
{
	static BoxSetHeight_func := GetProcAddress("BoxSetHeight")
	res := DllCall(BoxSetHeight_func,Int,id,Int,height)
	return res
}

BoxSetPos(id,x,y)
{
	static BoxSetPos_func	:= GetProcAddress("BoxSetPos")
	res := DllCall(BoxSetPos_func,Int,id,Int,x,Int,y)
	return res
}

BoxSetWidth(id,width)
{
	static BoxSetWidth_func := GetProcAddress("BoxSetWidth")
	res := DllCall(BoxSetWidth_func,Int,id,Int,width)
	return res
}

LineCreate(x1,y1,x2,y2,width,color,show)
{
	static LineCreate_func := GetProcAddress("LineCreate")
	res := DllCall(LineCreate_func,Int,x1,Int,y1,Int,x2,Int,y2,Int,Width,UInt,color,UChar,show)
	return res
}

LineDestroy(id)
{
	static LineDestroy_func := GetProcAddress("LineDestroy")
	res := DllCall(LineDestroy_func,Int,id)
	return res
}

LineSetShown(id,show)
{
	static LineSetShown_func := GetProcAddress("LineSetShown")
	res := DllCall(LineSetShown_func,Int,id,UChar,show)
	return res
}

LineSetColor(id,color)
{
	static LineSetColor_func := GetProcAddress("LineSetColor")
	res := DllCall(LineSetColor_func,Int,id,UInt,color)
	return res
}

LineSetWidth(id, width)
{
	static LineSetWidth_func := GetProcAddress("LineSetWidth")
	res := DllCall(LineSetWidth_func,Int,id,Int,width)
	return res
}

LineSetPos(id,x1,y1,x2,y2)
{
	static LineSetPos_func := GetProcAddress("LineSetPos")
	res := DllCall(LineSetPos_func,Int,id,Int,x1,Int,y1,Int,x2,Int,y2)
	return res
}

ImageCreate(path, x, y, rotation, align, show)
{
	static ImageCreate_func := GetProcAddress("ImageCreate")
	res := DllCall(ImageCreate_func, AStr, path, Int, x, Int, y, Int, rotation, Int, align, UChar, show)
	return res
}

ImageDestroy(id)
{
	static ImageDestroy_func := GetProcAddress("ImageDestroy")
	res := DllCall(ImageDestroy_func,Int,id)
	return res
}

ImageSetShown(id,show)
{
	static ImageSetShown_func := GetProcAddress("ImageSetShown")
	res := DllCall(ImageSetShown_func,Int,id,UChar,show)
	return res
}

ImageSetAlign(id,align)
{
	static ImageSetAlign_func := GetProcAddress("ImageSetAlign")
	res := DllCall(ImageSetAlign_func,Int,id,Int,align)
	return res
}

ImageSetPos(id, x, y)
{
	static ImageSetPos_func := GetProcAddress("ImageSetPos")
	res := DllCall(ImageSetPos_func,Int,id,Int,x, Int, y)
	return res
}

ImageSetRotation(id, rotation)
{
	static ImageSetRotation_func := GetProcAddress("ImageSetRotation")
	res := DllCall(ImageSetRotation_func,Int,id,Int, rotation)
	return res
}

DestroyAllVisual()
{
	static DestroyAllVisual_func := GetProcAddress("DestroyAllVisual")
	res := DllCall(DestroyAllVisual_func)
	return res 
}

ShowAllVisual()
{
	static ShowAllVisual_func := GetProcAddress("ShowAllVisual")
	res := DllCall(ShowAllVisual_func)
	return res
}

HideAllVisual()
{
	static HideAllVisual_func := GetProcAddress("HideAllVisual")
	res := DllCall(HideAllVisual_func )
	return res
}

GetFrameRate()
{
	static GetFrameRate_func := GetProcAddress("GetFrameRate")
	res := DllCall(GetFrameRate_func )
	return res
}

GetScreenSpecs(ByRef width, ByRef height)
{ ;If he can get the screen size, why limit coordinates to 800x600?
	static GetScreenSpecs_func := GetProcAddress("GetScreenSpecs")
	res := DllCall(GetScreenSpecs_func, IntP, width, IntP, height)
	return res
}

RelToAbs(root, dir, s = "\") {
	pr := SubStr(root, 1, len := InStr(root, s, "", InStr(root, s . s) + 2) - 1)
		, root := SubStr(root, len + 1), sk := 0
	If InStr(root, s, "", 0) = StrLen(root)
		StringTrimRight, root, root, 1
	If InStr(dir, s, "", 0) = StrLen(dir)
		StringTrimRight, dir, dir, 1
	Loop, Parse, dir, %s%
	{
		If A_LoopField = ..
			StringLeft, root, root, InStr(root, s, "", 0) - 1
		Else If A_LoopField =
			root =
		Else If A_LoopField != .
			Continue
		StringReplace, dir, dir, %A_LoopField%%s%
	}
	Return, pr . root . s . dir
}
User avatar
Masonjar13
Posts: 1555
Joined: 20 Jul 2014, 10:16
Location: Не Россия
Contact:

Re: DX9-Overlay-API: Inject overlays into fullscreen games!

05 Jan 2016, 18:30

Apologies for the revival. I'm trying to use this with BGamer's LAN mod for CoD: Blops. It uses DX9, specifically, D3DX9_43.dll. None of the samples work for me, either with ANSI or Uni (32-bit). There aren't any errors, it simply doesn't display anything. I'm using LinearSpoon's revision of overlay.ahk, and here is one slightly modified sample script.

Code: Select all

#SingleInstance, force
#NoEnv
#include ..\..\include\ahk\overlay.ahk

text_overlay:=-1

SetParam("process","BGamerT5.exe")
return


~1::
if(text_overlay != -1)
	return

text_overlay := TextCreate("Arial", 25, false, false, 300, 300, 0xFFFFFFFF, "Hello world", true, true)
return

~2::
if(text_overlay == -1)
	return

TextDestroy(text_overlay)
text_overlay := -1
return
The mod is a complete wrapper, therefore there is only one process running (except for the launcher, which stays running in the background).
OS: Windows 10 Pro | Editor: Notepad++
My Personal Function Library | Old Build - New Build
User avatar
joedf
Posts: 8977
Joined: 29 Sep 2013, 17:08
Location: Canada
Contact:

Re: DX9-Overlay-API: Inject overlays into fullscreen games!

09 Jul 2017, 14:27

readme wrote:Supported DirectX versions

DirectX 9.0
DirectX 9.0 Extended
DirectX 10
DirectX 11
:+1:
Image Image Image Image Image
Windows 10 x64 Professional, Intel i5-8500, NVIDIA GTX 1060 6GB, 2x16GB Kingston FURY Beast - DDR4 3200 MHz | [About Me] | [About the AHK Foundation] | [Courses on AutoHotkey]
[ASPDM - StdLib Distribution] | [Qonsole - Quake-like console emulator] | [LibCon - Autohotkey Console Library]

Return to “Scripts and Functions (v1)”

Who is online

Users browsing this forum: No registered users and 79 guests