diff --git a/Common/FileSystemHooks.cpp b/Common/FileSystemHooks.cpp index 6e0a0bf7..d5d3bd0e 100644 --- a/Common/FileSystemHooks.cpp +++ b/Common/FileSystemHooks.cpp @@ -685,8 +685,8 @@ void InstallCreateProcessHooks() // Hook CreateProcess APIs HMODULE h_kernel32 = GetModuleHandle(L"kernel32.dll"); - InterlockedExchangePointer((PVOID*)&p_CreateProcessA, Hook::HotPatch(Hook::GetProcAddress(h_kernel32, "CreateProcessA"), "CreateProcessA", *CreateProcessAHandler)); - InterlockedExchangePointer((PVOID*)&p_CreateProcessW, Hook::HotPatch(Hook::GetProcAddress(h_kernel32, "CreateProcessW"), "CreateProcessW", *CreateProcessWHandler)); + InterlockedExchangePointer((PVOID)&p_CreateProcessA, Hook::HotPatch(Hook::GetProcAddress(h_kernel32, "CreateProcessA"), "CreateProcessA", *CreateProcessAHandler)); + InterlockedExchangePointer((PVOID)&p_CreateProcessW, Hook::HotPatch(Hook::GetProcAddress(h_kernel32, "CreateProcessW"), "CreateProcessW", *CreateProcessWHandler)); } void DisableFileSystemHooking() @@ -706,16 +706,16 @@ void InstallFileSystemHooks(HMODULE hModule) // Hook GetModuleFileName and GetModuleHandleEx to fix module name in modules loaded from memory HMODULE h_kernel32 = GetModuleHandle(L"kernel32.dll"); - InterlockedExchangePointer((PVOID*)&p_GetModuleFileNameA, Hook::HotPatch(Hook::GetProcAddress(h_kernel32, "GetModuleFileNameA"), "GetModuleFileNameA", GetModuleFileNameAHandler)); - InterlockedExchangePointer((PVOID*)&p_GetModuleFileNameW, Hook::HotPatch(Hook::GetProcAddress(h_kernel32, "GetModuleFileNameW"), "GetModuleFileNameW", GetModuleFileNameWHandler)); + InterlockedExchangePointer((PVOID)&p_GetModuleFileNameA, Hook::HotPatch(Hook::GetProcAddress(h_kernel32, "GetModuleFileNameA"), "GetModuleFileNameA", *GetModuleFileNameAHandler)); + InterlockedExchangePointer((PVOID)&p_GetModuleFileNameW, Hook::HotPatch(Hook::GetProcAddress(h_kernel32, "GetModuleFileNameW"), "GetModuleFileNameW", *GetModuleFileNameWHandler)); // Hook FileSystem APIs - InterlockedExchangePointer((PVOID*)&p_CreateFileA, Hook::HotPatch(Hook::GetProcAddress(h_kernel32, "CreateFileA"), "CreateFileA", *CreateFileAHandler)); - InterlockedExchangePointer((PVOID*)&p_CreateFileW, Hook::HotPatch(Hook::GetProcAddress(h_kernel32, "CreateFileW"), "CreateFileW", *CreateFileWHandler)); - InterlockedExchangePointer((PVOID*)&p_FindFirstFileA, Hook::HotPatch(Hook::GetProcAddress(h_kernel32, "FindFirstFileA"), "FindFirstFileA", *FindFirstFileAHandler)); - InterlockedExchangePointer((PVOID*)&p_FindNextFileA, Hook::HotPatch(Hook::GetProcAddress(h_kernel32, "FindNextFileA"), "FindNextFileA", *FindNextFileAHandler)); - InterlockedExchangePointer((PVOID*)&p_GetPrivateProfileStringA, Hook::HotPatch(Hook::GetProcAddress(h_kernel32, "GetPrivateProfileStringA"), "GetPrivateProfileStringA", *GetPrivateProfileStringAHandler)); - InterlockedExchangePointer((PVOID*)&p_GetPrivateProfileStringW, Hook::HotPatch(Hook::GetProcAddress(h_kernel32, "GetPrivateProfileStringW"), "GetPrivateProfileStringW", *GetPrivateProfileStringWHandler)); + InterlockedExchangePointer((PVOID)&p_CreateFileA, Hook::HotPatch(Hook::GetProcAddress(h_kernel32, "CreateFileA"), "CreateFileA", *CreateFileAHandler)); + InterlockedExchangePointer((PVOID)&p_CreateFileW, Hook::HotPatch(Hook::GetProcAddress(h_kernel32, "CreateFileW"), "CreateFileW", *CreateFileWHandler)); + InterlockedExchangePointer((PVOID)&p_FindFirstFileA, Hook::HotPatch(Hook::GetProcAddress(h_kernel32, "FindFirstFileA"), "FindFirstFileA", *FindFirstFileAHandler)); + InterlockedExchangePointer((PVOID)&p_FindNextFileA, Hook::HotPatch(Hook::GetProcAddress(h_kernel32, "FindNextFileA"), "FindNextFileA", *FindNextFileAHandler)); + InterlockedExchangePointer((PVOID)&p_GetPrivateProfileStringA, Hook::HotPatch(Hook::GetProcAddress(h_kernel32, "GetPrivateProfileStringA"), "GetPrivateProfileStringA", *GetPrivateProfileStringAHandler)); + InterlockedExchangePointer((PVOID)&p_GetPrivateProfileStringW, Hook::HotPatch(Hook::GetProcAddress(h_kernel32, "GetPrivateProfileStringW"), "GetPrivateProfileStringW", *GetPrivateProfileStringWHandler)); // Check for hook failures if (!p_GetModuleFileNameA || !p_GetModuleFileNameW || diff --git a/Patches/Patches.h b/Patches/Patches.h index d1691f39..80a633fd 100644 --- a/Patches/Patches.h +++ b/Patches/Patches.h @@ -119,6 +119,7 @@ void PatchSpecificSoundLoopFix(); void PatchTexAddr(); void PatchTownWestGateEvent(); void PatchTreeLighting(); +void PatchWindowIcon(); void PatchWindowTitle(); void PatchXInputVibration(); void PatchSaveGameSound(); diff --git a/Patches/ReplaceWindowTitle.cpp b/Patches/ReplaceWindowTitle.cpp index 9405b173..762789be 100644 --- a/Patches/ReplaceWindowTitle.cpp +++ b/Patches/ReplaceWindowTitle.cpp @@ -16,21 +16,24 @@ #define WIN32_LEAN_AND_MEAN #include +#include "resource.h" +#include "Common\Settings.h" #include "Common\Utils.h" #include "Logging\Logging.h" -#include "External/Hooking.Patterns/Hooking.Patterns.h" - -HWND __stdcall CreateWindowExA_Hook(DWORD dwExStyle, LPCSTR lpClassName, LPCSTR lpWindowName, DWORD dwStyle, int X, int Y, int nWidth, int nHeight, HWND hWndParent, HMENU hMenu, HINSTANCE hInstance, LPVOID lpParam) -{ - UNREFERENCED_PARAMETER(lpWindowName); - - return CreateWindowExA(dwExStyle, lpClassName, "Silent Hill 2: Enhanced Edition" , dwStyle, X, Y, nWidth, nHeight, hWndParent, hMenu, hInstance, lpParam); -} +#include "External\Hooking.Patterns\Hooking.Patterns.h" // Replace the vanilla "SH2PC Title" with ours void PatchWindowTitle() { - Logging::Log() << "Patching window title..."; + struct ClassHandler + { + static HWND WINAPI CreateWindowExAHandler(DWORD dwExStyle, LPCSTR lpClassName, LPCSTR lpWindowName, DWORD dwStyle, int X, int Y, int nWidth, int nHeight, HWND hWndParent, HMENU hMenu, HINSTANCE hInstance, LPVOID lpParam) + { + UNREFERENCED_PARAMETER(lpWindowName); + + return CreateWindowExA(dwExStyle, lpClassName, "Silent Hill 2: Enhanced Edition", dwStyle, X, Y, nWidth, nHeight, hWndParent, hMenu, hInstance, lpParam); + } + }; auto pattern = hook::pattern("FF 15 ? ? ? ? 85 C0 A3 ? ? ? ? 74 ? 8B 0D ? ? ? ? 6A"); if (pattern.size() != 1) @@ -39,5 +42,41 @@ void PatchWindowTitle() return; } - WriteCalltoMemory((BYTE*)pattern.count(1).get(0).get(0), CreateWindowExA_Hook, 6); + Logging::Log() << "Patching window title..."; + + WriteCalltoMemory((BYTE*)pattern.count(1).get(0).get(0), ClassHandler::CreateWindowExAHandler, 6); +} + +// Add icon to the Windows taskbar +void PatchWindowIcon() +{ + struct ClassHandler + { + static ATOM WINAPI RegisterClassExAHandler(WNDCLASSEXA* lpwcx) + { + lpwcx->hIcon = LoadIconA(m_hModule, MAKEINTRESOURCEA(OIC_SH2_ICON)); + lpwcx->hIconSm = LoadIconA(m_hModule, MAKEINTRESOURCEA(OIC_SH2_ICON)); + lpwcx->hbrBackground = CreateSolidBrush(RGB(0, 0, 0)); + if (!lpwcx->hIcon || !lpwcx->hIconSm) + { + Logging::Log() << __FUNCTION__ " Error: failed to create icon!"; + } + + return RegisterClassExA(lpwcx); + } + }; + + // Get RegisterClass address + constexpr BYTE SearchBytesRegisterClass[]{ 0x8D, 0x4C, 0x24, 0x04, 0x51, 0x89, 0x44, 0x24, 0x24, 0xC7, 0x44, 0x24, 0x28, 0x06, 0x00, 0x00, 0x00, 0x89, 0x74, 0x24, 0x2C, 0xC7, 0x44, 0x24, 0x30 }; + DWORD RegisterClassAddr = SearchAndGetAddresses(0x0040699E, 0x0040699E, 0x004069AE, SearchBytesRegisterClass, sizeof(SearchBytesRegisterClass), 0x21); + + if (!RegisterClassAddr) + { + Logging::Log() << __FUNCTION__ " Error: failed to find memory address!"; + return; + } + + Logging::Log() << "Patching window icon..."; + + WriteCalltoMemory((BYTE*)RegisterClassAddr, ClassHandler::RegisterClassExAHandler, 6); } diff --git a/Resources/BuildNo.rc b/Resources/BuildNo.rc index 451349dc..409790b3 100644 --- a/Resources/BuildNo.rc +++ b/Resources/BuildNo.rc @@ -1 +1 @@ -#define BUILD_NUMBER 2005 +#define BUILD_NUMBER 2006 diff --git a/Resources/Resource.h b/Resources/Resource.h index 7e25fb0e..f6e406ad 100644 --- a/Resources/Resource.h +++ b/Resources/Resource.h @@ -3,6 +3,8 @@ #include "BuildNo.rc" // Included resource files +#define OIC_SH2_ICON 151 + #define IDR_RESHADE_INI 101 #define IDR_SETTINGS_INI 102 #define IDR_LANG_RES 103 diff --git a/Resources/UALx86.rc b/Resources/UALx86.rc index 4ec0a91e..7972de5f 100644 Binary files a/Resources/UALx86.rc and b/Resources/UALx86.rc differ diff --git a/Resources/sh2.ico b/Resources/sh2.ico new file mode 100644 index 00000000..b32a41e8 Binary files /dev/null and b/Resources/sh2.ico differ diff --git a/dllmain.cpp b/dllmain.cpp index 5647ddff..c2a4c206 100644 --- a/dllmain.cpp +++ b/dllmain.cpp @@ -181,6 +181,9 @@ void DelayedStart() // Replace window title PatchWindowTitle(); + // Fix window icon + PatchWindowIcon(); + // Get wrapper mode Wrapper::GetWrapperMode();