Zoom-In Script (Sniper)

Ask gaming related questions
SkyBreather
Posts: 10
Joined: 25 May 2016, 13:37

Zoom-In Script (Sniper)

25 Oct 2016, 07:01

Hello, if you read the title, and have come to help, I hope you could be of some assistance to me. I'm in dire need of some help. I'm looking for a script that Zooms In, into the middle of the screen only, Toggleable with "XButton1" Key, and I can change the Zoom Value by using Mouse Wheel. Along with the main reason of me posting in this Section, for it to work for games in Full-Screen, and Windowed. Thank you for taking the time to read this, and I hope you can help me out on this :) (By the Way, I almost have no Experience with Autohotkey, I tried, but it got Overwhelming and I got Over-Exterted).
John
Posts: 75
Joined: 10 Apr 2014, 08:59

Re: Zoom-In Script (Sniper)

26 Oct 2016, 02:50

There isn't very many ways to go about doing this and regardless of which you'll pick you'll have somewhat subpar results. For an fps game and sniping, most if not all options you could muster up with AHK wouldn't be sufficient.
Sure it's possible and sure you could get close to equal fps, but it would take more work than i'd be willing to do.

If you're motivated enough, your best bet would be by using tic's gdi+ and from there mainly relying on lockbits and bitblt or stretchblitting onto the game window or another alwaysontop gui. I can give you advice, but the work and 'research' would still be something for you to do.

Alternatively I'd suggest searching from google. Someone at some time has more likely than not written something like this using c++, mpgh and other such sites are a haven for gaming related scripts.

Actually I'm fairly sure there is pretty fast 'magnifying glass' apps for elderly that could work the way you want.
Create a script that toggles it's window's parameters (forced on top etc) via ahk whenever you press xbutton1 and you'd have your mlg hacks.
SkyBreather
Posts: 10
Joined: 25 May 2016, 13:37

Re: Zoom-In Script (Sniper)

27 Oct 2016, 02:24

John wrote:There isn't very many ways to go about doing this and regardless of which you'll pick you'll have somewhat subpar results. For an fps game and sniping, most if not all options you could muster up with AHK wouldn't be sufficient.
Sure it's possible and sure you could get close to equal fps, but it would take more work than i'd be willing to do.

If you're motivated enough, your best bet would be by using tic's gdi+ and from there mainly relying on lockbits and bitblt or stretchblitting onto the game window or another alwaysontop gui. I can give you advice, but the work and 'research' would still be something for you to do.

Alternatively I'd suggest searching from google. Someone at some time has more likely than not written something like this using c++, mpgh and other such sites are a haven for gaming related scripts.

Actually I'm fairly sure there is pretty fast 'magnifying glass' apps for elderly that could work the way you want.
Create a script that toggles it's window's parameters (forced on top etc) via ahk whenever you press xbutton1 and you'd have your mlg hacks.
I just tried Windows Magnifier Tool, it's pretty good, except for the fact that it doesn't stay at a fixed Postion. Any Zoom Tools you could recommend to me that does this, and works for games? I tried looking for One for a total of 3-5 Hours, but no Luck. Please help me, and thank you for your Time
SkyBreather
Posts: 10
Joined: 25 May 2016, 13:37

Re: Zoom-In Script (Sniper)

27 Oct 2016, 02:56

John wrote:Create a script that toggles it's window's parameters (forced on top etc) via ahk whenever you press xbutton1 and you'd have your mlg hacks.
I have Literally No Clue how to do This, Could you lend me a Hand please?
SkyBreather
Posts: 10
Joined: 25 May 2016, 13:37

Re: Zoom-In Script (Sniper)

02 Nov 2016, 22:42

SkyBreather wrote:
John wrote:Create a script that toggles it's window's parameters (forced on top etc) via ahk whenever you press xbutton1 and you'd have your mlg hacks.
I have Literally No Clue how to do This, Could you lend me a Hand please?
Bump, Could Anyone help me out with this?
John
Posts: 75
Joined: 10 Apr 2014, 08:59

Re: Zoom-In Script (Sniper)

03 Nov 2016, 02:38

To change different settings for other windows, use "WinSet" https://autohotkey.com/docs/commands/WinSet.htm
E.g. always on top would be

Code: Select all

winset, alwaysOnTop, on, ahk_class Screen Magnifier Window
To toggle when it shows and doesn't you could do something like this

