From 778b0f21088729321f8182f298c7669e8a772865 Mon Sep 17 00:00:00 2001 From: Christian Semmler Date: Wed, 3 Jan 2024 15:53:21 -0500 Subject: [PATCH] Implement/match MxDeviceEnumerate::ParseDeviceName and ProcessDeviceBytes (#398) * WIP * WIP * WIP * WIP * WIP * WIP --- LEGO1/mxdirect3d.cpp | 70 +++++++++++++++++++++++++++++++++++++++++--- LEGO1/mxdirect3d.h | 3 +- util/compat.h | 3 +- 3 files changed, 70 insertions(+), 6 deletions(-) diff --git a/LEGO1/mxdirect3d.cpp b/LEGO1/mxdirect3d.cpp index 974c5654..fae5e38e 100644 --- a/LEGO1/mxdirect3d.cpp +++ b/LEGO1/mxdirect3d.cpp @@ -266,7 +266,7 @@ void MxDevice::Init( // FUNCTION: LEGO1 0x1009bec0 MxDeviceEnumerate::MxDeviceEnumerate() { - m_unk0x10 = FALSE; + m_initialized = FALSE; } // FUNCTION: LEGO1 0x1009c070 @@ -388,7 +388,7 @@ HRESULT MxDeviceEnumerate::EnumDevicesCallback( // FUNCTION: LEGO1 0x1009c6c0 MxResult MxDeviceEnumerate::DoEnumerate() { - if (m_unk0x10) + if (m_initialized) return FAILURE; HRESULT ret = DirectDrawEnumerate(DirectDrawEnumerateCallback, this); @@ -397,7 +397,7 @@ MxResult MxDeviceEnumerate::DoEnumerate() return FAILURE; } - m_unk0x10 = TRUE; + m_initialized = TRUE; return SUCCESS; } @@ -418,9 +418,71 @@ const char* MxDeviceEnumerate::EnumerateErrorToString(HRESULT p_error) return ""; } -// STUB: LEGO1 0x1009ce60 +// FUNCTION: LEGO1 0x1009ce60 MxS32 MxDeviceEnumerate::ParseDeviceName(const char* p_deviceId) { + if (!m_initialized) + return -1; + + MxS32 num = -1; + MxS32 hex[4]; + + if (sscanf(p_deviceId, "%d 0x%x 0x%x 0x%x 0x%x", &num, &hex[0], &hex[1], &hex[2], &hex[3]) != 5) + return -1; + + if (num < 0) + return -1; + + GUID guid; + memcpy(&guid, hex, sizeof(guid)); + + MxS32 result = ProcessDeviceBytes(num, guid); + + if (result < 0) + return ProcessDeviceBytes(-1, guid); + return result; +} + +// FUNCTION: LEGO1 0x1009cf20 +MxS32 MxDeviceEnumerate::ProcessDeviceBytes(MxS32 p_num, GUID& p_guid) +{ + if (!m_initialized) + return -1; + + MxS32 i = 0; + MxS32 j = 0; + + struct GUID4 { + MxS32 m_data1; + MxS32 m_data2; + MxS32 m_data3; + MxS32 m_data4; + }; + + static_assert(sizeof(GUID4) == sizeof(GUID), "Equal size"); + + GUID4 deviceGuid; + memcpy(&deviceGuid, &p_guid, sizeof(GUID4)); + + for (list::iterator it = m_list.begin(); it != m_list.end(); it++) { + if (p_num >= 0 && p_num < i) + return -1; + + GUID4 compareGuid; + MxDeviceEnumerateElement& elem = *it; + for (list::iterator it2 = elem.m_devices.begin(); it2 != elem.m_devices.end(); it2++) { + memcpy(&compareGuid, (*it2).m_guid, sizeof(GUID4)); + + if (compareGuid.m_data1 == deviceGuid.m_data1 && compareGuid.m_data2 == deviceGuid.m_data2 && + compareGuid.m_data3 == deviceGuid.m_data3 && compareGuid.m_data4 == deviceGuid.m_data4 && i == p_num) + return j; + + j++; + } + + i++; + } + return -1; } diff --git a/LEGO1/mxdirect3d.h b/LEGO1/mxdirect3d.h index ca16cd89..fb9d5618 100644 --- a/LEGO1/mxdirect3d.h +++ b/LEGO1/mxdirect3d.h @@ -167,6 +167,7 @@ class MxDeviceEnumerate { ); const char* EnumerateErrorToString(HRESULT p_error); MxS32 ParseDeviceName(const char* p_deviceId); + MxS32 ProcessDeviceBytes(MxS32 p_num, GUID& p_guid); MxResult FUN_1009d030(MxS32 p_und1, undefined** p_und2, undefined** p_und3); MxResult FUN_1009d0d0(); MxResult FUN_1009d210(); @@ -186,7 +187,7 @@ class MxDeviceEnumerate { private: list m_list; // 0x04 - MxBool m_unk0x10; // 0x10 + MxBool m_initialized; // 0x10 }; // VTABLE: LEGO1 0x100d9cc8 diff --git a/util/compat.h b/util/compat.h index c1175cd2..e83b115e 100644 --- a/util/compat.h +++ b/util/compat.h @@ -21,8 +21,9 @@ // We use `override` so newer compilers can tell us our vtables are valid, // however this keyword was added in C++11, so we define it as empty for // compatibility with older compilers. -#if defined(_MSC_VER) && _MSC_VER <= 1200 // 1200 corresponds to VC6.0 but "override" was probably added even later +#if __cplusplus < 201103L #define override +#define static_assert(expr, msg) #endif #endif // COMPAT_H