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.



None.

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.



None.

Options
  Back to forum
Please log in to reply to this topic or to report it.
Members in this topic: None.
[11:36 pm]
Zoan -- what was weird was if you give the buildings to another player the computer player keeps on building it even though it doesn'y belong to them
[11:35 pm]
Zoan -- not any unit, but I did try move buildings
[11:35 pm]
Ahli -- tried moving any unit?
[08:57 pm]
Zoan -- i just tested. you actually just cant move unfinished buildings I guess. Tried moving all players and players 9 -12, tried giving players then moving. nothing works if its unfinished, but as soon as it's finished it works.
[07:54 pm]
Zoan -- Voyager7456
Voyager7456 shouted: Zoan no
;o what else do they do?
[07:49 pm]
Voyager7456 -- Zoan
Zoan shouted: so like disable all buildings but two. I mean what else is the computer player gonna do, won't they necessarily just buiild whatever they can?
no
[05:43 pm]
Zoan -- idk
[05:43 pm]
Zoan -- At least you can set the hp and build time of terran buildings so that repair never actually conteracts their hp loss while on fire..
[05:42 pm]
Zoan -- also I think you can set the hp and build time of a building so that it literally will never complete it's build, iirc.
[05:41 pm]
Zoan -- maybe if they're allied to all other players, so they don't try to do something like attack with their scv I guess.
Please log in to shout.


Members Online: Roy