Shaggi Posted August 1, 2011 Share Posted August 1, 2011 (edited) For the terrified game-automation people and triggerhappy mods out there: Don't worry, and read on. I just wrote a small, cool script for people still playing this oldschool game While heroes def. is fun, it can get boring if you play with more than 2 people (long waiting times between rounds). Therefore, I always wanted Heroes III to run windowed, but it wont go into window mode if desktop depth isn't 16 bits. Since im too lazy to change this, i created a small "shellexecuter" which autosets this before and after the game is run. Also, i hate how the scrolling works windowed, so this program also confines the mouse in the window - just alt+tab out if needed. Maybe somebody out there appreciates this expandcollapse popup;###################################################### ;~> <~; ;~> AutoIt Version: 3.3.6.1 <~; ;~> Author: Shaggi <~; ;~> Version: 1.0 <~; ;~> Scriptname: Heroes III.au3 <~; ;~> <~; ;~> Script Function: <~; ;~> Opens Heroes III using the path supplied, <~; ;~> changing the color depth if needed and <~; ;~> keeps the mouse inside the window until it <~; ;~> doesn't exist. <~; ;~> Requirements: <~; ;~> Os: Xp++ <~; ;~> <~; ;~> Credits: <~; ;~> psandu.ro, PartyPooper <~; ;###################################################### ; /***************************************** ; * Directories ; *****************************************/ #AutoIt3Wrapper_usex64=no #include <Misc.au3> ; /***************************************** ; * Settings ; *****************************************/ Global $Title = "Heroes of Might and Magic III", _ $Folder = "C:\Games\Heroes of Might and Magic 3 (shadow of death )\", _ $Exe = "Heroes III.exe", _ $Offsets[4] = [4, 45, -4, -4] ;Might need to adjust these. Format is Left-top-right-bottom ; /***************************************** ; * Consts ; *****************************************/ Global Const $CCHDEVICENAME = 32 Global Const $CCHFORMNAME = 32 Global Const $DM_PELSWIDTH = 0x00080000 Global Const $DM_PELSHEIGHT = 0x00100000 Global Const $DM_BITSPERPEL = 0x00040000 Global Const $DM_DISPLAYFREQUENCY = 0x00400000 Global Const $CDS_TEST = 0x00000002 Global Const $CDS_UPDATEREGISTRY = 0x00000001 Global Const $DISP_CHANGE_RESTART = 1 Global Const $DISP_CHANGE_SUCCESSFUL = 0 Global Const $HWND_BROADCAST = 0xFFFF Global Const $WM_DISPLAYCHANGE = 0x007E Global $tagDEVMODE = "" & _ "CHAR dmDeviceName[" & $CCHDEVICENAME & "];" & _ "WORD dmSpecVersion;" & _ "WORD dmDriverVersion;" & _ "WORD dmSize;" & _ "WORD dmDriverExtra;" & _ "DWORD dmFields;" & _ "LONG dmPositionx;" & _ "LONG dmPositiony;" & _ "DWORD dmDisplayOrientation;" & _ "DWORD dmDisplayFixedOutput;" & _ "short dmColor;" & _ "short dmDuplex;" & _ "short dmYResolution;" & _ "short dmTTOption;" & _ "short dmCollate;" & _ "CHAR dmFormName[" & $CCHFORMNAME & "];" & _ "WORD dmLogPixels;" & _ "DWORD dmBitsPerPel;" & _ "DWORD dmPelsWidth;" & _ "WORD dmPelsHeight;" & _ "DWORD dmDisplayFlags;" & _ "DWORD dmDisplayFrequency;" & _ "DWORD dmICMMethod;" & _ "DWORD dmICMIntent;" & _ "DWORD dmMediaType;" & _ "DWORD dmDitherType;" & _ "DWORD dmReserved1;" & _ "DWORD dmReserved2;" & _ "DWORD dmPanningWidth;" & _ "DWORD dmPanningHeight;" ; /***************************************** ; * Globals ; *****************************************/ Global $Pos1[4], $isTrapEnabled = False, $Pos_old[4] ; /***************************************** ; * Main ; *****************************************/ Main() Func Main() If _ChangeScreenRes(@DesktopWidth,@DesktopHeight,16) AND NOT @ERROR Then Adlibregister("Relock") RunWait($Folder & $Exe,$Folder) AdlibUnregister("Relock") _ChangeScreenRes(@DesktopWidth,@DesktopHeight,32) EndIf EndFunc ; /***************************************** ; * Lock mouse inside window ; *****************************************/ Func Relock() $pos1 = WinGetPos($Title) If WinActive($Title) Then If (($pos_old[0] <> $pos1[0]) OR ($pos_old[1] <> $pos1[1])) Then $pos_old = $pos1 _MouseTrap($pos1[0]+$Offsets[0], $pos1[1]+$Offsets[1], $pos1[0] + $pos1[2]+$Offsets[2], $pos1[1] + $pos1[3]+$Offsets[3]) $isTrapEnabled = True EndIf If NOT $isTrapEnabled Then _MouseTrap($pos1[0]+$Offsets[0], $pos1[1]+$Offsets[1], $pos1[0] + $pos1[2]+$Offsets[2], $pos1[1] + $pos1[3]+$Offsets[3]) $pos_old = $pos1 $isTrapEnabled = True EndIf Else If $isTrapEnabled Then _MouseTrap() $isTrapEnabled = False EndIf Endif EndFunc ;=============================================================================== ; Function Name: _ChangeScreenRes() ; Description: Changes the current screen geometry, colour and refresh rate. ; Version: 1.0.0.2 ; Parameter(s): $i_Width - Width of the desktop screen in pixels. (horizontal resolution) ; $i_Height - Height of the desktop screen in pixels. (vertical resolution) ; $i_BitsPP - Depth of the desktop screen in bits per pixel. ; $i_RefreshRate - Refresh rate of the desktop screen in hertz. ; Requirement(s): AutoIt Beta > 3.1 ; Return Value(s): On Success - Screen is adjusted, @ERROR = 0 ; On Failure - sets @ERROR = 1 ; Forum(s): http://www.autoitscript.com/forum/index.php?showtopic=20121 ; Author(s): Original code - psandu.ro ; Modifications - PartyPooper, Shaggi (should work with Windows 7 and downwards now) ;=============================================================================== Func _ChangeScreenRes($i_Width = @DesktopWidth, $i_Height = @DesktopHeight, $i_BitsPP = @DesktopDepth, $i_RefreshRate = @DesktopRefresh) If $i_Width = "" Or $i_Width = -1 Then $i_Width = @DesktopWidth ; default to current setting If $i_Height = "" Or $i_Height = -1 Then $i_Height = @DesktopHeight ; default to current setting If $i_BitsPP = "" Or $i_BitsPP = -1 Then $i_BitsPP = @DesktopDepth ; default to current setting If $i_RefreshRate = "" Or $i_RefreshRate = -1 Then $i_RefreshRate = @DesktopRefresh ; default to current setting Local $DEVMODE = DllStructCreate($tagDEVMODE) DllStructSetData($Devmode,"dmSize",DllStructGetSize($DEVMODE)) DllStructSetData($Devmode,"dmDriverExtra",0) Local $B = DllCall("user32.dll", "BOOL", "EnumDisplaySettings", "ptr", 0, "dword", 0, "ptr", DllStructGetPtr($DEVMODE)) If @error Then SetError(1) Return False Else $B = $B[0] EndIf If $B <> 0 Then DllStructSetData($DEVMODE, "dmFields", BitOR($DM_PELSWIDTH, $DM_PELSHEIGHT, $DM_BITSPERPEL, $DM_DISPLAYFREQUENCY)) DllStructSetData($DEVMODE, "dmPelsWidth", $i_Width) DllStructSetData($DEVMODE, "dmPelsHeight", $i_Height) DllStructSetData($DEVMODE, "dmBitsPerPel", $i_BitsPP) DllStructSetData($DEVMODE, "dmDisplayFrequency", $i_RefreshRate) $B = DllCall("user32.dll", "long", "ChangeDisplaySettings", "ptr", DllStructGetPtr($DEVMODE), "dword", $CDS_TEST) If @error Then $B = -1 Else $B = $B[0] EndIf Switch $B Case $DISP_CHANGE_RESTART $DEVMODE = 0 Return False Case $DISP_CHANGE_SUCCESSFUL DllCall("user32.dll", "long", "ChangeDisplaySettings", "ptr", DllStructGetPtr($DEVMODE), "dword", $CDS_UPDATEREGISTRY) DllCall("user32.dll", "lresult", "SendMessage", "hwnd", $HWND_BROADCAST, "uint", $WM_DISPLAYCHANGE, _ "WPARAM", $i_BitsPP, "LPARAM", $i_Height * 2 ^ 16 + $i_Width) $DEVMODE = 0 Return True Case Else $DEVMODE = 0 SetError(1) Return False EndSwitch EndIf EndFuncYou might need to adjust some of the stuff under settings. Have fun Ps. you trigger windowed mode on F4 Edited August 1, 2011 by Shaggi Ever wanted to call functions in another process? ProcessCall UDFConsole stuff: Console UDFC Preprocessor for AutoIt OMG Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now