-
Notifications
You must be signed in to change notification settings - Fork 23
/
Copy pathUnRen.bat
388 lines (350 loc) · 13.8 KB
/
UnRen.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
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
@echo off
REM [DEV//WARN_START
title UnRen.bat Error
echo/
echo Error!
echo/
echo This is the development version of UnRen. This is non functional and not
echo intended to be used by end users.
echo Please use the release version instead, found in the F95zone thread:
echo/
echo https://f95zone.to/threads/unren-bat-rpa-extractor-rpyc-decompiler-console-developer-menu-enabler.3083/
echo/
pause>nul|set/p=. Press any key to exit...
echo/
pause
exit
REM DEV//WARN_END]
REM --------------------------------------------------------------------------------
REM Configuration:
REM Set a Quick Save and Quick Load hotkey - http://www.pygame.org/docs/ref/key.html
REM --------------------------------------------------------------------------------
set "quicksavekey=K_F5"
set "quickloadkey=K_F9"
REM --------------------------------------------------------------------------------
REM !! END CONFIG !!
REM --------------------------------------------------------------------------------
REM The following variables are Base64 encoded strings for unrpyc and rpatool
REM Due to batch limitations on variable lengths, they need to be split into
REM multiple variables, and joined later using powershell.
REM --------------------------------------------------------------------------------
REM unrpyc by CensoredUsername
REM https://github.com/CensoredUsername/unrpyc
REM Edited to remove multiprocessing and adjust output spacing [UNRPYC//SHA] [UNRPYC//DATE]
REM https://github.com/F95Sam/unrpyc
REM --------------------------------------------------------------------------------
REM set unrpyccab01=
[UNRPYC//BASE]
REM --------------------------------------------------------------------------------
REM rpatool by Shizmob [RPATOOL//SHA] [RPATOOL//DATE]
REM https://github.com/Shizmob/rpatool
REM --------------------------------------------------------------------------------
REM set rpatool01=
[RPATOOL//BASE]
REM --------------------------------------------------------------------------------
REM !! DO NOT EDIT BELOW THIS LINE !!
REM --------------------------------------------------------------------------------
set "version=0.9.0-dev ([DEV//BUILD_DATE])"
title UnRen.bat v%version%
:init
REM --------------------------------------------------------------------------------
REM Splash screen
REM --------------------------------------------------------------------------------
cls
echo/
echo __ __ ____ __ __
echo / / / /___ / __ \___ ____ / /_ ____ _/ /_
echo / / / / __ \/ /_/ / _ \/ __ \ / __ \/ __ ^`/ __/
echo / /_/ / / / / _^, _/ __/ / / / / /_/ / /_/ / /_
echo \____/_/ /_/_/ ^|_^|\___/_/ /_(_)_.___/\__^,_/\__/ v%version%
echo Sam @ www.f95zone.to
echo/
echo ----------------------------------------------------
echo/
REM --------------------------------------------------------------------------------
REM Set up the work paths and assert script, python and powershell location
REM Note: 'if/else/else if' would be nice, but make just problems in batch
REM --------------------------------------------------------------------------------
set err=0
set err_msg="Unknown reason..."
set currentdir=%~dp0
if exist "game" if exist "lib" if exist "renpy" (
set "pythondir=%currentdir%lib\windows-i686\"
set "renpydir=%currentdir%renpy\"
set "gamedir=%currentdir%game\"
goto :path_ok
)
if exist "..\game" if exist "..\lib" if exist "..\renpy" (
set "pythondir=%currentdir%..\lib\windows-i686\"
set "renpydir=%currentdir%..\renpy\"
set gamedir=%currentdir%
goto :path_ok
)
echo ! Error: The location of UnRen appears to be wrong. It should
echo be in the game's root directory.
echo (dirs 'game', 'lib', 'renpy' are present)
echo/
goto :error
:path_ok
if not exist "%pythondir%python.exe" (
echo ! Error: Cannot locate python.exe, unable to continue.
echo Are you sure we're in the game's root directory?
echo/
goto :error
)
if not exist "%SystemRoot%\system32\WindowsPowerShell\v1.0\powershell.exe" (
echo ! Error: Powershell is required, unable to continue.
echo This is included in Windows 7, 8, 10. XP/Vista users can
echo download it here: http://support.microsoft.com/kb/968929
echo/
goto :error
)
REM --------------------------------------------------------------------------------
REM Menu selection
REM --------------------------------------------------------------------------------
:menu
set exitoption=
echo Available Options:
echo 1) Extract RPA packages
echo 2) Decompile rpyc files
echo 3) Enable Console and Developer Menu
echo 4) Enable Quick Save and Quick Load
echo 5) Force enable skipping of unseen content
echo 6) Force enable rollback (scroll wheel)
echo/
echo 9) All of the above
echo/
set /p option=. Enter a number:
echo/
echo ----------------------------------------------------
echo/
if "%option%"=="1" goto :extract
if "%option%"=="2" goto :decompile
if "%option%"=="3" goto :console
if "%option%"=="4" goto :quick
if "%option%"=="5" goto :skip
if "%option%"=="6" goto :rollback
if "%option%"=="9" goto :extract
goto :init
REM --------------------------------------------------------------------------------
REM Write _rpatool.py from our base64 strings
REM --------------------------------------------------------------------------------
:extract
set "rpatool=%currentdir%_rpatool.py"
echo/
echo Creating rpatool...
if exist "%rpatool%.tmp" (
del "%rpatool%.tmp"
)
if exist "%rpatool%" (
del "%rpatool%"
)
REM echo %rpatool%>> "%rpatool%.tmp"
[RPATOOL//MERGE]
set "rpatoolps=%rpatool:[=`[%"
set "rpatoolps=%rpatoolps:]=`]%"
set "rpatoolps=%rpatoolps:^=^^%"
set "rpatoolps=%rpatoolps:&=^&%"
powershell.exe -nologo -noprofile -noninteractive -command "& { [IO.File]::WriteAllBytes(\"%rpatoolps%\", [Convert]::FromBase64String([IO.File]::ReadAllText(\"%rpatoolps%.tmp\"))) }"
REM --------------------------------------------------------------------------------
REM Check if rpatool is there.
REM --------------------------------------------------------------------------------
if not exist "%rpatool%" (
echo ! Error: 'rpatool' is missing. Please check if UnRen and Powershell
echo are working correctly.
echo/
set err=1 & goto :rpatool_cleanup
)
REM --------------------------------------------------------------------------------
REM Unpack RPA
REM --------------------------------------------------------------------------------
echo/
echo Searching for RPA packages
cd "%gamedir%"
for %%f in (*.rpa) do (
echo + Unpacking "%%~nf%%~xf" - %%~zf bytes
"%pythondir%python.exe" -O "%rpatool%" -x "%%f"
)
REM --------------------------------------------------------------------------------
REM Clean up
REM --------------------------------------------------------------------------------
:rpatool_cleanup
echo/
echo Cleaning up temporary files...
del "%rpatool%.tmp"
del "%rpatool%"
echo/
)
if not %err% == 0 goto :error
if not "%option%" == "9" goto :finish
REM --------------------------------------------------------------------------------
REM Write to temporary file first, then convert. Needed due to binary file
REM --------------------------------------------------------------------------------
:decompile
set "unrpyccab=%gamedir%..\_unrpyc.cab"
set "decompilerdir=%gamedir%..\decompiler"
set "unrpycpy=%gamedir%..\unrpyc.py"
echo/
echo Creating _unrpyc.cab...
if exist "%unrpyccab%.tmp" (
del "%unrpyccab%.tmp"
)
if exist "%unrpyccab%" (
del "%unrpyccab%"
)
if exist "%unrpycpy%" (
del "%unrpycpy%"
)
if exist "%decompilerdir%" (
rmdir /Q /S "%decompilerdir%"
)
REM echo %unrpyccab%>> "%unrpyccab%.tmp"
[UNRPYC//MERGE]
set "unrpyccabps=%unrpyccab:[=`[%"
set "unrpyccabps=%unrpyccabps:]=`]%"
set "unrpyccabps=%unrpyccabps:^=^^%"
set "unrpyccabps=%unrpyccabps:&=^&%"
powershell.exe -nologo -noprofile -noninteractive -command "& { [IO.File]::WriteAllBytes(\"%unrpyccabps%\", [Convert]::FromBase64String([IO.File]::ReadAllText(\"%unrpyccabps%.tmp\"))) }"
REM --------------------------------------------------------------------------------
REM Once converted, extract the cab file. Needs to be a cab file due to expand.exe
REM --------------------------------------------------------------------------------
echo/
echo Extracting _unrpyc.cab...
mkdir "%decompilerdir%"
expand -F:* "%unrpyccab%" "%decompilerdir%" >nul
move "%decompilerdir%\unrpyc.py" "%unrpycpy%" >nul
REM --------------------------------------------------------------------------------
REM Check if unrpyc is there
REM --------------------------------------------------------------------------------
if not exist "%unrpycpy%" (
echo ! Error: 'unrpyc' is missing. Please check if UnRen and Powershell
echo are working correctly.
echo/
set err=1 & goto :unrpyc_cleanup
)
REM --------------------------------------------------------------------------------
REM Decompile rpyc files
REM --------------------------------------------------------------------------------
echo/
echo Searching for rpyc files...
cd "%gamedir%"
for /r %%f in (*.rpyc) do (
if not %%~nf == un (
echo + Decompiling "%%~nf%%~xf" - %%~zf bytes
"%pythondir%python.exe" -O "%unrpycpy%" "%%f"
)
)
REM --------------------------------------------------------------------------------
REM Clean up
REM --------------------------------------------------------------------------------
:unrpyc_cleanup
echo/
echo Cleaning up temporary files...
del "%unrpyccab%.tmp"
del "%unrpyccab%"
del "%unrpycpy%"
rmdir /Q /S "%decompilerdir%"
if not %err% == 0 goto :error
if not "%option%" == "9" goto :finish
:console
REM --------------------------------------------------------------------------------
REM Drop our console/dev mode enabler into the game folder
REM --------------------------------------------------------------------------------
echo/
echo Creating Developer/Console file...
set "consolefile=%gamedir%unren-dev.rpy"
if exist "%consolefile%" (
del "%consolefile%"
)
echo init 999 python:>> "%consolefile%"
echo config.developer = True>> "%consolefile%"
echo config.console = True>> "%consolefile%"
echo + Console: SHIFT+O
echo + Dev Menu: SHIFT+D
if not "%option%" == "9" goto :finish
REM --------------------------------------------------------------------------------
REM Drop our Quick Save/Load file into the game folder
REM --------------------------------------------------------------------------------
:quick
echo/
echo Creating Quick Save/Quick Load file...
set "quickfile=%gamedir%unren-quick.rpy"
if exist "%quickfile%" (
del "%quickfile%"
)
echo init 999 python:>> "%quickfile%"
echo try:>> "%quickfile%"
echo config.underlay[0].keymap['quickSave'] = QuickSave()>> "%quickfile%"
echo config.keymap['quickSave'] = '%quicksavekey%'>> "%quickfile%"
echo config.underlay[0].keymap['quickLoad'] = QuickLoad()>> "%quickfile%"
echo config.keymap['quickLoad'] = '%quickloadkey%'>> "%quickfile%"
echo except:>> "%quickfile%"
echo pass>> "%quickfile%"
echo Default hotkeys:
echo + Quick Save: F5
echo + Quick Load: F9
if not "%option%" == "9" goto :finish
REM --------------------------------------------------------------------------------
REM Drop our skip file into the game folder
REM --------------------------------------------------------------------------------
:skip
echo/
echo Creating skip file...
set "skipfile=%gamedir%unren-skip.rpy"
if exist "%skipfile%" (
del "%skipfile%"
)
echo init 999 python:>> "%skipfile%"
echo _preferences.skip_unseen = True>> "%skipfile%"
echo renpy.game.preferences.skip_unseen = True>> "%skipfile%"
echo renpy.config.allow_skipping = True>> "%skipfile%"
echo renpy.config.fast_skipping = True>> "%skipfile%"
echo + You can now skip all text using TAB and CTRL keys
if not "%option%" == "9" goto :finish
REM --------------------------------------------------------------------------------
REM Drop our rollback file into the game folder
REM --------------------------------------------------------------------------------
:rollback
echo/
echo Creating rollback file...
set "rollbackfile=%gamedir%unren-rollback.rpy"
if exist "%rollbackfile%" (
del "%rollbackfile%"
)
echo init 999 python:>> "%rollbackfile%"
echo renpy.config.rollback_enabled = True>> "%rollbackfile%"
echo renpy.config.hard_rollback_limit = 256>> "%rollbackfile%"
echo renpy.config.rollback_length = 256>> "%rollbackfile%"
echo def unren_noblock( *args, **kwargs ):>> "%rollbackfile%"
echo return>> "%rollbackfile%"
echo renpy.block_rollback = unren_noblock>> "%rollbackfile%"
echo try:>> "%rollbackfile%"
echo config.keymap['rollback'] = [ 'K_PAGEUP', 'repeat_K_PAGEUP', 'K_AC_BACK', 'mousedown_4' ]>> "%rollbackfile%"
echo except:>> "%rollbackfile%"
echo pass>> "%rollbackfile%"
echo + You can now rollback using the scrollwheel
REM --------------------------------------------------------------------------------
REM We are done
REM --------------------------------------------------------------------------------
:finish
echo ----------------------------------------------------
echo/
echo Finished!
echo/
echo Enter "1" to go back to the menu, or any other
set /p exitoption=. key to exit:
echo/
echo ----------------------------------------------------
if "%exitoption%"=="1" goto menu
exit 0
REM --------------------------------------------------------------------------------
REM Bad end
REM --------------------------------------------------------------------------------
:error
echo/
echo Terminating.
echo If a reason was stated correct the problem, if not check path
echo and script for possible issues.
echo/
pause>nul|set/p=. Press any key to exit...
exit 1