compile resources again + cleanup
This commit is contained in:
parent
850dfda0f5
commit
153bfda117
25 changed files with 3811 additions and 3849 deletions
114
src/clipper.c
Normal file
114
src/clipper.c
Normal file
|
@ -0,0 +1,114 @@
|
|||
/*
|
||||
* Copyright (c) 2010 Toni Spets <toni.spets@iki.fi>
|
||||
*
|
||||
* 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 <windows.h>
|
||||
#include <stdio.h>
|
||||
#include "clipper.h"
|
||||
|
||||
HRESULT __stdcall ddraw_clipper_QueryInterface(IDirectDrawClipperImpl *This, REFIID riid, void **obj)
|
||||
{
|
||||
printf("DirectDrawClipper::QueryInterface(This=%p, riid=%08X, obj=%p)\n", This, (unsigned int)riid, obj);
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
ULONG __stdcall ddraw_clipper_AddRef(IDirectDrawClipperImpl *This)
|
||||
{
|
||||
printf("DirectDrawClipper::AddRef(This=%p)\n", This);
|
||||
|
||||
This->Ref++;
|
||||
|
||||
return This->Ref;
|
||||
}
|
||||
|
||||
ULONG __stdcall ddraw_clipper_Release(IDirectDrawClipperImpl *This)
|
||||
{
|
||||
printf("DirectDrawClipper::Release(This=%p)\n", This);
|
||||
|
||||
This->Ref--;
|
||||
|
||||
if(This->Ref == 0)
|
||||
{
|
||||
HeapFree(GetProcessHeap(), 0, This);
|
||||
return 0;
|
||||
}
|
||||
|
||||
return This->Ref;
|
||||
}
|
||||
|
||||
HRESULT __stdcall ddraw_clipper_GetClipList(IDirectDrawClipperImpl *This, LPRECT a, LPRGNDATA b, LPDWORD c)
|
||||
{
|
||||
printf("IDirectDrawClipper::GetClipList(This=%p, ...)\n", This);
|
||||
return DD_OK;
|
||||
}
|
||||
|
||||
HRESULT __stdcall ddraw_clipper_GetHWnd(IDirectDrawClipperImpl *This, HWND FAR *a)
|
||||
{
|
||||
printf("IDirectDrawClipper::GetHWnd(This=%p, ...)\n", This);
|
||||
return DD_OK;
|
||||
}
|
||||
|
||||
HRESULT __stdcall ddraw_clipper_Initialize(IDirectDrawClipperImpl *This, LPDIRECTDRAW a, DWORD b)
|
||||
{
|
||||
printf("IDirectDrawClipper::Initialize(This=%p, ...)\n", This);
|
||||
return DD_OK;
|
||||
}
|
||||
|
||||
HRESULT __stdcall ddraw_clipper_IsClipListChanged(IDirectDrawClipperImpl *This, BOOL FAR *a)
|
||||
{
|
||||
printf("IDirectDrawClipper::IsClipListChanged(This=%p, ...)\n", This);
|
||||
return DD_OK;
|
||||
}
|
||||
|
||||
HRESULT __stdcall ddraw_clipper_SetClipList(IDirectDrawClipperImpl *This, LPRGNDATA a, DWORD b)
|
||||
{
|
||||
printf("IDirectDrawClipper::SetClipList(This=%p, ...)\n", This);
|
||||
return DD_OK;
|
||||
}
|
||||
|
||||
HRESULT __stdcall ddraw_clipper_SetHWnd(IDirectDrawClipperImpl *This, DWORD a, HWND b)
|
||||
{
|
||||
printf("IDirectDrawClipper::SetHWnd(This=%p, ...)\n", This);
|
||||
return DD_OK;
|
||||
}
|
||||
|
||||
struct IDirectDrawClipperImplVtbl ciface =
|
||||
{
|
||||
/* IUnknown */
|
||||
ddraw_clipper_QueryInterface,
|
||||
ddraw_clipper_AddRef,
|
||||
ddraw_clipper_Release,
|
||||
/* IDirectDrawClipper */
|
||||
ddraw_clipper_GetClipList,
|
||||
ddraw_clipper_GetHWnd,
|
||||
ddraw_clipper_Initialize,
|
||||
ddraw_clipper_IsClipListChanged,
|
||||
ddraw_clipper_SetClipList,
|
||||
ddraw_clipper_SetHWnd
|
||||
};
|
||||
|
||||
HRESULT __stdcall ddraw_CreateClipper(IDirectDrawImpl *This, DWORD dwFlags, LPDIRECTDRAWCLIPPER FAR *lplpDDClipper, IUnknown FAR *pUnkOuter )
|
||||
{
|
||||
printf("DirectDraw::CreateClipper(This=%p, dwFlags=%d, DDClipper=%p, unkOuter=%p)\n", This, (int)dwFlags, lplpDDClipper, pUnkOuter);
|
||||
|
||||
IDirectDrawClipperImpl *Clipper = (IDirectDrawClipperImpl *)HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(IDirectDrawClipperImpl));
|
||||
Clipper->lpVtbl = &ciface;
|
||||
printf(" Clipper = %p\n", Clipper);
|
||||
*lplpDDClipper = (LPDIRECTDRAWCLIPPER)Clipper;
|
||||
|
||||
ddraw_clipper_AddRef(Clipper);
|
||||
|
||||
return DD_OK;
|
||||
}
|
983
src/main.c
Normal file
983
src/main.c
Normal file
|
@ -0,0 +1,983 @@
|
|||
/*
|
||||
* Copyright (c) 2010 Toni Spets <toni.spets@iki.fi>
|
||||
*
|
||||
* 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 <windows.h>
|
||||
#include <windowsx.h>
|
||||
#include <stdio.h>
|
||||
#include <ctype.h>
|
||||
#include "ddraw.h"
|
||||
|
||||
#include "main.h"
|
||||
#include "palette.h"
|
||||
#include "surface.h"
|
||||
#include "clipper.h"
|
||||
|
||||
#define IDR_MYMENU 93
|
||||
|
||||
/* from mouse.c */
|
||||
BOOL WINAPI fake_GetCursorPos(LPPOINT lpPoint);
|
||||
void mouse_init(HWND);
|
||||
void mouse_lock();
|
||||
void mouse_unlock();
|
||||
|
||||
/* from screenshot.c */
|
||||
#ifdef HAVE_LIBPNG
|
||||
BOOL screenshot(struct IDirectDrawSurfaceImpl *);
|
||||
#endif
|
||||
|
||||
IDirectDrawImpl *ddraw = NULL;
|
||||
|
||||
DWORD WINAPI render_main(void);
|
||||
DWORD WINAPI render_soft_main(void);
|
||||
DWORD WINAPI render_dummy_main(void);
|
||||
|
||||
int WindowPosX;
|
||||
int WindowPosY;
|
||||
char SettingsIniPath[MAX_PATH];
|
||||
|
||||
BOOL WINAPI DllMain(HANDLE hDll, DWORD dwReason, LPVOID lpReserved)
|
||||
{
|
||||
switch (dwReason)
|
||||
{
|
||||
case DLL_PROCESS_ATTACH:
|
||||
{
|
||||
printf("cnc-ddraw DLL_PROCESS_ATTACH");
|
||||
|
||||
//SetProcessPriorityBoost(GetCurrentProcess(), TRUE);
|
||||
timeBeginPeriod(1);
|
||||
break;
|
||||
}
|
||||
case DLL_PROCESS_DETACH:
|
||||
{
|
||||
printf("cnc-ddraw DLL_PROCESS_DETACH");
|
||||
|
||||
char buf[16];
|
||||
sprintf(buf, "%d", WindowPosX);
|
||||
WritePrivateProfileString("ddraw", "posX", buf, SettingsIniPath);
|
||||
|
||||
sprintf(buf, "%d", WindowPosY);
|
||||
WritePrivateProfileString("ddraw", "posY", buf, SettingsIniPath);
|
||||
|
||||
timeEndPeriod(1);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
HRESULT __stdcall ddraw_Compact(IDirectDrawImpl *This)
|
||||
{
|
||||
printf("DirectDraw::Compact(This=%p)\n", This);
|
||||
|
||||
return DD_OK;
|
||||
}
|
||||
|
||||
HRESULT __stdcall ddraw_DuplicateSurface(IDirectDrawImpl *This, LPDIRECTDRAWSURFACE src, LPDIRECTDRAWSURFACE *dest)
|
||||
{
|
||||
printf("DirectDraw::DuplicateSurface(This=%p, ...)\n", This);
|
||||
return DD_OK;
|
||||
}
|
||||
|
||||
HRESULT __stdcall ddraw_EnumDisplayModes(IDirectDrawImpl *This, DWORD a, LPDDSURFACEDESC b, LPVOID c, LPDDENUMMODESCALLBACK d)
|
||||
{
|
||||
printf("DirectDraw::EnumDisplayModes(This=%p, ...)\n", This);
|
||||
return DD_OK;
|
||||
}
|
||||
|
||||
HRESULT __stdcall ddraw_EnumSurfaces(IDirectDrawImpl *This, DWORD a, LPDDSURFACEDESC b, LPVOID c, LPDDENUMSURFACESCALLBACK d)
|
||||
{
|
||||
printf("DirectDraw::EnumSurfaces(This=%p, ...)\n", This);
|
||||
return DD_OK;
|
||||
}
|
||||
|
||||
HRESULT __stdcall ddraw_FlipToGDISurface(IDirectDrawImpl *This)
|
||||
{
|
||||
printf("DirectDraw::FlipToGDISurface(This=%p)\n", This);
|
||||
|
||||
return DD_OK;
|
||||
}
|
||||
|
||||
HRESULT __stdcall ddraw_GetCaps(IDirectDrawImpl *This, LPDDCAPS lpDDDriverCaps, LPDDCAPS lpDDEmulCaps)
|
||||
{
|
||||
printf("DirectDraw::GetCaps(This=%p, lpDDDriverCaps=%p, lpDDEmulCaps=%p)\n", This, lpDDDriverCaps, lpDDEmulCaps);
|
||||
|
||||
if(lpDDDriverCaps)
|
||||
{
|
||||
lpDDDriverCaps->dwSize = sizeof(DDCAPS);
|
||||
lpDDDriverCaps->dwCaps = DDCAPS_BLT|DDCAPS_PALETTE;
|
||||
lpDDDriverCaps->dwCKeyCaps = 0;
|
||||
lpDDDriverCaps->dwPalCaps = DDPCAPS_8BIT|DDPCAPS_PRIMARYSURFACE;
|
||||
lpDDDriverCaps->dwVidMemTotal = 16777216;
|
||||
lpDDDriverCaps->dwVidMemFree = 16777216;
|
||||
lpDDDriverCaps->dwMaxVisibleOverlays = 0;
|
||||
lpDDDriverCaps->dwCurrVisibleOverlays = 0;
|
||||
lpDDDriverCaps->dwNumFourCCCodes = 0;
|
||||
lpDDDriverCaps->dwAlignBoundarySrc = 0;
|
||||
lpDDDriverCaps->dwAlignSizeSrc = 0;
|
||||
lpDDDriverCaps->dwAlignBoundaryDest = 0;
|
||||
lpDDDriverCaps->dwAlignSizeDest = 0;
|
||||
}
|
||||
|
||||
if(lpDDEmulCaps)
|
||||
{
|
||||
lpDDEmulCaps->dwSize = 0;
|
||||
}
|
||||
|
||||
return DD_OK;
|
||||
}
|
||||
|
||||
HRESULT __stdcall ddraw_GetDisplayMode(IDirectDrawImpl *This, LPDDSURFACEDESC a)
|
||||
{
|
||||
printf("DirectDraw::GetDisplayMode(This=%p, ...)\n", This);
|
||||
return DD_OK;
|
||||
}
|
||||
|
||||
HRESULT __stdcall ddraw_GetFourCCCodes(IDirectDrawImpl *This, LPDWORD a, LPDWORD b)
|
||||
{
|
||||
printf("DirectDraw::GetFourCCCodes(This=%p, ...)\n", This);
|
||||
return DD_OK;
|
||||
}
|
||||
|
||||
HRESULT __stdcall ddraw_GetGDISurface(IDirectDrawImpl *This, LPDIRECTDRAWSURFACE *a)
|
||||
{
|
||||
printf("DirectDraw::GetGDISurface(This=%p, ...)\n", This);
|
||||
return DD_OK;
|
||||
}
|
||||
|
||||
HRESULT __stdcall ddraw_GetMonitorFrequency(IDirectDrawImpl *This, LPDWORD a)
|
||||
{
|
||||
printf("DirectDraw::GetMonitorFrequency(This=%p, ...)\n", This);
|
||||
return DD_OK;
|
||||
}
|
||||
|
||||
HRESULT __stdcall ddraw_GetScanLine(IDirectDrawImpl *This, LPDWORD a)
|
||||
{
|
||||
printf("DirectDraw::GetScanLine(This=%p, ...)\n", This);
|
||||
return DD_OK;
|
||||
}
|
||||
|
||||
HRESULT __stdcall ddraw_GetVerticalBlankStatus(IDirectDrawImpl *This, LPBOOL a)
|
||||
{
|
||||
printf("DirectDraw::GetVerticalBlankStatus(This=%p, ...)\n", This);
|
||||
return DD_OK;
|
||||
}
|
||||
|
||||
HRESULT __stdcall ddraw_Initialize(IDirectDrawImpl *This, GUID *a)
|
||||
{
|
||||
printf("DirectDraw::Initialize(This=%p, ...)\n", This);
|
||||
return DD_OK;
|
||||
}
|
||||
|
||||
HRESULT __stdcall ddraw_RestoreDisplayMode(IDirectDrawImpl *This)
|
||||
{
|
||||
printf("DirectDraw::RestoreDisplayMode(This=%p)\n", This);
|
||||
|
||||
if(!This->render.run)
|
||||
{
|
||||
return DD_OK;
|
||||
}
|
||||
|
||||
if(!ddraw->windowed)
|
||||
{
|
||||
ChangeDisplaySettings(&This->mode, 0);
|
||||
}
|
||||
|
||||
return DD_OK;
|
||||
}
|
||||
|
||||
HRESULT __stdcall ddraw_SetDisplayMode(IDirectDrawImpl *This, DWORD width, DWORD height, DWORD bpp)
|
||||
{
|
||||
printf("DirectDraw::SetDisplayMode(This=%p, width=%d, height=%d, bpp=%d)\n", This, (unsigned int)width, (unsigned int)height, (unsigned int)bpp);
|
||||
|
||||
This->mode.dmSize = sizeof(DEVMODE);
|
||||
This->mode.dmDriverExtra = 0;
|
||||
|
||||
if(EnumDisplaySettings(NULL, ENUM_CURRENT_SETTINGS, &This->mode) == FALSE)
|
||||
{
|
||||
/* not expected */
|
||||
return DDERR_UNSUPPORTED;
|
||||
}
|
||||
|
||||
This->width = width;
|
||||
This->height = height;
|
||||
This->bpp = bpp;
|
||||
This->cursorclip.width = width;
|
||||
This->cursorclip.height = height;
|
||||
|
||||
ddraw->cursor.x = ddraw->cursorclip.width / 2;
|
||||
ddraw->cursor.y = ddraw->cursorclip.height / 2;
|
||||
|
||||
if(This->render.width < This->width)
|
||||
{
|
||||
This->render.width = This->width;
|
||||
}
|
||||
if(This->render.height < This->height)
|
||||
{
|
||||
This->render.height = This->height;
|
||||
}
|
||||
|
||||
This->render.run = TRUE;
|
||||
|
||||
if (This->renderer == render_dummy_main)
|
||||
{
|
||||
if(This->render.thread == NULL)
|
||||
{
|
||||
This->render.thread = CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)This->renderer, NULL, 0, NULL);
|
||||
SetThreadPriority(This->render.thread, THREAD_PRIORITY_BELOW_NORMAL);
|
||||
}
|
||||
return DD_OK;
|
||||
}
|
||||
|
||||
mouse_unlock();
|
||||
|
||||
const HANDLE hbicon = LoadImage(GetModuleHandle(0), MAKEINTRESOURCE(IDR_MYMENU), IMAGE_ICON, GetSystemMetrics(SM_CXICON), GetSystemMetrics(SM_CYICON), 0);
|
||||
if (hbicon)
|
||||
SendMessage(This->hWnd, WM_SETICON, ICON_BIG, (LPARAM)hbicon);
|
||||
|
||||
const HANDLE hsicon = LoadImage(GetModuleHandle(0), MAKEINTRESOURCE(IDR_MYMENU), IMAGE_ICON, GetSystemMetrics(SM_CXSMICON), GetSystemMetrics(SM_CYSMICON), 0);
|
||||
if (hsicon)
|
||||
SendMessage(This->hWnd, WM_SETICON, ICON_SMALL, (LPARAM)hsicon);
|
||||
|
||||
|
||||
memset(&This->render.mode, 0, sizeof(DEVMODE));
|
||||
This->render.mode.dmSize = sizeof(DEVMODE);
|
||||
This->render.mode.dmFields = DM_PELSWIDTH|DM_PELSHEIGHT;
|
||||
This->render.mode.dmPelsWidth = This->render.width;
|
||||
This->render.mode.dmPelsHeight = This->render.height;
|
||||
if(This->render.bpp)
|
||||
{
|
||||
This->render.mode.dmFields |= DM_BITSPERPEL;
|
||||
This->render.mode.dmBitsPerPel = This->render.bpp;
|
||||
}
|
||||
|
||||
if(This->windowed)
|
||||
{
|
||||
if(!This->windowed_init)
|
||||
{
|
||||
if (!This->border)
|
||||
{
|
||||
SetWindowLong(This->hWnd, GWL_STYLE, GetWindowLong(This->hWnd, GWL_STYLE) & ~(WS_CAPTION | WS_THICKFRAME | WS_MINIMIZE | WS_MAXIMIZE | WS_SYSMENU));
|
||||
}
|
||||
else
|
||||
{
|
||||
SetWindowLong(This->hWnd, GWL_STYLE, GetWindowLong(This->hWnd, GWL_STYLE) | WS_CAPTION | WS_BORDER | WS_SYSMENU | WS_MINIMIZEBOX | WS_MAXIMIZEBOX);
|
||||
}
|
||||
|
||||
/* center the window with correct dimensions */
|
||||
int x = (WindowPosX != -1) ? WindowPosX : (This->mode.dmPelsWidth / 2) - (This->render.width / 2);
|
||||
int y = (WindowPosY != -1) ? WindowPosY : (This->mode.dmPelsHeight / 2) - (This->render.height / 2);
|
||||
RECT dst = { x, y, This->render.width+x, This->render.height+y };
|
||||
AdjustWindowRect(&dst, GetWindowLong(This->hWnd, GWL_STYLE), FALSE);
|
||||
SetWindowPos(This->hWnd, HWND_NOTOPMOST, dst.left, dst.top, (dst.right - dst.left), (dst.bottom - dst.top), SWP_SHOWWINDOW);
|
||||
|
||||
This->windowed_init = TRUE;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
SetWindowPos(This->hWnd, HWND_TOPMOST, 0, 0, This->render.width, This->render.height, SWP_SHOWWINDOW);
|
||||
|
||||
mouse_lock();
|
||||
|
||||
if(!This->devmode && ChangeDisplaySettings(&This->render.mode, CDS_FULLSCREEN) != DISP_CHANGE_SUCCESSFUL)
|
||||
{
|
||||
This->render.run = FALSE;
|
||||
return DDERR_INVALIDMODE;
|
||||
}
|
||||
}
|
||||
|
||||
if(This->render.thread == NULL)
|
||||
{
|
||||
This->render.thread = CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)This->renderer, NULL, 0, NULL);
|
||||
SetThreadPriority(This->render.thread, THREAD_PRIORITY_BELOW_NORMAL);
|
||||
}
|
||||
|
||||
return DD_OK;
|
||||
}
|
||||
|
||||
/* minimal window proc for dummy renderer as everything is emulated */
|
||||
LRESULT CALLBACK dummy_WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
|
||||
{
|
||||
switch(uMsg)
|
||||
{
|
||||
/* if the plugin window changes */
|
||||
case WM_USER:
|
||||
ddraw->hWnd = (HWND)lParam;
|
||||
ddraw->render.hDC = GetDC(ddraw->hWnd);
|
||||
case WM_ACTIVATEAPP:
|
||||
if (wParam == TRUE)
|
||||
{
|
||||
break;
|
||||
}
|
||||
case WM_SIZE:
|
||||
case WM_NCACTIVATE:
|
||||
return DefWindowProc(hWnd, uMsg, wParam, lParam);
|
||||
case WM_MOUSEMOVE:
|
||||
case WM_NCMOUSEMOVE:
|
||||
ddraw->cursor.x = GET_X_LPARAM(lParam);
|
||||
ddraw->cursor.y = GET_Y_LPARAM(lParam);
|
||||
break;
|
||||
}
|
||||
|
||||
if (ddraw->WndProc)
|
||||
{
|
||||
return ddraw->WndProc(hWnd, uMsg, wParam, lParam);
|
||||
}
|
||||
|
||||
return DefWindowProc(hWnd, uMsg, wParam, lParam);
|
||||
}
|
||||
|
||||
void ToggleFullscreen()
|
||||
{
|
||||
if (ddraw->windowed)
|
||||
{
|
||||
if(ChangeDisplaySettings(&ddraw->render.mode, CDS_FULLSCREEN) == DISP_CHANGE_SUCCESSFUL)
|
||||
{
|
||||
ddraw->windowed = FALSE;
|
||||
|
||||
SetWindowLong(ddraw->hWnd, GWL_STYLE, GetWindowLong(ddraw->hWnd, GWL_STYLE) & ~(WS_CAPTION | WS_THICKFRAME | WS_MINIMIZE | WS_MAXIMIZE | WS_SYSMENU));
|
||||
SetWindowPos(ddraw->hWnd, HWND_TOPMOST, 0, 0, ddraw->render.width, ddraw->render.height, SWP_SHOWWINDOW);
|
||||
if (ddraw->locked)
|
||||
{
|
||||
mouse_unlock();
|
||||
mouse_lock();
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if(ChangeDisplaySettings(&ddraw->mode, 0) == DISP_CHANGE_SUCCESSFUL)
|
||||
{
|
||||
if (!ddraw->border)
|
||||
{
|
||||
SetWindowLong(ddraw->hWnd, GWL_STYLE, GetWindowLong(ddraw->hWnd, GWL_STYLE) & ~(WS_CAPTION | WS_THICKFRAME | WS_MINIMIZE | WS_MAXIMIZE | WS_SYSMENU));
|
||||
}
|
||||
else
|
||||
{
|
||||
SetWindowLong(ddraw->hWnd, GWL_STYLE, GetWindowLong(ddraw->hWnd, GWL_STYLE) | WS_CAPTION | WS_BORDER | WS_SYSMENU | WS_MINIMIZEBOX | WS_MAXIMIZEBOX);
|
||||
}
|
||||
|
||||
int x = (WindowPosX != -1) ? WindowPosX : (ddraw->mode.dmPelsWidth / 2) - (ddraw->render.width / 2);
|
||||
int y = (WindowPosY != -1) ? WindowPosY : (ddraw->mode.dmPelsHeight / 2) - (ddraw->render.height / 2);
|
||||
RECT dst = { x, y, ddraw->render.width+x, ddraw->render.height+y };
|
||||
AdjustWindowRect(&dst, GetWindowLong(ddraw->hWnd, GWL_STYLE), FALSE);
|
||||
SetWindowPos(ddraw->hWnd, HWND_NOTOPMOST, dst.left, dst.top, (dst.right - dst.left), (dst.bottom - dst.top), SWP_SHOWWINDOW);
|
||||
|
||||
if (ddraw->locked)
|
||||
{
|
||||
mouse_unlock();
|
||||
mouse_lock();
|
||||
}
|
||||
|
||||
ddraw->windowed = TRUE;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
LRESULT CALLBACK WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
|
||||
{
|
||||
RECT rc = { 0, 0, ddraw->render.width, ddraw->render.height };
|
||||
|
||||
switch(uMsg)
|
||||
{
|
||||
case WM_MOVE:
|
||||
{
|
||||
if (ddraw->windowed)
|
||||
{
|
||||
int x = (int)(short)LOWORD(lParam);
|
||||
int y = (int)(short)HIWORD(lParam);
|
||||
|
||||
if (x != -32000)
|
||||
WindowPosX = x; // -32000 = Exit/Minimize
|
||||
|
||||
if (y != -32000)
|
||||
WindowPosY = y;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
/* Carmageddon stops the main loop when it sees these, DefWindowProc is also bad */
|
||||
//case WM_WINDOWPOSCHANGING:
|
||||
//case WM_WINDOWPOSCHANGED:
|
||||
// return 0;
|
||||
|
||||
/* C&C and RA really don't want to close down */
|
||||
case WM_SYSCOMMAND:
|
||||
if (wParam == SC_CLOSE)
|
||||
{
|
||||
exit(0);
|
||||
}
|
||||
if (wParam == SC_MAXIMIZE)
|
||||
{
|
||||
ToggleFullscreen();
|
||||
return 0;
|
||||
}
|
||||
|
||||
return DefWindowProc(hWnd, uMsg, wParam, lParam);
|
||||
|
||||
case WM_ACTIVATE:
|
||||
if (wParam == WA_ACTIVE || wParam == WA_CLICKACTIVE)
|
||||
{
|
||||
if (wParam == WA_ACTIVE)
|
||||
{
|
||||
mouse_lock();
|
||||
}
|
||||
if (!ddraw->windowed)
|
||||
{
|
||||
ChangeDisplaySettings(&ddraw->render.mode, CDS_FULLSCREEN);
|
||||
}
|
||||
}
|
||||
else if (wParam == WA_INACTIVE)
|
||||
{
|
||||
mouse_unlock();
|
||||
|
||||
/* minimize our window on defocus when in fullscreen */
|
||||
if (!ddraw->windowed)
|
||||
{
|
||||
ChangeDisplaySettings(&ddraw->mode, 0);
|
||||
ShowWindow(ddraw->hWnd, SW_MINIMIZE);
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
|
||||
case WM_MOUSELEAVE:
|
||||
mouse_unlock();
|
||||
return 0;
|
||||
|
||||
case WM_ACTIVATEAPP:
|
||||
/* C&C and RA stop drawing when they receive this with FALSE wParam, disable in windowed mode */
|
||||
if (ddraw->windowed)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
break;
|
||||
case WM_NCLBUTTONDBLCLK:
|
||||
{
|
||||
ToggleFullscreen();
|
||||
return 0;
|
||||
}
|
||||
case WM_SYSKEYDOWN:
|
||||
{
|
||||
if (wParam == VK_RETURN)
|
||||
{
|
||||
ToggleFullscreen();
|
||||
return 0;
|
||||
}
|
||||
break;
|
||||
}
|
||||
case WM_KEYDOWN:
|
||||
if(wParam == VK_CONTROL || wParam == VK_TAB)
|
||||
{
|
||||
if(GetAsyncKeyState(VK_CONTROL) & 0x8000 && GetAsyncKeyState(VK_TAB) & 0x8000)
|
||||
{
|
||||
mouse_unlock();
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
#ifdef HAVE_LIBPNG
|
||||
if(wParam == VK_CONTROL || wParam == ddraw->screenshotKey)
|
||||
{
|
||||
if(GetAsyncKeyState(VK_CONTROL) & 0x8000 && GetAsyncKeyState(ddraw->screenshotKey) & 0x8000)
|
||||
{
|
||||
screenshot(ddraw->primary);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
break;
|
||||
|
||||
/* button up messages reactivate cursor lock */
|
||||
case WM_LBUTTONUP:
|
||||
case WM_RBUTTONUP:
|
||||
case WM_MBUTTONUP:
|
||||
if (ddraw->mhack && !ddraw->locked)
|
||||
{
|
||||
ddraw->cursor.x = LOWORD(lParam) * ((float)ddraw->width / ddraw->render.width);
|
||||
ddraw->cursor.y = HIWORD(lParam) * ((float)ddraw->height / ddraw->render.height);
|
||||
mouse_lock();
|
||||
return 0;
|
||||
}
|
||||
/* fall through for lParam */
|
||||
|
||||
/* down messages are ignored if we have no cursor lock */
|
||||
case WM_LBUTTONDOWN:
|
||||
case WM_RBUTTONDOWN:
|
||||
case WM_MBUTTONDOWN:
|
||||
case WM_MOUSEMOVE:
|
||||
if (ddraw->mhack)
|
||||
{
|
||||
if (!ddraw->locked)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
fake_GetCursorPos(NULL); /* update our own cursor */
|
||||
lParam = MAKELPARAM(ddraw->cursor.x, ddraw->cursor.y);
|
||||
}
|
||||
|
||||
if (ddraw->devmode)
|
||||
{
|
||||
mouse_lock();
|
||||
ddraw->cursor.x = GET_X_LPARAM(lParam);
|
||||
ddraw->cursor.y = GET_Y_LPARAM(lParam);
|
||||
}
|
||||
break;
|
||||
|
||||
/* make sure we redraw when WM_PAINT is requested */
|
||||
case WM_PAINT:
|
||||
EnterCriticalSection(&ddraw->cs);
|
||||
ReleaseSemaphore(ddraw->render.sem, 1, NULL);
|
||||
LeaveCriticalSection(&ddraw->cs);
|
||||
break;
|
||||
|
||||
case WM_ERASEBKGND:
|
||||
EnterCriticalSection(&ddraw->cs);
|
||||
FillRect(ddraw->render.hDC, &rc, (HBRUSH) GetStockObject(BLACK_BRUSH));
|
||||
ReleaseSemaphore(ddraw->render.sem, 1, NULL);
|
||||
LeaveCriticalSection(&ddraw->cs);
|
||||
break;
|
||||
}
|
||||
|
||||
return ddraw->WndProc(hWnd, uMsg, wParam, lParam);
|
||||
}
|
||||
|
||||
HRESULT __stdcall ddraw_SetCooperativeLevel(IDirectDrawImpl *This, HWND hWnd, DWORD dwFlags)
|
||||
{
|
||||
PIXELFORMATDESCRIPTOR pfd;
|
||||
|
||||
printf("DirectDraw::SetCooperativeLevel(This=%p, hWnd=0x%08X, dwFlags=0x%08X)\n", This, (unsigned int)hWnd, (unsigned int)dwFlags);
|
||||
|
||||
/* Red Alert for some weird reason does this on Windows XP */
|
||||
if(hWnd == NULL)
|
||||
{
|
||||
return DDERR_INVALIDPARAMS;
|
||||
}
|
||||
|
||||
if (This->hWnd == NULL)
|
||||
{
|
||||
This->hWnd = hWnd;
|
||||
}
|
||||
|
||||
mouse_init(hWnd);
|
||||
|
||||
This->WndProc = (LRESULT CALLBACK (*)(HWND, UINT, WPARAM, LPARAM))GetWindowLong(hWnd, GWL_WNDPROC);
|
||||
|
||||
if (This->renderer == render_dummy_main)
|
||||
{
|
||||
This->render.hDC = GetDC(This->hWnd);
|
||||
SetWindowLong(hWnd, GWL_WNDPROC, (LONG)dummy_WndProc);
|
||||
ShowWindow(hWnd, SW_HIDE);
|
||||
PostMessage(hWnd, WM_ACTIVATEAPP, TRUE, TRUE);
|
||||
PostMessage(This->hWnd, WM_USER, 0, (LPARAM)hWnd);
|
||||
return DD_OK;
|
||||
}
|
||||
|
||||
SetWindowLong(This->hWnd, GWL_WNDPROC, (LONG)WndProc);
|
||||
|
||||
if(!This->render.hDC)
|
||||
{
|
||||
This->render.hDC = GetDC(This->hWnd);
|
||||
|
||||
memset(&pfd, 0, sizeof(PIXELFORMATDESCRIPTOR));
|
||||
pfd.nSize = sizeof(PIXELFORMATDESCRIPTOR);
|
||||
pfd.nVersion = 1;
|
||||
pfd.dwFlags = PFD_DRAW_TO_WINDOW | PFD_DOUBLEBUFFER | (This->renderer == render_main ? PFD_SUPPORT_OPENGL : 0);
|
||||
pfd.iPixelType = PFD_TYPE_RGBA;
|
||||
pfd.cColorBits = ddraw->render.bpp ? ddraw->render.bpp : ddraw->mode.dmBitsPerPel;
|
||||
pfd.iLayerType = PFD_MAIN_PLANE;
|
||||
SetPixelFormat( This->render.hDC, ChoosePixelFormat( This->render.hDC, &pfd ), &pfd );
|
||||
}
|
||||
|
||||
SetCursor(LoadCursor(NULL, IDC_ARROW));
|
||||
|
||||
GetWindowText(This->hWnd, (LPTSTR)&This->title, sizeof(This->title));
|
||||
|
||||
if (!strcmp(This->title, "Red Alert"))
|
||||
{
|
||||
ddraw->isredalert = 1;
|
||||
}
|
||||
|
||||
return DD_OK;
|
||||
}
|
||||
|
||||
HRESULT __stdcall ddraw_WaitForVerticalBlank(IDirectDrawImpl *This, DWORD a, HANDLE b)
|
||||
{
|
||||
#if _DEBUG
|
||||
printf("DirectDraw::WaitForVerticalBlank(This=%p, ...)\n", This);
|
||||
#endif
|
||||
return DD_OK;
|
||||
}
|
||||
|
||||
HRESULT __stdcall ddraw_QueryInterface(IDirectDrawImpl *This, REFIID riid, void **obj)
|
||||
{
|
||||
printf("DirectDraw::QueryInterface(This=%p, riid=%08X, obj=%p)\n", This, (unsigned int)riid, obj);
|
||||
|
||||
*obj = This;
|
||||
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
ULONG __stdcall ddraw_AddRef(IDirectDrawImpl *This)
|
||||
{
|
||||
printf("DirectDraw::AddRef(This=%p)\n", This);
|
||||
|
||||
This->Ref++;
|
||||
|
||||
return This->Ref;
|
||||
}
|
||||
|
||||
ULONG __stdcall ddraw_Release(IDirectDrawImpl *This)
|
||||
{
|
||||
printf("DirectDraw::Release(This=%p)\n", This);
|
||||
|
||||
This->Ref--;
|
||||
|
||||
if(This->Ref == 0)
|
||||
{
|
||||
if (This->hWnd && This->renderer == render_dummy_main)
|
||||
{
|
||||
PostMessage(This->hWnd, WM_USER, 0, 0);
|
||||
}
|
||||
|
||||
if (This->render.thread)
|
||||
{
|
||||
EnterCriticalSection(&This->cs);
|
||||
HANDLE thread = This->render.thread;
|
||||
This->render.thread = NULL;
|
||||
ReleaseSemaphore(This->render.sem, 1, NULL);
|
||||
LeaveCriticalSection(&This->cs);
|
||||
|
||||
WaitForSingleObject(thread, INFINITE);
|
||||
}
|
||||
|
||||
if(This->render.hDC)
|
||||
{
|
||||
ReleaseDC(This->hWnd, This->render.hDC);
|
||||
This->render.hDC = NULL;
|
||||
}
|
||||
|
||||
if(This->real_dll)
|
||||
{
|
||||
FreeLibrary(This->real_dll);
|
||||
}
|
||||
|
||||
DeleteCriticalSection(&This->cs);
|
||||
|
||||
/* restore old wndproc, subsequent ddraw creation will otherwise fail */
|
||||
SetWindowLong(This->hWnd, GWL_WNDPROC, (LONG)This->WndProc);
|
||||
HeapFree(GetProcessHeap(), 0, This);
|
||||
ddraw = NULL;
|
||||
return 0;
|
||||
}
|
||||
|
||||
return This->Ref;
|
||||
}
|
||||
|
||||
struct IDirectDrawImplVtbl iface =
|
||||
{
|
||||
/* IUnknown */
|
||||
ddraw_QueryInterface,
|
||||
ddraw_AddRef,
|
||||
ddraw_Release,
|
||||
/* IDirectDrawImpl */
|
||||
ddraw_Compact,
|
||||
ddraw_CreateClipper,
|
||||
ddraw_CreatePalette,
|
||||
ddraw_CreateSurface,
|
||||
ddraw_DuplicateSurface,
|
||||
ddraw_EnumDisplayModes,
|
||||
ddraw_EnumSurfaces,
|
||||
ddraw_FlipToGDISurface,
|
||||
ddraw_GetCaps,
|
||||
ddraw_GetDisplayMode,
|
||||
ddraw_GetFourCCCodes,
|
||||
ddraw_GetGDISurface,
|
||||
ddraw_GetMonitorFrequency,
|
||||
ddraw_GetScanLine,
|
||||
ddraw_GetVerticalBlankStatus,
|
||||
ddraw_Initialize,
|
||||
ddraw_RestoreDisplayMode,
|
||||
ddraw_SetCooperativeLevel,
|
||||
ddraw_SetDisplayMode,
|
||||
ddraw_WaitForVerticalBlank
|
||||
};
|
||||
|
||||
HRESULT WINAPI DirectDrawEnumerateA(LPDDENUMCALLBACK lpCallback, LPVOID lpContext)
|
||||
{
|
||||
return DD_OK;
|
||||
}
|
||||
|
||||
int stdout_open = 0;
|
||||
HRESULT WINAPI DirectDrawCreate(GUID FAR* lpGUID, LPDIRECTDRAW FAR* lplpDD, IUnknown FAR* pUnkOuter)
|
||||
{
|
||||
#if _DEBUG
|
||||
if(!stdout_open)
|
||||
{
|
||||
freopen("stdout.txt", "w", stdout);
|
||||
setvbuf(stdout, NULL, _IONBF, 0);
|
||||
stdout_open = 1;
|
||||
}
|
||||
#endif
|
||||
|
||||
printf("DirectDrawCreate(lpGUID=%p, lplpDD=%p, pUnkOuter=%p)\n", lpGUID, lplpDD, pUnkOuter);
|
||||
|
||||
if(ddraw)
|
||||
{
|
||||
/* FIXME: check the calling module before passing the call! */
|
||||
return ddraw->DirectDrawCreate(lpGUID, lplpDD, pUnkOuter);
|
||||
|
||||
/*
|
||||
printf(" returning DDERR_DIRECTDRAWALREADYCREATED\n");
|
||||
return DDERR_DIRECTDRAWALREADYCREATED;
|
||||
*/
|
||||
}
|
||||
|
||||
IDirectDrawImpl *This = (IDirectDrawImpl *)HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(IDirectDrawImpl));
|
||||
This->lpVtbl = &iface;
|
||||
printf(" This = %p\n", This);
|
||||
*lplpDD = (LPDIRECTDRAW)This;
|
||||
This->Ref = 0;
|
||||
ddraw_AddRef(This);
|
||||
|
||||
ddraw = This;
|
||||
|
||||
This->real_dll = LoadLibrary("system32\\ddraw.dll");
|
||||
if(!This->real_dll)
|
||||
{
|
||||
ddraw_Release(This);
|
||||
return DDERR_GENERIC;
|
||||
}
|
||||
|
||||
This->DirectDrawCreate = (HRESULT WINAPI (*)(GUID FAR*, LPDIRECTDRAW FAR*, IUnknown FAR*))GetProcAddress(This->real_dll, "DirectDrawCreate");
|
||||
|
||||
if(!This->DirectDrawCreate)
|
||||
{
|
||||
ddraw_Release(This);
|
||||
return DDERR_GENERIC;
|
||||
}
|
||||
|
||||
InitializeCriticalSection(&This->cs);
|
||||
This->render.sem = CreateSemaphore(NULL, 0, 1, NULL);
|
||||
|
||||
/* load configuration options from ddraw.ini */
|
||||
char cwd[MAX_PATH];
|
||||
char tmp[256];
|
||||
GetCurrentDirectoryA(sizeof(cwd), cwd);
|
||||
snprintf(SettingsIniPath, sizeof(SettingsIniPath), "%s\\ddraw.ini", cwd);
|
||||
|
||||
if(GetFileAttributes(SettingsIniPath) == 0xFFFFFFFF)
|
||||
{
|
||||
FILE *fh = fopen(SettingsIniPath, "w");
|
||||
fputs(
|
||||
"[ddraw]\n"
|
||||
"; width and height of the window, defaults to the size game requests\r\n"
|
||||
"width=0\n"
|
||||
"height=0\n"
|
||||
"; bits per pixel, possible values: 16, 24 and 32, 0 = auto\n"
|
||||
"bpp=0\n"
|
||||
"windowed=true\n"
|
||||
"; show window borders in windowed mode\n"
|
||||
"border=true\n"
|
||||
"; use letter- or windowboxing to make a best fit (GDI only!)\n"
|
||||
"boxing=false\n"
|
||||
"; real rendering rate, -1 = screen rate, 0 = unlimited, n = cap\n"
|
||||
"max_fps=120\n"
|
||||
"; vertical synchronization, enable if you get tearing (OpenGL only)\n"
|
||||
"vsync=false\n"
|
||||
"; scaling filter, nearest = sharp, linear = smooth (OpenGL only)\n"
|
||||
"filter=nearest\n"
|
||||
"; automatic mouse sensitivity scaling\n"
|
||||
"adjmouse=false\n"
|
||||
"; manual sensitivity scaling, 0 = disabled, 0.5 = half, 1.0 = normal\n"
|
||||
"sensitivity=0.0\n"
|
||||
"; enable C&C/RA mouse hack\n"
|
||||
"mhack=true\n"
|
||||
"; enable C&C video resize hack, auto = auto-detect game, true = forced, false = disabled (OpenGL only)\n"
|
||||
"vhack=false\n"
|
||||
"; switch between OpenGL (opengl) and software (gdi) renderers, latter supports less features but might be faster depending on the GPU\n"
|
||||
"renderer=gdi\n"
|
||||
"; force CPU0 affinity, avoids crashes with RA, *might* have a performance impact\n"
|
||||
"singlecpu=true\n"
|
||||
"; Window position, -1 = center to screen\n"
|
||||
"posX=-1\n"
|
||||
"posY=-1\n"
|
||||
"; Screenshot Hotkey, default = CTRL + G\n"
|
||||
"screenshotKey=G\n"
|
||||
, fh);
|
||||
fclose(fh);
|
||||
}
|
||||
|
||||
GetPrivateProfileStringA("ddraw", "windowed", "TRUE", tmp, sizeof(tmp), SettingsIniPath);
|
||||
if (tolower(tmp[0]) == 'n' || tolower(tmp[0]) == 'f' || tolower(tmp[0]) == 'd' || tmp[0] == '0')
|
||||
{
|
||||
This->windowed = FALSE;
|
||||
}
|
||||
else
|
||||
{
|
||||
This->windowed = TRUE;
|
||||
}
|
||||
|
||||
GetPrivateProfileStringA("ddraw", "border", "TRUE", tmp, sizeof(tmp), SettingsIniPath);
|
||||
if (tolower(tmp[0]) == 'n' || tolower(tmp[0]) == 'f' || tolower(tmp[0]) == 'd' || tmp[0] == '0')
|
||||
{
|
||||
This->border = FALSE;
|
||||
}
|
||||
else
|
||||
{
|
||||
This->border = TRUE;
|
||||
}
|
||||
|
||||
GetPrivateProfileStringA("ddraw", "boxing", "FALSE", tmp, sizeof(tmp), SettingsIniPath);
|
||||
if (tolower(tmp[0]) == 'n' || tolower(tmp[0]) == 'f' || tolower(tmp[0]) == 'd' || tmp[0] == '0')
|
||||
{
|
||||
This->boxing = FALSE;
|
||||
}
|
||||
else
|
||||
{
|
||||
This->boxing = TRUE;
|
||||
}
|
||||
|
||||
GetPrivateProfileStringA("ddraw", "screenshotKey", "G", tmp, sizeof(tmp), SettingsIniPath);
|
||||
ddraw->screenshotKey = toupper(tmp[0]);
|
||||
|
||||
This->render.maxfps = GetPrivateProfileIntA("ddraw", "max_fps", 120, SettingsIniPath);
|
||||
This->render.width = GetPrivateProfileIntA("ddraw", "width", 0, SettingsIniPath);
|
||||
This->render.height = GetPrivateProfileIntA("ddraw", "height", 0, SettingsIniPath);
|
||||
WindowPosX = GetPrivateProfileIntA("ddraw", "posX", -1, SettingsIniPath);
|
||||
WindowPosY = GetPrivateProfileIntA("ddraw", "posY", -1, SettingsIniPath);
|
||||
|
||||
This->render.bpp = GetPrivateProfileIntA("ddraw", "bpp", 32, SettingsIniPath);
|
||||
if (This->render.bpp != 16 && This->render.bpp != 24 && This->render.bpp != 32)
|
||||
{
|
||||
This->render.bpp = 0;
|
||||
}
|
||||
|
||||
GetPrivateProfileStringA("ddraw", "filter", tmp, tmp, sizeof(tmp), SettingsIniPath);
|
||||
if (tolower(tmp[0]) == 'l' || tolower(tmp[3]) == 'l')
|
||||
{
|
||||
This->render.filter = 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
This->render.filter = 0;
|
||||
}
|
||||
|
||||
GetPrivateProfileStringA("ddraw", "adjmouse", "FALSE", tmp, sizeof(tmp), SettingsIniPath);
|
||||
if (tolower(tmp[0]) == 'y' || tolower(tmp[0]) == 't' || tolower(tmp[0]) == 'e' || tmp[0] == '1')
|
||||
{
|
||||
This->adjmouse = TRUE;
|
||||
}
|
||||
else
|
||||
{
|
||||
This->adjmouse = FALSE;
|
||||
}
|
||||
|
||||
GetPrivateProfileStringA("ddraw", "mhack", "TRUE", tmp, sizeof(tmp), SettingsIniPath);
|
||||
if (tolower(tmp[0]) == 'y' || tolower(tmp[0]) == 't' || tolower(tmp[0]) == 'e' || tmp[0] == '1')
|
||||
{
|
||||
This->mhack = TRUE;
|
||||
}
|
||||
else
|
||||
{
|
||||
This->mhack = FALSE;
|
||||
}
|
||||
|
||||
GetPrivateProfileStringA("ddraw", "devmode", "FALSE", tmp, sizeof(tmp), SettingsIniPath);
|
||||
if (tolower(tmp[0]) == 'y' || tolower(tmp[0]) == 't' || tolower(tmp[0]) == 'e' || tmp[0] == '1')
|
||||
{
|
||||
This->devmode = TRUE;
|
||||
This->mhack = FALSE;
|
||||
}
|
||||
else
|
||||
{
|
||||
This->devmode = FALSE;
|
||||
}
|
||||
|
||||
GetPrivateProfileStringA("ddraw", "vsync", "FALSE", tmp, sizeof(tmp), SettingsIniPath);
|
||||
if (tolower(tmp[0]) == 'y' || tolower(tmp[0]) == 't' || tolower(tmp[0]) == 'e' || tmp[0] == '1')
|
||||
{
|
||||
This->vsync = TRUE;
|
||||
}
|
||||
else
|
||||
{
|
||||
This->vsync = FALSE;
|
||||
}
|
||||
|
||||
GetPrivateProfileStringA("ddraw", "sensitivity", "0", tmp, sizeof(tmp), SettingsIniPath);
|
||||
This->sensitivity = strtof(tmp, NULL);
|
||||
|
||||
GetPrivateProfileStringA("ddraw", "vhack", "false", tmp, sizeof(tmp), SettingsIniPath);
|
||||
if (tolower(tmp[0]) == 'y' || tolower(tmp[0]) == 't' || tolower(tmp[0]) == 'e' || tmp[0] == '1')
|
||||
{
|
||||
This->vhack = 2;
|
||||
}
|
||||
else if(tolower(tmp[0]) == 'a')
|
||||
{
|
||||
This->vhack = 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
This->vhack = 0;
|
||||
}
|
||||
|
||||
GetPrivateProfileStringA("ddraw", "renderer", "gdi", tmp, sizeof(tmp), SettingsIniPath);
|
||||
if(tolower(tmp[0]) == 'd' || tolower(tmp[0]) == 'd')
|
||||
{
|
||||
printf("DirectDrawCreate: Using dummy renderer\n");
|
||||
This->renderer = render_dummy_main;
|
||||
}
|
||||
else if(tolower(tmp[0]) == 's' || tolower(tmp[0]) == 'g')
|
||||
{
|
||||
printf("DirectDrawCreate: Using software renderer\n");
|
||||
This->renderer = render_soft_main;
|
||||
}
|
||||
else
|
||||
{
|
||||
printf("DirectDrawCreate: Using OpenGL renderer\n");
|
||||
This->renderer = render_main;
|
||||
}
|
||||
|
||||
GetPrivateProfileStringA("ddraw", "singlecpu", "true", tmp, sizeof(tmp), SettingsIniPath);
|
||||
if (tolower(tmp[0]) == 'y' || tolower(tmp[0]) == 't' || tolower(tmp[0]) == 'e' || tmp[0] == '1')
|
||||
{
|
||||
printf("DirectDrawCreate: Setting CPU0 affinity\n");
|
||||
SetProcessAffinityMask(GetCurrentProcess(), 1);
|
||||
}
|
||||
|
||||
/* last minute check for cnc-plugin */
|
||||
if (GetEnvironmentVariable("DDRAW_WINDOW", tmp, sizeof(tmp)) > 0)
|
||||
{
|
||||
This->hWnd = (HWND)atoi(tmp);
|
||||
This->renderer = render_dummy_main;
|
||||
This->windowed = TRUE;
|
||||
|
||||
if (GetEnvironmentVariable("DDRAW_WIDTH", tmp, sizeof(tmp)) > 0)
|
||||
{
|
||||
This->render.width = atoi(tmp);
|
||||
}
|
||||
|
||||
if (GetEnvironmentVariable("DDRAW_HEIGHT", tmp, sizeof(tmp)) > 0)
|
||||
{
|
||||
This->render.height = atoi(tmp);
|
||||
}
|
||||
|
||||
printf("DirectDrawCreate: Detected cnc-plugin at window %08X in %dx%d\n", (unsigned int)This->hWnd, This->render.width, This->render.height);
|
||||
}
|
||||
|
||||
|
||||
return DD_OK;
|
||||
}
|
256
src/mouse.c
Normal file
256
src/mouse.c
Normal file
|
@ -0,0 +1,256 @@
|
|||
/*
|
||||
* Copyright (c) 2010 Toni Spets <toni.spets@iki.fi>
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
/* This is a special mouse coordinate fix for games that use GetCursorPos and expect to be in fullscreen */
|
||||
|
||||
#include <windows.h>
|
||||
#include <stdio.h>
|
||||
#include "main.h"
|
||||
#include "surface.h"
|
||||
|
||||
#define MAX_HOOKS 16
|
||||
|
||||
BOOL mouse_active = FALSE;
|
||||
int real_height = 0;
|
||||
|
||||
struct hook { char name[32]; void *func; };
|
||||
struct hack
|
||||
{
|
||||
char name[32];
|
||||
struct hook hooks[MAX_HOOKS];
|
||||
};
|
||||
|
||||
BOOL WINAPI fake_GetCursorPos(LPPOINT lpPoint)
|
||||
{
|
||||
POINT pt;
|
||||
|
||||
if(mouse_active && ddraw->locked)
|
||||
{
|
||||
GetCursorPos(&pt);
|
||||
|
||||
if(ddraw->sensitivity > 0 && ddraw->sensitivity < 10)
|
||||
{
|
||||
ddraw->cursor.x += (pt.x - ddraw->center.x) * ddraw->sensitivity;
|
||||
ddraw->cursor.y += (pt.y - ddraw->center.y) * ddraw->sensitivity;
|
||||
}
|
||||
else if(ddraw->adjmouse)
|
||||
{
|
||||
ddraw->cursor.x += (pt.x - ddraw->center.x) * ((float)ddraw->width / ddraw->render.width);
|
||||
ddraw->cursor.y += (pt.y - ddraw->center.y) * ((float)ddraw->height / ddraw->render.height);
|
||||
}
|
||||
else
|
||||
{
|
||||
ddraw->cursor.x += pt.x - ddraw->center.x;
|
||||
ddraw->cursor.y += pt.y - ddraw->center.y;
|
||||
}
|
||||
|
||||
if(ddraw->cursor.x < 0) ddraw->cursor.x = 0;
|
||||
if(ddraw->cursor.y < 0) ddraw->cursor.y = 0;
|
||||
if(ddraw->cursor.x > ddraw->cursorclip.width-1) ddraw->cursor.x = ddraw->cursorclip.width-1;
|
||||
|
||||
if(real_height > 0 && real_height < ddraw->cursorclip.height)
|
||||
{
|
||||
if(ddraw->cursor.y > real_height-1) ddraw->cursor.y = real_height-1;
|
||||
}
|
||||
else
|
||||
{
|
||||
if(ddraw->cursor.y > ddraw->cursorclip.height-1) ddraw->cursor.y = ddraw->cursorclip.height-1;
|
||||
}
|
||||
|
||||
if(pt.x != ddraw->center.x || pt.y != ddraw->center.y)
|
||||
{
|
||||
SetCursorPos(ddraw->center.x, ddraw->center.y);
|
||||
}
|
||||
}
|
||||
|
||||
if (lpPoint)
|
||||
{
|
||||
lpPoint->x = (int)ddraw->cursor.x;
|
||||
lpPoint->y = (int)ddraw->cursor.y;
|
||||
}
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
BOOL WINAPI fake_ClipCursor(const RECT *lpRect)
|
||||
{
|
||||
if(lpRect)
|
||||
{
|
||||
/* hack for 640x480 mode */
|
||||
real_height = lpRect->bottom;
|
||||
}
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
int WINAPI fake_ShowCursor(BOOL bShow)
|
||||
{
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
HCURSOR WINAPI fake_SetCursor(HCURSOR hCursor)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
struct hack hacks[] =
|
||||
{
|
||||
{
|
||||
"user32.dll",
|
||||
{
|
||||
{ "GetCursorPos", fake_GetCursorPos },
|
||||
{ "ClipCursor", fake_ClipCursor },
|
||||
{ "ShowCursor", fake_ShowCursor },
|
||||
{ "SetCursor", fake_SetCursor } ,
|
||||
{ "", NULL }
|
||||
}
|
||||
},
|
||||
{
|
||||
"",
|
||||
{
|
||||
{ "", NULL }
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
void hack_iat(struct hack *hck)
|
||||
{
|
||||
int i;
|
||||
char buf[32];
|
||||
struct hook *hk;
|
||||
DWORD dwWritten;
|
||||
IMAGE_DOS_HEADER dos_hdr;
|
||||
IMAGE_NT_HEADERS nt_hdr;
|
||||
IMAGE_IMPORT_DESCRIPTOR *dir;
|
||||
IMAGE_THUNK_DATA thunk;
|
||||
PDWORD ptmp;
|
||||
|
||||
HMODULE base = GetModuleHandle(NULL);
|
||||
HANDLE hProcess = GetCurrentProcess();
|
||||
|
||||
ReadProcessMemory(hProcess, (void *)base, &dos_hdr, sizeof(IMAGE_DOS_HEADER), &dwWritten);
|
||||
ReadProcessMemory(hProcess, (void *)base+dos_hdr.e_lfanew, &nt_hdr, sizeof(IMAGE_NT_HEADERS), &dwWritten);
|
||||
dir = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, (nt_hdr.OptionalHeader.DataDirectory[1].Size));
|
||||
ReadProcessMemory(hProcess, (void *)base+nt_hdr.OptionalHeader.DataDirectory[1].VirtualAddress, dir, nt_hdr.OptionalHeader.DataDirectory[1].Size, &dwWritten);
|
||||
|
||||
while(dir->Name > 0)
|
||||
{
|
||||
memset(buf, 0, 32);
|
||||
ReadProcessMemory(hProcess, (void *)base+dir->Name, buf, 32, &dwWritten);
|
||||
if(stricmp(buf, hck->name) == 0)
|
||||
{
|
||||
ptmp = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(DWORD) * 64);
|
||||
ReadProcessMemory(hProcess, (void *)base+dir->Characteristics, ptmp, sizeof(DWORD) * 64, &dwWritten);
|
||||
i=0;
|
||||
while(*ptmp)
|
||||
{
|
||||
memset(buf, 0, 32);
|
||||
ReadProcessMemory(hProcess, (void *)base+(*ptmp)+2, buf, 32, &dwWritten);
|
||||
|
||||
hk = &hck->hooks[0];
|
||||
while(hk->func)
|
||||
{
|
||||
if(stricmp(hk->name, buf) == 0)
|
||||
{
|
||||
thunk.u1.Function = (DWORD)hk->func;
|
||||
thunk.u1.Ordinal = (DWORD)hk->func;
|
||||
thunk.u1.AddressOfData = (DWORD)hk->func;
|
||||
VirtualProtectEx(hProcess, (void *)base+dir->FirstThunk+(sizeof(IMAGE_THUNK_DATA) * i), sizeof(IMAGE_THUNK_DATA), PAGE_EXECUTE_READWRITE, &dwWritten);
|
||||
WriteProcessMemory(hProcess, (void *)base+dir->FirstThunk+(sizeof(IMAGE_THUNK_DATA) * i), &thunk, sizeof(IMAGE_THUNK_DATA), &dwWritten);
|
||||
mouse_active = TRUE;
|
||||
}
|
||||
hk++;
|
||||
}
|
||||
|
||||
ptmp++;
|
||||
i++;
|
||||
}
|
||||
}
|
||||
dir++;
|
||||
}
|
||||
|
||||
CloseHandle(hProcess);
|
||||
}
|
||||
|
||||
void mouse_lock()
|
||||
{
|
||||
RECT rc;
|
||||
|
||||
if (ddraw->devmode)
|
||||
{
|
||||
while(ShowCursor(FALSE) > 0);
|
||||
return;
|
||||
}
|
||||
|
||||
if (mouse_active && !ddraw->locked)
|
||||
{
|
||||
GetWindowRect(ddraw->hWnd, &rc);
|
||||
|
||||
ddraw->center.x = (rc.right + rc.left) / 2;
|
||||
ddraw->center.y = (rc.top + rc.bottom) / 2;
|
||||
|
||||
SetCursorPos(ddraw->center.x, ddraw->center.y);
|
||||
SetCapture(ddraw->hWnd);
|
||||
ClipCursor(&rc);
|
||||
|
||||
while(ShowCursor(FALSE) > 0);
|
||||
ddraw->locked = TRUE;
|
||||
}
|
||||
}
|
||||
|
||||
void mouse_unlock()
|
||||
{
|
||||
RECT rc;
|
||||
POINT pt;
|
||||
|
||||
if (ddraw->devmode)
|
||||
{
|
||||
while(ShowCursor(TRUE) < 0);
|
||||
return;
|
||||
}
|
||||
|
||||
if(!mouse_active)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if(ddraw->locked)
|
||||
{
|
||||
ddraw->locked = FALSE;
|
||||
|
||||
GetWindowRect(ddraw->hWnd, &rc);
|
||||
|
||||
pt.x = (rc.right - rc.left - ddraw->render.width) / 2;
|
||||
pt.y = (rc.bottom - rc.top - ddraw->render.height - pt.x);
|
||||
rc.left += pt.x;
|
||||
rc.top += pt.y;
|
||||
|
||||
SetCursorPos(rc.left + (ddraw->cursor.x * ddraw->render.width / ddraw->width), rc.top + (ddraw->cursor.y * ddraw->render.height / ddraw->height));
|
||||
while(ShowCursor(TRUE) < 0);
|
||||
SetCursor(LoadCursor(NULL, IDC_ARROW));
|
||||
|
||||
ClipCursor(NULL);
|
||||
ReleaseCapture();
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
void mouse_init(HWND hWnd)
|
||||
{
|
||||
if(ddraw->mhack || ddraw->devmode)
|
||||
{
|
||||
hack_iat(&hacks[0]);
|
||||
mouse_active = TRUE;
|
||||
}
|
||||
}
|
141
src/palette.c
Normal file
141
src/palette.c
Normal file
|
@ -0,0 +1,141 @@
|
|||
/*
|
||||
* Copyright (c) 2010 Toni Spets <toni.spets@iki.fi>
|
||||
*
|
||||
* 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 <windows.h>
|
||||
#include <stdio.h>
|
||||
#include "palette.h"
|
||||
#include "surface.h"
|
||||
|
||||
HRESULT __stdcall ddraw_palette_GetEntries(IDirectDrawPaletteImpl *This, DWORD dwFlags, DWORD dwBase, DWORD dwNumEntries, LPPALETTEENTRY lpEntries)
|
||||
{
|
||||
int i;
|
||||
|
||||
printf("DirectDrawPalette::GetEntries(This=%p, dwFlags=%d, dwBase=%d, dwNumEntries=%d, lpEntries=%p)\n", This, (int)dwFlags, (int)dwBase, (int)dwNumEntries, lpEntries);
|
||||
|
||||
for(i=dwBase;i<dwBase+dwNumEntries;i++)
|
||||
{
|
||||
if (This->data_rgb)
|
||||
{
|
||||
lpEntries[i].peRed = This->data_rgb[i].rgbRed;
|
||||
lpEntries[i].peGreen = This->data_rgb[i].rgbGreen;
|
||||
lpEntries[i].peBlue = This->data_rgb[i].rgbBlue;
|
||||
}
|
||||
}
|
||||
|
||||
return DD_OK;
|
||||
}
|
||||
|
||||
HRESULT __stdcall ddraw_palette_SetEntries(IDirectDrawPaletteImpl *This, DWORD dwFlags, DWORD dwStartingEntry, DWORD dwCount, LPPALETTEENTRY lpEntries)
|
||||
{
|
||||
int i;
|
||||
|
||||
#if _DEBUG
|
||||
printf("DirectDrawPalette::SetEntries(This=%p, dwFlags=%d, dwStartingEntry=%d, dwCount=%d, lpEntries=%p)\n", This, (int)dwFlags, (int)dwStartingEntry, (int)dwCount, lpEntries);
|
||||
#endif
|
||||
|
||||
for(i=dwStartingEntry;i<dwStartingEntry+dwCount;i++)
|
||||
{
|
||||
This->data_bgr[i] = (lpEntries[i].peBlue<<16)|(lpEntries[i].peGreen<<8)|lpEntries[i].peRed;
|
||||
|
||||
if (This->data_rgb)
|
||||
{
|
||||
This->data_rgb[i].rgbRed = lpEntries[i].peRed;
|
||||
This->data_rgb[i].rgbGreen = lpEntries[i].peGreen;
|
||||
This->data_rgb[i].rgbBlue = lpEntries[i].peBlue;
|
||||
This->data_rgb[i].rgbReserved = 0;
|
||||
}
|
||||
}
|
||||
|
||||
/* FIXME: only refresh the screen when the primary palette is changed */
|
||||
if(ddraw->primary)
|
||||
{
|
||||
ReleaseSemaphore(ddraw->render.sem, 1, NULL);
|
||||
}
|
||||
|
||||
return DD_OK;
|
||||
}
|
||||
|
||||
HRESULT __stdcall ddraw_palette_QueryInterface(IDirectDrawPaletteImpl *This, REFIID riid, void **obj)
|
||||
{
|
||||
printf("DirectDrawPalette::QueryInterface(This=%p, riid=%08X, obj=%p)\n", This, (unsigned int)riid, obj);
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
ULONG __stdcall ddraw_palette_AddRef(IDirectDrawPaletteImpl *This)
|
||||
{
|
||||
printf("DirectDrawPalette::AddRef(This=%p)\n", This);
|
||||
|
||||
This->Ref++;
|
||||
|
||||
return This->Ref;
|
||||
}
|
||||
|
||||
ULONG __stdcall ddraw_palette_Release(IDirectDrawPaletteImpl *This)
|
||||
{
|
||||
printf("DirectDrawPalette::Release(This=%p)\n", This);
|
||||
|
||||
This->Ref--;
|
||||
|
||||
if(This->Ref == 0)
|
||||
{
|
||||
HeapFree(GetProcessHeap(), 0, This);
|
||||
return 0;
|
||||
}
|
||||
|
||||
return This->Ref;
|
||||
}
|
||||
|
||||
HRESULT __stdcall ddraw_palette_GetCaps(IDirectDrawPaletteImpl *This, LPDWORD caps)
|
||||
{
|
||||
printf("DirectDrawPalette::GetCaps(This=%p, caps=%p)\n", This, caps);
|
||||
return DD_OK;
|
||||
}
|
||||
|
||||
HRESULT __stdcall ddraw_palette_Initialize(IDirectDrawPaletteImpl *This, LPDIRECTDRAW lpDD, DWORD dw, LPPALETTEENTRY paent)
|
||||
{
|
||||
printf("DirectDrawPalette::Initialize(This=%p, ...)\n", This);
|
||||
return DD_OK;
|
||||
}
|
||||
|
||||
struct IDirectDrawPaletteImplVtbl piface =
|
||||
{
|
||||
/* IUnknown */
|
||||
ddraw_palette_QueryInterface,
|
||||
ddraw_palette_AddRef,
|
||||
ddraw_palette_Release,
|
||||
/* IDirectDrawPalette */
|
||||
ddraw_palette_GetCaps,
|
||||
ddraw_palette_GetEntries,
|
||||
ddraw_palette_Initialize,
|
||||
ddraw_palette_SetEntries
|
||||
};
|
||||
|
||||
HRESULT __stdcall ddraw_CreatePalette(IDirectDrawImpl *This, DWORD dwFlags, LPPALETTEENTRY lpDDColorArray, LPDIRECTDRAWPALETTE FAR * lpDDPalette, IUnknown FAR * unkOuter)
|
||||
{
|
||||
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(), HEAP_ZERO_MEMORY, sizeof(IDirectDrawPaletteImpl));
|
||||
Palette->lpVtbl = &piface;
|
||||
printf(" Palette = %p\n", Palette);
|
||||
*lpDDPalette = (LPDIRECTDRAWPALETTE)Palette;
|
||||
|
||||
ddraw_palette_SetEntries(Palette, dwFlags, 0, 256, lpDDColorArray);
|
||||
|
||||
ddraw_palette_AddRef(Palette);
|
||||
|
||||
return DD_OK;
|
||||
}
|
||||
|
171
src/render.c
Normal file
171
src/render.c
Normal file
|
@ -0,0 +1,171 @@
|
|||
/*
|
||||
* Copyright (c) 2010 Toni Spets <toni.spets@iki.fi>
|
||||
*
|
||||
* 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 <windows.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#include "main.h"
|
||||
#include "surface.h"
|
||||
|
||||
#define CUTSCENE_WIDTH 640
|
||||
#define CUTSCENE_HEIGHT 400
|
||||
|
||||
BOOL detect_cutscene();
|
||||
|
||||
DWORD WINAPI render_main(void)
|
||||
{
|
||||
Sleep(500);
|
||||
|
||||
int i,j;
|
||||
HGLRC hRC;
|
||||
|
||||
int tex_width = ddraw->width > 1024 ? ddraw->width : 1024;
|
||||
int tex_height = ddraw->height > 1024 ? ddraw->height : 1024;
|
||||
float scale_w = 1.0f;
|
||||
float scale_h = 1.0f;
|
||||
int *tex = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, tex_width * tex_height * sizeof(int));
|
||||
|
||||
hRC = wglCreateContext( ddraw->render.hDC );
|
||||
wglMakeCurrent( ddraw->render.hDC, hRC );
|
||||
|
||||
char *glext = (char *)glGetString(GL_EXTENSIONS);
|
||||
|
||||
if(glext && strstr(glext, "WGL_EXT_swap_control"))
|
||||
{
|
||||
BOOL (APIENTRY *wglSwapIntervalEXT)(int) = (BOOL (APIENTRY *)(int))wglGetProcAddress("wglSwapIntervalEXT");
|
||||
if(wglSwapIntervalEXT)
|
||||
{
|
||||
if(ddraw->vsync)
|
||||
{
|
||||
wglSwapIntervalEXT(1);
|
||||
}
|
||||
else
|
||||
{
|
||||
wglSwapIntervalEXT(0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
DWORD tick_start = 0;
|
||||
DWORD tick_end = 0;
|
||||
DWORD frame_len = 0;
|
||||
|
||||
if(ddraw->render.maxfps < 0)
|
||||
{
|
||||
ddraw->render.maxfps = ddraw->mode.dmDisplayFrequency;
|
||||
}
|
||||
|
||||
if(ddraw->render.maxfps > 0)
|
||||
{
|
||||
frame_len = 1000.0f / ddraw->render.maxfps;
|
||||
}
|
||||
|
||||
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, tex_width, tex_height, 0, GL_RGBA, GL_UNSIGNED_BYTE, tex);
|
||||
glViewport(0, 0, ddraw->render.width, ddraw->render.height);
|
||||
|
||||
if(ddraw->render.filter)
|
||||
{
|
||||
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR);
|
||||
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);
|
||||
}
|
||||
else
|
||||
{
|
||||
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_NEAREST);
|
||||
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_NEAREST);
|
||||
}
|
||||
|
||||
glEnable(GL_TEXTURE_2D);
|
||||
|
||||
|
||||
while(ddraw->render.thread && WaitForSingleObject(ddraw->render.sem, INFINITE) != WAIT_FAILED)
|
||||
{
|
||||
scale_w = (float)ddraw->width/tex_width;
|
||||
scale_h = (float)ddraw->height/tex_height;
|
||||
|
||||
if(ddraw->render.maxfps > 0)
|
||||
{
|
||||
tick_start = timeGetTime();
|
||||
}
|
||||
|
||||
/* convert ddraw surface to opengl texture */
|
||||
EnterCriticalSection(&ddraw->cs);
|
||||
|
||||
if(ddraw->primary && ddraw->primary->palette)
|
||||
{
|
||||
if(ddraw->vhack && detect_cutscene())
|
||||
{
|
||||
scale_w *= (float)CUTSCENE_WIDTH / ddraw->width;
|
||||
scale_h *= (float)CUTSCENE_HEIGHT / ddraw->height;
|
||||
|
||||
if (ddraw->cursorclip.width != CUTSCENE_WIDTH || ddraw->cursorclip.height != CUTSCENE_HEIGHT)
|
||||
{
|
||||
ddraw->cursorclip.width = CUTSCENE_WIDTH;
|
||||
ddraw->cursorclip.height = CUTSCENE_HEIGHT;
|
||||
ddraw->cursor.x = CUTSCENE_WIDTH / 2;
|
||||
ddraw->cursor.y = CUTSCENE_HEIGHT / 2;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (ddraw->cursorclip.width != ddraw->width || ddraw->cursorclip.height != ddraw->height)
|
||||
{
|
||||
ddraw->cursorclip.width = ddraw->width;
|
||||
ddraw->cursorclip.height = ddraw->height;
|
||||
ddraw->cursor.x = ddraw->width / 2;
|
||||
ddraw->cursor.y = ddraw->height / 2;
|
||||
}
|
||||
}
|
||||
|
||||
for(i=0; i<ddraw->height; i++)
|
||||
{
|
||||
for(j=0; j<ddraw->width; j++)
|
||||
{
|
||||
tex[i*ddraw->width+j] = ddraw->primary->palette->data_bgr[((unsigned char *)ddraw->primary->surface)[i*ddraw->primary->lPitch + j*ddraw->primary->lXPitch]];
|
||||
}
|
||||
}
|
||||
}
|
||||
LeaveCriticalSection(&ddraw->cs);
|
||||
|
||||
glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, ddraw->width, ddraw->height, GL_RGBA, GL_UNSIGNED_BYTE, tex);
|
||||
|
||||
glBegin(GL_TRIANGLE_FAN);
|
||||
glTexCoord2f(0,0); glVertex2f(-1, 1);
|
||||
glTexCoord2f(scale_w,0); glVertex2f( 1, 1);
|
||||
glTexCoord2f(scale_w,scale_h); glVertex2f( 1, -1);
|
||||
glTexCoord2f(0,scale_h); glVertex2f(-1, -1);
|
||||
glEnd();
|
||||
|
||||
SwapBuffers(ddraw->render.hDC);
|
||||
|
||||
if(ddraw->render.maxfps > 0)
|
||||
{
|
||||
tick_end = timeGetTime();
|
||||
|
||||
if(tick_end - tick_start < frame_len)
|
||||
{
|
||||
Sleep( frame_len - (tick_end - tick_start));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
HeapFree(GetProcessHeap(), 0, tex);
|
||||
|
||||
wglMakeCurrent(NULL, NULL);
|
||||
wglDeleteContext(hRC);
|
||||
|
||||
return 0;
|
||||
}
|
29
src/render_dummy.c
Normal file
29
src/render_dummy.c
Normal file
|
@ -0,0 +1,29 @@
|
|||
/*
|
||||
* Copyright (c) 2011 Toni Spets <toni.spets@iki.fi>
|
||||
*
|
||||
* 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 <windows.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#include "main.h"
|
||||
#include "surface.h"
|
||||
|
||||
DWORD WINAPI render_soft_main(void);
|
||||
|
||||
DWORD WINAPI render_dummy_main(void)
|
||||
{
|
||||
/* well, eh, duh */
|
||||
return render_soft_main();
|
||||
}
|
167
src/render_soft.c
Normal file
167
src/render_soft.c
Normal file
|
@ -0,0 +1,167 @@
|
|||
/*
|
||||
* Copyright (c) 2011 Toni Spets <toni.spets@iki.fi>
|
||||
*
|
||||
* 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 <windows.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#include "main.h"
|
||||
#include "surface.h"
|
||||
|
||||
#define CUTSCENE_WIDTH 640
|
||||
#define CUTSCENE_HEIGHT 400
|
||||
|
||||
static unsigned char getPixel(int x, int y)
|
||||
{
|
||||
return ((unsigned char *)ddraw->primary->surface)[y*ddraw->primary->lPitch + x*ddraw->primary->lXPitch];
|
||||
}
|
||||
|
||||
int* InMovie = (int*)0x00665F58;
|
||||
int* IsVQA640 = (int*)0x0065D7BC;
|
||||
BYTE* ShouldStretch = (BYTE*)0x00607D78;
|
||||
|
||||
BOOL detect_cutscene()
|
||||
{
|
||||
if(ddraw->width <= CUTSCENE_WIDTH || ddraw->height <= CUTSCENE_HEIGHT)
|
||||
return FALSE;
|
||||
|
||||
if (ddraw->isredalert == TRUE)
|
||||
{
|
||||
if ((*InMovie && !*IsVQA640) || *ShouldStretch)
|
||||
{
|
||||
return TRUE;
|
||||
}
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
return getPixel(CUTSCENE_WIDTH + 1, 0) == 0 || getPixel(CUTSCENE_WIDTH + 5, 1) == 0 ? TRUE : FALSE;
|
||||
}
|
||||
|
||||
DWORD WINAPI render_soft_main(void)
|
||||
{
|
||||
Sleep(500);
|
||||
|
||||
PBITMAPINFO bmi = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(BITMAPINFOHEADER) + sizeof(RGBQUAD) * 256);
|
||||
|
||||
bmi->bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
|
||||
bmi->bmiHeader.biWidth = ddraw->width;
|
||||
bmi->bmiHeader.biHeight = -ddraw->height;
|
||||
bmi->bmiHeader.biPlanes = 1;
|
||||
bmi->bmiHeader.biBitCount = ddraw->bpp;
|
||||
bmi->bmiHeader.biCompression = BI_RGB;
|
||||
|
||||
DWORD dst_top = 0;
|
||||
DWORD dst_left = 0;
|
||||
DWORD dst_width = ddraw->render.width;
|
||||
DWORD dst_height = ddraw->render.height;
|
||||
|
||||
DWORD tick_start = 0;
|
||||
DWORD tick_end = 0;
|
||||
DWORD frame_len = 0;
|
||||
|
||||
if (ddraw->boxing)
|
||||
{
|
||||
dst_width = ddraw->width;
|
||||
dst_height = ddraw->height;
|
||||
|
||||
/* test if we can double scale the window */
|
||||
if (ddraw->width * 2 <= ddraw->render.width && ddraw->height * 2 <= ddraw->render.height)
|
||||
{
|
||||
dst_width *= 2;
|
||||
dst_height *= 2;
|
||||
}
|
||||
|
||||
dst_top = ddraw->render.height / 2 - dst_height / 2;
|
||||
dst_left = ddraw->render.width / 2 - dst_width / 2;
|
||||
}
|
||||
|
||||
if(ddraw->render.maxfps < 0)
|
||||
{
|
||||
ddraw->render.maxfps = ddraw->mode.dmDisplayFrequency;
|
||||
}
|
||||
|
||||
if(ddraw->render.maxfps > 0)
|
||||
{
|
||||
frame_len = 1000.0f / ddraw->render.maxfps;
|
||||
}
|
||||
|
||||
while (ddraw->render.thread && WaitForSingleObject(ddraw->render.sem, INFINITE) != WAIT_FAILED)
|
||||
{
|
||||
if(ddraw->render.maxfps > 0)
|
||||
{
|
||||
tick_start = timeGetTime();
|
||||
}
|
||||
|
||||
EnterCriticalSection(&ddraw->cs);
|
||||
|
||||
if (ddraw->primary && (ddraw->primary->palette || ddraw->bpp == 16))
|
||||
{
|
||||
if (ddraw->primary->palette && ddraw->primary->palette->data_rgb == NULL)
|
||||
{
|
||||
ddraw->primary->palette->data_rgb = &bmi->bmiColors[0];
|
||||
}
|
||||
|
||||
if ((ddraw->render.width != ddraw->width || ddraw->render.height != ddraw->height) && !(ddraw->vhack && detect_cutscene()) )
|
||||
{
|
||||
StretchDIBits(ddraw->render.hDC, dst_left, dst_top, dst_width, dst_height, 0, 0, ddraw->width, ddraw->height, ddraw->primary->surface, bmi, DIB_RGB_COLORS, SRCCOPY);
|
||||
}
|
||||
else if (!(ddraw->vhack && detect_cutscene()))
|
||||
{
|
||||
SetDIBitsToDevice(ddraw->render.hDC, 0, 0, ddraw->width, ddraw->height, 0, 0, 0, ddraw->height, ddraw->primary->surface, bmi, DIB_RGB_COLORS);
|
||||
}
|
||||
|
||||
}
|
||||
if (ddraw->vhack && ddraw->primary && detect_cutscene()) // for vhack
|
||||
{
|
||||
if (ddraw->primary->palette && ddraw->primary->palette->data_rgb == NULL)
|
||||
{
|
||||
ddraw->primary->palette->data_rgb = &bmi->bmiColors[0];
|
||||
}
|
||||
|
||||
StretchDIBits(ddraw->render.hDC, 0, 0, ddraw->render.width, ddraw->render.height, 0, ddraw->height-400, CUTSCENE_WIDTH, CUTSCENE_HEIGHT, ddraw->primary->surface, bmi, DIB_RGB_COLORS, SRCCOPY);
|
||||
|
||||
if (ddraw->primary->palette && (ddraw->cursorclip.width != CUTSCENE_WIDTH || ddraw->cursorclip.height != CUTSCENE_HEIGHT))
|
||||
{
|
||||
ddraw->cursorclip.width = CUTSCENE_WIDTH;
|
||||
ddraw->cursorclip.height = CUTSCENE_HEIGHT;
|
||||
ddraw->cursor.x = CUTSCENE_WIDTH / 2;
|
||||
ddraw->cursor.y = CUTSCENE_HEIGHT / 2;
|
||||
}
|
||||
}
|
||||
else if(ddraw->primary && ddraw->primary->palette && (ddraw->cursorclip.width != ddraw->width || ddraw->cursorclip.height != ddraw->height))
|
||||
{
|
||||
ddraw->cursorclip.width = ddraw->width;
|
||||
ddraw->cursorclip.height = ddraw->height;
|
||||
ddraw->cursor.x = ddraw->width / 2;
|
||||
ddraw->cursor.y = ddraw->height / 2;
|
||||
}
|
||||
|
||||
LeaveCriticalSection(&ddraw->cs);
|
||||
|
||||
if(ddraw->render.maxfps > 0)
|
||||
{
|
||||
tick_end = timeGetTime();
|
||||
|
||||
if(tick_end - tick_start < frame_len)
|
||||
{
|
||||
Sleep( frame_len - (tick_end - tick_start));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
HeapFree(GetProcessHeap(), 0, bmi);
|
||||
|
||||
return TRUE;
|
||||
}
|
106
src/screenshot.c
Normal file
106
src/screenshot.c
Normal file
|
@ -0,0 +1,106 @@
|
|||
/*
|
||||
* Copyright (c) 2010 Toni Spets <toni.spets@iki.fi>
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#ifdef HAVE_LIBPNG
|
||||
|
||||
#include <windows.h>
|
||||
#include <stdio.h>
|
||||
#include <ctype.h>
|
||||
#include "ddraw.h"
|
||||
|
||||
#include "palette.h"
|
||||
#include "surface.h"
|
||||
|
||||
#include <png.h>
|
||||
|
||||
BOOL screenshot(struct IDirectDrawSurfaceImpl *src)
|
||||
{
|
||||
int i;
|
||||
FILE *fh;
|
||||
char title[128];
|
||||
char filename[128];
|
||||
|
||||
png_structp png_ptr;
|
||||
png_infop info_ptr;
|
||||
png_bytep *row_pointers;
|
||||
png_color palette[256];
|
||||
|
||||
char str_time[64];
|
||||
time_t t = time(NULL);
|
||||
|
||||
strncpy(title, ddraw->title, sizeof(ddraw->title));
|
||||
|
||||
for(i=0;i<strlen(title);i++) {
|
||||
if(title[i] == ' ')
|
||||
{
|
||||
title[i] = '_';
|
||||
}
|
||||
else
|
||||
{
|
||||
title[i] = tolower(title[i]);
|
||||
}
|
||||
}
|
||||
|
||||
strftime(str_time, 64, "%Y-%m-%d-%H_%M_%S", localtime(&t));
|
||||
snprintf(filename, 128, "%s-%s.png", title, str_time);
|
||||
|
||||
if(!src || !src->palette)
|
||||
{
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
if( !(fh = fopen(filename, "wb")) )
|
||||
{
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
png_ptr = png_create_write_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL);
|
||||
if(!png_ptr)
|
||||
{
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
info_ptr = png_create_info_struct(png_ptr);
|
||||
|
||||
for(i=0;i<256;i++) {
|
||||
palette[i].red = src->palette->data_bgr[i];
|
||||
palette[i].green = src->palette->data_bgr[i] >> 8;
|
||||
palette[i].blue = src->palette->data_bgr[i] >> 16;
|
||||
}
|
||||
|
||||
setjmp(png_jmpbuf(png_ptr));
|
||||
|
||||
png_init_io(png_ptr, fh);
|
||||
|
||||
png_set_IHDR(png_ptr, info_ptr, src->width, src->height, 8, PNG_COLOR_TYPE_PALETTE, PNG_INTERLACE_NONE, PNG_COMPRESSION_TYPE_BASE, PNG_FILTER_TYPE_BASE);
|
||||
png_set_PLTE(png_ptr, info_ptr, (png_colorp)&palette, 256);
|
||||
|
||||
row_pointers = (png_bytep *)png_malloc(png_ptr, sizeof(png_bytep) * src->height);
|
||||
|
||||
for(i=0;i<src->height;i++) {
|
||||
row_pointers[i] = src->surface + (src->width * i);
|
||||
}
|
||||
|
||||
png_set_rows(png_ptr, info_ptr, row_pointers);
|
||||
|
||||
png_write_png(png_ptr, info_ptr, PNG_TRANSFORM_IDENTITY, NULL);
|
||||
|
||||
fclose(fh);
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
#endif
|
586
src/surface.c
Normal file
586
src/surface.c
Normal file
|
@ -0,0 +1,586 @@
|
|||
/*
|
||||
* Copyright (c) 2010 Toni Spets <toni.spets@iki.fi>
|
||||
*
|
||||
* 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 <windows.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#include "main.h"
|
||||
#include "surface.h"
|
||||
|
||||
void dump_ddscaps(DWORD dwCaps);
|
||||
void dump_ddsd(DWORD dwFlags);
|
||||
|
||||
HRESULT __stdcall ddraw_surface_QueryInterface(IDirectDrawSurfaceImpl *This, REFIID riid, void **obj)
|
||||
{
|
||||
printf("DirectDrawSurface::QueryInterface(This=%p, riid=%08X, obj=%p)\n", This, (unsigned int)riid, obj);
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
ULONG __stdcall ddraw_surface_AddRef(IDirectDrawSurfaceImpl *This)
|
||||
{
|
||||
printf("DirectDrawSurface::AddRef(This=%p)\n", This);
|
||||
This->Ref++;
|
||||
return This->Ref;
|
||||
}
|
||||
|
||||
ULONG __stdcall ddraw_surface_Release(IDirectDrawSurfaceImpl *This)
|
||||
{
|
||||
printf("DirectDrawSurface::Release(This=%p)\n", This);
|
||||
|
||||
This->Ref--;
|
||||
|
||||
if(This->Ref == 0)
|
||||
{
|
||||
if(This->caps == DDSCAPS_PRIMARYSURFACE)
|
||||
{
|
||||
EnterCriticalSection(&ddraw->cs);
|
||||
ddraw->primary = NULL;
|
||||
LeaveCriticalSection(&ddraw->cs);
|
||||
}
|
||||
if(This->surface)
|
||||
{
|
||||
HeapFree(GetProcessHeap(), 0, This->surface);
|
||||
}
|
||||
if(This->palette)
|
||||
{
|
||||
IDirectDrawPalette_Release(This->palette);
|
||||
}
|
||||
HeapFree(GetProcessHeap(), 0, This);
|
||||
return 0;
|
||||
}
|
||||
return This->Ref;
|
||||
}
|
||||
|
||||
HRESULT __stdcall ddraw_surface_AddAttachedSurface(IDirectDrawSurfaceImpl *This, LPDIRECTDRAWSURFACE lpDDSurface)
|
||||
{
|
||||
printf("DirectDrawSurface::AddAttachedSurface(This=%p, lpDDSurface=%p)\n", This, lpDDSurface);
|
||||
IDirectDrawSurface_AddRef(lpDDSurface);
|
||||
return DD_OK;
|
||||
}
|
||||
|
||||
HRESULT __stdcall ddraw_surface_AddOverlayDirtyRect(IDirectDrawSurfaceImpl *This, LPRECT a)
|
||||
{
|
||||
printf("DirectDrawSurface::AddOverlayDirtyRect(This=%p, ...)\n", This);
|
||||
return DD_OK;
|
||||
}
|
||||
|
||||
HRESULT __stdcall ddraw_surface_Blt(IDirectDrawSurfaceImpl *This, LPRECT lpDestRect, LPDIRECTDRAWSURFACE lpDDSrcSurface, LPRECT lpSrcRect, DWORD dwFlags, LPDDBLTFX lpDDBltFx)
|
||||
{
|
||||
IDirectDrawSurfaceImpl *Source = (IDirectDrawSurfaceImpl *)lpDDSrcSurface;
|
||||
|
||||
#if _DEBUG
|
||||
printf("DirectDrawSurface::Blt(This=%p, lpDestRect=%p, lpDDSrcSurface=%p, lpSrcRect=%p, dwFlags=%d, lpDDBltFx=%p)\n", This, lpDestRect, lpDDSrcSurface, lpSrcRect, (int)dwFlags, lpDDBltFx);
|
||||
if(lpDestRect)
|
||||
{
|
||||
printf(" dest: l: %d t: %d r: %d b: %d\n", (int)lpDestRect->left, (int)lpDestRect->top, (int)lpDestRect->right, (int)lpDestRect->bottom);
|
||||
}
|
||||
if(lpSrcRect)
|
||||
{
|
||||
printf(" src: l: %d t: %d r: %d b: %d\n", (int)lpSrcRect->left, (int)lpSrcRect->top, (int)lpSrcRect->right, (int)lpSrcRect->bottom);
|
||||
}
|
||||
#endif
|
||||
|
||||
if(Source)
|
||||
{
|
||||
int dx=0,dy=0;
|
||||
if (lpDestRect)
|
||||
{
|
||||
dx=lpDestRect->left;
|
||||
dy=lpDestRect->top;
|
||||
}
|
||||
int x0=0,y0=0,x1=Source->width,y1=Source->height;
|
||||
if (lpSrcRect)
|
||||
{
|
||||
x0 = max(x0, lpSrcRect->left);
|
||||
x1 = min(x1, lpSrcRect->right);
|
||||
y0 = max(y0, lpSrcRect->top);
|
||||
y1 = min(y1, lpSrcRect->bottom);
|
||||
}
|
||||
unsigned char* to=This->surface + dy*This->width + dx;
|
||||
unsigned char* from=Source->surface + y0*Source->width + x0;
|
||||
int s = x1-x0;
|
||||
|
||||
if((This->caps & DDSCAPS_PRIMARYSURFACE) && !(This->flags & DDSD_BACKBUFFERCOUNT))
|
||||
{
|
||||
EnterCriticalSection(&ddraw->cs);
|
||||
|
||||
int y;
|
||||
for(y=y0; y<y1; ++y, to+=This->width, from+=Source->width)
|
||||
memcpy(to, from, s);
|
||||
|
||||
ReleaseSemaphore(ddraw->render.sem, 1, NULL);
|
||||
LeaveCriticalSection(&ddraw->cs);
|
||||
}
|
||||
else
|
||||
{
|
||||
int y;
|
||||
for(y=y0; y<y1; ++y, to+=This->width, from+=Source->width)
|
||||
memcpy(to, from, s);
|
||||
}
|
||||
}
|
||||
|
||||
return DD_OK;
|
||||
}
|
||||
|
||||
HRESULT __stdcall ddraw_surface_BltBatch(IDirectDrawSurfaceImpl *This, LPDDBLTBATCH a, DWORD b, DWORD c)
|
||||
{
|
||||
printf("IDirectDrawSurface::BltBatch(This=%p, ...)\n", This);
|
||||
return DD_OK;
|
||||
}
|
||||
|
||||
HRESULT __stdcall ddraw_surface_BltFast(IDirectDrawSurfaceImpl *This, DWORD a, DWORD b, LPDIRECTDRAWSURFACE c, LPRECT d, DWORD e)
|
||||
{
|
||||
printf("IDirectDrawSurface::BltFast(This=%p, ...)\n", This);
|
||||
return DD_OK;
|
||||
}
|
||||
|
||||
HRESULT __stdcall ddraw_surface_DeleteAttachedSurface(IDirectDrawSurfaceImpl *This, DWORD dwFlags, LPDIRECTDRAWSURFACE lpDDSurface)
|
||||
{
|
||||
printf("IDirectDrawSurface::DeleteAttachedSurface(This=%p, dwFlags=%d, lpDDSurface=%p)\n", This, (int)dwFlags, lpDDSurface);
|
||||
IDirectDrawSurface_Release(lpDDSurface);
|
||||
return DD_OK;
|
||||
}
|
||||
|
||||
HRESULT __stdcall ddraw_surface_GetSurfaceDesc(IDirectDrawSurfaceImpl *This, LPDDSURFACEDESC lpDDSurfaceDesc)
|
||||
{
|
||||
#if _DEBUG
|
||||
printf("IDirectDrawSurface::GetSurfaceDesc(This=%p, lpDDSurfaceDesc=%p)\n", This, lpDDSurfaceDesc);
|
||||
#endif
|
||||
|
||||
lpDDSurfaceDesc->dwSize = sizeof(DDSURFACEDESC);
|
||||
lpDDSurfaceDesc->dwFlags = DDSD_WIDTH|DDSD_HEIGHT|DDSD_PITCH|DDSD_PIXELFORMAT|DDSD_LPSURFACE;
|
||||
lpDDSurfaceDesc->dwWidth = This->width;
|
||||
lpDDSurfaceDesc->dwHeight = This->height;
|
||||
lpDDSurfaceDesc->lPitch = This->lPitch;
|
||||
lpDDSurfaceDesc->lpSurface = This->surface;
|
||||
lpDDSurfaceDesc->ddpfPixelFormat.dwFlags = DDPF_RGB;
|
||||
lpDDSurfaceDesc->ddpfPixelFormat.dwRGBBitCount = This->bpp;
|
||||
|
||||
if (This->bpp == 16)
|
||||
{
|
||||
/* RGB 555 */
|
||||
lpDDSurfaceDesc->ddpfPixelFormat.dwRBitMask = 0x7C00;
|
||||
lpDDSurfaceDesc->ddpfPixelFormat.dwGBitMask = 0x03E0;
|
||||
lpDDSurfaceDesc->ddpfPixelFormat.dwBBitMask = 0x001F;
|
||||
}
|
||||
|
||||
return DD_OK;
|
||||
}
|
||||
|
||||
HRESULT __stdcall ddraw_surface_EnumAttachedSurfaces(IDirectDrawSurfaceImpl *This, LPVOID lpContext, LPDDENUMSURFACESCALLBACK lpEnumSurfacesCallback)
|
||||
{
|
||||
printf("IDirectDrawSurface::EnumAttachedSurfaces(This=%p, lpContext=%p, lpEnumSurfacesCallback=%p)\n", This, lpContext, lpEnumSurfacesCallback);
|
||||
|
||||
/* this is not actually complete, but Carmageddon seems to call EnumAttachedSurfaces instead of GetSurfaceDesc to get the main surface description */
|
||||
static LPDDSURFACEDESC lpDDSurfaceDesc;
|
||||
lpDDSurfaceDesc = (LPDDSURFACEDESC)HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(DDSURFACEDESC));
|
||||
ddraw_surface_GetSurfaceDesc(This, lpDDSurfaceDesc);
|
||||
lpEnumSurfacesCallback((LPDIRECTDRAWSURFACE)This, lpDDSurfaceDesc, lpContext);
|
||||
HeapFree(GetProcessHeap(), 0, lpDDSurfaceDesc);
|
||||
|
||||
return DD_OK;
|
||||
}
|
||||
|
||||
HRESULT __stdcall ddraw_surface_EnumOverlayZOrders(IDirectDrawSurfaceImpl *This, DWORD a, LPVOID b, LPDDENUMSURFACESCALLBACK c)
|
||||
{
|
||||
printf("IDirectDrawSurface::EnumOverlayZOrders(This=%p, ...)\n", This);
|
||||
return DD_OK;
|
||||
}
|
||||
|
||||
HRESULT __stdcall ddraw_surface_Flip(IDirectDrawSurfaceImpl *This, LPDIRECTDRAWSURFACE a, DWORD b)
|
||||
{
|
||||
#if _DEBUG
|
||||
printf("IDirectDrawSurface::Flip(This=%p, ...)\n", This);
|
||||
#endif
|
||||
|
||||
if(This->caps & DDSCAPS_PRIMARYSURFACE)
|
||||
{
|
||||
ReleaseSemaphore(ddraw->render.sem, 1, NULL);
|
||||
}
|
||||
|
||||
return DD_OK;
|
||||
}
|
||||
|
||||
HRESULT __stdcall ddraw_surface_GetAttachedSurface(IDirectDrawSurfaceImpl *This, LPDDSCAPS a, LPDIRECTDRAWSURFACE FAR *b)
|
||||
{
|
||||
printf("IDirectDrawSurface::GetAttachedSurface(This=%p, ...)\n", This);
|
||||
return DD_OK;
|
||||
}
|
||||
|
||||
HRESULT __stdcall ddraw_surface_GetBltStatus(IDirectDrawSurfaceImpl *This, DWORD a)
|
||||
{
|
||||
#if _DEBUG
|
||||
printf("IDirectDrawSurface::GetBltStatus(This=%p, ...)\n", This);
|
||||
#endif
|
||||
return DD_OK;
|
||||
}
|
||||
|
||||
HRESULT __stdcall ddraw_surface_GetCaps(IDirectDrawSurfaceImpl *This, LPDDSCAPS lpDDSCaps)
|
||||
{
|
||||
printf("DirectDrawSurface::GetCaps(This=%p, lpDDSCaps=%p)\n", This, lpDDSCaps);
|
||||
lpDDSCaps->dwCaps = This->caps;
|
||||
return DD_OK;
|
||||
}
|
||||
|
||||
HRESULT __stdcall ddraw_surface_GetClipper(IDirectDrawSurfaceImpl *This, LPDIRECTDRAWCLIPPER FAR *a)
|
||||
{
|
||||
printf("IDirectDrawSurface::GetClipper(This=%p, ...)\n", This);
|
||||
return DD_OK;
|
||||
}
|
||||
|
||||
HRESULT __stdcall ddraw_surface_GetColorKey(IDirectDrawSurfaceImpl *This, DWORD a, LPDDCOLORKEY b)
|
||||
{
|
||||
printf("IDirectDrawSurface::GetColorKey(This=%p, ...)\n", This);
|
||||
return DD_OK;
|
||||
}
|
||||
|
||||
HRESULT __stdcall ddraw_surface_GetDC(IDirectDrawSurfaceImpl *This, HDC FAR *a)
|
||||
{
|
||||
printf("IDirectDrawSurface::GetDC(This=%p, ...)\n", This);
|
||||
return DD_OK;
|
||||
}
|
||||
|
||||
HRESULT __stdcall ddraw_surface_GetFlipStatus(IDirectDrawSurfaceImpl *This, DWORD a)
|
||||
{
|
||||
printf("IDirectDrawSurface::GetFlipStatus(This=%p, ...)\n", This);
|
||||
return DD_OK;
|
||||
}
|
||||
|
||||
HRESULT __stdcall ddraw_surface_GetOverlayPosition(IDirectDrawSurfaceImpl *This, LPLONG a, LPLONG b)
|
||||
{
|
||||
printf("IDirectDrawSurface::GetOverlayPosition(This=%p, ...)\n", This);
|
||||
return DD_OK;
|
||||
}
|
||||
|
||||
HRESULT __stdcall ddraw_surface_GetPalette(IDirectDrawSurfaceImpl *This, LPDIRECTDRAWPALETTE FAR *lplpDDPalette)
|
||||
{
|
||||
printf("DirectDrawSurface::GetPalette(This=%p, lplpDDPalette=%p)\n", This, lplpDDPalette);
|
||||
*lplpDDPalette = (LPDIRECTDRAWPALETTE)This->palette;
|
||||
return DD_OK;
|
||||
}
|
||||
|
||||
HRESULT __stdcall ddraw_surface_GetPixelFormat(IDirectDrawSurfaceImpl *This, LPDDPIXELFORMAT a)
|
||||
{
|
||||
printf("IDirectDrawSurface::GetPixelFormat(This=%p, ...)\n", This);
|
||||
return DD_OK;
|
||||
}
|
||||
|
||||
HRESULT __stdcall ddraw_surface_Initialize(IDirectDrawSurfaceImpl *This, LPDIRECTDRAW a, LPDDSURFACEDESC b)
|
||||
{
|
||||
printf("IDirectDrawSurface::Initialize(This=%p, ...)\n", This);
|
||||
return DD_OK;
|
||||
}
|
||||
|
||||
HRESULT __stdcall ddraw_surface_IsLost(IDirectDrawSurfaceImpl *This)
|
||||
{
|
||||
#if _DEBUG
|
||||
printf("IDirectDrawSurface::IsLost(This=%p)\n", This);
|
||||
#endif
|
||||
return DD_OK;
|
||||
}
|
||||
|
||||
HRESULT __stdcall ddraw_surface_Lock(IDirectDrawSurfaceImpl *This, LPRECT lpDestRect, LPDDSURFACEDESC lpDDSurfaceDesc, DWORD dwFlags, HANDLE hEvent)
|
||||
{
|
||||
#if _DEBUG
|
||||
printf("DirectDrawSurface::Lock(This=%p, lpDestRect=%p, lpDDSurfaceDesc=%p, dwFlags=%d, hEvent=%p)\n", This, lpDestRect, lpDDSurfaceDesc, (int)dwFlags, hEvent);
|
||||
|
||||
if(dwFlags & DDLOCK_SURFACEMEMORYPTR)
|
||||
{
|
||||
printf(" dwFlags: DDLOCK_SURFACEMEMORYPTR\n");
|
||||
}
|
||||
if(dwFlags & DDLOCK_WAIT)
|
||||
{
|
||||
printf(" dwFlags: DDLOCK_WAIT\n");
|
||||
}
|
||||
if(dwFlags & DDLOCK_EVENT)
|
||||
{
|
||||
printf(" dwFlags: DDLOCK_EVENT\n");
|
||||
}
|
||||
if(dwFlags & DDLOCK_READONLY)
|
||||
{
|
||||
printf(" dwFlags: DDLOCK_READONLY\n");
|
||||
}
|
||||
if(dwFlags & DDLOCK_WRITEONLY)
|
||||
{
|
||||
printf(" dwFlags: DDLOCK_WRITEONLY\n");
|
||||
}
|
||||
#endif
|
||||
|
||||
return ddraw_surface_GetSurfaceDesc(This, lpDDSurfaceDesc);
|
||||
}
|
||||
|
||||
HRESULT __stdcall ddraw_surface_ReleaseDC(IDirectDrawSurfaceImpl *This, HDC a)
|
||||
{
|
||||
printf("DirectDrawSurface::ReleaseDC(This=%p, ...)\n", This);
|
||||
return DD_OK;
|
||||
}
|
||||
|
||||
HRESULT __stdcall ddraw_surface_Restore(IDirectDrawSurfaceImpl *This)
|
||||
{
|
||||
printf("DirectDrawSurface::Restore(This=%p)\n", This);
|
||||
return DD_OK;
|
||||
}
|
||||
|
||||
HRESULT __stdcall ddraw_surface_SetClipper(IDirectDrawSurfaceImpl *This, LPDIRECTDRAWCLIPPER a)
|
||||
{
|
||||
printf("DirectDrawSurface::SetClipper(This=%p, ...)\n", This);
|
||||
return DD_OK;
|
||||
}
|
||||
|
||||
HRESULT __stdcall ddraw_surface_SetColorKey(IDirectDrawSurfaceImpl *This, DWORD a, LPDDCOLORKEY b)
|
||||
{
|
||||
printf("DirectDrawSurface::SetColorKey(This=%p, ...)\n", This);
|
||||
return DD_OK;
|
||||
}
|
||||
|
||||
HRESULT __stdcall ddraw_surface_SetOverlayPosition(IDirectDrawSurfaceImpl *This, LONG a, LONG b)
|
||||
{
|
||||
printf("DirectDrawSurface::SetOverlayPosition(This=%p, ...)\n", This);
|
||||
return DD_OK;
|
||||
}
|
||||
|
||||
HRESULT __stdcall ddraw_surface_SetPalette(IDirectDrawSurfaceImpl *This, LPDIRECTDRAWPALETTE lpDDPalette)
|
||||
{
|
||||
printf("DirectDrawSurface::SetPalette(This=%p, lpDDPalette=%p)\n", This, lpDDPalette);
|
||||
|
||||
IDirectDrawPalette_AddRef(lpDDPalette);
|
||||
|
||||
if(This->palette)
|
||||
{
|
||||
IDirectDrawPalette_Release(This->palette);
|
||||
}
|
||||
|
||||
This->palette = (IDirectDrawPaletteImpl *)lpDDPalette;
|
||||
|
||||
return DD_OK;
|
||||
}
|
||||
|
||||
HRESULT __stdcall ddraw_surface_Unlock(IDirectDrawSurfaceImpl *This, LPVOID lpRect)
|
||||
{
|
||||
#if _DEBUG
|
||||
printf("DirectDrawSurface::Unlock(This=%p, lpRect=%p)\n", This, lpRect);
|
||||
#endif
|
||||
|
||||
if(This->caps & DDSCAPS_PRIMARYSURFACE && !(This->flags & DDSD_BACKBUFFERCOUNT))
|
||||
{
|
||||
ReleaseSemaphore(ddraw->render.sem, 1, NULL);
|
||||
}
|
||||
|
||||
return DD_OK;
|
||||
}
|
||||
|
||||
HRESULT __stdcall ddraw_surface_UpdateOverlay(IDirectDrawSurfaceImpl *This, LPRECT a, LPDIRECTDRAWSURFACE b, LPRECT c, DWORD d, LPDDOVERLAYFX e)
|
||||
{
|
||||
printf("DirectDrawSurface::UpdateOverlay(This=%p, ...)\n", This);
|
||||
return DD_OK;
|
||||
}
|
||||
|
||||
HRESULT __stdcall ddraw_surface_UpdateOverlayDisplay(IDirectDrawSurfaceImpl *This, DWORD a)
|
||||
{
|
||||
printf("DirectDrawSurface::UpdateOverlayDisplay(This=%p, ...)\n", This);
|
||||
return DD_OK;
|
||||
}
|
||||
|
||||
HRESULT __stdcall ddraw_surface_UpdateOverlayZOrder(IDirectDrawSurfaceImpl *This, DWORD a, LPDIRECTDRAWSURFACE b)
|
||||
{
|
||||
printf("DirectDrawSurface::UpdateOverlayZOrder(This=%p, ...)\n", This);
|
||||
return DD_OK;
|
||||
}
|
||||
|
||||
struct IDirectDrawSurfaceImplVtbl siface =
|
||||
{
|
||||
/* IUnknown */
|
||||
ddraw_surface_QueryInterface,
|
||||
ddraw_surface_AddRef,
|
||||
ddraw_surface_Release,
|
||||
/* IDirectDrawSurface */
|
||||
ddraw_surface_AddAttachedSurface,
|
||||
ddraw_surface_AddOverlayDirtyRect,
|
||||
ddraw_surface_Blt,
|
||||
ddraw_surface_BltBatch,
|
||||
ddraw_surface_BltFast,
|
||||
ddraw_surface_DeleteAttachedSurface,
|
||||
ddraw_surface_EnumAttachedSurfaces,
|
||||
ddraw_surface_EnumOverlayZOrders,
|
||||
ddraw_surface_Flip,
|
||||
ddraw_surface_GetAttachedSurface,
|
||||
ddraw_surface_GetBltStatus,
|
||||
ddraw_surface_GetCaps,
|
||||
ddraw_surface_GetClipper,
|
||||
ddraw_surface_GetColorKey,
|
||||
ddraw_surface_GetDC,
|
||||
ddraw_surface_GetFlipStatus,
|
||||
ddraw_surface_GetOverlayPosition,
|
||||
ddraw_surface_GetPalette,
|
||||
ddraw_surface_GetPixelFormat,
|
||||
ddraw_surface_GetSurfaceDesc,
|
||||
ddraw_surface_Initialize,
|
||||
ddraw_surface_IsLost,
|
||||
ddraw_surface_Lock,
|
||||
ddraw_surface_ReleaseDC,
|
||||
ddraw_surface_Restore,
|
||||
ddraw_surface_SetClipper,
|
||||
ddraw_surface_SetColorKey,
|
||||
ddraw_surface_SetOverlayPosition,
|
||||
ddraw_surface_SetPalette,
|
||||
ddraw_surface_Unlock,
|
||||
ddraw_surface_UpdateOverlay,
|
||||
ddraw_surface_UpdateOverlayDisplay,
|
||||
ddraw_surface_UpdateOverlayZOrder
|
||||
};
|
||||
|
||||
HRESULT __stdcall ddraw_CreateSurface(IDirectDrawImpl *This, LPDDSURFACEDESC lpDDSurfaceDesc, LPDIRECTDRAWSURFACE FAR *lpDDSurface, IUnknown FAR * unkOuter)
|
||||
{
|
||||
printf("DirectDraw::CreateSurface(This=%p, lpDDSurfaceDesc=%p, lpDDSurface=%p, unkOuter=%p)\n", This, lpDDSurfaceDesc, lpDDSurface, unkOuter);
|
||||
|
||||
dump_ddsd(lpDDSurfaceDesc->dwFlags);
|
||||
|
||||
IDirectDrawSurfaceImpl *Surface = (IDirectDrawSurfaceImpl *)HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(IDirectDrawSurfaceImpl));
|
||||
|
||||
Surface->lpVtbl = &siface;
|
||||
|
||||
/* private stuff */
|
||||
Surface->bpp = This->bpp;
|
||||
Surface->flags = lpDDSurfaceDesc->dwFlags;
|
||||
|
||||
if(lpDDSurfaceDesc->dwFlags & DDSD_CAPS)
|
||||
{
|
||||
if(lpDDSurfaceDesc->ddsCaps.dwCaps & DDSCAPS_PRIMARYSURFACE)
|
||||
{
|
||||
ddraw->primary = Surface;
|
||||
|
||||
Surface->width = This->width;
|
||||
Surface->height = This->height;
|
||||
}
|
||||
|
||||
dump_ddscaps(lpDDSurfaceDesc->ddsCaps.dwCaps);
|
||||
Surface->caps = lpDDSurfaceDesc->ddsCaps.dwCaps;
|
||||
}
|
||||
|
||||
if( !(lpDDSurfaceDesc->dwFlags & DDSD_CAPS) || !(lpDDSurfaceDesc->ddsCaps.dwCaps & DDSCAPS_PRIMARYSURFACE) )
|
||||
{
|
||||
Surface->width = lpDDSurfaceDesc->dwWidth;
|
||||
Surface->height = lpDDSurfaceDesc->dwHeight;
|
||||
}
|
||||
|
||||
if(Surface->width && Surface->height)
|
||||
{
|
||||
Surface->lXPitch = Surface->bpp / 8;
|
||||
Surface->lPitch = Surface->width * Surface->lXPitch;
|
||||
Surface->surface = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, Surface->lPitch * Surface->height * Surface->lXPitch);
|
||||
}
|
||||
|
||||
printf(" Surface = %p (%dx%d@%d)\n", Surface, (int)Surface->width, (int)Surface->height, (int)Surface->bpp);
|
||||
|
||||
*lpDDSurface = (LPDIRECTDRAWSURFACE)Surface;
|
||||
|
||||
Surface->Ref = 0;
|
||||
ddraw_surface_AddRef(Surface);
|
||||
|
||||
return DD_OK;
|
||||
}
|
||||
|
||||
void dump_ddscaps(DWORD dwCaps)
|
||||
{
|
||||
if(dwCaps & DDSCAPS_PRIMARYSURFACE)
|
||||
{
|
||||
printf(" DDSCAPS_PRIMARYSURFACE\n");
|
||||
}
|
||||
if(dwCaps & DDSCAPS_OFFSCREENPLAIN)
|
||||
{
|
||||
printf(" DDSCAPS_OFFSCREENPLAIN\n");
|
||||
}
|
||||
if(dwCaps & DDSCAPS_VIDEOMEMORY)
|
||||
{
|
||||
printf(" DDSCAPS_VIDEOMEMORY\n");
|
||||
}
|
||||
if(dwCaps & DDSCAPS_LOCALVIDMEM)
|
||||
{
|
||||
printf(" DDSCAPS_LOCALVIDMEM\n");
|
||||
}
|
||||
}
|
||||
|
||||
void dump_ddsd(DWORD dwFlags)
|
||||
{
|
||||
if(dwFlags & DDSD_CAPS)
|
||||
{
|
||||
printf(" DDSD_CAPS\n");
|
||||
}
|
||||
if(dwFlags & DDSD_HEIGHT)
|
||||
{
|
||||
printf(" DDSD_HEIGHT\n");
|
||||
}
|
||||
if(dwFlags & DDSD_WIDTH)
|
||||
{
|
||||
printf(" DDSD_WIDTH\n");
|
||||
}
|
||||
if(dwFlags & DDSD_PITCH)
|
||||
{
|
||||
printf(" DDSD_PITCH\n");
|
||||
}
|
||||
if(dwFlags & DDSD_BACKBUFFERCOUNT)
|
||||
{
|
||||
printf(" DDSD_BACKBUFFERCOUNT\n");
|
||||
}
|
||||
if(dwFlags & DDSD_ZBUFFERBITDEPTH)
|
||||
{
|
||||
printf(" DDSD_ZBUFFERBITDEPTH\n");
|
||||
}
|
||||
if(dwFlags & DDSD_ALPHABITDEPTH)
|
||||
{
|
||||
printf(" DDSD_ALPHABITDEPTH\n");
|
||||
}
|
||||
if(dwFlags & DDSD_LPSURFACE)
|
||||
{
|
||||
printf(" DDSD_LPSURFACE\n");
|
||||
}
|
||||
if(dwFlags & DDSD_PIXELFORMAT)
|
||||
{
|
||||
printf(" DDSD_PIXELFORMAT\n");
|
||||
}
|
||||
if(dwFlags & DDSD_CKDESTOVERLAY)
|
||||
{
|
||||
printf(" DDSD_CKDESTOVERLAY\n");
|
||||
}
|
||||
if(dwFlags & DDSD_CKDESTBLT)
|
||||
{
|
||||
printf(" DDSD_CKDESTBLT\n");
|
||||
}
|
||||
if(dwFlags & DDSD_CKSRCOVERLAY)
|
||||
{
|
||||
printf(" DDSD_CKSRCOVERLAY\n");
|
||||
}
|
||||
if(dwFlags & DDSD_CKSRCBLT)
|
||||
{
|
||||
printf(" DDSD_CKSRCBLT\n");
|
||||
}
|
||||
if(dwFlags & DDSD_MIPMAPCOUNT)
|
||||
{
|
||||
printf(" DDSD_MIPMAPCOUNT\n");
|
||||
}
|
||||
if(dwFlags & DDSD_REFRESHRATE)
|
||||
{
|
||||
printf(" DDSD_REFRESHRATE\n");
|
||||
}
|
||||
if(dwFlags & DDSD_LINEARSIZE)
|
||||
{
|
||||
printf(" DDSD_LINEARSIZE\n");
|
||||
}
|
||||
if(dwFlags & DDSD_ALL)
|
||||
{
|
||||
printf(" DDSD_ALL\n");
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue