diff options
author | Rangi <remy.oukaour+rangi42@gmail.com> | 2020-06-29 12:26:45 -0400 |
---|---|---|
committer | Rangi <remy.oukaour+rangi42@gmail.com> | 2020-06-29 12:26:45 -0400 |
commit | c8346c0bf99aaef85757bae09311661d06d801c4 (patch) | |
tree | 7c32be6879465b259cdfa92acfd5953a8f82c74c | |
parent | 416255bea47756eefb365f32c996100d5c88c9c3 (diff) | |
parent | 9dbe676f445210aaaa6eedcd805cbb65318ac77f (diff) |
Merge branch 'master' of https://github.com/pret/pokegold
-rw-r--r-- | gfx/lz.mk | 3 | ||||
-rw-r--r-- | tools/lz/mpcomp.c | 2 | ||||
-rw-r--r-- | tools/lz/output.c | 12 | ||||
-rw-r--r-- | tools/lz/uncomp.c | 4 |
4 files changed, 15 insertions, 6 deletions
@@ -44,8 +44,9 @@ gfx/tilesets/johto_modern.2bpp.lz: LZFLAGS = --compressor null --method 1 --alig gfx/tilesets/kanto.2bpp.lz: LZFLAGS = --compressor null --method 1 --align 1 gfx/tilesets/mansion.2bpp.lz: LZFLAGS += --method 2 --align 4 gfx/tilesets/mart.2bpp.lz: LZFLAGS += --method 2 --align 4 +gfx/tilesets/players_room.2bpp.lz: LZFLAGS += --method 4 --align 4 gfx/tilesets/radio_tower.2bpp.lz: LZFLAGS += --method 2 --align 4 -gfx/tilesets/ruins_of_alph.2bpp.lz: LZFLAGS += --method 2 --align 4 +gfx/tilesets/ruins_of_alph.2bpp.lz: LZFLAGS += --method 6 --align 4 gfx/tilesets/tower.2bpp.lz: LZFLAGS += --method 2 --align 4 gfx/title/hooh_gold.2bpp.lz: LZFLAGS += --align 3 diff --git a/tools/lz/mpcomp.c b/tools/lz/mpcomp.c index 5961be8e..c8829852 100644 --- a/tools/lz/mpcomp.c +++ b/tools/lz/mpcomp.c @@ -101,7 +101,7 @@ struct command pick_copy_for_pass (const unsigned char * data, const unsigned ch current = buffer + refpos - (length - 3); else current = reference + refpos; - if (memcmp(data + position, current, 4)) continue; + if (memcmp(data + position, current, ((position + 4) > length) ? length - position : 4)) continue; for (count = 4; (count < (length - position)) && (count < (length - refpos)); count ++) if (data[position + count] != current[count]) break; if (count > (length - refpos)) count = length - refpos; if (count > (length - position)) count = length - position; diff --git a/tools/lz/output.c b/tools/lz/output.c index 43e7ba92..484a9516 100644 --- a/tools/lz/output.c +++ b/tools/lz/output.c @@ -28,8 +28,16 @@ void write_commands_and_padding_to_textfile (const char * file, const struct com if (fputs("\tlzend\n", fp) < 0) error_exit(1, "could not write terminator to compressed output"); if (padding_size) { input_stream += padding_offset; - int rv = fprintf(fp, "\tdb $%02hhx", *(input_stream ++)); - while ((rv >= 0) && (-- padding_size)) rv = fprintf(fp, ", $%02hhx", *(input_stream ++)); + int rv = 0; + unsigned pos; + const char * prefix = "\tdb"; + for (pos = 0; (rv >= 0) && (pos < padding_size); pos ++) { + if (input_stream[pos]) + rv = fprintf(fp, "%s $%02hhx", prefix, input_stream[pos]); + else + rv = fprintf(fp, "%s 0", prefix); + prefix = ","; + } if (rv >= 0) rv = -(putc('\n', fp) == EOF); if (rv < 0) error_exit(1, "could not write padding to compressed output"); } diff --git a/tools/lz/uncomp.c b/tools/lz/uncomp.c index 3544cd93..b22fc75f 100644 --- a/tools/lz/uncomp.c +++ b/tools/lz/uncomp.c @@ -49,7 +49,7 @@ struct command * get_commands_from_file (const unsigned char * data, unsigned sh } if (slack) *slack = *size - (rp - data); *size = current - result; - return realloc(result, *size * sizeof(struct command)); + return realloc(result, (*size ? *size : 1) * sizeof(struct command)); error: free(result); return NULL; @@ -88,5 +88,5 @@ unsigned char * get_uncompressed_data (const struct command * commands, const un } } *size = current - result; - return result; + return realloc(result, *size ? *size : 1); } |