Fix bug with strvar dumping

This commit is contained in:
PikalaxALT 2021-08-27 14:48:02 -04:00
parent 122fd8fd3a
commit 048dd786a8
4 changed files with 28 additions and 4 deletions

View File

@ -80,4 +80,18 @@ uint16_t MessagesConverter::CalcCRC()
return crc;
}
void MessagesConverter::WriteBinaryDecoded(string &filename)
{
ofstream outfile(filename, ios::binary);
if (!outfile.good()) {
throw ios::failure("Unable to open file " + filename + " for writing");
}
outfile.write((char *)&header, sizeof(header));
outfile.write((char *)alloc_table.data(), alloc_table.size() * sizeof(MsgAlloc));
for (auto msg : vec_encoded) {
outfile.write((char *)msg.data(), msg.size() * 2);
}
outfile.close();
}
MessagesConverter::~MessagesConverter() = default;

View File

@ -96,6 +96,8 @@ public:
uint16_t GetKey() {
return header.key;
}
void WriteBinaryDecoded(string &filename);
};
#endif //GUARD_MESSAGESCONVERTER_H

View File

@ -116,12 +116,14 @@ string MessagesDecoder::DecodeMessage(u16string &message, int &i) {
decoded += command;
int nargs = message[j++];
debug_printf("%04X ", nargs);
if (is_strvar) {
decoded += ' ';
decoded += to_string(code & 0xFF);
if (nargs != 0)
decoded += ',';
}
for (int k = 0; k < nargs; k++) {
decoded += ' ';
if (is_strvar) {
decoded += to_string(code & 0xFF) + ", ";
is_strvar = false;
}
decoded += to_string(message[j + k]);
debug_printf("%04X ", message[j + k]);
if (k != nargs - 1)

View File

@ -25,6 +25,7 @@ static inline void usage() {
cout << "-k KEY The 16-bit encryption key for this message bank. Default: computes it from the binary file name" << endl;
cout << "-v Print the program version and exit." << endl;
cout << "-h Print this message and exit." << endl;
cout << "-D DUMPNAME Dump the intermediate binary (after decryption or before encryption)." << endl;
}
struct Options {
@ -35,6 +36,7 @@ struct Options {
string charmap;
bool printUsage = false;
bool printVersion = false;
string dumpBinary;
Options(int argc, char ** argv) {
for (int i = 1; i < argc; i++) {
string arg(argv[i]);
@ -55,6 +57,8 @@ struct Options {
key |= 0x10000;
} else if (arg == "-c") {
charmap = argv[++i];
} else if (arg == "-D") {
dumpBinary = argv[++i];
} else if (arg[0] != '-') {
posargs.push_back(arg);
} else {
@ -100,6 +104,8 @@ int main(int argc, char ** argv) {
converter->ReadInput();
converter->ReadCharmap();
converter->Convert();
if (!options.dumpBinary.empty())
converter->WriteBinaryDecoded(options.dumpBinary);
converter->WriteOutput();
if (options.mode == CONV_DECODE) {
cout << "Key: " << hex << converter->GetKey() << endl;