From 62ad3dfc4f2df1432244fb58f462bae0737fdf82 Mon Sep 17 00:00:00 2001 From: Fatbag Date: Fri, 25 May 2012 15:48:09 -0500 Subject: [PATCH] Added PALT viewing to iff2html --- Libraries/FileHandler/iff/CMakeLists.txt | 1 + Libraries/FileHandler/iff/bcon.c | 4 +-- Libraries/FileHandler/iff/cats.c | 4 +-- Libraries/FileHandler/iff/iff.c | 4 +++ Libraries/FileHandler/iff/iff.h | 13 ++++++- Libraries/FileHandler/iff/palt.c | 42 ++++++++++++++++++++++ Libraries/FileHandler/iff/str.c | 4 +-- Libraries/FileHandler/iff/tmpl.c | 2 +- Libraries/FileHandler/iff/trcn.c | 6 ++-- Tools/hitutils/hitdump.cpp | 5 ++- Tools/hitutils/hitld.cpp | 7 ++-- Tools/iff2html/iff2html.c | 45 ++++++++++++++++++++++-- 12 files changed, 116 insertions(+), 21 deletions(-) create mode 100644 Libraries/FileHandler/iff/palt.c diff --git a/Libraries/FileHandler/iff/CMakeLists.txt b/Libraries/FileHandler/iff/CMakeLists.txt index 8f65b9f..3eb9806 100644 --- a/Libraries/FileHandler/iff/CMakeLists.txt +++ b/Libraries/FileHandler/iff/CMakeLists.txt @@ -7,6 +7,7 @@ set(IFF_SOURCES bcon.c fcns.c glob.c + palt.c rsmp.c str.c string.c diff --git a/Libraries/FileHandler/iff/bcon.c b/Libraries/FileHandler/iff/bcon.c index d18f4eb..750888e 100644 --- a/Libraries/FileHandler/iff/bcon.c +++ b/Libraries/FileHandler/iff/bcon.c @@ -30,7 +30,7 @@ int iff_parse_bcon(IFFChunk * ChunkInfo, const uint8_t * Buffer){ if(ChunkInfo->FormattedData == NULL) return 0; - BCONData = (IFF_BCON*) ChunkInfo->FormattedData; + BCONData = ChunkInfo->FormattedData; BCONData->ConstantCount = read_uint8le(Buffer); BCONData->Flags = read_uint8le(Buffer + 1); if(BCONData->ConstantCount == 0) @@ -49,6 +49,6 @@ int iff_parse_bcon(IFFChunk * ChunkInfo, const uint8_t * Buffer){ } void iff_free_bcon(void * FormattedData){ - IFF_BCON *BCONData = (IFF_BCON*) FormattedData; + IFF_BCON *BCONData = FormattedData; free(BCONData->Constants); } \ No newline at end of file diff --git a/Libraries/FileHandler/iff/cats.c b/Libraries/FileHandler/iff/cats.c index 50786e0..af3c70b 100644 --- a/Libraries/FileHandler/iff/cats.c +++ b/Libraries/FileHandler/iff/cats.c @@ -26,7 +26,7 @@ int iff_parse_cats(IFFChunk * ChunkInfo, const uint8_t * Buffer){ ChunkInfo->FormattedData = calloc(1, sizeof(IFFStringPair)); if(ChunkInfo->FormattedData == NULL) return 0; - StringData = (IFFStringPair*) ChunkInfo->FormattedData; + StringData = ChunkInfo->FormattedData; for(s=0; s<2; s++){ unsigned length; @@ -49,7 +49,7 @@ int iff_parse_cats(IFFChunk * ChunkInfo, const uint8_t * Buffer){ } void iff_free_cats(void * FormattedData){ - IFFStringPair * StringData = (IFFStringPair*) FormattedData; + IFFStringPair * StringData = FormattedData; free(StringData->Key); free(StringData->Value); } \ No newline at end of file diff --git a/Libraries/FileHandler/iff/iff.c b/Libraries/FileHandler/iff/iff.c index 1580ca1..a49505d 100644 --- a/Libraries/FileHandler/iff/iff.c +++ b/Libraries/FileHandler/iff/iff.c @@ -33,6 +33,7 @@ iff_register(cats); iff_register(c_string); iff_register(glob); iff_register(fcns); +iff_register(palt); iff_register(tmpl); iff_register(trcn); iff_register(rsmp); @@ -45,6 +46,7 @@ const char chunktypes[] = "GLOB" "BCON" "FCNS" + "PALT" "TMPL" "TRCN" "rsmp" @@ -56,6 +58,7 @@ int (* const iff_parse_function[])(IFFChunk*, const uint8_t*) = { iff_parse_glob, iff_parse_bcon, iff_parse_fcns, + iff_parse_palt, iff_parse_tmpl, iff_parse_trcn, iff_parse_rsmp @@ -67,6 +70,7 @@ void (* const iff_free_function[])(void*) = { NULL, iff_free_bcon, iff_free_fcns, + NULL, iff_free_tmpl, iff_free_trcn, iff_free_rsmp diff --git a/Libraries/FileHandler/iff/iff.h b/Libraries/FileHandler/iff/iff.h index 5616676..9b8c8b4 100644 --- a/Libraries/FileHandler/iff/iff.h +++ b/Libraries/FileHandler/iff/iff.h @@ -98,6 +98,17 @@ typedef struct IFFConstantList_s IFFConstant * Constants; } IFFConstantList; +/* PALT chunk */ + +typedef struct IFFPalette_s +{ + uint32_t Version; + uint32_t ColorCount; + uint32_t Reserved1; + uint32_t Reserved2; + uint8_t Data[256*3]; +} IFFPalette; + /* STR# chunk */ enum IFFLanguage { @@ -161,7 +172,7 @@ typedef struct IFFTemplate_s typedef struct IFFRangeEntry_s { - uint32_t IsUnused; + uint32_t IsUsed; uint32_t DefaultValue; char * Name; char * Comment; diff --git a/Libraries/FileHandler/iff/palt.c b/Libraries/FileHandler/iff/palt.c new file mode 100644 index 0000000..a9fc487 --- /dev/null +++ b/Libraries/FileHandler/iff/palt.c @@ -0,0 +1,42 @@ +/* + FileHandler - General-purpose file handling library for Niotso + palt.c - Copyright (c) 2012 Niotso Project + Author(s): Fatbag + + Permission to use, copy, modify, and/or distribute this software for any + purpose with or without fee is hereby granted, provided that the above + copyright notice and this permission notice appear in all copies. + + THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. +*/ + +#include "iff.h" + +int iff_parse_palt(IFFChunk * ChunkInfo, const uint8_t * Buffer){ + IFFPalette *Palette; + unsigned Size = ChunkInfo->Size - 76; + + if(Size < 16) + return 0; + ChunkInfo->FormattedData = malloc(sizeof(IFFPalette)); + if(ChunkInfo->FormattedData == NULL) + return 0; + + Palette = ChunkInfo->FormattedData; + Palette->Version = read_uint32le(Buffer); + Palette->ColorCount = read_uint32le(Buffer+4); + Palette->Reserved1 = read_uint32le(Buffer+8); + Palette->Reserved2 = read_uint32le(Buffer+12); + if(Palette->Version != 1 || Palette->ColorCount == 0 || Palette->ColorCount > 256 || + Palette->Reserved1 != 0 || Palette->Reserved2 != 0 || Palette->ColorCount*3 > Size-16) + return 0; + + memcpy(Palette->Data, Buffer+16, Palette->ColorCount*3); + return 1; +} \ No newline at end of file diff --git a/Libraries/FileHandler/iff/str.c b/Libraries/FileHandler/iff/str.c index 6d50f73..4afe162 100644 --- a/Libraries/FileHandler/iff/str.c +++ b/Libraries/FileHandler/iff/str.c @@ -29,7 +29,7 @@ int iff_parse_str(IFFChunk * ChunkInfo, const uint8_t * Buffer){ if(ChunkInfo->FormattedData == NULL) return 0; - StringData = (IFFString*) ChunkInfo->FormattedData; + StringData = ChunkInfo->FormattedData; StringData->Format = read_int16le(Buffer); if((Size-=2) < 2) /* TSO allows this; as seen in the animations chunk in personglobals.iff */ return 1; @@ -261,7 +261,7 @@ void iff_free_str(void * FormattedData){ ** - If the Pairs pointer is nonzero, there must be PairCount initialized pairs in Pairs */ - IFFString * StringData = (IFFString*) FormattedData; + IFFString * StringData = FormattedData; unsigned ls; for(ls=0; ls<20; ls++){ diff --git a/Libraries/FileHandler/iff/tmpl.c b/Libraries/FileHandler/iff/tmpl.c index 70daad0..ca673af 100644 --- a/Libraries/FileHandler/iff/tmpl.c +++ b/Libraries/FileHandler/iff/tmpl.c @@ -39,7 +39,7 @@ int iff_parse_tmpl(IFFChunk * ChunkInfo, const uint8_t * Buffer){ if(ChunkInfo->FormattedData == NULL) return 0; - Template = (IFFTemplate*) ChunkInfo->FormattedData; + Template = ChunkInfo->FormattedData; Template->FieldCount = FieldCount; Template->Fields = calloc(FieldCount, sizeof(IFFTemplateField)); if(Template->Fields == NULL) diff --git a/Libraries/FileHandler/iff/trcn.c b/Libraries/FileHandler/iff/trcn.c index a05ecea..4dd8ccd 100644 --- a/Libraries/FileHandler/iff/trcn.c +++ b/Libraries/FileHandler/iff/trcn.c @@ -30,7 +30,7 @@ int iff_parse_trcn(IFFChunk * ChunkInfo, const uint8_t * Buffer){ if(ChunkInfo->FormattedData == NULL) return 0; - RangeSet = (IFFRangeSet*) ChunkInfo->FormattedData; + RangeSet = ChunkInfo->FormattedData; RangeSet->Ranges = NULL; RangeSet->Reserved = read_uint32le(Buffer); RangeSet->Version = read_uint32le(Buffer+4); @@ -53,7 +53,7 @@ int iff_parse_trcn(IFFChunk * ChunkInfo, const uint8_t * Buffer){ if(Size < 10) return 0; - Range->IsUnused = read_uint32le(Buffer); + Range->IsUsed = read_uint32le(Buffer); Range->DefaultValue = read_uint32le(Buffer+4); Buffer += 8; Size -= 8; @@ -116,7 +116,7 @@ int iff_parse_trcn(IFFChunk * ChunkInfo, const uint8_t * Buffer){ } void iff_free_trcn(void * FormattedData){ - IFFRangeSet *RangeSet = (IFFRangeSet*) FormattedData; + IFFRangeSet *RangeSet = FormattedData; if(RangeSet->Ranges){ unsigned i; for(i=0; iRangeCount; i++){ diff --git a/Tools/hitutils/hitdump.cpp b/Tools/hitutils/hitdump.cpp index 306be50..7326475 100644 --- a/Tools/hitutils/hitdump.cpp +++ b/Tools/hitutils/hitdump.cpp @@ -23,9 +23,8 @@ int main(){ " [-hot outfile.hot] infile.hit\n" "Disassemble a HIT binary.\n" "\n" - "The HSM and HOT files associated with the HIT file are required\n" - "as inputs; their paths default to same base name as the input\n" - "file but can be changed with the above options.\n" + "The HSM and HOT files contain necessary information and are\n" + "required as inputs.\n" "Use -f to force overwriting without confirmation.\n" "\n" "Report bugs to .\n" diff --git a/Tools/hitutils/hitld.cpp b/Tools/hitutils/hitld.cpp index fc48086..860d7b5 100644 --- a/Tools/hitutils/hitld.cpp +++ b/Tools/hitutils/hitld.cpp @@ -21,11 +21,8 @@ int main(){ printf("Usage: hitld [-f] [-hsm infile.hsm] [-hot infile.hot]\n" " outfile.hit INFILES\n" - "Link object files produced by hitasm into a HIT binary.\n" - "\n" - "The HSM and HOT files associated with the HIT file are required\n" - "for modification; their paths are normally defined by one of the\n" - "linked objects but can be forced using the above options.\n" + "Link object files produced by hitasm into a HIT binary, and\n" + "relink the game's HSM and HOT files.\n" "Use -f to force overwriting without confirmation.\n" "\n" "Report bugs to .\n" diff --git a/Tools/iff2html/iff2html.c b/Tools/iff2html/iff2html.c index 2ae2bf6..ad7f240 100644 --- a/Tools/iff2html/iff2html.c +++ b/Tools/iff2html/iff2html.c @@ -244,6 +244,18 @@ int main(int argc, char *argv[]){ fprintf(hFile, " margin: auto auto;\n"); fprintf(hFile, "}\n"); fprintf(hFile, "\n"); + fprintf(hFile, ".palette td, .palette th {\n"); + fprintf(hFile, " border: none;\n"); + fprintf(hFile, " width: 16px;\n"); + fprintf(hFile, " height: 16px;\n"); + fprintf(hFile, " font-size: 12px;\n"); + fprintf(hFile, " line-height: 16px;\n"); + fprintf(hFile, "}\n"); + fprintf(hFile, ".palette td[title] {\n"); + fprintf(hFile, " border: 1px solid #000;\n"); + fprintf(hFile, " cursor: help;\n"); + fprintf(hFile, "}\n"); + fprintf(hFile, "\n"); fprintf(hFile, "#footer {\n"); fprintf(hFile, " margin-top: 2em;\n"); fprintf(hFile, " padding-bottom: 0.5em;\n"); @@ -447,18 +459,47 @@ int main(int argc, char *argv[]){ fprintf(hFile, "
\n"); fprintf(hFile, "\n"); - fprintf(hFile, "" + fprintf(hFile, "" "\n"); for(i=0, Range=RangeSet->Ranges; iRangeCount; i++, Range++) fprintf(hFile, "\n", i+1, - Range->IsUnused ? "No" : "Yes", Range->DefaultValue, + Range->IsUsed ? "Yes" : "No", Range->DefaultValue, Range->Name ? Range->Name : "", Range->Comment ? Range->Comment : "", Range->Enforced ? "Yes" : "No", Range->RangeMin, Range->RangeMax); fprintf(hFile, "
Used yetDefault valueName
In useDefault valueNameCommentRange is enforcedMinimumMaximum
%u%s%u%s%s%s%u%u
\n"); } + }else if(!strcmp(ChunkData->Type, "PALT")){ + /**** + ** PALT parsing + */ + + IFFPalette * Palette = ChunkData->FormattedData; + uint8_t * Data = Palette->Data; + unsigned i, j; + + fprintf(hFile, "\n"); + fprintf(hFile, ""); + for(i=0; i<16; i++) fprintf(hFile, "", i); + fprintf(hFile, "\n"); + for(i=0; i<16; i++){ + fprintf(hFile, "", i); + for(j=0; j<16; j++){ + if(i*16 + j < Palette->ColorCount){ + unsigned blue = *(Data++); + unsigned green = *(Data++); + unsigned red = *(Data++); + + fprintf(hFile, "\n", + red, green, blue, i*16 + j, red, green, blue); + }else + fprintf(hFile, "\n"); + } + fprintf(hFile, "\n"); + } + fprintf(hFile, "
%X
%X
\n"); }else{ fprintf(hFile, "The contents of this chunk cannot be shown on this page.\n"); }