Staredit Network > Forums > SC1 Mapping Tools > Topic: Tool to parse .chk format into JSON/Python objects
Tool to parse .chk format into JSON/Python objects
Mar 4 2019, 4:24 pm
By: sethmachine  

Mar 4 2019, 4:24 pm sethmachine Post #1



Hi,

Before I go making this in Python, is there a well documented, commented, and existing codebase for the sole purpose of turning the data in the .chk file into human friendly JSON objects or Python objects? There are dozens of previous projects that have to parse the .chk format, but they muddle it all with other goals (e.g. creating a new GUI editor) and for some reason almost always choose C++ instead of Python. I don't want the GUI, just literally two functions that parse .chk into JSON and parse JSON back into .chk.

The format is well documented here: http://www.starcraftai.com/wiki/CHK_Format (let me know if this not up to date), and while it's straightforward to implement a .chk reader, it would take some time to write all the code to parse the bytes, and then create the appropriate code package up JSON data back into the bytes for a valid .chk file.

I did this for Warcraft 3 terrain format, to go from the .w3e to JSON and back. See this for what I'm looking for: https://github.com/sethmachine/pyw3x/blob/master/pyw3x/terrain.py. It made manipulating terrain very intuitive and easy. So I don't understand why nobody has ever created a .chk to JSON and back library.

And here is the kind of code I'm looking for for unpacking/packing those bytes: https://github.com/sethmachine/pyw3x/blob/master/pyw3x/terrain_tiles.py. Note how each unpack method is documented with a doctoring that explains what is being unpacked and its possible values.

If this doesn't exist that's fine and I'll implement it, but it seems like it would be the first step to any modding project--to abstract away parsing the .chk into human friendly JSON/objects and use that as a dependency for mods / custom GUI editors. E.g. if I need to extract files from an MPQ archive, I use an existing library that does this for me, and I sure as hell wouldn't write my own code to do this because it doesn't make sense to repeat work. It seems like everyone does this in their own projects--writes their own .chk reader/packager rather than re-use a central .chk reader library.

Thanks!

Post has been edited 1 time(s), last time on Mar 4 2019, 4:57 pm by sethmachine.



None.

Mar 4 2019, 4:46 pm poiuy_qwert Post #2

PyMS and ProTRG developer

I think the closest thing to what you are looking for would be PyMS, which parses a .chk into Python objects (and if you really wanted to, it wouldn't be that hard to map those objects to json). It is not well documented, and not thoroughly tested, since there are not many people who have wanted to use it, but I am always willing to provide help and updates. A basic example was provided in your other thread




Mar 13 2019, 7:59 pm X405 Post #3



I've implemented something rudimentary in Python here.

I used it for a very specific project and I mostly cared about reading the MTXM section (in-game tiles). It ignores most other sections. Documentation/comments/heredocs are non-existent. Also writing CHK files is not implemented (although I'm planning to at some point). In theory it directly reads SCM/SCX files - but that would be tricky to use without some documentation on my side.

If it looks like something you could use, I can implement the sections you are interested in and document the usage. Pull requests are welcome too.




Mar 14 2019, 12:10 am sethmachine Post #4



Thanks!

I am looking for a library that has very high standards for documentation, including near obligatory type annotations.

I decided to start this myself in a project called chkjson. It is very early and not ready for use yet. I don't aim to support parsing every section, only the ones I need like TRG, MRGN, and STR. Right now I just created the part that compiles and decompiles the "STR " section.

If you look at the project, you can get an idea of the kind of library I am looking for.

See: https://github.com/sethmachine/chkjson




Mar 14 2019, 12:30 pm X405 Post #5



Quote from sethmachine
I am looking for a library that has very high standards for documentation, including near obligatory type annotations.

Not my code. At least not at the moment :)

Quote from sethmachine
I decided to start this myself in a project called chkjson. It is very early and not ready for use yet. I don't aim to support parsing every section, only the ones I need like TRG, MRGN, and STR. Right now I just created the part that compiles and decompiles the "STR " section.

Looks good. Starred! And I do agree on the merits of reusing a single library in multiple projects. Unfortunately I have some very specific timeframes and requirements and I won't be able to use/contribute to your code for a while.




Options
  Back to forum
Please log in to reply to this topic or to report it.
Members in this topic: None.
[06:53 am]
TECHLANDBD -- Air Fryer Price in Bangladesh 2026 | Techland BD
[05:17 am]
Oh_Man -- Like it doesnt even bother to build a comsat unless it sees a lurker or dt, etc
[05:15 am]
Oh_Man -- Hope that makes sense. Also artosiscast just dropped a 1 hour vid he analayses a bunch of its games. The TLDR is the maphack is responsible for a large percentage of its wins because its just hard countering zerg rushes
[05:14 am]
Oh_Man -- It's EMULATING the behaviour of a control group select and move without having the actual functionality to do that
[05:13 am]
Oh_Man -- Vrael
Vrael shouted: yeah but it looks like pluto's eAPM is still 6000 based on issuing all those orders
k the APM is inflated because it issues 12 identical orders individually. Its not 12 unique orders
[03:02 am]
Vrael -- which does reduce down to the same tradeoff I mentioned below, aka trading APM for time, but still interesting
[03:01 am]
Vrael -- and while the reaver was reloading it used that time to aggregate enough marine/tank to fend it off
[03:01 am]
Vrael -- like its micro vs one of the in-base reaver drops was pretty insane, basically it made the reaver spend 1 scarab per unit instead of 1 scarab for many workers/units
[02:58 am]
Vrael -- all the stuff I've said below is based on the actual gameplay vs some strong human performers, seems like the bot just has unfair advantages, but its also doing some cool stuff
[02:57 am]
Vrael -- NimoStar
NimoStar shouted: If its any consolation, the human brain would still mop the floor with this bot if it wasn't limited by the mechanical interface
I mean human brains trained the bot too, its not completely infeasible for the bot to actually be strong in certain scenarios
Please log in to shout.


Members Online: NudeRaider, TECHLANDBD