Generally the best way to work with 8-bit color games and palettes would be to use a file format with an 8-bit palette itself. Most old game programs/editors use 8-bit BMPs for this. But I suppose any 8-bit picture format would do. But the logistics of how all that would work is beyond me. They probably each have their own way of storing the palette.
I once tried converting a BMP to a SCI1 picture manually via hex. Obviously I was doomed to failure, but I did notice that the palette header portion was mostly the same; R, G, B values for each bit separated by a null bit or some other random character (can't remember which used what between SCI1 PIC and BMP). I exported a background as a BMP with SCI Viewer and loaded it into PSP5 and fooled around with the colour sliders to make the Deltaur ship in SQ1VGA blue instead of green. But when I went to copy the palette data from my altered BMP to the original SCI PIC in a hex editor the picture came out red ingame instead of blue. So the RGB values must be in an inverted order for every colour which is weird (like BGR instead or something).
Yeah, I've just tested loading some 8 bit images, and the palettes are there and intact, so it should be trivial to extract (I'm just using gdiplus to load them, so I don't need to worry about any specific formats - I've tested it with 8 bit .gif and .bmp so far). The main work will be in giving the user options when they import it. I figure:
- import with palette exactly as is (ignoring which slots are "reserved")
- import with palette indices to the slots NOT used by global palette 999 (generally index 64 to 254) (if there is room). This would be the most common option.
- import with palette shrunk to fit to the free slots 64-254 (if no room), either by recalculating from scratch, or rejecting least commonly used palette colors and replacing them with the closest remaining ones
- remap to the current palette in the pic (basically throwing away the imported palette and generating anew)
- for images without a palette (e.g. 24/32 bit images), either
- generate custom palette based on free slots (64-254)
- generate custom palette ignoring global palette
- map colors to current pic palette
Whew!
Are you using manged or unmanged code? It is a little more involved using unmanged in C#. How hard would it be to port your script disassembler to C#?
It's in native code. It would be a pretty large chunk of work to port it to C#. But if it's in its own library, it wouldn't be hard to make calls to it from managed code if the API layer is "thin" (i.e. just give it the game folder, a script #, and a place to put the resulting file). But I think there are already simpler tools out there that do that?
With regards to the decompiler (not disassembler), it's coming along, though I haven't done too much work on it lately. However, I think I'm going to introduce a new piece of syntax for the "SCI Studio" syntax to support the ternary operator. This is used extensively in the scripts I've decompiled so far. You can sort of emulate it with if/else statements, but it's less than ideal. So, in C++, this is:
gEgo.view = (someVar == someValue) ? 1 : 2;
And in the SCI studio syntax, I'm proposing:
(send gEgo:view(? (== someVar someValue) 1 2))
Currently in SCI Studio syntax, you'd need to use:
(if (== someVar someValue)
(send gEgo:view(1))
)
(else
(send gEgo:view(2))
)
I tried cramming if/else statements directly into the assignment, but I couldn't get something that compiled with SCI Studio (plus it looks ugly). Expanding it out into the above form isn't really feasible either, as they often part of statements that use multiple selectors on the same receiver.
edit..... ok, it does look like SCI Studio permits this (but SCI Companion barfs on it!). Not sure why I came to a different conclusion before... maybe there are some scenarios where it doesn't work? Anyway, it looks like this:
(send gEgo:view( (if (== someVar someValue) 1) (else 2) ))