Code: Select all

space::
if (t:=!t)
	winhide, ahk_class Screen Magnifier Window
else
	winshow, ahk_class Screen Magnifier Window	
return
You'd also have to change your game to windowed borderless so even if something comes to foreground, it won't minimize the game.
Helgef
Posts: 3898
Joined: 17 Jul 2016, 01:02
Contact:

Re: Zoom-In Script (Sniper)

03 Nov 2016, 11:03

John wrote:There isn't very many ways to go about doing this and regardless of which you'll pick you'll have somewhat subpar results. For an fps game and sniping, most if not all options you could muster up with AHK wouldn't be sufficient.
In contrast, I think this could be quite easily made using DWM.
Helgef
Posts: 3898
Joined: 17 Jul 2016, 01:02
Contact:

Re: Zoom-In Script (Sniper)

03 Nov 2016, 16:51

SkyBreather wrote:Hello,
Hi, you are welcome to try this. It is quite preliminary and lacks some features. I made it as a plugin for UCR (tested on v0.1.3). It is quite straight forward to use. Download UCR, extract, no install needed, save this code as zoom.ahk in the UCR\Plugins\user\ folder. Then go Plugin Selection -> zoom -> Add. Select a hotkey, type in the name of the games executable, eg, game.exe, and try it out. Note, probably only works in window mode, also, only for Windows Vista or later, no XP.
I know of several issues that needs to be fixed, and you are welcome to report any problems.
Good Luck.

Code: Select all

class Zoom extends _UCR.Classes.Plugin
{
	; Author: Helgef
	; Date: 2016-11-03
	; Preliminary version.
	
	; Plugin variables
	type:="Zoom"
	description:="Zooms in the center of a window"
	
	; Instance variables
	toggleState:=0							; Initially, the plugin is off.
	
	; 
	init()
	{
		; Gui
		; Rows for gui placement
		row1:=" y5 ",  		row1_:=" y2 "
		row2:=" y35 ",  		row2_:=" y32 "
		row3:=" y65 ", 	 	row3_:=" y62 "
		row4:=" y95 ", 		row4_:=" y93 "
		row5:=" y125 ", 	row5_:=" y123 "
		row6:=" y155 ", 	row6_:=" y153 "
		
		; Columns for gui placement
		col1:=" x15 ", col2:=" x200 ", col3:=" x335 ", col4:=" x455 "	
		
		Gui, Add, Text, % row1 col1 , % "Hotkey to zoom:"
		this.AddControl("InputButton","HotkeyToggle", 0, this.toggle.Bind(this), row1_ col2  " w125 h25")
		this.AddControl("Checkbox","toggleMode", 0, row1 col3 " Checked", "Toggle mode (uncheck to zoom out on release)")
		
		Gui, Add, Text, % row2 col1 , % "Zoom level (1 = max,100 = no zoom) :"
		this.AddControl("Edit","ZoomLevel", this.zoomChanged.Bind(this), row2_ col2  " w125 h25 center number", 50)
		
		Gui, Add, Text, % row2 col3 , % "Game name (exe)"
		this.AddControl("Edit","exe", this.exeChanged.Bind(this), row2_ col4  " w125 h25")
		
		this.dId:="" ; Destination id.
	}
	
	onClose()
	{
		this.exeChanged() ; Close zoom window and unregister thumbnail, if exist.
		base.onClose() ;?
	}
	
	; Gui functions
	
	zoomChanged()
	{
		this.scale(this.dW,this.dH,sX1,sY1,sX2,sY2) ; sX/Y\1/2 are ByRef.
		this.sX1:=sX1, this.sY1:=sY1, this.sX2:=sX2, this.sY2:=sY2
		this.Dwm_updateRegistredThumbnailProperties(this.tId, 0, 0, this.dW, this.dH, 1,, this.sX1, this.sY1, this.sX2, this.sY2)
		return
	}
	
	exeChanged()
	{
		; Indicates that a new zoom window must be made.
		; User changed exe edit field.
		this.exeChanged:=1
		DHW_Setting:=A_DetectHiddenWindows
		DetectHiddenWindows, On
		IfWinExist, % "ahk_id " this.dId
		{
			this.Dwm_unregisterThumbnail(this.tId)
			Gui, % this.dId ": Destroy"
		}
		this.dId:=""
		DetectHiddenWindows, % DHW_Setting
		return
	}
	
