-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathReg_Patch_DS2.bat
260 lines (211 loc) · 8.19 KB
/
Reg_Patch_DS2.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
252
253
254
255
256
257
258
259
260
@echo off
@setlocal enableextensions
title Reg Patcher for Dungeon Siege 2 by Genesis (v1.45)
:linux_check
rem Check if run from Linux
if defined WINEPREFIX goto init
rem Check and validating 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 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 _2K_BW=HKLM\Software\2K Games\Dungeon Siege 2 Broken World
set _2K_BW_EXPORT=HKEY_LOCAL_MACHINE\Software\Wow6432Node\2K Games\Dungeon Siege 2 Broken World
set _GPG_BW=HKLM\Software\Gas Powered Games\Dungeon Siege 2 Broken World
set _GPG_BW_EXPORT=HKEY_LOCAL_MACHINE\Software\Wow6432Node\Gas Powered Games\Dungeon Siege 2 Broken World\1.00.0000
set _MS_DS2=HKLM\Software\Microsoft\Microsoft Games\DungeonSiege2
set _MS_DS2_EXPORT=HKEY_LOCAL_MACHINE\Software\Wow6432Node\Microsoft\Microsoft Games\DungeonSiege2
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 _2K_BW_EXPORT=HKEY_LOCAL_MACHINE\Software\2K Games\Dungeon Siege 2 Broken World
set _GPG_BW_EXPORT=HKEY_LOCAL_MACHINE\Software\Gas Powered Games\Dungeon Siege 2 Broken World\1.00.0000
set _MS_DS2_EXPORT=HKEY_LOCAL_MACHINE\Software\Microsoft\Microsoft Games\DungeonSiege2
set _REG_ARG=
)
if defined WINEPREFIX (
set _2K_BW_EXPORT=HKEY_LOCAL_MACHINE\Software\2K Games\Dungeon Siege 2 Broken World
set _GPG_BW_EXPORT=HKEY_LOCAL_MACHINE\Software\Gas Powered Games\Dungeon Siege 2 Broken World\1.00.0000
set _MS_DS2_EXPORT=HKEY_LOCAL_MACHINE\Software\Microsoft\Microsoft Games\DungeonSiege2
set _REG_ARG=
)
:exe_check
rem Check for the game executable in the current directory
echo Checking for the game executable...
if exist DungeonSiege2.exe (
set _INSTALL_LOCATION=%CD%
echo OK
goto menu
) else (
echo DungeonSiege2.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 39200" /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 the game executable in the installation directory
echo Checking for the game executable...
if exist "%_INSTALL_LOCATION%\DungeonSiege2.exe" (
echo OK
goto menu
) else (
echo DungeonSiege2.exe not found in the installation directory!
goto end
)
)
:menu
rem Selection menu
echo Please make a selection:
echo.
echo 1. Add registry entries for Dungeon Siege 2 (needed for BW, Elys DS2 and the DS2 Tool Kit)
echo 2. Add registry entries for Dungeon Siege 2 Broken World (needed for Elys DS2BW)
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.
echo Note: if you're not sure which option to select, just press 1.
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 DS2
if %ERRORLEVEL% == 2 goto DS2BW
if %ERRORLEVEL% == 3 goto junction
if %ERRORLEVEL% == 4 goto export
if %ERRORLEVEL% == 5 goto cleanup
if %ERRORLEVEL% == 6 exit /B
:DS2
echo Adding registry entries for Dungeon Siege 2...
REG ADD "%_MS_DS2%" /v "AppPath" /t REG_SZ /d "%_INSTALL_LOCATION%" /f %_REG_ARG% > nul
REG ADD "%_MS_DS2%" /v "InstallationDirectory" /t REG_SZ /d "%_INSTALL_LOCATION%" /f %_REG_ARG% > nul
REG ADD "%_MS_DS2%" /v "PID" /t REG_SZ /d "77033-133-5335624-40332" /f %_REG_ARG% > nul
echo DONE
goto end
:DS2BW
echo Adding registry entries for Dungeon Siege 2: Broken World...
REG ADD "%_2K_BW%" /v "AppPath" /t REG_SZ /d "%_INSTALL_LOCATION%" /f %_REG_ARG% > nul
REG ADD "%_2K_BW%" /v "InstallationDirectory" /t REG_SZ /d "%_INSTALL_LOCATION%" /f %_REG_ARG% > nul
REG ADD "%_2K_BW%" /v "PID" /t REG_SZ /d "0204-993D-D268-A1E2" /f %_REG_ARG% > nul
REG ADD "%_GPG_BW%\1.00.0000" /v "InstallLocation" /t REG_SZ /d "%_INSTALL_LOCATION%" /f %_REG_ARG% > nul
echo DONE
goto end
:junction
rem https://stackoverflow.com/a/8071683
rem Get the current 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.
)
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 2...
echo [%_MS_DS2_EXPORT%]>> %_REG_FILE%
echo "AppPath"="%_INSTALL_LOCATION_DOUBLE_BACKSLASH%">> %_REG_FILE%
echo "InstallationDirectory"="%_INSTALL_LOCATION_DOUBLE_BACKSLASH%">> %_REG_FILE%
echo.>> %_REG_FILE%
echo DONE
echo.
echo Exporting registry entries for Dungeon Siege 2: Broken World...
echo [%_2K_BW_EXPORT%]>> %_REG_FILE%
echo "AppPath"="%_INSTALL_LOCATION_DOUBLE_BACKSLASH%">> %_REG_FILE%
echo "InstallationDirectory"="%_INSTALL_LOCATION_DOUBLE_BACKSLASH%">> %_REG_FILE%
echo.>> %_REG_FILE%
echo [%_GPG_BW_EXPORT%]>> %_REG_FILE%
echo "InstallLocation"="%_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 2...
REG DELETE "%_MS_DS2%" /f %_REG_ARG% > nul
echo DONE
echo.
echo Removing registry entries for Dungeon Siege 2: Broken World...
REG DELETE "%_2K_BW%" /f %_REG_ARG% > nul
REG DELETE "%_GPG_BW%" /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