From b716abeadb1434b602fa28ecd7b853c6875eafbc Mon Sep 17 00:00:00 2001 From: Ethan Roseman Date: Mon, 11 Dec 2023 18:44:57 +0900 Subject: [PATCH] Misc tidying (#1134) Cleaned up Yay0compress cod Identified / classified remaining bins in the US yaml Tiny comment removal in a source file --- src/audio/e0b30_len_b80.c | 1 - tools/build/yay0/Yay0compress.c | 565 +++++++++++++++----------------- ver/us/splat.yaml | 13 +- 3 files changed, 274 insertions(+), 305 deletions(-) diff --git a/src/audio/e0b30_len_b80.c b/src/audio/e0b30_len_b80.c index 7227476b3a..58da9278be 100644 --- a/src/audio/e0b30_len_b80.c +++ b/src/audio/e0b30_len_b80.c @@ -4,7 +4,6 @@ void bgm_update_volume(void); void bgm_set_target_volume(s16 volume); -// these are BSS SHIFT_BSS s16 MusicDefaultVolume; SHIFT_BSS s16 MusicMaxVolume; SHIFT_BSS s16 MusicCurrentVolume; diff --git a/tools/build/yay0/Yay0compress.c b/tools/build/yay0/Yay0compress.c index 22ffb64121..0dc49ea2a0 100644 --- a/tools/build/yay0/Yay0compress.c +++ b/tools/build/yay0/Yay0compress.c @@ -2,315 +2,284 @@ #include #include -int main(int argc, const char **argv, const char **envp); -void encode(); -void search(unsigned int a1, int a2, int *a3, unsigned int *a4); -int mischarsearch(unsigned char *a1, int a2, unsigned char *a3, int a4); -void initskip(unsigned char *a1, int a2); -void writeshort(short a1); -void writeint4(int a1); +int main(int argc, const char** argv, const char** envp); +void encode(FILE* fp, int insize, unsigned char* bz); +void search(unsigned int a1, int insize, int* a3, unsigned int* a4, unsigned char* bz); +int mischarsearch(unsigned char* pattern, int patternlen, unsigned char* data, int datalen); +void initskip(unsigned short* skip, unsigned char* a1, int a2); +void writeshort(FILE* fp, short a1); +void writeint4(FILE* fp, int a1); -unsigned short skip[256]; // idb -int cp; // weak -int ndp; // weak -FILE *fp; // idb -unsigned char *def; -unsigned short *pol; -int pp; // weak -int insize; // idb -int ncp; // weak -int npp; // weak -unsigned char *bz; -int dp; // idb -unsigned int *cmd; +int main(int argc, const char** argv, const char** envp) { + FILE* fp; // idb + char src[999]; + char dest[999]; + int insize; // idb + unsigned char* bz; -int main(int argc, const char **argv, const char **envp) -{ - char src[999]; - char dest[999]; + if (argc < 3) { + fprintf(stderr, "Yay0compress [infile] [outfile]\n"); + return 1; + } - - if (argc < 3) - { - fprintf(stderr, "Yay0compress [infile] [outfile]\n"); - return 1; - } - - strcpy(src, argv[1]); + strcpy(src, argv[1]); strcpy(dest, argv[2]); - if ((fp = fopen(src, "rb")) == NULL) - { - fprintf(stderr, "FILE OPEN ERROR![%s]\n", src); - return 1; - } - - fseek(fp, 0, SEEK_END); - insize = ftell(fp); - fseek(fp, 0, SEEK_SET); - - bz = malloc(insize); - fread(bz, 1, insize, fp); - fclose(fp); - - for (int i = 0; src[i]; i++) - { - if (src[i] == '.') - { - src[i] = 0; - break; - } - } - - if ((fp = fopen(dest, "wb")) == NULL) - { - fprintf(stderr, "FILE CREATE ERROR![%s]\n", dest); - exit(1); - } - - encode(); - - fprintf(fp, "Yay0"); - - writeint4(insize); - - writeint4(4 * cp + 16); - writeint4(2 * pp + 4 * cp + 16); - - for (int i = 0; i < cp; i++) - writeint4(cmd[i]); - - for (int i = 0; i < pp; i++) - writeshort(pol[i]); - - fwrite(def, 1u, dp, fp); - fclose(fp); - - return 0; -} - -void encode() -{ - unsigned int v0; // esi - unsigned int v1; // edi - int v2; // edx - int v3; // ebx - int v4; // edx - char v5; // [esp+Ch] [ebp-18h] - unsigned int v6; // [esp+10h] [ebp-14h] - unsigned int v7; // [esp+14h] [ebp-10h] - int v8; // [esp+18h] [ebp-Ch] - unsigned int a4; // [esp+1Ch] [ebp-8h] - int a3; // [esp+20h] [ebp-4h] - - dp = 0; - pp = 0; - cp = 0; - npp = 4096; - ndp = 4096; - ncp = 4096; - cmd = calloc(0x4000u, 1u); - pol = malloc(2 * npp); - def = malloc(4 * ndp); - v0 = 0; - v6 = 1024; - v1 = 2147483648; - while ( insize > v0 ) - { - if ( v6 < v0 ) - v6 += 1024; - search(v0, insize, &a3, &a4); - if ( a4 <= 2 ) - { - cmd[cp] |= v1; - def[dp++] = bz[v0++]; - if ( ndp == dp ) - { - ndp = dp + 4096; - def = realloc(def, dp + 4096); - } - } - else - { - search(v0 + 1, insize, &v8, &v7); - if ( v7 > a4 + 1 ) - { - cmd[cp] |= v1; - def[dp++] = bz[v0++]; - if ( ndp == dp ) - { - ndp = dp + 4096; - def = realloc(def, dp + 4096); - } - v1 >>= 1; - if ( !v1 ) - { - v1 = 2147483648; - v2 = cp++; - if ( cp == ncp ) - { - ncp = v2 + 1025; - cmd = realloc(cmd, 4 * (v2 + 1025)); - } - cmd[cp] = 0; - } - a4 = v7; - a3 = v8; - } - v3 = v0 - a3 - 1; - a3 = v0 - a3 - 1; - v5 = a4; - if ( a4 > 0x11 ) - { - pol[pp++] = v3; - def[dp++] = v5 - 18; - if ( ndp == dp ) - { - ndp = dp + 4096; - def = realloc(def, dp + 4096); - } - } - else - { - pol[pp++] = v3 | (((short)a4 - 2) << 12); - } - if ( npp == pp ) - { - npp = pp + 4096; - pol = realloc(pol, 2 * (pp + 4096)); - } - v0 += a4; - } - v1 >>= 1; - if ( !v1 ) - { - v1 = 2147483648; - v4 = cp++; - if ( cp == ncp ) - { - ncp = v4 + 1025; - cmd = realloc(cmd, 4 * (v4 + 1025)); - } - cmd[cp] = 0; - } - } - if ( v1 != 0x80000000 ) - ++cp; - //fprintf(stderr, "IN=%d OUT=%d\n", insize, dp + 2 * pp + 4 * cp + 16); -} - -void search(unsigned int a1, int a2, int *a3, unsigned int *a4) -{ - unsigned int v4; // ebx - unsigned int v5; // esi - unsigned int *v6; // edi - unsigned int v7; // [esp+Ch] [ebp-10h] - int v8; // [esp+14h] [ebp-8h] - unsigned int v9; // [esp+18h] [ebp-4h] - - v4 = 3; - v5 = 0; - if ( a1 > 0x1000 ) - v5 = a1 - 4096; - v9 = 273; - if ( a2 - a1 <= 0x111 ) - v9 = a2 - a1; - if ( v9 > 2 ) - { - while ( a1 > v5 ) - { - v7 = mischarsearch(&bz[a1], v4, &bz[v5], v4 + a1 - v5); - if ( v7 >= a1 - v5 ) - break; - for ( ; v9 > v4; ++v4 ) - { - if ( bz[v4 + v5 + v7] != bz[v4 + a1] ) - break; - } - if ( v9 == v4 ) - { - *a3 = v7 + v5; - goto LABEL_17; - } - v8 = v5 + v7; - ++v4; - v5 += v7 + 1; - } - *a3 = v8; - if ( v4 > 3 ) - { - --v4; -LABEL_17: - *a4 = v4; - return; - } - v6 = a4; - } - else - { - *a4 = 0; - v6 = a3; - } - *v6 = 0; -} - -int mischarsearch(unsigned char *pattern, int patternlen, unsigned char *data, int datalen) -{ - int result; // eax - int i; // ebx - int v6; // eax - int j; // ecx - - result = datalen; - if ( patternlen <= datalen ) - { - initskip(pattern, patternlen); - for ( i = patternlen - 1; ; i += v6 ) - { - if ( pattern[patternlen - 1] == data[i] ) - { - --i; - j = patternlen - 2; - if ( patternlen - 2 < 0 ) - return i + 1; - while ( pattern[j] == data[i] ) - { - --i; - if ( --j < 0 ) - return i + 1; - } - v6 = patternlen - j; - if ( skip[data[i]] > patternlen - j ) - v6 = skip[data[i]]; - } - else - { - v6 = skip[data[i]]; - } + if ((fp = fopen(src, "rb")) == NULL) { + fprintf(stderr, "FILE OPEN ERROR![%s]\n", src); + return 1; } - } - return result; + + fseek(fp, 0, SEEK_END); + insize = ftell(fp); + fseek(fp, 0, SEEK_SET); + + bz = malloc(insize); + fread(bz, 1, insize, fp); + fclose(fp); + + for (int i = 0; src[i]; i++) { + if (src[i] == '.') { + src[i] = 0; + break; + } + } + + if ((fp = fopen(dest, "wb")) == NULL) { + fprintf(stderr, "FILE CREATE ERROR![%s]\n", dest); + exit(1); + } + + encode(fp, insize, bz); + + return 0; } -void initskip(unsigned char *pattern, int len) -{ - for (int i = 0; i < 256; i++) - skip[i] = len; +void encode(FILE* fp, int insize, unsigned char* bz) { + int pp; // weak + int dp; // idb + unsigned int* cmd; + unsigned char* def; + unsigned short* pol; + unsigned int v0; // esi + unsigned int v1 = 0; // edi + int v2 = 0; // edx + int v3 = 0; // ebx + int v4 = 0; // edx + unsigned int v6; // [esp+10h] [ebp-14h] + unsigned int v7 = 0; // [esp+14h] [ebp-10h] + int v8 = 0; // [esp+18h] [ebp-Ch] + unsigned int a4 = 0; // [esp+1Ch] [ebp-8h] + int a3 = 0; // [esp+20h] [ebp-4h] + int ncp; // weak + int npp; // weak + int ndp; // weak + int cp; - for (int i = 0; i < len; i++) - skip[pattern[i]] = len - i - 1; + dp = 0; + pp = 0; + cp = 0; + npp = 0x1000; + ndp = 0x1000; + ncp = 0x1000; + cmd = calloc(0x4000, 1); + pol = malloc(2 * npp); + def = malloc(4 * ndp); + v0 = 0; + v6 = 1024; + v1 = 0x80000000; + while (v0 < insize) { + if (dp == 73) { + int dog = 5; + } + + if (v6 < v0) { + v6 += 1024; + } + search(v0, insize, &a3, &a4, bz); + if (a4 <= 2) { + cmd[cp] |= v1; + def[dp++] = bz[v0++]; + if (ndp == dp) { + ndp = dp + 0x1000; + def = realloc(def, dp + 0x1000); + } + } else { + search(v0 + 1, insize, &v8, &v7, bz); + if (v7 > a4 + 1) { + cmd[cp] |= v1; + def[dp++] = bz[v0++]; + if (ndp == dp) { + ndp = dp + 0x1000; + def = realloc(def, dp + 0x1000); + } + v1 >>= 1; + if (!v1) { + v1 = 0x80000000; + v2 = cp++; + if (cp == ncp) { + ncp = v2 + 1025; + cmd = realloc(cmd, 4 * (v2 + 1025)); + } + cmd[cp] = 0; + } + a4 = v7; + a3 = v8; + } + v3 = v0 - a3 - 1; + a3 = v0 - a3 - 1; + if (a4 > 0x11) { + pol[pp++] = v3; + def[dp++] = a4 - 18; + if (ndp == dp) { + ndp = dp + 0x1000; + def = realloc(def, dp + 0x1000); + } + } else { + pol[pp++] = v3 | (((short)a4 - 2) << 12); + } + if (npp == pp) { + npp += 0x1000; + pol = realloc(pol, 2 * (pp + 0x1000)); + } + v0 += a4; + } + v1 >>= 1; + if (!v1) { + v1 = 0x80000000; + v4 = cp++; + if (cp == ncp) { + ncp = v4 + 1025; + cmd = realloc(cmd, 4 * (v4 + 1025)); + } + cmd[cp] = 0; + } + } + if (v1 != 0x80000000) { + cp++; + } + + fprintf(fp, "Yay0"); + + writeint4(fp, insize); + + writeint4(fp, 4 * cp + 16); + writeint4(fp, 2 * pp + 4 * cp + 16); + + for (int i = 0; i < cp; i++) + writeint4(fp, cmd[i]); + + for (int i = 0; i < pp; i++) + writeshort(fp, pol[i]); + + fwrite(def, 1, dp, fp); + fclose(fp); } -void writeshort(short val) -{ - fputc((val & 0xff00) >> 8, fp); - fputc((val & 0x00ff) >> 0, fp); +void search(unsigned int a1, int insize, int* a3, unsigned int* a4, unsigned char* bz) { + unsigned int patternlen; // ebx + unsigned int v5; // esi + unsigned int* v6 = 0; // edi + unsigned int v7 = 0; // [esp+Ch] [ebp-10h] + int v8 = 0; // [esp+14h] [ebp-8h] + unsigned int v9; // [esp+18h] [ebp-4h] + + patternlen = 3; + v5 = 0; + if (a1 > 0x1000) { + v5 = a1 - 0x1000; + } + v9 = 273; + if (insize - a1 <= 273) { + v9 = insize - a1; + } + if (v9 > 2) { + while (a1 > v5) { + v7 = mischarsearch(&bz[a1], patternlen, &bz[v5], patternlen + a1 - v5); + + if (v7 >= a1 - v5) { + break; + } + + for (; patternlen < v9; patternlen++) { + if (bz[patternlen + v5 + v7] != bz[patternlen + a1]) { + break; + } + } + if (v9 == patternlen) { + *a3 = v7 + v5; + *a4 = patternlen; + return; + } + v8 = v5 + v7; + patternlen++; + v5 += v7 + 1; + } + *a3 = v8; + if (patternlen > 3) { + patternlen--; + *a4 = patternlen; + return; + } + v6 = a4; + } else { + *a4 = 0; + v6 = a3; + } + *v6 = 0; } -void writeint4(int val) -{ - fputc((val & 0x00ff000000) >> 24, fp); - fputc((val & 0x0000ff0000) >> 16, fp); - fputc((val & 0x000000ff00) >> 8, fp); - fputc((val & 0x00000000ff) >> 0, fp); +int mischarsearch(unsigned char* pattern, int patternlen, unsigned char* data, int datalen) { + unsigned short skip[256]; // idb + int i; // ebx + int v6; // eax + int j; // ecx + + if (patternlen <= datalen) { + // initskip + for (int k = 0; k < 256; k++) { + skip[k] = patternlen; + } + + for (int k = 0; k < patternlen; k++) { + skip[pattern[k]] = patternlen - k - 1; + } + + for (i = patternlen - 1;; i += v6) { + if (pattern[patternlen - 1] == data[i]) { + i--; + j = patternlen - 2; + if (j < 0) { + return i + 1; + } + + while (pattern[j] == data[i]) { + i--; + j--; + if (j < 0) { + return i + 1; + } + } + + if (skip[data[i]] <= patternlen - j) { + v6 = patternlen - j; + continue; + } + } + v6 = skip[data[i]]; + } + } + return datalen; +} + +void writeshort(FILE* fp, short val) { + fputc((val & 0xff00) >> 8, fp); + fputc((val & 0x00ff) >> 0, fp); +} + +void writeint4(FILE* fp, int val) { + fputc((val & 0x00ff000000) >> 24, fp); + fputc((val & 0x0000ff0000) >> 16, fp); + fputc((val & 0x000000ff00) >> 8, fp); + fputc((val & 0x00000000ff) >> 0, fp); } diff --git a/ver/us/splat.yaml b/ver/us/splat.yaml index 8fee4f6cfe..faa7954393 100644 --- a/ver/us/splat.yaml +++ b/ver/us/splat.yaml @@ -14725,7 +14725,7 @@ segments: ################# ### Dead maps ### ################# - - [0xE9ECD0, bin] # tail of dead kzn_11 + - [0xE9ECD0, bin, dead_kzn_11_end] # tail of dead kzn_11 #- name: dead_kzn_11 # dir: world/dead/area_kzn/kzn_11 # type: code @@ -15006,9 +15006,10 @@ segments: - [auto, c, flo_19_5_beanstalk] - [0xF00000, pm_sbn, audio] - - [0x1942C40, bin] + - [0x1942C40, bin, copy_1942C40] # copy of 0x1642C40 - 0x1643000 - { start: 0x1943000, align: 8, type: pm_sprites, name: sprites } - - [0x1B82208, bin] # end of sprite data - todo: figure out what this is + - [0x1B82208, bin, pad_1B82208] # zeros + - [0x1B8220C, bin, copy_1B8220C] # copy of 0x188220C - 0x1883000 - start: 0x1B83000 type: pm_msg files: @@ -15059,8 +15060,8 @@ segments: - 2C_QuizQuestions - 2D_QuizChoices - 2E_Credits - - [0x1C84D30, bin] # junk(?) - - [0x1E00000, bin] # junk (player sprite data; can be zeroed out with no effect) + - [0x1C84D30, bin, unk_1C84D30] # junk(?) + - [0x1E00000, bin, copy_1E00000] # copy of 0x1943000 - 0x1983000 - [0x1E40000, pm_map_data, mapfs] - - { type: bin, start: 0x27FEE22, subalign: 2 } + - { name: copy_27FEE22, type: bin, start: 0x27FEE22, subalign: 2 } # copy of 0x232EE22 - 0x2330000 - [0x2800000]