Jump to content

Using Bammer to create and edit BAMs


Recommended Posts

Posted

For the EEs, we used a tool internally called Bammer. It's since been made available publicly (Github repo) though, since I don't see any compiled versions on the repo, I've attached an exe for Windows users.

Bammer is a command-line tool that allows you to decompile a BAM file into a pile of PNG images and a bamd text file that contains human-readable instructions about how to compile these back into a BAM using Bammer. Bammer grew out of making it easier for the art team--we left the art in PNGs which would get converted by Bammer into BAMs during the build process, meaning the art team could simple edit PNGs in the tool of their choice to make changes. We can do an easy demonstration of both processes by revisiting an old oBG2 bug.

In oBG2, Spell Shield uses opcode 226 to block spells of type MAGICATTACK. Unfortunately, op 226 is hardcoded to display portrait icon #73, Protection from Magical Energy, instead of the correct Spell Shield portrait icon, #123. Without access to the source, BG2 Fixpack swapped these two icons in the portrait icon file itself so that icon #73 became the Spell Shield icon and #123 became Protection from Magical Energy, and then adjusting any spell that used these icons to the new values.

Portrait icons are stored in states.bam and states2.bam, which is an absolute nightmare of a BAM file. Back in the day fixing this was a massive PITA since most of the BAM editing tools at the time are best described as "crashy". We're going to re-do this fix with Bammer instead.

First, we export the buggy states.bam from oBG2 and drop it into a folder with our copy of Bammer. Create a folder named the same as the bam, in this case "states", and then open the command line:

bammer -input states.bam -output states > states.bamd

Normally Bammer would just throw a bunch of text back at you with the frame and sequence info; we use "> states.bamd" to redirect this output into a file. (Note that if you have an error, it'll redirect the error message here too!) This processes states.bam, pulling out all of its artwork into a series of PNGs in the states folder and creating states.bamd, a text file that describes the structure of the BAM. Here are a few excerpts from the newly-created states.bamd:

frame f00000 "states/states_000.png" 0 13
frame f00001 "states/states_001.png" 0 13
frame f00002 "states/states_002.png" 0 13
...
frame f00171 "states/states_171.png" 0 13
frame f00172 "states/states_172.png" 0 13
frame f00173 "states/states_173.png" 0 13

sequence f00000 f00000  // SEQ 0
sequence f00000 f00000  // SEQ 1
sequence f00037  // SEQ 2
sequence f00037  // SEQ 3
...
sequence f00037  // SEQ 252
sequence f00037  // SEQ 253
sequence f00039  // SEQ 254

Each frame has an image source with its x and y offsets. These are followed by the cycles (or sequences in Bammer-speak) that reference these frames. Sequences 0 and 1 are two-frame cycles, and the rest are simple one-frame cycles. If you just wanted to edit the art, you could simply open up the PNGs and edit them in your tool of choice--you don't need to worry about palettes, as the tool will handle that when it builds the BAM.

In this case, we're simply swapping two frames. The Spell Shield icon is states_124.png and PfME is states_74.png, so we simply edit these lines in the bamd from

frame f00074 "states/states_074.png" 0 13
...
frame f00124 "states/states_124.png" 0 13

to

frame f00074 "states/states_124.png" 0 13
...
frame f00124 "states/states_074.png" 0 13

swapping the art source for these two frames. You could, of course, change the contents directly in the PNGs with something like Photoshop or Gimp, but this works just fine. (Note: since Bammer will build the palette on the fly, you can discard the palette and edit it with a full color range, though I'd suggest converting any lime green to transparency first.) Since both PNGs are the same size, we also don't need to worry about adjusting the offsets.

Now we simply use Bammer to turn this back into a BAM with

bammer -input states.bamd -output states.bam

We don't need to worry about palettes, as Bammer will poll the art and build a palette for us. It'll handle transparency as well--if you give it transparent PNGs, it'll insert the normal lime green (0.255.0), or you can use the lime green directly--either way it'll set it as color 0 in the palette, making it transparent to the engine.

One thing Bammer does not handle is highlights for ground icons. The teal highlight color (0.255.255) needs to be the second color in the palette, which Bammer doesn't do, but thankfully you can build the BAM, open it in NI, and re-arrange the palette by drag-and-drop.

bammer.zip

Posted (edited)

This is freakin' awesome.  Thanks!

p.s.  Windows thinks it's Trojan/Script: Wacatac.B!ml

Edited by Awachi
Posted
14 minutes ago, Awachi said:

p.s.  Windows thinks it's Trojan/Script: Wacatac.B!ml

Ha, Windows is dumb. I inserted a Dogecoin miner, not some dumb Trojan!

Seriously, though: I just used this two days ago for the last IWDification edits.

Posted

Having been using both Bammer and PS-BAM extensively the past month, I wanted to point out a raised issue with Bammer, which seems to reduce the palette extensively for reasons not yet known.

Join the conversation

You are posting as a guest. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...