From 201a20a57b64d067af9293c19e15281260de92f5 Mon Sep 17 00:00:00 2001 From: MD Holland <45853441+z64me@users.noreply.github.com> Date: Mon, 27 Nov 2023 14:20:32 -0500 Subject: [PATCH 1/6] system(): allow win32 paths on linux builds --- src/wow.h | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/src/wow.h b/src/wow.h index 8fbdc90..7df4d65 100644 --- a/src/wow.h +++ b/src/wow.h @@ -580,7 +580,28 @@ wow_system(char const *path) return rval; #else /* not win32 unicode */ + #ifdef _WIN32 return system(path); + #else + // allow win32 paths on linux builds + if (strchr(path, '\\')) + { + char *tmp = strdup(path); + int rval; + + for (char *c = tmp; *c; ++c) + if (*c == '\\') + *c = '/'; + + rval = system(tmp); + free(tmp); + return rval; + } + else + { + return system(path); + } + #endif #endif } From bfb1a484ee449d8076a481e1ade876363d0fb037 Mon Sep 17 00:00:00 2001 From: MD Holland <45853441+z64me@users.noreply.github.com> Date: Fri, 8 Dec 2023 20:04:52 -0500 Subject: [PATCH 2/6] new function: sha1(data, sz) also updated version number from v1.0.5 to v1.0.6 --- src/sha1.h | 2 ++ src/xc.c | 17 ++++++++++++++++- 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/src/sha1.h b/src/sha1.h index 184eb88..68cccdc 100644 --- a/src/sha1.h +++ b/src/sha1.h @@ -52,6 +52,7 @@ static void stb__sha1(stb_uchar *chunk, stb_uint h[5]) h[4] += e; } +static void stb_sha1(stb_uchar output[20], stb_uchar *buffer, stb_uint len) { unsigned char final_block[128]; @@ -119,6 +120,7 @@ void stb_sha1(stb_uchar output[20], stb_uchar *buffer, stb_uint len) } // client can truncate this wherever they like +static void stb_sha1_readable(char display[30], unsigned char sha[20]) { char encoding[65] = "0123456789abcdefghijklmnopqrstuv" diff --git a/src/xc.c b/src/xc.c index 4af5407..5014cbd 100644 --- a/src/xc.c +++ b/src/xc.c @@ -17,6 +17,7 @@ #include "zzrtl.h" #include "preproc.h" #include "rnd.h" /* rnd_pcg */ +#include "sha1.h" #undef fopen #undef fread @@ -227,7 +228,7 @@ zzrtl(void) fprintf( stderr, "/*************************\n" - " * zzrtl v1.0.5 <z64.me> *\n" + " * zzrtl v1.0.6 <z64.me> *\n" " *************************/\n" ); fprintf( @@ -432,6 +433,7 @@ SCAT,SCMP,SCCM,EXIT , ZZXC_string_list_file , ZZXC_loadfile , ZZXC_tsv_col_row + , ZZXC_sha1 /* directory */ , ZZXC_DIR_EXISTS , ZZXC_DIR_ENTER @@ -541,6 +543,7 @@ SCAT,SCMP,SCCM,EXIT " string_list_file " \ " loadfile " \ " tsv_col_row " \ +" sha1 " \ /* directory */ \ " dir_exists " \ " dir_enter " \ @@ -2518,6 +2521,18 @@ ZZXC_FUNC_INST_STR[op * 5] { ax = (int)tsv_col_row((void *)sp[2], (char *)sp[1], *sp); } + + /* get sha1 checksum of a buffer */ + else if (op == ZZXC_sha1) + { + unsigned char checksum[64]; + char readable[64]; + + stb_sha1(checksum, (stb_uchar *)sp[1], *sp); + stb_sha1_readable(readable, checksum); + + ax = (int)strdup(readable); + } /* directory */ else if (op == ZZXC_DIR_EXISTS) From f3df21ba976ce11630581cc938fbe38bc51bcd8f Mon Sep 17 00:00:00 2001 From: MD Holland <45853441+z64me@users.noreply.github.com> Date: Wed, 10 Jan 2024 01:41:23 -0500 Subject: [PATCH 3/6] loadfile: allow glob like loadfile("*.zscene") --- src/zzrtl.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/zzrtl.c b/src/zzrtl.c index b58c822..c2fc608 100644 --- a/src/zzrtl.c +++ b/src/zzrtl.c @@ -1894,6 +1894,9 @@ loadfile(char *fn, int *sz, int optional) if (!fn) die_i("loadfile no filename given"); + /* if fn starts with '*', grab by extension */ + fn = find_extension(fn, 0); + data = file_load(fn, &Nsz, 16); if (!data && !optional) die_i("loadfile failed to load '%s'", fn); From f31cb0e7fc5d107db60b4890ffd076ec6bb47c72 Mon Sep 17 00:00:00 2001 From: MD Holland <45853441+z64me@users.noreply.github.com> Date: Sat, 17 Feb 2024 14:00:31 -0500 Subject: [PATCH 4/6] push old sha1/realloc changes Not thoroughly tested so these features are not recommended for production use, but pushing these changes just in case. --- src/xc.c | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/src/xc.c b/src/xc.c index 5014cbd..cb5fda8 100644 --- a/src/xc.c +++ b/src/xc.c @@ -434,6 +434,7 @@ SCAT,SCMP,SCCM,EXIT , ZZXC_loadfile , ZZXC_tsv_col_row , ZZXC_sha1 + , ZZXC_realloc /* directory */ , ZZXC_DIR_EXISTS , ZZXC_DIR_ENTER @@ -544,6 +545,7 @@ SCAT,SCMP,SCCM,EXIT " loadfile " \ " tsv_col_row " \ " sha1 " \ +" realloc " \ /* directory */ \ " dir_exists " \ " dir_enter " \ @@ -650,6 +652,8 @@ SCAT,SCMP,SCCM,EXIT ",FSTR" /* string_list_file */ \ ",LFIL" /* loadfile */ \ ",TVCR" /* tsv_col_row */ \ + ",SHA1" /* sha1 */ \ + ",RALC" /* realloc */ \ /* directory */ \ ",DRXS" /* dir_exists */ \ ",DREN" /* dir_enter */ \ @@ -2533,6 +2537,21 @@ ZZXC_FUNC_INST_STR[op * 5] ax = (int)strdup(readable); } + + /* load a file */ + else if (op == ZZXC_realloc) + { + void *src = (void*)sp[1]; + int len = (REGXC_INT)*sp; + void *result = realloc(src, len); + + //fprintf(stderr, "realloc %p %p\n", src, len); + + ax = (int)result; + + if (!result) + die("[!] realloc memory error"); + } /* directory */ else if (op == ZZXC_DIR_EXISTS) From b71336d910fb0949ba2cfe32b65abcecf301ceb3 Mon Sep 17 00:00:00 2001 From: z64me <45853441+z64me@users.noreply.github.com> Date: Mon, 30 Sep 2024 12:48:55 -0400 Subject: [PATCH 5/6] fix compression oversight on moved files, more verbose output This commit fixes a compression oversight pertaining to uncompressed (but relocated) files running past the filesize limit set by the user (cases where Pend = 0 but Pstart + Psize > compsz). Also made the output more verbose so it reports exactly how many bytes of overflow are present. --- src/zzrtl.c | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/src/zzrtl.c b/src/zzrtl.c index c2fc608..c2b1fa7 100644 --- a/src/zzrtl.c +++ b/src/zzrtl.c @@ -2566,6 +2566,7 @@ rom_compress(struct rom *rom, char *enc, int mb) int i; float total_compressed = 0; float total_decompressed = 0; + const float toMib = 1.0 / (1024 * 1024); struct compThread *compThread = 0; int numThread = 4; /* TODO make this external */ @@ -2926,8 +2927,8 @@ rom_compress(struct rom *rom, char *enc, int mb) #endif // fprintf(stdout, "%08X: %08X %08X\n", dma - rom->dma, dma->Pstart, dma->Pend); // fprintf(stdout, "%08X: %08X %08X %08X\n", dma - rom->dma, dma->start, dma->Pstart, dma->Pend); - if (dma->Pend > compsz) - die_i("i ran out of compressed rom space"); + if (comp_total > compsz) + continue; /* external cached file logic */ if (g_use_cache) @@ -2944,6 +2945,16 @@ rom_compress(struct rom *rom, char *enc, int mb) memcpy(dst, dma->compbuf, dma->compSz); } } + + if (comp_total > compsz) + die_i( + "ran out of compressed rom space\n" + "(have: %.2f mib, need: %.2f mib)\n" + "(0x%X bytes over limit)" + , compsz * toMib, comp_total * toMib + , comp_total - compsz + ); + fprintf(stderr, "success!\n"); fprintf( From 6aedb0c37fa9d7b701424fcf5a07dac660f30198 Mon Sep 17 00:00:00 2001 From: z64me <45853441+z64me@users.noreply.github.com> Date: Mon, 30 Sep 2024 12:57:01 -0400 Subject: [PATCH 6/6] update compiler paths in win32 build script No longer using hardcoded paths --- release-win32.sh | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/release-win32.sh b/release-win32.sh index f6a2b68..02ebe46 100755 --- a/release-win32.sh +++ b/release-win32.sh @@ -2,15 +2,15 @@ mkdir -p o # build compression functions (slow) -~/c/mxe/usr/bin/i686-w64-mingw32.static-gcc -c -DNDEBUG -s -Ofast -flto -lm -Wall src/enc/*.c src/enc/lzo/*.c src/enc/ucl/comp/*.c src/enc/apultra/*.c +i686-w64-mingw32.static-gcc -c -DNDEBUG -s -Ofast -flto -lm -Wall src/enc/*.c src/enc/lzo/*.c src/enc/ucl/comp/*.c src/enc/apultra/*.c mv *.o o # build stb functions (slow) -~/c/mxe/usr/bin/i686-w64-mingw32.static-gcc -c -DNDEBUG src/stb/*.c -Wall -lm -s -Os -flto -lpthread -Wno-unused-function -Wno-unused-variable +i686-w64-mingw32.static-gcc -c -DNDEBUG src/stb/*.c -Wall -lm -s -Os -flto -lpthread -Wno-unused-function -Wno-unused-variable mv *.o o # build everything else -~/c/mxe/usr/bin/i686-w64-mingw32.static-gcc -o zzrtl.exe -DNDEBUG src/*.c o/*.o -Wall -lm -s -Os -flto -lpthread -Wno-unused-function -Wno-unused-variable +i686-w64-mingw32.static-gcc -o zzrtl.exe -DNDEBUG src/*.c o/*.o -Wall -lm -s -Os -flto -lpthread -Wno-unused-function -Wno-unused-variable # move to bin directory mkdir -p bin/win32