diff options
Diffstat (limited to 'Xenogears')
-rw-r--r-- | Xenogears/Decrypt.cpp | 507 | ||||
-rwxr-xr-x | Xenogears/Makefile | 23 | ||||
-rw-r--r-- | Xenogears/Translate.cpp | 256 | ||||
-rw-r--r-- | Xenogears/XenoCD1.map | 52 | ||||
-rw-r--r-- | Xenogears/XenoCD2.map | 52 | ||||
-rw-r--r-- | Xenogears/archive.cpp | 37 | ||||
-rw-r--r-- | Xenogears/build-sector-2.cpp | 14 | ||||
-rw-r--r-- | Xenogears/build-sector.cpp | 14 | ||||
-rw-r--r-- | Xenogears/compil-2.lex | 254 | ||||
-rw-r--r-- | Xenogears/compil.lex | 383 | ||||
-rw-r--r-- | Xenogears/main_dump.cpp | 291 | ||||
-rwxr-xr-x | Xenogears/map2sqr | 34 | ||||
-rw-r--r-- | Xenogears/reinsert.cpp | 305 | ||||
-rw-r--r-- | Xenogears/script-comp.cpp | 96 | ||||
-rw-r--r-- | Xenogears/script-dec.cpp | 69 | ||||
-rw-r--r-- | Xenogears/test-dlz77.cpp | 7 | ||||
-rw-r--r-- | Xenogears/test-lz77.cpp | 7 |
17 files changed, 2401 insertions, 0 deletions
diff --git a/Xenogears/Decrypt.cpp b/Xenogears/Decrypt.cpp new file mode 100644 index 0000000..2f4d99f --- /dev/null +++ b/Xenogears/Decrypt.cpp @@ -0,0 +1,507 @@ +#include<stdio.h> +#include<string.h> + +void init_table(long table[5000]) +{ + long i; + + for (i = 0; i < 5000; i++) { + table[i] = 0; + } +} + +char found_position(long table[5000], int number, FILE * f_source) +{ + long position; + long i; + + position = ftell(f_source); + + for (i = 0; i < number; i++) { + if (table[i] <= position) + return (1); + } + return (0); +} + +long found_next(long table[5000], long script_number, long max_script) +{ + long i; + long next = 0xFFFF; + long actual = table[script_number]; + + for (i = 0; i < script_number; i++) { + if (table[i] > actual) { + if (table[i] < next) + next = table[i]; + } + } + + for (i = script_number + 1; i < max_script; i++) { + if (table[i] > actual) { + if (table[i] < next) + next = table[i]; + } + } + + return (next); +} + +void dump_text(FILE * f_source, FILE * f_cible, long table[5000], long script_number, + long max_script, unsigned char *length_table, unsigned char *line_table) +{ + long next; + unsigned char val; + char temp_string[2]; + long position; + unsigned char temp1 = 0; + unsigned char temp2 = 0; + long temp; + + temp_string[1] = NULL; + + next = found_next(table, script_number, max_script); + + fseek(f_source, table[script_number], SEEK_SET); + + fprintf(f_cible, "<Text_block lines:%d width:%d>\n", + line_table[script_number], length_table[script_number]); + + position = ftell(f_source); + + while (position < next) { + val = 0; + + fread((unsigned char *) &val, 1, 1, f_source); + + if (val == 0x00) // "<Close>" + { + break; + } else if (val == 0x01) // "\n" + { + fprintf(f_cible, "\n"); + } else if (val == 0x02) // "<New>" + { + fprintf(f_cible, "<New>\n"); + } else if (val == 0x03) // "<Wait>" + { + fprintf(f_cible, "<Wait>"); + } else if (val == 0x0F) // "<Delay X> + { + fread((unsigned char *) &temp1, 1, 1, f_source); + fread((unsigned char *) &temp2, 1, 1, f_source); + if (temp1 == 0) { + fprintf(f_cible, "<Delay %d>", temp2); + } else if (temp1 == 5) { + switch (temp2) { + case 0: + fprintf(f_cible, "<Fei>"); + break; + case 1: + fprintf(f_cible, "<Elly>"); + break; + case 2: + fprintf(f_cible, "<Citan>"); + break; + case 3: + fprintf(f_cible, "<Bart>"); + break; + case 4: + fprintf(f_cible, "<Billy>"); + break; + case 5: + fprintf(f_cible, "<Rico>"); + break; + case 6: + fprintf(f_cible, "<Emeralda>"); + break; + case 7: + fprintf(f_cible, "<Chu-Chu>"); + break; + case 8: + fprintf(f_cible, "<Maria>"); + break; + case 9: + fprintf(f_cible, "<Citan2>"); + break; + case 10: + fprintf(f_cible, "<Emeralda2>"); + break; + case 11: + fprintf(f_cible, "<Weltall>"); + break; + case 12: + fprintf(f_cible, "<Weltall-2>"); + break; + case 13: + fprintf(f_cible, "<Vierge>"); + break; + case 14: + fprintf(f_cible, "<Heimdal>"); + break; + case 15: + fprintf(f_cible, "<Brigandier>"); + break; + case 16: + fprintf(f_cible, "<Renmazuo>"); + break; + case 17: + fprintf(f_cible, "<Stier>"); + break; + case 18: + fprintf(f_cible, "<BigChu-chu>"); + break; + case 19: + fprintf(f_cible, "<Seibzehn>"); + break; + case 20: + fprintf(f_cible, "<Crescens>"); + break; + case 21: + fprintf(f_cible, "<Regurus>"); + break; + case 22: + fprintf(f_cible, "<Fenrir>"); + break; + case 23: + fprintf(f_cible, "<Andvari>"); + break; + case 24: + fprintf(f_cible, "<Renmazuo>"); + break; + case 25: + fprintf(f_cible, "<Stier-2>"); + break; + case 26: + fprintf(f_cible, "<Xenogears>"); + break; + case 27: + fprintf(f_cible, "<BARTHOS>"); + break; + case 28: + fprintf(f_cible, "<Yggdra>"); + break; + case 128: + fprintf(f_cible, "<Perso1>"); + break; + case 129: + fprintf(f_cible, "<Perso2>"); + break; + case 130: + fprintf(f_cible, "<Perso3>"); + break; + default: + fprintf(f_cible, "<Gear %d>", temp2); + } + } else { + fprintf(f_cible, "<Opcode %d %d>", temp1, temp2); + } + } else if (val == 0x10) // " " + { + fprintf(f_cible, " "); + } else if (val == 0x11) // "+" + { + fprintf(f_cible, "+"); + } else if (val == 0x12) // "," + { + fprintf(f_cible, ","); + } else if (val == 0x13) // "-" + { + fprintf(f_cible, "-"); + } else if (val == 0x14) // "." + { + fprintf(f_cible, "."); + } else if (val == 0x15) // "/" + { + fprintf(f_cible, "/"); + } else if ((val >= 0x16) && (val <= 0x1F)) // "0-9" + { + temp_string[0] = val + 0x1A; + fprintf(f_cible, temp_string); + } else if ((val >= 0x20) && (val <= 0x39)) // "A-Z" + { + temp_string[0] = val + 0x21; + fprintf(f_cible, temp_string); + } else if (val == 0x3A) // "[" + { + fprintf(f_cible, "["); + } else if (val == 0x3B) // "]" + { + fprintf(f_cible, "]"); + } else if (val == 0x3C) // "=" + { + fprintf(f_cible, "="); + } else if ((val >= 0x3D) && (val <= 0x56)) // "a-z" + { + temp_string[0] = val + 0x24; + fprintf(f_cible, temp_string); + } else if (val == 0x57) // "!" + { + fprintf(f_cible, "!"); + } else if (val == 0x58) // "\"" + { + fprintf(f_cible, "\""); + } else if (val == 0x59) // "#" + { + fprintf(f_cible, "#"); + } else if (val == 0x5A) // "%" + { + fprintf(f_cible, "%%"); + } else if (val == 0x5B) // "&" + { + fprintf(f_cible, "&"); + } else if (val == 0x5C) // "'" + { + fprintf(f_cible, "'"); + } else if (val == 0x5D) // "(" + { + fprintf(f_cible, "("); + } else if (val == 0x5E) // ")" + { + fprintf(f_cible, ")"); + } else if (val == 0x5F) // ":" + { + fprintf(f_cible, ":"); + } else if (val == 0x60) // "?" + { + fprintf(f_cible, "?"); + } else if (val == 0x61) // "<0>" + { + fprintf(f_cible, "<0>"); + } else if (val == 0x62) // "<1>" + { + fprintf(f_cible, "<1>"); + } else if (val == 0x63) // "<2>" + { + fprintf(f_cible, "<2>"); + } else if (val == 0x64) // "<3>" + { + fprintf(f_cible, "<3>"); + } else if (val == 0x65) // "<4>" + { + fprintf(f_cible, "<4>"); + } else if (val == 0x66) // "<5>" + { + fprintf(f_cible, "<5>"); + } else if (val == 0x67) // "<6>" + { + fprintf(f_cible, "<6>"); + } else if (val == 0x68) // "<7>" + { + fprintf(f_cible, "<7>"); + } else if (val == 0x69) // "<8>" + { + fprintf(f_cible, "<8>"); + } else if (val == 0x6A) // "<9>" + { + fprintf(f_cible, "<9>"); + } else if (val == 0x6B) // "<%>" + { + fprintf(f_cible, "<%%>"); + } else if (val == 0x6C) // "<&>" + { + fprintf(f_cible, "<&>"); + } else if (val == 0x6D) // "*" + { + fprintf(f_cible, "*"); + } else if (val == 0x6E) // "<C>" + { + fprintf(f_cible, "<C>"); + } else if (val == 0x6F) // "<S>" + { + fprintf(f_cible, "<S>"); + } else if (val == 0x70) // "<T>" + { + fprintf(f_cible, "<T>"); + } else if (val == 0x71) // "<*>" + { + fprintf(f_cible, "<*>"); + } else if (val == 0x72) // "<R>" + { + fprintf(f_cible, "<R>"); + } else if (val == 0x73) // "<L>" + { + fprintf(f_cible, "<L>"); + } else if (val == 0x74) // "<U>" + { + fprintf(f_cible, "<U>"); + } else if (val == 0x75) // "<U>" + { + fprintf(f_cible, "<D>"); + } else if (val == 0x76) // "<.>" + { + fprintf(f_cible, "<.>"); + } else if (val == 0x77) // "<:>" + { + fprintf(f_cible, "<:>"); + } else if (val == 0x79) // "</>" + { + fprintf(f_cible, "</>"); + } else if (val == 0x7A) // "<..>" + { + fprintf(f_cible, "<..>"); + } else if (val == 0x7B) // "<`>" + { + fprintf(f_cible, "<`>"); + } else if (val == 0x7D) // "<+>" + { + fprintf(f_cible, "<+>"); + } else if (val == 0x7E) // "<->" + { + fprintf(f_cible, "<->"); + } else if (val == 0x7F) // "<X>" + { + fprintf(f_cible, "<X>"); + } else if (val == 0x80) // "<[>" + { + fprintf(f_cible, "<[>"); + } else if (val == 0x81) // "<]>" + { + fprintf(f_cible, "<]>"); + } else if (val == 0x82) // "<%>" + { + fprintf(f_cible, "<%%>"); + } else if (val == 0x83) // "<&>" + { + fprintf(f_cible, "<&>"); + } else if (val == 0x84) // "<(>" + { + fprintf(f_cible, "<(>"); + } else if (val == 0x85) // "<)>" + { + fprintf(f_cible, "<)>"); + } else if (val == 0x86) // "<#>" + { + fprintf(f_cible, "<#>"); + } else if (val == 0x87) // "`" + { + fprintf(f_cible, "`"); + } else if (val == 0x88) // "°" + { + fprintf(f_cible, "°"); + } else if (val == 0x89) // "<=>" + { + fprintf(f_cible, "<=>"); + } else if (val == 0x8A) // "<?>" + { + fprintf(f_cible, "<?>"); + } else if (val == 0x8B) // "<!>" + { + fprintf(f_cible, "<!>"); + } else if (val == 0x8C) // "_" + { + fprintf(f_cible, "_"); + } else if (val == 0x8D) // "~" + { + fprintf(f_cible, "~"); + } else if (val == 0x8E) // "<...>" + { + fprintf(f_cible, "<...>"); + } else if (val == 0x8F) // "<'>" + { + fprintf(f_cible, "<'>"); + } else if (val == 0xFE) // "<Extra1 X> + { + fread((unsigned char *) &temp1, 1, 1, f_source); + fprintf(f_cible, "<Extra1 %d>", temp1); + } else if (val == 0xFF) // "<Extra2 X> + { + fread((unsigned char *) &temp1, 1, 1, f_source); + fprintf(f_cible, "<Extra2 %d>", temp1); + } else { + fprintf(f_cible, "<Bare %X>", val); + } + + position = ftell(f_source); + } + fprintf(f_cible, "\n<End_of_block>\n\n"); +} + +int decrypt(FILE * f_source, FILE * f_cible, int room_number) +{ + long i, j; + long table[5000]; + unsigned char line_table[5000]; + unsigned char length_table[5000]; + long script_number = 0; + long temp = 0; + char temp_char; + int counter = 0; + + fread((long *) &script_number, 4, 1, f_source); + + if (script_number == 0x0000FFFF) + return (1); + + script_number = (script_number++); + + fprintf(f_cible, "<Blocks:%i>\n", script_number); + init_table(table); + + i = j = 0; + + while (i < script_number) { + fread((long *) &temp, 2, 1, f_source); + if (table[j - 1] != temp) + table[j++] = temp; + i++; + } + + script_number = j; + + for (i = 0; i < script_number; i++) { + fread((unsigned char *) &length_table[i], 1, 1, f_source); + fread((unsigned char *) &line_table[i], 1, 1, f_source); + } + + fseek(f_source, table[script_number - 1], SEEK_SET); + + do { + fread((char *) &temp_char, 1, 1, f_source); + counter++; + } while (temp_char != 0); + + table[script_number] = ftell(f_source); + + for (i = 0; i < script_number; i++) { + dump_text(f_source, f_cible, table, i, script_number, length_table, line_table); + } + + return (0); +} + +int main(void) +{ + int i; + char file_name[100]; + FILE *f_source, *f_cible; + + for (i = 0; i < 730; i++) { + printf("%d\n", i); + sprintf(file_name, "xeno_d1/ROOMS/%04d/script.comp", i); + f_source = fopen(file_name, "rb"); + + sprintf(file_name, "xeno_d1/ROOMS/%04d/script.txt", i); + + if (f_source != NULL) { + f_cible = fopen(file_name, "w"); + decrypt(f_source, f_cible, 5); + fclose(f_source); + fclose(f_cible); + } + } + for (i = 0; i < 730; i++) { + printf("%d\n", i); + sprintf(file_name, "xeno_d2/ROOMS/%04d/script.comp", i); + f_source = fopen(file_name, "rb"); + + sprintf(file_name, "xeno_d2/ROOMS/%04d/script.txt", i); + + if (f_source != NULL) { + f_cible = fopen(file_name, "w"); + decrypt(f_source, f_cible, 5); + fclose(f_source); + fclose(f_cible); + } + } +} diff --git a/Xenogears/Makefile b/Xenogears/Makefile new file mode 100755 index 0000000..22d6392 --- /dev/null +++ b/Xenogears/Makefile @@ -0,0 +1,23 @@ +#!/usr/bin/make -f + +CPPFLAGS=-Wall -g -I. -O3 -mcpu=i686 +CXX=g++ + +TARGET = lz77 dlz77 yazedc cd-tool + +all: ${TARGET} + +lz77: lz77.cpp lz77.h generic.cpp generic.h fileutils.h fileutils.cpp + ${CXX} ${CPPFLAGS} ${LDFLAGS} -DLZ77_MAIN lz77.cpp generic.cpp fileutils.cpp -o lz77 + +dlz77: lz77 + ln -fs lz77 dlz77 + +yazedc: yazedc.cpp crctables crctable.out + ${CXX} ${CPPFLAGS} ${LDFLAGS} yazedc.cpp -DMAIN -o yazedc + +cd-tool: cd-tool.cpp cdutils.cpp cdutils.h fileutils.cpp fileutils.h generic.cpp generic.h yazedc.cpp yazedc.h + ${CXX} ${CPPFLAGS} ${LDFLAGAS} cd-tool.cpp cdutils.cpp fileutils.cpp yazedc.cpp generic.cpp -o cd-tool + +clean: + rm -f *.o ${TARGET} compil.c diff --git a/Xenogears/Translate.cpp b/Xenogears/Translate.cpp new file mode 100644 index 0000000..3f85437 --- /dev/null +++ b/Xenogears/Translate.cpp @@ -0,0 +1,256 @@ +#include <stdio.h> +#include <string.h> + +void dump_text(FILE * f_source, FILE * f_cible) +{ + unsigned char val; + unsigned char temp1 = 0; + unsigned char temp2 = 0; + + while (!feof(f_source)) { + val = 0; + + fread((unsigned char *) &val, 1, 1, f_source); + + if (val == 0x00) // "<Close>" + { +// break; + fprintf(f_cible, "<EOF>\n"); + } else if (val == 0x01) // "\n" + { + fprintf(f_cible, "\n"); + } else if (val == 0x02) // "<New>" + { + fprintf(f_cible, "<New>\n"); + } else if (val == 0x03) // "<Wait>" + { + fprintf(f_cible, "<Wait>"); + } else if (val == 0x0F) // "<Delay X> + { + fread((unsigned char *) &temp1, 1, 1, f_source); + fread((unsigned char *) &temp2, 1, 1, f_source); + if (temp1 == 0) { + fprintf(f_cible, "<Delay %d>", temp2); + } else if (temp1 == 5) { + fprintf(f_cible, "<Gear %d>", temp2); + } else { + fprintf(f_cible, "<Opcode %d %d>", temp1, temp2); + } + } else if (val == 0x10) // " " + { + fprintf(f_cible, " "); + } else if (val == 0x11) // "+" + { + fprintf(f_cible, "+"); + } else if (val == 0x12) // "," + { + fprintf(f_cible, ","); + } else if (val == 0x13) // "-" + { + fprintf(f_cible, "-"); + } else if (val == 0x14) // "." + { + fprintf(f_cible, "."); + } else if (val == 0x15) // "/" + { + fprintf(f_cible, "/"); + } else if ((val >= 0x16) && (val <= 0x1F)) // "0-9" + { + fprintf(f_cible, "%c", val + 0x1a); + } else if ((val >= 0x20) && (val <= 0x39)) // "A-Z" + { + fprintf(f_cible, "%c", val + 0x21); + } else if (val == 0x3A) // "[" + { + fprintf(f_cible, "["); + } else if (val == 0x3B) // "]" + { + fprintf(f_cible, "]"); + } else if (val == 0x3C) // "=" + { + fprintf(f_cible, "="); + } else if ((val >= 0x3D) && (val <= 0x56)) // "a-z" + { + fprintf(f_cible, "%c", val + 0x24); + } else if (val == 0x57) // "!" + { + fprintf(f_cible, "!"); + } else if (val == 0x58) // "\"" + { + fprintf(f_cible, "\""); + } else if (val == 0x59) // "#" + { + fprintf(f_cible, "#"); + } else if (val == 0x5A) // "%" + { + fprintf(f_cible, "%%"); + } else if (val == 0x5B) // "&" + { + fprintf(f_cible, "&"); + } else if (val == 0x5C) // "'" + { + fprintf(f_cible, "'"); + } else if (val == 0x5D) // "(" + { + fprintf(f_cible, "("); + } else if (val == 0x5E) // ")" + { + fprintf(f_cible, ")"); + } else if (val == 0x5F) // ":" + { + fprintf(f_cible, ":"); + } else if (val == 0x60) // "?" + { + fprintf(f_cible, "?"); + } else if (val == 0x61) // "<0>" + { + fprintf(f_cible, "<0>"); + } else if (val == 0x62) // "<1>" + { + fprintf(f_cible, "<1>"); + } else if (val == 0x63) // "<2>" + { + fprintf(f_cible, "<2>"); + } else if (val == 0x64) // "<3>" + { + fprintf(f_cible, "<3>"); + } else if (val == 0x65) // "<4>" + { + fprintf(f_cible, "<4>"); + } else if (val == 0x66) // "<5>" + { + fprintf(f_cible, "<5>"); + } else if (val == 0x67) // "<6>" + { + fprintf(f_cible, "<6>"); + } else if (val == 0x68) // "<7>" + { + fprintf(f_cible, "<7>"); + } else if (val == 0x69) // "<8>" + { + fprintf(f_cible, "<8>"); + } else if (val == 0x6A) // "<9>" + { + fprintf(f_cible, "<9>"); + } else if (val == 0x6B) // "<%>" + { + fprintf(f_cible, "<%%>"); + } else if (val == 0x6C) // "<&>" + { + fprintf(f_cible, "<&>"); + } else if (val == 0x6D) // "*" + { + fprintf(f_cible, "*"); + } else if (val == 0x6E) // "<C>" + { + fprintf(f_cible, "<C>"); + } else if (val == 0x6F) // "<S>" + { + fprintf(f_cible, "<S>"); + } else if (val == 0x70) // "<T>" + { + fprintf(f_cible, "<T>"); + } else if (val == 0x71) // "<*>" + { + fprintf(f_cible, "<*>"); + } else if (val == 0x72) // "<R>" + { + fprintf(f_cible, "<R>"); + } else if (val == 0x73) // "<L>" + { + fprintf(f_cible, "<L>"); + } else if (val == 0x74) // "<U>" + { + fprintf(f_cible, "<U>"); + } else if (val == 0x75) // "<U>" + { + fprintf(f_cible, "<D>"); + } else if (val == 0x76) // "<.>" + { + fprintf(f_cible, "<.>"); + } else if (val == 0x77) // "<:>" + { + fprintf(f_cible, "<:>"); + } else if (val == 0x79) // "</>" + { + fprintf(f_cible, "</>"); + } else if (val == 0x7A) // "<..>" + { + fprintf(f_cible, "<..>"); + } else if (val == 0x7B) // "<`>" + { + fprintf(f_cible, "<`>"); + } else if (val == 0x7D) // "<+>" + { + fprintf(f_cible, "<+>"); + } else if (val == 0x7E) // "<->" + { + fprintf(f_cible, "<->"); + } else if (val == 0x7F) // "<X>" + { + fprintf(f_cible, "<X>"); + } else if (val == 0x80) // "<[>" + { + fprintf(f_cible, "<[>"); + } else if (val == 0x81) // "<]>" + { + fprintf(f_cible, "<]>"); + } else if (val == 0x82) // "<%>" + { + fprintf(f_cible, "<%%>"); + } else if (val == 0x83) // "<&>" + { + fprintf(f_cible, "<&>"); + } else if (val == 0x84) // "<(>" + { + fprintf(f_cible, "<(>"); + } else if (val == 0x85) // "<)>" + { + fprintf(f_cible, "<)>"); + } else if (val == 0x86) // "<#>" + { + fprintf(f_cible, "<#>"); + } else if (val == 0x87) // "`" + { + fprintf(f_cible, "`"); + } else if (val == 0x88) // "°" + { + fprintf(f_cible, "°"); + } else if (val == 0x89) // "<=>" + { + fprintf(f_cible, "<=>"); + } else if (val == 0x8A) // "<?>" + { + fprintf(f_cible, "<?>"); + } else if (val == 0x8B) // "<!>" + { + fprintf(f_cible, "<!>"); + } else if (val == 0x8C) // "_" + { + fprintf(f_cible, "_"); + } else if (val == 0x8D) // "~" + { + fprintf(f_cible, "~"); + } else if (val == 0x8E) // "<...>" + { + fprintf(f_cible, "<...>"); + } else if (val == 0x8F) // "<'>" + { + fprintf(f_cible, "<'>"); + } else if (val == 0xFE) // "<Extra1 X> + { + fread((unsigned char *) &temp1, 1, 1, f_source); + fprintf(f_cible, "<Extra1 %d>", temp1); + } else if (val == 0xFF) // "<Extra2 X> + { + fread((unsigned char *) &temp1, 1, 1, f_source); + fprintf(f_cible, "<Extra2 %d>", temp1); + } else { + fprintf(f_cible, "<Bare %X>", val); + } + } +} + +int main(void) { + dump_text(stdin, stdout); +} diff --git a/Xenogears/XenoCD1.map b/Xenogears/XenoCD1.map new file mode 100644 index 0000000..8649f1b --- /dev/null +++ b/Xenogears/XenoCD1.map @@ -0,0 +1,52 @@ +Xenogears CD1 +718738272 +xeno_d1 +3728 + 0 16 VIDEOS 2 Videos + 17 17 SYSTEM 3 Codec MDEC + 18 18 SYSTEM 3 System.cnf + 19 19 SLUS 3 slus 00664 + 20 25 BOOT 3 Boot system following SLUS + 26 37 BFCODE 3 Battle field code and datas + 38 86 MISC05 3 Misc part 05 + 87 93 MISC06 3 Misc part 06 + 94 239 MISC07 3 Misc part 07 + 240 250 MISC08 3 Misc part 08 + 251 252 MISC09 3 Misc part 09 + 253 285 MISC10 3 Misc part 10 + 286 376 HEADS 3 Heads shown in dialogs + 377 383 MISC12 3 Misc part 12 + 384 1843 ROOMS 3 Rooms +1844 1988 MISC14 3 Misc part 14 +1989 2109 MISC15 3 Misc part 15 +2110 2197 TIMS 3 Various TIM files +2198 2216 BUNCH 3 Bunch of various files +2217 2220 MISC18 3 Misc part 18 +2221 2373 MISC19 3 Misc part 19 +2374 2375 MISC20 3 Misc part 20 +2376 2525 MISC21 3 Misc part 21 +2526 2747 BATTLE 3 Battle infos +2748 2978 MISC23 3 Misc part 23 +2979 3518 MISC24 3 Misc part 24 +3519 3534 MISC25 3 Misc part 25 +3535 3551 MISC26 3 Misc part 26 +3552 3553 SAVE 3 Save system +3554 3556 MISC28 3 Misc part 28 +3557 3566 MAPS 3 Map 01 +3567 3576 MAPS 3 Map 02 +3577 3586 MAPS 3 Map 03 +3587 3596 MAPS 3 Map 04 +3597 3606 MAPS 3 Map 05 +3607 3616 MAPS 3 Map 06 +3617 3626 MAPS 3 Map 07 +3627 3636 MAPS 3 Map 08 +3637 3646 MAPS 3 Map 09 +3647 3656 MAPS 3 Map 10 +3657 3666 MAPS 3 Map 11 +3667 3676 MAPS 3 Map 12 +3677 3686 MAPS 3 Map 13 +3687 3696 MAPS 3 Map 14 +3697 3706 MAPS 3 Map 15 +3707 3716 MAPS 3 Map 16 +3717 3726 MAPS 3 Map 17 +3727 3727 TRASH 0 Zero padding diff --git a/Xenogears/XenoCD2.map b/Xenogears/XenoCD2.map new file mode 100644 index 0000000..4c491f7 --- /dev/null +++ b/Xenogears/XenoCD2.map @@ -0,0 +1,52 @@ +Xenogears CD2 +688700880 +xeno_d2 +3723 + 0 11 VIDEOS 2 Videos + 12 12 SYSTEM 3 Codec MDEC + 13 13 SYSTEM 3 System.cnf + 14 14 SLUS 3 slus 00669 + 15 20 BOOT 3 Boot system following SLUS + 21 32 BFCODE 3 Battle field code and datas + 33 81 MISC05 3 Misc part 05 + 82 88 MISC06 3 Misc part 06 + 89 234 MISC07 3 Misc part 07 + 235 245 MISC08 3 Misc part 08 + 246 247 MISC09 3 Misc part 09 + 248 280 MISC10 3 Misc part 10 + 281 371 HEADS 3 Heads shown in dialogs + 372 378 MISC12 3 Misc part 12 + 379 1838 ROOMS 3 Rooms +1839 1983 MISC14 3 Misc part 14 +1984 2104 MISC15 3 Misc part 15 +2105 2192 TIMS 3 Various TIM files +2193 2211 BUNCH 3 Bunch of various files +2212 2215 MISC18 3 Misc part 18 +2216 2368 MISC19 3 Misc part 19 +2369 2370 MISC20 3 Misc part 20 +2371 2520 MISC21 3 Misc part 21 +2521 2742 BATTLE 3 Battle infos +2743 2973 MISC23 3 Misc part 23 +2974 3513 MISC24 3 Misc part 24 +3514 3529 MISC25 3 Misc part 25 +3530 3546 MISC26 3 Misc part 26 +3547 3548 SAVE 3 Save system +3549 3551 MISC28 3 Misc part 28 +3552 3561 MAPS 3 Map 01 +3562 3571 MAPS 3 Map 02 +3572 3581 MAPS 3 Map 03 +3582 3591 MAPS 3 Map 04 +3592 3601 MAPS 3 Map 05 +3602 3611 MAPS 3 Map 06 +3612 3621 MAPS 3 Map 07 +3622 3631 MAPS 3 Map 08 +3632 3641 MAPS 3 Map 09 +3642 3651 MAPS 3 Map 10 +3652 3661 MAPS 3 Map 11 +3662 3671 MAPS 3 Map 12 +3672 3681 MAPS 3 Map 13 +3682 3691 MAPS 3 Map 14 +3692 3701 MAPS 3 Map 15 +3702 3711 MAPS 3 Map 16 +3712 3721 MAPS 3 Map 17 +3722 3722 TRASH 0 Zero padding diff --git a/Xenogears/archive.cpp b/Xenogears/archive.cpp new file mode 100644 index 0000000..6701c2c --- /dev/null +++ b/Xenogears/archive.cpp @@ -0,0 +1,37 @@ +#include <stdio.h> +#include <values.h> +#include <stdlib.h> +#include "fileutils.h" + +void dearchive(FILE * f) { + long nb; + long * address; + char fname[100]; + int i; + FILE * f_out; + + fread(&nb, 4, 1, f); + nb++; + fprintf(stderr, "Reading index... (%li elements)\n", nb); + + address = (long *) malloc(nb * sizeof(long) + 1); + + for (i = 0; i < nb; i++) { + fread(address + i, 4, 1, f); + } + address[nb] = MAXINT; + + for (i = 0; i < nb; i++) { + fprintf(stderr, "Dumping file %i\n", i); + sprintf(fname, "part-%i.lz", i); + f_out = fopen(fname, "wb"); + copy(fileno(f), fileno(f_out), address[i + 1] - address[i]); + fclose(f_out); + } + + free(address); +} + +int main(void) { + dearchive(stdin); +} diff --git a/Xenogears/build-sector-2.cpp b/Xenogears/build-sector-2.cpp new file mode 100644 index 0000000..6ab7835 --- /dev/null +++ b/Xenogears/build-sector-2.cpp @@ -0,0 +1,14 @@ +#include <stdio.h> +#include "yazedc.h" + +int main(void) { + unsigned char datas[2352]; + + fread(datas, 2352, 1, stdin); + minute = datas[12]; + second = datas[13]; + frame = datas[14]; + fprintf(stderr, "Sector info: %2i:%02i:%04i\n", minute, second, frame); + do_encode_L2(datas, MODE_2, 0); + fwrite(datas, 2352, 1, stdout); +} diff --git a/Xenogears/build-sector.cpp b/Xenogears/build-sector.cpp new file mode 100644 index 0000000..3effc35 --- /dev/null +++ b/Xenogears/build-sector.cpp @@ -0,0 +1,14 @@ +#include <stdio.h> +#include "yazedc.h" + +int main(void) { + unsigned char datas[2352]; + + fread(datas, 2352, 1, stdin); + minute = datas[12]; + second = datas[13]; + frame = datas[14]; + fprintf(stderr, "Sector info: %2i:%02i:%04i\n", minute, second, frame); + do_encode_L2(datas, MODE_2_FORM_1, 0); + fwrite(datas, 2352, 1, stdout); +} diff --git a/Xenogears/compil-2.lex b/Xenogears/compil-2.lex new file mode 100644 index 0000000..805a964 --- /dev/null +++ b/Xenogears/compil-2.lex @@ -0,0 +1,254 @@ + /* In text block */ +%s I + /* Outside of text block */ +%s O + /* Waiting for Width argument */ +%s W + /* Waiting for OpCode arguments */ +%s Op + + int num_blocks = 0; + int num_lines = 0; + int cur_num_lines = 0; + int cur_num_block = 0; + int line_width = 0; + int max_line_width = 0; + int block_lines = 0; + int block_width = 0; + int errstate = 0; + void yputc(int c, int a); + +%% + +<INITIAL>"<Blocks:"\ *[[:digit:]]+">"\n { + int i; + char zeros[4] = {0, 0, 0, 0}; + num_blocks = atoi(yytext + 8); + fprintf(stderr, "Number of blocks: %i\n", num_blocks); + + num_lines = 2; + + BEGIN(O); + } + +<INITIAL>.* { + fprintf(stderr, "Invalid file, must begin with <Blocks: XX>\n"); + errstate = 1; + num_lines = 2; + num_blocks = 9999; + } + +<O>"<Text_block lines:"\ *[[:digit:]]+\ + { + if (cur_num_block >= num_blocks) { + fprintf(stderr, "Error: too much blocks at line %i\n", num_lines); + errstate = 1; + } + block_lines = atoi(yytext + 18); + BEGIN(W); + } + +<W>"width:"\ *[[:digit:]]+">\n" { + block_width = atoi(yytext + 6); + fprintf(stderr, "Begin of block %i at line %i -- lines = %i, width = %i\n", cur_num_block, num_lines, block_lines, block_width); + num_lines++; + line_width = 0; + max_line_width = 0; + cur_num_lines = 1; + BEGIN(I); + } + +<W>.* { + fprintf(stderr, "Error: invalid arguments to command Text_block at line %i: '%s'\n", num_lines, yytext); + errstate = 1; + BEGIN(O); + } + +<I>\n { + if (line_width > block_width) { + fprintf(stderr, "Warning: line %i too long (%i > %i).\n", num_lines, line_width, block_width); + } + if (line_width > max_line_width) + max_line_width = line_width; + line_width = 0; + num_lines++; + cur_num_lines++; + if (cur_num_lines > block_lines) { + fprintf(stderr, "Warning: too much lines for text block %i at line %i (%i > %i)\n", cur_num_block, num_lines, cur_num_lines, block_lines); + } + putc('\n', yyout); + } + +<I>"<New>\n" { + if (line_width > block_width) { + fprintf(stderr, "Warning: line %i too long (%i > %i).\n", num_lines, line_width, block_width); + } + if (line_width > max_line_width) + max_line_width = line_width; + line_width = 0; + num_lines++; + cur_num_lines = 1; + putc('\n', yyout); + } + +<I>"<Wait>\n" { + if (line_width > block_width) { + fprintf(stderr, "Warning: line %i too long (%i > %i).\n", num_lines, line_width, block_width); + } + if (line_width > max_line_width) + max_line_width = line_width; + line_width = 0; + num_lines++; + cur_num_lines = 1; + putc('\n', yyout); + } + +<I>"<Wait>" { + cur_num_lines = 1; + } + +<I>"<Delay"\ +[[:digit:]]+">" { + int d = atoi(yytext + 7); + if (d > 255) { + fprintf(stderr, "Error: delay too important: %i\n", d); + errstate = 1; + } + } + +<I>"<Gear"\ +[[:digit:]]+">" { + int d = atoi(yytext + 5); + if (d > 255) { + fprintf(stderr, "Error: gear number too important: %i\n", d); + errstate = 1; + } else { + putc(0xf, yyout); + putc(5, yyout); + putc(d, yyout); + line_width += 16; + } + } + +<I>"<Opcode"\ +/[[:digit:]]+\ +[[:digit:]]+">" { + BEGIN(Op); + } + +<Op>[[:digit:]]+\ +[[:digit:]]+">" { + int o1, o2; + o1 = atoi(yytext); + o2 = atoi(yytext + (o1 < 10 ? 2 : o1 < 100 ? 3 : 4)); + BEGIN(I); + } + +<Op>[^<]*">" { + yytext[strlen(yytext - 1)] = 0; + fprintf(stderr, "Error: invalid OpCode '%s'\n", yytext); + errstate = 1; + BEGIN(I); + } + +<I>"<"[[:digit:]]">" unput(*(yytext + 1)); +<I>"<".">" unput(*(yytext + 1)); +<I>"<..>" unput('.'); unput('.'); +<I>"<...>" unput('.'); unput('.'); unput('.'); + +<I>"<Extra1"\ +[[:digit:]]+">" { + int d = atoi(yytext + 7); + if (d > 255) { + fprintf(stderr, "Error: Extra1 number too important: %i\n", d); + errstate = 1; + } else { + putc(0xfe, yyout); + putc(d, yyout); + } + } + +<I>"<Extra2"\ +[[:digit:]]+">" { + int d = atoi(yytext + 7); + if (d > 255) { + fprintf(stderr, "Error: Extra2 number too important: %i\n", d); + errstate = 1; + } else { + putc(0xff, yyout); + putc(d, yyout); + } + } + +<I>"<Bare"\ +[[:xdigit:]]{1,2}">" { + char str[5] = {'0', 'x', 0, 0, 0}; + int d; + for (yytext += 6; *yytext == ' '; yytext++); + str[2] = *(yytext++); + str[3] = *(yytext++); + sscanf(str, "%i", &d); + if (d > 255) { + fprintf(stderr, "Error: Bare number too important: %i\n", d); + errstate = 1; + } else { + putc(d, yyout); + } + } + +<I>"<oe>" unput('e'); unput('o'); +<I>"<ae>" unput('e'); unput('a'); + +<I>"\n<End_of_block>" { + if (line_width > max_line_width) + max_line_width = line_width; + if (max_line_width < block_width) + fprintf(stderr, "Warning: block %i too large (%i < %i)\n", cur_num_block, max_line_width, block_width); + num_lines++; + cur_num_block++; + putc('\n', yyout); + putc('\n', yyout); + BEGIN(O); + } + +<I>"<"[^\>\n]*">" { + yytext[strlen(yytext) - 1] = 0; + fprintf(stderr, "Error: Invalid command at line %i: '%s'\n", num_lines, yytext + 1); + errstate = 1; + } + +<O>\n num_lines++; +<O>. /* Eat up comments */ + +<I>. { + putc(*yytext, yyout); + } + +. { + fprintf(stderr, "Hu uh, something's wrong at line %i...\n", num_lines); + } + +%% + +int yywrap(void) { + if (cur_num_block < num_blocks) { + fprintf(stderr, "Warning: Too few blocks at end of file.\n"); + } + exit(errstate ? -1 : 0); +} + +int main(int argc, char ** argv) { + if ((argc < 2) || (argc > 3)) { + fprintf(stderr, "Usage: %s <output> [input]\n", argv[0]); + exit(-1); + } + if (!(yyout = fopen(argv[1], "wb"))) { + fprintf(stderr, "Error: can't open file %s\n", argv[1]); + exit(-1); + } + if (argc == 3) { + if (!(yyin = fopen(argv[2], "rb"))) { + fprintf(stderr, "Error: can't open file %s\n", argv[2]); + exit(-1); + } + } + fprintf(stderr, "Creating file %s\n", argv[1]); + yylex(); + exit(errstate ? -1 : 0); +} + +void yputc(int c, int a) { + line_width += a; + putc(c, yyout); +} diff --git a/Xenogears/compil.lex b/Xenogears/compil.lex new file mode 100644 index 0000000..f6ceda8 --- /dev/null +++ b/Xenogears/compil.lex @@ -0,0 +1,383 @@ + #include <string.h> + /* In text block */ +%s I + /* Outside of text block */ +%s O + /* Waiting for Width argument */ +%s W + /* Waiting for OpCode arguments */ +%s Op + + int num_blocks = 0; + int num_lines = 0; + int cur_num_lines = 0; + int cur_num_block = 0; + int line_width = 0; + int max_line_width = 0; + int block_lines = 0; + int block_width = 0; + int errstate = 0; + void yputc(int c, int a); + void unputs(char *); + +%% + +<INITIAL>"<Blocks:"\ *[[:digit:]]+">"\n { + int i; + char zeros[4] = {0, 0, 0, 0}; + num_blocks = atoi(yytext + 8); + fprintf(stderr, "Number of blocks: %i\n", num_blocks); + num_blocks--; + fwrite(&num_blocks, 4, 1, yyout); + num_blocks++; + + for (i = 0; i < num_blocks; i++) { + fwrite(zeros, 4, 1, yyout); + } + + num_lines = 2; + + BEGIN(O); + } + +<INITIAL>.* { + fprintf(stderr, "Invalid file, must begin with <Blocks: XX>\n"); + errstate = 1; + num_lines = 2; + num_blocks = 9999; + } + +<O>"<Text_block lines:"\ *[[:digit:]]+\ + { + if (cur_num_block >= num_blocks) { + fprintf(stderr, "Error: too much blocks at line %i\n", num_lines); + errstate = 1; + } + block_lines = atoi(yytext + 18); + BEGIN(W); + } + +<W>"width:"\ *[[:digit:]]+">\n" { + block_width = atoi(yytext + 6); + fprintf(stderr, "Begin of block %i at line %i -- lines = %i, width = %i\n", cur_num_block, num_lines, block_lines, block_width); + num_lines++; + line_width = 0; + max_line_width = 0; + cur_num_lines = 1; + if (num_blocks != 9999) { + long p = ftell(yyout); + fseek(yyout, 4 + cur_num_block * 2, SEEK_SET); + fwrite(&p, 2, 1, yyout); + fseek(yyout, (num_blocks - 1) * 2, SEEK_CUR); + putc(block_width, yyout); + putc(block_lines, yyout); + fseek(yyout, 0, SEEK_END); + } + BEGIN(I); + } + +<W>.* { + fprintf(stderr, "Error: invalid arguments to command Text_block at line %i: '%s'\n", num_lines, yytext); + errstate = 1; + BEGIN(O); + } + +<I>"\n" { + if (line_width > block_width) { + fprintf(stderr, "Warning: line %i too long (%i > %i).\n", num_lines, line_width, block_width); + } + if (line_width > max_line_width) + max_line_width = line_width; + line_width = 0; + num_lines++; + cur_num_lines++; + if (cur_num_lines > block_lines) { + fprintf(stderr, "Warning: too much lines for text block %i at line %i (%i > %i)\n", cur_num_block, num_lines, cur_num_lines, block_lines); + } + putc(1, yyout); + } + +<I>"<New>\n" { + if (line_width > block_width) { + fprintf(stderr, "Warning: line %i too long (%i > %i).\n", num_lines, line_width, block_width); + } + if (line_width > max_line_width) + max_line_width = line_width; + line_width = 0; + num_lines++; + cur_num_lines = 1; + putc(2, yyout); + } + +<I>"<Wait>\n" { + if (line_width > block_width) { + fprintf(stderr, "Warning: line %i too long (%i > %i).\n", num_lines, line_width, block_width); + } + if (line_width > max_line_width) + max_line_width = line_width; + line_width = 0; + num_lines++; + cur_num_lines = 1; + putc(1, yyout); + putc(3, yyout); + } + +<I>"<Wait>" { + cur_num_lines = 1; + putc(3, yyout); + } + +<I>"<Delay"\ +[[:digit:]]+">" { + int d = atoi(yytext + 7); + if (d > 255) { + fprintf(stderr, "Error: delay too important: %i\n", d); + errstate = 1; + } else { + putc(0xf, yyout); + putc(0, yyout); + putc(d, yyout); + } + } + +<I>"<Gear"\ +[[:digit:]]+">" { + int d = atoi(yytext + 5); + if (d > 255) { + fprintf(stderr, "Error: gear number too important: %i\n", d); + errstate = 1; + } else { + putc(0xf, yyout); + putc(5, yyout); + putc(d, yyout); + line_width += 16; + } + } + +<I>"<Opcode"\ +/[[:digit:]]+\ +[[:digit:]]+">" { + BEGIN(Op); + } + +<Op>[[:digit:]]+\ +[[:digit:]]+">" { + int o1, o2; + o1 = atoi(yytext); + o2 = atoi(yytext + (o1 < 10 ? 2 : o1 < 100 ? 3 : 4)); + putc(0xf, yyout); + putc(o1, yyout); + putc(o2, yyout); + BEGIN(I); + } + +<Op>[^<]*">" { + yytext[strlen(yytext - 1)] = 0; + fprintf(stderr, "Error: invalid OpCode '%s'\n", yytext); + errstate = 1; + BEGIN(I); + } + +<I>" " yputc(0x10, 2); +<I>"+" yputc(0x11, 2); +<I>"," yputc(0x12, 2); +<I>"-" yputc(0x13, 2); +<I>"." yputc(0x14, 2); +<I>"/" yputc(0x15, 2); +<I>[[:digit:]] yputc(*yytext - 0x1a, 2); +<I>[[:upper:]] yputc(*yytext - 0x21, 2); +<I>"[" yputc(0x3a, 2); +<I>"]" yputc(0x3b, 2); +<I>"=" yputc(0x3c, 2); +<I>[[:lower:]] yputc(*yytext - 0x24, 2); +<I>"!" yputc(0x57, 2); +<I>"\"" yputc(0x58, 2); +<I>"#" yputc(0x59, 2); +<I>"%" yputc(0x5a, 2); +<I>"&" yputc(0x5b, 2); +<I>"'" yputc(0x5c, 2); +<I>"(" yputc(0x5d, 2); +<I>")" yputc(0x5e, 2); +<I>":" yputc(0x5f, 2); +<I>"?" yputc(0x60, 2); +<I>"<"[[:digit:]]">" yputc(*(yytext + 1) + 0x31, 3); +<I>"<%>" yputc(0x6b, 3); +<I>"<&>" yputc(0x6c, 3); +<I>"*" yputc(0x6d, 3); +<I>"<C>" yputc(0x6e, 3); +<I>"<S>" yputc(0x6f, 3); +<I>"<T>" yputc(0x70, 3); +<I>"<*>" yputc(0x71, 3); +<I>"<R>" yputc(0x72, 3); +<I>"<L>" yputc(0x73, 3); +<I>"<U>" yputc(0x74, 3); +<I>"<D>" yputc(0x75, 3); +<I>"<.>" yputc(0x76, 3); +<I>"<:>" yputc(0x77, 3); +<I>"</>" yputc(0x79, 3); +<I>"<..>" yputc(0x7a, 3); +<I>"<`>" yputc(0x7b, 3); +<I>"<+>" yputc(0x7d, 3); +<I>"<->" yputc(0x7e, 3); +<I>"<X>" yputc(0x7f, 3); +<I>"<[>" yputc(0x80, 3); +<I>"<]>" yputc(0x81, 3); +<I>"<(>" yputc(0x84, 3); +<I>"<)>" yputc(0x85, 3); +<I>"<#>" yputc(0x86, 3); +<I>"`" yputc(0x87, 3); +<I>"°" yputc(0x88, 3); +<I>"<=>" yputc(0x89, 3); +<I>"<?>" yputc(0x8a, 3); +<I>"<!>" yputc(0x8b, 3); +<I>"_" yputc(0x8c, 3); +<I>"~" yputc(0x8d, 3); +<I>"<...>" yputc(0x8e, 3); +<I>"<'>" yputc(0x8f, 3); + +<I>"<Extra1"\ +[[:digit:]]+">" { + int d = atoi(yytext + 7); + if (d > 255) { + fprintf(stderr, "Error: Extra1 number too important: %i\n", d); + errstate = 1; + } else { + putc(0xfe, yyout); + putc(d, yyout); + } + } + +<I>"<Extra2"\ +[[:digit:]]+">" { + int d = atoi(yytext + 7); + if (d > 255) { + fprintf(stderr, "Error: Extra2 number too important: %i\n", d); + errstate = 1; + } else { + putc(0xff, yyout); + putc(d, yyout); + } + } + +<I>"<Bare"\ +[[:xdigit:]]{1,2}">" { + char str[5] = {'0', 'x', 0, 0, 0}; + int d; + for (yytext += 6; *yytext == ' '; yytext++); + str[2] = *(yytext++); + str[3] = *(yytext++); + sscanf(str, "%i", &d); + if (d > 255) { + fprintf(stderr, "Error: Bare number too important: %i\n", d); + errstate = 1; + } else { + putc(d, yyout); + } + } + +<I>à|â|ä unput('a'); +<I>é|è|ê|ë unput('e'); +<I>î|ï unput('i'); +<I>ô|ö unput('o'); +<I>û|ü|ù unput('u'); +<I>ç unput('c'); +<I>"<oe>" unput('e'); unput('o'); +<I>"<ae>" unput('e'); unput('a'); + +<I>"<Fei>" unputs("<Gear 00>"); +<I>"<Elly>" unputs("<Gear 01>"); +<I>"<Citan>" unputs("<Gear 02>"); +<I>"<Bart>" unputs("<Gear 03>"); +<I>"<Billy>" unputs("<Gear 04>"); +<I>"<Rico>" unputs("<Gear 05>"); +<I>"<Emeralda>" unputs("<Gear 06>"); +<I>"<Chu-Chu>" unputs("<Gear 07>"); +<I>"<Maria>" unputs("<Gear 08>"); +<I>"<Citan-2>" unputs("<Gear 09>"); +<I>"<Emeralda-2>" unputs("<Gear 10>"); +<I>"<Weltall>" unputs("<Gear 11>"); +<I>"<Waltall-2>" unputs("<Gear 12>"); +<I>"<Vierge>" unputs("<Gear 13>"); +<I>"<Heimdal>" unputs("<Gear 14>"); +<I>"<Brigandier>" unputs("<Gear 15>"); +<I>"<Renmazuo>" unputs("<Gear 16>"); +<I>"<Stier>" unputs("<Gear 17>"); +<I>"<BigChu-chu>" unputs("<Gear 18>"); +<I>"<Seibzehn>" unputs("<Gear 19>"); +<I>"<Crescens>" unputs("<Gear 20>"); +<I>"<Regurus>" unputs("<Gear 21>"); +<I>"<Fenrir>" unputs("<Gear 22>"); +<I>"<Andvari>" unputs("<Gear 23>"); +<I>"<Renmazuo>" unputs("<Gear 24>"); +<I>"<Stier-2>" unputs("<Gear 25>"); +<I>"<Xenogears>" unputs("<Gear 26>"); +<I>"<BARTHOS>" unputs("<Gear 27>"); +<I>"<Yggdra>" unputs("<Gear 29>"); +<I>"<Perso1>" unputs("<Gear 128>"); +<I>"<Perso2>" unputs("<Gear 129>"); +<I>"<Perso3>" unputs("<Gear 130>"); + + +<I>"\n<End_of_block>" { + if (line_width > max_line_width) + max_line_width = line_width; + if (max_line_width < block_width) + fprintf(stderr, "Warning: block %i too large (%i < %i)\n", cur_num_block, max_line_width, block_width); + if (line_width > block_width) + fprintf(stderr, "Warning: line %i too long (%i > %i).\n", num_lines, line_width, block_width); + num_lines++; + cur_num_block++; + putc(0, yyout); + BEGIN(O); + } + +<I>"<"[^\>\n]*">" { + yytext[strlen(yytext) - 1] = 0; + fprintf(stderr, "Error: Invalid command at line %i: '%s'\n", num_lines, yytext + 1); + errstate = 1; + } + +<O>\n num_lines++; +<O>. /* Eat up comments */ + +<I>. { + fprintf(stderr, "Invalid character at line %i: '%c'\n", num_lines, *yytext); + errstate = 1; + } + +. { + fprintf(stderr, "Hu uh, something's wrong at line %i...\n", num_lines); + } + +%% + +int yywrap(void) { + if (cur_num_block < num_blocks) { + fprintf(stderr, "Warning: Too few blocks at end of file.\n"); + } + exit(errstate ? -1 : 0); +} + +int main(int argc, char ** argv) { + if ((argc < 2) || (argc > 3)) { + fprintf(stderr, "Usage: %s <output> [input]\n", argv[0]); + exit(-1); + } + if (!(yyout = fopen(argv[1], "wb"))) { + fprintf(stderr, "Error: can't open file %s\n", argv[1]); + exit(-1); + } + if (argc == 3) { + if (!(yyin = fopen(argv[2], "rb"))) { + fprintf(stderr, "Error: can't open file %s\n", argv[2]); + exit(-1); + } + } + fprintf(stderr, "Creating file %s\n", argv[1]); + yylex(); + exit(errstate ? -1 : 0); +} + +void yputc(int c, int a) { + line_width += a; + putc(c, yyout); +} + +void unputs(char * s) { + int l = strlen(s), i; + + for (i = l - 1; i >= 0; i--) { + unput(s[i]); + } +} diff --git a/Xenogears/main_dump.cpp b/Xenogears/main_dump.cpp new file mode 100644 index 0000000..2f79a86 --- /dev/null +++ b/Xenogears/main_dump.cpp @@ -0,0 +1,291 @@ +/* + * Xenogears extractor by Nicolas "Pixel" Noble (nicolas@nobis-crew.org) + * Highly based upon Yazoo's Chrono Cross CD extractor + * + * ******** Original disclaimer by Yazoo ******** + * + * Chrono Cross CD extractor Copyright 2000-2001 by Yazoo (hamm@efrei.fr) Revision 0.1b ANSI C + * + * + * Features: + * + * Dump the complete content of Chrono Chross CD1/CD2 US and Japanese version It requires a iso + * named Chrono1.iso in the same directory + * + * Todo list: + * + * Find a way to locate end of the last file Better support for CD2 Dump in subdirectory according + * to CD1/CD2 repartition Recompilation in Visual C++ 6 for disk speed optimisation Source comment + * and reorganisation Log feature (Optional since you can redirect output with > ) Progression + * indicator Better detection of the ISO with error control Major code optimisation Integration in + * main Chrono Cross Hacking tool + * + * ******** End of original disclaimer by Yazoo ******** + * + */ + +#include <stdio.h> +#include <string.h> +#include <stdlib.h> +#include "fileutils.h" +#include "cdutils.h" +#include "generic.h" + +unsigned int tourne = 0; + +struct t_index_tab { + unsigned long address; + long size; + long type; + long index; +}; + +struct t_sequence { + unsigned int n; + unsigned int sum; + char *prefix; + char *name; + int type; +}; + +char *title, *iso_filename, *prefix; +unsigned long iso_size; +unsigned int nb_records, nb_seqs = 0; +struct t_sequence sequences[1000]; + +long check_iso(int f_iso); +void read_files(int f_iso); +void file_dump(int f_iso, unsigned long debut, unsigned long taille, long num, int seq); +int process_def_file(int f_def); + +unsigned char user_data[2352]; + +int main(int argc, char **argv) +{ + int f_def, f_iso; + + verbosity = 3; + + fprintf(stderr, +"Xenogears File Extractor by Nicolas \"Pixel\" Noble\n" +"Highly based upon the Chrono Cross File Extractor By Yazoo\n\n"); + + if (argc != 3) { + fprintf(stderr, "Usage: %s <definition_file.sqr> <iso_file_name>\nSee readme.txt for details\n", + argv[0]); + exit(-1); + } + + printm(M_STATUS, "Processing file %s...\n", argv[1]); + + if ((f_def = open(argv[1], O_RDONLY)) < 0) { + printm(M_ERROR, "Unable to open the definition file \"%s\"...\n", argv[1]); + exit(-1); + } + + if (process_def_file(f_def)) { + close(f_def); + printm(M_ERROR, "Unable to process the definition file \"%s\"...\n", argv[1]); + exit(-1); + } + + iso_filename = argv[2]; + + printm(M_STATUS, "Begin processing iso file.\n"); + if ((f_iso = open(iso_filename, O_RDONLY)) < 0) { + printm(M_ERROR, "Unable to open the iso file \"%s\"...\n", iso_filename); + exit(-1); + } + + if (check_iso(f_iso)) { + printm(M_ERROR, "Invalid iso file for %s\n", title); + printm(M_ERROR, "===> Make sure you are using a Genuine iso file.\n"); + } else { + printm(M_INFO, "Genuine %s iso detected.\n", title); + } + printm(M_STATUS, "Entering files read sequence\n"); + read_files(f_iso); + close(f_iso); + exit(0); +} + +/* + * Ugly but working... for now + */ +int process_def_file(int h_f_def) +{ + char t[1024], *p; + unsigned int n, sum = 0; + FILE * f_def = fdopen(h_f_def, "r"); + + if ((p = strchr(fgets(t, 1024, f_def), '\n')) == NULL) + return 1; + *p = 0; + printm(M_INFO, "Read title: %s\n", t); + title = strdup(t); + + if (fscanf(f_def, "%lu\n", &iso_size) != 1) + return 1; + printm(M_INFO, "Read iso size: %lu bytes\n", iso_size); + + if ((p = strchr(fgets(t, 1024, f_def), '\n')) == NULL) + return 1; + *p = 0; + printm(M_INFO, "Read global directory prefix: %s\n", t); + prefix = strdup(t); + + if (fscanf(f_def, "%u\n", &nb_records) != 1) + return 1; + printm(M_INFO, "Read total of records: %u\n", nb_records); + + while (1) { + if (fscanf(f_def, "%u\n", &n) != 1) + return 1; + if (!n) { + if (sum == nb_records) { + printm(M_INFO, "Definition file seems coherent\n"); + return 0; + } else { + printm(M_ERROR, "Definition file incoherent\n"); + return 1; + } + } + sum += n; + sequences[nb_seqs].n = n; + sequences[nb_seqs].sum = sum; + if ((p = strchr(fgets(t, 1024, f_def), '\n')) == NULL) + return 1; + *p = 0; + sequences[nb_seqs].prefix = strdup(t); + if (fscanf(f_def, "%u\n", &n) != 1) + return 1; + sequences[nb_seqs].type = n; + if ((p = strchr(fgets(t, 1024, f_def), '\n')) == NULL) + return 1; + *p = 0; + sequences[nb_seqs].name = strdup(t); + printm(M_INFO, "Read definition of sequence %i:\n===> %5i (sum = %5i) chunks of %s (%s)\n", + nb_seqs, n, sum, t, sequences[nb_seqs].prefix); + nb_seqs++; + } +} + +long check_iso(int f_iso) +{ + unsigned long length; + + length = filesize(f_iso); + printm(M_INFO, "Filesize of iso file %s is %ld bytes\n", iso_filename, length); + if (length != iso_size) { + return 1; + } + return 0; +} + +void read_files(int f_iso) +{ + t_index_tab index_tab[10000]; + unsigned char t[8]; + unsigned long i; + unsigned long j; + unsigned int seq = 0; + unsigned long indexer; + struct t_index_tab *p = (struct t_index_tab *) t; + + unsigned char fat[32768]; + +#define INDEXPOS 24 + + sector_seek(f_iso, INDEXPOS); + for (i = INDEXPOS; i < (INDEXPOS + 16); i++) { + printm(M_INFO, "Reading fat sector %lu\n", i); + read_sector(f_iso, &fat[2048 * (i - INDEXPOS)], MODE_2_FORM_1); + } + + indexer = 0; + for (j = 0; j < 32768; j = j + 7) { + t[0] = 0; + bcopy((char *) &fat[j], (char *) t + 1, 7); + p->address >>= 8; + index_tab[indexer] = *p; + if (p->size > 0 && p->address != 0) { + index_tab[indexer].index = j / 7; + printm(M_INFO, "Found a quite valid index: number %4lu, address %6lu, size %3li\n", + indexer, index_tab[indexer].address, index_tab[indexer].size); + indexer++; + if (indexer == nb_records) + break; + } else { + printm(M_WARNING, "Ignored invalid index chunk number %4lu (size = %lu) (%02x %02x %02x %02x %02x %02x %02x)\n", + j / 7, -index_tab[indexer].size, t[0], t[1], t[2], t[4], t[5], t[6], t[7]); + } + } + printm(M_STATUS, "Index file generation complete.\n\n"); + + for (i = 0; i < nb_records; i++) { + if (sequences[seq].sum == i) + seq++; + index_tab[i].type = sequences[seq].type; + if (sequences[seq].type == 0) { + printm(M_INFO, "%6lu (%10lu): ignored\n", index_tab[i].address, index_tab[i].size); + } else { + printm(M_INFO, "%6lu (%10lu): ", index_tab[i].address, index_tab[i].size); + file_dump(f_iso, index_tab[i].address, index_tab[i].size, i, seq); + if (verbosity >= M_INFO) { + fprintf(stderr, "\n"); + } + } + } + fprintf(stderr, "\n"); +} + +void file_dump(int f_iso, unsigned long debut, unsigned long taille, long num, int seq) +{ + long i; + long nbsects; + char nom[1000] = ""; + char *extention = ".out"; + char nom_t[1000] = ""; + int f_out; + char type = sequences[seq].type; + char ptitbidule[] = "-\\|/"; + + sprintf(nom_t, "%ld", num); + + strcat(nom, "./"); + + strcat(nom, prefix); + strcat(nom, "/"); + MKDIR(nom); + + strcat(nom, sequences[seq].prefix); + strcat(nom, "/"); + MKDIR(nom); + + if (num < 10) + strcat(nom, "0"); + if (num < 100) + strcat(nom, "0"); + if (num < 1000) + strcat(nom, "0"); + strcat(nom, nom_t); + + strcat(nom, extention); + f_out = open(nom, O_WRONLY | O_CREAT | O_TRUNC, 00644); + nbsects = taille / sec_sizes[type]; + if (taille % sec_sizes[type]) + nbsects++; + sector_seek(f_iso, debut); + for (i = 0; i < nbsects; i++) { + if (verbosity < M_INFO) + fprintf(stderr, " (%c)\010\010\010\010\010", ptitbidule[((tourne++) >> 8) % 4]); + read_sector(f_iso, user_data, type); + if (i != (nbsects - 1)) { + write(f_out, user_data, sec_sizes[type]); + } else { + write(f_out, user_data, taille % sec_sizes[type] ? taille % sec_sizes[type] : sec_sizes[type]); + } + } + close(f_out); + fprintf(stderr, " (*) Dumped file number %4ld - type \"%s\" \r", num, sequences[seq].name); +} diff --git a/Xenogears/map2sqr b/Xenogears/map2sqr new file mode 100755 index 0000000..4621d54 --- /dev/null +++ b/Xenogears/map2sqr @@ -0,0 +1,34 @@ +#!/usr/bin/awk -f +BEGIN { + ol = -1; +} + +NR <= 4 { + print $0; +} + +NR > 4 { + f = $1; + l = $2; + c = l - f + 1; + if ((ol + 1) != f) { + print "You blew it @ line", NR > "/dev/stderr" + exit -1; + } + ol = l; + print c; + + d = $3; + print d; + d = $4; + print d; + for (i = 5; i < NR; i++) { + $(i - 4) = $i; + } + NF -= 4; + print $0; +} + +END { + print 0; +} diff --git a/Xenogears/reinsert.cpp b/Xenogears/reinsert.cpp new file mode 100644 index 0000000..e58b871 --- /dev/null +++ b/Xenogears/reinsert.cpp @@ -0,0 +1,305 @@ +#include <stdio.h> +#include <string.h> +#include <stdlib.h> +#include "fileutils.h" +#include "cdutils.h" +#include "generic.h" + +unsigned int tourne = 0; + +struct t_index_tab { + unsigned long address; + long size; + long type; + long index; +}; + +struct t_sequence { + unsigned int n; + unsigned int sum; + char *prefix; + char *name; + int type; +}; + +char *title, *iso_filename, *tbl_filename, *prefix, *in_filename; +unsigned long iso_size; +unsigned int nb_records, nb_seqs = 0; +struct t_sequence sequences[1000]; + +int slus_index = -1, force = 0; + +long check_iso(int f_iso); +void write_files(int f_iso_r, int f_iso_w, int f_in, int fileindex); +int process_def_file(int f_def); + +unsigned char user_data[2352]; + +void usage(char ** argv) { + fprintf(stderr, "Usage: %s <definition_file.sqr> <iso_file_name> <file_index> <filename> [-f]\nSee readme.txt for details\n", + argv[0]); + exit(-1); +} + +int main(int argc, char **argv) +{ + int f_def, f_iso_r, f_iso_w, f_in; + int fileindex; + + verbosity = 1; + + fprintf(stderr, "Xenogears File Insertor by Nicolas \"Pixel\" Noble\n\n"); + + if ((argc != 5) && (argc != 6)) { + usage(argv); + } + + if (argc == 6) { + if (strcmp(argv[5], "-f")) { + usage(argv); + } else { + force = 1; + } + } + + printm(M_STATUS, "Processing file %s...\n", argv[1]); + + if ((f_def = open(argv[1], O_RDONLY)) < 0) { + printm(M_ERROR, "Unable to open the definition file \"%s\"...\n", argv[1]); + exit(-1); + } + + if (process_def_file(f_def)) { + close(f_def); + printm(M_ERROR, "Unable to process the definition file \"%s\"...\n", argv[1]); + exit(-1); + } + + iso_filename = argv[2]; + + printm(M_STATUS, "Begin processing iso file.\n"); + if ((f_iso_r = open(iso_filename, O_RDONLY)) < 0) { + printm(M_ERROR, "Unable to open the iso file \"%s\"...\n", iso_filename); + exit(-1); + } + + if ((f_iso_w = open(iso_filename, O_WRONLY)) < 0) { + printm(M_ERROR, "Unable to open the iso file \"%s\"...\n", iso_filename); + exit(-1); + } + + if (check_iso(f_iso_r)) { + printm(M_ERROR, "Invalid iso file for %s\n", title); + printm(M_ERROR, "===> Make sure you are using a Genuine iso file.\n"); + } else { + printm(M_INFO, "Genuine %s iso detected.\n", title); + } + + fileindex = atoi(argv[3]); + in_filename = argv[4]; + if ((f_in = open(in_filename, O_RDONLY)) < 0) { + printm(M_ERROR, "Unable to open the file \"%s\"...\n", in_filename); + exit(-1); + } + + printm(M_STATUS, "Entering files write sequence\n"); + write_files(f_iso_r, f_iso_w, f_in, fileindex); + close(f_iso_r); + close(f_iso_w); + exit(0); +} + +/* + * Ugly but working... for now + */ +int process_def_file(int h_f_def) +{ + char t[1024], *p; + unsigned int n, sum = 0; + FILE * f_def = fdopen(h_f_def, "r"); + + if ((p = strchr(fgets(t, 1024, f_def), '\n')) == NULL) + return 1; + *p = 0; + printm(M_INFO, "Read title: %s\n", t); + title = strdup(t); + + if (fscanf(f_def, "%lu\n", &iso_size) != 1) + return 1; + printm(M_INFO, "Read iso size: %lu bytes\n", iso_size); + + if ((p = strchr(fgets(t, 1024, f_def), '\n')) == NULL) + return 1; + *p = 0; + printm(M_INFO, "Read index table filename: %s\n", t); + tbl_filename = strdup(t); + + if ((p = strchr(fgets(t, 1024, f_def), '\n')) == NULL) + return 1; + *p = 0; + printm(M_INFO, "Read global directory prefix: %s\n", t); + prefix = strdup(t); + + if (fscanf(f_def, "%u\n", &nb_records) != 1) + return 1; + printm(M_INFO, "Read total of records: %u\n", nb_records); + + while (1) { + if (fscanf(f_def, "%u\n", &n) != 1) + return 1; + if (!n) { + if (sum == nb_records) { + printm(M_INFO, "Definition file seems coherent\n"); + return 0; + } else { + printm(M_ERROR, "Definition file incoherent\n"); + return 1; + } + } + sum += n; + sequences[nb_seqs].n = n; + sequences[nb_seqs].sum = sum; + if ((p = strchr(fgets(t, 1024, f_def), '\n')) == NULL) + return 1; + *p = 0; + sequences[nb_seqs].prefix = strdup(t); + if (fscanf(f_def, "%u\n", &n) != 1) + return 1; + sequences[nb_seqs].type = n; + if ((p = strchr(fgets(t, 1024, f_def), '\n')) == NULL) + return 1; + *p = 0; + sequences[nb_seqs].name = strdup(t); + printm(M_INFO, "Read definition of sequence %i:\n===> %5i (sum = %5i) chunks of %s (%s)\n", + nb_seqs, n, sum, t, sequences[nb_seqs].prefix); + nb_seqs++; + } +} + +long check_iso(int f_iso) +{ + unsigned long length; + + length = filesize(f_iso); + printm(M_INFO, "Filesize of iso file %s is %ld bytes\n", iso_filename, length); + if (length != iso_size) { + return 1; + } + return 0; +} + +#define INDEXPOS 24 + +void rewrite_fat(int f_iso_r, int f_iso_w, unsigned char * new_fat) { + unsigned char old_fat[34816]; + int i; + + sector_seek(f_iso_w, INDEXPOS); + for (i = INDEXPOS; i < (INDEXPOS + 16); i++) { + printm(M_INFO, "Writing fat sector %lu\n", i); + write_sector(f_iso_r, f_iso_w, &new_fat[2048 * (i - INDEXPOS)], MODE_2_FORM_1); + } + + sector_seek(f_iso_r, slus_index + 1); + for (i = slus_index + 1; i < (slus_index + 18); i++) { + printm(M_INFO, "Reading SLUS sector %lu\n", i); + read_sector(f_iso_r, &old_fat[2048 * (i - slus_index - 1)], MODE_2_FORM_1); + } + + bcopy((char *) new_fat, (char *) old_fat + 4, 32768); + sector_seek(f_iso_w, slus_index + 1); + for (i = slus_index + 1; i < (slus_index + 18); i++) { + printm(M_INFO, "Writing SLUS sector %lu\n", i); + write_sector(f_iso_r, f_iso_w, &old_fat[2048 * (i - slus_index - 1)], MODE_2_FORM_1); + } +} + +void write_files(int f_iso_r, int f_iso_w, int f_in, int fileindex) +{ + t_index_tab index_tab[10000]; + unsigned char t[8]; + unsigned long i; + unsigned long j; + unsigned int seq = 0; + unsigned long indexer; + struct t_index_tab *p = (struct t_index_tab *) t; + + long old_file_size, new_file_size, old_nb_sects, new_nb_sects; + unsigned char fat[32768]; + + sector_seek(f_iso_r, INDEXPOS); + for (i = INDEXPOS; i < (INDEXPOS + 16); i++) { + printm(M_INFO, "Reading fat sector %lu\n", i); + read_sector(f_iso_r, &fat[2048 * (i - INDEXPOS)], MODE_2_FORM_1); + } + + indexer = 0; + for (j = 0; j < 32768; j = j + 7) { + t[0] = 0; + bcopy((char *) &fat[j], (char *) t + 1, 7); + p->address >>= 8; + index_tab[indexer] = *p; + if (p->size > 0 && p->address != 0) { + index_tab[indexer].index = j / 7; + printm(M_INFO, "Found a quite valid index: number %4lu, address %6lu, size %3li\n", + indexer, index_tab[indexer].address, index_tab[indexer].size); + indexer++; + if (indexer == nb_records) + break; + } else { + printm(M_WARNING, "Ignored invalid index chunk number %4lu (size = %lu) (%02x %02x %02x %02x %02x %02x %02x)\n", + j / 7, -index_tab[indexer].size, t[0], t[1], t[2], t[4], t[5], t[6], t[7]); + } + } + printm(M_STATUS, "Index file generation complete.\n\n"); + + for (i = 0; i < nb_records; i++) { + if (sequences[seq].sum == i) + seq++; + index_tab[i].type = sequences[seq].type; + if (!strcmp(sequences[seq].prefix, "SLUS")) { + if (slus_index >= 0) { + printm(M_ERROR, "Two SLUS files defined\n"); + exit(-1); + } + slus_index = index_tab[i].address; + } + } + + if (slus_index < 0) { + printm(M_ERROR, "No SLUS file defined\n"); + exit(-1); + } + + printm(M_INFO, "SLUS file found at sector %6i\n", slus_index); + + new_file_size = filesize(f_in); + old_file_size = index_tab[fileindex].size; + + new_nb_sects = new_file_size / sec_sizes[index_tab[fileindex].type]; + old_nb_sects = old_file_size / sec_sizes[index_tab[fileindex].type]; + + if (new_file_size % sec_sizes[index_tab[fileindex].type]) { + new_nb_sects++; + } + + if (old_file_size % sec_sizes[index_tab[fileindex].type]) { + old_nb_sects++; + } + + if (new_nb_sects > old_nb_sects) { + printm(M_ERROR, "New file too big.\n"); + if (!force) { + exit(-1); + } + } + + printm(M_INFO, "New file size: %12li, old file size: %12li\n", new_file_size, old_file_size); + printm(M_INFO, "New file ssize: %12li, old file ssize: %12li\n", new_nb_sects, old_nb_sects); + + printm(M_INFO, "File address: %6i\n", index_tab[fileindex].address); + + write_file(f_iso_r, f_iso_w, f_in, index_tab[fileindex].type, index_tab[fileindex].address); + *((long *)(&fat[index_tab[fileindex].index * 7 + 3])) = new_file_size; + rewrite_fat(f_iso_r, f_iso_w, fat); +} diff --git a/Xenogears/script-comp.cpp b/Xenogears/script-comp.cpp new file mode 100644 index 0000000..96645df --- /dev/null +++ b/Xenogears/script-comp.cpp @@ -0,0 +1,96 @@ +#include <stdio.h> +#include <stdlib.h> +#include "lz77.h" +#include "fileutils.h" + +void process_one_file(int f, int d, int n) { + char nom_du_fichier[100]; + char zeros[4] = {0, 0, 0, 0}, * datas; + long script_position, true_length, delta, data_length; + int f_part; + + fprintf(stderr, " Copying header\n"); + + lseek(f, 0x14c, SEEK_SET); + read(f, &script_position, 4); + lseek(f, 0, SEEK_SET); + copy(f, d, script_position); + + lseek(f, 0x150, SEEK_SET); + read(f, &script_position, 4); + lseek(f, script_position, SEEK_SET); + + data_length = filesize(f) - script_position; + + datas = (char *) malloc(data_length); + read(f, datas, data_length); + + fprintf(stderr, " Processing script\n"); + sprintf(nom_du_fichier, "xeno_d1/ROOMS/%04i/script.comp", n); + + f_part = open(nom_du_fichier, O_RDONLY); + true_length = filesize(f_part); + + script_position = lseek(d, 0, SEEK_CUR); + lseek(d, 0x14c, SEEK_SET); + write(d, &script_position, 4); + lseek(d, 0x128, SEEK_SET); + write(d, &true_length, 4); + lseek(d, 0, SEEK_END); + + lz77_comp(f_part, d, &delta); + + close(f_part); + + script_position = lseek(d, 0, SEEK_CUR); + if ((true_length = (script_position & 3))) { + write(d, zeros, 4 - true_length); + } + + fprintf(stderr, " Processing extra datas\n"); + script_position = lseek(d, 0, SEEK_CUR); + lseek(d, 0x150, SEEK_SET); + write(d, &script_position, 4); + lseek(d, 0, SEEK_END); + + write(d, datas, data_length); + + free(datas); +} + +int main(int argc, char ** argv) +{ + int f_script_comp, f_new_script; + int i; + int num = 0; + char nom_du_fichier[100]; + + for (i = 384; i < 1844; i = i + 2) { + fprintf(stderr, "CD1 - File %d -> Script %d\n", i, num); + sprintf(nom_du_fichier, "xeno_d1/ROOMS/%04d.out", i); + f_script_comp = open(nom_du_fichier, O_RDONLY); + sprintf(nom_du_fichier, "xeno_d1/ROOMS/%04d.out-new", i); + f_new_script = open(nom_du_fichier, O_WRONLY | O_CREAT | O_TRUNC, 00644); + + process_one_file(f_script_comp, f_new_script, num); + + close(f_script_comp); + num++; + } + num = 0; + + + for (i = 379; i < 1838; i = i + 2) { + fprintf(stderr, "CD2 - File %d -> Script %d\n", i, num); + sprintf(nom_du_fichier, "xeno_d2/ROOMS/%04d.out", i); + f_script_comp = open(nom_du_fichier, O_RDONLY); + sprintf(nom_du_fichier, "xeno_d2/ROOMS/%04d.out-new", i); + f_new_script = open(nom_du_fichier, O_WRONLY | O_CREAT | O_TRUNC, 00644); + + process_one_file(f_script_comp, f_new_script, num); + + close(f_script_comp); + num++; + } + fprintf(stderr, "Done !\n"); +} diff --git a/Xenogears/script-dec.cpp b/Xenogears/script-dec.cpp new file mode 100644 index 0000000..9d4faf3 --- /dev/null +++ b/Xenogears/script-dec.cpp @@ -0,0 +1,69 @@ +#include <stdio.h> +#include <stdlib.h> +#include "lz77.h" +#include "fileutils.h" + +void process_one_file(int f, int d, int n) { + char nom_du_fichier[100]; + long script_position, true_length; + int i; + int f_out; + + if (filesize(f) == 24) return; + + sprintf(nom_du_fichier, "xeno_d%d/ROOMS/%04i", d, n); + MKDIR(nom_du_fichier); + + i = 7; +// for (i = 0; i < 9; i++) { +// fprintf(stderr, " Processing part %i\n", i); + sprintf(nom_du_fichier, "xeno_d%d/ROOMS/%04i/script.comp", d, n); +// sprintf(nom_du_fichier, "xeno_d%d/ROOMS/%04i/part-%i", d, n, i); + f_out = open(nom_du_fichier, O_WRONLY | O_TRUNC | O_CREAT, 00644); + lseek(f, 0x130 + i * 4, SEEK_SET); + read(f, &script_position, 4); + lseek(f, 0x10c + i * 4, SEEK_SET); + read(f, &true_length, 4); + lseek(f, script_position, SEEK_SET); + lz77_decomp(f, f_out, true_length); +// if (i == 7) { +// fseek(f_out, 0, SEEK_SET); +// fread(&true_length, 4, 1, f_out); +// fprintf(stderr, " (seems to be the script number %i)\n", true_length); +// } + close(f_out); +// } +} + +int main(void) +{ + int f_script_comp; + int i; + int num = 0; + char nom_du_fichier[100]; + + for (i = 384; i < 1844; i = i + 2) { + fprintf(stderr, "CD 1 - File %d -> Script %d\n", i, num); + sprintf(nom_du_fichier, "xeno_d1/ROOMS/%04d.out", i); + f_script_comp = open(nom_du_fichier, O_RDONLY); + + process_one_file(f_script_comp, 1, num); + + close(f_script_comp); + num++; + } + + num = 0; + + for (i = 379; i < 1838; i = i + 2) { + fprintf(stderr, "CD 2 - File %d -> Script %d\n", i, num); + sprintf(nom_du_fichier, "xeno_d2/ROOMS/%04d.out", i); + f_script_comp = open(nom_du_fichier, O_RDONLY); + + process_one_file(f_script_comp, 2, num); + + close(f_script_comp); + num++; + } + fprintf(stderr, "Done !\n"); +} diff --git a/Xenogears/test-dlz77.cpp b/Xenogears/test-dlz77.cpp new file mode 100644 index 0000000..98373a6 --- /dev/null +++ b/Xenogears/test-dlz77.cpp @@ -0,0 +1,7 @@ +#include <stdio.h> +#include "lz77.h" + +int main(void) { + lz77_decomp(0, 1); + return 0; +} diff --git a/Xenogears/test-lz77.cpp b/Xenogears/test-lz77.cpp new file mode 100644 index 0000000..8efce98 --- /dev/null +++ b/Xenogears/test-lz77.cpp @@ -0,0 +1,7 @@ +#include <stdio.h> +#include "lz77.h" + +int main(void) { + lz77_comp(0, 1); + return 0; +} |