/* Lunar Dragon Song English Script Dumper By Tristan Wilkinson AKA Twilkitri Began: 18/11/2014 Hardcoded to take in lunardsscript.lgs and output lunardsscript.txt because I am lazy */ /* Preprocessor */ //Includes #include //Defines #define TABLE_BASE 0x174454 #define ENTRIES_START 0x174464 #define NUM_ENTRIES 0x17E2 #define LUNARDSSCRIPT_START 0x08 #define LUNARDSSCRIPT_END 0x0C84 #define MAX_CHARS_ON_LINE 30 #define ROM_NAME "0026_0281E0-lunardsscript.lgs" #define OUT_NAME "0026_0281E0-lunardsscript.txt" //Function Prototypes /* Main */ int main(int argc, char* argv[]) { unsigned char textarg1; unsigned char dumping; unsigned char nextchar; FILE *out; FILE *rom; unsigned int entryloc; unsigned int curentry; unsigned int charsonline; rom = fopen(ROM_NAME, "rb"); if(!rom) { printf("Could not open ROM file ROM_NAME. Please ensure that this file exists~\n"); return 1; } out = fopen(OUT_NAME, "wb"); if(!out) { printf("Could not open output file OUT_NAME. Please ensure that this file does not already exist and is in use by say MICROSOFT WORD AS YOU ARE CONSTANTLY FORGETTING.\n"); fclose(rom); return 1; } ///* Main Loop */ //curentry = 0; //while(curentry < NUM_ENTRIES) //{ ////Move to entry location //fseek(rom, ENTRIES_START + (curentry * 0x04), SEEK_SET); ////Collect entry location //entryloc = fgetc(rom); //entryloc += fgetc(rom) << 8; //entryloc += fgetc(rom) << 16; //entryloc += TABLE_BASE; ////Move to entry //fseek(rom, entryloc, SEEK_SET); fseek(rom, LUNARDSSCRIPT_START, SEEK_SET); ////Identification //fprintf(out, "Entry: 0x%04X ][ Loc: 0x%06X (0x%06X)\n", curentry, entryloc, ENTRIES_START + (curentry * 0x04)); charsonline = 0; //Dump entry dumping = 1; while(dumping) { //get next character nextchar = fgetc(rom); switch(nextchar) { //0 case 0x00: fprintf(out, " "); charsonline++; break; case 0x02: fprintf(out, "A"); charsonline++; break; case 0x03: fprintf(out, "B"); charsonline++; break; case 0x04: fprintf(out, "C"); charsonline++; break; case 0x05: fprintf(out, "D"); charsonline++; break; case 0x06: fprintf(out, "E"); charsonline++; break; case 0x07: fprintf(out, "F"); charsonline++; break; case 0x08: fprintf(out, "G"); charsonline++; break; case 0x09: fprintf(out, "H"); charsonline++; break; case 0x0A: fprintf(out, "I"); charsonline++; break; case 0x0B: fprintf(out, "J"); charsonline++; break; case 0x0C: fprintf(out, "K"); charsonline++; break; case 0x0D: fprintf(out, "L"); charsonline++; break; case 0x0E: fprintf(out, "M"); charsonline++; break; case 0x0F: fprintf(out, "N"); charsonline++; break; //1 case 0x10: fprintf(out, "O"); charsonline++; break; case 0x11: fprintf(out, "P"); charsonline++; break; case 0x12: fprintf(out, "Q"); charsonline++; break; case 0x13: fprintf(out, "R"); charsonline++; break; case 0x14: fprintf(out, "S"); charsonline++; break; case 0x15: fprintf(out, "T"); charsonline++; break; case 0x16: fprintf(out, "U"); charsonline++; break; case 0x17: fprintf(out, "V"); charsonline++; break; case 0x18: fprintf(out, "W"); charsonline++; break; case 0x19: fprintf(out, "X"); charsonline++; break; case 0x1A: fprintf(out, "Y"); charsonline++; break; case 0x1B: fprintf(out, "Z"); charsonline++; break; //2 case 0x24: fprintf(out, "!"); charsonline++; break; case 0x25: fprintf(out, "?"); charsonline++; break; case 0x26: fprintf(out, "-"); charsonline++; break; case 0x29: fprintf(out, ","); charsonline++; break; case 0x2A: fprintf(out, "."); charsonline++; break; //3 case 0x30: fprintf(out, "0"); charsonline++; break; case 0x31: fprintf(out, "1"); charsonline++; break; case 0x32: fprintf(out, "2"); charsonline++; break; case 0x33: fprintf(out, "3"); charsonline++; break; case 0x34: fprintf(out, "4"); charsonline++; break; case 0x35: fprintf(out, "5"); charsonline++; break; case 0x36: fprintf(out, "6"); charsonline++; break; case 0x37: fprintf(out, "7"); charsonline++; break; case 0x38: fprintf(out, "8"); charsonline++; break; case 0x39: fprintf(out, "9"); charsonline++; break; case 0x3A: fprintf(out, "a"); charsonline++; break; case 0x3B: fprintf(out, "b"); charsonline++; break; case 0x3C: fprintf(out, "c"); charsonline++; break; case 0x3D: fprintf(out, "d"); charsonline++; break; case 0x3E: fprintf(out, "e"); charsonline++; break; case 0x3F: fprintf(out, "f"); charsonline++; break; //4 case 0x40: fprintf(out, "g"); charsonline++; break; case 0x41: fprintf(out, "h"); charsonline++; break; case 0x42: fprintf(out, "i"); charsonline++; break; case 0x43: fprintf(out, "j"); charsonline++; break; case 0x44: fprintf(out, "k"); charsonline++; break; case 0x45: fprintf(out, "l"); charsonline++; break; case 0x46: fprintf(out, "m"); charsonline++; break; case 0x47: fprintf(out, "n"); charsonline++; break; case 0x48: fprintf(out, "o"); charsonline++; break; case 0x49: fprintf(out, "p"); charsonline++; break; case 0x4A: fprintf(out, "q"); charsonline++; break; case 0x4B: fprintf(out, "r"); charsonline++; break; case 0x4C: fprintf(out, "s"); charsonline++; break; case 0x4D: fprintf(out, "t"); charsonline++; break; case 0x4E: fprintf(out, "u"); charsonline++; break; case 0x4F: fprintf(out, "v"); charsonline++; break; //5 case 0x50: fprintf(out, "w"); charsonline++; break; case 0x51: fprintf(out, "x"); charsonline++; break; case 0x52: fprintf(out, "y"); charsonline++; break; case 0x53: fprintf(out, "z"); charsonline++; break; case 0x54: fprintf(out, "'"); charsonline++; break; case 0x5A: //Vertically centered (as opposed to 0x2A), but I don't think we need to care about that detail fprintf(out, "."); charsonline++; break; case 0x5B: fprintf(out, "~"); charsonline++; break; //6 //7 //8 //9 //A //B //C //D //E //F case 0xFB: textarg1 = fgetc(rom); switch(textarg1) { case 0x01: fprintf(out, "[to-green]"); break; case 0x02: //Duplicate of 0x03? fprintf(out, "[to-pink-v2]"); break; case 0x03: fprintf(out, "[to-pink]"); break; case 0x04: fprintf(out, "[to-blue]"); break; case 0x06: fprintf(out, "[to-yellow]"); break; case 0x07: fprintf(out, "[to-white]"); break; default: fprintf(out, "[to-colour-%02X]", textarg1); break; } break; case 0xFC: fprintf(out, "[clear-text]\r\n"); charsonline = 0; break; case 0xFD: fprintf(out, "[manual-linebreak]\r\n"); charsonline = 0; break; case 0xFE: fprintf(out, "[wait-for-button]\r\n"); break; case 0xFF: fprintf(out, "[end]\r\n\r\n"); charsonline = 0; break; default: fprintf(out, "[x%02X]", nextchar); charsonline++; break; } if(charsonline >= MAX_CHARS_ON_LINE) { fprintf(out, " "); charsonline = 0; } if(ftell(rom) >= LUNARDSSCRIPT_END) { dumping = 0; } } // fprintf(out, "\n\n"); // //next entry // curentry++; //} //cleanup fclose(out); fclose(rom); return 0; }