Skip to content

Commit

Permalink
ANM: check for thtk's -u filenames
Browse files Browse the repository at this point in the history
  • Loading branch information
32th-System committed Aug 28, 2023
1 parent ffda608 commit c21e5da
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 16 deletions.
2 changes: 2 additions & 0 deletions thcrap/thcrap.def
Original file line number Diff line number Diff line change
Expand Up @@ -395,6 +395,8 @@ EXPORTS
str_num_base
str_hexdate_format
str_address_value
_asprintf
_vasprintf

; thcrap_update wrapper functions
; -------------------------------
Expand Down
41 changes: 32 additions & 9 deletions thcrap_tsa/src/anm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
#include "thcrap_tsa.h"
#include "anm.hpp"
#include <GdiPlus.h>
#include <filesystem>

/// GDI+
/// ----
Expand Down Expand Up @@ -1141,15 +1142,25 @@ int patch_png_apply(img_patch_t &patch, std::vector<sprite_local_t>& sprites, co
return ret;
}

int stack_game_png_apply(img_patch_t& patch, std::vector<sprite_local_t>& sprites)
int stack_game_png_apply(img_patch_t& patch, std::vector<sprite_local_t>& sprites, const char* anm_fn, size_t entry_num)
{
int ret = -1;
stack_chain_iterate_t sci;
sci.fn = NULL;
ret = 0;
if(char** chain = resolve_chain_game(patch.name);
chain && chain[0])
{
std::filesystem::path img_path(patch.name);
std::filesystem::path anm_path(anm_fn);

char* thtk_fn = nullptr;
_asprintf(&thtk_fn, "%s/%s@%s@%d%s",
img_path.parent_path().u8string().c_str(),
img_path.stem().u8string().c_str(),
anm_path.stem().u8string().c_str(),
entry_num,
img_path.extension().u8string().c_str()
);
defer(SAFE_FREE(thtk_fn));

int ret = 0;
auto iterate_png = [&](char** chain) {
stack_chain_iterate_t sci;
sci.fn = NULL;
log_printf("(PNG) Resolving %s... ", chain[0]);
while (stack_chain_iterate(&sci, chain, SCI_FORWARDS)) {
if (!patch_png_apply(patch, sprites, sci.patch_info, sci.fn)) {
Expand All @@ -1158,7 +1169,16 @@ int stack_game_png_apply(img_patch_t& patch, std::vector<sprite_local_t>& sprite
}
log_print(ret ? "\n" : "not found\n");
chain_free(chain);
};

if (thtk_fn) {
iterate_png(resolve_chain_game(thtk_fn));
if (ret) {
return ret;
}
}

iterate_png(resolve_chain_game(patch.name));
return ret;
}

Expand Down Expand Up @@ -1232,6 +1252,7 @@ int patch_anm(void *file_inout, size_t size_out, size_t size_in, const char *fn,
anm_entry_t entry = {};
png_image_ex png = {};
png_image_ex bounds = {};
size_t entry_num = 0;

auto* file_in = (uint8_t*)malloc(size_in);
auto* anm_entry_in = file_in;
Expand Down Expand Up @@ -1270,7 +1291,7 @@ int patch_anm(void *file_inout, size_t size_out, size_t size_in, const char *fn,
thtx_header_t* thtx_in = (thtx_header_t*)(anm_entry_in + entry.thtxoffset);

img_patch_t img_patch = img_get_patch(entry, thtx_in);
stack_game_png_apply(img_patch, entry.sprites);
stack_game_png_apply(img_patch, entry.sprites, fn, entry_num);
img_encode(img_patch);

thtx_header_t* thtx_out = (thtx_header_t*)(anm_entry_out + entry.thtxoffset);
Expand Down Expand Up @@ -1299,6 +1320,8 @@ int patch_anm(void *file_inout, size_t size_out, size_t size_in, const char *fn,
}
anm_entry_in = entry.next;
anm_entry_clear(entry);

entry_num++;
}
png_image_clear(bounds);
png_image_clear(png);
Expand Down
2 changes: 1 addition & 1 deletion thcrap_tsa/src/anm.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -353,7 +353,7 @@ int sprite_patch(const sprite_patch_t &sp);
// Walks through the patch stack and patches every game-local PNG file called
// [entry->name] onto the THTX texture [entry->thtx] on sprite level, using
// the coordinates in [entry->sprites].
int stack_game_png_apply(img_patch_t& patch, std::vector<sprite_local_t>& sprites);
int stack_game_png_apply(img_patch_t& patch, std::vector<sprite_local_t>& sprites, const char* anm_fn, size_t entry_num);
/// ---------------------

/// Sprite boundary dumping
Expand Down
6 changes: 0 additions & 6 deletions thcrap_tsa/thcrap_tsa.def
Original file line number Diff line number Diff line change
Expand Up @@ -61,12 +61,6 @@ EXPORTS
BP_th185_spell_name
spells_mod_init

; Dialog
; ------
patch_msg
patch_msg_dlg
patch_msg_end

; Mission
; -------
BP_mission
Expand Down

0 comments on commit c21e5da

Please # to comment.