mirror of
https://github.com/simtactics/niotso.git
synced 2025-07-04 13:47:05 -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
|
@ -2,10 +2,12 @@ cmake_minimum_required(VERSION 2.6)
|
|||
project(iff)
|
||||
|
||||
set(IFF_SOURCES
|
||||
cats.c
|
||||
iff.c
|
||||
bcon.c
|
||||
rsmp.c
|
||||
str.c
|
||||
string.c
|
||||
trcn.c
|
||||
)
|
||||
|
||||
|
@ -17,7 +19,7 @@ set_target_properties(iff_static PROPERTIES
|
|||
|
||||
#### Shared library (uncomment to build)
|
||||
#add_library(iff_shared SHARED ${IFF_SOURCES})
|
||||
#set_target_properties(libiff_shared PROPERTIES
|
||||
#set_target_properties(iff_shared PROPERTIES
|
||||
# OUTPUT_NAME "iff"
|
||||
# PREFIX ""
|
||||
# CLEAN_DIRECT_OUTPUT 1)
|
||||
|
|
|
@ -1,5 +1,8 @@
|
|||
/*
|
||||
bcon.c - Copyright (c) 2012 Fatbag <X-Fi6@phppoll.org>
|
||||
FileHandler - General-purpose file handling library for Niotso
|
||||
bcon.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
|
||||
|
@ -33,14 +36,12 @@ int iff_parse_bcon(IFFChunk * ChunkInfo, const uint8_t * Buffer){
|
|||
BCONData->Flags = read_uint8le(Buffer + 1);
|
||||
if(BCONData->ConstantCount == 0)
|
||||
return 1;
|
||||
if(BCONData->ConstantCount * 2 /* bytes */ > Size - 2){
|
||||
if(BCONData->ConstantCount * 2 /* bytes */ > Size - 2)
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
BCONData->Constants = malloc(BCONData->ConstantCount * sizeof(uint16_t));
|
||||
if(BCONData->Constants == NULL){
|
||||
if(BCONData->Constants == NULL)
|
||||
return 0;
|
||||
}
|
||||
|
||||
Buffer += 2;
|
||||
for(i=0; i<BCONData->ConstantCount; i++, Buffer += 2)
|
||||
|
|
18
Libraries/FileHandler/iff/bhav.c
Normal file
18
Libraries/FileHandler/iff/bhav.c
Normal file
|
@ -0,0 +1,18 @@
|
|||
/*
|
||||
FileHandler - General-purpose file handling library for Niotso
|
||||
bhav.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
|
||||
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.
|
||||
*/
|
55
Libraries/FileHandler/iff/cats.c
Normal file
55
Libraries/FileHandler/iff/cats.c
Normal file
|
@ -0,0 +1,55 @@
|
|||
/*
|
||||
FileHandler - General-purpose file handling library for Niotso
|
||||
cats.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_cats(IFFChunk * ChunkInfo, const uint8_t * Buffer){
|
||||
IFFStringPair * StringData;
|
||||
unsigned Size = ChunkInfo->Size - 76;
|
||||
int s;
|
||||
|
||||
ChunkInfo->FormattedData = calloc(1, sizeof(IFFStringPair));
|
||||
if(ChunkInfo->FormattedData == NULL)
|
||||
return 0;
|
||||
StringData = (IFFStringPair*) ChunkInfo->FormattedData;
|
||||
|
||||
for(s=0; s<2; s++){
|
||||
unsigned length;
|
||||
for(length=0; length != Size && Buffer[length]; length++);
|
||||
if(length == Size) return 0;
|
||||
|
||||
if(length != 0){
|
||||
char ** string = (s==0) ? &StringData->Key : &StringData->Value;
|
||||
*string = malloc(length+1);
|
||||
if(*string == NULL) return 0;
|
||||
strcpy(*string, (char*) Buffer);
|
||||
|
||||
Buffer += length;
|
||||
Size -= length;
|
||||
}
|
||||
Buffer++; Size--;
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
void iff_free_cats(void * FormattedData){
|
||||
IFFStringPair * StringData = (IFFStringPair*) FormattedData;
|
||||
free(StringData->Key);
|
||||
free(StringData->Value);
|
||||
}
|
0
Libraries/FileHandler/iff/fcns.c
Normal file
0
Libraries/FileHandler/iff/fcns.c
Normal file
0
Libraries/FileHandler/iff/glob.c
Normal file
0
Libraries/FileHandler/iff/glob.c
Normal file
|
@ -1,5 +1,8 @@
|
|||
/*
|
||||
iff.c - Copyright (c) 2012 Fatbag <X-Fi6@phppoll.org>
|
||||
FileHandler - General-purpose file handling library for Niotso
|
||||
iff.c - Copyright (c) 2012 Niotso Project <http://niotso.org/>
|
||||
Author(s): Fatbag <X-Fi6@phppoll.org>
|
||||
Ahmed El-Mahdawy <aa.mahdawy.10@gmail.com>
|
||||
|
||||
Permission to use, copy, modify, and/or distribute this software for any
|
||||
purpose with or without fee is hereby granted, provided that the above
|
||||
|
@ -26,24 +29,31 @@
|
|||
|
||||
int iff_parse_rsmp(IFFChunk * ChunkInfo, const uint8_t * Buffer, unsigned IFFSize);
|
||||
int iff_free_rsmp(void * FormattedData);
|
||||
|
||||
/* The order of these chunks must remain the same throughout this block: */
|
||||
iff_register(bcon);
|
||||
iff_register(str);
|
||||
iff_register(cats);
|
||||
iff_register(c_string);
|
||||
iff_register(trcn);
|
||||
|
||||
/* The ordering of these chunk types must match throughout this block: */
|
||||
const char chunktypes[] =
|
||||
"STR#" "CTSS" "FAMs" "TTAs"
|
||||
"STR#" "CTSS" "FAMs" "TTAs" "CST\0"
|
||||
"CATS"
|
||||
"FWAV"
|
||||
"BCON"
|
||||
"TRCN"
|
||||
;
|
||||
int (* const iff_parse_function[])(IFFChunk*, const uint8_t*) = {
|
||||
iff_parse_str, iff_parse_str, iff_parse_str, iff_parse_str,
|
||||
iff_parse_str, iff_parse_str, iff_parse_str, iff_parse_str, iff_parse_str,
|
||||
iff_parse_cats,
|
||||
iff_parse_c_string,
|
||||
iff_parse_bcon,
|
||||
iff_parse_trcn
|
||||
};
|
||||
void (* const iff_free_function[])(void*) = {
|
||||
iff_free_str, iff_free_str, iff_free_str, iff_free_str,
|
||||
iff_free_str, iff_free_str, iff_free_str, iff_free_str, iff_free_str,
|
||||
iff_free_cats,
|
||||
NULL,
|
||||
iff_free_bcon,
|
||||
iff_free_trcn
|
||||
};
|
||||
|
@ -58,7 +68,7 @@ IFFFile * iff_create()
|
|||
{
|
||||
IFFFile *ptr = calloc(1, sizeof(IFFFile));
|
||||
if(ptr == NULL) return NULL;
|
||||
|
||||
|
||||
ptr->Chunks = malloc(sizeof(IFFChunk));
|
||||
if(ptr->Chunks == NULL){
|
||||
free(ptr);
|
||||
|
@ -94,13 +104,12 @@ IFFChunk * iff_add_chunk(IFFFile * IFFFileInfo)
|
|||
if(IFFFileInfo->SizeAllocated > SIZE_MAX/2) return NULL;
|
||||
ptr = realloc(IFFFileInfo->Chunks, IFFFileInfo->SizeAllocated<<1);
|
||||
if(ptr == NULL) return NULL;
|
||||
|
||||
|
||||
IFFFileInfo->Chunks = ptr;
|
||||
IFFFileInfo->SizeAllocated<<=1;
|
||||
}
|
||||
|
||||
IFFFileInfo->ChunkCount++;
|
||||
return IFFFileInfo->Chunks + IFFFileInfo->ChunkCount-1;
|
||||
return &IFFFileInfo->Chunks[IFFFileInfo->ChunkCount++];
|
||||
}
|
||||
|
||||
int iff_read_chunk(IFFChunk * ChunkInfo, const uint8_t * Buffer, unsigned MaxChunkSize)
|
||||
|
@ -126,6 +135,7 @@ int iff_read_chunk(IFFChunk * ChunkInfo, const uint8_t * Buffer, unsigned MaxChu
|
|||
return 0;
|
||||
memcpy(ChunkInfo->Data, Buffer+76, ChunkInfo->Size - 76);
|
||||
}
|
||||
ChunkInfo->FormattedData = NULL;
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
@ -150,7 +160,7 @@ int iff_parse_chunk(IFFChunk * ChunkInfo, const uint8_t * Buffer){
|
|||
for(i=0; chunktypes[i*4] != '\0'; i++){
|
||||
if(!memcmp(ChunkInfo->Type, chunktypes+i*4, 4)){
|
||||
if(iff_parse_function[i](ChunkInfo, Buffer)) return 1;
|
||||
iff_free_chunk(ChunkInfo->FormattedData);
|
||||
iff_free_chunk(ChunkInfo);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
@ -159,13 +169,14 @@ int iff_parse_chunk(IFFChunk * ChunkInfo, const uint8_t * Buffer){
|
|||
|
||||
void iff_free_chunk(IFFChunk * ChunkInfo){
|
||||
unsigned i;
|
||||
if(ChunkInfo == NULL || ChunkInfo->FormattedData) return;
|
||||
if(ChunkInfo == NULL || ChunkInfo->FormattedData == NULL) return;
|
||||
|
||||
for(i=0; chunktypes[i*4] != '\0'; i++){
|
||||
if(!memcmp(ChunkInfo->Type, chunktypes+i*4, 4)){
|
||||
if(iff_free_function[i])
|
||||
iff_free_function[i](ChunkInfo->FormattedData);
|
||||
free(ChunkInfo->FormattedData);
|
||||
ChunkInfo->FormattedData = NULL;
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,5 +1,8 @@
|
|||
/*
|
||||
iff.h - Copyright (c) 2012 Fatbag <X-Fi6@phppoll.org>
|
||||
FileHandler - General-purpose file handling library for Niotso
|
||||
iff.h - Copyright (c) 2012 Niotso Project <http://niotso.org/>
|
||||
Author(s): Fatbag <X-Fi6@phppoll.org>
|
||||
Ahmed El-Mahdawy <aa.mahdawy.10@gmail.com>
|
||||
|
||||
Permission to use, copy, modify, and/or distribute this software for any
|
||||
purpose with or without fee is hereby granted, provided that the above
|
||||
|
@ -120,29 +123,29 @@ typedef struct IFF_STR_s
|
|||
{
|
||||
int16_t Format;
|
||||
IFFLanguageSet LanguageSets[20];
|
||||
} IFF_STR;
|
||||
} IFFString;
|
||||
|
||||
/* TRCN chunk */
|
||||
|
||||
typedef struct IFFRangePair_s
|
||||
typedef struct IFFRangeEntry_s
|
||||
{
|
||||
uint32_t IsUnused;
|
||||
uint32_t Unknown;
|
||||
char * Key;
|
||||
char * Value;
|
||||
uint32_t DefaultValue;
|
||||
char * Name;
|
||||
char * Comment;
|
||||
uint8_t Enforced;
|
||||
uint16_t RangeMin;
|
||||
uint16_t RangeMax;
|
||||
} IFFRangePair;
|
||||
} IFFRangeEntry;
|
||||
|
||||
typedef struct IFF_TRCN_s
|
||||
typedef struct IFFRangeSet_s
|
||||
{
|
||||
uint32_t Reserved;
|
||||
uint32_t Version;
|
||||
char MagicNumber[5];
|
||||
uint32_t EntryCount;
|
||||
IFFRangePair * Entries;
|
||||
} IFF_TRCN;
|
||||
uint32_t RangeCount;
|
||||
IFFRangeEntry * Ranges;
|
||||
} IFFRangeSet;
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
/*
|
||||
iffexport.c - Copyright (c) 2012 Fatbag <X-Fi6@phppoll.org>
|
||||
FileHandler - General-purpose file handling library for Niotso
|
||||
iffexport.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
|
||||
|
@ -133,7 +135,8 @@ int main(int argc, char *argv[]){
|
|||
while((c = strchr(c, filter[i])) != NULL)
|
||||
*c = '.';
|
||||
}
|
||||
sprintf(destination, "%s/%s.%s", OutDirectory, name, (!memcmp(ChunkData->Type, "BMP_", 4)) ? "bmp" : "dat");
|
||||
sprintf(destination, "%s/%s.%s", OutDirectory, name,
|
||||
(!memcmp(ChunkData->Type, "BMP_", 4) || !memcmp(ChunkData->Type, "FBMP", 4)) ? "bmp" : "dat");
|
||||
|
||||
hFile = CreateFile(destination, GENERIC_WRITE, 0, NULL, CREATE_NEW+overwrite,
|
||||
FILE_ATTRIBUTE_NORMAL | FILE_FLAG_SEQUENTIAL_SCAN, NULL);
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
/*
|
||||
rsmp.c - Copyright (c) 2012 Fatbag <X-Fi6@phppoll.org>
|
||||
FileHandler - General-purpose file handling library for Niotso
|
||||
rsmp.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
|
||||
|
|
|
@ -1,5 +1,8 @@
|
|||
/*
|
||||
str.c - Copyright (c) 2012 Fatbag <X-Fi6@phppoll.org>
|
||||
FileHandler - General-purpose file handling library for Niotso
|
||||
str.c - Copyright (c) 2012 Niotso Project <http://niotso.org/>
|
||||
Author(s): Fatbag <X-Fi6@phppoll.org>
|
||||
Ahmed El-Mahdawy <aa.mahdawy.10@gmail.com>
|
||||
|
||||
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,23 +20,23 @@
|
|||
#include "iff.h"
|
||||
|
||||
int iff_parse_str(IFFChunk * ChunkInfo, const uint8_t * Buffer){
|
||||
IFF_STR * StringData;
|
||||
IFFString * StringData;
|
||||
unsigned Size = ChunkInfo->Size - 76;
|
||||
|
||||
if(Size < 2)
|
||||
return 0;
|
||||
ChunkInfo->FormattedData = calloc(1, sizeof(IFF_STR));
|
||||
ChunkInfo->FormattedData = calloc(1, sizeof(IFFString));
|
||||
if(ChunkInfo->FormattedData == NULL)
|
||||
return 0;
|
||||
|
||||
StringData = (IFF_STR*) ChunkInfo->FormattedData;
|
||||
|
||||
StringData = (IFFString*) 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;
|
||||
Buffer += 2;
|
||||
|
||||
|
||||
switch(StringData->Format){
|
||||
|
||||
|
||||
case 0: { /* 00 00 */
|
||||
unsigned i;
|
||||
IFFLanguageSet * LanguageSet = &StringData->LanguageSets[0];
|
||||
|
@ -69,23 +72,22 @@ int iff_parse_str(IFFChunk * ChunkInfo, const uint8_t * Buffer){
|
|||
case -1: { /* FF FF */
|
||||
unsigned i;
|
||||
IFFLanguageSet * LanguageSet = &StringData->LanguageSets[0];
|
||||
|
||||
|
||||
LanguageSet->PairCount = read_uint16le(Buffer);
|
||||
Buffer += 2; Size -= 2;
|
||||
if(LanguageSet->PairCount == 0)
|
||||
return 1;
|
||||
|
||||
|
||||
LanguageSet->Pairs = calloc(LanguageSet->PairCount, sizeof(IFFStringPair));
|
||||
if(LanguageSet->Pairs == NULL)
|
||||
return 0;
|
||||
|
||||
|
||||
for(i=0; i<LanguageSet->PairCount; i++){
|
||||
unsigned length;
|
||||
|
||||
if(Size == 0) return 0;
|
||||
for(length=0; Size-length && Buffer[length]; length++);
|
||||
if(Buffer[length] != 0x00) return 0;
|
||||
|
||||
for(length=0; length != Size && Buffer[length]; length++);
|
||||
if(length == Size) return 0;
|
||||
|
||||
if(length != 0){
|
||||
LanguageSet->Pairs[i].Key = malloc(length+1);
|
||||
if(LanguageSet->Pairs[i].Key == NULL) return 0;
|
||||
|
@ -101,25 +103,24 @@ int iff_parse_str(IFFChunk * ChunkInfo, const uint8_t * Buffer){
|
|||
case -2: { /* FE FF */
|
||||
unsigned i;
|
||||
IFFLanguageSet * LanguageSet = &StringData->LanguageSets[0];
|
||||
|
||||
|
||||
LanguageSet->PairCount = read_uint16le(Buffer);
|
||||
Buffer += 2; Size -= 2;
|
||||
if(LanguageSet->PairCount == 0)
|
||||
return 1;
|
||||
|
||||
|
||||
LanguageSet->Pairs = calloc(LanguageSet->PairCount, sizeof(IFFStringPair));
|
||||
if(LanguageSet->Pairs == NULL)
|
||||
return 0;
|
||||
|
||||
|
||||
for(i=0; i<LanguageSet->PairCount; i++){
|
||||
int s;
|
||||
|
||||
for(s=0; s<2; s++){
|
||||
unsigned length;
|
||||
if(Size == 0) return 0;
|
||||
for(length=0; Size-length && Buffer[length]; length++);
|
||||
if(Buffer[length] != 0x00) return 0;
|
||||
|
||||
for(length=0; length != Size && Buffer[length]; length++);
|
||||
if(length == Size) return 0;
|
||||
|
||||
if(length != 0){
|
||||
char ** string = (s==0) ? &LanguageSet->Pairs[i].Key : &LanguageSet->Pairs[i].Value;
|
||||
*string = malloc(length+1);
|
||||
|
@ -144,7 +145,7 @@ int iff_parse_str(IFFChunk * ChunkInfo, const uint8_t * Buffer){
|
|||
|
||||
if(TotalPairCount == 0)
|
||||
return 1;
|
||||
|
||||
|
||||
/*
|
||||
** Scan through the chunk to count up the number of strings in each LanguageSet,
|
||||
** and then allocate exactly that much and fill in the data on the second pass
|
||||
|
@ -158,30 +159,29 @@ int iff_parse_str(IFFChunk * ChunkInfo, const uint8_t * Buffer){
|
|||
if(lang >= 20) return 0;
|
||||
LanguageSet[lang].PairCount++;
|
||||
Buffer++; Size--;
|
||||
|
||||
|
||||
for(s=0; s<2; s++){
|
||||
/* Includes the string length check too */
|
||||
unsigned length;
|
||||
if(Size == 0) return 0;
|
||||
for(length=0; Size-length && Buffer[length]; length++);
|
||||
if(Buffer[length] != 0x00) return 0;
|
||||
for(length=0; length != Size && Buffer[length]; length++);
|
||||
if(length == Size) return 0;
|
||||
Buffer += length+1;
|
||||
Size -= length+1;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
for(i=0; i<20; i++){
|
||||
LanguageSet[i].Pairs = calloc(LanguageSet[i].PairCount, sizeof(IFFStringPair));
|
||||
if(LanguageSet[i].Pairs == NULL) return 0;
|
||||
}
|
||||
|
||||
|
||||
/* 2nd pass */
|
||||
Buffer = Start;
|
||||
for(i=0; i<TotalPairCount; i++){
|
||||
unsigned lang = read_uint8le(Buffer) - 1, s;
|
||||
IFFStringPair * Pair = &LanguageSet[lang].Pairs[Index[lang]++];
|
||||
Buffer++;
|
||||
|
||||
|
||||
for(s=0; s<2; s++){
|
||||
unsigned length = strlen((char*) Buffer);
|
||||
if(length != 0){
|
||||
|
@ -202,11 +202,11 @@ int iff_parse_str(IFFChunk * ChunkInfo, const uint8_t * Buffer){
|
|||
unsigned LanguageSetCount = read_uint8le(Buffer);
|
||||
Buffer++; Size--;
|
||||
if(LanguageSetCount > 20) return 0;
|
||||
|
||||
|
||||
for(lang=0; lang<LanguageSetCount; lang++){
|
||||
unsigned i;
|
||||
IFFLanguageSet * LanguageSet = &StringData->LanguageSets[lang];
|
||||
|
||||
|
||||
if(Size < 2) return 0;
|
||||
LanguageSet->PairCount = read_uint16le(Buffer);
|
||||
Buffer += 2; Size -= 2;
|
||||
|
@ -216,12 +216,12 @@ int iff_parse_str(IFFChunk * ChunkInfo, const uint8_t * Buffer){
|
|||
LanguageSet->Pairs = calloc(LanguageSet->PairCount, sizeof(IFFStringPair));
|
||||
if(LanguageSet->Pairs == NULL)
|
||||
return 0;
|
||||
|
||||
|
||||
for(i=0; i<LanguageSet->PairCount; i++){
|
||||
unsigned s;
|
||||
if(Size == 0) return 0;
|
||||
Buffer++; Size--; /* Skip over the "Language set index" */
|
||||
|
||||
|
||||
for(s=0; s<2; s++){
|
||||
unsigned length;
|
||||
if(Size == 0) return 0;
|
||||
|
@ -248,7 +248,7 @@ int iff_parse_str(IFFChunk * ChunkInfo, const uint8_t * Buffer){
|
|||
}
|
||||
}
|
||||
} return 1;
|
||||
|
||||
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
@ -261,9 +261,9 @@ void iff_free_str(void * FormattedData){
|
|||
** - If the Pairs pointer is nonzero, there must be PairCount initialized pairs in Pairs
|
||||
*/
|
||||
|
||||
IFF_STR * StringData = (IFF_STR*) FormattedData;
|
||||
IFFString * StringData = (IFFString*) FormattedData;
|
||||
unsigned ls;
|
||||
|
||||
|
||||
for(ls=0; ls<20; ls++){
|
||||
IFFLanguageSet * LanguageSet = &StringData->LanguageSets[ls];
|
||||
unsigned p;
|
||||
|
|
38
Libraries/FileHandler/iff/string.c
Normal file
38
Libraries/FileHandler/iff/string.c
Normal file
|
@ -0,0 +1,38 @@
|
|||
/*
|
||||
FileHandler - General-purpose file handling library for Niotso
|
||||
string.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_c_string(IFFChunk * ChunkInfo, const uint8_t * Buffer){
|
||||
char ** string = (char**) &ChunkInfo->FormattedData;
|
||||
unsigned Size = ChunkInfo->Size - 76;
|
||||
unsigned length;
|
||||
|
||||
if(Size == 0)
|
||||
return 0;
|
||||
|
||||
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);
|
||||
}
|
||||
return 1;
|
||||
}
|
0
Libraries/FileHandler/iff/tprp.c
Normal file
0
Libraries/FileHandler/iff/tprp.c
Normal file
|
@ -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);
|
||||
}
|
0
Libraries/FileHandler/iff/ttab.c
Normal file
0
Libraries/FileHandler/iff/ttab.c
Normal file
Loading…
Add table
Add a link
Reference in a new issue