ReactOS  0.4.13-dev-249-gcba1a2f
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 51 of file d3dxof.c.

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

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 185 of file parsing.c.

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

Referenced by IDirectXFileImpl_CreateEnumObject(), and IDirectXFileImpl_RegisterTemplates().

◆ parse_object()

BOOL parse_object ( parse_buffer buf)

Definition at line 1380 of file parsing.c.

1381 {
1382  ULONG i;
1383 
1384  buf->pxo->pos_data = buf->cur_pos_data;
1385  buf->pxo->ptarget = NULL;
1386  buf->pxo->binary = FALSE;
1387  buf->pxo->root = buf->pxo_tab;
1388 
1389  if (get_TOKEN(buf) != TOKEN_NAME)
1390  return FALSE;
1391 
1392  /* To do template lookup */
1393  for (i = 0; i < buf->pdxf->nb_xtemplates; i++)
1394  {
1395  if (!strcasecmp((char*)buf->value, buf->pdxf->xtemplates[i].name))
1396  {
1397  buf->pxt[buf->level] = &buf->pdxf->xtemplates[i];
1398  memcpy(&buf->pxo->type, &buf->pdxf->xtemplates[i].class_id, 16);
1399  break;
1400  }
1401  }
1402  if (i == buf->pdxf->nb_xtemplates)
1403  {
1404  ERR("Unknown template %s\n", (char*)buf->value);
1405  return FALSE;
1406  }
1407 
1408  if (check_TOKEN(buf) == TOKEN_NAME)
1409  {
1410  get_TOKEN(buf);
1411  strcpy(buf->pxo->name, (char*)buf->value);
1412  }
1413  else
1414  buf->pxo->name[0] = 0;
1415 
1416  if (get_TOKEN(buf) != TOKEN_OBRACE)
1417  return FALSE;
1418  if (check_TOKEN(buf) == TOKEN_GUID)
1419  {
1420  get_TOKEN(buf);
1421  memcpy(&buf->pxo->class_id, buf->value, 16);
1422  }
1423  else
1424  memset(&buf->pxo->class_id, 0, 16);
1425 
1426  if (!parse_object_parts(buf, TRUE))
1427  return FALSE;
1428  if (get_TOKEN(buf) != TOKEN_CBRACE)
1429  return FALSE;
1430 
1431  /* For seeking to a possibly eof to avoid parsing another object next time */
1432  check_TOKEN(buf);
1433 
1434  return TRUE;
1435 }
#define TRUE
Definition: types.h:120
#define strcasecmp
Definition: fake.h:9
GLenum GLuint GLenum GLsizei const GLchar * buf
Definition: glext.h:7751
#define TOKEN_OBRACE
Definition: parsing.c:57
static WORD check_TOKEN(parse_buffer *buf)
Definition: parsing.c:876
#define TOKEN_GUID
Definition: parsing.c:54
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
smooth NULL
Definition: ftsmooth.c:416
static BOOL parse_object_parts(parse_buffer *buf, BOOL allow_optional)
Definition: parsing.c:1294
#define memcpy(s1, s2, n)
Definition: mkisofs.h:878
#define ERR(fmt,...)
Definition: debug.h:109
#define TOKEN_NAME
Definition: parsing.c:51
char * strcpy(char *DstString, const char *SrcString)
Definition: utclib.c:388
unsigned int ULONG
Definition: retypes.h:1
#define TOKEN_CBRACE
Definition: parsing.c:58
static WORD get_TOKEN(parse_buffer *buf)
Definition: parsing.c:863
#define memset(x, y, z)
Definition: compat.h:39

Referenced by IDirectXFileEnumObjectImpl_GetNextDataObject(), and parse_object_parts().

◆ parse_templates()

BOOL parse_templates ( parse_buffer buf,
BOOL  templates_only 
)

Definition at line 1099 of file parsing.c.

1100 {
1101  while (check_TOKEN(buf) != TOKEN_NONE)
1102  {
1103  if (templates_only && (check_TOKEN(buf) != TOKEN_TEMPLATE))
1104  return TRUE;
1105  if (!parse_template(buf))
1106  {
1107  WARN("Template is not correct\n");
1108  return FALSE;
1109  }
1110  else
1111  {
1112  TRACE("Template successfully parsed:\n");
1113  if (TRACE_ON(d3dxof_parsing))
1114  dump_template(buf->pdxf->xtemplates, &buf->pdxf->xtemplates[buf->pdxf->nb_xtemplates - 1]);
1115  }
1116  }
1117  return TRUE;
1118 }
#define TRUE
Definition: types.h:120
GLenum GLuint GLenum GLsizei const GLchar * buf
Definition: glext.h:7751
#define WARN(fmt,...)
Definition: debug.h:111
static BOOL parse_template(parse_buffer *buf)
Definition: parsing.c:1076
static WORD check_TOKEN(parse_buffer *buf)
Definition: parsing.c:876
#define TOKEN_NONE
Definition: parsing.c:50
#define TOKEN_TEMPLATE
Definition: parsing.c:68
#define TRACE(s)
Definition: solgame.cpp:4
static void dump_template(xtemplate *templates_array, xtemplate *ptemplate)
Definition: parsing.c:128
#define TRACE_ON(x)
Definition: compat.h:65

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