ReactOS 0.4.15-dev-8236-g99f0937
d3dxof_private.h File Reference
#include <stdarg.h>
#include "windef.h"
#include "winbase.h"
#include "wtypes.h"
#include "wingdi.h"
#include "winuser.h"
#include "dxfile.h"
Include dependency graph for d3dxof_private.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  member
 
struct  xtemplate
 
struct  xobject_member
 
struct  _xobject
 
struct  IDirectXFileImpl
 
struct  IDirectXFileBinaryImpl
 
struct  IDirectXFileDataImpl
 
struct  IDirectXFileDataReferenceImpl
 
struct  IDirectXFileObjectImpl
 
struct  parse_buffer
 
struct  IDirectXFileEnumObjectImpl
 
struct  IDirectXFileSaveObjectImpl
 

Macros

#define MAX_NAME_LEN   40
 
#define MAX_ARRAY_DIM   4
 
#define MAX_MEMBERS   50
 
#define MAX_CHILDREN   200
 
#define MAX_TEMPLATES   200
 
#define MAX_OBJECTS   500
 
#define MAX_SUBOBJECTS   2000
 
#define MAX_STRINGS_BUFFER   10000
 

Typedefs

typedef struct _xobject xobject
 

Functions

HRESULT IDirectXFileImpl_Create (IUnknown *pUnkOuter, LPVOID *ppObj) DECLSPEC_HIDDEN
 
HRESULT parse_header (parse_buffer *buf, BYTE **decomp_buffer_ptr) DECLSPEC_HIDDEN
 
BOOL parse_object (parse_buffer *buf) DECLSPEC_HIDDEN
 
BOOL parse_templates (parse_buffer *buf, BOOL templates_only) DECLSPEC_HIDDEN
 
int mszip_decompress (int inlen, int outlen, char *inbuffer, char *outbuffer) DECLSPEC_HIDDEN
 

Macro Definition Documentation

◆ MAX_ARRAY_DIM

#define MAX_ARRAY_DIM   4

Definition at line 34 of file d3dxof_private.h.

◆ MAX_CHILDREN

#define MAX_CHILDREN   200

Definition at line 36 of file d3dxof_private.h.

◆ MAX_MEMBERS

#define MAX_MEMBERS   50

Definition at line 35 of file d3dxof_private.h.

◆ MAX_NAME_LEN

#define MAX_NAME_LEN   40

Definition at line 33 of file d3dxof_private.h.

◆ MAX_OBJECTS

#define MAX_OBJECTS   500

Definition at line 38 of file d3dxof_private.h.

◆ MAX_STRINGS_BUFFER

#define MAX_STRINGS_BUFFER   10000

Definition at line 40 of file d3dxof_private.h.

◆ MAX_SUBOBJECTS

#define MAX_SUBOBJECTS   2000

Definition at line 39 of file d3dxof_private.h.

◆ MAX_TEMPLATES

#define MAX_TEMPLATES   200

Definition at line 37 of file d3dxof_private.h.

Typedef Documentation

◆ xobject

Definition at line 85 of file d3dxof_private.h.

Function Documentation

◆ IDirectXFileImpl_Create()

HRESULT IDirectXFileImpl_Create ( IUnknown pUnkOuter,
LPVOID ppObj 
)

Definition at line 50 of file d3dxof.c.

