diff options
author | Pixel <Pixel> | 2002-05-04 17:53:08 +0000 |
---|---|---|
committer | Pixel <Pixel> | 2002-05-04 17:53:08 +0000 |
commit | 24fb33726eca4e8c5a88797adc9c17f4d541f543 (patch) | |
tree | 72b385bd9e880e699e43c7db3ba12817f0e8e45e /Xenogears/Decrypt.cpp |
Initial revision
Diffstat (limited to 'Xenogears/Decrypt.cpp')
-rw-r--r-- | Xenogears/Decrypt.cpp | 507 |
1 files changed, 507 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); + } + } +} |