mirror of
https://github.com/simtactics/niotso.git
synced 2025-07-14 02:01:56 -04:00
* License header formatting change
* New IFF chunk formats supported: CST, FBMP, CATS * Rebranded libfar to simply far * Started preliminary work on the hitutils package
This commit is contained in:
parent
55659f43b5
commit
bc51bb4aad
96 changed files with 2321 additions and 424 deletions
|
@ -1,5 +1,8 @@
|
|||
/*
|
||||
trcn.c - Copyright (c) 2012 Fatbag <X-Fi6@phppoll.org>
|
||||
FileHandler - General-purpose file handling library for Niotso
|
||||
trcn.c - Copyright (c) 2012 Niotso Project <http://niotso.org/>
|
||||
Author(s): Ahmed El-Mahdawy <aa.mahdawy.10@gmail.com>
|
||||
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
|
||||
|
@ -17,39 +20,105 @@
|
|||
#include "iff.h"
|
||||
|
||||
int iff_parse_trcn(IFFChunk * ChunkInfo, const uint8_t * Buffer){
|
||||
return 0; /*
|
||||
IFF_TRCN * TRCNData;
|
||||
IFFRangeSet *RangeSet;
|
||||
unsigned Size = ChunkInfo->Size - 76;
|
||||
unsigned i;
|
||||
|
||||
|
||||
if(Size < 16)
|
||||
return 0;
|
||||
ChunkInfo->FormattedData = malloc(sizeof(IFF_TRCN));
|
||||
ChunkInfo->FormattedData = malloc(sizeof(IFFRangeSet));
|
||||
if(ChunkInfo->FormattedData == NULL)
|
||||
return 0;
|
||||
|
||||
TRCNData = (IFF_TRCN*) ChunkInfo->FormattedData;
|
||||
TRCNData->Reserved = read_uint32le(Buffer+0);
|
||||
TRCNData->Version = read_uint32le(Buffer+4);
|
||||
memcpy(TRCNData->MagicNumber, Buffer+8, 4);
|
||||
TRCNData->MagicNumber[4] = 0x00;
|
||||
TRCNData->EntryCount = read_uint32le(Buffer+12);
|
||||
|
||||
if(TRCNData->Reserved != 0 || TRCNData->Version > 2 || strcmp(TRCNData->MagicNumber, "NCRT")){
|
||||
free(TRCNData);
|
||||
|
||||
RangeSet = (IFFRangeSet*) ChunkInfo->FormattedData;
|
||||
RangeSet->Ranges = NULL;
|
||||
RangeSet->Reserved = read_uint32le(Buffer);
|
||||
RangeSet->Version = read_uint32le(Buffer+4);
|
||||
memcpy(RangeSet->MagicNumber, Buffer+8, 4);
|
||||
RangeSet->MagicNumber[4] = 0x00;
|
||||
RangeSet->RangeCount = read_uint32le(Buffer+12);
|
||||
if(RangeSet->Version > 2)
|
||||
return 0;
|
||||
}
|
||||
ChunkInfo->FormattedData = malloc(TRCNData->EntryCount * sizeof(IFFRangePair));
|
||||
if(ChunkInfo->FormattedData == NULL){
|
||||
free(TRCNData);
|
||||
if(RangeSet->RangeCount == 0)
|
||||
return 1;
|
||||
|
||||
RangeSet->Ranges = calloc(RangeSet->RangeCount, sizeof(IFFRangeEntry));
|
||||
if(RangeSet->Ranges == NULL)
|
||||
return 0;
|
||||
|
||||
Buffer += 16; Size -= 16;
|
||||
for(i=0; i<RangeSet->RangeCount; i++){
|
||||
unsigned s;
|
||||
IFFRangeEntry * Range = &RangeSet->Ranges[i];
|
||||
if(Size < 10)
|
||||
return 0;
|
||||
|
||||
Range->IsUnused = read_uint32le(Buffer);
|
||||
Range->DefaultValue = read_uint32le(Buffer+4);
|
||||
Buffer += 8; Size -= 8;
|
||||
|
||||
for(s=0; s<2; s++){
|
||||
char ** string = (s==0) ? &Range->Name : &Range->Comment;
|
||||
unsigned length;
|
||||
if(Size == 0) return 0;
|
||||
|
||||
if(RangeSet->Version < 2){
|
||||
/* C string */
|
||||
for(length=0; length != Size && Buffer[length]; length++);
|
||||
if(length == Size) return 0;
|
||||
|
||||
if(length != 0){
|
||||
*string = malloc(length+1);
|
||||
if(*string == NULL) return 0;
|
||||
strcpy(*string, (char*) Buffer);
|
||||
}
|
||||
|
||||
Buffer += length+1;
|
||||
Size -= length+1;
|
||||
|
||||
/* Skip past the 0xA3 character;
|
||||
** see global.iff chunk 546 for why you can't do modulo-2 to detect this */
|
||||
if(Size && *Buffer == 0xA3){
|
||||
Buffer++; Size--;
|
||||
}
|
||||
}else{
|
||||
/* Pascal string */
|
||||
length = read_uint8le(Buffer);
|
||||
Buffer++; Size--;
|
||||
|
||||
if(length != 0){
|
||||
*string = malloc(length+1);
|
||||
if(*string == NULL) return 0;
|
||||
memcpy(*string, Buffer, length);
|
||||
(*string)[length] = 0x00;
|
||||
}
|
||||
|
||||
Buffer += length;
|
||||
Size -= length;
|
||||
}
|
||||
}
|
||||
|
||||
if(RangeSet->Version != 0){
|
||||
if(Size < 5) return 0;
|
||||
Range->Enforced = read_uint8le(Buffer);
|
||||
Range->RangeMin = read_uint16le(Buffer+1);
|
||||
Range->RangeMax = read_uint16le(Buffer+3);
|
||||
Buffer += 5; Size -= 5;
|
||||
}
|
||||
}
|
||||
|
||||
Buffer += 16;
|
||||
for(i=0; i<TRCNData->EntryCount; i++){
|
||||
} */
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
void iff_free_trcn(void * FormattedData){
|
||||
/*IFF_TRCN *TRCNData = (IFF_TRCN*) FormattedData;*/
|
||||
IFFRangeSet *RangeSet = (IFFRangeSet*) FormattedData;
|
||||
if(RangeSet->Ranges){
|
||||
unsigned i;
|
||||
for(i=0; i<RangeSet->RangeCount; i++){
|
||||
IFFRangeEntry *Entry = &RangeSet->Ranges[i];
|
||||
free(Entry->Name);
|
||||
free(Entry->Comment);
|
||||
}
|
||||
}
|
||||
free(RangeSet->Ranges);
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue