Niotso
git revision 558726a9f13d7c3423a683dd2f4323589b66c310
The New Implementation of The Sims Online
Main Page
Related Pages
Namespaces
Classes
Files
File List
File Members
All
Classes
Namespaces
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Macros
Pages
Libraries
FileHandler
iff
iff.h
Go to the documentation of this file.
1
/*
2
FileHandler - General-purpose file handling library for Niotso
3
iff.h - Copyright (c) 2012 Niotso Project <http://niotso.org/>
4
Author(s): Fatbag <X-Fi6@phppoll.org>
5
Ahmed El-Mahdawy <aa.mahdawy.10@gmail.com>
6
7
Permission to use, copy, modify, and/or distribute this software for any
8
purpose with or without fee is hereby granted, provided that the above
9
copyright notice and this permission notice appear in all copies.
10
11
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
12
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
13
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
14
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
15
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
16
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
17
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
18
*/
19
20
#ifndef IFF_H
21
#define IFF_H
22
23
#include <stdlib.h>
24
#include <string.h>
25
#include <stdint.h>
26
#include <limits.h>
27
28
#ifndef read_uint32be
29
#define read_int32be(x) (signed)(((x)[0]<<(8*3)) | ((x)[1]<<(8*2)) | ((x)[2]<<(8*1)) | ((x)[3]<<(8*0)))
30
#define read_int24be(x) (signed)(((x)[0]<<(8*2)) | ((x)[1]<<(8*1)) | ((x)[2]<<(8*0)))
31
#define read_int16be(x) (signed)(((x)[0]<<(8*1)) | ((x)[1]<<(8*0)))
32
#define read_int8be(x) (signed)(((x)[0]<<(8*0)))
33
#define read_int32le(x) (signed)(((x)[0]<<(8*0)) | ((x)[1]<<(8*1)) | ((x)[2]<<(8*2)) | ((x)[3]<<(8*3)))
34
#define read_int24le(x) (signed)(((x)[0]<<(8*0)) | ((x)[1]<<(8*1)) | ((x)[2]<<(8*2)))
35
#define read_int16le(x) (signed)(((x)[0]<<(8*0)) | ((x)[1]<<(8*1)))
36
#define read_int8le(x) (signed)(((x)[0]<<(8*0)))
37
#define read_uint32be(x) (unsigned)(((x)[0]<<(8*3)) | ((x)[1]<<(8*2)) | ((x)[2]<<(8*1)) | ((x)[3]<<(8*0)))
38
#define read_uint24be(x) (unsigned)(((x)[0]<<(8*2)) | ((x)[1]<<(8*1)) | ((x)[2]<<(8*0)))
39
#define read_uint16be(x) (unsigned)(((x)[0]<<(8*1)) | ((x)[1]<<(8*0)))
40
#define read_uint8be(x) (unsigned)(((x)[0]<<(8*0)))
41
#define read_uint32le(x) (unsigned)(((x)[0]<<(8*0)) | ((x)[1]<<(8*1)) | ((x)[2]<<(8*2)) | ((x)[3]<<(8*3)))
42
#define read_uint24le(x) (unsigned)(((x)[0]<<(8*0)) | ((x)[1]<<(8*1)) | ((x)[2]<<(8*2)))
43
#define read_uint16le(x) (unsigned)(((x)[0]<<(8*0)) | ((x)[1]<<(8*1)))
44
#define read_uint8le(x) (unsigned)(((x)[0]<<(8*0)))
45
#endif
46
47
/*
48
** IFF file structs
49
*/
50
51
typedef
struct
IFFChunk_s
52
{
53
char
Type
[5];
54
uint32_t
Size
;
/* After subtracting the 76-byte header */
55
uint16_t
ChunkID
;
56
uint16_t
Flags
;
57
char
Label
[65];
58
uint8_t *
Data
;
59
void
*
FormattedData
;
60
}
IFFChunk
;
61
62
typedef
struct
IFFFile_s
63
{
64
uint8_t
Header
[64];
65
66
uint32_t
ChunkCount
;
67
size_t
SizeAllocated
;
68
IFFChunk
*
Chunks
;
69
IFFChunk
*
ResourceMap
;
70
}
IFFFile
;
71
72
static
const
uint8_t
Header_IFF
[] =
"IFF FILE 2.5:TYPE FOLLOWED BY SIZE\0 JAMIE DOORNBOS & MAXIS 1"
;
73
74
/*
75
** IFF chunk structs
76
*/
77
78
/* BCON chunk */
79
80
typedef
struct
IFF_BCON_s
81
{
82
uint8_t
ConstantCount
;
83
uint8_t
Flags
;
84
uint16_t *
Constants
;
85
}
IFF_BCON
;
86
87
/* BHAV chunk */
88
89
typedef
struct
IFFInstruction_s
90
{
91
uint16_t
Opcode
;
92
uint8_t
TDest
;
93
uint8_t
FDest
;
94
uint8_t
Operands
[8];
95
}
IFFInstruction
;
96
97
typedef
struct
IFFBehavior_s
98
{
99
uint16_t
Version
;
100
uint32_t
InstructionCount
;
101
uint8_t
Type
;
102
uint8_t
ArgumentCount
;
103
uint16_t
LocalCount
;
104
uint16_t
Flags
;
105
IFFInstruction
*
Instructions
;
106
}
IFFBehavior
;
107
108
/* DGRP chunk */
109
110
typedef
struct
IFFSpriteInfo_s
111
{
112
uint16_t
Type
;
113
uint32_t
ChunkID
;
114
uint32_t
SpriteIndex
;
115
uint16_t
Flags
;
116
int32_t
SpriteX
;
117
int32_t
SpriteY
;
118
float
ObjectZ
;
119
float
ObjectX
;
120
float
ObjectY
;
121
}
IFFSpriteInfo
;
122
123
typedef
struct
IFFDrawAngle_s
124
{
125
uint16_t
SpriteCount
;
126
uint32_t
Direction
;
127
uint32_t
Zoom
;
128
IFFSpriteInfo
*
SpriteInfo
;
129
}
IFFDrawAngle
;
130
131
typedef
struct
IFFDrawGroup_s
132
{
133
uint16_t
Version
;
134
uint32_t
AngleCount
;
135
IFFDrawAngle
DrawAngles
[12];
136
}
IFFDrawGroup
;
137
138
enum
IFFDrawDirection
{
139
IFFDIRECTION_NORTHEAST
= 1,
140
IFFDIRECTION_SOUTHEAST
= 4,
141
IFFDIRECTION_NORTHWEST
= 16,
142
IFFDIRECTION_SOUTHWEST
= 64
143
};
144
145
enum
IFFDrawZoom
{
146
IFFZOOM_FAR
= 1,
147
IFFZOOM_MIDDLE
,
148
IFFZOOM_CLOSE
149
};
150
151
/* FCNS chunk */
152
153
typedef
struct
IFFConstant_s
154
{
155
char
*
Name
;
156
float
Value
;
157
char
*
Description
;
158
}
IFFConstant
;
159
160
typedef
struct
IFFConstantList_s
161
{
162
uint32_t
Reserved
;
163
uint32_t
Version
;
164
char
MagicNumber
[5];
165
uint32_t
ConstantCount
;
166
IFFConstant
*
Constants
;
167
}
IFFConstantList
;
168
169
/* OBJf chunk */
170
171
typedef
struct
IFFFunction_s
172
{
173
uint16_t
ConditionID
;
174
uint16_t
ActionID
;
175
}
IFFFunction
;
176
177
typedef
struct
IFFFunctionTable_s
178
{
179
uint32_t
Reserved
;
180
uint32_t
Version
;
181
char
MagicNumber
[5];
182
uint32_t
FunctionCount
;
183
IFFFunction
*
Functions
;
184
}
IFFFunctionTable
;
185
186
/* PALT chunk */
187
188
typedef
struct
IFFPalette_s
189
{
190
uint32_t
Version
;
191
uint32_t
ColorCount
;
192
uint32_t
Reserved1
;
193
uint32_t
Reserved2
;
194
uint8_t
Data
[256*3];
195
}
IFFPalette
;
196
197
/* SPR#/SPR2 chunk */
198
199
typedef
struct
IFFSprite_s
200
{
201
uint32_t
Reserved
;
202
uint16_t
Height
;
203
uint16_t
Width
;
204
uint32_t
Flags
;
205
uint16_t
PaletteID
;
206
uint16_t
TransparentColor
;
207
int16_t
YLoc
;
208
int16_t
XLoc
;
209
uint8_t *
IndexData
;
210
uint8_t *
BGRA32Data
;
211
uint8_t *
ZBuffer
;
212
213
uint8_t
InvalidDimensions
;
214
}
IFFSprite
;
215
216
typedef
struct
IFFSpriteList_s
217
{
218
uint32_t
Version
;
219
uint32_t
SpriteCount
;
220
uint32_t
PaletteID
;
221
IFFSprite
*
Sprites
;
222
}
IFFSpriteList
;
223
224
enum
IFFSpriteFlags
{
225
IFFSPRITE_FLAG_COLOR
= 1,
226
IFFSPRITE_FLAG_ZBUFFER
= 2,
227
IFFSPRITE_FLAG_ALPHA
= 4
228
};
229
230
int
iff_depalette
(
IFFSprite
* Sprite,
const
IFFPalette
* Palette);
231
232
/* STR# chunk */
233
234
enum
IFFLanguage
{
235
IFFLANG_DEFAULT
= 0,
236
IFFLANG_EN_US
= 1,
237
IFFLANG_EN_INTERNATIONAL
= 2,
238
IFFLANG_FRENCH
= 3,
239
IFFLANG_GERMAN
= 4,
240
IFFLANG_ITALIAN
= 5,
241
IFFLANG_SPANISH
= 6,
242
IFFLANG_DUTCH
= 7,
243
IFFLANG_DANISH
= 8,
244
IFFLANG_SWEDISH
= 9,
245
IFFLANG_NORWEGIAN
= 10,
246
IFFLANG_FINNISH
= 11,
247
IFFLANG_HEBREW
= 12,
248
IFFLANG_RUSSIAN
= 13,
249
IFFLANG_PORTUGUESE
= 14,
250
IFFLANG_JAPANESE
= 15,
251
IFFLANG_POLISH
= 16,
252
IFFLANG_CHINESE_SIMPLIFIED
= 17,
253
IFFLANG_CHINESE_TRADITIONAL
= 18,
254
IFFLANG_THAI
= 19,
255
IFFLANG_KOREAN
= 20
256
};
257
258
typedef
struct
IFFStringPair_s
259
{
260
uint8_t
LanguageSet
;
261
char
*
Key
;
262
char
*
Value
;
263
}
IFFStringPair
;
264
265
typedef
struct
IFFLanguageSet_s
266
{
267
uint16_t
PairCount
;
268
IFFStringPair
*
Pairs
;
269
}
IFFLanguageSet
;
270
271
typedef
struct
IFF_STR_s
272
{
273
int16_t
Format
;
274
IFFLanguageSet
LanguageSets
[20];
275
}
IFFString
;
276
277
/* TMPL chunk */
278
279
typedef
struct
IFFTemplateField_s
280
{
281
char
*
Name
;
282
char
Type
[5];
283
}
IFFTemplateField
;
284
285
typedef
struct
IFFTemplate_s
286
{
287
uint32_t
FieldCount
;
288
IFFTemplateField
*
Fields
;
289
}
IFFTemplate
;
290
291
/* TRCN chunk */
292
293
typedef
struct
IFFRangeEntry_s
294
{
295
uint32_t
IsUsed
;
296
uint32_t
DefaultValue
;
297
char
*
Name
;
298
char
*
Comment
;
299
uint8_t
Enforced
;
300
uint16_t
RangeMin
;
301
uint16_t
RangeMax
;
302
}
IFFRangeEntry
;
303
304
typedef
struct
IFFRangeSet_s
305
{
306
uint32_t
Reserved
;
307
uint32_t
Version
;
308
char
MagicNumber
[5];
309
uint32_t
RangeCount
;
310
IFFRangeEntry
*
Ranges
;
311
}
IFFRangeSet
;
312
313
/* rsmp chunk */
314
315
typedef
struct
IFFResource_s
316
{
317
uint32_t
Offset
;
318
uint32_t
ChunkID
;
319
uint16_t
Flags
;
320
char
*
Label
;
321
}
IFFResource
;
322
323
typedef
struct
IFFResouceType_s
324
{
325
char
Type
[5];
326
uint32_t
ResourceCount
;
327
IFFResource
*
Resources
;
328
}
IFFResourceType
;
329
330
typedef
struct
IFFResourceMap_s
331
{
332
uint32_t
Reserved
;
333
uint32_t
Version
;
334
char
MagicNumber
[5];
335
uint32_t
IFFSize
;
336
uint32_t
TypeCount
;
337
IFFResourceType
*
ResourceTypes
;
338
}
IFFResourceMap
;
339
340
#ifdef __cplusplus
341
extern
"C"
{
342
#endif
343
344
/*
345
** IFF file functions
346
*/
347
348
int
iff_create
(
IFFFile
*
IFFFileInfo
);
349
int
iff_read_header
(
IFFFile
* IFFFileInfo,
const
uint8_t * Buffer,
unsigned
FileSize
);
350
351
IFFChunk
*
iff_add_chunk
(
IFFFile
* IFFFileInfo);
352
int
iff_read_chunk
(
IFFChunk
* ChunkInfo,
const
uint8_t * Buffer,
unsigned
MaxChunkSize);
353
int
iff_parse_chunk
(
IFFChunk
* ChunkInfo,
const
uint8_t * Buffer);
354
int
iff_enumerate_chunks
(
IFFFile
* IFFFileInfo,
const
uint8_t * Buffer,
unsigned
BufferSize);
355
IFFChunk
*
iff_find_chunk
(
IFFFile
* IFFFileInfo,
const
char
* Type,
int
ChunkID);
356
357
void
iff_free_chunk
(
IFFChunk
* ChunkInfo);
358
void
iff_delete_chunk
(
IFFFile
* IFFFileInfo,
int
Position);
359
void
iff_delete
(
IFFFile
* IFFFileInfo);
360
361
#ifdef __cplusplus
362
}
363
#endif
364
365
#endif
Generated on Sat Jun 15 2013 03:02:15 for Niotso by
1.8.4