diff options
| author | Cleverking2003 <30466983+Cleverking2003@users.noreply.github.com> | 2020-08-09 19:40:52 +0300 | 
|---|---|---|
| committer | GitHub <noreply@github.com> | 2020-08-09 19:40:52 +0300 | 
| commit | c259e6ed18294c001033fed62d924d379276021a (patch) | |
| tree | c036aa40000313bb66e8b2c2dd6da81505916284 /tools/msgenc | |
| parent | 8c3282cded0a1f6a54160e7166bfea23ec31da7e (diff) | |
| parent | ce9522e71ee209b7381bf87a4f09fe2f92f65b0e (diff) | |
Merge pull request #260 from PikalaxALT/pikalax_work
Text commands
Diffstat (limited to 'tools/msgenc')
| -rw-r--r-- | tools/msgenc/msgenc.cpp | 36 | 
1 files changed, 29 insertions, 7 deletions
| diff --git a/tools/msgenc/msgenc.cpp b/tools/msgenc/msgenc.cpp index 24bcda8d..232a3bee 100644 --- a/tools/msgenc/msgenc.cpp +++ b/tools/msgenc/msgenc.cpp @@ -29,6 +29,11 @@ using namespace std;  string ReadTextFile(string filename) {      fstream file(filename); +    if (!file.good()) { +        stringstream s; +        s << "unable to open file \"" << filename << "\" for reading"; +        throw runtime_error(s.str()); +    }      stringstream ss;      ss << file.rdbuf();      file.close(); @@ -63,6 +68,11 @@ static vector<u16string> outfiles;  void read_key(string keyfname) {      fstream keyfile(keyfname, ios_base::in | ios_base::binary); +    if (!keyfile.good()) { +        stringstream s; +        s << "unable to open file \"" << keyfname << "\" for reading"; +        throw runtime_error(s.str()); +    }      keyfile.read((char *)&header.key, 2);  } @@ -89,6 +99,17 @@ uint16_t enc_short(uint16_t value, uint16_t & seed) {      return value;  } +static map<string, uint16_t> cmdmap = { +    {"STRVAR", 0x0100}, +    {"YESNO", 0x200}, +    {"PAUSE", 0x201}, +    {"WAIT", 0x202}, +    {"CURSOR_X", 0x203}, +    {"CURSOR_Y", 0x204}, +    {"COLOR", 0xFF00}, +    {"SIZE", 0xFF01} +}; +  void encode_messages() {      int i = 1;      for (auto message : files) { @@ -102,13 +123,10 @@ void encode_messages() {                  size_t pos = enclosed.find(' ');                  string command = enclosed.substr(0, pos);                  enclosed = enclosed.substr(pos + 1); -                uint16_t command_i = charmap[command]; -                if (command_i != 0 || command == "STRVAR") { +                if (cmdmap.find(command) != cmdmap.end()) { +                    uint16_t command_i = cmdmap[command];                      encoded += enc_short(0xFFFE, seed);                      vector<uint16_t> args; -                    if (command_i != 0) { -                        args.push_back(command_i); -                    }                      do {                          k = enclosed.find(',');                          string num = enclosed.substr(0, k); @@ -116,8 +134,12 @@ void encode_messages() {                          args.push_back(num_i);                          enclosed = enclosed.substr(k + 1);                      } while (k++ != string::npos); -                    encoded += enc_short(args[0], seed); -                    args.erase(args.begin()); + +                    if (command == "STRVAR") { +                        command_i |= args[0]; +                        args.erase(args.begin()); +                    } +                    encoded += enc_short(command_i, seed);                      encoded += enc_short(args.size(), seed);                      for (auto num_i : args) {                          encoded += enc_short(num_i, seed); | 
