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.
[03:29 am]
DarkenedFantasies -- Probably just didn't care. For example, at some point before release, they've updated the graphics of some of the Protoss buildings (Forge, CyberCore, Citadel, Observatory, Arbiter Tribunal), but instead of properly re-rendering them with edited 3D models, they did crappy copy-paste jobs on the rendered graphics.
[08:35 pm]
Ultraviolet -- :wob:
[2026-6-21. : 11:38 pm]
Symmetry -- :wob:
[2026-6-21. : 4:56 am]
Ultraviolet -- I suppose we'll likely never know, but my guess would be that they already saw it operating successfully and there was no monetary incentive to finish the original work. And the dev cycle in old school Blizzard was so hectic, it's possible it just got forgotten about after the original game got released. Plus there's an element of existing MPQ files that were packaged with the original discs becoming outdated if they updated it. And it's not like they remade the original MPQs, they just made new ones for BW specifically
[2026-6-21. : 4:26 am]
Oh_Man -- so that makes me think maybe the theory they are unfinished is not true and its a deliberate design decision, coz why not finish them wen ur making brood war?
[2026-6-21. : 4:25 am]
Oh_Man -- the thing is thos buildings are from classic. that means they went ahead and made brood war without ever finishing the 'unfinished' buildings
[2026-6-20. : 6:15 pm]
Ultraviolet -- Yeah he's talked about a lot of that stuff in his casts before. It seems plausible. Especially knowing how Blizzard of yesteryear operated.
[2026-6-20. : 3:47 pm]
NudeRaider -- to clarify: couldn't recall the behavior for every single Protoss building but I was aware the disparity exists.
[2026-6-20. : 3:43 pm]
NudeRaider -- Contained nothing new for me. Didn't know all building's behavior, but very much all unit's. Also Terran balance whine - also nothing new :lol:
[2026-6-19. : 9:57 am]
Oh_Man -- makes me wonder if SEN knows anything about the topic
Please log in to shout.


Members Online: jun3hong, Roy