Page 1 of 1

Help with gdip imagesearch (black screen)

Posted: 15 Jun 2021, 09:49
by origenal
Recently started looking into gdip imagesearch, and ran into a problem. For some reason, it cannot find images in the GTA5 game.
Here's the code I wrote:

Code: Select all

#Include Gdip_All.ahk
#Include Gdip_ImageSearch.ahk

pToken := Gdip_Startup()
pHaystack := Gdip_BitmapFromHwnd(WinExist("GTA5"))
pNeedle := Gdip_CreateBitmapFromFile("image.png")
result := Gdip_ImageSearch(pHaystack, pNeedle, outputVar)

Gdip_DisposeImage(pHaystack)
Gdip_DisposeImage(pNeedle)
Gdip_Shutdown(pToken)

if (result = 1)
{
    RegExMatch(outputVar, "(.*),(.*)", out)
    MsgBox, X: %out1% Y: %out2%
}
else
{
	MsgBox, EROR
}

ExitApp
It finds coordinates in other applications, but there is a problem with GTA5.
I took a screenshot with the same library and got a completely black screenshot.
The code that took the screenshot:

Code: Select all

#Include Gdip_All.ahk
pToken := Gdip_Startup()

pBitmap := Gdip_BitmapFromHwnd(WinExist("GTA5"))
Gdip_SaveBitmapToFile(pBitmap, A_Desktop "\image.png")
Gdip_DisposeImage(pBitmap)

Gdip_Shutdown(pToken)
ExitApp
Help solve the problem, thank you in advance for your time.

Re: Help with gdip imagesearch (black screen)

Posted: 15 Jun 2021, 17:44
by boiler
Try replacing the Gdip_BitmapFromHWND() function in your Gdip library with this fix:

Code: Select all

Gdip_BitmapFromHWND(hwnd)
{
	WinGetPos,,, Width, Height, ahk_id %hwnd%
	hbm := CreateDIBSection(Width, Height), hdc := CreateCompatibleDC(), obm := SelectObject(hdc, hbm)
	RegExMatch(A_OsVersion, "\d+", Version)
	PrintWindow(hwnd, hdc, Version >= 8 ? 2 : 0)
	pBitmap := Gdip_CreateBitmapFromHBITMAP(hbm)
	SelectObject(hdc, obm), DeleteObject(hbm), DeleteDC(hdc)
	return pBitmap
}

Re: Help with gdip imagesearch (black screen)

Posted: 16 Jun 2021, 12:24
by origenal
boiler wrote:
15 Jun 2021, 17:44
Try replacing the Gdip_BitmapFromHWND() function in your Gdip library with this fix:

Code: Select all

Gdip_BitmapFromHWND(hwnd)
{
	WinGetPos,,, Width, Height, ahk_id %hwnd%
	hbm := CreateDIBSection(Width, Height), hdc := CreateCompatibleDC(), obm := SelectObject(hdc, hbm)
	RegExMatch(A_OsVersion, "\d+", Version)
	PrintWindow(hwnd, hdc, Version >= 8 ? 2 : 0)
	pBitmap := Gdip_CreateBitmapFromHBITMAP(hbm)
	SelectObject(hdc, obm), DeleteObject(hbm), DeleteDC(hdc)
	return pBitmap
}
Unfortunately, it didn't help. I found that part of the code you wrote about in the Gdip_All.ahk file, but the situation has not changed by now. Perhaps there are more ideas.

Re: Help with gdip imagesearch (black screen)

Posted: 16 Jun 2021, 14:04
by swagfag
gta5 is a directX game. these ...fromHWND functions wont work on it. u can either:
  • run the game in windowed/borderless mode and instead take a snapshot of the entire screen with GDIP
  • or inject a dll into the game, hooking the directX draw calls(then u can run it even in fullscreen if u wanted to)

Re: Help with gdip imagesearch (black screen)

Posted: 30 Jan 2022, 16:11
by ibieel
swagfag wrote:
16 Jun 2021, 14:04
gta5 is a directX game. these ...fromHWND functions wont work on it. u can either:
  • run the game in windowed/borderless mode and instead take a snapshot of the entire screen with GDIP
  • or inject a dll into the game, hooking the directX draw calls(then u can run it even in fullscreen if u wanted to)
interesting, so anti-cheats block this? :o

for example, I play an RPG where the "Print Screen" is always a black screen. even playing in window.

the game has an anti-cheat to prevent the game memory from being accessed, so it's impossible to do pixel analysis? do you have any idea what i can do?

Re: Help with gdip imagesearch (black screen)

Posted: 20 Jun 2022, 01:44
by nick79
Hi, I have the same problem with another program (Safe Exam Browser). The program starts in borderless full screen mode and any attempted screenshot produces a completely black image. I have already tried with the various methods (Gdip and CaptureScreen) indicated in the forum. Anyone have alternative ideas?

Re: Help with gdip imagesearch (black screen)

Posted: 20 Jun 2022, 02:07
by BoBo
@nick79
"Once upon a time" ... once you've heard 'black screen' the keyword(s) "graphics adapter overlay setting" popped up... :think:
https://www.nvidia.com/en-us/geforce/forums/geforce-experience/14/301317/nvidia-in-game-overlay-black-screen/ :?: :?: :?:

[BBBF]What about overlaying the overlay with a transparent overlay so a screenshot won't trigger the restricting layer?[/BBBF]
Just in case you didn't know that I have no idea about graphic (adapter) concepts. Now you do.

* BBBF AKA BoBoBrainFart

Re: Help with gdip imagesearch (black screen)

Posted: 20 Jun 2022, 04:13
by gregster
When I read "Safe Exam Browser", I imagine that there is a good reason that it blocks screenshots... and that circumventing it could be considered malicious :problem:

Re: Help with gdip imagesearch (black screen)

Posted: 21 Jun 2022, 08:36
by nick79
BoBo wrote:
20 Jun 2022, 02:07
@nick79
"Once upon a time" ... once you've heard 'black screen' the keyword(s) "graphics adapter overlay setting" popped up... :think:
https://www.nvidia.com/en-us/geforce/forums/geforce-experience/14/301317/nvidia-in-game-overlay-black-screen/ :?: :?: :?:

[BBBF]What about overlaying the overlay with a transparent overlay so a screenshot won't trigger the restricting layer?[/BBBF]
Just in case you didn't know that I have no idea about graphic (adapter) concepts. Now you do.

* BBBF AKA BoBoBrainFart
Is there any script to get this result? I have no idea