mirror of
https://github.com/pret/pokeheartgold.git
synced 2024-12-04 11:13:34 +00:00
Fix bug with strvar dumping
This commit is contained in:
parent
122fd8fd3a
commit
048dd786a8
@ -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;
|
||||
|
@ -96,6 +96,8 @@ public:
|
||||
uint16_t GetKey() {
|
||||
return header.key;
|
||||
}
|
||||
|
||||
void WriteBinaryDecoded(string &filename);
|
||||
};
|
||||
|
||||
#endif //GUARD_MESSAGESCONVERTER_H
|
||||
|
@ -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)
|
||||
|
@ -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;
|
||||
|
Loading…
Reference in New Issue
Block a user