mirror of
https://github.com/Raymonf/whack.git
synced 2024-11-24 00:20:10 +01:00
make galliumhook somewhat configurable
This commit is contained in:
parent
4d9bb91ad8
commit
46d9ff33aa
@ -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;
|
||||
@ -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);
|
||||
}
|
||||
|
||||
@ -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);
|
||||
@ -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)
|
||||
{
|
||||
@ -78,6 +85,31 @@ int CreateHooks()
|
||||
return 0;
|
||||
}
|
||||
|
||||
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
|
||||
@ -87,6 +119,7 @@ BOOL APIENTRY DllMain( HMODULE hModule,
|
||||
{
|
||||
case DLL_PROCESS_ATTACH:
|
||||
LoadLibrary(L"mercuryhook.dll");
|
||||
LoadSettings();
|
||||
CreateHooks();
|
||||
break;
|
||||
case DLL_THREAD_ATTACH:
|
||||
@ -96,4 +129,3 @@ BOOL APIENTRY DllMain( HMODULE hModule,
|
||||
}
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
|
@ -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>
|
||||
@ -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>
|
||||
@ -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>
|
||||
@ -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>
|
||||
@ -143,6 +147,7 @@
|
||||
<ItemGroup>
|
||||
<ClInclude Include="framework.h" />
|
||||
<ClInclude Include="pch.h" />
|
||||
<ClInclude Include="toml.hpp" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="dllmain.cpp" />
|
||||
|
@ -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">
|
||||
|
17257
galliumhook/galliumhook/toml.hpp
Normal file
17257
galliumhook/galliumhook/toml.hpp
Normal file
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue
Block a user