-
Notifications
You must be signed in to change notification settings - Fork 0
/
empire_start_wali_mach.bat
287 lines (227 loc) · 12.7 KB
/
empire_start_wali_mach.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
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
@echo Off
setlocal enabledelayedexpansion
SET empire_dir=%~dp0
SET "package_script_path=%userprofile%\AppData\Roaming\The Creative Assembly\Empire\scripts\user.empire_script.txt"
SET log_file_path=!empire_dir!empire_start_wali_mach.log
echo Deleting log file "!log_file_path!" >"!empire_dir!_" && type "!empire_dir!_" && type "!empire_dir!_" > !log_file_path!
SET exe_name=
if exist "VDM_Start.bat" (
echo "VadAntS Disease Mod" Launcher "VDM_Start.bat" is detected >"!empire_dir!_" && type "!empire_dir!_" && type "!empire_dir!_" >> !log_file_path!
SET exe_name=VDM_Start.bat
)
for /f "tokens=*" %%G in ('dir /b /a:d "!empire_dir!data\campaigns\*"') DO (call :campaign_scripting %%G)
if not exist "VDM_Start.bat" (
echo Preparing to start WALI >"!empire_dir!_" && type "!empire_dir!_" && type "!empire_dir!_" >> !log_file_path!
echo Changing directory to ./data/WALI >"!empire_dir!_" && type "!empire_dir!_" && type "!empire_dir!_" >> !log_file_path!
cd /d "%~dp0\data\WALI"
echo Launching WALI >"!empire_dir!_" && type "!empire_dir!_" && type "!empire_dir!_" >> !log_file_path!
start launch.bat 2>&1
echo Changing directory to Empire directory "%~dp0" >"!empire_dir!_" && type "!empire_dir!_" && type "!empire_dir!_" >> !log_file_path!
cd /d "%~dp0"
) else (
echo No need to start WALI because VadAntS Disease Mod is installed >"!empire_dir!_" && type "!empire_dir!_" && type "!empire_dir!_" >> !log_file_path!
)
SET process_name=
if exist Imperial.Splendour.exe (
echo Starting Imperial Splendour Launcher "Imperial.Splendour.exe" >"!empire_dir!_" && type "!empire_dir!_" && type "!empire_dir!_" >> !log_file_path!
start Imperial.Splendour.exe > output.log
SET exe_name=Imperial.Splendour.exe
SET process_name=javaw.exe
) else if exist ACW\\ACW3.exe (
echo Starting ACW Brother vs. Brother Launcher "ACW\\ACW3.exe" >"!empire_dir!_" && type "!empire_dir!_" && type "!empire_dir!_" >> !log_file_path!
start ACW\\ACW3.exe > output.log
SET exe_name=ACW3.exe
SET process_name=ACW3.exe
) else if exist "data\\DME\\DME Platinum.exe" (
echo Starting Darth Mod Empire Platinum Launcher "data\\DME\\DME Platinum.exe" >"!empire_dir!_" && type "!empire_dir!_" && type "!empire_dir!_" >> !log_file_path!
start "data\\DME\\DME Platinum.exe" > output.log
SET exe_name="data\\DME\\DME Platinum.exe"
SET process_name="DME Platinum.exe"
) else if exist "VDM_Start.bat" (
echo Starting VadAntS Disease Mod Launcher "VDM_Start.bat" >"!empire_dir!_" && type "!empire_dir!_" && type "!empire_dir!_" >> !log_file_path!
start VDM_Start.bat > output.log
SET exe_name=VDM_Start.bat
SET process_name=Empire.exe
) else (
echo Starting Empire Total War "Empire.exe" >"!empire_dir!_" && type "!empire_dir!_" && type "!empire_dir!_" >> !log_file_path!
start Empire.exe > output.log
SET exe_name=Empire.exe
SET process_name=Empire.exe
)
echo Checking if "!exe_name!" is still running. If not, kill WALI. >"!empire_dir!_" && type "!empire_dir!_" && type "!empire_dir!_" >> !log_file_path!
ping -n 5 127.0.0.1 > nul
:STILLRUNNING
cd /d "%~dp0"
ping -n 5 127.0.0.1 > nul
tasklist /FI "IMAGENAME eq !process_name!" | find /i "!process_name!"
IF NOT ERRORLEVEL 1 (GOTO STILLRUNNING)
IF ERRORLEVEL 1 (GOTO NOTRUNNING)
:NOTRUNNING
echo "!exe_name!" is no longer running. Shutting down WALI and cleaning up Machiavelli's Mods >"!empire_dir!_" && type "!empire_dir!_" && type "!empire_dir!_" >> !log_file_path!
for /f "tokens=*" %%G in ('dir /b /a:d "!empire_dir!data\campaigns\*"') DO (call :campaign_scripting_restore %%G)
echo Killing WALI processes. >"!empire_dir!_" && type "!empire_dir!_" && type "!empire_dir!_" >> !log_file_path!
TASKKILL /F /IM launch.bat /IM Launcher_ETW.exe /IM "WALI_Engine.exe" /IM "WALI_Engine.exe *32"
echo Successfully finished. >"!empire_dir!_" && type "!empire_dir!_" && type "!empire_dir!_" >> !log_file_path!
echo Deleting file "!empire_dir!_" >"!empire_dir!_" && type "!empire_dir!_" && type "!empire_dir!_" >> !log_file_path!
del "!empire_dir!_"
TASKKILL /F /IM "cmd.exe"
pause
exit
REM FUNCTION SECTION
:campaign_scripting
SETLOCAL
SET campaign_dir=%~nx1
SET scripting_lua="!empire_dir!data\campaigns\%campaign_dir%\scripting.lua"
SET scripting_lua_backup="!empire_dir!data\campaigns\%campaign_dir%\scripting.lua.bak"
echo Preparing campaign directory "%campaign_dir%" for MACH Mods >"!empire_dir!_" && type "!empire_dir!_" && type "!empire_dir!_" >> !log_file_path!
set "process=y"
if "%campaign_dir%"=="episodic_1" (
echo This is not a compatible campaign directory "%campaign_dir%" for MACH Mods >"!empire_dir!_" && type "!empire_dir!_" && type "!empire_dir!_" >> !log_file_path!
exit /b
)
if "%campaign_dir%"=="episodic_3" (
echo This is not a compatible campaign directory "%campaign_dir%" for MACH Mods >"!empire_dir!_" && type "!empire_dir!_" && type "!empire_dir!_" >> !log_file_path!
exit /b
)
if "%campaign_dir%"=="episodic_5" (
echo This is not a compatible campaign directory "%campaign_dir%" for MACH Mods >"!empire_dir!_" && type "!empire_dir!_" && type "!empire_dir!_" >> !log_file_path!
exit /b
)
echo Preparing %scripting_lua% >"!empire_dir!_" && type "!empire_dir!_" && type "!empire_dir!_" >> !log_file_path!
echo Backing up scripting.lua files for "%campaign_dir%" >"!empire_dir!_" && type "!empire_dir!_" && type "!empire_dir!_" >> !log_file_path!
copy %scripting_lua_backup% %scripting_lua%
copy %scripting_lua% %scripting_lua_backup%
del /f %scripting_lua%
echo Adding MACH mod to scripting.lua files for "%campaign_dir%" >"!empire_dir!_" && type "!empire_dir!_" && type "!empire_dir!_" >> !log_file_path!
echo --START Machiavelli's Mods > %scripting_lua%
echo mach = require "WALI/mach" >> %scripting_lua%
echo mach_lib = require "WALI/mach_lib" >> %scripting_lua%
echo mach_lib.create_mach_lua_log() >> %scripting_lua%
echo mach_lib.update_mach_lua_log("Finished creating MACH log.") >> %scripting_lua%
echo function error_catch_function() >> %scripting_lua%
echo mach.initialize_mach() >> %scripting_lua%
echo --END Machiavelli's Mods >> %scripting_lua%
echo.>> %scripting_lua%
echo Finished adding MACH mod prefix to scripting.lua >"!empire_dir!_" && type "!empire_dir!_" && type "!empire_dir!_" >> !log_file_path!
type "!empire_dir!\data\campaigns\%campaign_dir%\scripting.lua.bak" >> %scripting_lua%
echo Finished adding original contents to scripting.lua >"!empire_dir!_" && type "!empire_dir!_" && type "!empire_dir!_" >> !log_file_path!
if "!exe_name!"=="VDM_Start.bat" (
if "%campaign_dir%"=="main" (
call :vadants_disease_mod_scripting_edits
)
)
echo.>> %scripting_lua%
echo --START Machiavelli's Mods >> %scripting_lua%
echo end >> %scripting_lua%
echo val,err = pcall(error_catch_function) >> %scripting_lua%
echo mach_lib.update_mach_lua_log(err.."\n") >> %scripting_lua%
echo --END Machiavelli's Mods >> %scripting_lua%
echo Finished adding MACH mod suffix to scripting.lua >"!empire_dir!_" && type "!empire_dir!_" && type "!empire_dir!_" >> !log_file_path!
echo Finished preparing campaign directory "%campaign_dir%" for MACH Mods >"!empire_dir!_" && type "!empire_dir!_" && type "!empire_dir!_" >> !log_file_path!
ENDLOCAL
exit /b
:vadants_disease_mod_scripting_edits
SETLOCAL
echo Making additional compatibility edits for "VadAntS Disease Mod" >"!empire_dir!_" && type "!empire_dir!_" && type "!empire_dir!_" >> !log_file_path!
set scripting_lua_vadants="!empire_dir!data\campaigns\%campaign_dir%\scripting.lua.new"
set scripting_lua_vadants2="!empire_dir!data\campaigns\%campaign_dir%\scripting.lua.new2"
set found_first_line=false
del /f %scripting_lua_vadants%
del /f %scripting_lua_vadants2%
setlocal enabledelayedexpansion
echo Editing scripting.lua >"!empire_dir!_" && type "!empire_dir!_" && type "!empire_dir!_" >> !log_file_path!
for /f "tokens=1* delims=:" %%f in ('findstr /n "^" %scripting_lua%') do (
set prefix=%%f
set scripting_line=%%g
if "!scripting_line!"=="events.PanelOpenedCampaign[#events.PanelOpenedCampaign+1] = function (context)" (
if !found_first_line!==false (
echo found line: "events.PanelOpenedCampaign[#events.PanelOpenedCampaign+1] = function (context)" in scripting.lua >"!empire_dir!_" && type "!empire_dir!_" && type "!empire_dir!_" >> !log_file_path!
echo !scripting_line!>> %scripting_lua_vadants%
echo --START Machiavelli's Mods >> %scripting_lua_vadants%
echo if path then>> %scripting_lua_vadants%
echo --END Machiavelli's Mods >> %scripting_lua_vadants%
set found_first_line=true
)
) else if "!scripting_line!"==" justSaved = false" (
if !found_first_line!==true (
echo found line: " justSaved = false" in scripting.lua >"!empire_dir!_" && type "!empire_dir!_" && type "!empire_dir!_" >> !log_file_path!
echo !scripting_line!>> %scripting_lua_vadants%
echo --START Machiavelli's Mods >> %scripting_lua_vadants%
echo end>> %scripting_lua_vadants%
echo --END Machiavelli's Mods >> %scripting_lua_vadants%
set found_first_line=false
)
) else if "!scripting_line!"==" " (
echo.>> %scripting_lua_vadants%
) else if "!scripting_line!"=="<TAB>" (
echo.>> %scripting_lua_vadants%
) else if "!scripting_line!"==" " (
echo.>> %scripting_lua_vadants%
) else if "!scripting_line!"=="" (
echo.>> %scripting_lua_vadants%
) else if !scripting_line!=="" (
echo.>> %scripting_lua_vadants%
) else if not defined scripting_line (
echo.>> %scripting_lua_vadants%
) else if "!scripting_line!"=="ECHO is off." (
echo.>> %scripting_lua_vadants%
) else if !found_first_line!==true (
echo !scripting_line!>> %scripting_lua_vadants%
) else (
echo !scripting_line!>> %scripting_lua_vadants%
)
)
echo Removing "ECHO is off." statements from scripting.lua >"!empire_dir!_" && type "!empire_dir!_" && type "!empire_dir!_" >> !log_file_path!
for /f "tokens=1* delims=:" %%f in ('findstr /n "^" %scripting_lua_vadants%') do (
set prefix=%%f
set scripting_line2=%%g
if "!scripting_line!"==" " (
echo.>> %scripting_lua_vadants2%
) else if "!scripting_line2!"=="<TAB>" (
echo.>> %scripting_lua_vadants2%
) else if "!scripting_line2!"==" " (
echo.>> %scripting_lua_vadants2%
) else if "!scripting_line2!"=="" (
echo.>> %scripting_lua_vadants2%
) else if !scripting_line2!=="" (
echo.>> %scripting_lua_vadants2%
) else if not defined scripting_line2 (
echo.>> %scripting_lua_vadants2%
) else if "!scripting_line2!"=="ECHO is off." (
echo.>> %scripting_lua_vadants2%
) else (
echo !scripting_line2!>> %scripting_lua_vadants2%
)
)
echo Finished removing "ECHO is off." statements from scripting.lua >"!empire_dir!_" && type "!empire_dir!_" && type "!empire_dir!_" >> !log_file_path!
del /f %scripting_lua%
del /f %scripting_lua_vadants%
rename %scripting_lua_vadants2% scripting.lua
echo Finished making additional compatibility edits for "VadAntS Disease Mod" >"!empire_dir!_" && type "!empire_dir!_" && type "!empire_dir!_" >> !log_file_path!
ENDLOCAL
exit /b
:campaign_scripting_restore
SETLOCAL
SET campaign_dir=%~nx1
SET scripting_lua="!empire_dir!data\campaigns\%campaign_dir%\scripting.lua"
SET scripting_lua_backup="!empire_dir!data\campaigns\%campaign_dir%\scripting.lua.bak"
set "process=y"
if "%campaign_dir%"=="episodic_1" (
echo This is not a compatible campaign directory "%campaign_dir%" for MACH Mods >"!empire_dir!_" && type "!empire_dir!_" && type "!empire_dir!_" >> !log_file_path!
exit /b
)
if "%campaign_dir%"=="episodic_3" (
echo This is not a compatible campaign directory "%campaign_dir%" for MACH Mods >"!empire_dir!_" && type "!empire_dir!_" && type "!empire_dir!_" >> !log_file_path!
exit /b
)
if "%campaign_dir%"=="episodic_5" (
echo This is not a compatible campaign directory "%campaign_dir%" for MACH Mods >"!empire_dir!_" && type "!empire_dir!_" && type "!empire_dir!_" >> !log_file_path!
exit /b
)
echo Restoring %scripting_lua% >"!empire_dir!_" && type "!empire_dir!_" && type "!empire_dir!_" >> !log_file_path!
echo Restoring backup scripting.lua files in "%campaign_dir%". >"!empire_dir!_" && type "!empire_dir!_" && type "!empire_dir!_" >> !log_file_path!
del /f %scripting_lua%
rename %scripting_lua_backup% scripting.lua
echo Finished restoring backup scripting.lua files in "%campaign_dir%". >"!empire_dir!_" && type "!empire_dir!_" && type "!empire_dir!_" >> !log_file_path!
ENDLOCAL
exit /b