ReactOS  0.4.14-dev-828-g8dc90a4
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 }
#define TRUE
Definition: types.h:120
static const struct IDirectXFileVtbl IDirectXFile_Vtbl
Definition: d3dxof.c:36
#define TRACE(s)
Definition: solgame.cpp:4
#define GetProcessHeap()
Definition: compat.h:403
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:47
#define DXFILEERR_BADALLOC
Definition: dxfile.h:274
void * object
Definition: jmemsys.h:48
#define TOKEN_FLOAT
Definition: d3dxof.c:48

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)))
194  return DXFILEERR_BADFILETYPE;
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 
204  if (header[0] != XOFFILE_FORMAT_MAGIC)
205  return DXFILEERR_BADFILETYPE;
206 
209 
212  {
213  WARN("File type %s unknown\n", debugstr_fourcc(header[2]));
214  return DXFILEERR_BADFILETYPE;
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)))
238  return DXFILEERR_BADFILETYPE;
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)))
257  return DXFILEERR_BADFILETYPE;
258  if (!read_bytes(buf, &comp_chunk_size, sizeof(comp_chunk_size)))
259  return DXFILEERR_BADFILETYPE;
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 }
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:168
#define XOFFILE_FORMAT_VERSION_302
Definition: parsing.c:38
#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:85
#define XOFFILE_FORMAT_MAGIC
Definition: parsing.c:37
#define TRACE(s)
Definition: solgame.cpp:4
#define GetProcessHeap()
Definition: compat.h:403
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:40
#define XOFFILE_FORMAT_TEXT
Definition: parsing.c:41
#define memcpy(s1, s2, n)
Definition: mkisofs.h:878
#define err(...)
#define XOFFILE_FORMAT_TEXT_MSZIP
Definition: parsing.c:43
#define ERR(fmt,...)
Definition: debug.h:109
#define S_OK
Definition: intsafe.h:59
#define XOFFILE_FORMAT_FLOAT_BITS_32
Definition: parsing.c:45
#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:42
#define HeapFree(x, y, z)
Definition: compat.h:402
#define XOFFILE_FORMAT_FLOAT_BITS_64
Definition: parsing.c:46
#define XOFFILE_FORMAT_VERSION_303
Definition: parsing.c:39

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 
1425  if (!parse_object_parts(buf, TRUE))
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 */
1431  check_TOKEN(buf);
1432 
1433  return TRUE;
1434 }
#define TRUE
Definition: types.h:120
GLenum GLuint GLenum GLsizei const GLchar * buf
Definition: glext.h:7751
#define TOKEN_OBRACE
Definition: parsing.c:56
static WORD check_TOKEN(parse_buffer *buf)
Definition: parsing.c:875
#define TOKEN_GUID
Definition: parsing.c:53
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
_Check_return_ _CRTIMP int __cdecl _strnicmp(_In_reads_or_z_(_MaxCount) const char *_Str1, _In_reads_or_z_(_MaxCount) const char *_Str2, _In_ size_t _MaxCount)
smooth NULL
Definition: ftsmooth.c:416
static BOOL parse_object_parts(parse_buffer *buf, BOOL allow_optional)
Definition: parsing.c:1293
#define memcpy(s1, s2, n)
Definition: mkisofs.h:878
#define ERR(fmt,...)
Definition: debug.h:109
#define TOKEN_NAME
Definition: parsing.c:50
char * strcpy(char *DstString, const char *SrcString)
Definition: utclib.c:388
unsigned int ULONG
Definition: retypes.h:1
#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

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 }
#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:1075
static WORD check_TOKEN(parse_buffer *buf)
Definition: parsing.c:875
#define TOKEN_NONE
Definition: parsing.c:49
#define TOKEN_TEMPLATE
Definition: parsing.c:67
#define TRACE(s)
Definition: solgame.cpp:4
static void dump_template(xtemplate *templates_array, xtemplate *ptemplate)
Definition: parsing.c:127
#define TRACE_ON(x)
Definition: compat.h:65

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