33 * Note: Requires WeiDU v239 or later! *
44 * *
55 * Author: Argent77 *
6- * Version: 1.2 *
6+ * Version: 1.3 *
77 *******************************************************************************************************/
88
99/*
1010 * Overview of functions provided by this library:
1111 *
12+ * Action function: HANDLE_TIS2OVL
13+ * Executes "tis2ovl" to convert TIS overlays between classic BG2 and Enhanced Edition game formats.
14+ * Note: Requires WeiDU v239 or later!
15+ *
16+ * Parameters:
17+ * INT_VAR silent Set to zero to show visual feedback during conversion. (Default: 1)
18+ * INT_VAR to_ee Set to non-zero to convert tilesets from classic BG2 format to Enhanced Edition game format. (Default: autodetect)
19+ * INT_VAR to_classic Set to non-zero to convert tilesets from Enhanced Edition game format to classic BG2 format. (Default: autodetect)
20+ * INT_VAR exec_type Specify when to execute the command. (Default: 0)
21+ * Supported values: 0 = AT_NOW, 1 = AT_EXIT, 2 = AT_UNINSTALL,
22+ * 3 = AT_INTERACTIVE_NOW, 4 = AT_INTERACTIVE_EXIT, 5 = AT_INTERACTIVE_UNINSTALL
23+ * STR_VAR input_path (mandatory) Path to a single WED input file or the directory containing WED files to convert.
24+ * Note: You can specify multiple input paths by appending an underscore and an ascending number starting at 0
25+ * to the parameter name, e.g. input_path_0, input_path_1, ...
26+ * STR_VAR search_path Search path for TIS files. (Default: "override" folder of the game)
27+ * Note: You can specify multiple search paths by appending an underscore and an ascending number starting at 0
28+ * to the parameter name, e.g. search_path_0, search_path_1, ...
29+ * STR_VAR output_path Output directory for TIS files. (Default: overwrite input TIS files)
30+ * STR_VAR tis2ovl_path Full path to the "tis2ovl" binary.
31+ * Default: Attempts to find the the tool binary in "%MOD_FOLDER%/tools/tis2ovl/", "%input_path%/tis2ovl/" or
32+ * "%output_path%/tis2ovl/" if not specified. (See default folder structure of GET_TOOL_BINARY below for more information.)
33+ * RET num_converted Returns the number of successfully converted TIS files.
34+ *
35+ *
1236 * Action function: HANDLE_TILE2EE
1337 * Executes "tile2ee" to convert MOS/TIS between palette-based (V1) and pvrz-based (V2) formats.
1438 * Note: Requires WeiDU v239 or later!
2751 * 3 = AT_INTERACTIVE_NOW, 4 = AT_INTERACTIVE_EXIT, 5 = AT_INTERACTIVE_UNINSTALL
2852 * STR_VAR input_path (mandatory) Path to a single MOS/TIS input file or the directory containing MOS or TIS files to convert.
2953 * STR_VAR tile2ee_path Full path to the "tile2ee" binary.
30- * Default: Attempts to find the the tool binary in "%MOD_FOLDER%/tools/tile2ee/", "%input_path%/tile2ee/" or
54+ * Default: Attempts to find the the tool binary in "%MOD_FOLDER%/tools/tile2ee/", "%input_path%/tile2ee/" or
3155 * "%output_path%/tile2ee/" if not specified. (See default folder structure of GET_TOOL_BINARY below for more information.)
3256 * STR_VAR output_path Output path for converted MOS and TIS files. (Default: override)
3357 * RET num_converted Returns the number of successfully converted MOS and TIS files (not counting PVRZ files generated in the process).
4973 * 3 = AT_INTERACTIVE_NOW, 4 = AT_INTERACTIVE_EXIT, 5 = AT_INTERACTIVE_UNINSTALL
5074 * STR_VAR input_path (mandatory) Path to a single MBC/TBC input file or the directory containing MBC or TBC files to decode.
5175 * STR_VAR tileconv_path Full path to the "tileconv" binary.
52- * Default: Attempts to find the the tool binary in "%MOD_FOLDER%/tools/tileconv/", "%input_path%/tileconv/" or
76+ * Default: Attempts to find the the tool binary in "%MOD_FOLDER%/tools/tileconv/", "%input_path%/tileconv/" or
5377 * "%output_path%/tileconv/" if not specified. (See default folder structure of GET_TOOL_BINARY below for more information.)
5478 * STR_VAR output_path Output path for MOS/TIS files. (Default: override)
5579 * RET num_converted Returns the number of successfully converted files.
6589 * STR_VAR tool_binary (mandatory) The full path to the tool binary.
6690 * STR_VAR arg_0, arg_1, ... Variable number of arguments for the specified tool. Use arg_0, arg_1, ...
6791 * RET command Returns the fully assembled command.
92+ * RET result Contains the return value of the executed tool if the function was called with exec_type set to 0 or 3.
6893 *
6994 *
7095 * Action function: FIND_TOOL_BINARY
107132 *
108133 *
109134 * Changelog:
135+ * v1.3:
136+ * - Added action function HANDLE_TIS2OVL for dealing with tis2ovl.
137+ *
110138 * v1.2:
111139 * - Fixed a bug that could fail HANDLE_TILECONV and HANDLE_TILE2EE with large output files.
140+ * - Improved action function GET_TOOL_BINARY.
112141 *
113142 * v1.1:
114143 * - Added support for converting single input file in HANDLE_TILECONV and HANDLE_TILE2EE.
@@ -169,7 +198,7 @@ echo %a7arch%>override/a7arch.txt
169198 DEFAULT
170199 END
171200
172- ACTION_IF (~%SYSTEM_ARCH%~ STRING_EQUAL ~~) BEGIN
201+ ACTION_IF (~%SYSTEM_ARCH%~ STR_EQ ~~) BEGIN
173202 OUTER_TEXT_SPRINT SYSTEM_ARCH ~%WEIDU_ARCH%~
174203 END
175204END
@@ -197,23 +226,23 @@ DEFINE_ACTION_FUNCTION GET_TOOL_BINARY
197226BEGIN
198227 OUTER_TEXT_SPRINT tool_binary ~~
199228
200- ACTION_IF (tool_name STRING_EQUAL ~~) BEGIN
229+ ACTION_IF (tool_name STR_EQ ~~) BEGIN
201230 FAIL ~ERROR: No tool name specified.~
202231 END
203232
204- ACTION_IF (~%WEIDU_OS%~ STRING_EQUAL_CASE ~osx~) BEGIN
233+ ACTION_IF (~%WEIDU_OS%~ STR_EQ ~osx~) BEGIN
205234 OUTER_TEXT_SPRINT SYSTEM_ARCH ~~
206235 END ELSE BEGIN
207236 LAF GET_SYSTEM_ARCH RET SYSTEM_ARCH END
208237 END
209238
210- ACTION_IF (~%WEIDU_OS%~ STRING_EQUAL_CASE ~win32~) BEGIN
239+ ACTION_IF (~%WEIDU_OS%~ STR_EQ ~win32~) BEGIN
211240 OUTER_TEXT_SPRINT tool_name ~%tool_name%.exe~
212241 END
213242
214- ACTION_IF (~%SYSTEM_ARCH%~ STRING_EQUAL_CASE ~amd64~) BEGIN
243+ ACTION_IF (~%SYSTEM_ARCH%~ STR_EQ ~amd64~) BEGIN
215244 OUTER_TEXT_SPRINT tool_binary ~%tool_os_64_path%/%tool_name%~
216- END ELSE ACTION_IF (~%SYSTEM_ARCH%~ STRING_EQUAL_CASE ~x86~) BEGIN
245+ END ELSE ACTION_IF (~%SYSTEM_ARCH%~ STR_EQ ~x86~) BEGIN
217246 OUTER_TEXT_SPRINT tool_binary ~%tool_os_32_path%/%tool_name%~
218247 END
219248
@@ -250,7 +279,7 @@ BEGIN
250279
251280 // 2. Search extra paths if needed
252281 OUTER_SET idx = 0
253- OUTER_WHILE (~%tool_binary%~ STRING_EQUAL ~~) && (VARIABLE_IS_SET EVAL ~path_%idx%~) BEGIN
282+ OUTER_WHILE (~%tool_binary%~ STR_EQ ~~) && (VARIABLE_IS_SET EVAL ~path_%idx%~) BEGIN
254283 OUTER_TEXT_SPRINT path EVAL ~%path_%idx%%~
255284 ACTION_IF (NOT DIRECTORY_EXISTS ~%path%~) BEGIN
256285 LAF DIRECTORY_OF_FILESPEC STR_VAR filespec = EVAL ~%path%~ RET directory END
@@ -278,28 +307,30 @@ DEFINE_ACTION_FUNCTION EXECUTE_TOOL
278307 // arg_0, arg_1, ...
279308 RET
280309 command
310+ result
281311BEGIN
282312 // assembling list of arguments
283313 OUTER_TEXT_SPRINT params ~~
284314 OUTER_FOR (idx = 0; VARIABLE_IS_SET EVAL ~arg_%idx%~; ++idx) BEGIN
285315 OUTER_TEXT_SPRINT param EVAL ~%arg_%idx%%~
286- ACTION_IF (NOT ~%param%~ STRING_EQUAL ~~ &&
287- NOT ~%param%~ STRING_EQUAL ~%arg_%idx%%~) BEGIN
316+ ACTION_IF (NOT ~%param%~ STR_EQ ~~ &&
317+ NOT ~%param%~ STR_EQ ~%arg_%idx%%~) BEGIN
288318 OUTER_TEXT_SPRINT params ~%params% %param%~
289319 END
290320 END
291321
292322 OUTER_TEXT_SPRINT command ~%tool_binary%%params%~
323+ OUTER_SET result = 0
293324
294- ACTION_IF (~%WEIDU_OS%~ STRING_EQUAL_CASE ~osx~ OR
295- ~%WEIDU_OS%~ STRING_EQUAL_CASE ~unix~) BEGIN
325+ ACTION_IF (~%WEIDU_OS%~ STR_EQ ~osx~ OR
326+ ~%WEIDU_OS%~ STR_EQ ~unix~) BEGIN
296327 AT_NOW ~chmod +x %tool_binary%~
297328 END
298329
299- ACTION_IF (exec_type = 0) BEGIN AT_NOW ~%command%~ END
330+ ACTION_IF (exec_type = 0) BEGIN AT_NOW result ~%command%~ END
300331 ELSE ACTION_IF (exec_type = 1) BEGIN AT_EXIT ~%command%~ END
301332 ELSE ACTION_IF (exec_type = 2) BEGIN AT_UNINSTALL ~%command%~ END
302- ELSE ACTION_IF (exec_type = 3) BEGIN AT_INTERACTIVE_NOW ~%command%~ END
333+ ELSE ACTION_IF (exec_type = 3) BEGIN AT_INTERACTIVE_NOW result ~%command%~ END
303334 ELSE ACTION_IF (exec_type = 4) BEGIN AT_INTERACTIVE_EXIT ~%command%~ END
304335 ELSE ACTION_IF (exec_type = 5) BEGIN AT_INTERACTIVE_UNINSTALL ~%command%~ END
305336 ELSE BEGIN FAIL ~ERROR: Invalid execution type specified~ END
@@ -323,7 +354,7 @@ DEFINE_ACTION_FUNCTION HANDLE_TILECONV
323354 num_converted
324355BEGIN
325356 // checking path to tileconv binary
326- ACTION_IF (~%tileconv_path%~ STRING_EQUAL ~~) BEGIN
357+ ACTION_IF (~%tileconv_path%~ STR_EQ ~~) BEGIN
327358 LAF FIND_TOOL_BINARY
328359 STR_VAR
329360 tool_name = ~tileconv~
@@ -332,21 +363,21 @@ BEGIN
332363 RET
333364 tool_binary
334365 END
335- ACTION_IF (~%tool_binary%~ STRING_EQUAL ~~) BEGIN
366+ ACTION_IF (~%tool_binary%~ STR_EQ ~~) BEGIN
336367 FAIL ~ERROR: tileconv not found: "%tileconv_path%"~
337368 END ELSE BEGIN
338369 OUTER_TEXT_SPRINT tileconv_path ~%tool_binary%~
339370 END
340371 END
341372
342373 // don't allow empty input path
343- ACTION_IF (~%input_path%~ STRING_EQUAL ~~) BEGIN OUTER_TEXT_SPRINT input_path ~.~ END
374+ ACTION_IF (~%input_path%~ STR_EQ ~~) BEGIN OUTER_TEXT_SPRINT input_path ~.~ END
344375
345376 // don't allow empty output path
346- ACTION_IF (~%output_path%~ STRING_EQUAL ~~) BEGIN OUTER_TEXT_SPRINT output_path ~.~ END
377+ ACTION_IF (~%output_path%~ STR_EQ ~~) BEGIN OUTER_TEXT_SPRINT output_path ~.~ END
347378
348379 // needed to take care of file paths containing whitespace characters
349- ACTION_IF (~%WEIDU_OS%~ STRING_EQUAL_CASE ~win32~) BEGIN
380+ ACTION_IF (~%WEIDU_OS%~ STR_EQ ~win32~) BEGIN
350381 OUTER_TEXT_SPRINT quote ~"~
351382 END ELSE BEGIN
352383 OUTER_TEXT_SPRINT quote ~'~
@@ -365,15 +396,15 @@ BEGIN
365396 // processing directory content
366397 ACTION_BASH_FOR ~%input_path%~ ~.+\.[mt]bc$~ BEGIN
367398 OUTER_TEXT_SPRINT bc_folder ~%output_path%/%folder_prefix%%BASH_FOR_RES%~
368- ACTION_IF (~%BASH_FOR_EXT%~ STRING_EQUAL_CASE ~tbc~ && convert_tbc) BEGIN
399+ ACTION_IF (~%BASH_FOR_EXT%~ STR_EQ ~tbc~ && convert_tbc) BEGIN
369400 OUTER_TEXT_SPRINT bc_file ~%bc_folder%/%BASH_FOR_RES%.tis~
370- END ELSE ACTION_IF (~%BASH_FOR_EXT%~ STRING_EQUAL_CASE ~mbc~ && convert_mbc) BEGIN
401+ END ELSE ACTION_IF (~%BASH_FOR_EXT%~ STR_EQ ~mbc~ && convert_mbc) BEGIN
371402 OUTER_TEXT_SPRINT bc_file ~%bc_folder%/%BASH_FOR_RES%.mos~
372403 END ELSE BEGIN
373404 OUTER_TEXT_SPRINT bc_file ~~
374405 END
375406
376- ACTION_IF (NOT ~%bc_file%~ STRING_EQUAL_CASE ~~) BEGIN
407+ ACTION_IF (NOT ~%bc_file%~ STR_EQ ~~) BEGIN
377408 MKDIR ~%bc_folder%~
378409 OUTER_TEXT_SPRINT arg_output ~-o %quote%%bc_file%%quote%~
379410 OUTER_TEXT_SPRINT arg_input ~%quote%%BASH_FOR_FILESPEC%%quote%~
@@ -402,9 +433,9 @@ BEGIN
402433 LAF RES_OF_FILESPEC STR_VAR filespec = EVAL ~%input_path%~ RET res END
403434 LAF EXT_OF_FILESPEC STR_VAR filespec = EVAL ~%input_path%~ RET ext END
404435 OUTER_TEXT_SPRINT bc_folder ~%output_path%/%folder_prefix%%res%~
405- ACTION_IF (~%ext%~ STRING_EQUAL_CASE ~tbc~) BEGIN
436+ ACTION_IF (~%ext%~ STR_EQ ~tbc~) BEGIN
406437 OUTER_TEXT_SPRINT bc_file ~%bc_folder%/%res%.tis~
407- END ELSE ACTION_IF (~%ext%~ STRING_EQUAL_CASE ~mbc~) BEGIN
438+ END ELSE ACTION_IF (~%ext%~ STR_EQ ~mbc~) BEGIN
408439 OUTER_TEXT_SPRINT bc_file ~%bc_folder%/%res%.mos~
409440 END ELSE BEGIN
410441 FAIL ~ERROR: Unsupported source file extension: %ext%~
@@ -455,7 +486,7 @@ DEFINE_ACTION_FUNCTION HANDLE_TILE2EE
455486 num_converted
456487BEGIN
457488 // checking path to tile2ee binary
458- ACTION_IF (~%tile2ee_path%~ STRING_EQUAL ~~) BEGIN
489+ ACTION_IF (~%tile2ee_path%~ STR_EQ ~~) BEGIN
459490 LAF FIND_TOOL_BINARY
460491 STR_VAR
461492 tool_name = ~tile2ee~
@@ -464,21 +495,21 @@ BEGIN
464495 RET
465496 tool_binary
466497 END
467- ACTION_IF (~%tool_binary%~ STRING_EQUAL ~~) BEGIN
498+ ACTION_IF (~%tool_binary%~ STR_EQ ~~) BEGIN
468499 FAIL ~ERROR: tile2ee not found: "%tile2ee_path%"~
469500 END ELSE BEGIN
470501 OUTER_TEXT_SPRINT tile2ee_path ~%tool_binary%~
471502 END
472503 END
473504
474505 // don't allow empty input path
475- ACTION_IF (~%input_path%~ STRING_EQUAL ~~) BEGIN OUTER_TEXT_SPRINT input_path ~.~ END
506+ ACTION_IF (~%input_path%~ STR_EQ ~~) BEGIN OUTER_TEXT_SPRINT input_path ~.~ END
476507
477508 // don't allow empty output path
478- ACTION_IF (~%output_path%~ STRING_EQUAL ~~) BEGIN OUTER_TEXT_SPRINT output_path ~.~ END
509+ ACTION_IF (~%output_path%~ STR_EQ ~~) BEGIN OUTER_TEXT_SPRINT output_path ~.~ END
479510
480511 // needed to take care of file paths containing whitespace characters
481- ACTION_IF (~%WEIDU_OS%~ STRING_EQUAL_CASE ~win32~) BEGIN
512+ ACTION_IF (~%WEIDU_OS%~ STR_EQ ~win32~) BEGIN
482513 OUTER_TEXT_SPRINT quote ~"~
483514 END ELSE BEGIN
484515 OUTER_TEXT_SPRINT quote ~'~
@@ -547,7 +578,7 @@ BEGIN
547578 OUTER_PATCH_SAVE cur_index ~%BASH_FOR_RES%~ BEGIN
548579 REPLACE_TEXTUALLY CASE_INSENSITIVE EVALUATE_REGEXP ~^mos0*~ ~~
549580 END
550- ACTION_IF (~%cur_index%~ STRING_EQUAL ~~) BEGIN OUTER_SET cur_index = 0 END
581+ ACTION_IF (~%cur_index%~ STR_EQ ~~) BEGIN OUTER_SET cur_index = 0 END
551582 ACTION_IF (cur_index >= min_pvrz_index) BEGIN
552583 OUTER_SET min_pvrz_index = cur_index + 1
553584 END
@@ -617,3 +648,98 @@ BEGIN
617648 FAIL ~ERROR: Path does not exist: %input_path%~
618649 END
619650END
651+
652+
653+ DEFINE_ACTION_FUNCTION HANDLE_TIS2OVL
654+ INT_VAR
655+ silent = 1
656+ to_ee = 0
657+ to_classic = 0
658+ exec_type = 0
659+ STR_VAR
660+ input_path = ~~
661+ search_path = ~override~
662+ output_path = ~~
663+ tis2ovl_path = ~~
664+ RET
665+ num_converted
666+ BEGIN
667+ // TODO: make function "uninstallable"
668+ OUTER_SET num_converted = 0
669+
670+ // checking path to tis2ovl binary
671+ ACTION_IF (~%tis2ovl_path%~ STR_EQ ~~) BEGIN
672+ LAF FIND_TOOL_BINARY
673+ STR_VAR
674+ tool_name = ~tis2ovl~
675+ path_0 = EVAL ~%search_path%~
676+ path_1 = EVAL ~%output_path%~
677+ RET
678+ tool_binary
679+ END
680+ ACTION_IF (~%tool_binary%~ STR_EQ ~~) BEGIN
681+ FAIL ~ERROR: tis2ovl not found: "%tis2ovl_path%"~
682+ END ELSE BEGIN
683+ OUTER_TEXT_SPRINT tis2ovl_path ~%tool_binary%~
684+ END
685+ END
686+
687+ // needed to take care of file paths containing whitespace characters
688+ ACTION_IF (~%WEIDU_OS%~ STR_EQ ~win32~) BEGIN
689+ OUTER_TEXT_SPRINT quote ~"~
690+ END ELSE BEGIN
691+ OUTER_TEXT_SPRINT quote ~'~
692+ END
693+
694+ // initializing parameters
695+ ACTION_IF (silent) BEGIN OUTER_TEXT_SPRINT arg_silent ~-q~ END ELSE BEGIN OUTER_TEXT_SPRINT arg_silent ~~ END
696+ ACTION_IF (to_ee) BEGIN OUTER_TEXT_SPRINT arg_to_ee ~-c~ END ELSE BEGIN OUTER_TEXT_SPRINT arg_to_ee ~~ END
697+ ACTION_IF (to_classic) BEGIN OUTER_TEXT_SPRINT arg_to_classic ~-e~ END ELSE BEGIN OUTER_TEXT_SPRINT arg_to_classic ~~ END
698+ ACTION_IF (NOT ~%output_path%~ STR_EQ ~~) BEGIN OUTER_TEXT_SPRINT arg_out ~-o %quote%%output_path%%quote%~ END ELSE BEGIN OUTER_TEXT_SPRINT arg_out ~~ END
699+
700+ // setting search paths
701+ OUTER_TEXT_SPRINT arg_search ~~
702+ OUTER_FOR (i = "-1"; i < 0 || VARIABLE_IS_SET EVAL ~search_path_%i%~; ++i) BEGIN
703+ ACTION_IF (i < 0) BEGIN OUTER_TEXT_SPRINT arg ~%search_path%~ END ELSE BEGIN OUTER_TEXT_SPRINT arg EVAL ~%search_path_%i%%~ END
704+ OUTER_PATCH_SAVE arg ~%arg%~ BEGIN REPLACE_TEXTUALLY ~^[ %TAB%]+~ ~~ REPLACE_TEXTUALLY ~[ %TAB%]+$~ ~~ END
705+ ACTION_IF (NOT ~%arg%~ STR_EQ ~~) BEGIN OUTER_TEXT_SPRINT arg_search ~%arg_search% -s %quote%%arg%%quote%~ END
706+ END
707+
708+ // setting input paths
709+ OUTER_SET input_files = 0
710+ OUTER_FOR (i = "-1"; i < 0 || VARIABLE_IS_SET EVAL ~input_path_%i%~; ++i) BEGIN
711+ ACTION_IF (i < 0) BEGIN OUTER_TEXT_SPRINT arg ~%input_path%~ END ELSE BEGIN OUTER_TEXT_SPRINT arg EVAL ~%input_path_%i%%~ END
712+ OUTER_PATCH_SAVE arg ~%arg%~ BEGIN REPLACE_TEXTUALLY ~^[ %TAB%]+~ ~~ REPLACE_TEXTUALLY ~[ %TAB%]+$~ ~~ END
713+ ACTION_IF (NOT ~%arg%~ STR_EQ ~~) BEGIN
714+ ACTION_IF (DIRECTORY_EXISTS ~%arg%~) BEGIN
715+ ACTION_BASH_FOR ~%arg%~ ~.+\.wed$~ BEGIN
716+ OUTER_TEXT_SPRINT $input_files(~%input_files%~) ~%quote%%BASH_FOR_FILESPEC%%quote%~
717+ END
718+ END ELSE BEGIN
719+ OUTER_TEXT_SPRINT $input_files(~%input_files%~) ~%quote%%arg%%quote%~
720+ OUTER_SET input_files += 1
721+ END
722+ END
723+ END
724+
725+ OUTER_FOR (i = 0; i < input_files; ++i) BEGIN
726+ OUTER_TEXT_SPRINT input_file $input_files(~%i%~)
727+ LAF EXECUTE_TOOL
728+ INT_VAR
729+ exec_type
730+ STR_VAR
731+ tool_binary = EVAL ~%tis2ovl_path%~
732+ arg_0 = EVAL ~%arg_silent%~
733+ arg_1 = EVAL ~%arg_to_ee%~
734+ arg_2 = EVAL ~%arg_to_classic%~
735+ arg_3 = EVAL ~%arg_search%~
736+ arg_4 = EVAL ~%arg_out%~
737+ arg_5 = EVAL ~%input_file%~
738+ RET
739+ result
740+ END
741+ ACTION_IF (result = 0) BEGIN
742+ OUTER_SET num_converted += 1
743+ END
744+ END
745+ END
0 commit comments