mirror of
https://github.com/simtactics/niotso.git
synced 2025-03-22 02:52:18 +00:00
Added PALT viewing to iff2html
This commit is contained in:
parent
783227a630
commit
62ad3dfc4f
12 changed files with 116 additions and 21 deletions
|
@ -7,6 +7,7 @@ set(IFF_SOURCES
|
||||||
bcon.c
|
bcon.c
|
||||||
fcns.c
|
fcns.c
|
||||||
glob.c
|
glob.c
|
||||||
|
palt.c
|
||||||
rsmp.c
|
rsmp.c
|
||||||
str.c
|
str.c
|
||||||
string.c
|
string.c
|
||||||
|
|
|
@ -30,7 +30,7 @@ int iff_parse_bcon(IFFChunk * ChunkInfo, const uint8_t * Buffer){
|
||||||
if(ChunkInfo->FormattedData == NULL)
|
if(ChunkInfo->FormattedData == NULL)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
BCONData = (IFF_BCON*) ChunkInfo->FormattedData;
|
BCONData = ChunkInfo->FormattedData;
|
||||||
BCONData->ConstantCount = read_uint8le(Buffer);
|
BCONData->ConstantCount = read_uint8le(Buffer);
|
||||||
BCONData->Flags = read_uint8le(Buffer + 1);
|
BCONData->Flags = read_uint8le(Buffer + 1);
|
||||||
if(BCONData->ConstantCount == 0)
|
if(BCONData->ConstantCount == 0)
|
||||||
|
@ -49,6 +49,6 @@ int iff_parse_bcon(IFFChunk * ChunkInfo, const uint8_t * Buffer){
|
||||||
}
|
}
|
||||||
|
|
||||||
void iff_free_bcon(void * FormattedData){
|
void iff_free_bcon(void * FormattedData){
|
||||||
IFF_BCON *BCONData = (IFF_BCON*) FormattedData;
|
IFF_BCON *BCONData = FormattedData;
|
||||||
free(BCONData->Constants);
|
free(BCONData->Constants);
|
||||||
}
|
}
|
|
@ -26,7 +26,7 @@ int iff_parse_cats(IFFChunk * ChunkInfo, const uint8_t * Buffer){
|
||||||
ChunkInfo->FormattedData = calloc(1, sizeof(IFFStringPair));
|
ChunkInfo->FormattedData = calloc(1, sizeof(IFFStringPair));
|
||||||
if(ChunkInfo->FormattedData == NULL)
|
if(ChunkInfo->FormattedData == NULL)
|
||||||
return 0;
|
return 0;
|
||||||
StringData = (IFFStringPair*) ChunkInfo->FormattedData;
|
StringData = ChunkInfo->FormattedData;
|
||||||
|
|
||||||
for(s=0; s<2; s++){
|
for(s=0; s<2; s++){
|
||||||
unsigned length;
|
unsigned length;
|
||||||
|
@ -49,7 +49,7 @@ int iff_parse_cats(IFFChunk * ChunkInfo, const uint8_t * Buffer){
|
||||||
}
|
}
|
||||||
|
|
||||||
void iff_free_cats(void * FormattedData){
|
void iff_free_cats(void * FormattedData){
|
||||||
IFFStringPair * StringData = (IFFStringPair*) FormattedData;
|
IFFStringPair * StringData = FormattedData;
|
||||||
free(StringData->Key);
|
free(StringData->Key);
|
||||||
free(StringData->Value);
|
free(StringData->Value);
|
||||||
}
|
}
|
|
@ -33,6 +33,7 @@ iff_register(cats);
|
||||||
iff_register(c_string);
|
iff_register(c_string);
|
||||||
iff_register(glob);
|
iff_register(glob);
|
||||||
iff_register(fcns);
|
iff_register(fcns);
|
||||||
|
iff_register(palt);
|
||||||
iff_register(tmpl);
|
iff_register(tmpl);
|
||||||
iff_register(trcn);
|
iff_register(trcn);
|
||||||
iff_register(rsmp);
|
iff_register(rsmp);
|
||||||
|
@ -45,6 +46,7 @@ const char chunktypes[] =
|
||||||
"GLOB"
|
"GLOB"
|
||||||
"BCON"
|
"BCON"
|
||||||
"FCNS"
|
"FCNS"
|
||||||
|
"PALT"
|
||||||
"TMPL"
|
"TMPL"
|
||||||
"TRCN"
|
"TRCN"
|
||||||
"rsmp"
|
"rsmp"
|
||||||
|
@ -56,6 +58,7 @@ int (* const iff_parse_function[])(IFFChunk*, const uint8_t*) = {
|
||||||
iff_parse_glob,
|
iff_parse_glob,
|
||||||
iff_parse_bcon,
|
iff_parse_bcon,
|
||||||
iff_parse_fcns,
|
iff_parse_fcns,
|
||||||
|
iff_parse_palt,
|
||||||
iff_parse_tmpl,
|
iff_parse_tmpl,
|
||||||
iff_parse_trcn,
|
iff_parse_trcn,
|
||||||
iff_parse_rsmp
|
iff_parse_rsmp
|
||||||
|
@ -67,6 +70,7 @@ void (* const iff_free_function[])(void*) = {
|
||||||
NULL,
|
NULL,
|
||||||
iff_free_bcon,
|
iff_free_bcon,
|
||||||
iff_free_fcns,
|
iff_free_fcns,
|
||||||
|
NULL,
|
||||||
iff_free_tmpl,
|
iff_free_tmpl,
|
||||||
iff_free_trcn,
|
iff_free_trcn,
|
||||||
iff_free_rsmp
|
iff_free_rsmp
|
||||||
|
|
|
@ -98,6 +98,17 @@ typedef struct IFFConstantList_s
|
||||||
IFFConstant * Constants;
|
IFFConstant * Constants;
|
||||||
} IFFConstantList;
|
} 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 */
|
/* STR# chunk */
|
||||||
|
|
||||||
enum IFFLanguage {
|
enum IFFLanguage {
|
||||||
|
@ -161,7 +172,7 @@ typedef struct IFFTemplate_s
|
||||||
|
|
||||||
typedef struct IFFRangeEntry_s
|
typedef struct IFFRangeEntry_s
|
||||||
{
|
{
|
||||||
uint32_t IsUnused;
|
uint32_t IsUsed;
|
||||||
uint32_t DefaultValue;
|
uint32_t DefaultValue;
|
||||||
char * Name;
|
char * Name;
|
||||||
char * Comment;
|
char * Comment;
|
||||||
|
|
42
Libraries/FileHandler/iff/palt.c
Normal file
42
Libraries/FileHandler/iff/palt.c
Normal file
|
@ -0,0 +1,42 @@
|
||||||
|
/*
|
||||||
|
FileHandler - General-purpose file handling library for Niotso
|
||||||
|
palt.c - Copyright (c) 2012 Niotso Project <http://niotso.org/>
|
||||||
|
Author(s): Fatbag <X-Fi6@phppoll.org>
|
||||||
|
|
||||||
|
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;
|
||||||
|
}
|
|
@ -29,7 +29,7 @@ int iff_parse_str(IFFChunk * ChunkInfo, const uint8_t * Buffer){
|
||||||
if(ChunkInfo->FormattedData == NULL)
|
if(ChunkInfo->FormattedData == NULL)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
StringData = (IFFString*) ChunkInfo->FormattedData;
|
StringData = ChunkInfo->FormattedData;
|
||||||
StringData->Format = read_int16le(Buffer);
|
StringData->Format = read_int16le(Buffer);
|
||||||
if((Size-=2) < 2) /* TSO allows this; as seen in the animations chunk in personglobals.iff */
|
if((Size-=2) < 2) /* TSO allows this; as seen in the animations chunk in personglobals.iff */
|
||||||
return 1;
|
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
|
** - If the Pairs pointer is nonzero, there must be PairCount initialized pairs in Pairs
|
||||||
*/
|
*/
|
||||||
|
|
||||||
IFFString * StringData = (IFFString*) FormattedData;
|
IFFString * StringData = FormattedData;
|
||||||
unsigned ls;
|
unsigned ls;
|
||||||
|
|
||||||
for(ls=0; ls<20; ls++){
|
for(ls=0; ls<20; ls++){
|
||||||
|
|
|
@ -39,7 +39,7 @@ int iff_parse_tmpl(IFFChunk * ChunkInfo, const uint8_t * Buffer){
|
||||||
if(ChunkInfo->FormattedData == NULL)
|
if(ChunkInfo->FormattedData == NULL)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
Template = (IFFTemplate*) ChunkInfo->FormattedData;
|
Template = ChunkInfo->FormattedData;
|
||||||
Template->FieldCount = FieldCount;
|
Template->FieldCount = FieldCount;
|
||||||
Template->Fields = calloc(FieldCount, sizeof(IFFTemplateField));
|
Template->Fields = calloc(FieldCount, sizeof(IFFTemplateField));
|
||||||
if(Template->Fields == NULL)
|
if(Template->Fields == NULL)
|
||||||
|
|
|
@ -30,7 +30,7 @@ int iff_parse_trcn(IFFChunk * ChunkInfo, const uint8_t * Buffer){
|
||||||
if(ChunkInfo->FormattedData == NULL)
|
if(ChunkInfo->FormattedData == NULL)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
RangeSet = (IFFRangeSet*) ChunkInfo->FormattedData;
|
RangeSet = ChunkInfo->FormattedData;
|
||||||
RangeSet->Ranges = NULL;
|
RangeSet->Ranges = NULL;
|
||||||
RangeSet->Reserved = read_uint32le(Buffer);
|
RangeSet->Reserved = read_uint32le(Buffer);
|
||||||
RangeSet->Version = read_uint32le(Buffer+4);
|
RangeSet->Version = read_uint32le(Buffer+4);
|
||||||
|
@ -53,7 +53,7 @@ int iff_parse_trcn(IFFChunk * ChunkInfo, const uint8_t * Buffer){
|
||||||
if(Size < 10)
|
if(Size < 10)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
Range->IsUnused = read_uint32le(Buffer);
|
Range->IsUsed = read_uint32le(Buffer);
|
||||||
Range->DefaultValue = read_uint32le(Buffer+4);
|
Range->DefaultValue = read_uint32le(Buffer+4);
|
||||||
Buffer += 8; Size -= 8;
|
Buffer += 8; Size -= 8;
|
||||||
|
|
||||||
|
@ -116,7 +116,7 @@ int iff_parse_trcn(IFFChunk * ChunkInfo, const uint8_t * Buffer){
|
||||||
}
|
}
|
||||||
|
|
||||||
void iff_free_trcn(void * FormattedData){
|
void iff_free_trcn(void * FormattedData){
|
||||||
IFFRangeSet *RangeSet = (IFFRangeSet*) FormattedData;
|
IFFRangeSet *RangeSet = FormattedData;
|
||||||
if(RangeSet->Ranges){
|
if(RangeSet->Ranges){
|
||||||
unsigned i;
|
unsigned i;
|
||||||
for(i=0; i<RangeSet->RangeCount; i++){
|
for(i=0; i<RangeSet->RangeCount; i++){
|
||||||
|
|
|
@ -23,9 +23,8 @@ int main(){
|
||||||
" [-hot outfile.hot] infile.hit\n"
|
" [-hot outfile.hot] infile.hit\n"
|
||||||
"Disassemble a HIT binary.\n"
|
"Disassemble a HIT binary.\n"
|
||||||
"\n"
|
"\n"
|
||||||
"The HSM and HOT files associated with the HIT file are required\n"
|
"The HSM and HOT files contain necessary information and are\n"
|
||||||
"as inputs; their paths default to same base name as the input\n"
|
"required as inputs.\n"
|
||||||
"file but can be changed with the above options.\n"
|
|
||||||
"Use -f to force overwriting without confirmation.\n"
|
"Use -f to force overwriting without confirmation.\n"
|
||||||
"\n"
|
"\n"
|
||||||
"Report bugs to <X-Fi6@phppoll.org>.\n"
|
"Report bugs to <X-Fi6@phppoll.org>.\n"
|
||||||
|
|
|
@ -21,11 +21,8 @@
|
||||||
int main(){
|
int main(){
|
||||||
printf("Usage: hitld [-f] [-hsm infile.hsm] [-hot infile.hot]\n"
|
printf("Usage: hitld [-f] [-hsm infile.hsm] [-hot infile.hot]\n"
|
||||||
" outfile.hit INFILES\n"
|
" outfile.hit INFILES\n"
|
||||||
"Link object files produced by hitasm into a HIT binary.\n"
|
"Link object files produced by hitasm into a HIT binary, and\n"
|
||||||
"\n"
|
"relink the game's HSM and HOT files.\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"
|
|
||||||
"Use -f to force overwriting without confirmation.\n"
|
"Use -f to force overwriting without confirmation.\n"
|
||||||
"\n"
|
"\n"
|
||||||
"Report bugs to <X-Fi6@phppoll.org>.\n"
|
"Report bugs to <X-Fi6@phppoll.org>.\n"
|
||||||
|
|
|
@ -244,6 +244,18 @@ int main(int argc, char *argv[]){
|
||||||
fprintf(hFile, " margin: auto auto;\n");
|
fprintf(hFile, " margin: auto auto;\n");
|
||||||
fprintf(hFile, "}\n");
|
fprintf(hFile, "}\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, "#footer {\n");
|
||||||
fprintf(hFile, " margin-top: 2em;\n");
|
fprintf(hFile, " margin-top: 2em;\n");
|
||||||
fprintf(hFile, " padding-bottom: 0.5em;\n");
|
fprintf(hFile, " padding-bottom: 0.5em;\n");
|
||||||
|
@ -447,18 +459,47 @@ int main(int argc, char *argv[]){
|
||||||
|
|
||||||
fprintf(hFile, "<br />\n");
|
fprintf(hFile, "<br />\n");
|
||||||
fprintf(hFile, "<table class=\"center\">\n");
|
fprintf(hFile, "<table class=\"center\">\n");
|
||||||
fprintf(hFile, "<tr><th colspan=\"2\">Used yet</th><th>Default value</th><th>Name</th>"
|
fprintf(hFile, "<tr><th colspan=\"2\">In use</th><th>Default value</th><th>Name</th>"
|
||||||
"<th>Comment</th><th>Range is enforced</th><th>Minimum</th><th>Maximum</th></tr>\n");
|
"<th>Comment</th><th>Range is enforced</th><th>Minimum</th><th>Maximum</th></tr>\n");
|
||||||
for(i=0, Range=RangeSet->Ranges; i<RangeSet->RangeCount; i++, Range++)
|
for(i=0, Range=RangeSet->Ranges; i<RangeSet->RangeCount; i++, Range++)
|
||||||
fprintf(hFile, "<tr><td>%u</td><td>%s</td><td>%u</td><td>%s</td><td>%s</td><td>%s</td><td>%u</td><td>%u</td></tr>\n",
|
fprintf(hFile, "<tr><td>%u</td><td>%s</td><td>%u</td><td>%s</td><td>%s</td><td>%s</td><td>%u</td><td>%u</td></tr>\n",
|
||||||
i+1,
|
i+1,
|
||||||
Range->IsUnused ? "No" : "Yes", Range->DefaultValue,
|
Range->IsUsed ? "Yes" : "No", Range->DefaultValue,
|
||||||
Range->Name ? Range->Name : "",
|
Range->Name ? Range->Name : "",
|
||||||
Range->Comment ? Range->Comment : "",
|
Range->Comment ? Range->Comment : "",
|
||||||
Range->Enforced ? "Yes" : "No",
|
Range->Enforced ? "Yes" : "No",
|
||||||
Range->RangeMin, Range->RangeMax);
|
Range->RangeMin, Range->RangeMax);
|
||||||
fprintf(hFile, "</table>\n");
|
fprintf(hFile, "</table>\n");
|
||||||
}
|
}
|
||||||
|
}else if(!strcmp(ChunkData->Type, "PALT")){
|
||||||
|
/****
|
||||||
|
** PALT parsing
|
||||||
|
*/
|
||||||
|
|
||||||
|
IFFPalette * Palette = ChunkData->FormattedData;
|
||||||
|
uint8_t * Data = Palette->Data;
|
||||||
|
unsigned i, j;
|
||||||
|
|
||||||
|
fprintf(hFile, "<table class=\"center palette\" border=\"0\">\n");
|
||||||
|
fprintf(hFile, "<tr><th></th>");
|
||||||
|
for(i=0; i<16; i++) fprintf(hFile, "<th>%X</th>", i);
|
||||||
|
fprintf(hFile, "</tr>\n");
|
||||||
|
for(i=0; i<16; i++){
|
||||||
|
fprintf(hFile, "<tr><th>%X</th>", 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<td style=\"background:#%.2x%.2x%.2x\" title=\"%u: #%.2x%.2x%.2x\"></td>",
|
||||||
|
red, green, blue, i*16 + j, red, green, blue);
|
||||||
|
}else
|
||||||
|
fprintf(hFile, "\n<td></td>");
|
||||||
|
}
|
||||||
|
fprintf(hFile, "</tr>\n");
|
||||||
|
}
|
||||||
|
fprintf(hFile, "</table>\n");
|
||||||
}else{
|
}else{
|
||||||
fprintf(hFile, "The contents of this chunk cannot be shown on this page.\n");
|
fprintf(hFile, "The contents of this chunk cannot be shown on this page.\n");
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue