-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathReg_Patch_DS1.bat
251 lines (203 loc) · 7.23 KB
/
Reg_Patch_DS1.bat
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
@echo off
@setlocal enableextensions
title Reg Patcher for Dungeon Siege 1 by Genesis (v1.44)
:linux_check
rem Check if run from Linux
if defined WINEPREFIX goto init
rem Check and validate arguments
if not "%1" == "" (
rem If one argument is specified, it must be "-c"
if "%1" == "-c" (
rem If the first argument is valid, a second argument must be specified
if not "%2" == "" (
rem It must be a digit between 1 and 5 to match the choices below
if "%2" GEQ "1" (
if "%2" LEQ "5" (
set _CHOICE=%2
) else (
goto usage
)
) else (
goto usage
)
) else (
goto usage
)
) else (
goto usage
)
)
:admin_check
rem https://ss64.com/vb/syntax-elevate.html
rem Restart the script as admin if it wasn't the case already
echo Checking if the script is run as admin...
fsutil dirty query %SYSTEMDRIVE% > nul
if %ERRORLEVEL%% == 0 (
echo OK
) else (
echo ERROR: admin rights not detected.
echo.
echo The script will now restart as admin.
echo set UAC = CreateObject^("Shell.Application"^) > "%TEMP%\ElevateMe.vbs"
echo UAC.ShellExecute """%~f0""", "%*", "", "runas", 1 >> "%TEMP%\ElevateMe.vbs"
"%TEMP%\ElevateMe.vbs"
del "%TEMP%\ElevateMe.vbs"
exit /B
)
echo.
:init
rem https://www.codeproject.com/Tips/119828/Running-a-bat-file-as-administrator-Correcting-cur
rem Correct the current directory when a script is run as admin
@cd /d "%~dp0"
rem https://ss64.com/nt/syntax-64bit.html
set _OS_BITNESS=64
set _PROGRAM_FILES=%PROGRAMFILES(X86)%
if %PROCESSOR_ARCHITECTURE% == x86 (
if not defined PROCESSOR_ARCHITEW6432 (
set _OS_BITNESS=32
set _PROGRAM_FILES=%PROGRAMFILES%
)
)
rem Shortcuts for registry stuff
set _MS_DS=HKLM\Software\Microsoft\Microsoft Games\DungeonSiege
set _MS_DS_EXPORT=HKEY_LOCAL_MACHINE\Software\Wow6432Node\Microsoft\Microsoft Games\DungeonSiege\1.0
set _MS_LOA=HKLM\Software\Microsoft\Microsoft Games\Dungeon Siege Legends of Aranna
set _MS_LOA_EXPORT=HKEY_LOCAL_MACHINE\Software\Wow6432Node\Microsoft\Microsoft Games\Dungeon Siege Legends of Aranna\1.0
set _REG_ARG=/reg:32
set _REG_FILE=%~n0.reg
rem WOW6432Node and /reg:32 aren't present on 32-bit systems
if %_OS_BITNESS% == 32 (
set _MS_DS_EXPORT=HKEY_LOCAL_MACHINE\Software\Microsoft\Microsoft Games\DungeonSiege\1.0
set _MS_LOA_EXPORT=HKEY_LOCAL_MACHINE\Software\Microsoft\Microsoft Games\Dungeon Siege Legends of Aranna\1.0
set _REG_ARG=
)
if defined WINEPREFIX (
set _MS_DS_EXPORT=HKEY_LOCAL_MACHINE\Software\Microsoft\Microsoft Games\DungeonSiege\1.0
set _MS_LOA_EXPORT=HKEY_LOCAL_MACHINE\Software\Microsoft\Microsoft Games\Dungeon Siege Legends of Aranna\1.0
set _REG_ARG=
)
:exe_check
rem Check for game executables in the current directory
echo Checking for the game executable...
if exist DungeonSiege.exe (
set _INSTALL_LOCATION=%CD%
echo OK
goto menu
) else if exist DSLOA.exe (
set _INSTALL_LOCATION=%CD%
echo OK
goto menu
) else (
echo DungeonSiege.exe and DSLOA.exe not found in the current directory!
)
:install_detection
rem Check where the game is installed from the registry
echo.
echo Searching for the game installation directory...
for /F "tokens=2* delims= " %%A in (' REG QUERY "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\Steam App 39190" /v InstallLocation 2^>nul') do set _INSTALL_LOCATION=%%B
if "%_INSTALL_LOCATION%" == "" (
echo.
echo No game installation directory found!
goto end
) else (
echo Game installation directory found: %_INSTALL_LOCATION%
rem Check for game executables in the installation directory
echo Checking for the game executable...
if exist "%_INSTALL_LOCATION%\DungeonSiege.exe" (
echo OK
goto menu
) else if exist "%_INSTALL_LOCATION%\DSLOA.exe" (
echo OK
goto menu
) else (
echo DungeonSiege.exe and DSLOA.exe not found in the installation directory!
goto end
)
)
:menu
rem Selection menu
echo.
echo Please make a selection:
echo.
echo 1. Add registry entries for Dungeon Siege 1 (needed for DSMod and the DS1 Tool Kit)
echo 2. Add registry entries for Dungeon Siege 1 Lands of Aranna (needed for DSLOAMod)
echo 3. Create a directory junction in Program Files (useful for GameRanger)
echo 4. Export registry entries to a REG file (useful on Linux)
echo 5. Remove registry entries for both games
echo 6. Exit
echo.
rem Automatically make a selection in case of arguments
if defined _CHOICE (
choice /C:123456 /N /T 0 /D %_CHOICE%
) else (
choice /C:123456 /N
)
if %ERRORLEVEL% == 1 goto DS1
if %ERRORLEVEL% == 2 goto DS1LOA
if %ERRORLEVEL% == 3 goto junction
if %ERRORLEVEL% == 4 goto export
if %ERRORLEVEL% == 5 goto cleanup
if %ERRORLEVEL% == 6 exit /B
:DS1
echo Adding registry entries for Dungeon Siege 1...
REG ADD "%_MS_DS%\1.0" /v "EXE Path" /t REG_SZ /d "%_INSTALL_LOCATION%" /f %_REG_ARG% > nul
echo DONE
goto end
:DS1LOA
echo Adding registry entries for Dungeon Siege 1: Lands of Aranna...
REG ADD "%_MS_LOA%\1.0" /v "EXE Path" /t REG_SZ /d "%_INSTALL_LOCATION%" /f %_REG_ARG% > nul
echo DONE
goto end
:junction
rem https://stackoverflow.com/a/8071683
rem Get the install directory name
for %%a in ("%_INSTALL_LOCATION%") do set _CURRENT_DIRECTORY=%%~nxa
if exist "%_PROGRAM_FILES%\%_CURRENT_DIRECTORY%" rmdir /Q "%_PROGRAM_FILES%\%_CURRENT_DIRECTORY%" > nul
mklink /J "%_PROGRAM_FILES%\%_CURRENT_DIRECTORY%" "%_INSTALL_LOCATION%"
if %ERRORLEVEL% == 0 (
echo.
echo You can now select the game's executable from "%_PROGRAM_FILES%\%_CURRENT_DIRECTORY%" to add the game to GameRanger.
echo.
echo Warning: do NOT move the directory junction somewhere else as it will also move your entire game directory!
echo It can safely be renamed or deleted.
)
echo DONE
goto end
:export
rem https://alt.msdos.batch.narkive.com/LNB84uUc/replace-all-backslashes-in-a-string-with-double-backslash
rem Double backslashes in the install directory path
set _INSTALL_LOCATION_DOUBLE_BACKSLASH=%_INSTALL_LOCATION:\=\\%
echo REGEDIT4> %_REG_FILE%
echo.>> %_REG_FILE%
echo Exporting registry entries for Dungeon Siege 1...
echo [%_MS_DS_EXPORT%]>> %_REG_FILE%
echo "EXE Path"="%_INSTALL_LOCATION_DOUBLE_BACKSLASH%">> %_REG_FILE%
echo.>> %_REG_FILE%
echo DONE
echo.
echo Exporting registry entries for Dungeon Siege 1: Lands of Aranna...
echo [%_MS_LOA_EXPORT%]>> %_REG_FILE%
echo "EXE Path"="%_INSTALL_LOCATION_DOUBLE_BACKSLASH%">> %_REG_FILE%
echo.>> %_REG_FILE%
echo DONE
echo.
echo A new file called "%_REG_FILE%" has been created in the current directory.
goto end
:cleanup
echo Removing registry entries for Dungeon Siege 1...
REG DELETE "%_MS_DS%" /f %_REG_ARG% > nul
echo DONE
echo.
echo Removing registry entries for Dungeon Siege 1: Lands of Aranna...
REG DELETE "%_MS_LOA%" /f %_REG_ARG% > nul
echo DONE
goto end
:usage
echo Usage:
echo.
echo %~0 -c X (where X is a number between 1 and 5)
goto end
:end
echo.
pause
endlocal