51{
53
54 TRACE("(%p,%p)\n", pUnkOuter, ppObj);
55
57 if (!object)
58 return DXFILEERR_BADALLOC;
59
60 object->IDirectXFile_iface.lpVtbl = &IDirectXFile_Vtbl;
61 object->ref = 1;
62
63 /* Reserve first template to handle the case sensitive legacy type indexColor */
64 object->nb_xtemplates = 1;
65 strcpy(object->xtemplates[0].name, "indexColor");
66 object->xtemplates[0].nb_members = 2;
67 object->xtemplates[0].members[0].type = TOKEN_DWORD;
68 object->xtemplates[0].members[0].nb_dims = 0;
69 object->xtemplates[0].members[1].type = TOKEN_FLOAT;
70 object->xtemplates[0].members[1].nb_dims = 1;
71 object->xtemplates[0].members[1].dim_fixed[0] = TRUE;
72 object->xtemplates[0].members[1].dim_value[0] = 4;
73
74 *ppObj = &object->IDirectXFile_iface;
75
76 return S_OK;
77}
char * strcpy(char *DstString, const char *SrcString)
Definition: utclib.c:388
#define TOKEN_FLOAT
Definition: d3dxof.c:48
#define TOKEN_DWORD
Definition: d3dxof.c:47
static const struct IDirectXFileVtbl IDirectXFile_Vtbl
Definition: d3dxof.c:36
#define TRUE
Definition: types.h:120
#define GetProcessHeap()
Definition: compat.h:736
#define HeapAlloc
Definition: compat.h:733
#define HEAP_ZERO_MEMORY
Definition: compat.h:134
#define DXFILEERR_BADALLOC
Definition: dxfile.h:274
#define S_OK
Definition: intsafe.h:52
#define TRACE(s)
Definition: solgame.cpp:4

Referenced by DirectXFileCreate().

◆ mszip_decompress()

int mszip_decompress ( int  inlen,
int  outlen,
char inbuffer,
char outbuffer 
)

Referenced by parse_header().

◆ parse_header()

HRESULT parse_header ( parse_buffer buf,
BYTE **  decomp_buffer_ptr 
)

Definition at line 184 of file parsing.c.

