Help with gdip imagesearch (black screen)

Ask gaming related questions (AHK v1.1 and older)
origenal
Posts: 4
Joined: 14 Jun 2021, 10:45

Help with gdip imagesearch (black screen)

15 Jun 2021, 09:49

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.
User avatar
boiler
Posts: 16912
Joined: 21 Dec 2014, 02:44

Re: Help with gdip imagesearch (black screen)

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
}
origenal
Posts: 4
Joined: 14 Jun 2021, 10:45

Re: Help with gdip imagesearch (black screen)

16 Jun 2021, 12:24

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.
swagfag
Posts: 6222
Joined: 11 Jan 2017, 17:59

Re: Help with gdip imagesearch (black screen)

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)
User avatar
ibieel
Posts: 216
Joined: 17 Oct 2021, 23:30

Re: Help with gdip imagesearch (black screen)

30 Jan 2022, 16:11

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?
nick79
Posts: 2
Joined: 20 Jun 2022, 01:30

Re: Help with gdip imagesearch (black screen)

20 Jun 2022, 01:44

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?
BoBo
Posts: 6564
Joined: 13 May 2014, 17:15

Re: Help with gdip imagesearch (black screen)

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
gregster
Posts: 8999
Joined: 30 Sep 2013, 06:48

Re: Help with gdip imagesearch (black screen)

20 Jun 2022, 04:13

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:
nick79
Posts: 2
Joined: 20 Jun 2022, 01:30

Re: Help with gdip imagesearch (black screen)

21 Jun 2022, 08:36

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
Last edited by gregster on 21 Jun 2022, 09:21, edited 1 time in total.
Reason: Topic locked, for now.

Return to “Gaming Help (v1)”

Who is online

Users browsing this forum: Shoobis and 57 guests