Simple shapes patcher

Questions about the content creation procedure go here, including using Forge, Anvil, or other editors, or operating emulators like Basilisk II.

Post Dec 21st '08, 22:50

I've written a simple shapes patcher, which I've included in this post (about 2 kilobytes). It's a zipped Python program; you unzip it and it's ready to go.

You will need a Python runtime installed in order to run it, of course, but MacOS X and several Linux distributions come with one already installed. If you don't have one installed, you can download one from http://www.python.org

Once you get it, you unzip it, and on a Unix-like OS at least, it ought to have execute privileges. If it doesn't then do
chmod a+x SimpleShapesPatcher.py
in the command line. You can now run it without having to put "python" in front:
SimpleShapesPatcher.py <args>
vs.
python SimpleShapesPatcher.py <args>

How to run it:

To list the contents of a shapes file, do

SimpleShapesPatcher.py list <shapes_file_input>

It will then print out a list of all the chunks with:
  • Collection number: 0 to 31
  • Shapes-depth number: 0 is for a standard color table,, 1 is for a custom one
  • Chunk size in bytes
  • MD5 hash of the chunk contents as hexadecimal
The hash is useful for telling whether some shapes file's chunks have gotten changed.

To extract the contents of a shapes file, do

SimpleShapesPatcher.py extract <shapes_file_input> <shapes_file_patch> <collection numbers>

The collection numbers are for those to put in the patch; they range from 0 to 31, but they can be in any order, and can be repeated.

The patch file will be in the format of a shapes file, but will contain only the shapes chunks for the collection numbers entered for it.

To patch a shapes file, do

SimpleShapesPatcher.py patch <shapes_file_input> <shapes_file_patch> <shapes_file_output>

If a shapes chunk is present in the patch file, it will get placed in the output shapes file, otherwise the corresponding patch in the input shapes file will be used.

My Simple Shapes Patcher will set a shapes file's type and creator codes appropriately in MacOS X, if you have Apple's developer tools installed. It looks for
/Developer/Tools/SetFile

This version does not have much error checking, and it does not support MacBinary.

Development of this utility was so quick and convenient that I've decided to update some old utilities of mine in this fashion -- my Marathon Map Analyzer, Exporter, and possible even Viewer. Though Python is not the best for speed, it is good for object management, and it has lots of nice stuff in its standard libraries; that's often a good tradeoff.
Attachments
SimpleShapesPatcher.py.zip
(2.04 KiB) Downloaded 103 times
User avatar

lpetrich

Post Dec 22nd '08, 06:35

The technical specifications went over my head. Do you think you could make a GUI for this?
Embrace imagination.
User avatar

chinkeeyong
Singapore

Post Dec 23rd '08, 02:54

chinkeeyong wrote:The technical specifications went over my head. Do you think you could make a GUI for this?


It seemed a bit small for making a GUI for, though I may be able to make a cross-platform one with Tkinter (a Python interface for Tcl/Tk). It looks like one can create open and save dialog boxes with it, which is what's most critical for this application.

And I've received a request from treellama -- to make a version that exports patches in Anvil's patch format. Due to its complexity, it'll take a while, but I think I can do it.
User avatar

lpetrich

Post Dec 23rd '08, 13:12

I agree with you Loren, it seems a bit small for making a GUI for it, plus it's really easy to use it, even with my minimal experience with the terminal and other text-based interfaces. Although not everyone do have the experience with such a system so perhaps a good detailed manual with "human english" for the people that are not used to text-based interface would be just as good as a GUI. And would take a lot less time.

plus i like text-based interfaces. makes me feel like i'm a cool nerd. ;)
User avatar

JohannesG

Post Dec 23rd '08, 14:28

lpetrich wrote:And I've received a request from treellama -- to make a version that exports patches in Anvil's patch format. Due to its complexity, it'll take a while, but I think I can do it.

I hadn't realized just how simple SimpleShapesPatcher.py was until I looked at the code last night. I didn't realize how much work my request was--I thought you were already parsing shapes files.

I don't know if Tkinter gives you native load/save dialogs, but wxPython definitely would.
Last edited by treellama on Dec 23rd '08, 14:29, edited 1 time in total.
User avatar

treellama
Pittsburgh

Post Jan 6th '09, 08:35

I've gotten to work on it.

I've decided to do a complete shapes parser in C++ instead of Python, out of a desire to be more broadly compatible. Even with C++ instead of plain C, it'll take some work to put in what you can get for free in higher-level languages like Python.

However, I'll likely write cross-platform command-line programs, as I'd done with the Python one, and create GUI front ends that run them. That should work for Unix-like OSes; I don't know how well that might work with Windows.

Tkinter does have open/save dialog boxes, though the OSX version makes them in X-windows rather than using OSX's built-in GUI shell.
User avatar

lpetrich

Post Jan 6th '09, 11:26

Would it be possible to use this to extract the shapes from sets with indexes other than 0-31? Some of us have long since wanted to efficiently transfer the Prime Target shapes to places anvil can read them.
User avatar

Shadowbreaker
Melbourne, Victoria

Post Jan 6th '09, 13:24

Shadowbreaker wrote:Would it be possible to use this to extract the shapes from sets with indexes other than 0-31? Some of us have long since wanted to efficiently transfer the Prime Target shapes to places anvil can read them.

It should be easy to modify my simple Python shapes patcher for that, if one knows how many shapes collections to read.

However, I don't have the Prime Target data files on hand, so I am in no position to reverse-engineer them.
User avatar

lpetrich

Post Jan 6th '09, 15:27

lpetrich wrote:I've decided to do a complete shapes parser in C++ instead of Python

Such a thing already exists, in ShapeFusion. It would be pretty trivial to add shapes patch support to it, and it's already cross platform.

I only suggested adding support to your utility because I thought you wanted to use Python now :)
User avatar

treellama
Pittsburgh

Post Jan 23rd '09, 17:40

I've succeeded in creating a shapes reader in C++, complete with rather heavy use of <vector> for such things as image data, sequences, frames, and bitmap structs. I've also put it into a namespace named "Shapes", so I don't have to create lots of "Shapes_" object names.

I debugged its image reading by dumping images as netpbm files, which have an almost absurdly simple format. Fortunately, GIMP can preview and open them, so I can tell whether I'm on the right track with those files. And for parameter values, I'd check against ShapeFusion.

I'm doing this for my Crystal Space map viewer, so I've only done read support so far. But, all I'd need for creating Anvil patches is writing the various structs -- I won't need to work out the offset tables. But for applying them, I'd need full writing-out capability, offset tables and all.

My next stop will be a map reader.
Last edited by lpetrich on Jan 23rd '09, 17:42, edited 1 time in total.
User avatar

lpetrich

Post Jan 23rd '09, 18:11

lpetrich wrote:My next stop will be a map reader.

I believe I've already mentioned Ferro, which is C++ and understands the wad format (including Unimaps)
http://sourceforge.net/projects/igniferroque.
It already has parsers for reading map info (Minf), and reading/writing terminal (term) chunks, so maybe in the spirit of reuse you could use it and add stuff like PNTS, LINS, etc.? I can add you to the project for SVN access.

Or, if the idea is to learn by doing it all yourself, that's cool too. If there is anything I can do to help, let me know :)
Last edited by treellama on Jan 24th '09, 01:41, edited 1 time in total.
User avatar

treellama
Pittsburgh


Return to Editors, Emulation, Etcetera



Who is online

Users browsing this forum: No registered users