a great performance hit when using Gdip_BitmapFromHWND(hwnd)

Ask gaming related questions (AHK v1.1 and older)
takayo97
Posts: 63
Joined: 09 Jun 2018, 16:30

a great performance hit when using Gdip_BitmapFromHWND(hwnd)

01 Oct 2019, 05:55

I'm playing Diablo 3.
I wrote a script keep checking the skill cooldown status and auto cast when out of cooldown
I used Gdip_BitmapFromHWND(hwnd), Gdip_CreateBitmapFromFile(imagefile)
Gdip_ImageSearch() to accomplish this purpose.

However I found a really big side effect, the game framerate will drop from 60 to 4X and even 2X sometimes


I dont use imagesearch because a 3rd party tool used for diablo 3 is banned direct screen capture
User avatar
Xtra
Posts: 2750
Joined: 02 Oct 2015, 12:15

Re: a great performance hit when using Gdip_BitmapFromHWND(hwnd)

01 Oct 2019, 12:20

123.PNG
123.PNG (10.21 KiB) Viewed 2573 times
Dont over think it just do a simple pixelgetcolor on one pixel. (see in image)
When on CD it will not be the castable color.

Have Fun
takayo97
Posts: 63
Joined: 09 Jun 2018, 16:30

Re: a great performance hit when using Gdip_BitmapFromHWND(hwnd)

01 Oct 2019, 16:45

the performance hit is coming from gdip_bitmapfromhwnd
For my testing, even not execute the gdip_imagesearch, fps still drop
Even in pixelcolor search, it still required to get whole game screen bitmap using gdip lib
takayo97
Posts: 63
Joined: 09 Jun 2018, 16:30

Re: a great performance hit when using Gdip_BitmapFromHWND(hwnd)

01 Oct 2019, 16:50

with using gdip_bitmapfromhwnd, i cannot capture selected area instead of a whole screen
User avatar
Xtra
Posts: 2750
Joined: 02 Oct 2015, 12:15

Re: a great performance hit when using Gdip_BitmapFromHWND(hwnd)

01 Oct 2019, 17:01

Hint: DONT use GDIP i shown an easy solution that is beyond fast enough for D3.

GL
takayo97
Posts: 63
Joined: 09 Jun 2018, 16:30

Re: a great performance hit when using Gdip_BitmapFromHWND(hwnd)

01 Oct 2019, 17:50

what is GL ? pls provide more infomation
ssjkakaroto
Posts: 5
Joined: 09 Mar 2019, 07:56

Re: a great performance hit when using Gdip_BitmapFromHWND(hwnd)

03 Nov 2019, 11:19

@Xtra for some reason I get a huge performance hit using pixelsearch/pixelgetcolor with D3. On the other hand, using Gdi+ doesn't affect the game's performance at all.
User avatar
Xtra
Posts: 2750
Joined: 02 Oct 2015, 12:15

Re: a great performance hit when using Gdip_BitmapFromHWND(hwnd)

03 Nov 2019, 14:53

ssjkakaroto wrote:
03 Nov 2019, 11:19
@Xtra for some reason I get a huge performance hit using pixelsearch/pixelgetcolor with D3. On the other hand, using Gdi+ doesn't affect the game's performance at all.
It could be with how you are using it. If you are running a loop with no sleep just about anything will cause a game to lag.
Its been awhile but i remember no issues with using settimer running 50ms intervals (20x a second)
Without more context with how you setup your script its just a guess at best.

If you got GDI+ to work well for you why not share with the OP what you did?
ssjkakaroto
Posts: 5
Joined: 09 Mar 2019, 07:56

Re: a great performance hit when using Gdip_BitmapFromHWND(hwnd)

03 Nov 2019, 19:47

I tried it with many sleep values, only at 1000 I could get it back to ~50 fps. I don't know why pixelsearch was so slow here.

My GDI+ script was actually suggested by OP on another forum, he just didn't update it here. With it the game runs steadily at 60 fps (vsync on).

I used an alternative Gdip_BitmapFromHWND and the result I used with Gdip_ImageSearch:

Code: Select all

Gdip_BitmapFromHWNDCropped(hwnd, Screen) {
	Raster := ""
	Ptr := A_PtrSize ? "UPtr" : "UInt"
	hhdc := GetDCEx(hwnd, 3)
	S := StrSplit(Screen, "|")
	_x := S[1], _y := S[2], _w := S[3], _h := S[4]


	chdc := CreateCompatibleDC(), hbm := CreateDIBSection(_w, _h, chdc)
	obm := SelectObject(chdc, hbm), hhdc := hhdc ? hhdc : GetDC()
	BitBlt(chdc, 0, 0, _w, _h, hhdc, _x, _y, Raster)
	ReleaseDC(hhdc)

	pBitmap := Gdip_CreateBitmapFromHBITMAP(hbm)
	SelectObject(chdc, obm), DeleteObject(hbm), DeleteDC(hhdc), DeleteDC(chdc)
	return pBitmap
}

Code: Select all

bmpHaystack := Gdip_BitmapFromHWNDCropped(d3hwnd, _x "|" _y "|" _w "|" _h)
sready := Gdip_ImageSearch(bmpHaystack,vengeanceNeedle,LIST,0,0,0,0,0,0xFFFFFF,1,0)
if (sready == 1) {
	Send %Key3%
}
sready := Gdip_ImageSearch(bmpHaystack,companionNeedle,LIST,0,0,0,0,0,0xFFFFFF,1,0)
if (sready == 1) {
	Send %Key4%
}
Gdip_DisposeImage(bmpHaystack)

Return to “Gaming Help (v1)”

Who is online

Users browsing this forum: No registered users and 66 guests