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.
[11:50 pm]
O)FaRTy1billion[MM] -- nice, now i have more than enough
[11:49 pm]
O)FaRTy1billion[MM] -- if i don't gamble them away first
[11:49 pm]
O)FaRTy1billion[MM] -- o, due to a donation i now have enough minerals to send you minerals
[03:26 am]
O)FaRTy1billion[MM] -- i have to ask for minerals first tho cuz i don't have enough to send
[01:53 am]
Vrael -- bet u'll ask for my minerals first and then just send me some lousy vespene gas instead
[01:52 am]
Vrael -- hah do you think I was born yesterday?
[01:08 am]
O)FaRTy1billion[MM] -- i'll trade you mineral counts
[2024-4-16. : 5:05 pm]
Vrael -- Its simple, just send all minerals to Vrael until you have 0 minerals then your account is gone
[2024-4-16. : 4:31 pm]
Zoan -- where's the option to delete my account
[2024-4-16. : 4:30 pm]
Zoan -- goodbye forever
Please log in to shout.


Members Online: O)FaRTy1billion[MM]