Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Manual fixes required for EU4 gamestate data before parsing #39

Closed
tommy5dollar opened this issue Aug 3, 2020 · 3 comments
Closed

Manual fixes required for EU4 gamestate data before parsing #39

tommy5dollar opened this issue Aug 3, 2020 · 3 comments

Comments

@tommy5dollar
Copy link

Hello,

I'm playing an EU4 (v1.30.3) multiplayer game on a weekly basis and parsing the save game to calculate session scores based on some rules we've set.

Essentially once I've unzipped the gamestate file from the save and read it in as a string I go to parse it but encounter some errors. I've manually fixed these on the string before parsing and it now works fine but wondering if I can contribute any examples or help to get these fixed? I'm unsure if they're corruptions that have crept into the file or just weird syntactic edge cases.

I've attached the save mp_Dithmarschen1500_09_10.zip and here's the bodgy code I've put together to fix the string:

  const fixedGamestateString = gamestateString
    .split(`map_area_data{`)
    .join(`map_area_data={`)
    .split(`
{
\t\t\t}`)
    .join(``)
    .split(`
{STK\t\t\t}`).
    join(``)
    .split(`
{AKT\t\t\t}`)
    .join(``)
@nickbabcock
Copy link
Owner

Thanks for the report. I don't know what would cause this issue offhand. The good news is that I'm working on an updated engine that handles your attached save flawlessly. In the meantime, if I or someone else comes across a bugfix for this, I'll create a new release.

@nickbabcock
Copy link
Owner

nickbabcock commented Aug 7, 2020

Please try installing the @next package.

npm i jomini@next

It contains the new engine. Below is some sample code to get you started:

const { readFileSync, writeFileSync } = require("fs");
const { Jomini } = require("jomini");
const args = process.argv.slice(2);
if (args.length !== 1) {
  console.info("expected one argument for the file path");
  process.exit(1);
}

console.time("read file");
const buffer = readFileSync(args[0]);
console.timeLog("read file");

(async function () {
  let start = process.hrtime();
  console.time("initialize jomini");
  const parser = await Jomini.Initialize();
  console.timeLog("initialize jomini");

  console.time("parse text");
  const data = parser.parseText(buffer);
  console.timeLog("parse text");

  console.time("stringify json");
  const json = JSON.stringify(data, null, 2);
  console.timeLog("stringify json")

  const outFile = `${args[0]}.json`
  writeFileSync(outFile, json);
  console.log(`json written to ${outFile}`)
})();

The new engine is 3x faster and uses a third of the memory. I've tested on your uploaded save and it works as far as I know. Let me know if this works for you.

@nickbabcock
Copy link
Owner

Fixed in latest release

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants