Jump to content

R&D Replacing / Adding Icons


Amineri

Recommended Posts

I figured I'd start easier than replacing entire meshes, and being able to replace (or even add new) icons would be extremely useful in customizing the perk tree, since there are at least a couple of working perks ("Ready for Anything" and "Bombadier") that have no icons.

 

The bad news is that the icons are stored as Run-Length-Encoded TGA files, which means that each icon is very likely a different size. This prohibits a simple swapping of one icon for another, as the replacement is not the same size as the original.

 

There is some good news, though. The icon library appears to be stored within an SWF file in Startup.upk. Changing the size of a upk file is a daunting task because the header tables all would have to be rewritten. However, an entire SWF block can be replaced with an identical-size SWF block without violating the "no size change" rule for upks.

 

SWF files are much, much more modular than upk files are. See a description of the overall SWF file format here: http://www-lehre.inf.uos.de/~fbstark/diplom/docs/swf/Intro.htm

Essentially it consists of a small header (containing just the SWF file size), and a number of tagged blocks. Even the number of tagged blocks contained in the SWF file is not specified in the header, let alone their position.

To parse the SWF file, the interpretter must parse sequentially through the file, recording each tagged block and its size -- this happens at run-time, not compile time.

This means that it is relatively easy to add, remove, and resize tagged blocks _within_ an SWF file. This is how I implemented both the interceptor and perk tree UI mods. I made one tagged block smaller in order to make the adjoining tagged block larger.

Since there are likely some "deadweight" tagged blocks stored in the SWF file, these tagged blocks can be removed or drastically resized down.

 

-------------------------------------------------------------------------------------------------

 

Here are the steps that I foresee to replace an icon in an SWF file:

 

1) Identify the tagged blocks in the SWF file -- their position and size (we'll be juggling these at the block level), and parse them temporarily into separate files

 

2) Identify the tagged block containing the icon to be replaced, and its size

 

3) Build the replacement tagged block containing the new icon, noting its size

 

4) Adjust the "slop" tagged block size (with dummy data) based on the size difference between original and new icon tagged blocks

 

5) Reassemble the SWF file from the saved tagged blocks, including the replacement icon tagged block instead of the original

 

6) Replace the original SWF file embedded within the UPK with the new SWF file (which should be of identical size)

 

 

At a high level I think it would work. It would of course require some tools to make it practical. The tool would essentially be acting as an actionscript delinker/linker.

 

-----------------------------------------------------------

 

Parsing through the SWF file is pretty straightforward.

 

1) Read the file header, which contains the overall file size

 

2) Read the tagged block size from the block's header

 

a) Each tagged block begins with a 2 or 6 byte descriptor

b) There is always a 2-byte descriptor, which is broken into a 10 bit operator ID and a 6 bit tagged block size

c) if the 6 bit block size = 0b111111 = 0x3F, then there is an additional 4 byte integer following the 2-byte descriptor containing the tagged block size -- this effectively makes it a 6 byte descriptor

d) The tagged block size number does NOT include the 2 or 6 bytes in the descriptor

 

4) Jump ahead to the next tagged block, which will start with another 2 or 6 byte descriptor

 

5) Continue reading and jumping until the end of the file

 

Link to comment
Share on other sites

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...