	; Main toggle
	toggle(state)
	{
		if (state=0 && this.GuiControls.toggleMode.Get()) ; Toggle mode, do not close zoomwin on release
			return
		if (state && this.toggleState && !this.GuiControls.toggleMode.Get()) ; Hold mode, close zoomwin on release
			return
		exe:=this.GuiControls.exe.Get()
		exe:= RegExMatch(exe,".exe$")?exe:exe ".exe" ; Append .exe if needed
		if 1 ; Always do this, for now (this.exeChanged || !this.dId)
		{
			this.exeChanged:=0
			if !this.newZoomWin(exe)
				return ; Fail
		}
		this.toggleState:=!this.toggleState
		if this.toggleState
		{
			Gui, % this.dId ": Show", % "NoActivate"
			this.Dwm_showRegistredThumbnail(this.tId)
		}
		else
		{
			WinHide, % "ahk_id " this.dId
		}
		return
	}
	
	; Set up zoom window
	newZoomWin(exe)
	{
		; return 0 on fail, 1 on success.
		IfWinNotExist ahk_exe %exe%
			return 0 ; fail.
		; Exe exists, collect data.
		this.sId:=WinExist("ahk_exe " exe)
		this.GetClientRect(this.sId,dW,dH)					; dW,dH are byref
		this.ClientToScreen(this.sId, 0, 0, dX1, dY1)		; dX1,dY1 are byref
		;WinGetPos,dX1,dY1,dW,dH, % "ahk_id " this.sId
		
		; Destroy the old zoom window if exist.
		IfWinExist, % "ahk_id " this.dId
		{
			this.Dwm_unregisterThumbnail(this.tId)
			Gui, % this.dId ": Destroy"
		}
		; Create a new zoom window.
		Gui, new
		Gui, +hwnddId +ToolWindow -Caption +AlwaysOnTop
		Gui, Show, % "hide x" dX1 " y" dY1 " w" dW " h" dH, % "Zoom window for " exe "."
		this.dId:=dId
		this.Dwm_SetWindowAttributeTransistionDisable(this.dId)		; Possibly not needed. Does not hurt.
		this.tId:=this.Dwm_registerThumbnail(this.dId,this.sId) 	; Register thumbnail relationship, tId holds the thumbnailId.
		if !this.tId
		{
			Gui, % this.dId ": Destroy"
			this.dId:=""
			return 0 ; fail.
		}
		this.scale(dW,dH,sX1,sY1,sX2,sY2) ; sX/Y\1/2 are ByRef.
		this.dW:=dW, this.dH:=dH
		this.sX1:=sX1, this.sY1:=sY1, this.sX2:=sX2, this.sY2:=sY2
		; Make DWM_THUMBNAIL_PROPERTIES struct.
		VarSetCapacity(DWM_THUMBNAIL_PROPERTIES, 46, 0)
		this.DWM_THUMBNAIL_PROPERTIES:=&DWM_THUMBNAIL_PROPERTIES+4
		this.Dwm_updateRegistredThumbnailProperties(this.tId, 0, 0, this.dW, this.dH, 1,, this.sX1, this.sY1, this.sX2, this.sY2)
		return 1
	}
	
	; Helper func for newZoomWin()
	scale(dW,dH,ByRef sX1, ByRef sY1, ByRef sX2, ByRef sY2)
	{
		; Scale source coords to zoom level.
		zl:=this.GuiControls.zoomLevel.Get() / 100
		sW:=Round(dW*zl), sH:=Round(dH*zl)
		sX1:=Round((dW-sW)/2), sY1:=Round((dH-sH)/2)
		sX2:=sX1+sW, sY2:=sY1+sH
		return
	}
	
	; Helper funcs.
	
	; Coord funcs.
	GetClientRect(hwnd,ByRef X2, ByRef Y2)
	{
		VarSetCapacity(rc,16)
		DllCall("GetClientRect", "Uint", hwnd, "Uint", &rc)
		X2:=NumGet(rc,8,"Int")
		Y2:=NumGet(rc,12,"Int")
		return
	}
	