185{
186 /* X File common header:
187 * 0-3 -> Magic Number (format identifier)
188 * 4-7 -> Format Version
189 * 8-11 -> Format Type (text or binary, decompressed or compressed)
190 * 12-15 -> Float Size (32 or 64 bits) */
191 DWORD header[4];
192
193 if (!read_bytes(buf, header, sizeof(header)))
195
196 if (TRACE_ON(d3dxof_parsing))
197 {
198 char string[17];
199 memcpy(string, header, 16);
200 string[16] = 0;
201 TRACE("header = '%s'\n", string);
202 }
203
206
209
212 {
213 WARN("File type %s unknown\n", debugstr_fourcc(header[2]));
215 }
216
219
221
223 {
224 /* Extended header for compressed data:
225 * 16-19 -> size of decompressed file including xof header,
226 * 20-21 -> size of first decompressed MSZIP chunk, 22-23 -> size of first compressed MSZIP chunk
227 * 24-xx -> compressed MSZIP data chunk
228 * xx-xx -> size of next decompressed MSZIP chunk, xx-xx -> size of next compressed MSZIP chunk
229 * xx-xx -> compressed MSZIP data chunk
230 * .............................................................................................. */
231 int err;
232 DWORD decomp_file_size;
233 WORD decomp_chunk_size;
234 WORD comp_chunk_size;
235 LPBYTE decomp_buffer;
236
237 if (!read_bytes(buf, &decomp_file_size, sizeof(decomp_file_size)))
239
240 TRACE("Compressed format %s detected: decompressed file size with xof header = %d\n",
241 debugstr_fourcc(header[2]), decomp_file_size);
242
243 /* Does not take xof header into account */
244 decomp_file_size -= 16;
245
246 decomp_buffer = HeapAlloc(GetProcessHeap(), 0, decomp_file_size);
247 if (!decomp_buffer)
248 {
249 ERR("Out of memory\n");
250 return DXFILEERR_BADALLOC;
251 }
252 *decomp_buffer_ptr = decomp_buffer;
253
254 while (buf->rem_bytes)
255 {
256 if (!read_bytes(buf, &decomp_chunk_size, sizeof(decomp_chunk_size)))
258 if (!read_bytes(buf, &comp_chunk_size, sizeof(comp_chunk_size)))
260
261 TRACE("Process chunk: compressed_size = %d, decompressed_size = %d\n",
262 comp_chunk_size, decomp_chunk_size);
263
264 err = mszip_decompress(comp_chunk_size, decomp_chunk_size, (char*)buf->buffer, (char*)decomp_buffer);
265 if (err)
266 {
267 WARN("Error while decompressing MSZIP chunk %d\n", err);
268 HeapFree(GetProcessHeap(), 0, decomp_buffer);
269 return DXFILEERR_BADALLOC;
270 }
271 buf->rem_bytes -= comp_chunk_size;
272 buf->buffer += comp_chunk_size;
273 decomp_buffer += decomp_chunk_size;
274 }
275
276 if ((decomp_buffer - *decomp_buffer_ptr) != decomp_file_size)
277 ERR("Size of all decompressed chunks (%u) does not match decompressed file size (%u)\n",
278 (DWORD)(decomp_buffer - *decomp_buffer_ptr), decomp_file_size);
279
280 /* Use decompressed data */
281 buf->buffer = *decomp_buffer_ptr;
282 buf->rem_bytes = decomp_file_size;
283 }
284
285 TRACE("Header is correct\n");
286
287 return S_OK;
288}
#define WARN(fmt,...)
Definition: debug.h:115
#define ERR(fmt,...)
Definition: debug.h:113
int mszip_decompress(int inlen, int outlen, char *inbuffer, char *outbuffer) DECLSPEC_HIDDEN
#define TRACE_ON(x)
Definition: compat.h:75
#define HeapFree(x, y, z)
Definition: compat.h:735
#define DXFILEERR_BADFILEVERSION
Definition: dxfile.h:282
#define DXFILEERR_BADFILEFLOATSIZE
Definition: dxfile.h:283
#define DXFILEERR_BADFILETYPE
Definition: dxfile.h:281
unsigned long DWORD
Definition: ntddk_ex.h:95
unsigned short WORD
Definition: ntddk_ex.h:93
GLenum GLuint GLenum GLsizei const GLchar * buf
Definition: glext.h:7751
#define memcpy(s1, s2, n)
Definition: mkisofs.h:878
#define XOFFILE_FORMAT_MAGIC
Definition: parsing.c:37
#define XOFFILE_FORMAT_FLOAT_BITS_32
Definition: parsing.c:45
#define XOFFILE_FORMAT_VERSION_302
Definition: parsing.c:38
static BOOL read_bytes(parse_buffer *buf, LPVOID data, DWORD size)
Definition: parsing.c:168
static const char * debugstr_fourcc(DWORD fourcc)
Definition: parsing.c:85
#define XOFFILE_FORMAT_BINARY
Definition: parsing.c:40
#define XOFFILE_FORMAT_TEXT
Definition: parsing.c:41
#define XOFFILE_FORMAT_VERSION_303
Definition: parsing.c:39
#define XOFFILE_FORMAT_BINARY_MSZIP
Definition: parsing.c:42
#define XOFFILE_FORMAT_TEXT_MSZIP
Definition: parsing.c:43
#define XOFFILE_FORMAT_FLOAT_BITS_64
Definition: parsing.c:46
#define err(...)
unsigned char * LPBYTE
Definition: typedefs.h:53

Referenced by IDirectXFileImpl_CreateEnumObject(), and IDirectXFileImpl_RegisterTemplates().

◆ parse_object()

BOOL parse_object ( parse_buffer buf)

Definition at line 1379 of file parsing.c.

