Skip to content

Commit

Permalink
TSA: ANM: Always dump sprite boundaries if we have data, to support T…
Browse files Browse the repository at this point in the history
…H06. [V]

Funded by GhostPhanom.
  • Loading branch information
nmlgc committed Sep 27, 2018
1 parent ca43a72 commit a3248f4
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
12 changes: 7 additions & 5 deletions thcrap_tsa/src/anm.cpp
Expand Up @@ -342,7 +342,7 @@ int sprite_split_y(anm_entry_t &entry, sprite_local_t *sprite)
entry.sprite_num = header->sprites; \
entry.name = (const char*)(header->nameoffset + (size_t)header); \
thtxoffset = header->thtxoffset; \
hasdata = header->hasdata; \
entry.hasdata = (header->hasdata != 0); \
headersize = sizeof(type);

int anm_entry_init(anm_entry_t &entry, BYTE *in)
Expand All @@ -352,7 +352,6 @@ int anm_entry_init(anm_entry_t &entry, BYTE *in)
}

size_t thtxoffset = 0;
size_t hasdata = 0;
size_t headersize = 0;

anm_entry_clear(entry);
Expand All @@ -364,17 +363,20 @@ int anm_entry_init(anm_entry_t &entry, BYTE *in)
ANM_ENTRY_FILTER(in, anm_header06_t);
}

assert((hasdata == 0) == (thtxoffset == 0));
assert((entry.hasdata == false) == (thtxoffset == 0));
assert(headersize);

if(hasdata && thtxoffset) {
entry.hasdata |= (entry.name[0] != '@');
if(thtxoffset) {
entry.thtx = (thtx_header_t*)(thtxoffset + (size_t)in);
if(memcmp(entry.thtx->magic, "THTX", sizeof(entry.thtx->magic))) {
return 1;
}
entry.w = entry.thtx->w;
entry.h = entry.thtx->h;
}

if(entry.hasdata) {
// This will change with splits being appended...
size_t sprite_orig_num = entry.sprite_num;
size_t i;
Expand Down Expand Up @@ -532,7 +534,7 @@ int patch_anm(void *file_inout, size_t size_out, size_t size_in, const char *fn,
log_printf("Corrupt ANM file or format definition, aborting ...\n");
break;
}
if(entry.thtx) {
if(entry.hasdata) {
if(!name_prev || strcmp(entry.name, name_prev)) {
if(!json_is_false(dat_dump)) {
bounds_store(name_prev, bounds);
Expand Down
3 changes: 3 additions & 0 deletions thcrap_tsa/src/anm.hpp
Expand Up @@ -37,6 +37,9 @@ typedef struct {
png_uint_32 w;
png_uint_32 h;

// Relevant for TH06 which doesn't use THTX.
bool hasdata;

// Offset to the next entry in the ANM archive. 0 indicates the last one.
size_t nextoffset;

Expand Down

0 comments on commit a3248f4

Please sign in to comment.