	ClientToScreen(hwnd, cX, cY, ByRef sX, ByRef sY)
	{
		;	;
		;
		;	The ClientToScreen function converts the client-area coordinates of a specified point to screen coordinates.
		;	URL: https://msdn.microsoft.com/en-us/library/windows/desktop/dd183434(v=vs.85).aspx
		;
		;	Input:
		;			hwnd, a handle to the window whose client area is used for the conversion.
		;			cX,cY, client coordinates to be converted to screen coords.
		;	ByRef:
		;			sX,sY, screen coordinates to be returned.
		;	Output:
		;			If the function succeeds, the return value is nonzero.
		;			If the function fails, the return value is zero.
		;
		
		; Create point struct.
		; Url:	https://msdn.microsoft.com/en-us/library/windows/desktop/dd162805%28v=vs.85%29.aspx?f=255&MSPPError=-2147217396
		VarSetCapacity(pt,8,0)
		NumPut(cX,pt,0,"Int")
		NumPut(cY,pt,4,"Int")
		result:=DllCall("User32.dll\ClientToScreen", "Uint", hwnd, "Uint", &pt)
		sX:=NumGet(pt,0,"Int")
		sY:=NumGet(pt,4,"Int")
		return result 			; 0 if failed.
	}
	
	; DWM funcs
	
	Dwm_registerThumbnail(dHWND, sHWND, promptFailure:=1)
	{
		; Input:
		;		dHWND, hwnd id for destination window.
		;		sHWND, hwnd id for source window.
		;		promptFailure, 1 to prompt user upon failure, 0 don't.
		; Output:
		;		hThumbmailId, id for the thumbnail relationship between dHWND and sHWND.
		;		hThumbmailId=0 indicates failure.
		;		The hThumbmailIds are numbered in the order of registration, starting at 1,...
		; Notes:
		;		The window designated by hwndDestination must either be the desktop window itself or be owned by the process that is calling DwmRegisterThumbnail.
		;		This is required to prevent applications from affecting the content of other applications.
		;		The thumbnail registration handle obtained by this function is not globally unique but is unique to the process.
		;		Call the DwmUnregisterThumbnail function to unregister the thumbnail. This must be done within the process that the relationship was registered in.
		; Url:
		;		https://msdn.microsoft.com/en-us/library/windows/desktop/aa969521(v=vs.85).aspx - DwmRegisterThumbnail function
		;
		;
		if (DllCall("Dwmapi.dll\DwmRegisterThumbnail", "Uint", dHWND, "Uint", sHWND, "Uint*", hThumbnailId) && promptFailure)
			MsgBox, 8208, Error, Failed to register thumbnail relationship., 5 ; 5 Second time out
		return hThumbnailId ; 0 is failure.
	}

	Dwm_unregisterThumbnail(hThumbnailId)
	{
		; Removes a Desktop Window Manager (DWM) thumbnail relationship created by the DwmRegisterThumbnail function.
		; Input:
		;			The handle to the thumbnail relationship to be removed. Null or non-existent handles will result in a return value of E_INVALIDARG
		; Output:
		;			hresult, error msg. 0 is ok!
		; Notes:
		;			Call this function when hThumbnail is not needed anymore,
		;			for clean up.
		; Url:
		;			https://msdn.microsoft.com/en-us/library/windows/desktop/aa969525(v=vs.85).aspx - DwmUnregisterThumbnail function
		hr:=DllCall("Dwmapi.dll\DwmUnregisterThumbnail", "Uint", hThumbnailId)
		return hr ; 0 is ok!
	}
	
