From 24fb33726eca4e8c5a88797adc9c17f4d541f543 Mon Sep 17 00:00:00 2001 From: Pixel Date: Sat, 4 May 2002 17:53:08 +0000 Subject: Initial revision --- Xenogears/Decrypt.cpp | 507 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 507 insertions(+) create mode 100644 Xenogears/Decrypt.cpp (limited to 'Xenogears/Decrypt.cpp') 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 +#include + +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, "\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) // "" + { + break; + } else if (val == 0x01) // "\n" + { + fprintf(f_cible, "\n"); + } else if (val == 0x02) // "" + { + fprintf(f_cible, "\n"); + } else if (val == 0x03) // "" + { + fprintf(f_cible, ""); + } else if (val == 0x0F) // " + { + fread((unsigned char *) &temp1, 1, 1, f_source); + fread((unsigned char *) &temp2, 1, 1, f_source); + if (temp1 == 0) { + fprintf(f_cible, "", temp2); + } else if (temp1 == 5) { + switch (temp2) { + case 0: + fprintf(f_cible, ""); + break; + case 1: + fprintf(f_cible, ""); + break; + case 2: + fprintf(f_cible, ""); + break; + case 3: + fprintf(f_cible, ""); + break; + case 4: + fprintf(f_cible, ""); + break; + case 5: + fprintf(f_cible, ""); + break; + case 6: + fprintf(f_cible, ""); + break; + case 7: + fprintf(f_cible, ""); + break; + case 8: + fprintf(f_cible, ""); + break; + case 9: + fprintf(f_cible, ""); + break; + case 10: + fprintf(f_cible, ""); + break; + case 11: + fprintf(f_cible, ""); + break; + case 12: + fprintf(f_cible, ""); + break; + case 13: + fprintf(f_cible, ""); + break; + case 14: + fprintf(f_cible, ""); + break; + case 15: + fprintf(f_cible, ""); + break; + case 16: + fprintf(f_cible, ""); + break; + case 17: + fprintf(f_cible, ""); + break; + case 18: + fprintf(f_cible, ""); + break; + case 19: + fprintf(f_cible, ""); + break; + case 20: + fprintf(f_cible, ""); + break; + case 21: + fprintf(f_cible, ""); + break; + case 22: + fprintf(f_cible, ""); + break; + case 23: + fprintf(f_cible, ""); + break; + case 24: + fprintf(f_cible, ""); + break; + case 25: + fprintf(f_cible, ""); + break; + case 26: + fprintf(f_cible, ""); + break; + case 27: + fprintf(f_cible, ""); + break; + case 28: + fprintf(f_cible, ""); + break; + case 128: + fprintf(f_cible, ""); + break; + case 129: + fprintf(f_cible, ""); + break; + case 130: + fprintf(f_cible, ""); + break; + default: + fprintf(f_cible, "", temp2); + } + } else { + fprintf(f_cible, "", 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) // "" + { + fprintf(f_cible, ""); + } else if (val == 0x6F) // "" + { + fprintf(f_cible, ""); + } else if (val == 0x70) // "" + { + fprintf(f_cible, ""); + } else if (val == 0x71) // "<*>" + { + fprintf(f_cible, "<*>"); + } else if (val == 0x72) // "" + { + fprintf(f_cible, ""); + } else if (val == 0x73) // "" + { + fprintf(f_cible, ""); + } else if (val == 0x74) // "" + { + fprintf(f_cible, ""); + } else if (val == 0x75) // "" + { + fprintf(f_cible, ""); + } 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) // "" + { + fprintf(f_cible, ""); + } 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) // " + { + fread((unsigned char *) &temp1, 1, 1, f_source); + fprintf(f_cible, "", temp1); + } else if (val == 0xFF) // " + { + fread((unsigned char *) &temp1, 1, 1, f_source); + fprintf(f_cible, "", temp1); + } else { + fprintf(f_cible, "", val); + } + + position = ftell(f_source); + } + fprintf(f_cible, "\n\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, "\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); + } + } +} -- cgit v1.2.3