diff --git a/Makefile b/Makefile index 5ea6a88..d199333 100644 --- a/Makefile +++ b/Makefile @@ -1,5 +1,5 @@ all: - i586-mingw32msvc-gcc -Wall -Wl,--enable-stdcall-fixup -shared -s -o ddraw.dll main.c palette.c surface.c ddraw.def -lgdi32 -lopengl32 + i586-mingw32msvc-gcc -D_DEBUG -Wall -Wl,--enable-stdcall-fixup -shared -s -o ddraw.dll main.c palette.c surface.c clipper.c ddraw.def -lgdi32 -lopengl32 clean: rm -f ddraw.dll diff --git a/clipper.c b/clipper.c new file mode 100644 index 0000000..949c607 --- /dev/null +++ b/clipper.c @@ -0,0 +1,88 @@ +/* + * Copyright (c) 2010 Toni Spets + * + * Permission to use, copy, modify, and distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + */ + +#include +#include +#include "clipper.h" + +/* from main */ +HRESULT null(); + +HRESULT ddraw_clipper_QueryInterface(void *This, REFIID riid, void **obj) +{ + printf("DirectDrawClipper::QueryInterface(This=%p, riid=%08X, obj=%p)\n", This, (unsigned int)riid, obj); + return S_OK; +} + +ULONG ddraw_clipper_AddRef(void *_This) +{ + fakeDirectDrawClipperObject *This = (fakeDirectDrawClipperObject *)_This; + + printf("DirectDrawClipper::AddRef(This=%p)\n", This); + + This->Ref++; + + return This->Ref; +} + +ULONG ddraw_clipper_Release(void *_This) +{ + fakeDirectDrawClipperObject *This = (fakeDirectDrawClipperObject *)_This; + + printf("DirectDrawClipper::Release(This=%p)\n", This); + + This->Ref--; + + if(This->Ref == 0) + { + free(This); + return 0; + } + + return This->Ref; +} + +fakeDirectDrawClipper ciface = +{ + /* IUnknown */ + ddraw_clipper_QueryInterface, + ddraw_clipper_AddRef, + ddraw_clipper_Release, + /* IDirectDrawClipper */ + null, // ddraw_clipper_GetClipList + null, // ddraw_clipper_GetHWnd + null, // ddraw_clipper_Initialize + null, // ddraw_clipper_IsClipListChanged + null, // ddraw_clipper_SetClipList + null // ddraw_clipper_SetHwnd +}; + +HRESULT ddraw_CreateClipper(void *_This, DWORD dwFlags, LPDIRECTDRAWCLIPPER FAR *lplpDDClipper, IUnknown FAR *pUnkOuter ) +{ + fakeDirectDrawClipperObject *This = (fakeDirectDrawClipperObject *)_This; + + printf("DirectDraw::CreateClipper(This=%p, dwFlags=%d, DDClipper=%p, unkOuter=%p)\n", This, (int)dwFlags, lplpDDClipper, pUnkOuter); + + fakeDirectDrawClipperObject *Clipper = (fakeDirectDrawClipperObject *)malloc(sizeof(fakeDirectDrawClipperObject)); + Clipper->Functions = &ciface; + printf(" Clipper = %p\n", Clipper); + *lplpDDClipper = (LPDIRECTDRAWCLIPPER)Clipper; + + Clipper->Ref = 0; + ddraw_clipper_AddRef(Clipper); + + return DD_OK; +} diff --git a/clipper.h b/clipper.h new file mode 100644 index 0000000..72fbbe5 --- /dev/null +++ b/clipper.h @@ -0,0 +1,51 @@ +/* + * Copyright (c) 2010 Toni Spets + * + * Permission to use, copy, modify, and distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + */ + +#ifndef CLIPPER_H +#define CLIPPER_H + +#include +#include "ddraw.h" + +typedef struct +{ + /* IUnknown */ + HRESULT (*QueryInterface)(void *, REFIID, void **); + ULONG (*AddRef)(void *); + ULONG (*Release)(void *); + + /* IDirectDrawClipper */ + HRESULT (*GetClipList)(void *, LPRECT, LPRGNDATA, LPDWORD); + HRESULT (*GetHWnd)(void *, HWND FAR *); + HRESULT (*Initialize)(void *, LPDIRECTDRAW, DWORD); + HRESULT (*IsClipListChanged)(void *, BOOL FAR *); + HRESULT (*SetClipList)(void *, LPRGNDATA,DWORD); + HRESULT (*SetHWnd)(void *, DWORD, HWND ); +} fakeDirectDrawClipper; + +typedef struct +{ + fakeDirectDrawClipper *Functions; + + ULONG Ref; + +} fakeDirectDrawClipperObject; + +extern fakeDirectDrawClipper ciface; + +HRESULT ddraw_CreateClipper(void *_This, DWORD dwFlags, LPDIRECTDRAWCLIPPER FAR *lplpDDClipper, IUnknown FAR *pUnkOuter ); + +#endif diff --git a/main.c b/main.c index d05bcf3..5de7f95 100644 --- a/main.c +++ b/main.c @@ -21,6 +21,7 @@ #include "main.h" #include "palette.h" #include "surface.h" +#include "clipper.h" HRESULT ddraw_GetCaps(void *This, LPDDCAPS lpDDDriverCaps, LPDDCAPS lpDDEmulCaps) { @@ -131,7 +132,7 @@ fakeDirectDraw iface = ddraw_Release, /* IDirectDraw */ null, //Compact, - null, //CreateClipper, + ddraw_CreateClipper, ddraw_CreatePalette, ddraw_CreateSurface, null, //DuplicateSurface, @@ -154,6 +155,10 @@ fakeDirectDraw iface = HRESULT WINAPI DirectDrawCreate(GUID FAR* lpGUID, LPDIRECTDRAW FAR* lplpDD, IUnknown FAR* pUnkOuter) { +#if _DEBUG + freopen("stdout.txt", "w", stdout); +#endif + printf("DirectDrawCreate(lpGUID=%p, lplpDD=%p, pUnkOuter=%p)\n", lpGUID, lplpDD, pUnkOuter); fakeDirectDrawObject *This = (fakeDirectDrawObject *)malloc(sizeof(fakeDirectDrawObject)); diff --git a/main.h b/main.h index 51ffd14..397ea56 100644 --- a/main.h +++ b/main.h @@ -31,7 +31,7 @@ typedef struct /* IDirectDraw */ HRESULT (*Compact)(void *); - HRESULT (*CreateClipper)(void *); + HRESULT (*CreateClipper)(void *, DWORD, LPDIRECTDRAWCLIPPER FAR *, IUnknown FAR *); HRESULT (*CreatePalette)(void *, DWORD, LPPALETTEENTRY, LPDIRECTDRAWPALETTE FAR *, IUnknown FAR *); HRESULT (*CreateSurface)(void *, LPDDSURFACEDESC, LPDIRECTDRAWSURFACE FAR *, IUnknown FAR *); HRESULT (*DuplicateSurface)(void *);