Skip to content

Commit e3ef7ec

Browse files
committed
Add sh2 icon to the taskbar
1 parent 2902da0 commit e3ef7ec

File tree

8 files changed

+66
-21
lines changed

8 files changed

+66
-21
lines changed

Common/FileSystemHooks.cpp

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -685,8 +685,8 @@ void InstallCreateProcessHooks()
685685

686686
// Hook CreateProcess APIs
687687
HMODULE h_kernel32 = GetModuleHandle(L"kernel32.dll");
688-
InterlockedExchangePointer((PVOID*)&p_CreateProcessA, Hook::HotPatch(Hook::GetProcAddress(h_kernel32, "CreateProcessA"), "CreateProcessA", *CreateProcessAHandler));
689-
InterlockedExchangePointer((PVOID*)&p_CreateProcessW, Hook::HotPatch(Hook::GetProcAddress(h_kernel32, "CreateProcessW"), "CreateProcessW", *CreateProcessWHandler));
688+
InterlockedExchangePointer((PVOID)&p_CreateProcessA, Hook::HotPatch(Hook::GetProcAddress(h_kernel32, "CreateProcessA"), "CreateProcessA", *CreateProcessAHandler));
689+
InterlockedExchangePointer((PVOID)&p_CreateProcessW, Hook::HotPatch(Hook::GetProcAddress(h_kernel32, "CreateProcessW"), "CreateProcessW", *CreateProcessWHandler));
690690
}
691691

692692
void DisableFileSystemHooking()
@@ -706,16 +706,16 @@ void InstallFileSystemHooks(HMODULE hModule)
706706

707707
// Hook GetModuleFileName and GetModuleHandleEx to fix module name in modules loaded from memory
708708
HMODULE h_kernel32 = GetModuleHandle(L"kernel32.dll");
709-
InterlockedExchangePointer((PVOID*)&p_GetModuleFileNameA, Hook::HotPatch(Hook::GetProcAddress(h_kernel32, "GetModuleFileNameA"), "GetModuleFileNameA", GetModuleFileNameAHandler));
710-
InterlockedExchangePointer((PVOID*)&p_GetModuleFileNameW, Hook::HotPatch(Hook::GetProcAddress(h_kernel32, "GetModuleFileNameW"), "GetModuleFileNameW", GetModuleFileNameWHandler));
709+
InterlockedExchangePointer((PVOID)&p_GetModuleFileNameA, Hook::HotPatch(Hook::GetProcAddress(h_kernel32, "GetModuleFileNameA"), "GetModuleFileNameA", *GetModuleFileNameAHandler));
710+
InterlockedExchangePointer((PVOID)&p_GetModuleFileNameW, Hook::HotPatch(Hook::GetProcAddress(h_kernel32, "GetModuleFileNameW"), "GetModuleFileNameW", *GetModuleFileNameWHandler));
711711

712712
// Hook FileSystem APIs
713-
InterlockedExchangePointer((PVOID*)&p_CreateFileA, Hook::HotPatch(Hook::GetProcAddress(h_kernel32, "CreateFileA"), "CreateFileA", *CreateFileAHandler));
714-
InterlockedExchangePointer((PVOID*)&p_CreateFileW, Hook::HotPatch(Hook::GetProcAddress(h_kernel32, "CreateFileW"), "CreateFileW", *CreateFileWHandler));
715-
InterlockedExchangePointer((PVOID*)&p_FindFirstFileA, Hook::HotPatch(Hook::GetProcAddress(h_kernel32, "FindFirstFileA"), "FindFirstFileA", *FindFirstFileAHandler));
716-
InterlockedExchangePointer((PVOID*)&p_FindNextFileA, Hook::HotPatch(Hook::GetProcAddress(h_kernel32, "FindNextFileA"), "FindNextFileA", *FindNextFileAHandler));
717-
InterlockedExchangePointer((PVOID*)&p_GetPrivateProfileStringA, Hook::HotPatch(Hook::GetProcAddress(h_kernel32, "GetPrivateProfileStringA"), "GetPrivateProfileStringA", *GetPrivateProfileStringAHandler));
718-
InterlockedExchangePointer((PVOID*)&p_GetPrivateProfileStringW, Hook::HotPatch(Hook::GetProcAddress(h_kernel32, "GetPrivateProfileStringW"), "GetPrivateProfileStringW", *GetPrivateProfileStringWHandler));
713+
InterlockedExchangePointer((PVOID)&p_CreateFileA, Hook::HotPatch(Hook::GetProcAddress(h_kernel32, "CreateFileA"), "CreateFileA", *CreateFileAHandler));
714+
InterlockedExchangePointer((PVOID)&p_CreateFileW, Hook::HotPatch(Hook::GetProcAddress(h_kernel32, "CreateFileW"), "CreateFileW", *CreateFileWHandler));
715+
InterlockedExchangePointer((PVOID)&p_FindFirstFileA, Hook::HotPatch(Hook::GetProcAddress(h_kernel32, "FindFirstFileA"), "FindFirstFileA", *FindFirstFileAHandler));
716+
InterlockedExchangePointer((PVOID)&p_FindNextFileA, Hook::HotPatch(Hook::GetProcAddress(h_kernel32, "FindNextFileA"), "FindNextFileA", *FindNextFileAHandler));
717+
InterlockedExchangePointer((PVOID)&p_GetPrivateProfileStringA, Hook::HotPatch(Hook::GetProcAddress(h_kernel32, "GetPrivateProfileStringA"), "GetPrivateProfileStringA", *GetPrivateProfileStringAHandler));
718+
InterlockedExchangePointer((PVOID)&p_GetPrivateProfileStringW, Hook::HotPatch(Hook::GetProcAddress(h_kernel32, "GetPrivateProfileStringW"), "GetPrivateProfileStringW", *GetPrivateProfileStringWHandler));
719719