	Dwm_updateRegistredThumbnailProperties(hThumbnailId,dX1:="", dY1:="", dX2:="", dY2:="", SourceClientAreaOnly:="", Opacity:="", sX1:="", sY1:="", sX2:="", sY2:="")
	{
		; Input:
		;			d(X1/2/ Y1/2) destination rectangle
		;			sourceClientAreaOnly, 1 yes, 0 no.
		;			Opacity, 0-255
		;			s(X1/2 Y1/2) source rectangle
		;
		; Output:
		;			hresult, error msg. 0 is ok!	
		; Notes:
		;
		;			https://msdn.microsoft.com/en-us/library/windows/desktop/aa969502(v=vs.85).aspx
		;			https://msdn.microsoft.com/en-us/library/windows/desktop/aa969535(v=vs.85).aspx
		;
		options:=0
		if !(dX1="" || dY1="" || dX2="" || dY2="")										; Destination rectangle specified.
		{
			options+=1
			NumPut(dX1, this.DWM_THUMBNAIL_PROPERTIES, 4, "Int") 
			NumPut(dY1, this.DWM_THUMBNAIL_PROPERTIES, 8, "Int") 
			NumPut(dX2, this.DWM_THUMBNAIL_PROPERTIES, 12, "Int") 
			NumPut(dY2, this.DWM_THUMBNAIL_PROPERTIES, 16, "Int") 
		}
		if !(sX1="" || sY1="" || sX2="" || sY2="")										; Source rectangle specified.
		{
			options+=2
			NumPut(sX1, this.DWM_THUMBNAIL_PROPERTIES, 20, "Int") 
			NumPut(sY1, this.DWM_THUMBNAIL_PROPERTIES, 24, "Int") 
			NumPut(sX2, this.DWM_THUMBNAIL_PROPERTIES, 28, "Int") 
			NumPut(sY2, this.DWM_THUMBNAIL_PROPERTIES, 32, "Int") 
		}
		
		if opacity
		{
			options+=4
			NumPut(Opacity, this.DWM_THUMBNAIL_PROPERTIES, 36, "UChar")
		}
		if SourceClientAreaOnly
		{
			options+=16
			NumPut(SourceClientAreaOnly, this.DWM_THUMBNAIL_PROPERTIES, 41, "Int") 
		}
		NumPut(options, this.DWM_THUMBNAIL_PROPERTIES, 0, "UInt")
		hr:=DllCall("Dwmapi.dll\DwmUpdateThumbnailProperties", "Uint", hThumbnailId, "Uint", this.DWM_THUMBNAIL_PROPERTIES)
		return hr
	}
	
	Dwm_showRegistredThumbnail(hThumbnailId)
	{
		; Input:
		;			DWM_THUMBNAIL_PROPERTIES struct, see notes, from createThumbnailProperites()
		;			hThumbnailId, pointer to a registred thumbnail id.
		; Output:
		;			hresult, error msg. 0 is ok!
		; Notes:
		;
		;			https://msdn.microsoft.com/en-us/library/windows/desktop/aa969502(v=vs.85).aspx 
		;			https://msdn.microsoft.com/en-us/library/windows/desktop/aa969535(v=vs.85).aspx 
		;
		NumPut(NumGet(this.DWM_THUMBNAIL_PROPERTIES,0,"Uint")|8, this.DWM_THUMBNAIL_PROPERTIES, 0, "UInt") 					; Update Options
		NumPut(1, this.DWM_THUMBNAIL_PROPERTIES, 37, "Int") 																; Show
		hr:=DllCall("Dwmapi.dll\DwmUpdateThumbnailProperties", "Uint", hThumbnailId, "Uint", this.DWM_THUMBNAIL_PROPERTIES)
		return hr
	}

	Dwm_SetWindowAttributeTransistionDisable(hwnd,bool:=1)
	{
		;
		;	DWMWA_TRANSITIONS_FORCEDISABLED=3
		;	Use with DwmSetWindowAttribute. Enables or forcibly disables DWM transitions.
		;	The pvAttribute parameter points to a value of TRUE to disable transitions or FALSE to enable transitions.
		;
		dwAttribute:=3
		cbAttribute:=4
		VarSetCapacity(pvAttribute,4,0)
		NumPut(bool,pvAttribute,0,"Int")
		hr:=DllCall("Dwmapi.dll\DwmSetWindowAttribute", "Uint", hwnd, "Uint", dwAttribute, "Uint", &pvAttribute, "Uint", cbAttribute)
		return hr
	}
}
John
Posts: 75
Joined: 10 Apr 2014, 08:59

Re: Zoom-In Script (Sniper)

04 Nov 2016, 13:44

Helgef wrote:
John wrote:There isn't very many ways to go about doing this and regardless of which you'll pick you'll have somewhat subpar results. For an fps game and sniping, most if not all options you could muster up with AHK wouldn't be sufficient.
In contrast, I think this could be quite easily made using DWM.
Subjective, since it was pointed towards what he can do and the next part was a disclaimer on how much i'd be willing to work on something that didn't pique my interest.
Your script looks great tho, impressive stuff :)
Helgef
Posts: 3898
Joined: 17 Jul 2016, 01:02
Contact:

Re: Zoom-In Script (Sniper)

13 Nov 2016, 06:51

Thanks John, yes, of course it is subjective. :)
@SkyBreather, I have improved this script, and made a new topic for it, go here if you are interested.

Return to “Gaming”

Who is online

Users browsing this forum: No registered users and 36 guests