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:51 pm]
Vrael -- It is, and I could definitely use a company with a commitment to flexibility, quality, and customer satisfaction to provide effective solutions to dampness and humidity in my urban environment.
[06:50 pm]
NudeRaider -- Vrael
Vrael shouted: Idk, I was looking more for a dehumidifer company which maybe stands out as a beacon of relief amidst damp and unpredictable climates of bustling metropolises. Not sure Amazon qualifies
sounds like moisture control is often a pressing concern in your city
[06:50 pm]
Vrael -- Maybe here on the StarEdit Network I could look through the Forums for some Introductions to people who care about the Topics of Dehumidifiers and Carpet Cleaning?
[06:49 pm]
Vrael -- Perhaps even here I on the StarEdit Network I could look for some Introductions.
[06:48 pm]
Vrael -- On this Topic, I could definitely use some Introductions.
[06:48 pm]
Vrael -- Perhaps that utilizes cutting-edge technology and eco-friendly cleaning products?
[06:47 pm]
Vrael -- Do you know anyone with a deep understanding of the unique characteristics of your carpets, ensuring they receive the specialized care they deserve?
[06:45 pm]
NudeRaider -- Vrael
Vrael shouted: I've also recently becoming interested in Carpet Cleaning, but I'd like to find someone with a reputation for unparalleled quality and attention to detail.
beats me, but I'd make sure to pick the epitome of excellence and nothing less.
[06:41 pm]
Vrael -- It seems like I may need Introductions to multiple companies for the Topics that I care deeply about, even as early as Today, 6:03 am.
[06:38 pm]
Vrael -- I need a go-to solution and someone who understands that Carpets are more than just decorative elements in my home.
Please log in to shout.


Members Online: lil-Inferno, Vrael, Roy