Hey guys. I'm currently working on a program that extracts text from a specific game. The program works but it is extremely slow. If I try to extract 200kb of text it takes 2 minutes.
The program extracts text by reading bytes from a file and converting them into letters.
This is the code that converts bytes into letters:
void BinaryToString(){ //Find the letter/string equivalent of the hex character.
ifstream table (Tablefilename);
while (Byte!=0x0){
Byte=(int)Buffer[BufferPosition]&Mask;
if (Byte==0x0){
break;
}
if (Byte>0x80){ //Increase the pointer by 2 if the letter is an SJIS character.
Pointer=Pointer+0x02;
Buffer0=(int)Buffer[BufferPosition]&Mask;
Buffer1=(int)Buffer[BufferPosition+1]&Mask;
Byte=(Buffer0<<8)|(Buffer1);
BufferPosition=BufferPosition+0x02;
if (PT_Type=="-fl"){
TextAddress=TextAddress+0x02;}
}
elseif (Byte<0x80&Byte!=0x0){ //Increase the pointer by 1 if the letter is an Ascii character.
Pointer=Pointer+0x01;
BufferPosition=BufferPosition+0x01;
if (PT_Type=="-fl"){
TextAddress=TextAddress+0x01;}
}
while (getline(table,line)){ //Read the table file line by line; until the letter is found.
number=line.substr(0,line.find('=')); //Save the number of the table string.
letter=line.erase(0,line.find('=')+0x1); //Save the letter of the table string.
stringstream str;
str<<hex<<number;
str>>hex>>tablebyte;
if (tablebyte==Byte){ //Do this routine once the correct letter has been found.
TextString=TextString+letter;
table.close();
BinaryToString();
}
}}
}
It then writes every string into a buffer and puts it into an output file.
Here's the code that writes the string buffer to a file: outfile<<output;
It's fine for small 1kb files, but how can I make my code write 200kb faste