|
| 1 | +////////////////////////////////////////////////////////////////////////////////// |
| 2 | +//////////////////////// ps_tileset_repair_header ////////////////////////// |
| 3 | +////////////////////////////////////////////////////////////////////////////////// |
| 4 | +// This is a WeiDU patch function that repairs a couple of uncommon errors in tileset headers caused by other programs. |
| 5 | +// 1) An old version of DLTCEP erroneously wrote tilesets with an invalid version string of 'V2 '. This will be fixed. |
| 6 | +// 2) Old versions of Near Infinity erroneously exported tilesets without a header. A header can be generated but it requires making |
| 7 | +// some assumptions. One assumption is that it is a palette-based tileset, but as PVRz-based tilesets did not come out until after NI |
| 8 | +// was fixed, this should be a good assumption. The second assumption is that the tile dimensions are 64x64 px, but I have never seen |
| 9 | +// any other value used, so this should also be a reasonably good assumption. |
| 10 | +////////////////////////////////////////////////////////////////////////////////// |
| 11 | +DEFINE_PATCH_FUNCTION ps_tileset_repair_header BEGIN |
| 12 | + READ_ASCII 0x0 Signature (4) // Signature ("TIS ") |
| 13 | + PATCH_IF (~%Signature%~ STRING_EQUAL_CASE ~TIZ0~ = 1) OR (~%Signature%~ STRING_EQUAL_CASE ~TBC ~ = 1) OR (~%Signature%~ STRING_EQUAL_CASE ~TISC~ = 1) BEGIN // Tileset is compressed |
| 14 | + PATCH_PRINT ~Tileset "%SOURCE_FILESPEC%" is compressed but compressed tilesets are not supported: it will not be processed.~ |
| 15 | + END ELSE PATCH_IF (~%Signature%~ STRING_EQUAL_CASE ~TIS ~ = 1) BEGIN // Is an uncompressed tileset with a header |
| 16 | + READ_ASCII 0x4 Version (4) // Version ("V1 ") |
| 17 | + PATCH_IF (~%Version%~ STRING_EQUAL_CASE ~V2 ~ = 1) BEGIN // Tileset has invalid version |
| 18 | + WRITE_ASCIIE 0x4 ~V1 ~ // Fix the version |
| 19 | + END |
| 20 | + END ELSE PATCH_IF (~%SOURCE_EXT%~ STRING_EQUAL_CASE ~tis~ = 1) BEGIN // Appears to be a tileset without a header. A header can be generated but it requires making some assumptions. |
| 21 | + INSERT_BYTES 0 24 // Make room for the header |
| 22 | + WRITE_ASCIIE 0x0 ~TIS ~ // Signature ("TIS ") |
| 23 | + WRITE_ASCIIE 0x4 ~V1 ~ // Version ("V1 ") |
| 24 | + WRITE_LONG 0x8 (SOURCE_SIZE / 5120) // Count of tiles within this tileset (FileSize/LengthOfTilesSection) |
| 25 | + WRITE_LONG 0xc 5120 // Length of tiles section (1024+DimensionOfTile*DimensionOfTile) - assumption |
| 26 | + WRITE_LONG 0x10 24 // Size of the header (24) - assumption, but a very good one |
| 27 | + WRITE_LONG 0x14 64 // Dimension of 1 tile in pixels (64x64) - assumption, but a good one |
| 28 | + END ELSE BEGIN |
| 29 | + PATCH_PRINT ~"%SOURCE_FILESPEC%" does not appear to be a valid tileset: it will not be processed.~ |
| 30 | + END |
| 31 | +END |
0 commit comments