mirror of
https://github.com/FunkyFr3sh/cnc-ddraw.git
synced 2025-03-15 06:04:49 +01:00
Fix mouse hooks, workaround 64bit crash
This commit is contained in:
parent
4621157a67
commit
03b62b21d4
@ -103,12 +103,11 @@ HRESULT __stdcall ddraw_CreateClipper(IDirectDrawImpl *This, DWORD dwFlags, LPDI
|
||||
{
|
||||
printf("DirectDraw::CreateClipper(This=%p, dwFlags=%d, DDClipper=%p, unkOuter=%p)\n", This, (int)dwFlags, lplpDDClipper, pUnkOuter);
|
||||
|
||||
IDirectDrawClipperImpl *Clipper = (IDirectDrawClipperImpl *)HeapAlloc(GetProcessHeap(), 0, sizeof(IDirectDrawClipperImpl));
|
||||
IDirectDrawClipperImpl *Clipper = (IDirectDrawClipperImpl *)HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(IDirectDrawClipperImpl));
|
||||
Clipper->lpVtbl = &ciface;
|
||||
printf(" Clipper = %p\n", Clipper);
|
||||
*lplpDDClipper = (LPDIRECTDRAWCLIPPER)Clipper;
|
||||
|
||||
Clipper->Ref = 0;
|
||||
ddraw_clipper_AddRef(Clipper);
|
||||
|
||||
return DD_OK;
|
||||
|
5
main.c
5
main.c
@ -367,13 +367,14 @@ HRESULT WINAPI DirectDrawCreate(GUID FAR* lpGUID, LPDIRECTDRAW FAR* lplpDD, IUnk
|
||||
}
|
||||
#endif
|
||||
|
||||
printf("DirectDrawCreate(lpGUID=%p, lplpDD=%p, pUnkOuter=%p)\n", lpGUID, lplpDD, pUnkOuter);
|
||||
|
||||
if(ddraw)
|
||||
{
|
||||
printf(" returning DDERR_DIRECTDRAWALREADYCREATED\n");
|
||||
return DDERR_DIRECTDRAWALREADYCREATED;
|
||||
}
|
||||
|
||||
printf("DirectDrawCreate(lpGUID=%p, lplpDD=%p, pUnkOuter=%p)\n", lpGUID, lplpDD, pUnkOuter);
|
||||
|
||||
IDirectDrawImpl *This = (IDirectDrawImpl *)HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(IDirectDrawImpl));
|
||||
This->lpVtbl = &iface;
|
||||
printf(" This = %p\n", This);
|
||||
|
47
mouse.c
47
mouse.c
@ -37,12 +37,12 @@ struct game games[] =
|
||||
0x004C894A, /* address should contain 2E FF 15 */
|
||||
0x005B0184, /* GetCursorPos thunk addr */
|
||||
{
|
||||
0x004C88CB, /* ClipCursor */
|
||||
0x004C88DF, /* ClipCursor */
|
||||
0x0041114E, /* ShowCursor */
|
||||
0x00411197, /* ShowCursor */
|
||||
0x0045448F, /* ShowCursor */
|
||||
0x004CCE61, /* SetCursor */
|
||||
0x004C88CC, /* ClipCursor */
|
||||
0x004C88E0, /* ClipCursor */
|
||||
0x0041114F, /* ShowCursor */
|
||||
0x00411198, /* ShowCursor */
|
||||
0x00454490, /* ShowCursor */
|
||||
0x004CCE62, /* SetCursor */
|
||||
0x00000000
|
||||
},
|
||||
},
|
||||
@ -51,14 +51,14 @@ struct game games[] =
|
||||
0x005B39C0,
|
||||
0x005E6848,
|
||||
{
|
||||
0x005C194C, /* ClipCursor */
|
||||
0x005C196C, /* ClipCursor */
|
||||
0x004F839F, /* ShowCursor */
|
||||
0x005B3A25, /* ShowCursor */
|
||||
0x005B3A72, /* ShowCursor */
|
||||
0x005A02CC, /* SetCursor */
|
||||
0x005A0309, /* SetCursor */
|
||||
0x005A0323, /* SetCursor */
|
||||
0x005C194D, /* ClipCursor */
|
||||
0x005C196D, /* ClipCursor */
|
||||
0x004F83A0, /* ShowCursor */
|
||||
0x005B3A26, /* ShowCursor */
|
||||
0x005B3A73, /* ShowCursor */
|
||||
0x005A02CD, /* SetCursor */
|
||||
0x005A030A, /* SetCursor */
|
||||
0x005A0324, /* SetCursor */
|
||||
0x00000000
|
||||
},
|
||||
},
|
||||
@ -78,9 +78,11 @@ BOOL WINAPI fake_GetCursorPos(LPPOINT lpPoint)
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
BOOL mouse_active = FALSE;
|
||||
|
||||
void mouse_lock()
|
||||
{
|
||||
if(!ddraw->locked)
|
||||
if(mouse_active && !ddraw->locked)
|
||||
{
|
||||
ddraw->locked = TRUE;
|
||||
ClipCursor(&ddraw->cursorclip);
|
||||
@ -91,6 +93,11 @@ void mouse_lock()
|
||||
|
||||
void mouse_unlock()
|
||||
{
|
||||
if(!mouse_active)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if(ddraw->locked)
|
||||
{
|
||||
ShowCursor(TRUE);
|
||||
@ -114,7 +121,7 @@ void mouse_init(HWND hWnd)
|
||||
DWORD dwWritten;
|
||||
int i;
|
||||
|
||||
unsigned char buf[8];
|
||||
unsigned char buf[7];
|
||||
|
||||
GetWindowThreadProcessId(hWnd, &tmp);
|
||||
hProcess = OpenProcess(PROCESS_ALL_ACCESS, FALSE, tmp);
|
||||
@ -130,15 +137,19 @@ void mouse_init(HWND hWnd)
|
||||
{
|
||||
WriteProcessMemory(hProcess, (void *)ptr->hook, &tmp, 4, &dwWritten);
|
||||
|
||||
memset(buf, 0x90, 8);
|
||||
memset(buf, 0x90, 7); // NOP
|
||||
buf[0] = 0x58; // POP EAX
|
||||
buf[1] = 0x33; // XOR EAX,EAX
|
||||
buf[2] = 0xC0; // ^
|
||||
for(i=0;i<MAX_NOPS;i++)
|
||||
{
|
||||
if(!ptr->nops[i])
|
||||
break;
|
||||
|
||||
WriteProcessMemory(hProcess, (void *)ptr->nops[i], buf, 8, &dwWritten);
|
||||
WriteProcessMemory(hProcess, (void *)ptr->nops[i], buf, 7, &dwWritten);
|
||||
}
|
||||
|
||||
mouse_active = TRUE;
|
||||
return;
|
||||
}
|
||||
ptr++;
|
||||
|
@ -103,14 +103,13 @@ HRESULT __stdcall ddraw_CreatePalette(IDirectDrawImpl *This, DWORD dwFlags, LPPA
|
||||
{
|
||||
printf("DirectDraw::CreatePalette(This=%p, dwFlags=%d, DDColorArray=%p, DDPalette=%p, unkOuter=%p)\n", This, (int)dwFlags, lpDDColorArray, lpDDPalette, unkOuter);
|
||||
|
||||
IDirectDrawPaletteImpl *Palette = (IDirectDrawPaletteImpl *)HeapAlloc(GetProcessHeap(), 0, sizeof(IDirectDrawPaletteImpl));
|
||||
IDirectDrawPaletteImpl *Palette = (IDirectDrawPaletteImpl *)HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(IDirectDrawPaletteImpl));
|
||||
Palette->lpVtbl = &piface;
|
||||
printf(" Palette = %p\n", Palette);
|
||||
*lpDDPalette = (LPDIRECTDRAWPALETTE)Palette;
|
||||
|
||||
ddraw_palette_SetEntries(Palette, dwFlags, 0, 256, lpDDColorArray);
|
||||
|
||||
Palette->Ref = 0;
|
||||
ddraw_palette_AddRef(Palette);
|
||||
|
||||
return DD_OK;
|
||||
|
33
surface.c
33
surface.c
@ -53,22 +53,18 @@ ULONG __stdcall ddraw_surface_Release(IDirectDrawSurfaceImpl *This)
|
||||
This->dRun = FALSE;
|
||||
SetEvent(This->flipEvent);
|
||||
WaitForSingleObject(This->dThread, INFINITE);
|
||||
This->dThread = NULL;
|
||||
}
|
||||
if(This->surface)
|
||||
{
|
||||
free(This->surface);
|
||||
//free(This->surface);
|
||||
}
|
||||
#if USE_OPENGL
|
||||
if(This->glTex)
|
||||
{
|
||||
free(This->glTex);
|
||||
}
|
||||
#endif
|
||||
if(This->palette)
|
||||
{
|
||||
IDirectDrawPalette_Release(This->palette);
|
||||
}
|
||||
free(This);
|
||||
/* FIXME: crashing on 64bit windows, investigate! */
|
||||
//free(This);
|
||||
return 0;
|
||||
}
|
||||
return This->Ref;
|
||||
@ -403,22 +399,14 @@ HRESULT __stdcall ddraw_CreateSurface(IDirectDrawImpl *This, LPDDSURFACEDESC lpD
|
||||
|
||||
dump_ddsd(lpDDSurfaceDesc->dwFlags);
|
||||
|
||||
IDirectDrawSurfaceImpl *Surface = (IDirectDrawSurfaceImpl *)HeapAlloc(GetProcessHeap(), 0, sizeof(IDirectDrawSurfaceImpl));
|
||||
IDirectDrawSurfaceImpl *Surface = (IDirectDrawSurfaceImpl *)HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(IDirectDrawSurfaceImpl));
|
||||
|
||||
Surface->lpVtbl = &siface;
|
||||
|
||||
/* private stuff */
|
||||
Surface->parent = This;
|
||||
Surface->bpp = This->bpp;
|
||||
Surface->surface = NULL;
|
||||
Surface->caps = 0;
|
||||
Surface->palette = NULL;
|
||||
Surface->dThread = NULL;
|
||||
Surface->dRun = TRUE;
|
||||
#if USE_OPENGL
|
||||
Surface->hDC = NULL;
|
||||
Surface->glTex = NULL;
|
||||
#endif
|
||||
|
||||
if(lpDDSurfaceDesc->dwFlags & DDSD_CAPS)
|
||||
{
|
||||
@ -451,9 +439,6 @@ HRESULT __stdcall ddraw_CreateSurface(IDirectDrawImpl *This, LPDDSURFACEDESC lpD
|
||||
Surface->lPitch = Surface->width;
|
||||
Surface->lXPitch = Surface->bpp / 8;
|
||||
Surface->surface = malloc(Surface->width * Surface->height * Surface->lXPitch);
|
||||
#if USE_OPENGL
|
||||
Surface->glTex = malloc(Surface->width * Surface->height * sizeof(int));
|
||||
#endif
|
||||
}
|
||||
|
||||
printf(" Surface = %p (%dx%d@%d)\n", Surface, (int)Surface->width, (int)Surface->height, (int)Surface->bpp);
|
||||
@ -474,6 +459,8 @@ DWORD WINAPI ogl_Thread(IDirectDrawSurfaceImpl *This)
|
||||
|
||||
This->hDC = GetDC(This->hWnd);
|
||||
|
||||
int *glTex = malloc(This->width * This->height * sizeof(int));
|
||||
|
||||
memset(&pfd, 0, sizeof(PIXELFORMATDESCRIPTOR));
|
||||
pfd.nSize = sizeof(PIXELFORMATDESCRIPTOR);
|
||||
pfd.nVersion = 1;
|
||||
@ -499,11 +486,11 @@ DWORD WINAPI ogl_Thread(IDirectDrawSurfaceImpl *This)
|
||||
{
|
||||
for(j=0; j<This->width; j++)
|
||||
{
|
||||
This->glTex[i*This->width+j] = This->palette->data[((unsigned char *)This->surface)[i*This->lPitch + j*This->lXPitch]];
|
||||
glTex[i*This->width+j] = This->palette->data[((unsigned char *)This->surface)[i*This->lPitch + j*This->lXPitch]];
|
||||
}
|
||||
}
|
||||
|
||||
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, This->width, This->height, 0, GL_RGBA, GL_UNSIGNED_BYTE, This->glTex);
|
||||
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, This->width, This->height, 0, GL_RGBA, GL_UNSIGNED_BYTE, glTex);
|
||||
|
||||
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_NEAREST);
|
||||
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_NEAREST);
|
||||
@ -520,6 +507,8 @@ DWORD WINAPI ogl_Thread(IDirectDrawSurfaceImpl *This)
|
||||
SwapBuffers(This->hDC);
|
||||
}
|
||||
|
||||
free(glTex);
|
||||
|
||||
wglMakeCurrent(NULL, NULL);
|
||||
wglDeleteContext(This->hRC);
|
||||
ReleaseDC(This->hWnd, This->hDC);
|
||||
|
Loading…
x
Reference in New Issue
Block a user