mirror of
https://github.com/pret/pokeplatinum.git
synced 2026-09-30 21:40:45 -05:00
Make msgenc store encryption keys in gmm files
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
#include "Gmm.h"
|
||||
#include "pugixml.hpp"
|
||||
#include <regex>
|
||||
#include <string>
|
||||
|
||||
static const char WINCTXNAME[] = "window_context_name";
|
||||
static const char LANGUAGE[] = "English";
|
||||
@@ -68,7 +69,7 @@ void GMM::WriteGmmHeader(const string &_filename) {
|
||||
}
|
||||
|
||||
// Reads messages from GMM into memory to be converted
|
||||
void GMM::FromFile(MessagesConverter &converter) {
|
||||
int GMM::FromFile(MessagesConverter &converter) {
|
||||
pugi::xml_parse_result result = doc.load(stream);
|
||||
if (!result) {
|
||||
throw runtime_error(result.description());
|
||||
@@ -77,6 +78,7 @@ void GMM::FromFile(MessagesConverter &converter) {
|
||||
return strcmp(n.name(), "body") == 0;
|
||||
});
|
||||
int i = 0;
|
||||
int key = GMM_KEY_NOT_DEFINED;
|
||||
string rowname_pref = filename.substr(filename.find_last_of('/') + 1).substr(0, filename.find_first_of('.'));
|
||||
for (const auto &subnode : node.children()) {
|
||||
if (strcmp(subnode.name(), "row") == 0) {
|
||||
@@ -105,10 +107,16 @@ void GMM::FromFile(MessagesConverter &converter) {
|
||||
i++;
|
||||
IncRowNoBuf();
|
||||
}
|
||||
if (strcmp(subnode.name(), "key") == 0) {
|
||||
key = stoi(subnode.attribute("value").value(), nullptr, 0);
|
||||
key &= 0xFFFF;
|
||||
key |= 0x10000;
|
||||
}
|
||||
}
|
||||
if (!converter.GetHeaderFilename().empty()) {
|
||||
WriteGmmHeader(converter.GetHeaderFilename());
|
||||
}
|
||||
return key;
|
||||
}
|
||||
|
||||
// Writes decoded messages to a new GMM file
|
||||
@@ -124,6 +132,10 @@ void GMM::ToFile(MessagesConverter &converter) {
|
||||
}
|
||||
string rowname_pref = filename.substr(filename.find_last_of('/') + 1);
|
||||
rowname_pref = rowname_pref.substr(0, rowname_pref.find_first_of('.'));
|
||||
|
||||
auto key = body.append_child("key");
|
||||
key.append_attribute("value").set_value(std::to_string(converter.GetKey()).c_str());
|
||||
|
||||
int i = 0;
|
||||
for (const auto &message : converter.GetDecodedMessages()) {
|
||||
string rowname;
|
||||
|
||||
@@ -19,6 +19,8 @@
|
||||
#include "pugixml.hpp"
|
||||
#include "MessagesConverter.h"
|
||||
|
||||
#define GMM_KEY_NOT_DEFINED -1
|
||||
|
||||
class GMM {
|
||||
static const int _row_no_buf_ndigit = 5;
|
||||
char row_no_buf[_row_no_buf_ndigit + 1] = {0};
|
||||
@@ -46,7 +48,7 @@ public:
|
||||
GMM(string &_filename, ios::openmode _openmode) : filename(_filename), stream(_filename, _openmode) {
|
||||
memset(row_no_buf, '0', _row_no_buf_ndigit);
|
||||
}
|
||||
void FromFile(MessagesConverter &converter);
|
||||
int FromFile(MessagesConverter &converter);
|
||||
void ToFile(MessagesConverter &converter);
|
||||
|
||||
private:
|
||||
|
||||
@@ -30,7 +30,14 @@ void MessagesEncoder::ReadMessagesFromText(string& fname) {
|
||||
}
|
||||
|
||||
void MessagesEncoder::ReadMessagesFromGMM(string& filename) {
|
||||
GMM(filename, std::ios::in).FromFile(*this);
|
||||
int key_from_file = GMM(filename, std::ios::in).FromFile(*this);
|
||||
|
||||
// If key has been specified in the gmm, use
|
||||
// that instead of the command-line value
|
||||
if (key_from_file != GMM_KEY_NOT_DEFINED) {
|
||||
header.key = key_from_file;
|
||||
}
|
||||
|
||||
header.count = vec_decoded.size();
|
||||
debug_printf("%d lines\n", header.count);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user