From 877c278ce9d93bdbd64cab8bf20fcfbe37e18171 Mon Sep 17 00:00:00 2001 From: Joshua Peisach Date: Sat, 31 May 2025 18:33:38 -0400 Subject: [PATCH] start porting config from mfc to qt --- CMakeLists.txt | 7 +++- CONFIG/AboutDlg.cpp | 10 +++-- CONFIG/AboutDlg.h | 6 +-- CONFIG/StdAfx.h | 4 +- CONFIG/config.h | 3 +- CONFIG/detectdx5.cpp | 92 +++++++++++++++++++++++--------------------- 6 files changed, 68 insertions(+), 54 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index bd311e42..a5c93889 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -491,7 +491,9 @@ if (ISLE_BUILD_APP) endif() if (ISLE_BUILD_CONFIG) - add_executable(config WIN32 + find_package(Qt6 REQUIRED COMPONENTS Core Widgets) + qt_standard_project_setup() + qt_add_executable(config LEGO1/mxdirectx/mxdirectxinfo.cpp LEGO1/mxdirectx/legodxinfo.cpp CONFIG/config.cpp @@ -503,7 +505,8 @@ if (ISLE_BUILD_CONFIG) CONFIG/res/config.rc ) if (ISLE_MINIWIN) - target_link_libraries(config PRIVATE minimfc) + target_link_libraries(config PRIVATE minimfc) + target_link_libraries(config PRIVATE Qt6::Core Qt6::Widgets) endif() list(APPEND isle_targets config) target_compile_definitions(config PRIVATE _AFXDLL MXDIRECTX_FOR_CONFIG) diff --git a/CONFIG/AboutDlg.cpp b/CONFIG/AboutDlg.cpp index 9585d1c1..186145dc 100644 --- a/CONFIG/AboutDlg.cpp +++ b/CONFIG/AboutDlg.cpp @@ -6,14 +6,16 @@ DECOMP_SIZE_ASSERT(CDialog, 0x60) DECOMP_SIZE_ASSERT(CAboutDialog, 0x60) // FUNCTION: CONFIG 0x00403c20 -CAboutDialog::CAboutDialog() : CDialog(IDD) +CAboutDialog::CAboutDialog() : QDialog() { } // FUNCTION: CONFIG 0x00403d20 +/* void CAboutDialog::DoDataExchange(CDataExchange* pDX) { -} +*/ +//} -BEGIN_MESSAGE_MAP(CAboutDialog, CDialog) -END_MESSAGE_MAP() +/*BEGIN_MESSAGE_MAP(CAboutDialog, CDialog)*/ +/*END_MESSAGE_MAP()*/ diff --git a/CONFIG/AboutDlg.h b/CONFIG/AboutDlg.h index dc648d63..a6d0cdef 100644 --- a/CONFIG/AboutDlg.h +++ b/CONFIG/AboutDlg.h @@ -7,7 +7,7 @@ // VTABLE: CONFIG 0x00406308 // SIZE 0x60 -class CAboutDialog : public CDialog { +class CAboutDialog : public QDialog { public: CAboutDialog(); enum { @@ -15,10 +15,10 @@ class CAboutDialog : public CDialog { }; protected: - void DoDataExchange(CDataExchange* pDX) override; + /*void DoDataExchange(CDataExchange* pDX) override;*/ protected: - DECLARE_MESSAGE_MAP() + /*DECLARE_MESSAGE_MAP()*/ }; // SYNTHETIC: CONFIG 0x00403cb0 diff --git a/CONFIG/StdAfx.h b/CONFIG/StdAfx.h index a411b312..b46ebbcf 100644 --- a/CONFIG/StdAfx.h +++ b/CONFIG/StdAfx.h @@ -4,7 +4,9 @@ #define VC_EXTRALEAN // Exclude rarely-used stuff from Windows headers #ifdef MINIMFC -#include "miniwin/mfc.h" +/*#include "miniwin/mfc.h"*/ +#include +#include #else #include // MFC extensions #include // MFC core and standard components diff --git a/CONFIG/config.h b/CONFIG/config.h index bcc02cc5..05c945e9 100644 --- a/CONFIG/config.h +++ b/CONFIG/config.h @@ -1,6 +1,7 @@ #if !defined(AFX_CONFIG_H) #define AFX_CONFIG_H +#include "AboutDlg.h" #include "StdAfx.h" #include "compat.h" #include "decomp.h" @@ -19,7 +20,7 @@ struct MxDriver; // VTABLE: CONFIG 0x00406040 // SIZE 0x108 -class CConfigApp : public CWinApp { +class CConfigApp : public QApplication { public: CConfigApp(); diff --git a/CONFIG/detectdx5.cpp b/CONFIG/detectdx5.cpp index bf9f6f61..d767e775 100644 --- a/CONFIG/detectdx5.cpp +++ b/CONFIG/detectdx5.cpp @@ -3,12 +3,15 @@ #ifdef MINIWIN #include "miniwin/ddraw.h" #include "miniwin/dinput.h" -#include "miniwin/mfc.h" +#include "qoperatingsystemversion.h" +#include "qlibrary.h" #else #include #include #endif +typedef struct IUnknown* LPUNKNOWN; + typedef HRESULT WINAPI DirectDrawCreate_fn(GUID FAR* lpGUID, LPDIRECTDRAW FAR* lplpDD, IUnknown FAR* pUnkOuter); typedef HRESULT WINAPI DirectInputCreateA_fn(HINSTANCE hinst, DWORD dwVersion, LPDIRECTINPUTA* ppDI, LPUNKNOWN punkOuter); @@ -25,93 +28,96 @@ BOOL DetectDirectX5() // FUNCTION: CONFIG 0x00404920 void DetectDirectX(unsigned int* p_version, BOOL* p_found) { - OSVERSIONINFOA os_version; + QOperatingSystemVersion os_version = QOperatingSystemVersion::current(); - os_version.dwOSVersionInfoSize = sizeof(os_version); - if (!GetVersionEx(&os_version)) { + if (os_version.type() == QOperatingSystemVersion::Unknown) { *p_version = 0; *p_found = 0; return; } - if (os_version.dwPlatformId == 2) { + if (os_version.type() == QOperatingSystemVersion::Windows) { *p_found = 2; - if (os_version.dwMajorVersion < 4) { + if (os_version.majorVersion() < 4) { *p_found = 0; return; } - if (os_version.dwMajorVersion != 4) { + if (os_version.majorVersion() != 4) { *p_version = 0x501; return; } *p_version = 0x200; - HMODULE dinput_module = LoadLibrary("DINPUT.DLL"); - if (!dinput_module) { - OutputDebugString("Couldn't LoadLibrary DInput\r\n"); + QLibrary dinput_module("DINPUT.DLL"); + dinput_module.load(); + if (!dinput_module.isLoaded()) { + QT_DEBUG("Couldn't LoadLibrary DInput\r\n"); return; } DirectInputCreateA_fn* func_DirectInputCreateA = - (DirectInputCreateA_fn*) GetProcAddress(dinput_module, "DirectInputCreateA"); - FreeLibrary(dinput_module); + reinterpret_cast(dinput_module.resolve("DirectInputCreateA")); + dinput_module.unload(); if (!func_DirectInputCreateA) { - OutputDebugString("Couldn't GetProcAddress DInputCreate\r\n"); + QT_DEBUG("Couldn't GetProcAddress DInputCreate\r\n"); return; } *p_version = 0x300; return; } *p_found = 1; - if (LOWORD(os_version.dwBuildNumber) >= 0x550) { + if (os_version.majorVersion() >= 0x550) { + QT_DEBUG("what is this for??"); *p_version = 0x501; return; } - HMODULE ddraw_module = LoadLibrary("DDRAW.DLL"); - if (!ddraw_module) { + QLibrary ddraw_module("DDRAW.DLL"); + ddraw_module.load(); + if (!ddraw_module.isLoaded()) { *p_version = 0; *p_found = 0; - FreeLibrary(ddraw_module); + ddraw_module.unload(); return; } DirectDrawCreate_fn* func_DirectDrawCreate = - (DirectDrawCreate_fn*) GetProcAddress(ddraw_module, "DirectDrawCreate"); + reinterpret_cast(ddraw_module.resolve("DirectDrawCreate")); if (!func_DirectDrawCreate) { *p_version = 0; *p_found = 0; - FreeLibrary(ddraw_module); - OutputDebugString("Couldn't LoadLibrary DDraw\r\n"); + ddraw_module.unload(); + QT_DEBUG("Couldn't LoadLibrary DDraw\r\n"); return; } LPDIRECTDRAW ddraw; - if (FAILED(func_DirectDrawCreate(NULL, &ddraw, NULL))) { + if (func_DirectDrawCreate(NULL, &ddraw, NULL) < 0) { *p_version = 0; *p_found = 0; - FreeLibrary(ddraw_module); - OutputDebugString("Couldn't create DDraw\r\n"); + ddraw_module.unload(); + QT_DEBUG("Couldn't create DDraw\r\n"); return; } *p_version = 0x100; LPDIRECTDRAW2 ddraw2; - if (FAILED(ddraw->QueryInterface(IID_IDirectDraw2, (LPVOID*) &ddraw2))) { + if (ddraw->QueryInterface(IID_IDirectDraw2, (LPVOID*) &ddraw2) < 0) { ddraw->Release(); - FreeLibrary(ddraw_module); - OutputDebugString("Couldn't QI DDraw2\r\n"); + ddraw_module.unload(); + QT_DEBUG("Couldn't QI DDraw2\r\n"); return; } ddraw->Release(); *p_version = 0x200; - HMODULE dinput_module = LoadLibrary("DINPUT.DLL"); - if (!dinput_module) { - OutputDebugString("Couldn't LoadLibrary DInput\r\n"); + QLibrary dinput_module("DINPUT.DLL"); + dinput_module.load(); + if (!dinput_module.isLoaded()) { + QT_DEBUG("Couldn't LoadLibrary DInput\r\n"); ddraw2->Release(); - FreeLibrary(ddraw_module); + ddraw_module.unload(); return; } DirectInputCreateA_fn* func_DirectInputCreateA = - (DirectInputCreateA_fn*) GetProcAddress(dinput_module, "DirectInputCreateA"); - FreeLibrary(dinput_module); + reinterpret_cast(dinput_module.resolve("DirectInputCreateA")); + dinput_module.unload(); if (!func_DirectInputCreateA) { - FreeLibrary(ddraw_module); + ddraw_module.unload(); ddraw2->Release(); - OutputDebugString("Couldn't GetProcAddress DInputCreate\r\n"); + QT_DEBUG("Couldn't GetProcAddress DInputCreate\r\n"); return; } *p_version = 0x300; @@ -120,29 +126,29 @@ void DetectDirectX(unsigned int* p_version, BOOL* p_found) surface_desc.dwSize = sizeof(surface_desc); surface_desc.dwFlags = DDSD_CAPS; surface_desc.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE; - if (FAILED(ddraw2->SetCooperativeLevel(NULL, DDSCL_NORMAL))) { + if (ddraw2->SetCooperativeLevel(NULL, DDSCL_NORMAL) < 0) { ddraw2->Release(); - FreeLibrary(ddraw_module); + ddraw_module.unload(); *p_version = 0; - OutputDebugString("Couldn't Set coop level\r\n"); + QT_DEBUG("Couldn't Set coop level\r\n"); return; } LPDIRECTDRAWSURFACE surface; - if (FAILED(ddraw2->CreateSurface(&surface_desc, &surface, NULL))) { + if (ddraw2->CreateSurface(&surface_desc, &surface, NULL) < 0) { ddraw2->Release(); - FreeLibrary(ddraw_module); + ddraw_module.unload(); *p_version = 0; - OutputDebugString("Couldn't CreateSurface\r\n"); + QT_DEBUG("Couldn't CreateSurface\r\n"); return; } LPDIRECTDRAWSURFACE3 surface3; - if (FAILED(surface->QueryInterface(IID_IDirectDrawSurface3, (LPVOID*) &surface3))) { + if (surface->QueryInterface(IID_IDirectDrawSurface3, reinterpret_cast(&surface3)) < 0) { ddraw2->Release(); - FreeLibrary(ddraw_module); + ddraw_module.unload(); return; } *p_version = 0x500; surface3->Release(); ddraw2->Release(); - FreeLibrary(ddraw_module); + ddraw_module.unload(); }