diff --git a/CONFIG/MainDlg.cpp b/CONFIG/MainDlg.cpp index e2f52209..84083892 100644 --- a/CONFIG/MainDlg.cpp +++ b/CONFIG/MainDlg.cpp @@ -68,9 +68,10 @@ BOOL CMainDialog::OnInitDialog() const list& driver_list = enumerator->GetDriverList(); for (list::const_iterator it_driver = driver_list.begin(); it_driver != driver_list.end(); it_driver++) { const MxDriver& driver = *it_driver; - for (list::const_iterator it_device = driver.m_devices.begin(); it_device != driver.m_devices.end(); + for (list::const_iterator it_device = driver.m_devices.begin(); + it_device != driver.m_devices.end(); it_device++) { - const MxDevice& device = *it_device; + const Direct3DDeviceInfo& device = *it_device; if (&device == currentConfigApp->m_device) { selected = device_i; } diff --git a/CONFIG/config.h b/CONFIG/config.h index 771dc228..9c633ac4 100644 --- a/CONFIG/config.h +++ b/CONFIG/config.h @@ -8,7 +8,7 @@ #include class MxDeviceEnumerate; -struct MxDevice; +struct Direct3DDeviceInfo; struct MxDriver; #define currentConfigApp ((CConfigApp*) afxCurrentWinApp) @@ -56,7 +56,7 @@ class CConfigApp : public CWinApp { public: MxDeviceEnumerate* m_device_enumerator; // 0x0c4 MxDriver* m_driver; // 0x0c8 - MxDevice* m_device; // 0x0cc + Direct3DDeviceInfo* m_device; // 0x0cc int m_display_bit_depth; // 0x0d0 BOOL m_flip_surfaces; // 0x0d4 BOOL m_full_screen; // 0x0d8 diff --git a/ISLE/isleapp.cpp b/ISLE/isleapp.cpp index d98a9824..95bc6f62 100644 --- a/ISLE/isleapp.cpp +++ b/ISLE/isleapp.cpp @@ -445,7 +445,7 @@ LRESULT WINAPI WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam) return DefWindowProcA(hWnd, uMsg, wParam, lParam); case WM_DISPLAYCHANGE: if (g_isle && VideoManager() && g_isle->GetFullScreen() && VideoManager()->GetDirect3D()) { - if (VideoManager()->GetDirect3D()->GetAssignedDevice()) { + if (VideoManager()->GetDirect3D()->AssignedDevice()) { int targetDepth = wParam; int targetWidth = LOWORD(lParam); int targetHeight = HIWORD(lParam); diff --git a/LEGO1/lego/legoomni/src/video/legovideomanager.cpp b/LEGO1/lego/legoomni/src/video/legovideomanager.cpp index 24512f3e..5c5cebbc 100644 --- a/LEGO1/lego/legoomni/src/video/legovideomanager.cpp +++ b/LEGO1/lego/legoomni/src/video/legovideomanager.cpp @@ -62,7 +62,7 @@ MxResult LegoVideoManager::Create(MxVideoParam& p_videoParam, MxU32 p_frequencyM { MxBool paletteCreated = FALSE; MxDriver* driver = NULL; - MxDevice* device = NULL; + Direct3DDeviceInfo* device = NULL; MxResult result = FAILURE; MxDeviceEnumerate100d9cc8 deviceEnumerate; @@ -137,11 +137,11 @@ MxResult LegoVideoManager::Create(MxVideoParam& p_videoParam, MxU32 p_frequencyM if (MxVideoManager::VTable0x28( p_videoParam, - m_direct3d->GetDirectDraw(), - m_direct3d->GetDirect3D(), - m_direct3d->GetFrontBuffer(), - m_direct3d->GetBackBuffer(), - m_direct3d->GetClipper(), + m_direct3d->DirectDraw(), + m_direct3d->Direct3D(), + m_direct3d->FrontBuffer(), + m_direct3d->BackBuffer(), + m_direct3d->Clipper(), p_frequencyMS, p_createThread ) != SUCCESS) { @@ -169,8 +169,8 @@ MxResult LegoVideoManager::Create(MxVideoParam& p_videoParam, MxU32 p_frequencyM createStruct.m_pPalette = m_videoParam.GetPalette()->CreateNativePalette(); createStruct.m_isFullScreen = FALSE; createStruct.m_isWideViewAngle = m_videoParam.Flags().GetWideViewAngle(); - createStruct.m_direct3d = m_direct3d->GetDirect3D(); - createStruct.m_d3dDevice = m_direct3d->GetDirect3DDevice(); + createStruct.m_direct3d = m_direct3d->Direct3D(); + createStruct.m_d3dDevice = m_direct3d->Direct3DDevice(); if (!m_3dManager->Create(createStruct)) { goto done; @@ -501,7 +501,7 @@ MxResult LegoVideoManager::ConfigureD3DRM() return FAILURE; } - MxAssignedDevice* assignedDevice = m_direct3d->GetAssignedDevice(); + MxAssignedDevice* assignedDevice = m_direct3d->AssignedDevice(); if (assignedDevice && assignedDevice->GetFlags() & MxAssignedDevice::c_hardwareMode) { if (assignedDevice->GetDesc().dpcTriCaps.dwTextureFilterCaps & D3DPTFILTERCAPS_LINEAR) { diff --git a/LEGO1/mxdirectx/mxdirect3d.cpp b/LEGO1/mxdirectx/mxdirect3d.cpp index 0fd02023..ccfd6405 100644 --- a/LEGO1/mxdirectx/mxdirect3d.cpp +++ b/LEGO1/mxdirectx/mxdirect3d.cpp @@ -6,18 +6,24 @@ DECOMP_SIZE_ASSERT(MxAssignedDevice, 0xe4); DECOMP_SIZE_ASSERT(MxDirect3D, 0x894); #endif -DECOMP_SIZE_ASSERT(MxDevice, 0x1a4); +DECOMP_SIZE_ASSERT(Direct3DDeviceInfo, 0x1a4); DECOMP_SIZE_ASSERT(MxDisplayMode, 0x0c); DECOMP_SIZE_ASSERT(MxDriver, 0x190); DECOMP_SIZE_ASSERT(MxDeviceEnumerate, 0x14); #if !defined(MXDIRECTX_FOR_CONFIG) +#define RELEASE(x) \ + if (x != NULL) { \ + x->Release(); \ + x = NULL; \ + } + // FUNCTION: LEGO1 0x1009b0a0 MxDirect3D::MxDirect3D() { this->m_pDirect3d = NULL; this->m_pDirect3dDevice = NULL; - this->m_unk0x88c = 0; + this->m_bTexturesDisabled = FALSE; this->m_assignedDevice = NULL; } @@ -53,7 +59,7 @@ BOOL MxDirect3D::Create( paletteEntryCount ); - if (ret && CreateIDirect3D() && D3DSetMode()) { + if (ret && D3DCreate() && D3DSetMode()) { success = TRUE; } @@ -67,15 +73,8 @@ BOOL MxDirect3D::Create( // FUNCTION: LEGO1 0x1009b210 void MxDirect3D::Destroy() { - if (this->m_pDirect3dDevice) { - this->m_pDirect3dDevice->Release(); - this->m_pDirect3dDevice = NULL; - } - - if (this->m_pDirect3d) { - this->m_pDirect3d->Release(); - this->m_pDirect3d = NULL; - } + RELEASE(m_pDirect3dDevice); + RELEASE(m_pDirect3d); if (this->m_assignedDevice) { delete m_assignedDevice; @@ -92,27 +91,21 @@ void MxDirect3D::Destroy() // FUNCTION: LEGO1 0x1009b290 void MxDirect3D::DestroyButNotDirectDraw() { - if (this->m_pDirect3dDevice) { - this->m_pDirect3dDevice->Release(); - this->m_pDirect3dDevice = NULL; - } - if (this->m_pDirect3d) { - this->m_pDirect3d->Release(); - this->m_pDirect3d = NULL; - } + RELEASE(m_pDirect3dDevice); + RELEASE(m_pDirect3d); MxDirectDraw::DestroyButNotDirectDraw(); } // FUNCTION: LEGO1 0x1009b2d0 -BOOL MxDirect3D::CreateIDirect3D() +BOOL MxDirect3D::D3DCreate() { - HRESULT ret = IDirect3D_QueryInterface(m_pDirectDraw, IID_IDirect3D2, (LPVOID*) &m_pDirect3d); + HRESULT result; - if (ret) { - Error("Creation of IDirect3D failed", ret); + result = DirectDraw()->QueryInterface(IID_IDirect3D2, (LPVOID*) &m_pDirect3d); + if (result != DD_OK) { + Error("Creation of IDirect3D failed", result); return FALSE; } - return TRUE; } @@ -126,27 +119,25 @@ BOOL MxDirect3D::D3DSetMode() } if (m_assignedDevice->m_desc.dpcTriCaps.dwTextureCaps & D3DPTEXTURECAPS_PERSPECTIVE) { - m_unk0x88c = FALSE; + m_bTexturesDisabled = FALSE; } else { - m_unk0x88c = TRUE; + m_bTexturesDisabled = TRUE; } - DWORD bitDepth = GetZBufferBitDepth(m_assignedDevice); - if (!CreateZBuffer(DDSCAPS_VIDEOMEMORY, bitDepth)) { + if (!CreateZBuffer(DDSCAPS_VIDEOMEMORY, ZBufferDepth(m_assignedDevice))) { return FALSE; } } else { if (m_assignedDevice->m_desc.dpcTriCaps.dwTextureCaps & D3DPTEXTURECAPS_PERSPECTIVE) { - m_unk0x88c = FALSE; + m_bTexturesDisabled = FALSE; } else { - m_unk0x88c = TRUE; + m_bTexturesDisabled = TRUE; } - DWORD bitDepth = GetZBufferBitDepth(m_assignedDevice); - if (!CreateZBuffer(DDSCAPS_SYSTEMMEMORY, bitDepth)) { + if (!CreateZBuffer(DDSCAPS_SYSTEMMEMORY, ZBufferDepth(m_assignedDevice))) { return FALSE; } } @@ -160,9 +151,11 @@ BOOL MxDirect3D::D3DSetMode() MxDirectDraw::Mode mode = m_currentMode; - if (m_bFullScreen && !IsSupportedMode(mode.width, mode.height, mode.bitsPerPixel)) { - Error("This device cannot support the current display mode", DDERR_GENERIC); - return FALSE; + if (IsFullScreen()) { + if (!IsSupportedMode(mode.width, mode.height, mode.bitsPerPixel)) { + Error("This device cannot support the current display mode", DDERR_GENERIC); + return FALSE; + } } LPDIRECTDRAWSURFACE frontBuffer = m_pFrontBuffer; @@ -209,35 +202,39 @@ BOOL MxDirect3D::D3DSetMode() } // FUNCTION: LEGO1 0x1009b5a0 -DWORD MxDirect3D::GetZBufferBitDepth(MxAssignedDevice* p_assignedDevice) +int MxDirect3D::ZBufferDepth(MxAssignedDevice* p_assignedDevice) { - DWORD bitDepth; + int depth; + DWORD deviceDepth; if (p_assignedDevice->m_desc.dwFlags & D3DDD_DEVICEZBUFFERBITDEPTH) { - bitDepth = p_assignedDevice->m_desc.dwDeviceZBufferBitDepth; + deviceDepth = p_assignedDevice->m_desc.dwDeviceZBufferBitDepth; } else { - bitDepth = 0; + deviceDepth = 0; } - if (bitDepth & DDBD_32) { - return 32; + if (deviceDepth & DDBD_32) { + depth = 32; } - if (bitDepth & DDBD_24) { - return 24; + else if (deviceDepth & DDBD_24) { + depth = 24; } - if (bitDepth & DDBD_16) { - return 16; + else if (deviceDepth & DDBD_16) { + depth = 16; } - if (bitDepth & DDBD_8) { - return 8; + else if (deviceDepth & DDBD_8) { + depth = 8; + } + else { + depth = -1; } - return -1; + return depth; } // FUNCTION: LEGO1 0x1009b5f0 -BOOL MxDirect3D::SetDevice(MxDeviceEnumerate& p_deviceEnumerate, MxDriver* p_driver, MxDevice* p_device) +BOOL MxDirect3D::SetDevice(MxDeviceEnumerate& p_deviceEnumerate, MxDriver* p_driver, Direct3DDeviceInfo* p_device) { if (m_assignedDevice) { delete m_assignedDevice; @@ -286,8 +283,9 @@ BOOL MxDirect3D::SetDevice(MxDeviceEnumerate& p_deviceEnumerate, MxDriver* p_dri assignedDevice->m_flags |= MxAssignedDevice::c_primaryDevice; } - for (list::iterator it2 = driver.m_devices.begin(); it2 != driver.m_devices.end(); it2++) { - MxDevice& device = *it2; + for (list::iterator it2 = driver.m_devices.begin(); it2 != driver.m_devices.end(); + it2++) { + Direct3DDeviceInfo& device = *it2; if (&device != p_device) { continue; } @@ -395,7 +393,7 @@ void MxDriver::Init(LPGUID p_guid, LPSTR p_driverDesc, LPSTR p_driverName) } // FUNCTION: LEGO1 0x1009bd20 -MxDevice::MxDevice( +Direct3DDeviceInfo::Direct3DDeviceInfo( LPGUID p_guid, LPSTR p_deviceDesc, LPSTR p_deviceName, @@ -405,12 +403,12 @@ MxDevice::MxDevice( { memset(this, 0, sizeof(*this)); - Init(p_guid, p_deviceDesc, p_deviceName, p_HWDesc, p_HELDesc); + Initialize(p_guid, p_deviceDesc, p_deviceName, p_HWDesc, p_HELDesc); } // FUNCTION: CONFIG 0x401460 // FUNCTION: LEGO1 0x1009bd60 -MxDevice::~MxDevice() +Direct3DDeviceInfo::~Direct3DDeviceInfo() { if (m_guid) { delete m_guid; @@ -424,7 +422,7 @@ MxDevice::~MxDevice() } // FUNCTION: LEGO1 0x1009bda0 -void MxDevice::Init( +void Direct3DDeviceInfo::Initialize( LPGUID p_guid, LPSTR p_deviceDesc, LPSTR p_deviceName, @@ -601,7 +599,7 @@ HRESULT MxDeviceEnumerate::EnumDevicesCallback( LPD3DDEVICEDESC p_HELDesc ) { - MxDevice device(p_guid, p_deviceDesc, p_deviceName, p_HWDesc, p_HELDesc); + Direct3DDeviceInfo device(p_guid, p_deviceDesc, p_deviceName, p_HWDesc, p_HELDesc); m_list.back().m_devices.push_back(device); memset(&device, 0, sizeof(device)); return DDENUMRET_OK; @@ -899,7 +897,7 @@ int MxDeviceEnumerate::ProcessDeviceBytes(int p_deviceNum, GUID& p_guid) GUID4 compareGuid; MxDriver& driver = *it; - for (list::iterator it2 = driver.m_devices.begin(); it2 != driver.m_devices.end(); it2++) { + for (list::iterator it2 = driver.m_devices.begin(); it2 != driver.m_devices.end(); it2++) { memcpy(&compareGuid, (*it2).m_guid, sizeof(GUID4)); if (compareGuid.m_data1 == deviceGuid.m_data1 && compareGuid.m_data2 == deviceGuid.m_data2 && @@ -919,7 +917,7 @@ int MxDeviceEnumerate::ProcessDeviceBytes(int p_deviceNum, GUID& p_guid) // FUNCTION: CONFIG 0x00402730 // FUNCTION: LEGO1 0x1009d030 -int MxDeviceEnumerate::GetDevice(int p_deviceNum, MxDriver*& p_driver, MxDevice*& p_device) +int MxDeviceEnumerate::GetDevice(int p_deviceNum, MxDriver*& p_driver, Direct3DDeviceInfo*& p_device) { if (p_deviceNum >= 0 && m_initialized) { int i = 0; @@ -927,7 +925,8 @@ int MxDeviceEnumerate::GetDevice(int p_deviceNum, MxDriver*& p_driver, MxDevice* for (list::iterator it = m_list.begin(); it != m_list.end(); it++) { p_driver = &*it; - for (list::iterator it2 = p_driver->m_devices.begin(); it2 != p_driver->m_devices.end(); it2++) { + for (list::iterator it2 = p_driver->m_devices.begin(); it2 != p_driver->m_devices.end(); + it2++) { if (i == p_deviceNum) { p_device = &*it2; return 0; @@ -944,7 +943,8 @@ int MxDeviceEnumerate::GetDevice(int p_deviceNum, MxDriver*& p_driver, MxDevice* #if defined(MXDIRECTX_FOR_CONFIG) // FUNCTION: CONFIG 0x004027d0 -int MxDeviceEnumerate::FormatDeviceName(char* p_buffer, const MxDriver* p_driver, const MxDevice* p_device) const +int MxDeviceEnumerate::FormatDeviceName(char* p_buffer, const MxDriver* p_driver, const Direct3DDeviceInfo* p_device) + const { int number = 0; for (list::const_iterator it = m_list.begin(); it != m_list.end(); it++) { @@ -988,7 +988,7 @@ int MxDeviceEnumerate::FUN_1009d0d0() return k; } - for (list::iterator it2 = (*it).m_devices.begin(); it2 != (*it).m_devices.end(); it2++) { + for (list::iterator it2 = (*it).m_devices.begin(); it2 != (*it).m_devices.end(); it2++) { if ((*it2).m_HWDesc.dcmColorModel) { return j; } @@ -1095,8 +1095,8 @@ int MxDeviceEnumerate::FUN_1009d210() m_list.erase(it++); } else { - for (list::iterator it2 = driver.m_devices.begin(); it2 != driver.m_devices.end();) { - MxDevice& device = *it2; + for (list::iterator it2 = driver.m_devices.begin(); it2 != driver.m_devices.end();) { + Direct3DDeviceInfo& device = *it2; if (!FUN_1009d3d0(device)) { driver.m_devices.erase(it2++); @@ -1136,7 +1136,7 @@ unsigned char MxDeviceEnumerate::DriverSupportsRequiredDisplayMode(MxDriver& p_d // FUNCTION: CONFIG 0x00402b60 // FUNCTION: LEGO1 0x1009d3d0 -unsigned char MxDeviceEnumerate::FUN_1009d3d0(MxDevice& p_device) +unsigned char MxDeviceEnumerate::FUN_1009d3d0(Direct3DDeviceInfo& p_device) { if (m_list.size() <= 0) { return FALSE; @@ -1147,7 +1147,8 @@ unsigned char MxDeviceEnumerate::FUN_1009d3d0(MxDevice& p_device) p_device.m_HWDesc.dpcTriCaps.dwTextureCaps & D3DPTEXTURECAPS_PERSPECTIVE; } - for (list::iterator it = m_list.front().m_devices.begin(); it != m_list.front().m_devices.end(); it++) { + for (list::iterator it = m_list.front().m_devices.begin(); it != m_list.front().m_devices.end(); + it++) { if ((&*it) == &p_device) { return TRUE; } diff --git a/LEGO1/mxdirectx/mxdirect3d.h b/LEGO1/mxdirectx/mxdirect3d.h index 77d769b8..341f9c69 100644 --- a/LEGO1/mxdirectx/mxdirect3d.h +++ b/LEGO1/mxdirectx/mxdirect3d.h @@ -35,7 +35,7 @@ class MxAssignedDevice { class MxDeviceEnumerate; struct MxDriver; -struct MxDevice; +struct Direct3DDeviceInfo; // VTABLE: LEGO1 0x100db800 // SIZE 0x894 @@ -58,14 +58,17 @@ class MxDirect3D : public MxDirectDraw { void Destroy() override; // vtable+0x08 void DestroyButNotDirectDraw() override; // vtable+0x0c - BOOL CreateIDirect3D(); - BOOL D3DSetMode(); - DWORD GetZBufferBitDepth(MxAssignedDevice* p_assignedDevice); - BOOL SetDevice(MxDeviceEnumerate& p_deviceEnumerate, MxDriver* p_driver, MxDevice* p_device); + inline MxAssignedDevice* AssignedDevice() { return this->m_assignedDevice; } + inline IDirect3D2* Direct3D() { return this->m_pDirect3d; } + inline IDirect3DDevice2* Direct3DDevice() { return this->m_pDirect3dDevice; } - inline MxAssignedDevice* GetAssignedDevice() { return this->m_assignedDevice; } - inline IDirect3D2* GetDirect3D() { return this->m_pDirect3d; } - inline IDirect3DDevice2* GetDirect3DDevice() { return this->m_pDirect3dDevice; } + BOOL SetDevice(MxDeviceEnumerate& p_deviceEnumerate, MxDriver* p_driver, Direct3DDeviceInfo* p_device); + +protected: + BOOL D3DCreate(); + BOOL D3DSetMode(); + + int ZBufferDepth(MxAssignedDevice* p_assignedDevice); // SYNTHETIC: LEGO1 0x1009b120 // MxDirect3D::`scalar deleting destructor' @@ -74,16 +77,16 @@ class MxDirect3D : public MxDirectDraw { MxAssignedDevice* m_assignedDevice; // 0x880 IDirect3D2* m_pDirect3d; // 0x884 IDirect3DDevice2* m_pDirect3dDevice; // 0x888 - BOOL m_unk0x88c; // 0x88c + BOOL m_bTexturesDisabled; // 0x88c undefined4 m_unk0x890; // 0x890 }; #endif // SIZE 0x1a4 -struct MxDevice { - MxDevice() {} - ~MxDevice(); - MxDevice( +struct Direct3DDeviceInfo { + Direct3DDeviceInfo() {} + ~Direct3DDeviceInfo(); + Direct3DDeviceInfo( LPGUID p_guid, LPSTR p_deviceDesc, LPSTR p_deviceName, @@ -91,7 +94,7 @@ struct MxDevice { LPD3DDEVICEDESC p_HELDesc ); - void Init( + void Initialize( LPGUID p_guid, LPSTR p_deviceDesc, LPSTR p_deviceName, @@ -105,8 +108,8 @@ struct MxDevice { D3DDEVICEDESC m_HWDesc; // 0x0c D3DDEVICEDESC m_HELDesc; // 0xd8 - int operator==(MxDevice) const { return 0; } - int operator<(MxDevice) const { return 0; } + int operator==(Direct3DDeviceInfo) const { return 0; } + int operator<(Direct3DDeviceInfo) const { return 0; } }; // SIZE 0x0c @@ -131,7 +134,7 @@ struct MxDriver { char* m_driverDesc; // 0x04 char* m_driverName; // 0x08 DDCAPS m_ddCaps; // 0x0c - list m_devices; // 0x178 + list m_devices; // 0x178 list m_displayModes; // 0x184 int operator==(MxDriver) const { return 0; } @@ -141,7 +144,7 @@ struct MxDriver { // clang-format off // TEMPLATE: CONFIG 0x401000 // TEMPLATE: LEGO1 0x1009b900 -// list >::~list > +// list >::~list > // clang-format on // clang-format off @@ -152,7 +155,7 @@ struct MxDriver { // TEMPLATE: CONFIG 0x4010e0 // TEMPLATE: LEGO1 0x1009b9e0 -// List::~List +// List::~List // TEMPLATE: CONFIG 0x401130 // TEMPLATE: LEGO1 0x1009ba30 @@ -175,7 +178,7 @@ struct MxDriver { // SYNTHETIC: CONFIG 0x401b00 // SYNTHETIC: LEGO1 0x1009c400 -// list >::insert +// list >::insert // SYNTHETIC: CONFIG 0x401b60 // SYNTHETIC: LEGO1 0x1009c460 @@ -185,7 +188,7 @@ struct MxDriver { // MxDriver::`scalar deleting destructor' // SYNTHETIC: LEGO1 0x1009d470 -// MxDevice::`scalar deleting destructor' +// Direct3DDeviceInfo::`scalar deleting destructor' // VTABLE: CONFIG 0x00406000 // VTABLE: LEGO1 0x100db814 @@ -209,16 +212,16 @@ class MxDeviceEnumerate { const char* EnumerateErrorToString(HRESULT p_error); int ParseDeviceName(const char* p_deviceId); int ProcessDeviceBytes(int p_deviceNum, GUID& p_guid); - int GetDevice(int p_deviceNum, MxDriver*& p_driver, MxDevice*& p_device); + int GetDevice(int p_deviceNum, MxDriver*& p_driver, Direct3DDeviceInfo*& p_device); #if defined(MXDIRECTX_FOR_CONFIG) - int FormatDeviceName(char* p_buffer, const MxDriver* p_driver, const MxDevice* p_device) const; + int FormatDeviceName(char* p_buffer, const MxDriver* p_driver, const Direct3DDeviceInfo* p_device) const; #endif int FUN_1009d0d0(); int FUN_1009d210(); unsigned char DriverSupportsRequiredDisplayMode(MxDriver& p_driver); - unsigned char FUN_1009d3d0(MxDevice& p_device); + unsigned char FUN_1009d3d0(Direct3DDeviceInfo& p_device); static void BuildErrorString(const char*, ...); static BOOL CALLBACK diff --git a/LEGO1/mxdirectx/mxdirectdraw.cpp b/LEGO1/mxdirectx/mxdirectdraw.cpp index 0e31e8d1..0b3d05ff 100644 --- a/LEGO1/mxdirectx/mxdirectdraw.cpp +++ b/LEGO1/mxdirectx/mxdirectdraw.cpp @@ -5,6 +5,12 @@ DECOMP_SIZE_ASSERT(MxDirectDraw, 0x880); DECOMP_SIZE_ASSERT(MxDirectDraw::DeviceModesInfo, 0x17c); +#define RELEASE(x) \ + if (x != NULL) { \ + x->Release(); \ + x = NULL; \ + } + #ifndef DDSCAPS_3DDEVICE #define DDSCAPS_3DDEVICE 0x00002000l #endif @@ -75,7 +81,7 @@ int MxDirectDraw::GetPrimaryBitDepth() // FUNCTION: LEGO1 0x1009d5e0 BOOL MxDirectDraw::Create( HWND hWnd, - BOOL fullscreen_1, + BOOL fullscreen, BOOL surface_fullscreen, BOOL onlySystemMemory, int width, @@ -96,10 +102,9 @@ BOOL MxDirectDraw::Create( m_bFlipSurfaces = surface_fullscreen; m_bOnlySystemMemory = onlySystemMemory; m_bIsOnPrimaryDevice = !m_pCurrentDeviceModesList->m_guid; - BOOL fullscreen = 1; - if (m_bIsOnPrimaryDevice) { - fullscreen = fullscreen_1; + if (!m_bIsOnPrimaryDevice) { + fullscreen = TRUE; } if (!SetPaletteEntries(pPaletteEntries, paletteEntryCount, fullscreen)) { @@ -120,23 +125,19 @@ BOOL MxDirectDraw::Create( // FUNCTION: LEGO1 0x1009d690 BOOL MxDirectDraw::RecreateDirectDraw(GUID** ppGUID) { - if (m_pDirectDraw) { - m_pDirectDraw->Release(); - m_pDirectDraw = NULL; - } - + RELEASE(m_pDirectDraw); return (DirectDrawCreate(*ppGUID, &m_pDirectDraw, 0) == DD_OK); } // FUNCTION: LEGO1 0x1009d6c0 BOOL MxDirectDraw::CacheOriginalPaletteEntries() { - HDC dc; + HDC hdc; if (g_isPaletteIndexed8) { - dc = GetDC(0); - GetSystemPaletteEntries(dc, 0, _countof(m_originalPaletteEntries), m_originalPaletteEntries); - ReleaseDC(0, dc); + hdc = GetDC(NULL); + GetSystemPaletteEntries(hdc, 0, (1 << 8), &m_originalPaletteEntries[0]); + ReleaseDC(NULL, hdc); } return TRUE; } @@ -152,7 +153,7 @@ BOOL MxDirectDraw::SetPaletteEntries(const PALETTEENTRY* pPaletteEntries, int pa if (g_isPaletteIndexed8) { hdc = GetDC(NULL); - GetSystemPaletteEntries(hdc, 0, arraySize, m_paletteEntries); + GetSystemPaletteEntries(hdc, 0, (1 << 8), m_paletteEntries); ReleaseDC(NULL, hdc); } @@ -168,20 +169,21 @@ BOOL MxDirectDraw::SetPaletteEntries(const PALETTEENTRY* pPaletteEntries, int pa m_paletteEntries[i].peFlags = 0x84; } - for (i = arraySize - reservedHighEntryCount; i < arraySize; i++) { + for (i = 256 - reservedHighEntryCount; i < 256; i++) { m_paletteEntries[i].peFlags = 0x80; } if (paletteEntryCount != 0) { - for (i = reservedLowEntryCount; (i < paletteEntryCount) && (i < arraySize - reservedHighEntryCount); i++) { + for (i = reservedLowEntryCount; (i < paletteEntryCount) && (i < 256 - reservedHighEntryCount); i++) { m_paletteEntries[i].peRed = pPaletteEntries[i].peRed; m_paletteEntries[i].peGreen = pPaletteEntries[i].peGreen; m_paletteEntries[i].peBlue = pPaletteEntries[i].peBlue; } } - if (m_pPalette != NULL) { + if (m_pPalette) { HRESULT result; + result = m_pPalette->SetEntries(0, 0, _countof(m_paletteEntries), m_paletteEntries); if (result != DD_OK) { Error("SetEntries failed", result); @@ -199,10 +201,7 @@ void MxDirectDraw::Destroy() FUN_1009d920(); - if (m_pDirectDraw != NULL) { - m_pDirectDraw->Release(); - m_pDirectDraw = NULL; - } + RELEASE(m_pDirectDraw); m_bIsOnPrimaryDevice = TRUE; @@ -217,47 +216,20 @@ void MxDirectDraw::DestroyButNotDirectDraw() { RestoreOriginalPaletteEntries(); if (m_bFullScreen) { - if (m_pDirectDraw != NULL) { + if (m_pDirectDraw) { m_bIgnoreWMSIZE = TRUE; m_pDirectDraw->RestoreDisplayMode(); m_bIgnoreWMSIZE = FALSE; } } - if (m_pPalette) { - m_pPalette->Release(); - m_pPalette = NULL; - } - - if (m_pClipper) { - m_pClipper->Release(); - m_pClipper = NULL; - } - - if (m_pText1Surface) { - m_pText1Surface->Release(); - m_pText1Surface = NULL; - } - - if (m_pText2Surface) { - m_pText2Surface->Release(); - m_pText2Surface = NULL; - } - - if (m_pZBuffer) { - m_pZBuffer->Release(); - m_pZBuffer = NULL; - } - - if (m_pBackBuffer) { - m_pBackBuffer->Release(); - m_pBackBuffer = NULL; - } - - if (m_pFrontBuffer) { - m_pFrontBuffer->Release(); - m_pFrontBuffer = NULL; - } + RELEASE(m_pPalette); + RELEASE(m_pClipper); + RELEASE(m_pText1Surface); + RELEASE(m_pText2Surface); + RELEASE(m_pZBuffer); + RELEASE(m_pBackBuffer); + RELEASE(m_pFrontBuffer); } // FUNCTION: LEGO1 0x1009d920 @@ -366,16 +338,18 @@ BOOL MxDirectDraw::DDSetMode(int width, int height, int bpp) DWORD dwStyle; if (!m_bIsOnPrimaryDevice) { - Error("Attempt made enter a windowed mode on a DirectDraw device that is not the primary display", E_FAIL); + Error( + "Attempt made enter a windowed mode on a DirectDraw device that is not the primary display", + DDERR_GENERIC + ); return FALSE; } m_bIgnoreWMSIZE = TRUE; dwStyle = GetWindowLong(m_hWndMain, GWL_STYLE); dwStyle &= ~WS_POPUP; - dwStyle |= WS_CAPTION | WS_THICKFRAME | WS_OVERLAPPED; + dwStyle |= WS_OVERLAPPED | WS_CAPTION | WS_THICKFRAME; SetWindowLong(m_hWndMain, GWL_STYLE, dwStyle); - SetRect(&rc, 0, 0, width - 1, height - 1); AdjustWindowRectEx( &rc, @@ -443,9 +417,13 @@ BOOL MxDirectDraw::DDSetMode(int width, int height, int bpp) } // FUNCTION: LEGO1 0x1009dd80 -HRESULT MxDirectDraw::CreateDDSurface(LPDDSURFACEDESC a2, LPDIRECTDRAWSURFACE* a3, IUnknown* a4) +HRESULT MxDirectDraw::CreateDDSurface( + LPDDSURFACEDESC p_lpDDSurfDesc, + LPDIRECTDRAWSURFACE FAR* p_lpDDSurface, + IUnknown FAR* p_pUnkOuter +) { - return m_pDirectDraw->CreateSurface(a2, a3, a4); + return m_pDirectDraw->CreateSurface(p_lpDDSurfDesc, p_lpDDSurface, p_pUnkOuter); } // FUNCTION: LEGO1 0x1009dda0 @@ -453,8 +431,8 @@ BOOL MxDirectDraw::GetDDSurfaceDesc(LPDDSURFACEDESC lpDDSurfDesc, LPDIRECTDRAWSU { HRESULT result; - memset(lpDDSurfDesc, 0, sizeof(*lpDDSurfDesc)); - lpDDSurfDesc->dwSize = sizeof(*lpDDSurfDesc); + memset(lpDDSurfDesc, 0, sizeof(DDSURFACEDESC)); + lpDDSurfDesc->dwSize = sizeof(DDSURFACEDESC); result = lpDDSurf->GetSurfaceDesc(lpDDSurfDesc); if (result != DD_OK) { Error("Error getting a surface description", result); @@ -467,25 +445,23 @@ BOOL MxDirectDraw::GetDDSurfaceDesc(LPDDSURFACEDESC lpDDSurfDesc, LPDIRECTDRAWSU BOOL MxDirectDraw::DDCreateSurfaces() { HRESULT result; - DDSCAPS ddscaps; DDSURFACEDESC ddsd; + DDSCAPS ddscaps; if (m_bFlipSurfaces) { - memset(&ddsd, 0, sizeof(ddsd)); + memset(&ddsd, 0, sizeof(DDSURFACEDESC)); ddsd.dwSize = sizeof(ddsd); ddsd.dwFlags = DDSD_CAPS | DDSD_BACKBUFFERCOUNT; ddsd.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE | DDSCAPS_FLIP | DDSCAPS_3DDEVICE | DDSCAPS_COMPLEX; if (m_bOnlySystemMemory) { - ddsd.ddsCaps.dwCaps = - DDSCAPS_PRIMARYSURFACE | DDSCAPS_FLIP | DDSCAPS_3DDEVICE | DDSCAPS_COMPLEX | DDSCAPS_SYSTEMMEMORY; + ddsd.ddsCaps.dwCaps |= DDSCAPS_SYSTEMMEMORY; } ddsd.dwBackBufferCount = 1; - result = CreateDDSurface(&ddsd, &m_pFrontBuffer, 0); + result = CreateDDSurface(&ddsd, &m_pFrontBuffer, NULL); if (result != DD_OK) { Error("CreateSurface for front/back fullScreen buffer failed", result); return FALSE; } - ddscaps.dwCaps = DDSCAPS_BACKBUFFER; result = m_pFrontBuffer->GetAttachedSurface(&ddscaps, &m_pBackBuffer); if (result != DD_OK) { @@ -497,8 +473,8 @@ BOOL MxDirectDraw::DDCreateSurfaces() } } else { - memset(&ddsd, 0, sizeof(ddsd)); - ddsd.dwSize = sizeof(ddsd); + memset(&ddsd, 0, sizeof(DDSURFACEDESC)); + ddsd.dwSize = sizeof(DDSURFACEDESC); ddsd.dwFlags = DDSD_CAPS; ddsd.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE; result = CreateDDSurface(&ddsd, &m_pFrontBuffer, NULL); @@ -506,19 +482,18 @@ BOOL MxDirectDraw::DDCreateSurfaces() Error("CreateSurface for window front buffer failed", result); return FALSE; } + ddsd.dwFlags = DDSD_WIDTH | DDSD_HEIGHT | DDSD_CAPS; ddsd.dwHeight = m_currentMode.height; ddsd.dwWidth = m_currentMode.width; - ddsd.dwFlags = DDSD_WIDTH | DDSD_HEIGHT | DDSD_CAPS; ddsd.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN | DDSCAPS_3DDEVICE; if (m_bOnlySystemMemory) { - ddsd.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN | DDSCAPS_3DDEVICE | DDSCAPS_SYSTEMMEMORY; + ddsd.ddsCaps.dwCaps |= DDSCAPS_SYSTEMMEMORY; } result = CreateDDSurface(&ddsd, &m_pBackBuffer, NULL); if (result != DD_OK) { Error("CreateSurface for window back buffer failed", result); return FALSE; } - if (!GetDDSurfaceDesc(&ddsd, m_pBackBuffer)) { return FALSE; } @@ -590,7 +565,7 @@ BOOL MxDirectDraw::TextToTextSurface(const char* text, IDirectDrawSurface* pSurf RECT rc; size_t textLength; - if (pSurface == NULL) { + if (!pSurface) { return FALSE; } @@ -632,15 +607,14 @@ BOOL MxDirectDraw::CreateTextSurfaces() HRESULT result; DDCOLORKEY ddck; DDSURFACEDESC ddsd; - HDC dc; + HDC hdc; char dummyinfo[] = "000x000x00 (RAMP) 0000"; char dummyfps[] = "000.00 fps (000.00 fps (000.00 fps) 00000 tps)"; if (m_hFont != NULL) { DeleteObject(m_hFont); } - - m_hFont = CreateFontA( + m_hFont = CreateFont( m_currentMode.width <= 600 ? 12 : 24, 0, 0, @@ -657,28 +631,26 @@ BOOL MxDirectDraw::CreateTextSurfaces() "Arial" ); - dc = GetDC(NULL); - SelectObject(dc, m_hFont); - GetTextExtentPointA(dc, dummyfps, strlen(dummyfps), &m_text1SizeOnSurface); - GetTextExtentPointA(dc, dummyinfo, strlen(dummyinfo), &m_text2SizeOnSurface); - ReleaseDC(NULL, dc); + hdc = GetDC(NULL); + SelectObject(hdc, m_hFont); + GetTextExtentPoint(hdc, dummyfps, strlen(dummyfps), &m_text1SizeOnSurface); + GetTextExtentPoint(hdc, dummyinfo, strlen(dummyinfo), &m_text2SizeOnSurface); + ReleaseDC(NULL, hdc); memset(&ddsd, 0, sizeof(ddsd)); ddsd.dwSize = sizeof(ddsd); ddsd.dwFlags = DDSD_CAPS | DDSD_HEIGHT | DDSD_WIDTH; ddsd.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN; if (m_bOnlySystemMemory) { - ddsd.ddsCaps.dwCaps = DDSCAPS_SYSTEMMEMORY | DDSCAPS_OFFSCREENPLAIN; + ddsd.ddsCaps.dwCaps |= DDSCAPS_SYSTEMMEMORY; } ddsd.dwHeight = m_text1SizeOnSurface.cy; ddsd.dwWidth = m_text1SizeOnSurface.cx; - - result = CreateDDSurface(&ddsd, &m_pText1Surface, 0); + result = CreateDDSurface(&ddsd, &m_pText1Surface, NULL); if (result != DD_OK) { Error("CreateSurface for text surface 1 failed", result); return FALSE; } - memset(&ddck, 0, sizeof(ddck)); m_pText1Surface->SetColorKey(DDCKEY_SRCBLT, &ddck); if (!TextToTextSurface1(dummyfps)) { @@ -690,17 +662,15 @@ BOOL MxDirectDraw::CreateTextSurfaces() ddsd.dwFlags = DDSD_CAPS | DDSD_HEIGHT | DDSD_WIDTH; ddsd.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN; if (m_bOnlySystemMemory) { - ddsd.ddsCaps.dwCaps = DDSCAPS_SYSTEMMEMORY | DDSCAPS_OFFSCREENPLAIN; + ddsd.ddsCaps.dwCaps |= DDSCAPS_SYSTEMMEMORY; } ddsd.dwHeight = m_text2SizeOnSurface.cy; ddsd.dwWidth = m_text2SizeOnSurface.cx; - - result = CreateDDSurface(&ddsd, &m_pText2Surface, 0); + result = CreateDDSurface(&ddsd, &m_pText2Surface, NULL); if (result != DD_OK) { Error("CreateSurface for text surface 2 failed", result); return FALSE; } - memset(&ddck, 0, sizeof(ddck)); m_pText2Surface->SetColorKey(DDCKEY_SRCBLT, &ddck); if (!TextToTextSurface2(dummyinfo)) { @@ -777,13 +747,13 @@ BOOL MxDirectDraw::CreateZBuffer(DWORD memorytype, DWORD depth) memset(&ddsd, 0, sizeof(ddsd)); ddsd.dwSize = sizeof(ddsd); + ddsd.dwFlags = DDSD_WIDTH | DDSD_HEIGHT | DDSD_CAPS | DDSD_ZBUFFERBITDEPTH; ddsd.dwHeight = m_currentMode.height; ddsd.dwWidth = m_currentMode.width; ddsd.dwZBufferBitDepth = depth; - ddsd.dwFlags = DDSD_WIDTH | DDSD_HEIGHT | DDSD_CAPS | DDSD_ZBUFFERBITDEPTH; ddsd.ddsCaps.dwCaps = DDSCAPS_ZBUFFER | memorytype; - result = CreateDDSurface(&ddsd, &lpZBuffer, 0); + if (result != DD_OK) { Error("CreateSurface for fullScreen Z-buffer failed", result); return FALSE; @@ -800,10 +770,10 @@ BOOL MxDirectDraw::CreateZBuffer(DWORD memorytype, DWORD depth) } // FUNCTION: LEGO1 0x1009e6a0 -int MxDirectDraw::Pause(int p_increment) +int MxDirectDraw::Pause(BOOL p_pause) { - if (p_increment) { - m_pauseCount++; + if (p_pause) { + ++m_pauseCount; if (m_pauseCount > 1) { return TRUE; @@ -823,11 +793,13 @@ int MxDirectDraw::Pause(int p_increment) } } else { - m_pauseCount--; + --m_pauseCount; + if (m_pauseCount > 0) { return TRUE; } - else if (m_pauseCount < 0) { + + if (m_pauseCount < 0) { m_pauseCount = 0; } @@ -842,11 +814,13 @@ int MxDirectDraw::Pause(int p_increment) // FUNCTION: LEGO1 0x1009e750 BOOL MxDirectDraw::RestorePaletteEntries() { - HRESULT result; if (m_bFullScreen && m_bPrimaryPalettized) { if (m_pPalette) { - result = m_pPalette->SetEntries(0, 0, _countof(m_paletteEntries), m_paletteEntries); + HRESULT result; + + result = + m_pPalette->SetEntries(0, 0, sizeof(m_paletteEntries) / sizeof(m_paletteEntries[0]), m_paletteEntries); if (result != DD_OK) { Error("SetEntries failed", result); return FALSE; @@ -860,11 +834,16 @@ BOOL MxDirectDraw::RestorePaletteEntries() // FUNCTION: LEGO1 0x1009e7a0 BOOL MxDirectDraw::RestoreOriginalPaletteEntries() { - HRESULT result; - if (m_bPrimaryPalettized) { if (m_pPalette) { - result = m_pPalette->SetEntries(0, 0, 256, m_originalPaletteEntries); + HRESULT result; + + result = m_pPalette->SetEntries( + 0, + 0, + sizeof(m_originalPaletteEntries) / sizeof(m_originalPaletteEntries[0]), + m_originalPaletteEntries + ); if (result != DD_OK) { Error("SetEntries failed", result); return FALSE; @@ -878,17 +857,18 @@ BOOL MxDirectDraw::RestoreOriginalPaletteEntries() // FUNCTION: LEGO1 0x1009e7f0 int MxDirectDraw::FlipToGDISurface() { - HRESULT ret; if (m_pDirectDraw) { - ret = m_pDirectDraw->FlipToGDISurface(); - if (ret != DD_OK) { - Error("FlipToGDISurface failed", ret); + HRESULT result; + + result = m_pDirectDraw->FlipToGDISurface(); + if (result != DD_OK) { + Error("FlipToGDISurface failed", result); } - return !ret; + return (result == DD_OK); } - return 1; + return TRUE; } // FUNCTION: LEGO1 0x1009e830 diff --git a/LEGO1/mxdirectx/mxdirectdraw.h b/LEGO1/mxdirectx/mxdirectdraw.h index e082c2d4..61c92ae0 100644 --- a/LEGO1/mxdirectx/mxdirectdraw.h +++ b/LEGO1/mxdirectx/mxdirectdraw.h @@ -34,9 +34,7 @@ class MxDirectDraw { void* m_unk0x178; // 0x178 }; - int FlipToGDISurface(); static int GetPrimaryBitDepth(); - int Pause(int); MxDirectDraw(); virtual ~MxDirectDraw(); @@ -51,38 +49,50 @@ class MxDirectDraw { int bpp, const PALETTEENTRY* pPaletteEntries, int paletteEntryCount - ); // vtable+0x04 - virtual void Destroy(); // vtable+0x08 - virtual void DestroyButNotDirectDraw(); // vtable+0x0c - virtual const char* ErrorToString(HRESULT p_error); // vtable+0x10 + ); // vtable+0x04 + virtual void Destroy(); // vtable+0x08 + virtual void DestroyButNotDirectDraw(); // vtable+0x0c - BOOL CacheOriginalPaletteEntries(); - HRESULT CreateDDSurface(LPDDSURFACEDESC a2, LPDIRECTDRAWSURFACE* a3, IUnknown* a4); - BOOL CreateTextSurfaces(); - BOOL CreateZBuffer(DWORD memorytype, DWORD depth); - BOOL DDCreateSurfaces(); - BOOL DDInit(BOOL fullscreen); - BOOL DDSetMode(int width, int height, int bpp); - void Error(const char* p_message, int p_error); + inline IDirectDraw* DirectDraw() { return m_pDirectDraw; } + inline IDirectDrawSurface* FrontBuffer() { return m_pFrontBuffer; } + inline IDirectDrawSurface* BackBuffer() { return m_pBackBuffer; } + inline IDirectDrawClipper* Clipper() { return m_pClipper; } + + BOOL IsFullScreen() { return m_bFullScreen; } - BOOL GetDDSurfaceDesc(LPDDSURFACEDESC lpDDSurfDesc, LPDIRECTDRAWSURFACE lpDDSurf); BOOL IsSupportedMode(int width, int height, int bpp); - BOOL RecreateDirectDraw(GUID** a2); - BOOL RestoreOriginalPaletteEntries(); - BOOL RestorePaletteEntries(); + + int Pause(BOOL); BOOL RestoreSurfaces(); - BOOL SetPaletteEntries(const PALETTEENTRY* pPaletteEntries, int paletteEntryCount, BOOL fullscreen); - BOOL TextToTextSurface(const char* text, IDirectDrawSurface* pSurface, SIZE& textSizeOnSurface); + BOOL TextToTextSurface1(const char* text); BOOL TextToTextSurface2(const char* lpString); + + virtual const char* ErrorToString(HRESULT p_error); // vtable+0x10 + int FlipToGDISurface(); + +protected: + BOOL SetPaletteEntries(const PALETTEENTRY* pPaletteEntries, int paletteEntryCount, BOOL fullscreen); + BOOL CacheOriginalPaletteEntries(); + BOOL RestoreOriginalPaletteEntries(); + BOOL RestorePaletteEntries(); + + BOOL DDInit(BOOL fullscreen); + BOOL DDSetMode(int width, int height, int bpp); + BOOL DDCreateSurfaces(); + HRESULT CreateDDSurface(LPDDSURFACEDESC a2, LPDIRECTDRAWSURFACE* a3, IUnknown* a4); + BOOL GetDDSurfaceDesc(LPDDSURFACEDESC lpDDSurfDesc, LPDIRECTDRAWSURFACE lpDDSurf); + BOOL CreateZBuffer(DWORD memorytype, DWORD depth); + + BOOL CreateTextSurfaces(); + BOOL TextToTextSurface(const char* text, IDirectDrawSurface* pSurface, SIZE& textSizeOnSurface); + + void Error(const char* p_message, int p_error); + + BOOL RecreateDirectDraw(GUID** a2); void FUN_1009e020(); void FUN_1009d920(); - inline IDirectDraw* GetDirectDraw() { return m_pDirectDraw; } - inline IDirectDrawSurface* GetFrontBuffer() { return m_pFrontBuffer; } - inline IDirectDrawSurface* GetBackBuffer() { return m_pBackBuffer; } - inline IDirectDrawClipper* GetClipper() { return m_pClipper; } - // SYNTHETIC: LEGO1 0x1009d510 // MxDirectDraw::`scalar deleting destructor'