From 5ee268a36c97c84e306fdd3b377b0b15a8741cb8 Mon Sep 17 00:00:00 2001 From: Christian Semmler Date: Wed, 3 Jan 2024 12:50:25 -0500 Subject: [PATCH] Implement/match device enumeration (#397) * Implement/match device enumeration * Update skip --- LEGO1/mxdirect3d.cpp | 106 +++++++++++++++++++++++++++++++++++++------ LEGO1/mxdirect3d.h | 85 +++++++++++++++++++++++++--------- tools/ncc/skip.yml | 4 ++ 3 files changed, 160 insertions(+), 35 deletions(-) diff --git a/LEGO1/mxdirect3d.cpp b/LEGO1/mxdirect3d.cpp index eb81b419..974c5654 100644 --- a/LEGO1/mxdirect3d.cpp +++ b/LEGO1/mxdirect3d.cpp @@ -4,8 +4,8 @@ DECOMP_SIZE_ASSERT(MxDeviceModeFinder, 0xe4); DECOMP_SIZE_ASSERT(MxDirect3D, 0x894); -DECOMP_SIZE_ASSERT(MxDeviceEnumerate0x178Element, 0x1a4); -DECOMP_SIZE_ASSERT(MxDeviceDisplayMode, 0x0c); +DECOMP_SIZE_ASSERT(MxDevice, 0x1a4); +DECOMP_SIZE_ASSERT(MxDisplayMode, 0x0c); DECOMP_SIZE_ASSERT(MxDeviceEnumerateElement, 0x190); DECOMP_SIZE_ASSERT(MxDeviceEnumerate, 0x14); @@ -162,10 +162,8 @@ MxDeviceEnumerateElement::~MxDeviceEnumerateElement() { if (m_guid) delete m_guid; - if (m_driverDesc) delete[] m_driverDesc; - if (m_driverName) delete[] m_driverName; } @@ -199,6 +197,72 @@ void MxDeviceEnumerateElement::Init(LPGUID p_guid, LPSTR p_driverDesc, LPSTR p_d } } +// FUNCTION: LEGO1 0x1009bd20 +MxDevice::MxDevice( + LPGUID p_guid, + LPSTR p_deviceDesc, + LPSTR p_deviceName, + LPD3DDEVICEDESC p_HWDesc, + LPD3DDEVICEDESC p_HELDesc +) +{ + memset(this, 0, sizeof(*this)); + + Init(p_guid, p_deviceDesc, p_deviceName, p_HWDesc, p_HELDesc); +} + +// FUNCTION: LEGO1 0x1009bd60 +MxDevice::~MxDevice() +{ + if (m_guid) + delete m_guid; + if (m_deviceDesc) + delete[] m_deviceDesc; + if (m_deviceName) + delete[] m_deviceName; +} + +// FUNCTION: LEGO1 0x1009bda0 +void MxDevice::Init( + LPGUID p_guid, + LPSTR p_deviceDesc, + LPSTR p_deviceName, + LPD3DDEVICEDESC p_HWDesc, + LPD3DDEVICEDESC p_HELDesc +) +{ + if (m_deviceDesc) { + delete[] m_deviceDesc; + m_deviceDesc = NULL; + } + + if (m_deviceName) { + delete[] m_deviceName; + m_deviceName = NULL; + } + + if (p_guid) { + m_guid = new GUID; + memcpy(m_guid, p_guid, sizeof(*m_guid)); + } + + if (p_deviceDesc) { + m_deviceDesc = new char[strlen(p_deviceDesc) + 1]; + strcpy(m_deviceDesc, p_deviceDesc); + } + + if (p_deviceName) { + m_deviceName = new char[strlen(p_deviceName) + 1]; + strcpy(m_deviceName, p_deviceName); + } + + if (p_HWDesc) + memcpy(&m_HWDesc, p_HWDesc, sizeof(m_HWDesc)); + + if (p_HELDesc) + memcpy(&m_HELDesc, p_HELDesc, sizeof(m_HELDesc)); +} + // FUNCTION: LEGO1 0x1009bec0 MxDeviceEnumerate::MxDeviceEnumerate() { @@ -243,7 +307,7 @@ BOOL MxDeviceEnumerate::EnumDirectDrawCallback(LPGUID p_guid, LPSTR p_driverDesc if (result != DD_OK) BuildErrorString("D3D enum devices failed: %s\n", EnumerateErrorToString(result)); else { - if (newDevice.m_unk0x178.empty()) { + if (newDevice.m_devices.empty()) { m_list.pop_back(); } } @@ -280,23 +344,24 @@ HRESULT CALLBACK MxDeviceEnumerate::DisplayModesEnumerateCallback(LPDDSURFACEDES return deviceEnumerate->EnumDisplayModesCallback(p_ddsd); } -// STUB: LEGO1 0x1009c510 +// FUNCTION: LEGO1 0x1009c510 HRESULT CALLBACK MxDeviceEnumerate::DevicesEnumerateCallback( - LPGUID p_lpGuid, - LPSTR p_lpDeviceDescription, - LPSTR p_lpDeviceName, - LPD3DDEVICEDESC p_pHWDesc, - LPD3DDEVICEDESC p_pHELDesc, + LPGUID p_guid, + LPSTR p_deviceDesc, + LPSTR p_deviceName, + LPD3DDEVICEDESC p_HWDesc, + LPD3DDEVICEDESC p_HELDesc, LPVOID p_context ) { - return TRUE; + MxDeviceEnumerate* deviceEnumerate = (MxDeviceEnumerate*) p_context; + return deviceEnumerate->EnumDevicesCallback(p_guid, p_deviceDesc, p_deviceName, p_HWDesc, p_HELDesc); } // FUNCTION: LEGO1 0x1009c540 HRESULT MxDeviceEnumerate::EnumDisplayModesCallback(LPDDSURFACEDESC p_ddsd) { - MxDeviceDisplayMode displayMode; + MxDisplayMode displayMode; displayMode.m_width = p_ddsd->dwWidth; displayMode.m_height = p_ddsd->dwHeight; displayMode.m_bitsPerPixel = p_ddsd->ddpfPixelFormat.dwRGBBitCount; @@ -305,6 +370,21 @@ HRESULT MxDeviceEnumerate::EnumDisplayModesCallback(LPDDSURFACEDESC p_ddsd) return DDENUMRET_OK; } +// FUNCTION: LEGO1 0x1009c5d0 +HRESULT MxDeviceEnumerate::EnumDevicesCallback( + LPGUID p_guid, + LPSTR p_deviceDesc, + LPSTR p_deviceName, + LPD3DDEVICEDESC p_HWDesc, + LPD3DDEVICEDESC p_HELDesc +) +{ + MxDevice 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; +} + // FUNCTION: LEGO1 0x1009c6c0 MxResult MxDeviceEnumerate::DoEnumerate() { diff --git a/LEGO1/mxdirect3d.h b/LEGO1/mxdirect3d.h index d226a12d..ca16cd89 100644 --- a/LEGO1/mxdirect3d.h +++ b/LEGO1/mxdirect3d.h @@ -58,21 +58,43 @@ class MxDirect3D : public MxDirectDraw { }; // SIZE 0x1a4 -struct MxDeviceEnumerate0x178Element { - undefined m_unk0x00[0x1a4]; // 0x00 +struct MxDevice { + MxDevice() {} + ~MxDevice(); + MxDevice( + LPGUID p_guid, + LPSTR p_deviceDesc, + LPSTR p_deviceName, + LPD3DDEVICEDESC p_HWDesc, + LPD3DDEVICEDESC p_HELDesc + ); - MxBool operator==(MxDeviceEnumerate0x178Element) const { return TRUE; } - MxBool operator<(MxDeviceEnumerate0x178Element) const { return TRUE; } + void Init( + LPGUID p_guid, + LPSTR p_deviceDesc, + LPSTR p_deviceName, + LPD3DDEVICEDESC p_HWDesc, + LPD3DDEVICEDESC p_HELDesc + ); + + LPGUID m_guid; // 0x00 + char* m_deviceDesc; // 0x04 + char* m_deviceName; // 0x08 + D3DDEVICEDESC m_HWDesc; // 0x0c + D3DDEVICEDESC m_HELDesc; // 0xd8 + + MxBool operator==(MxDevice) const { return TRUE; } + MxBool operator<(MxDevice) const { return TRUE; } }; // SIZE 0x0c -struct MxDeviceDisplayMode { +struct MxDisplayMode { DWORD m_width; // 0x00 DWORD m_height; // 0x04 DWORD m_bitsPerPixel; // 0x08 - MxBool operator==(MxDeviceDisplayMode) const { return TRUE; } - MxBool operator<(MxDeviceDisplayMode) const { return TRUE; } + MxBool operator==(MxDisplayMode) const { return TRUE; } + MxBool operator<(MxDisplayMode) const { return TRUE; } }; // SIZE 0x190 @@ -83,12 +105,12 @@ struct MxDeviceEnumerateElement { void Init(LPGUID p_guid, LPSTR p_driverDesc, LPSTR p_driverName); - LPGUID m_guid; // 0x00 - char* m_driverDesc; // 0x04 - char* m_driverName; // 0x08 - DDCAPS m_ddCaps; // 0x0c - list m_unk0x178; // 0x178 - list m_displayModes; // 0x184 + LPGUID m_guid; // 0x00 + char* m_driverDesc; // 0x04 + char* m_driverName; // 0x08 + DDCAPS m_ddCaps; // 0x0c + list m_devices; // 0x178 + list m_displayModes; // 0x184 MxBool operator==(MxDeviceEnumerateElement) const { return TRUE; } MxBool operator<(MxDeviceEnumerateElement) const { return TRUE; } @@ -96,21 +118,31 @@ struct MxDeviceEnumerateElement { // clang-format off // TEMPLATE: LEGO1 0x1009b900 -// list >::~list > +// list >::~list > // clang-format on // clang-format off // TEMPLATE: LEGO1 0x1009b970 -// list >::~list > +// list >::~list > // clang-format on // TEMPLATE: LEGO1 0x1009b9e0 -// List::~List +// List::~List // TEMPLATE: LEGO1 0x1009ba30 -// List::~List +// List::~List + +// clang-format off +// TEMPLATE: LEGO1 0x1009bf50 +// list >::~list > +// clang-format on + +// TEMPLATE: LEGO1 0x1009bfc0 +// List::~List // Compiler-generated copy ctor +// Part of this function are two more synthetic sub-routines, +// LEGO1 0x1009c400 and LEGO1 0x1009c460 // SYNTHETIC: LEGO1 0x1009c290 // MxDeviceEnumerateElement::MxDeviceEnumerateElement @@ -119,11 +151,20 @@ struct MxDeviceEnumerateElement { class MxDeviceEnumerate { public: MxDeviceEnumerate(); + // FUNCTION: LEGO1 0x1009c010 + ~MxDeviceEnumerate() {} virtual MxResult DoEnumerate(); // vtable+0x00 BOOL EnumDirectDrawCallback(LPGUID p_guid, LPSTR p_driverDesc, LPSTR p_driverName); HRESULT EnumDisplayModesCallback(LPDDSURFACEDESC p_ddsd); + HRESULT EnumDevicesCallback( + LPGUID p_guid, + LPSTR p_deviceDesc, + LPSTR p_deviceName, + LPD3DDEVICEDESC p_HWDesc, + LPD3DDEVICEDESC p_HELDesc + ); const char* EnumerateErrorToString(HRESULT p_error); MxS32 ParseDeviceName(const char* p_deviceId); MxResult FUN_1009d030(MxS32 p_und1, undefined** p_und2, undefined** p_und3); @@ -135,11 +176,11 @@ class MxDeviceEnumerate { DirectDrawEnumerateCallback(LPGUID p_guid, LPSTR p_driverDesc, LPSTR p_driverName, LPVOID p_context); static HRESULT CALLBACK DisplayModesEnumerateCallback(LPDDSURFACEDESC p_ddsd, LPVOID p_context); static HRESULT CALLBACK DevicesEnumerateCallback( - LPGUID p_lpGuid, - LPSTR p_lpDeviceDescription, - LPSTR p_lpDeviceName, - LPD3DDEVICEDESC p_pHWDesc, - LPD3DDEVICEDESC p_pHELDesc, + LPGUID p_guid, + LPSTR p_deviceDesc, + LPSTR p_deviceName, + LPD3DDEVICEDESC p_HWDesc, + LPD3DDEVICEDESC p_HELDesc, LPVOID p_context ); diff --git a/tools/ncc/skip.yml b/tools/ncc/skip.yml index 75a186ca..fa8546d9 100644 --- a/tools/ncc/skip.yml +++ b/tools/ncc/skip.yml @@ -8,6 +8,10 @@ GetNoCD_SourceName(): 'DLL exported function' m_3dView: 'Allow this variable name' m_3dManager: 'Allow this variable name' m_16bitPal: 'Allow this variable name' +m_HWDesc: 'Allow this variable name' +m_HELDesc: 'Allow this variable name' +p_HWDesc: 'Allow this variable name' +p_HELDesc: 'Allow this variable name' p_milliseconds: 'Probably a bug with function call' m_increaseAmount: "Can't currently detect member in union" m_increaseFactor: "Can't currently detect member in union"