Skip to content

Commit

Permalink
Add sh2 icon to the taskbar
Browse files Browse the repository at this point in the history
  • Loading branch information
elishacloud committed Jul 21, 2022
1 parent 2902da0 commit e3ef7ec
Show file tree
Hide file tree
Showing 8 changed files with 66 additions and 21 deletions.
20 changes: 10 additions & 10 deletions Common/FileSystemHooks.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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 ||
Expand Down
1 change: 1 addition & 0 deletions Patches/Patches.h
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ void PatchSpecificSoundLoopFix();
void PatchTexAddr();
void PatchTownWestGateEvent();
void PatchTreeLighting();
void PatchWindowIcon();
void PatchWindowTitle();
void PatchXInputVibration();
void PatchSaveGameSound();
Expand Down
59 changes: 49 additions & 10 deletions Patches/ReplaceWindowTitle.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,21 +16,24 @@

#define WIN32_LEAN_AND_MEAN
#include <Windows.h>
#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)
Expand All @@ -39,5 +42,41 @@ void PatchWindowTitle()
return;
}

WriteCalltoMemory((BYTE*)pattern.count(1).get(0).get<uint32_t*>(0), CreateWindowExA_Hook, 6);
Logging::Log() << "Patching window title...";

WriteCalltoMemory((BYTE*)pattern.count(1).get(0).get<uint32_t*>(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);
}
2 changes: 1 addition & 1 deletion Resources/BuildNo.rc
Original file line number Diff line number Diff line change
@@ -1 +1 @@
#define BUILD_NUMBER 2005
#define BUILD_NUMBER 2006
2 changes: 2 additions & 0 deletions Resources/Resource.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Binary file modified Resources/UALx86.rc
Binary file not shown.
Binary file added Resources/sh2.ico
Binary file not shown.
3 changes: 3 additions & 0 deletions dllmain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,9 @@ void DelayedStart()
// Replace window title
PatchWindowTitle();

// Fix window icon
PatchWindowIcon();

// Get wrapper mode
Wrapper::GetWrapperMode();

Expand Down

0 comments on commit e3ef7ec

Please sign in to comment.