Абмеркаванні » Greasy Fork Feedback

Help needed decoding Imperia Online dynamic_map_objects.php response

Hi everyone,

I’m working on a custom userscript for Imperia Online and trying to decode the response from:

`/imperia/game_v5/game/json/dynamic_map_objects.php?b=XXXX`

The server returns compressed/encoded data which is not standard JSON.
Example output looks like this:


This is not gzip (even with Accept-Encoding set), not a typical atob JSON, and not a PNG or any other known format. It looks like a custom chunked encoding where characters like `D I Y A N` represent the length of the next segment before decoding.

I already extracted part of the decoding logic from the game JS:

```js
window.mapResponseDecodeKeys = {
D: 6,
I: 7,
Y: 8,
A: 9,
N: 10
};

function decodeMapResponse(response) {
let k = 0;
let decoded = '';
while (k < response.length - 1) {
const key = response[k];
const len = mapResponseDecodeKeys[key];
decoded += response.substr(k + 1, len);
k += len + 1;
}
return JSON.parse(atob(decoded));
}


async function scanRange(start, end, out) {
for (let b = start; b <= end; b++) {
const raw = await fetch(`/imperia/game_v5/game/json/dynamic_map_objects.php?b=${b}`).then(r => r.text());
if (!raw.trim()) continue;

try {
const data = decodeMapResponse(raw);
// ...
} catch (err) {
console.warn("Block error", b, err);
}
}
}



This works on some blocks (example: b=1637) but most blocks return empty values or result in Unexpected end of JSON input or InvalidCharacterError on atob().

I’m scanning the whole map like this:

async function scanRange(start, end, out) {
for (let b = start; b <= end; b++) {
const raw = await fetch(`/imperia/game_v5/game/json/dynamic_map_objects.php?b=${b}`).then(r => r.text());
if (!raw.trim()) continue;

try {
const data = decodeMapResponse(raw);
// ...
} catch (err) {
console.warn("Block error", b, err);
}
}
}


Question:
Does anyone know the full decoding logic for this data format?
Am I missing additional obfuscation, compression or XOR step before atob()?
It feels like the returned string is incomplete unless certain request headers are used.

Any documentation, tips, tools or example scripts would be really appreciated.

Thanks!

uP!

Post reply

Sign in to post a reply.