mirror of
https://github.com/simtactics/mysimulation.git
synced 2025-07-04 13:47:04 -04:00
Made the iffexport utility (design based on libfar), added in an HTML5 z-buffer renderer, and made tags for libfar 1.0.0 and libvitaboy 1.0.0.
This commit is contained in:
parent
f23bcd7b4d
commit
432d12397c
15 changed files with 671 additions and 0 deletions
|
@ -1,6 +1,7 @@
|
|||
cmake_minimum_required(VERSION 2.6)
|
||||
project(FileHandler)
|
||||
|
||||
add_subdirectory(iff)
|
||||
add_subdirectory(libexpat)
|
||||
add_subdirectory(libfar)
|
||||
add_subdirectory(libjpeg-turbo)
|
||||
|
|
10
Libraries/FileHandler/iff/CMakeLists.txt
Normal file
10
Libraries/FileHandler/iff/CMakeLists.txt
Normal file
|
@ -0,0 +1,10 @@
|
|||
cmake_minimum_required(VERSION 2.6)
|
||||
project(iff)
|
||||
|
||||
set(IFF_SOURCES
|
||||
chunks.c
|
||||
iff.c
|
||||
iffexport.c
|
||||
)
|
||||
|
||||
add_executable(iffexport ${IFF_SOURCES})
|
24
Libraries/FileHandler/iff/chunks.c
Normal file
24
Libraries/FileHandler/iff/chunks.c
Normal file
|
@ -0,0 +1,24 @@
|
|||
/*
|
||||
chunks.c - Copyright (c) 2012 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 <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <stdint.h>
|
||||
#include "iff.h"
|
||||
|
||||
int iff_read_rsmp(IFFChunk * ChunkInfo, const uint8_t * Buffer, unsigned MaxChunkSize, unsigned IFFSize){
|
||||
return 1;
|
||||
}
|
150
Libraries/FileHandler/iff/iff.c
Normal file
150
Libraries/FileHandler/iff/iff.c
Normal file
|
@ -0,0 +1,150 @@
|
|||
/*
|
||||
iff.c - Copyright (c) 2012 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 <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <stdint.h>
|
||||
#include "iff.h"
|
||||
|
||||
#ifndef __inline
|
||||
#define __inline
|
||||
#endif
|
||||
#ifndef __restrict
|
||||
#define __restrict
|
||||
#endif
|
||||
|
||||
IFFFile * iff_create()
|
||||
{
|
||||
IFFFile *ptr = malloc(sizeof(IFFFile));
|
||||
if(ptr == NULL) return NULL;
|
||||
|
||||
memset(ptr, 0, sizeof(IFFFile));
|
||||
|
||||
return ptr;
|
||||
}
|
||||
|
||||
int iff_read_header(IFFFile * IFFFileInfo, const uint8_t * Buffer, unsigned FileSize)
|
||||
{
|
||||
unsigned offset;
|
||||
|
||||
if(!FileSize) FileSize = ~0;
|
||||
else if(FileSize < 64)
|
||||
return 0;
|
||||
|
||||
if(memcmp(Buffer, Header_IFF, 60))
|
||||
return 0;
|
||||
memcpy(IFFFileInfo->Header, Buffer, 60);
|
||||
|
||||
offset = read_uint32be(Buffer+60);
|
||||
if(offset > FileSize - 28)
|
||||
return 0;
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
IFFChunkNode * iff_add_chunk(IFFFile * IFFFileInfo, int Position)
|
||||
{
|
||||
IFFChunkNode *ptr = malloc(sizeof(IFFChunkNode)), *node;
|
||||
if(ptr == NULL) return NULL;
|
||||
memset(ptr, 0, sizeof(IFFChunkNode));
|
||||
if(IFFFileInfo == NULL) return ptr;
|
||||
|
||||
if(Position >= 0){
|
||||
node = IFFFileInfo->FirstChunk;
|
||||
|
||||
if(node == NULL){
|
||||
IFFFileInfo->FirstChunk = ptr;
|
||||
IFFFileInfo->LastChunk = ptr;
|
||||
}else{
|
||||
/* Find the node we will take the place of */
|
||||
while(Position-- && node->NextChunk != NULL)
|
||||
node = node->NextChunk;
|
||||
|
||||
if(node->PrevChunk == NULL)
|
||||
IFFFileInfo->FirstChunk = ptr;
|
||||
|
||||
/* Shift this node and all nodes after it above us */
|
||||
ptr->PrevChunk = node->PrevChunk;
|
||||
ptr->NextChunk = node;
|
||||
node->PrevChunk = ptr;
|
||||
}
|
||||
}else{
|
||||
node = IFFFileInfo->LastChunk;
|
||||
|
||||
if(node == NULL){
|
||||
IFFFileInfo->FirstChunk = ptr;
|
||||
IFFFileInfo->LastChunk = ptr;
|
||||
}else{
|
||||
/* Find the node we will take the place of */
|
||||
while(++Position && node->PrevChunk != NULL)
|
||||
node = node->PrevChunk;
|
||||
|
||||
if(node->NextChunk == NULL)
|
||||
IFFFileInfo->LastChunk = ptr;
|
||||
|
||||
/* Shift this node and all nodes before it below us */
|
||||
ptr->PrevChunk = node;
|
||||
ptr->NextChunk = node->NextChunk;
|
||||
node->NextChunk = ptr;
|
||||
}
|
||||
}
|
||||
|
||||
IFFFileInfo->ChunkCount++;
|
||||
return ptr;
|
||||
}
|
||||
|
||||
int iff_read_chunk(IFFChunk * ChunkInfo, const uint8_t * Buffer, unsigned MaxChunkSize)
|
||||
{
|
||||
if(MaxChunkSize == 0) MaxChunkSize = ~0;
|
||||
|
||||
if(MaxChunkSize < 76)
|
||||
return 0;
|
||||
|
||||
memcpy(ChunkInfo->Type, Buffer+0, 4);
|
||||
ChunkInfo->Size = read_uint32be(Buffer+4);
|
||||
ChunkInfo->ChunkID = read_uint16be(Buffer+8);
|
||||
ChunkInfo->Flags = read_uint16be(Buffer+10);
|
||||
memcpy(ChunkInfo->Label, Buffer+12, 64);
|
||||
|
||||
if(ChunkInfo->Size < 76 || ChunkInfo->Size > MaxChunkSize)
|
||||
return 0;
|
||||
|
||||
if(ChunkInfo->Size > 76){
|
||||
ChunkInfo->Data = malloc(ChunkInfo->Size - 76);
|
||||
if(ChunkInfo->Data == NULL)
|
||||
return 0;
|
||||
memcpy(ChunkInfo->Data, Buffer+76, ChunkInfo->Size - 76);
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
int iff_enumerate_chunks(IFFFile * IFFFileInfo, const uint8_t * Buffer, unsigned BufferSize)
|
||||
{
|
||||
while(BufferSize){
|
||||
IFFChunkNode * chunk = iff_add_chunk(IFFFileInfo, -1);
|
||||
if(chunk == NULL)
|
||||
return 0;
|
||||
if(!iff_read_chunk(&chunk->Chunk, Buffer, BufferSize)){
|
||||
free(chunk);
|
||||
return 0;
|
||||
}
|
||||
|
||||
Buffer += chunk->Chunk.Size;
|
||||
BufferSize -= chunk->Chunk.Size;
|
||||
}
|
||||
return 1;
|
||||
}
|
85
Libraries/FileHandler/iff/iff.h
Normal file
85
Libraries/FileHandler/iff/iff.h
Normal file
|
@ -0,0 +1,85 @@
|
|||
/*
|
||||
iff.h - Copyright (c) 2012 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.
|
||||
*/
|
||||
|
||||
#ifndef read_uint32be
|
||||
#define read_uint32be(x) (unsigned)(((x)[0]<<(8*3)) | ((x)[1]<<(8*2)) | ((x)[2]<<(8*1)) | ((x)[3]<<(8*0)))
|
||||
#define read_uint24be(x) (unsigned)(((x)[0]<<(8*2)) | ((x)[1]<<(8*1)) | ((x)[2]<<(8*0)))
|
||||
#define read_uint16be(x) (unsigned)(((x)[0]<<(8*1)) | ((x)[1]<<(8*0)))
|
||||
#define read_uint8be(x) (unsigned)(((x)[0]<<(8*0)))
|
||||
#define read_uint32le(x) (unsigned)(((x)[0]<<(8*0)) | ((x)[1]<<(8*1)) | ((x)[2]<<(8*2)) | ((x)[3]<<(8*3)))
|
||||
#define read_uint24le(x) (unsigned)(((x)[0]<<(8*0)) | ((x)[1]<<(8*1)) | ((x)[2]<<(8*2)))
|
||||
#define read_uint16le(x) (unsigned)(((x)[0]<<(8*0)) | ((x)[1]<<(8*1)))
|
||||
#define read_uint8le(x) (unsigned)(((x)[0]<<(8*0)))
|
||||
#endif
|
||||
|
||||
typedef struct IFFChunk_struct
|
||||
{
|
||||
char Type[5];
|
||||
uint32_t Size;
|
||||
uint16_t ChunkID;
|
||||
uint16_t Flags;
|
||||
char Label[65];
|
||||
uint8_t * Data;
|
||||
void * FormattedData;
|
||||
} IFFChunk;
|
||||
|
||||
typedef struct IFFChunkNode_struct
|
||||
{
|
||||
IFFChunk Chunk;
|
||||
struct IFFChunkNode_struct * PrevChunk;
|
||||
struct IFFChunkNode_struct * NextChunk;
|
||||
} IFFChunkNode;
|
||||
|
||||
typedef struct IFFFile_struct
|
||||
{
|
||||
uint8_t Header[64];
|
||||
|
||||
uint32_t ChunkCount;
|
||||
IFFChunkNode * FirstChunk;
|
||||
IFFChunkNode * LastChunk;
|
||||
IFFChunkNode * ResourceMap;
|
||||
} IFFFile;
|
||||
|
||||
static const uint8_t Header_IFF[] = "IFF FILE 2.5:TYPE FOLLOWED BY SIZE\0 JAMIE DOORNBOS & MAXIS 1";
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/*
|
||||
** IFF file functions
|
||||
*/
|
||||
|
||||
IFFFile * iff_create();
|
||||
int iff_read_header(IFFFile * IFFFileInfo, const uint8_t * Buffer, unsigned FileSize);
|
||||
|
||||
IFFChunkNode * iff_add_chunk(IFFFile * IFFFileInfo, int Position);
|
||||
int iff_read_chunk(IFFChunk * ChunkInfo, const uint8_t * Buffer, unsigned MaxChunkSize);
|
||||
int iff_enumerate_chunks(IFFFile * IFFFileInfo, const uint8_t * Buffer, unsigned BufferSize);
|
||||
|
||||
void iff_delete_chunk(IFFFile * IFFFileInfo, int Position);
|
||||
void iff_delete(IFFFile * IFFFileInfo);
|
||||
|
||||
|
||||
/*
|
||||
** IFF chunk functions
|
||||
*/
|
||||
|
||||
int iff_read_rsmp(IFFChunk * ChunkInfo, const uint8_t * Buffer, unsigned MaxChunkSize, unsigned IFFSize);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
142
Libraries/FileHandler/iff/iffexport.c
Normal file
142
Libraries/FileHandler/iff/iffexport.c
Normal file
|
@ -0,0 +1,142 @@
|
|||
/*
|
||||
iffexport.c - Copyright (c) 2012 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 <stdio.h>
|
||||
#include <stdint.h>
|
||||
#include <windows.h>
|
||||
#include "iff.h"
|
||||
|
||||
int main(int argc, char *argv[]){
|
||||
HANDLE hFile;
|
||||
int overwrite = 0;
|
||||
char *InFile, *OutDirectory;
|
||||
HANDLE ProcessHeap = GetProcessHeap();
|
||||
DWORD FileSize;
|
||||
DWORD bytestransferred = 0;
|
||||
uint8_t * IFFData;
|
||||
unsigned chunkcount, chunk = 0;
|
||||
IFFFile * IFFFileInfo;
|
||||
IFFChunkNode * ChunkNode;
|
||||
|
||||
if(argc == 1 || !strcmp(argv[1], "-h") || !strcmp(argv[1], "--help")){
|
||||
printf("Usage: iffexport [-f] infile OutDirectory\n"
|
||||
"Export the resources of an EA IFF file.\n"
|
||||
"Use -f to force overwriting without confirmation.\n"
|
||||
"\n"
|
||||
"Report bugs to <X-Fi6@phppoll.org>.\n"
|
||||
"iffexport is maintained by the Niotso project.\n"
|
||||
"Home page: <http://www.niotso.org/>\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
if(argc >= 4 && !strcmp(argv[1], "-f")){
|
||||
overwrite++;
|
||||
InFile = argv[2];
|
||||
OutDirectory = argv[3];
|
||||
}else{
|
||||
InFile = argv[1];
|
||||
OutDirectory = argv[2];
|
||||
}
|
||||
|
||||
/****
|
||||
** Open the file and read in entire contents to memory
|
||||
*/
|
||||
|
||||
hFile = CreateFile(InFile, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_FLAG_SEQUENTIAL_SCAN, NULL);
|
||||
if(hFile == INVALID_HANDLE_VALUE){
|
||||
if(GetLastError() == ERROR_FILE_NOT_FOUND){
|
||||
printf("%sThe specified input file does not exist.", "iffexport: error: ");
|
||||
return -1;
|
||||
}
|
||||
printf("%sThe input file could not be opened for reading.", "iffexport: error: ");
|
||||
return -1;
|
||||
}
|
||||
FileSize = GetFileSize(hFile, NULL);
|
||||
if(FileSize < 64){
|
||||
printf("%sNot a valid IFF file.", "iffexport: error: ");
|
||||
return -1;
|
||||
}
|
||||
IFFData = HeapAlloc(ProcessHeap, HEAP_NO_SERIALIZE, FileSize);
|
||||
if(IFFData == NULL){
|
||||
printf("%sMemory for this file could not be allocated.", "iffexport: error: ");
|
||||
return -1;
|
||||
}
|
||||
if(!ReadFile(hFile, IFFData, FileSize, &bytestransferred, NULL) || bytestransferred != FileSize){
|
||||
printf("%sThe input file could not be read.", "iffexport: error: ");
|
||||
return -1;
|
||||
}
|
||||
CloseHandle(hFile);
|
||||
|
||||
/****
|
||||
** Load header information
|
||||
*/
|
||||
|
||||
IFFFileInfo = iff_create();
|
||||
if(IFFFileInfo == NULL){
|
||||
printf("%sMemory for this file could not be allocated.", "iffexport: error: ");
|
||||
return -1;
|
||||
}
|
||||
if(!iff_read_header(IFFFileInfo, IFFData, FileSize)){
|
||||
printf("%sNot a valid IFF file.", "iffexport: error: ");
|
||||
return -1;
|
||||
}
|
||||
|
||||
/****
|
||||
** Load entry information
|
||||
*/
|
||||
|
||||
if(!iff_enumerate_chunks(IFFFileInfo, IFFData+64, FileSize-64)){
|
||||
printf("%sChunk data is corrupt.", "iffexport: error: ");
|
||||
return -1;
|
||||
}
|
||||
|
||||
chunkcount = IFFFileInfo->ChunkCount;
|
||||
printf("This IFF file contains %u chunks.\n\nExporting\n", chunkcount);
|
||||
|
||||
/****
|
||||
** Extract each entry
|
||||
*/
|
||||
for(ChunkNode = IFFFileInfo->FirstChunk; ChunkNode; ChunkNode = ChunkNode->NextChunk){
|
||||
char name[256], destination[256];
|
||||
char filter[] = "\\/:*?\"<>|";
|
||||
int i;
|
||||
|
||||
chunk++;
|
||||
sprintf(name, "%03u-%s-%04X-%s", chunk, ChunkNode->Chunk.Type, ChunkNode->Chunk.ChunkID, ChunkNode->Chunk.Label);
|
||||
for(i=0; i<9; i++){
|
||||
char * c = name;
|
||||
while((c = strchr(c, filter[i])) != NULL)
|
||||
*c = '.';
|
||||
}
|
||||
sprintf(destination, "%s/%s.%s", OutDirectory, name, (!memcmp(ChunkNode->Chunk.Type, "BMP_", 4)) ? "bmp" : "dat");
|
||||
|
||||
hFile = CreateFile(destination, GENERIC_WRITE, 0, NULL, CREATE_NEW+overwrite,
|
||||
FILE_ATTRIBUTE_NORMAL | FILE_FLAG_SEQUENTIAL_SCAN, NULL);
|
||||
if(hFile == INVALID_HANDLE_VALUE){
|
||||
printf(" (%u/%u) Skipped (%s): %s\n", chunk, chunkcount,
|
||||
(!overwrite && GetLastError() == ERROR_FILE_EXISTS) ? "file exists" : "could not open",
|
||||
name);
|
||||
continue;
|
||||
}
|
||||
|
||||
printf(" (%u/%u) %s (%u bytes)\n", chunk, chunkcount, name, ChunkNode->Chunk.Size-76);
|
||||
|
||||
WriteFile(hFile, ChunkNode->Chunk.Data, ChunkNode->Chunk.Size-76, &bytestransferred, NULL);
|
||||
CloseHandle(hFile);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue