Skip to content

Commit

Permalink
Move Comdlg to an ini option
Browse files Browse the repository at this point in the history
  • Loading branch information
elishacloud committed Dec 24, 2024
1 parent 16eaea2 commit 6badbb8
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 10 deletions.
2 changes: 1 addition & 1 deletion Dllmain/BuildNo.rc
Original file line number Diff line number Diff line change
@@ -1 +1 @@
#define BUILD_NUMBER 7406
#define BUILD_NUMBER 7407
17 changes: 17 additions & 0 deletions Dllmain/Dllmain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
#include "Settings\Settings.h"
#include "Wrappers\wrapper.h"
#include "winmm.h"
#include "GDI\GDI.h"
#include "External\Hooking\Hook.h"
#ifdef DDRAWCOMPAT
#include "DDrawCompat\DDrawCompatExternal.h"
Expand Down Expand Up @@ -586,6 +587,22 @@ BOOL APIENTRY DllMain(HMODULE hModule, DWORD fdwReason, LPVOID lpReserved)
InitDDraw();
}

// Hook Comdlg functions
if (Config.EnableOpenDialogHook)
{
using namespace GdiWrapper;
if (!GetModuleHandleA("comdlg32.dll")) LoadLibrary("comdlg32.dll");
HMODULE comdlg32 = GetModuleHandleA("Comdlg32.dll");
if (comdlg32)
{
Logging::Log() << "Installing Comdlg32 hooks";
GetOpenFileNameA_out = (FARPROC)Hook::HotPatch(GetProcAddress(comdlg32, "GetOpenFileNameA"), "GetOpenFileNameA", comdlg_GetOpenFileNameA);
GetOpenFileNameW_out = (FARPROC)Hook::HotPatch(GetProcAddress(comdlg32, "GetOpenFileNameW"), "GetOpenFileNameW", comdlg_GetOpenFileNameW);
GetSaveFileNameA_out = (FARPROC)Hook::HotPatch(GetProcAddress(comdlg32, "GetSaveFileNameA"), "GetSaveFileNameA", comdlg_GetSaveFileNameA);
GetSaveFileNameW_out = (FARPROC)Hook::HotPatch(GetProcAddress(comdlg32, "GetSaveFileNameW"), "GetSaveFileNameW", comdlg_GetSaveFileNameW);
}
}

// Start fullscreen thread
if (Config.FullScreen || Config.ForceTermination)
{
Expand Down
1 change: 1 addition & 0 deletions Settings/AllSettings.ini
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ EnableDdrawWrapper = 0
EnableD3d9Wrapper = 0
EnableDinput8Wrapper = 0
EnableDsoundWrapper = 0
EnableOpenDialogHook = 0
WinVersionLie = off
WinVersionLieSP = 0
ForceTermination = 0
Expand Down
2 changes: 2 additions & 0 deletions Settings/Settings.h
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@
visit(EnableDinput8Wrapper) \
visit(EnableDsoundWrapper) \
visit(EnableImgui) \
visit(EnableOpenDialogHook) \
visit(EnableVSync) \
visit(EnableWindowMode) \
visit(ExcludeProcess) \
Expand Down Expand Up @@ -262,6 +263,7 @@ struct CONFIG
bool EnableDinput8Wrapper = false; // Enables the dinput8 wrapper
bool EnableDsoundWrapper = false; // Enables the dsound wrapper
bool EnableImgui = false; // Enables imgui for debugging
bool EnableOpenDialogHook = false; // Enables the hooks for the open dialog box
bool EnableWindowMode = false; // Enables WndMode for d3d9 wrapper
bool EnableVSync = false; // Enables VSync for d3d9 wrapper
bool FixHighFrequencyMouse = false; // Gets the latest mouse status by merging the DirectInput buffer data
Expand Down
1 change: 1 addition & 0 deletions Settings/Settings.ini
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ EnableDdrawWrapper = 0
EnableD3d9Wrapper = 0
EnableDinput8Wrapper = 0
EnableDsoundWrapper = 0
EnableOpenDialogHook = 0
WinVersionLie = off
WinVersionLieSP = 0
HandleExceptions = 0
Expand Down
9 changes: 0 additions & 9 deletions ddraw/ddraw.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,6 @@ void InitDDraw()
if (!GetModuleHandleA("user32.dll")) LoadLibrary("user32.dll");
HMODULE gdi32 = GetModuleHandleA("gdi32.dll");
HMODULE user32 = GetModuleHandleA("user32.dll");
HMODULE comdlg32 = GetModuleHandleA("Comdlg32.dll");
HMODULE kernel32 = GetModuleHandleA("kernel32.dll");
if (gdi32)
{
Expand All @@ -87,14 +86,6 @@ void InitDDraw()
//SetWindowLongA_out = (FARPROC)Hook::HotPatch(GetProcAddress(user32, "SetWindowLongA"), "SetWindowLongA", user_SetWindowLongA);
//SetWindowLongW_out = (FARPROC)Hook::HotPatch(GetProcAddress(user32, "SetWindowLongW"), "SetWindowLongW", user_SetWindowLongW);
}
if (comdlg32)
{
Logging::Log() << "Installing Comdlg32 hooks";
GetOpenFileNameA_out = (FARPROC)Hook::HotPatch(GetProcAddress(comdlg32, "GetOpenFileNameA"), "GetOpenFileNameA", comdlg_GetOpenFileNameA);
GetOpenFileNameW_out = (FARPROC)Hook::HotPatch(GetProcAddress(comdlg32, "GetOpenFileNameW"), "GetOpenFileNameW", comdlg_GetOpenFileNameW);
GetSaveFileNameA_out = (FARPROC)Hook::HotPatch(GetProcAddress(comdlg32, "GetSaveFileNameA"), "GetSaveFileNameA", comdlg_GetSaveFileNameA);
GetSaveFileNameW_out = (FARPROC)Hook::HotPatch(GetProcAddress(comdlg32, "GetSaveFileNameW"), "GetSaveFileNameW", comdlg_GetSaveFileNameW);
}
if (kernel32)
{
Logging::Log() << "Installing Kernel32 hooks";
Expand Down

0 comments on commit 6badbb8

Please sign in to comment.