It is currently April 24th, 2024, 9:02 am

"Upgraded" RainGame

Share and get help with Plugins and Addons

Do you consider this an improvement?

Yes
5
100%
No
0
No votes
 
Total votes: 5
User avatar
santa_ryan
Posts: 397
Joined: June 22nd, 2010, 4:11 am

"Upgraded" RainGame

Post by santa_ryan »

RainGame.zip
Eh, decided to take JSMorley's "RainGame" addon and improve on it.

Just run the executable and follow the instructions if needed.
This program writes to a config file so the program will need admin rights if you are running from a protected location (E.G. Program Files).

To change the Refresh Rate (how often it checks for games via topmost attribute), just open the raingame.ini configuration file and change the "RefreshRate" value. This value is in milliseconds.

You can also set up a whitelist, a group of programs that are not scanned by this program for "Topmost" status.
Input their process names seperated by a "|" (vertical bar). A default set/example is provided. Please do not remove these or you will get annoyed quickly.(;

Source (Also included in zip):

Code: Select all

#Include <WinAPI.au3>

#region ;Variable Declaration
Const $GWL_EXSTYLE = 0xFFFFFFEC
Const $WS_EX_TOPMOST = 0x00000008
;Constants that we will need to do the topmost check.
;BitAND(_WinAPI_GetWindowLong($Hwnd, $GWL_EXSTYLE), $WS_EX_TOPMOST)

Global $Hwnd
;Create variable to store the active window's handle.
Global $RainmeterExecutable
;Create a variable to store the location of the rainmeter executable and preload it with the executable.
Global $RefreshRate = 10000
;Create a variable that determines the "Refresh Rate" of the program and default this rate to 10000 milliseconds (10 seconds).
Global $ConfigurationFile = "RainGame.ini"
;Create a variable to store the name of the configuration file for easy access and changing later on if needed.
Global $EnableWhitelist
;Create a variable that will determine if the whitelist should be used or not.
Global $Whitelist[2] = ["3","Explorer|TaskMgr.exe|dwm.exe"]
;Create an array which will store the user declared whitelist and prepopulate it with "TaskManager.exe". See "Whitelist" region under the "Functions" region for more info.
#endregion ;Variable Declaration

_Init()
;See "Init" function in the "Functions" region.

#region ;Main Program
While 1
;Repeat the following forever:
	$Hwnd = WinGetHandle("[Active]")
	;Retrieve the current active window's handle
	If Not _WhiteListCompare(_Win2Process($Hwnd), $WhiteList) And BitAND(_WinAPI_GetWindowLong($Hwnd, $GWL_EXSTYLE), $WS_EX_TOPMOST) Then
	;If the current active window for "Fullscreen" status then...
		ProcessClose("Rainmeter.exe")
		;kill the rainmeter process
		Do
		;Do the following...
			Sleep($RefreshRate)
			;pause for the given refresh rate,
			$Hwnd = WinGetHandle("[Active]")
			;retrieve the current active window's handle
		Until Not BitAND(_WinAPI_GetWindowLong($Hwnd, $GWL_EXSTYLE), $WS_EX_TOPMOST)
		;...until the active window is no longer fullscreen.
		ShellExecute($RainmeterExecutable)
		;Once the active window is no longer fullscreen, restart the rainmeter process.
	;Else do nothing.
	EndIf
	Sleep($RefreshRate)
	;Once a single cycle "if" check is finished pause for the given refresh rate.
WEnd
#endregion ;Main Program

#region ;functions

;This function initilizes the script by changing the working directory and creating the config file if it doesn't exist or if it does exist grabbing the user defined variables.
Func _Init() ;Init
	FileChangeDir(@ScriptDir)
	;Make the working directory the path to the script. This ensures that we can always find the configuration file alongside the program.

	If Not FileExists($ConfigurationFile) Then
	;If the config file does not exist then...
		$RainmeterExecutable = _GetRainmeterExecutable()
		Local $CreateConfigFile[3][2] = [["RainmeterExecutable",$RainmeterExecutable],["RefreshRate",$RefreshRate],["Whitelist",_ArrayToString($WhiteList, "|", 1)]]
		;Create an array so we can prepopulated the config file with variables.
		IniWriteSection($ConfigurationFile, "Settings", $CreateConfigFile)
		;Create the config file, and writes a section to it titled "Settings". It then populates that section using the array we created.
	EndIf

	$RainmeterExecutable = IniRead($ConfigurationFile, "Settings", "RainmeterExecutable", "")
	If $RainmeterExecutable = "" Then
		$RainmeterExecutable = _GetRainmeterExecutable()
		IniWrite($ConfigurationFile, "Settings", "RainmeterExecutable", $RainmeterExecutable)
	EndIf
	_NewRefreshRate()
	_WhitelistRetrieve()

EndFunc ;Init

;This function allows a user to supply a new Refresh Rate via configuration file.
Func _NewRefreshRate()

	Local $TempRefreshRate
	;Create a variable that will temporarily store the user declared refresh rate read from the configuration file while the program checks it's usability.
	$TempRefreshRate = Number(iniRead($ConfigurationFile, "Settings", "RefreshRate", $RefreshRate))
	;Read the configuration file, convert the var type from a string to a number, and store it in the temporary refresh rate variable.
	If Not ($TempRefreshRate = "" Or $TempRefreshRate = 0) Then $RefreshRate = $TempRefreshRate
	;If the read refresh rate is not blank or 0 (zero) then permanently store it in the refresh rate variable.
	IniWrite($ConfigurationFile, "Settings", "RefreshRate", $RefreshRate)
	;Write the refresh rate back to the configuration file. This ensures that the value is populated with the default refresh rate if this is the first time the script is run or is populated with the last known user declared refresh rate.

EndFunc ;New Refresh Rate

#region ;Whitelist
;These are functions for retrieving, comparing, and changing the whitelist, a group of programs that are not scanned by this program for "Topmost" status.

;NOTE: THIS PROGRAM IS NOT COMPLETED SO ABILITY TO CHANGE WHITELIST IS NOT PRESENT!

;This function allows a user to retrieve the "whitelist" from the configuration file.
Func _WhitelistRetrieve($Action = "RETRIEVE")

	Local $WhiteListString
	;Create a variable to temporarily store the string read from the ini to determine usability and convert to an array.
	$WhiteListString = IniRead($ConfigurationFile, "Settings", "Whitelist", "")
	;Read the user defined whitelist into a temporary variable.
	If Not $WhitelistString = "" Then $WhiteList = StringSplit($WhiteListString, "|")
	;If the read variable is not blank then split the string and populate the whitelist array.
	IniWrite($ConfigurationFile, "Settings", "Whitelist", _ArrayToString($WhiteList, "|", 1))
	;Write the array back into the configuration file. This ensures that the value is populated with the default white list if this is the first time the script is run or its populated with the last known user declared whitelist.

EndFunc ;Whitelist Retrieve

;This function allows a user to compare the "whitelist" to a process for a boolean check.
Func _WhitelistCompare($aName, ByRef $aWhiteList)
	For $i = 1 To $aWhitelist[0]
		If $aWhiteList[$i] = $aName Then Return True
	Next
	Return False
EndFunc; _WhiteListCompare ;Whitelist Compare

#endregion ;Whitelist

Func _ArrayToString(Const ByRef $avArray, $sDelim = "|", $iStart = 0, $iEnd = 0)
	If Not IsArray($avArray) Then Return SetError(1, 0, "")
	If UBound($avArray, 0) <> 1 Then Return SetError(3, 0, "")
	Local $sResult, $iUBound = UBound($avArray) - 1
	; Bounds checking
	If $iEnd < 1 Or $iEnd > $iUBound Then $iEnd = $iUBound
	If $iStart < 0 Then $iStart = 0
	If $iStart > $iEnd Then Return SetError(2, 0, "")
	; Combine
	For $i = $iStart To $iEnd
		$sResult &= $avArray[$i] & $sDelim
	Next
	Return StringTrimRight($sResult, StringLen($sDelim))
EndFunc   ;==>_ArrayToString

func _Win2Process($wintitle)
    $wproc = WinGetProcess($wintitle)
	$wproc = processexists($wproc)
    $proc = ProcessList()
    for $p = 1 to $proc[0][0]
        if $proc[$p][1] = $wproc then return $proc[$p][0]
	Next
	Return -1
endfunc

Func _WinAPI_ProcessGetFilename($vProcessID,$bFullPath=False)
    ; Not a Process ID? Must be a Process Name
    If Not IsNumber($vProcessID) Then
        $vProcessID=ProcessExists($vProcessID)
        ; Process Name not found (or invalid parameter?)
        If Not $vProcessID Then Return SetError(1,0,"")
    EndIf

    Local $sDLLFunctionName,$tErr

    ; Since the parameters and returns are the same for both of these DLL calls, we can keep it all in one function
    If $bFullPath Then
        $sDLLFunctionName="GetModuleFileNameExW"
    Else
        $sDLLFunctionName="GetModuleBaseNameW"
    EndIf

    ; Get process handle
    Local $hProcess = DllCall('kernel32.dll','ptr', 'OpenProcess','int', BitOR(0x400,0x10),'int', 0,'int', $vProcessID)
    If @error Then Return SetError(2,0,"")
    If Not $hProcess[0] Then Return SetError(3,0,"")

    ; Create 'receiving' string buffers and make the call
    ; Path length size maximum in Unicode is 32767 (-1 for NULL)
    Local $stFilename=DllStructCreate("wchar[32767]")
    ; Make the call (same parameters for both)
    Local $aRet=DllCall("Psapi.dll","dword",$sDLLFunctionName,"ptr",$hProcess[0],"ptr",0,"ptr",DllStructGetPtr($stFilename),"dword",32767)

    If @error Then
        $tErr=2
    ElseIf Not $aRet[0] Then
        $tErr=4
    Else
        $tErr=0
    EndIf
    ; Close process handle
    DllCall('kernel32.dll','int', 'CloseHandle','ptr', $hProcess[0])
    ; Error above?
    If $tErr Then Return SetError($tErr,0,"")

    ;$stFilename should now contain either the filename or full path string (based on $bFullPath)
    Local $sFilename=DllStructGetData($stFilename,1)

    ; DLLStructDelete()'s
    $stFilename=0
    $hProcess=0

    SetError(0)
    Return $sFilename
EndFunc

Func _GetRainmeterExecutable()
	If Not ProcessExists("Rainmeter.exe") Then
		SplashTextOn("", "Please start Rainmeter now" & @LF & "for program to configure properly!", 334, 64, Default, Default, 35, Default, 16)
		Do
			Sleep(1000)
		Until ProcessExists("Rainmeter.exe")
		SplashOff()
	EndIf
	Return _WinAPI_ProcessGetFilename(ProcessExists("Rainmeter.exe"), True)
EndFunc

#endregion ;Functions
RainGame.zip
You do not have the required permissions to view the files attached to this post.
I have three rules when I'm trying to help you.
  • Don't get mad when you don't understand something
  • Be VERY specific with what you ask for.
    The more specific you are, the higher the quality of support you receive.
  • Do not just copy and paste what I put in examples and come back saying it doesn't work.
    It does work, but I purposely left blanks that you need to fill for your specific needs.