[PATCH] d3dxof: Add string expansion extension to d3dxof and make d3dx9_36 use it.
Christian Costa
titan.costa at gmail.com
Wed May 8 00:31:25 CDT 2013
d3dxof stores strings in data by putting its pointer while d3dx9_36 put directly its content.
This patch adds an extension to enable the string expansion mode by calling RegisterTemplates with a special 'expand_string' keyword.
---
dlls/d3dx9_36/xfile.c | 6 ++++++
dlls/d3dxof/d3dxof.c | 21 ++++++++++++++++-----
dlls/d3dxof/d3dxof_private.h | 1 +
dlls/d3dxof/parsing.c | 33 +++++++++++++++++++++++----------
4 files changed, 46 insertions(+), 15 deletions(-)
diff --git a/dlls/d3dx9_36/xfile.c b/dlls/d3dx9_36/xfile.c
index 81f9da3..e5075db 100644
--- a/dlls/d3dx9_36/xfile.c
+++ b/dlls/d3dx9_36/xfile.c
@@ -677,6 +677,7 @@ HRESULT WINAPI D3DXFileCreate(ID3DXFile **d3dxfile)
{
ID3DXFileImpl *object;
HRESULT ret;
+ const char expand_string[] = "expand_string";
TRACE("(%p)\n", d3dxfile);
@@ -701,6 +702,11 @@ HRESULT WINAPI D3DXFileCreate(ID3DXFile **d3dxfile)
object->ID3DXFile_iface.lpVtbl = &ID3DXFile_Vtbl;
object->ref = 1;
+ /* Enable string expansion extension in d3dxof */
+ ret = IDirectXFile_RegisterTemplates(object->dxfile, (void*)expand_string, sizeof(expand_string));
+ if (ret != DXFILE_OK)
+ ERR("Native d3dxof.dll used. Use builtin one to avoid problem.\n");
+
*d3dxfile = &object->ID3DXFile_iface;
return S_OK;
diff --git a/dlls/d3dxof/d3dxof.c b/dlls/d3dxof/d3dxof.c
index 498b192..c6b2cda 100644
--- a/dlls/d3dxof/d3dxof.c
+++ b/dlls/d3dxof/d3dxof.c
@@ -290,6 +290,7 @@ static HRESULT WINAPI IDirectXFileImpl_RegisterTemplates(IDirectXFile* iface, LP
parse_buffer buf;
HRESULT hr;
LPBYTE decomp_buffer = NULL;
+ const char expand_string[] = "expand_string";
buf.buffer = pvData;
buf.rem_bytes = cbSize;
@@ -302,6 +303,13 @@ static HRESULT WINAPI IDirectXFileImpl_RegisterTemplates(IDirectXFile* iface, LP
if (!pvData)
return DXFILEERR_BADVALUE;
+ if ((cbSize >= sizeof(expand_string)) && !strcmp(pvData, expand_string))
+ {
+ TRACE("Expand string mode enabled\n");
+ This->expand_string = TRUE;
+ return DXFILE_OK;
+ }
+
if (TRACE_ON(d3dxof_dump))
{
static USHORT num;
@@ -1022,12 +1030,15 @@ static HRESULT WINAPI IDirectXFileEnumObjectImpl_GetNextDataObject(IDirectXFileE
goto error;
}
- object->pstrings = HeapAlloc(GetProcessHeap(), 0, MAX_STRINGS_BUFFER);
- if (!object->pstrings)
+ if (!This->pDirectXFile->expand_string)
{
- ERR("Out of memory\n");
- hr = DXFILEERR_BADALLOC;
- goto error;
+ object->pstrings = HeapAlloc(GetProcessHeap(), 0, MAX_STRINGS_BUFFER);
+ if (!object->pstrings)
+ {
+ ERR("Out of memory\n");
+ hr = DXFILEERR_BADALLOC;
+ goto error;
+ }
}
object->cur_enum_object = 0;
diff --git a/dlls/d3dxof/d3dxof_private.h b/dlls/d3dxof/d3dxof_private.h
index 5bd3c71..9b8266b 100644
--- a/dlls/d3dxof/d3dxof_private.h
+++ b/dlls/d3dxof/d3dxof_private.h
@@ -89,6 +89,7 @@ typedef struct {
LONG ref;
ULONG nb_xtemplates;
xtemplate xtemplates[MAX_TEMPLATES];
+ BOOL expand_string;
} IDirectXFileImpl;
typedef struct {
diff --git a/dlls/d3dxof/parsing.c b/dlls/d3dxof/parsing.c
index 37cf2e1..6b96ca2 100644
--- a/dlls/d3dxof/parsing.c
+++ b/dlls/d3dxof/parsing.c
@@ -1248,20 +1248,33 @@ static BOOL parse_object_members_list(parse_buffer * buf)
{
get_TOKEN(buf);
TRACE("%s = %s\n", pt->members[i].name, (char*)buf->value);
- if (!check_buffer(buf, sizeof(LPSTR)))
- return FALSE;
if (pt->members[i].type == TOKEN_LPSTR)
{
int len = strlen((char*)buf->value) + 1;
- if ((buf->cur_pstrings - buf->pstrings + len) > MAX_STRINGS_BUFFER)
+
+ if (buf->pstrings)
+ {
+ /* Add a pointer to the string to the data */
+ if (!check_buffer(buf, sizeof(LPSTR)))
+ return FALSE;
+ if ((buf->cur_pstrings - buf->pstrings + len) > MAX_STRINGS_BUFFER)
+ {
+ FIXME("Buffer too small %p %p %d\n", buf->cur_pstrings, buf->pstrings, len);
+ return FALSE;
+ }
+ strcpy((char*)buf->cur_pstrings, (char*)buf->value);
+ *(((LPCSTR*)(buf->pdata + buf->cur_pos_data))) = (char*)buf->cur_pstrings;
+ buf->cur_pstrings += len;
+ buf->cur_pos_data += sizeof(LPSTR);
+ }
+ else
{
- FIXME("Buffer too small %p %p %d\n", buf->cur_pstrings, buf->pstrings, len);
- return FALSE;
+ /* Add the string to the data */
+ if (!check_buffer(buf, len))
+ return FALSE;
+ memcpy(buf->pdata + buf->cur_pos_data, buf->value, len);
+ buf->cur_pos_data += len;
}
- strcpy((char*)buf->cur_pstrings, (char*)buf->value);
- *(((LPCSTR*)(buf->pdata + buf->cur_pos_data))) = (char*)buf->cur_pstrings;
- buf->cur_pstrings += len;
- buf->cur_pos_data += sizeof(LPSTR);
}
else
{
@@ -1270,7 +1283,7 @@ static BOOL parse_object_members_list(parse_buffer * buf)
}
}
else
- {
+ {
FIXME("Unexpected token %d\n", token);
return FALSE;
}
More information about the wine-patches
mailing list