-
Notifications
You must be signed in to change notification settings - Fork 3
/
UCP_create_JSGME_install.cmd
569 lines (460 loc) · 14.1 KB
/
UCP_create_JSGME_install.cmd
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
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
@ECHO OFF
CLS
:: This script is Copyright (c) ermo 2011-2013 and is distributed under the
:: Creative Commons Attribution-NonCommercial-ShareAlike unported v3.0 license,
:: which can be read in full at http://creativecommons.org/licenses/by-nc-sa/3.0/
::
:: Authors: ermo@NoGripRacing (S2U Unofficial Community Patch maintainer)
:: matt2380@NoGripRacing (S2U Unofficial Community Patch creator)
::
:: Any remixes of this script shall include the above notices.
:: Automate the injection of relevant S2U BFF assets for the UCP.
::
:: Per request, this script now also works if it is
:: run as administrator directly from the S2U install folder.
::
:main
:: Let's not pollute the system variable namespace...
SETLOCAL EnableDelayedExpansion
SET _TIME=%TIME%
SET _VER=NoGrip_UCP_v1.1-pre1.0.99g
@ECHO.
@ECHO NFS SHIFT 2: Unleashed -- Unofficial Community Patch install script
@ECHO ===================================================================
@ECHO.
GOTO check
:help
@ECHO.
@ECHO %_MSG%
@ECHO.
@ECHO Usage: %~n0
@ECHO.
@ECHO HINT:
@ECHO.
@ECHO You should copy the contents of this folder (including subfolders)
@ECHO to your S2U installation folder and right click this script and
@ECHO choose the option 'Run as administrator'.
@ECHO.
GOTO exit
:check
:: get the folder from which this batch file was run
:: and save it for future reference.
:: d = drive letter, p = folder path, 0 = references this file
SET _CWD="%~dp0"
:: Get rid of any weird quoting in the path
:: -- this subroutine will be used all the time in the rest of the script
CALL :DeQuote _CWD
:: This is necessary when the script is run as administrator
:: cd /d also switches drive as appropriate
IF "%CD%"=="%windir%\system32" (
@ECHO + Looks like we were run as administrator ...
@ECHO.
CD /D "%_CWD%"
)
:: Now we should definitely be in the correct folder,
:: but we're going to check that assumption anyway, just
:: to be on the safe side.
IF "%CD%"=="%windir%\system32" (
@ECHO - Current working folder is:
@ECHO "%CD%"
@ECHO - It is supposed to be:
@ECHO "%_CWD%"
SET _MSG=- Aborting install because we won't be able to inject properly. Sorry.
GOTO die
)
@ECHO + Working folder is:
@ECHO "%_CWD%" -- good.
@ECHO.
:: ensure the S2U install folder was specified as the first argument
:: OR that we were run from the S2U install folder.
:: To begin with, be opportunistic and assume that we are run
:: from the S2U install folder
SET _S2U_DIR="%_CWD%"
:: If a parameter was supplied to the script, use that instead
IF NOT [%1]==[] (
SET _S2U_DIR="%1"
)
CALL :DeQuote _S2U_DIR
IF NOT EXIST "%_S2U_DIR%\SHIFT2U.exe" (
SET _MSG=- No SHIFT2U.exe file found in "%_S2U_DIR%" ^!
GOTO help
)
@ECHO + Found SHIFT2U.exe in:
@ECHO "%_S2U_DIR%" -- good.
@ECHO.
:: check for the unpacking tool before we start
IF NOT EXIST "%_CWD%\quickbms.exe" (
SET _MSG=- No quickbms.exe S2U unpack tool found in "%_CWD%" -- aborting^!
GOTO die
)
IF NOT EXIST "%_CWD%\nfsshift.bms" (
SET _MSG=- No nfsshift.bms S2U BMS script found in "%_CWD%" -- aborting^!
GOTO die
)
@ECHO + quickbms tool found in:
@ECHO "%_CWD%" -- good.
@ECHO.
:: check for the injector tool before we start
IF NOT EXIST "%_CWD%\NFSSInjector.exe" (
SET _MSG=- No NFSSInjector.exe tool found in "%_CWD%" -- aborting^!
GOTO die
)
@ECHO + NFSSInjector.exe tool found in:
@ECHO "%_CWD%" -- good.
@ECHO.
:: check for the existence of \MODS\S2U_Unpacked_version and point people towards the
:: install instructions if it doesn't exist
IF NOT EXIST "%_CWD%MODS\S2U_Unpacked_version\_RTFM_.txt" (
SET _MSG=- \MODS\S2U_Unpacked_version\ wasn^'t found^? Did you Read The Fine Manual^?
GOTO die
)
:: check that people activated \MODS\S2U_Unpacked_version and point them towards the
:: install instructions if hasn't been activated
IF NOT EXIST "%_CWD%_RTFM_.txt" (
SET _MSG=- S2U_Unpacked_version wasn^'t activated^? Did you Read The Fine Manual^?
GOTO die
)
:: Set up commands
:: xcopy is not available on Windows 8 and later - robocopy is not available on Windows XP and earlier
:: -- prefer robocopy over xcopy
:: note that %windir%\system32\ will always lead to the correct version on both 32bit and 64bit Windows
::
:: Moreover, notice that the built-in copy command does not automatically create folders, which
:: is why we need to use either xcopy or robocopy which DO create folders. Sheesh.
::
SET XCOPY=@ECHO XCOPY is unset! -- not copying^:
IF EXIST %WINDIR%\System32\xcopy.exe SET XCOPY=%WINDIR%\System32\xcopy.exe /S /I /Y /V
IF EXIST %WINDIR%\System32\robocopy.exe SET XCOPY=%WINDIR%\System32\robocopy.exe /S
SET COPY=copy /B /V /Y
SET INJECT=NFSSInjector.exe
SET UNPACK=quickbms.exe -o nfsshift.bms
:: Set up paths
SET _ASSETS=UCP_modified_assets
SET _INSTALL_DIR=MODS\%_VER%_JSGME_install
CALL :DeQuote _INSTALL_DIR
SET _TARGET="%_CWD%%_INSTALL_DIR%"
CALL :DeQuote _TARGET
SET _SRC="%_CWD%%_ASSETS%"
CALL :DeQuote _SRC
:prepare
:: In this phase, create a full folder structure ready for JSGME activation.
:: We need to support the case where the user copies the folder
:: directly into the S2U installation folder as well.
@ECHO + Preparing JSGME compatible UCP mod installation folder in:
@ECHO.
@ECHO "%_TARGET%"
@ECHO.
@ECHO (Press CTRL+C to quit now)
pause
@ECHO.
IF NOT EXIST "%_TARGET%" (
SET _MSG=- Could not create folder "%_TARGET%" -- aborting^!
MKDIR "%_TARGET%" || GOTO die
)
:: Getting a sense of how long it takes to prepare may be useful to users
SET _PREP_START=%TIME%
:: DLC1 various track fixes (for injection)
SET _DIR=DLC1\Pakfiles\Tracks
SET _SRC="%_S2U_DIR%\%_DIR%"
SET _DEST="%_TARGET%\%_DIR%\"
CALL :DeQuote _SRC _DEST
SET _MSG=- Couldn't copy files from "%_SRC%" -- aborting^!
IF NOT EXIST "%_DEST%" (
SET _MSG=- Could not create folder "%_DEST%" -- aborting^!
MKDIR "%_DEST%" || GOTO die
)
if exist "%_SRC%" (
@ECHO + Copying files from "%_SRC%" ...
@ECHO.
FOR %%F in (
hockenheim_era2.bff
rouen.bff
rouen_short.bff
silverstone_era2.bff
) DO (
@ECHO %%F
%COPY% "%_SRC%\%%F" "%_DEST%" 2>&1 > NUL || GOTO die
)
)
@ECHO.
:: DLC2 various track fixes (for injection)
SET _DIR=DLC2\Pakfiles\Tracks
SET _SRC="%_S2U_DIR%\%_DIR%"
SET _DEST="%_TARGET%\%_DIR%\"
CALL :DeQuote _SRC _DEST
SET _MSG=- Couldn't copy files from "%_SRC%" -- aborting^!
IF NOT EXIST "%_DEST%" (
SET _MSG=- Could not create folder "%_DEST%" -- aborting^!
MKDIR "%_DEST%" || GOTO die
)
if exist "%_SRC%" (
@ECHO + Copying files from "%_SRC%" ...
@ECHO.
FOR %%F in (
asia_drag_strip.bff
asia_drag_strip_night.bff
asia_drag_strip2.bff
asia_drag_strip2_night.bff
usa_drag_strip.bff
usa_drag_strip2.bff
) DO (
@ECHO %%F
%COPY% "%_SRC%\%%F" "%_DEST%" 2>&1 > NUL || GOTO die
)
)
@ECHO.
:: Stock game various track fixes (for injection)
SET _DIR=Pakfiles\Tracks
SET _SRC=%_S2U_DIR%\%_DIR%
SET _DEST=%_TARGET%\%_DIR%\
CALL :DeQuote _SRC _DEST
SET _MSG=- Couldn't copy files from "%_SRC%" -- aborting^!
IF NOT EXIST "%_DEST%" (
SET _MSG=- Could not create folder "%_DEST%" -- aborting^!
MKDIR "%_DEST%" || GOTO die
)
@ECHO + Copying files from "%_SRC%" ...
@ECHO.
FOR %%F in (
Tokyo_Circuit_Night.bff
Tokyo_Drift_Night.bff
USA_Drift_Night.bff
Shanghai_Circuit2_night.bff
Shanghai_Circuit3_night.bff
Shanghai_Circuit1_night.bff
Tokyo_Short_reverse_night.bff
Nuerburgring_Sprint_Short_night.bff
Port_Boucle_Night.bff
Monument_Loop_Night.bff
Nuerburgring_GP_night.bff
Nuerburgring_Sprint_night.bff
Irwindale_Drift1_Night.bff
Irwindale_Drift2_Night.bff
Irwindale_night.bff
London_Drift_Night.bff
Ebisu_West_Night.bff
glendale_club_Night.bff
glendale_east_Night.bff
Hazyview_Oval_Night.bff
Dubai_GP_Night.bff
Dubai_INT_Night.bff
Dubai_NAT_Night.bff
Dubai_Club_Night.bff
Monte_Grande.bff
Nuerburgring_Sprint_Short.bff
Tokyo_Circuit.bff
Tokyo_Circuit_reverse.bff
Hazyview_Eight_Night.bff
Irwindale.bff
Irwindale_Drift1.bff
Irwindale_Drift2.bff
London_Drift.bff
Casino_Riviera_Night.bff
Dubai_NAT.bff
Ebisu_Touge.bff
Ebisu_West.bff
Barcelona_National.bff
Casino_Riviera.bff
Chesterglen.bff
Hazyview_Eight.bff
Nuerburgring_Sprint.bff
Tokyo_Short_Night.bff
Zolder.bff
Monument_Loop.bff
Nevada_Drift4_Night.bff
Port_Boucle.bff
Willow_springs_Horse_Thief_Mile.bff
Dubai_GP.bff
Dubai_INT.bff
Ebisu_Touge_Night.bff
Monza_Era3.bff
Monza_Era3_jr.bff
Nevada_Drift1.bff
Nevada_Drift1_Night.bff
Nevada_Drift2_Night.bff
Nevada_Drift3_Night.bff
Nevada_Drift4.bff
Tokyo_Drift.bff
Tokyo_Short_reverse.bff
Bathurst_night.bff
Hockenheim_Short_Night.bff
Hockenheim_Short.bff
Nevada_Drift2.bff
Tokyo_Short.bff
Barcelona_CLUB.bff
Hockenheim_GP_Night.bff
Hockenheim_National_Night.bff
Rustle_Creek.bff
Donington_GP.bff
Donington_National.bff
Dubai_Club.bff
Glendale_West_Night.bff
Hockenheim_GP.bff
Monte_Grande_Night.bff
Nevada_Drift3.bff
Nuerburgring_GP.bff
Barcelona_GP.bff
Dijon.bff
Dijon_short.bff
Ebisu_South.bff
Ebisu_South_Night.bff
Hazyview_Oval.bff
Hockenheim_National.bff
) DO (
@ECHO %%F
%COPY% "%_SRC%\%%F" "%_DEST%" 2>&1 > NUL || GOTO die
)
@ECHO.
SET _PREP_FINISH=%TIME%
@ECHO + Done preparing (started at %_PREP_START%, finished at %_PREP_FINISH%) ...
@ECHO.
:inject
:: Ok, so we have prepared the files in the JSGME dir
:: and can now inject the modifed files into the .bffs there.
:: Ensure that we're on the correct drive and in the correct folder
:: when injecting; better safe than sorry and all that jazz...
CD /D "%_CWD%"
@ECHO.
@ECHO + Ready to inject modified assets into the packed files in:
@ECHO.
@ECHO "%_TARGET%\Pakfiles" ...
@ECHO.
REM pause
@ECHO.
SET _MSG=+ Going to run NFSSInjector.exe -i "%_ASSETS%\packed" "%_INSTALL_DIR%" :
@ECHO %_MSG%
@ECHO.
:: Getting a sense of how long it takes to inject may be useful to users
SET _INJECT_START=%TIME%
if exist "%_ASSETS%\packed" (
%INJECT% -i "%_ASSETS%\packed" "%_INSTALL_DIR%" || GOTO die
@ECHO.
) else (
@ECHO - Current working folder is:
@ECHO "%CD%"
@ECHO - It is supposed to be:
@ECHO "%_CWD%"
@ECHO.
@ECHO - Hm. This is not supposed to happen.
@ECHO.
@ECHO - But since it did anyway, we'd better stop here. Usually, this
@ECHO - indicates that your S2U folder lives on a different drive than
@ECHO - your Windows install and that you ran the script as administrator.
@ECHO.
@ECHO - If the above is true, try running the script normally instead
@ECHO - of with 'run as administrator' and see if that helps any.
GOTO die
)
if exist "%_INSTALL_DIR%\DLC1" (
SET _MSG=+ Going to run NFSSInjector.exe -i "%_ASSETS%\packedDLC1" "%_INSTALL_DIR%\DLC1" :
@ECHO %_MSG%
@ECHO.
%INJECT% -i "%_ASSETS%\packedDLC1" "%_INSTALL_DIR%\DLC1" || GOTO die
@ECHO.
)
if exist "%_INSTALL_DIR%\DLC2" (
SET _MSG=+ Going to run NFSSInjector.exe -i "%_ASSETS%\packedDLC2" "%_INSTALL_DIR%\DLC2" :
@ECHO %_MSG%
@ECHO.
%INJECT% -i "%_ASSETS%\packedDLC2" "%_INSTALL_DIR%\DLC2" || GOTO die
@ECHO.
)
SET _INJECT_FINISH=%TIME%
@ECHO.
@ECHO + Done injecting (started at %_INJECT_START%, finished at %_INJECT_FINISH%) ...
@ECHO.
:copy
:: Now copy in the UCP unpacked modified assets
SET _SRC="%_CWD%%_ASSETS%\unpacked"
SET _DEST="%_TARGET%"
CALL :DeQuote _SRC _DEST
SET _MSG=+ Copying UCP assets from "%_ASSETS%\unpacked" to install folder:
@ECHO %_MSG%
@ECHO.
@ECHO "%_TARGET%"
cd /d "%_CWD%"
@ECHO.
%XCOPY% "%_SRC%" "%_DEST%" 2>&1 > xcopy.log
SET _RV=%ERRORLEVEL%
:: Right, robocopy uses a return code bitmask to indicate status, which means that the usual
:: "|| goto die" idiom doesn't work. *sigh* ...
IF "%_RV%"=="1" (
IF "%XCOPY%"=="%WINDIR%\System32\robocopy.exe /S" (
goto finished
) ELSE (
@ECHO.
@ECHO - Asset copy exited with status %_RV%
@ECHO -- check the log in "%_CWD%\xcopy.log"
goto die
)
)
IF "%_RV%"=="0" (
IF "%XCOPY%"=="%WINDIR%\System32\xcopy.exe /S /I /Y /V" (
goto finished
)
ELSE (
@ECHO.
@ECHO - Asset copy exited with status %_RV%
@ECHO -- check the log in "%_CWD%\xcopy.log"
@ECHO.
goto die
)
)
:finished
:: get rid of xcopy.log -- it is only useful when stuff goes awry
IF EXIST "%_CWD%\xcopy.log" del "%_CWD%\xcopy.log" 2>&1 > NUL
@ECHO.
@ECHO + This UCP install script run started at %_TIME% and finished at %TIME%
@ECHO.
@ECHO + Successfully prepared the UCP JSGME installation folder in:
@ECHO.
@ECHO "%_TARGET%"
@ECHO.
@ECHO The next step is to activate the UCP version that you just built,
@ECHO using the JSGME tool.
@ECHO.
@ECHO Activating the UCP will take a little while as it needs to move a lot
@ECHO of files around, so please be patient during the activation process.
@ECHO.
@ECHO. -- The Authors
@ECHO.
REM @ECHO. + Preparation phase : from %_PREP_START% to %_PREP_FINISH%
REM @ECHO. + Injection phase : from %_INJECT_START% to %_INJECT_FINISH%
REM @ECHO.
GOTO exit
:: DeQuote function -- it simply removes all quotes in a variable, which is very useful
:DeQuote
FOR %%G IN (%*) DO (
SET DeQuote.Variable=%%G
CALL SET DeQuote.Contents=%%!DeQuote.Variable!%%
IF [!DeQuote.Contents:~0^,1!]==[^"] (
IF [!DeQuote.Contents:~-1!]==[^"] (
SET DeQuote.Contents=!DeQuote.Contents:~1,-1!
) ELSE (GOTO :EOF no end quote)
) ELSE (GOTO :EOF no beginning quote)
SET !DeQuote.Variable!=!DeQuote.Contents!
SET DeQuote.Variable=
SET DeQuote.Contents=
)
GOTO :EOF
:: Copied from http://ss64.com/nt/syntax-dequote.html
:::::::::::::::::::::::::::::::::::::::::::::::::::::::
:die
:: Set _MSG and GOTO die when something goes wrong.
@ECHO.
@ECHO - Uh Oh! Something went awry...
@ECHO.
@ECHO The process failed during the following step:
@ECHO.
@ECHO %_MSG%
@ECHO.
@ECHO - Please review the error message given, act appropriately, and try again :)
@ECHO.
GOTO exit
:exit
:: return to the root folder of the unpacked mod
CD /D %_CWD%
:: End local variable scope
ENDLOCAL
pause
:eof