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.
|
// dllmain.cpp : Defines the entry point for the DLL application.
|
||||||
#include "pch.h"
|
#include "pch.h"
|
||||||
|
#include "toml.hpp"
|
||||||
#include <cstdio>
|
#include <cstdio>
|
||||||
#include <cstdint>
|
#include <cstdint>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
// i hate C++20
|
||||||
|
#include <locale>
|
||||||
|
#include <codecvt>
|
||||||
#include "MinHook.h"
|
#include "MinHook.h"
|
||||||
|
|
||||||
const int TARGET_WIDTH = 1080;
|
int targetWidth = 1080;
|
||||||
const int TARGET_HEIGHT = 1920;
|
int targetHeight = 1920;
|
||||||
|
int windowX = 0;
|
||||||
|
int windowY = 0;
|
||||||
|
uint64_t wndProcAddr = 0x72AE80ull;
|
||||||
|
|
||||||
typedef int64_t(__fastcall* tWndProc)(HWND, UINT, WPARAM, WPARAM);
|
typedef int64_t(__fastcall* tWndProc)(HWND, UINT, WPARAM, WPARAM);
|
||||||
tWndProc WndProc;
|
tWndProc WndProc;
|
||||||
@ -16,8 +23,8 @@ typedef HWND(__stdcall* tCreateWindowExW)(DWORD dwExStyle, LPCWSTR lpClassName,
|
|||||||
tCreateWindowExW fpCreateWindowExW;
|
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)
|
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;
|
nWidth = targetWidth;
|
||||||
nHeight = TARGET_HEIGHT;
|
nHeight = targetHeight;
|
||||||
return fpCreateWindowExW(dwExStyle, lpClassName, lpWindowName, dwStyle, X, Y, nWidth, nHeight, hWndParent, hMenu, hInstance, lpParam);
|
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);
|
DefWindowProc(hWnd, uMsg, wParam, lParam);
|
||||||
MINMAXINFO* pmmi = (MINMAXINFO*)lParam;
|
MINMAXINFO* pmmi = (MINMAXINFO*)lParam;
|
||||||
pmmi->ptMaxTrackSize.x = TARGET_WIDTH;
|
pmmi->ptMaxTrackSize.x = targetWidth;
|
||||||
pmmi->ptMaxTrackSize.y = TARGET_HEIGHT;
|
pmmi->ptMaxTrackSize.y = targetHeight;
|
||||||
|
|
||||||
// is this needed? don't care because it works
|
// 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 0;
|
||||||
}
|
}
|
||||||
return fpWndProc(hWnd, uMsg, wParam, lParam);
|
return fpWndProc(hWnd, uMsg, wParam, lParam);
|
||||||
@ -41,7 +48,7 @@ int CreateHooks()
|
|||||||
{
|
{
|
||||||
OutputDebugStringW(L"[galliumhook] CreateHooks()\r\n");
|
OutputDebugStringW(L"[galliumhook] CreateHooks()\r\n");
|
||||||
auto base = (uint64_t)GetModuleHandleW(NULL);
|
auto base = (uint64_t)GetModuleHandleW(NULL);
|
||||||
WndProc = (tWndProc)(base + 0x72AE80ull);
|
WndProc = (tWndProc)(base + wndProcAddr);
|
||||||
|
|
||||||
if (MH_Initialize() != MH_OK)
|
if (MH_Initialize() != MH_OK)
|
||||||
{
|
{
|
||||||
@ -78,15 +85,41 @@ int CreateHooks()
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
BOOL APIENTRY DllMain( HMODULE hModule,
|
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,
|
DWORD ul_reason_for_call,
|
||||||
LPVOID lpReserved
|
LPVOID lpReserved
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
switch (ul_reason_for_call)
|
switch (ul_reason_for_call)
|
||||||
{
|
{
|
||||||
case DLL_PROCESS_ATTACH:
|
case DLL_PROCESS_ATTACH:
|
||||||
LoadLibrary(L"mercuryhook.dll");
|
LoadLibrary(L"mercuryhook.dll");
|
||||||
|
LoadSettings();
|
||||||
CreateHooks();
|
CreateHooks();
|
||||||
break;
|
break;
|
||||||
case DLL_THREAD_ATTACH:
|
case DLL_THREAD_ATTACH:
|
||||||
@ -96,4 +129,3 @@ BOOL APIENTRY DllMain( HMODULE hModule,
|
|||||||
}
|
}
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -74,10 +74,11 @@
|
|||||||
<ClCompile>
|
<ClCompile>
|
||||||
<WarningLevel>Level3</WarningLevel>
|
<WarningLevel>Level3</WarningLevel>
|
||||||
<SDLCheck>true</SDLCheck>
|
<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>
|
<ConformanceMode>true</ConformanceMode>
|
||||||
<PrecompiledHeader>Use</PrecompiledHeader>
|
<PrecompiledHeader>Use</PrecompiledHeader>
|
||||||
<PrecompiledHeaderFile>pch.h</PrecompiledHeaderFile>
|
<PrecompiledHeaderFile>pch.h</PrecompiledHeaderFile>
|
||||||
|
<LanguageStandard>stdcpp17</LanguageStandard>
|
||||||
</ClCompile>
|
</ClCompile>
|
||||||
<Link>
|
<Link>
|
||||||
<SubSystem>Windows</SubSystem>
|
<SubSystem>Windows</SubSystem>
|
||||||
@ -91,10 +92,11 @@
|
|||||||
<FunctionLevelLinking>true</FunctionLevelLinking>
|
<FunctionLevelLinking>true</FunctionLevelLinking>
|
||||||
<IntrinsicFunctions>true</IntrinsicFunctions>
|
<IntrinsicFunctions>true</IntrinsicFunctions>
|
||||||
<SDLCheck>true</SDLCheck>
|
<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>
|
<ConformanceMode>true</ConformanceMode>
|
||||||
<PrecompiledHeader>Use</PrecompiledHeader>
|
<PrecompiledHeader>Use</PrecompiledHeader>
|
||||||
<PrecompiledHeaderFile>pch.h</PrecompiledHeaderFile>
|
<PrecompiledHeaderFile>pch.h</PrecompiledHeaderFile>
|
||||||
|
<LanguageStandard>stdcpp17</LanguageStandard>
|
||||||
</ClCompile>
|
</ClCompile>
|
||||||
<Link>
|
<Link>
|
||||||
<SubSystem>Windows</SubSystem>
|
<SubSystem>Windows</SubSystem>
|
||||||
@ -108,11 +110,12 @@
|
|||||||
<ClCompile>
|
<ClCompile>
|
||||||
<WarningLevel>Level3</WarningLevel>
|
<WarningLevel>Level3</WarningLevel>
|
||||||
<SDLCheck>true</SDLCheck>
|
<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>
|
<ConformanceMode>true</ConformanceMode>
|
||||||
<PrecompiledHeader>Use</PrecompiledHeader>
|
<PrecompiledHeader>Use</PrecompiledHeader>
|
||||||
<PrecompiledHeaderFile>pch.h</PrecompiledHeaderFile>
|
<PrecompiledHeaderFile>pch.h</PrecompiledHeaderFile>
|
||||||
<AdditionalIncludeDirectories>$(SolutionDir)minhook-multihook\include</AdditionalIncludeDirectories>
|
<AdditionalIncludeDirectories>$(SolutionDir)minhook-multihook\include</AdditionalIncludeDirectories>
|
||||||
|
<LanguageStandard>stdcpp17</LanguageStandard>
|
||||||
</ClCompile>
|
</ClCompile>
|
||||||
<Link>
|
<Link>
|
||||||
<SubSystem>Windows</SubSystem>
|
<SubSystem>Windows</SubSystem>
|
||||||
@ -126,11 +129,12 @@
|
|||||||
<FunctionLevelLinking>true</FunctionLevelLinking>
|
<FunctionLevelLinking>true</FunctionLevelLinking>
|
||||||
<IntrinsicFunctions>true</IntrinsicFunctions>
|
<IntrinsicFunctions>true</IntrinsicFunctions>
|
||||||
<SDLCheck>true</SDLCheck>
|
<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>
|
<ConformanceMode>true</ConformanceMode>
|
||||||
<PrecompiledHeader>Use</PrecompiledHeader>
|
<PrecompiledHeader>Use</PrecompiledHeader>
|
||||||
<PrecompiledHeaderFile>pch.h</PrecompiledHeaderFile>
|
<PrecompiledHeaderFile>pch.h</PrecompiledHeaderFile>
|
||||||
<AdditionalIncludeDirectories>$(SolutionDir)minhook-multihook\include</AdditionalIncludeDirectories>
|
<AdditionalIncludeDirectories>$(SolutionDir)minhook-multihook\include</AdditionalIncludeDirectories>
|
||||||
|
<LanguageStandard>stdcpp17</LanguageStandard>
|
||||||
</ClCompile>
|
</ClCompile>
|
||||||
<Link>
|
<Link>
|
||||||
<SubSystem>Windows</SubSystem>
|
<SubSystem>Windows</SubSystem>
|
||||||
@ -143,6 +147,7 @@
|
|||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ClInclude Include="framework.h" />
|
<ClInclude Include="framework.h" />
|
||||||
<ClInclude Include="pch.h" />
|
<ClInclude Include="pch.h" />
|
||||||
|
<ClInclude Include="toml.hpp" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ClCompile Include="dllmain.cpp" />
|
<ClCompile Include="dllmain.cpp" />
|
||||||
|
@ -21,6 +21,9 @@
|
|||||||
<ClInclude Include="pch.h">
|
<ClInclude Include="pch.h">
|
||||||
<Filter>Header Files</Filter>
|
<Filter>Header Files</Filter>
|
||||||
</ClInclude>
|
</ClInclude>
|
||||||
|
<ClInclude Include="toml.hpp">
|
||||||
|
<Filter>Header Files</Filter>
|
||||||
|
</ClInclude>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ClCompile Include="dllmain.cpp">
|
<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