#include <conio.h> #include <iostream> unsigned char buff[0x7fffff]; unsigned int end; //offset of russian strings unsigned char s[1024]; unsigned int retpos; //return here after russian unsigned char cl[13] = {0x08, 0x08, 0x08, 0x02 , 0xE3 , 0x89 , 0x04, 0x00, 0x02, 0x7F, 0x98, 0x04, 0x00}; //prompt for click unsigned char ro = 250; //max len of string unsigned char todo_en; //must be 0x06 or 0x14 unsigned char size_en; //size of engish string unsigned char jmp = 0x06; //jumps to xx xx xx xx in LE unsigned char stl = 0x0E; //indicates new sring int ts; int k; unsigned char d; int parts; FILE *en; FILE *trans; FILE *text; char str1[255]; void main() { en = fopen("MemoriaENO.hcb", "rb"); //non-modifed english script text = fopen("text.txt", "r"); //translated strings trans = fopen("MemoriaEN.hcb", "wb"); //translated script rewind(trans); rewind(text); fseek(en, 0, SEEK_END); end = ftell(en); //begin writing localization here rewind(en); fread(buff, end, 1, en); fwrite(buff, end, 1, trans); fseek(en, 0x45798e, SEEK_SET); do { s[0] = '\0'; ts = 0; do { fscanf(text, "%c", &s[ts]); ts++; } while (s[ts-1] != 0); fseek(text, 4, SEEK_CUR); //get new string, terminated with \0 fseek(trans, ftell(en), SEEK_SET); fread(&todo_en, 1, 1, en); //if ((todo_en) != 14) break; fread(&size_en, 1, 1, en); fseek(en, size_en, SEEK_CUR); retpos = ftell(en); //english string begin + len = return here after russian fwrite(&jmp, 1, 1, trans); fwrite(&end, 4, 1, trans); //jump to the russian line fseek(trans, end, SEEK_SET); if (ts <= ro) { //if length of line < byte, just write it fwrite(&stl, 1, 1, trans); fwrite(&ts, 1, 1, trans); fwrite(s, ts, 1, trans); end += (ts + 2 + 5); } else { //get maximum amount of words, which does not exceed byte //and write it end += (ts + 2 + 5); do { str1[0] = '\0'; memcpy(str1, &s, ro); strrev(str1); d = strcspn(str1, " "); strrev(str1); str1[ro-d] = '\0'; d = strlen(str1); memcpy(s, &s[d], ts - d); ts -= (d + 1); str1[d-1] = 0x00; fwrite(&stl, 1, 1, trans); fwrite(&d, 1, 1, trans); fwrite(&str1, d, 1, trans); fwrite(cl, 13, 1, trans); end += 15; } while (ts > ro); //write the remaining part of line s[ts] = 0x00; fwrite(&stl, 1, 1, trans); fwrite(&ts, 1, 1, trans); fwrite(&s, ts+1, 1, trans); } fwrite(&jmp, 1, 1, trans); fwrite(&retpos, 4, 1, trans); //jump back to english fseek(en, 5, SEEK_CUR); if (retpos == 0x732aaf) break; //exit in case of last line } while (true); fclose(en); fclose(trans); fclose(text); }