720720
// Check for hook failures
721721
if (!p_GetModuleFileNameA || !p_GetModuleFileNameW ||

Patches/Patches.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,7 @@ void PatchSpecificSoundLoopFix();
119119
void PatchTexAddr();
120120
void PatchTownWestGateEvent();
121121
void PatchTreeLighting();
122+
void PatchWindowIcon();
122123
void PatchWindowTitle();
123124
void PatchXInputVibration();
124125
void PatchSaveGameSound();

Patches/ReplaceWindowTitle.cpp

Lines changed: 49 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -16,21 +16,24 @@
1616

1717
#define WIN32_LEAN_AND_MEAN
1818
#include <Windows.h>
19+
#include "resource.h"
20+
#include "Common\Settings.h"
1921
#include "Common\Utils.h"
2022
#include "Logging\Logging.h"
21-
#include "External/Hooking.Patterns/Hooking.Patterns.h"
22-
23-
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)
24-
{
25-
UNREFERENCED_PARAMETER(lpWindowName);
26-
27-
return CreateWindowExA(dwExStyle, lpClassName, "Silent Hill 2: Enhanced Edition" , dwStyle, X, Y, nWidth, nHeight, hWndParent, hMenu, hInstance, lpParam);
28-
}
23+
#include "External\Hooking.Patterns\Hooking.Patterns.h"
2924

3025
// Replace the vanilla "SH2PC Title" with ours
3126
void PatchWindowTitle()
3227
{
33-
Logging::Log() << "Patching window title...";
28+
struct ClassHandler
29+
{
30+
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)
31+
{
32+
UNREFERENCED_PARAMETER(lpWindowName);
33+
34+
return CreateWindowExA(dwExStyle, lpClassName, "Silent Hill 2: Enhanced Edition", dwStyle, X, Y, nWidth, nHeight, hWndParent, hMenu, hInstance, lpParam);
35+
}
36+
};
3437

3538
auto pattern = hook::pattern("FF 15 ? ? ? ? 85 C0 A3 ? ? ? ? 74 ? 8B 0D ? ? ? ? 6A");
3639
if (pattern.size() != 1)
@@ -39,5 +42,41 @@ void PatchWindowTitle()
3942
return;
4043
}
4144

42-
WriteCalltoMemory((BYTE*)pattern.count(1).get(0).get<uint32_t*>(0), CreateWindowExA_Hook, 6);
45+
Logging::Log() << "Patching window title...";
46+
47+
WriteCalltoMemory((BYTE*)pattern.count(1).get(0).get<uint32_t*>(0), ClassHandler::CreateWindowExAHandler, 6);
48+
}
49+
50+
// Add icon to the Windows taskbar
51+
void PatchWindowIcon()
52+
{
53+
struct ClassHandler
54+
{
55+
static ATOM WINAPI RegisterClassExAHandler(WNDCLASSEXA* lpwcx)
56+
{
57+
lpwcx->hIcon = LoadIconA(m_hModule, MAKEINTRESOURCEA(OIC_SH2_ICON));
58+
lpwcx->hIconSm = LoadIconA(m_hModule, MAKEINTRESOURCEA(OIC_SH2_ICON));
59+
lpwcx->hbrBackground = CreateSolidBrush(RGB(0, 0, 0));
60+
if (!lpwcx->hIcon || !lpwcx->hIconSm)
61+
{
62+
Logging::Log() << __FUNCTION__ " Error: failed to create icon!";
63+
}
64+
65+
return RegisterClassExA(lpwcx);
66+
}
67+
};
68+
69+
// Get RegisterClass address
70+
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 };
71+
DWORD RegisterClassAddr = SearchAndGetAddresses(0x0040699E, 0x0040699E, 0x004069AE, SearchBytesRegisterClass, sizeof(SearchBytesRegisterClass), 0x21);
72+
73+
if (!RegisterClassAddr)
74+
{
75+
Logging::Log() << __FUNCTION__ " Error: failed to find memory address!";
76+
return;
77+
}
78+
79+
Logging::Log() << "Patching window icon...";
80+
81+
WriteCalltoMemory((BYTE*)RegisterClassAddr, ClassHandler::RegisterClassExAHandler, 6);
4382
}

Resources/BuildNo.rc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
#define BUILD_NUMBER 2005
1+
#define BUILD_NUMBER 2006

Resources/Resource.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
#include "BuildNo.rc"
44

55
// Included resource files
6+
#define OIC_SH2_ICON 151
7+
68
#define IDR_RESHADE_INI 101
79
#define IDR_SETTINGS_INI 102
810
#define IDR_LANG_RES 103

Resources/UALx86.rc

78 Bytes
Binary file not shown.

Resources/sh2.ico

219 KB
Binary file not shown.

dllmain.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,9 @@ void DelayedStart()
181181
// Replace window title
182182
PatchWindowTitle();
183183

184+
// Fix window icon
185+
PatchWindowIcon();
186+
184187
// Get wrapper mode
185188
Wrapper::GetWrapperMode();
186189

0 commit comments

Comments
 (0)