1380{
1381 ULONG i;
1382
1383 buf->pxo->pos_data = buf->cur_pos_data;
1384 buf->pxo->ptarget = NULL;
1385 buf->pxo->binary = FALSE;
1386 buf->pxo->root = buf->pxo_tab;
1387
1388 if (get_TOKEN(buf) != TOKEN_NAME)
1389 return FALSE;
1390
1391 /* To do template lookup */
1392 for (i = 0; i < buf->pdxf->nb_xtemplates; i++)
1393 {
1394 if (!_strnicmp((char*)buf->value, buf->pdxf->xtemplates[i].name, -1))
1395 {
1396 buf->pxt[buf->level] = &buf->pdxf->xtemplates[i];
1397 memcpy(&buf->pxo->type, &buf->pdxf->xtemplates[i].class_id, 16);
1398 break;
1399 }
1400 }
1401 if (i == buf->pdxf->nb_xtemplates)
1402 {
1403 ERR("Unknown template %s\n", (char*)buf->value);
1404 return FALSE;
1405 }
1406
1407 if (check_TOKEN(buf) == TOKEN_NAME)
1408 {
1409 get_TOKEN(buf);
1410 strcpy(buf->pxo->name, (char*)buf->value);
1411 }
1412 else
1413 buf->pxo->name[0] = 0;
1414
1415 if (get_TOKEN(buf) != TOKEN_OBRACE)
1416 return FALSE;
1417 if (check_TOKEN(buf) == TOKEN_GUID)
1418 {
1419 get_TOKEN(buf);
1420 memcpy(&buf->pxo->class_id, buf->value, 16);
1421 }
1422 else
1423 memset(&buf->pxo->class_id, 0, 16);
1424
1426 return FALSE;
1427 if (get_TOKEN(buf) != TOKEN_CBRACE)
1428 return FALSE;
1429
1430 /* For seeking to a possibly eof to avoid parsing another object next time */
1432
1433 return TRUE;
1434}
#define NULL
Definition: types.h:112
#define FALSE
Definition: types.h:117
#define _strnicmp(_String1, _String2, _MaxCount)
Definition: compat.h:23
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
#define TOKEN_GUID
Definition: parsing.c:53
#define TOKEN_NAME
Definition: parsing.c:50
static BOOL parse_object_parts(parse_buffer *buf, BOOL allow_optional)
Definition: parsing.c:1293
#define TOKEN_OBRACE
Definition: parsing.c:56
static WORD check_TOKEN(parse_buffer *buf)
Definition: parsing.c:875
#define TOKEN_CBRACE
Definition: parsing.c:57
static WORD get_TOKEN(parse_buffer *buf)
Definition: parsing.c:862
#define memset(x, y, z)
Definition: compat.h:39
uint32_t ULONG
Definition: typedefs.h:59

Referenced by IDirectXFileEnumObjectImpl_GetNextDataObject(), and parse_object_parts().

◆ parse_templates()

BOOL parse_templates ( parse_buffer buf,
BOOL  templates_only 
)

Definition at line 1098 of file parsing.c.

1099{
1100 while (check_TOKEN(buf) != TOKEN_NONE)
1101 {
1102 if (templates_only && (check_TOKEN(buf) != TOKEN_TEMPLATE))
1103 return TRUE;
1104 if (!parse_template(buf))
1105 {
1106 WARN("Template is not correct\n");
1107 return FALSE;
1108 }
1109 else
1110 {
1111 TRACE("Template successfully parsed:\n");
1112 if (TRACE_ON(d3dxof_parsing))
1113 dump_template(buf->pdxf->xtemplates, &buf->pdxf->xtemplates[buf->pdxf->nb_xtemplates - 1]);
1114 }
1115 }
1116 return TRUE;
1117}
static void dump_template(xtemplate *templates_array, xtemplate *ptemplate)
Definition: parsing.c:127
#define TOKEN_TEMPLATE
Definition: parsing.c:67
static BOOL parse_template(parse_buffer *buf)
Definition: parsing.c:1075
#define TOKEN_NONE
Definition: parsing.c:49

Referenced by IDirectXFileEnumObjectImpl_GetNextDataObject(), IDirectXFileImpl_CreateEnumObject(), and IDirectXFileImpl_RegisterTemplates().