Skip to content

Commit

Permalink
make galliumhook somewhat configurable
Browse files Browse the repository at this point in the history
  • Loading branch information
Raymonf committed Dec 18, 2022
1 parent 4d9bb91 commit 46d9ff3
Show file tree
Hide file tree
Showing 4 changed files with 17,314 additions and 17 deletions.
58 changes: 45 additions & 13 deletions galliumhook/galliumhook/dllmain.cpp
Original file line number Diff line number Diff line change
@@ -1,12 +1,19 @@
// dllmain.cpp : Defines the entry point for the DLL application.
#include "pch.h"
#include "toml.hpp"
#include <cstdio>
#include <cstdint>
#include <string>
// i hate C++20
#include <locale>
#include <codecvt>
#include "MinHook.h"

const int TARGET_WIDTH = 1080;
const int TARGET_HEIGHT = 1920;
int targetWidth = 1080;
int targetHeight = 1920;
int windowX = 0;
int windowY = 0;
uint64_t wndProcAddr = 0x72AE80ull;

typedef int64_t(__fastcall* tWndProc)(HWND, UINT, WPARAM, WPARAM);
tWndProc WndProc;
Expand All @@ -16,8 +23,8 @@ typedef HWND(__stdcall* tCreateWindowExW)(DWORD dwExStyle, LPCWSTR lpClassName,
tCreateWindowExW fpCreateWindowExW;
HWND __stdcall DetourCreateWindowExW(DWORD dwExStyle, LPCWSTR lpClassName, LPCWSTR lpWindowName, DWORD dwStyle, int X, int Y, int nWidth, int nHeight, HWND hWndParent, HMENU hMenu, HINSTANCE hInstance, LPVOID lpParam)
{
nWidth = TARGET_WIDTH;
nHeight = TARGET_HEIGHT;
nWidth = targetWidth;
nHeight = targetHeight;
return fpCreateWindowExW(dwExStyle, lpClassName, lpWindowName, dwStyle, X, Y, nWidth, nHeight, hWndParent, hMenu, hInstance, lpParam);
}

Expand All @@ -27,11 +34,11 @@ int64_t __fastcall DetourWndProc(HWND hWnd, UINT uMsg, WPARAM wParam, WPARAM lPa
{
DefWindowProc(hWnd, uMsg, wParam, lParam);
MINMAXINFO* pmmi = (MINMAXINFO*)lParam;
pmmi->ptMaxTrackSize.x = TARGET_WIDTH;
pmmi->ptMaxTrackSize.y = TARGET_HEIGHT;
pmmi->ptMaxTrackSize.x = targetWidth;
pmmi->ptMaxTrackSize.y = targetHeight;

// is this needed? don't care because it works
SetWindowPos(hWnd, HWND_TOP, 0, 0, TARGET_WIDTH, TARGET_HEIGHT, SWP_NOMOVE | SWP_FRAMECHANGED);
SetWindowPos(hWnd, HWND_TOP, windowX, windowY, targetWidth, targetHeight, SWP_NOMOVE | SWP_FRAMECHANGED);
return 0;
}
return fpWndProc(hWnd, uMsg, wParam, lParam);
Expand All @@ -41,7 +48,7 @@ int CreateHooks()
{
OutputDebugStringW(L"[galliumhook] CreateHooks()\r\n");
auto base = (uint64_t)GetModuleHandleW(NULL);
WndProc = (tWndProc)(base + 0x72AE80ull);
WndProc = (tWndProc)(base + wndProcAddr);

if (MH_Initialize() != MH_OK)
{
Expand Down Expand Up @@ -78,15 +85,41 @@ int CreateHooks()
return 0;
}

BOOL APIENTRY DllMain( HMODULE hModule,
DWORD ul_reason_for_call,
LPVOID lpReserved
)
void LoadSettings()
{
OutputDebugStringW(L"[galliumhook] LoadSettings()\r\n");

std::wstring_convert<std::codecvt_utf8_utf16<wchar_t>> converter;
try
{
auto config = toml::parse_file("galliumhook.toml");
targetWidth = config["window"]["width"].value_or(targetWidth);
targetHeight = config["window"]["height"].value_or(targetHeight);
wndProcAddr = config["window"]["wndproc"].value_or(wndProcAddr);

// don't know if these do anything
windowX = config["position"]["x"].value_or(windowX);
windowY = config["position"]["y"].value_or(windowY);
}
catch (std::runtime_error& e)
{
OutputDebugStringW(L"error while loading settings occurred");

auto message = converter.from_bytes(e.what());
OutputDebugStringW(message.c_str());
}
}

BOOL APIENTRY DllMain(HMODULE hModule,
DWORD ul_reason_for_call,
LPVOID lpReserved
)
{
switch (ul_reason_for_call)
{
case DLL_PROCESS_ATTACH:
LoadLibrary(L"mercuryhook.dll");
LoadSettings();
CreateHooks();
break;
case DLL_THREAD_ATTACH:
Expand All @@ -96,4 +129,3 @@ BOOL APIENTRY DllMain( HMODULE hModule,
}
return TRUE;
}

13 changes: 9 additions & 4 deletions galliumhook/galliumhook/galliumhook.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -74,10 +74,11 @@
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<SDLCheck>true</SDLCheck>
<PreprocessorDefinitions>WIN32;_DEBUG;GALLIUMHOOK_EXPORTS;_WINDOWS;_USRDLL;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<PreprocessorDefinitions>_SILENCE_CXX17_CODECVT_HEADER_DEPRECATION_WARNING;WIN32;_DEBUG;GALLIUMHOOK_EXPORTS;_WINDOWS;_USRDLL;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<ConformanceMode>true</ConformanceMode>
<PrecompiledHeader>Use</PrecompiledHeader>
<PrecompiledHeaderFile>pch.h</PrecompiledHeaderFile>
<LanguageStandard>stdcpp17</LanguageStandard>
</ClCompile>
<Link>
<SubSystem>Windows</SubSystem>
Expand All @@ -91,10 +92,11 @@
<FunctionLevelLinking>true</FunctionLevelLinking>
<IntrinsicFunctions>true</IntrinsicFunctions>
<SDLCheck>true</SDLCheck>
<PreprocessorDefinitions>WIN32;NDEBUG;GALLIUMHOOK_EXPORTS;_WINDOWS;_USRDLL;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<PreprocessorDefinitions>_SILENCE_CXX17_CODECVT_HEADER_DEPRECATION_WARNING;WIN32;NDEBUG;GALLIUMHOOK_EXPORTS;_WINDOWS;_USRDLL;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<ConformanceMode>true</ConformanceMode>
<PrecompiledHeader>Use</PrecompiledHeader>
<PrecompiledHeaderFile>pch.h</PrecompiledHeaderFile>
<LanguageStandard>stdcpp17</LanguageStandard>
</ClCompile>
<Link>
<SubSystem>Windows</SubSystem>
Expand All @@ -108,11 +110,12 @@
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<SDLCheck>true</SDLCheck>
<PreprocessorDefinitions>_DEBUG;GALLIUMHOOK_EXPORTS;_WINDOWS;_USRDLL;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<PreprocessorDefinitions>_SILENCE_CXX17_CODECVT_HEADER_DEPRECATION_WARNING;_DEBUG;GALLIUMHOOK_EXPORTS;_WINDOWS;_USRDLL;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<ConformanceMode>true</ConformanceMode>
<PrecompiledHeader>Use</PrecompiledHeader>
<PrecompiledHeaderFile>pch.h</PrecompiledHeaderFile>
<AdditionalIncludeDirectories>$(SolutionDir)minhook-multihook\include</AdditionalIncludeDirectories>
<LanguageStandard>stdcpp17</LanguageStandard>
</ClCompile>
<Link>
<SubSystem>Windows</SubSystem>
Expand All @@ -126,11 +129,12 @@
<FunctionLevelLinking>true</FunctionLevelLinking>
<IntrinsicFunctions>true</IntrinsicFunctions>
<SDLCheck>true</SDLCheck>
<PreprocessorDefinitions>NDEBUG;GALLIUMHOOK_EXPORTS;_WINDOWS;_USRDLL;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<PreprocessorDefinitions>_SILENCE_CXX17_CODECVT_HEADER_DEPRECATION_WARNING;NDEBUG;GALLIUMHOOK_EXPORTS;_WINDOWS;_USRDLL;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<ConformanceMode>true</ConformanceMode>
<PrecompiledHeader>Use</PrecompiledHeader>
<PrecompiledHeaderFile>pch.h</PrecompiledHeaderFile>
<AdditionalIncludeDirectories>$(SolutionDir)minhook-multihook\include</AdditionalIncludeDirectories>
<LanguageStandard>stdcpp17</LanguageStandard>
</ClCompile>
<Link>
<SubSystem>Windows</SubSystem>
Expand All @@ -143,6 +147,7 @@
<ItemGroup>
<ClInclude Include="framework.h" />
<ClInclude Include="pch.h" />
<ClInclude Include="toml.hpp" />
</ItemGroup>
<ItemGroup>
<ClCompile Include="dllmain.cpp" />
Expand Down
3 changes: 3 additions & 0 deletions galliumhook/galliumhook/galliumhook.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@
<ClInclude Include="pch.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="toml.hpp">
<Filter>Header Files</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<ClCompile Include="dllmain.cpp">
Expand Down
Loading

0 comments on commit 46d9ff3

Please sign in to comment.