From e6f1a9d26921a071acd732a3aa8eb0ecb3636848 Mon Sep 17 00:00:00 2001 From: Weigo <37270925+weigo87@users.noreply.github.com> Date: Fri, 10 Jan 2025 05:57:42 +0100 Subject: [PATCH] compressed bif check --- bggo/bggo.tp2 | 1 + bggo/lib/a7_area_references.tpa | 130 ++++++++++++++++++++++++++++++++ bggo/lib/macros.tpa | 23 +++++- 3 files changed, 153 insertions(+), 1 deletion(-) create mode 100644 bggo/lib/a7_area_references.tpa diff --git a/bggo/bggo.tp2 b/bggo/bggo.tp2 index 51abe53..e65fbaf 100644 --- a/bggo/bggo.tp2 +++ b/bggo/bggo.tp2 @@ -14,6 +14,7 @@ ALWAYS INCLUDE ~%MOD_FOLDER%/lib/alter_searchmap.tpa~ INCLUDE ~%MOD_FOLDER%/lib/debug.tpa~ INCLUDE ~%MOD_FOLDER%/lib/a7_pvrz_tis.tpa~ + INCLUDE ~%MOD_FOLDER%/lib/a7_area_references.tpa~ ACTION_IF GAME_IS ~eet bgee bg2ee~ BEGIN OUTER_SPRINT ee ~ee~ diff --git a/bggo/lib/a7_area_references.tpa b/bggo/lib/a7_area_references.tpa new file mode 100644 index 0000000..a04fc74 --- /dev/null +++ b/bggo/lib/a7_area_references.tpa @@ -0,0 +1,130 @@ +/** + * This function scans ARE resources of the game to find referenced game files. + * + * INT_VAR compressed_only Whether only resources in compressed BIFF archives should be returned. Default: 1 + * INT_VAR bmp Whether to consider BMP resources in the scan. Default: 0 + * INT_VAR mos Whether to consider MOS resources in the scan. Default: 0 + * INT_VAR tis Whether to consider TIS resources in the scan. Default: 0 + * INT_VAR wav Whether to consider WAV resources in the scan. Default: 0 + * INT_VAR wed Whether to consider WED resources in the scan. Default: 0 + * STR_VAR are_regexp File name pattern as regular expression to filter ARE resources. + * The pattern should always end with "\.are$" to match ARE resources. + * Default: "^.+\.are$" + * RET_ARRAY resources Associative array with the referenced game resources. + * (key: resource name, value: reference count) + */ +DEFINE_ACTION_FUNCTION a7#get_are_resources +INT_VAR + compressed_only = 1 + bmp = 0 + mos = 0 + tis = 0 + wav = 0 + wed = 0 +STR_VAR + are_regexp = "^.+\.are$" +RET_ARRAY + resources +BEGIN + ACTION_IF (~%are_regexp%~ STR_EQ ~~) BEGIN + OUTER_SPRINT are_regexp ~^.+\.are$~ + END + + COPY_EXISTING_REGEXP ~%are_regexp%~ ~override~ + READ_ASCII 0x00 sig (8) + PATCH_IF (~%sig%~ STR_EQ ~AREAV1.0~) BEGIN + // bmp + PATCH_IF (bmp) BEGIN + PATCH_FOR_EACH suffix IN ~HT~ ~LM~ ~LN~ ~SR~ BEGIN + LPF a7#add_if_compressed INT_VAR compressed_only STR_VAR resref = EVAL ~%SOURCE_RES%%suffix%~ ext = ~BMP~ RET_ARRAY resources END + END + END + + // mos + PATCH_IF (mos) BEGIN + PATCH_FOR_EACH suffix IN ~~ ~N~ BEGIN + LPF a7#add_if_compressed INT_VAR compressed_only STR_VAR resref = EVAL ~%SOURCE_RES%%suffix%~ ext = ~MOS~ RET_ARRAY resources END + END + END + + PATCH_IF (wed || tis) BEGIN + READ_ASCII 0x08 resref (8) NULL + // wed + PATCH_IF (wed) BEGIN + LPF a7#add_if_compressed INT_VAR compressed_only STR_VAR resref ext = ~WED~ RET_ARRAY resources END + END + + // tis + PATCH_IF (tis) BEGIN + INNER_ACTION BEGIN + COPY_EXISTING ~%resref%.WED~ ~override~ + READ_ASCII 0x00 sig (8) + PATCH_IF (~%sig%~ STR_EQ ~WED V1.3~) BEGIN + READ_LONG 0x08 num_ovl + READ_LONG 0x10 ofs_ovl + FOR (i = 0; i < num_ovl; ++i) BEGIN + SET cur_ofs = ofs_ovl + i * 0x18 + READ_ASCII (cur_ofs + 0x04) resref (8) NULL + LPF a7#add_if_compressed INT_VAR compressed_only STR_VAR resref ext = ~TIS~ RET_ARRAY resources END + END + END + BUT_ONLY IF_EXISTS + END + END + END + + // ambient sounds (wav) + PATCH_IF (wav) BEGIN + READ_SHORT 0x82 num_ambients + READ_LONG 0x84 ofs_ambients + FOR (i = 0; i < num_ambients; ++i) BEGIN + SET cur_ofs = ofs_ambients + i * 0xd4 + READ_SHORT (cur_ofs + 0x80) num_sounds + SET num_sounds = (num_sounds > 10) ? 10 : num_sounds + FOR (j = 0; j < num_sounds; ++j) BEGIN + READ_ASCII (cur_ofs + 0x30 + j * 8) resref (8) NULL + LPF a7#add_if_compressed INT_VAR compressed_only STR_VAR resref ext = ~WAV~ RET_ARRAY resources END + END + END + END + + END ELSE BEGIN + PATCH_WARN ~WARNING: a7#get_are_resources: Not an area file: %SOURCE_FILE%~ + END + BUT_ONLY IF_EXISTS +END + + +/** + *Adds the specified resource to the "resources" array if it's located in a compressed BIFF archive. + * + * INT_VAR compressed_only Whether only resources in compressed BIFF archives should be returned. Default: 1 + * STR_VAR resref Resref of the resource. + * STR_VAR ext File extension of the resource. + * RET_ARRAY resources Array entry with the resource if all conditions are met. + */ +DEFINE_PATCH_FUNCTION a7#add_if_compressed +INT_VAR + compressed_only = 1 +STR_VAR + resref = ~~ + ext = ~~ +RET_ARRAY + resources +BEGIN + SPRINT resource ~%resref%.%ext%~ + + SET condition = NOT (~%resref%~ STR_EQ ~~ || ~%ext%~ STR_EQ ~~) + PATCH_IF (condition && compressed_only) BEGIN + SET condition = NOT FILE_EXISTS ~override/%resource%~ && FILE_IS_IN_COMPRESSED_BIFF ~%resource%~ + END + + PATCH_IF (condition) BEGIN + TO_UPPER ~resource~ + PATCH_IF (VARIABLE_IS_SET $resources(~%resource%~)) BEGIN + SET $resources(~%resource%~) = $resources(~%resource%~) + 1 + END ELSE BEGIN + SET $resources(~%resource%~) = 1 + END + END +END diff --git a/bggo/lib/macros.tpa b/bggo/lib/macros.tpa index a770fb7..7723c04 100644 --- a/bggo/lib/macros.tpa +++ b/bggo/lib/macros.tpa @@ -238,9 +238,30 @@ BEGIN END PATCH_IF FILE_EXISTS ~%MOD_FOLDER%/base/are_patch/%are%_are.tpa~ BEGIN // add animation for braziers, candles ... PATCH_INCLUDE ~%MOD_FOLDER%/base/are_patch/%are%_are.tpa~ + END + END + BUT_ONLY + + // Get files from compressed biffs + //code by Argent77 https://github.com/Argent77/A7-BiffedAreasFix + LAF a7#get_are_resources + INT_VAR + compressed_only = 1 + bmp = 1 + mos = 1 + tis = 1 + wav = 1 + wed = 1 + STR_VAR + are_regexp = EVAL "^%are2%\.are$" + RET_ARRAY + resources END + ACTION_PHP_EACH resources AS resource => ref_count BEGIN + PRINT ~Test~ + COPY_EXISTING ~%resource%~ ~override~ IF_EXISTS END - BUT_ONLY + ACTION_CLEAR_ARRAY resources // biff only areas with tis and pvrz files OUTER_SET area_biff = 0