Last active
March 30, 2016 11:30
-
-
Save awstanley/fccf8795acb798ddbe68aae862f9b131 to your computer and use it in GitHub Desktop.
Dominions 4 Pretender Parser (proof of concept)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdint.h> | |
#include <fstream> | |
#include <string> | |
#include <vector> | |
struct FileHeader | |
{ | |
/* 0 */char header[6]; | |
/* 6 */uint32_t serial; | |
/* 10 */uint32_t version; | |
/* 14 */int godnumber; | |
/* 18 */int turnnbr; | |
/* 22 */int unk2; | |
/* 26 */int unk3; | |
/* 30 */int unk4; | |
/* 34 */int unk5; | |
/* 38 */std::string gameName; // ^0x4F each byte; newlord for pretender files | |
/* ? */char* playerPassword; // read until 0x78 | |
/* ? */char* masterPassword; | |
/* */int unk6; | |
/* */int unk7; | |
}; | |
struct Pretender : public FileHeader | |
{ | |
/* */uint8_t unit[64]; | |
/* */int unk8; | |
/* */int unk9; | |
/* */std::string pretenderName;// ^0x4F each byte | |
}; | |
void parse(std::string fn) | |
{ | |
Pretender p; | |
std::ifstream fp(fn); | |
fp.read(p.header, 6); | |
fp.read((char*)&p.serial, 4); | |
fp.read((char*)&p.version, 4); | |
fp.read((char*)&p.godnumber, 4); | |
fp.read((char*)&p.turnnbr, 4); | |
fp.read((char*)&p.unk2, 4); | |
fp.read((char*)&p.unk3, 4); | |
fp.read((char*)&p.unk4, 4); | |
fp.read((char*)&p.unk5, 4); | |
{ | |
char c; | |
fp.read(&c, 1); | |
while (c != 0x4F) | |
{ | |
c = c ^ 0x4F; | |
p.gameName.push_back(c); | |
fp.read(&c, 1); | |
}; | |
} | |
{ | |
std::vector<char> pw; | |
char c = 0; | |
fp.read(&c, 1); | |
while (c != 0x78) | |
{ | |
pw.push_back(c); | |
fp.read(&c, 1); | |
} | |
if(pw.size() > 0) | |
{ | |
p.playerPassword = new char[pw.size()]; | |
memcpy(p.playerPassword, &pw[0], pw.size()); | |
} | |
} | |
{ | |
std::vector<char> pw; | |
char c = 0; | |
fp.read(&c, 1); | |
while (c != 0x78) | |
{ | |
pw.push_back(c); | |
fp.read(&c, 1); | |
} | |
if(pw.size() > 0) | |
{ | |
p.masterPassword = new char[pw.size()]; | |
memcpy(p.masterPassword, &pw[0], pw.size()); | |
} | |
} | |
fp.read((char*)&p.unk6, 4); | |
fp.read((char*)&p.unk7, 4); | |
fp.read((char*)&p.unit, 64); | |
fp.read((char*)&p.unk8, 4); | |
fp.read((char*)&p.unk9, 4); | |
{ | |
char c; | |
fp.read(&c, 1); | |
while (c != 0x4F) | |
{ | |
c = c ^ 0x4F; | |
p.pretenderName.push_back(c); | |
fp.read(&c, 1); | |
}; | |
} | |
printf("game: `%s`\npretender:`%s`\n", p.gameName.c_str(), p.pretenderName.c_str()); | |
} | |
int main(int argc, char **argv) | |
{ | |
parse(argv[1]); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment