diff --git a/meson.build b/meson.build index f50c2e8..9217ed4 100644 --- a/meson.build +++ b/meson.build @@ -28,6 +28,7 @@ add_project_link_arguments( language: 'cpp', ) +minhook = subproject('minhook') tomlc99 = subproject('tomlc99') sdl2 = subproject('sdl2', default_options: ['default_library=static', 'test=false', 'use_render=disabled']) xxhash = subproject('xxhash', default_options: ['default_library=static', 'cli=false']) @@ -52,6 +53,7 @@ pugixml_dep = pugixml.get_variable('pugixml_static_dep') library( 'bnusio', link_with: [ + minhook.get_variable('minhook_lib'), tomlc99.get_variable('tomlc99_lib'), sdl2.get_variable('sdl2'), xxhash.get_variable('xxhash'), @@ -61,6 +63,7 @@ library( link_args : '-Wl,--allow-multiple-definition', include_directories: [ 'src', + minhook.get_variable('minhook_inc'), tomlc99.get_variable('tomlc99_inc'), sdl2.get_variable('core_inc'), xxhash.get_variable('inc'), diff --git a/src/bnusio.cpp b/src/bnusio.cpp index 6012ab7..d1c2dcb 100644 --- a/src/bnusio.cpp +++ b/src/bnusio.cpp @@ -297,7 +297,7 @@ HOOK (u64, bngrw_ReqWaitTouch, PROC_ADDRESS ("bngrw.dll", "BngRwReqWaitTouch"), return 1; } else { // This is called when we use an original card reader and acceptInvalidCards is set to true - return originalbngrw_ReqWaitTouch.call (a1, a2, a3, InspectWaitTouch, _touchData); + return originalbngrw_ReqWaitTouch (a1, a2, a3, InspectWaitTouch, _touchData); } } diff --git a/src/dllmain.cpp b/src/dllmain.cpp index 4628fd5..f9dd2bd 100644 --- a/src/dllmain.cpp +++ b/src/dllmain.cpp @@ -35,7 +35,7 @@ std::string logLevelStr = "INFO"; bool logToFile = true; HWND hGameWnd; -HOOK (i32, ShowMouse, PROC_ADDRESS ("user32.dll", "ShowCursor"), bool) { return originalShowMouse.call (true); } +HOOK (i32, ShowMouse, PROC_ADDRESS ("user32.dll", "ShowCursor"), bool) { return originalShowMouse (true); } HOOK (i32, ExitWindows, PROC_ADDRESS ("user32.dll", "ExitWindowsEx")) { ExitProcess (0); } HOOK (HWND, CreateWindow, PROC_ADDRESS ("user32.dll", "CreateWindowExW"), DWORD dwExStyle, LPCWSTR lpClassName, LPCWSTR lpWindowName, DWORD dwStyle, i32 X, i32 Y, i32 nWidth, i32 nHeight, HWND hWndParent, HMENU hMenu, HINSTANCE hInstance, LPVOID lpParam) { @@ -43,12 +43,12 @@ HOOK (HWND, CreateWindow, PROC_ADDRESS ("user32.dll", "CreateWindowExW"), DWORD if (wcscmp (lpWindowName, L"Taiko") == 0) { if (windowed) dwStyle = WS_TILEDWINDOW ^ WS_MAXIMIZEBOX ^ WS_THICKFRAME; - hGameWnd = originalCreateWindow.call (dwExStyle, lpClassName, lpWindowName, dwStyle, X, Y, nWidth, nHeight, hWndParent, hMenu, + hGameWnd = originalCreateWindow (dwExStyle, lpClassName, lpWindowName, dwStyle, X, Y, nWidth, nHeight, hWndParent, hMenu, hInstance, lpParam); return hGameWnd; } } - return originalCreateWindow.call (dwExStyle, lpClassName, lpWindowName, dwStyle, X, Y, nWidth, nHeight, hWndParent, hMenu, hInstance, + return originalCreateWindow (dwExStyle, lpClassName, lpWindowName, dwStyle, X, Y, nWidth, nHeight, hWndParent, hMenu, hInstance, lpParam); } HOOK (bool, SetWindowPosition, PROC_ADDRESS ("user32.dll", "SetWindowPos"), HWND hWnd, HWND hWndInsertAfter, i32 X, i32 Y, i32 cx, i32 cy, @@ -60,12 +60,12 @@ HOOK (bool, SetWindowPosition, PROC_ADDRESS ("user32.dll", "SetWindowPos"), HWND cx = (rw.right - rw.left) - (rc.right - rc.left) + cx; cy = (rw.bottom - rw.top) - (rc.bottom - rc.top) + cy; } - return originalSetWindowPosition.call (hWnd, hWndInsertAfter, X, Y, cx, cy, uFlags); + return originalSetWindowPosition (hWnd, hWndInsertAfter, X, Y, cx, cy, uFlags); } HOOK (void, ExitProcessHook, PROC_ADDRESS ("kernel32.dll", "ExitProcess"), u32 uExitCode) { bnusio::Close (); - originalExitProcessHook.call (uExitCode); + originalExitProcessHook (uExitCode); } HOOK (i32, XinputGetState, PROC_ADDRESS ("xinput9_1_0.dll", "XInputGetState")) { return ERROR_DEVICE_NOT_CONNECTED; } @@ -82,7 +82,7 @@ HOOK (i64, UsbFinderGetSerialNumber, PROC_ADDRESS ("nbamUsbFinder.dll", "nbamUsb } HOOK (i32, ws2_getaddrinfo, PROC_ADDRESS ("ws2_32.dll", "getaddrinfo"), const char *node, char *service, void *hints, void *out) { - return originalws2_getaddrinfo.call (server.c_str (), service, hints, out); + return originalws2_getaddrinfo (server.c_str (), service, hints, out); } void diff --git a/src/helpers.h b/src/helpers.h index 95cbca0..b2dabbd 100644 --- a/src/helpers.h +++ b/src/helpers.h @@ -4,6 +4,7 @@ #include #include #include +#include #include #include #include @@ -36,35 +37,41 @@ const HMODULE MODULE_HANDLE = GetModuleHandle (nullptr); #define ASLR(address) ((u64)MODULE_HANDLE + (u64)address - (u64)BASE_ADDRESS) #endif -#define HOOK(returnType, functionName, location, ...) \ - SafetyHookInline original##functionName{}; \ - void *where##functionName = (void *)location; \ +#define HOOK(returnType, functionName, location, ...) \ + typedef returnType (*functionName) (__VA_ARGS__); \ + functionName original##functionName = NULL; \ + void *where##functionName = (void *)(location); \ returnType implOf##functionName (__VA_ARGS__) -#define HOOK_DYNAMIC(returnType, functionName, ...) \ - SafetyHookInline original##functionName{}; \ - void *where##functionName = NULL; \ +#define HOOK_DYNAMIC(returnType, functionName, ...) \ + typedef returnType (*functionName) (__VA_ARGS__); \ + functionName original##functionName = NULL; \ + void *where##functionName = NULL; \ returnType implOf##functionName (__VA_ARGS__) -#define VTABLE_HOOK(returnType, className, functionName, ...) \ - SafetyHookInline original##className##functionName{}; \ - void *where##className##functionName = NULL; \ +#define VTABLE_HOOK(returnType, className, functionName, ...) \ + typedef returnType (*className##functionName) (className * This, __VA_ARGS__); \ + className##functionName original##className##functionName = NULL; \ + void *where##className##functionName = NULL; \ returnType implOf##className##functionName (className *This, __VA_ARGS__) -#define MID_HOOK(functionName, location, ...) \ - SafetyHookMid midHook##functionName{}; \ - void *where##functionName = (void *)location; \ +#define MID_HOOK(functionName, location, ...) \ + typedef void (*functionName) (__VA_ARGS__); \ + SafetyHookMid midHook##functionName{}; \ + u64 where##functionName = (location); \ void implOf##functionName (SafetyHookContext &ctx) -#define MID_HOOK_DYNAMIC(functionName, ...) \ - SafetyHookMid midHook##functionName{}; \ - void *where##functionName = NULL; \ +#define MID_HOOK_DYNAMIC(functionName, ...) \ + typedef void (*functionName) (__VA_ARGS__); \ + std::map mapOf##functionName; \ void implOf##functionName (SafetyHookContext &ctx) -#define INSTALL_HOOK(functionName) \ - { \ - LogMessage (LOG_LEVEL_DEBUG, (std::string ("Installing hook for ") + #functionName).c_str ()); \ - original##functionName = safetyhook::create_inline (where##functionName, implOf##functionName); \ +#define INSTALL_HOOK(functionName) \ + { \ + LogMessage (LOG_LEVEL_DEBUG, (std::string ("Installing hook for ") + #functionName).c_str ()); \ + MH_Initialize (); \ + MH_CreateHook ((void *)where##functionName, (void *)implOf##functionName, (void **)(&original##functionName)); \ + MH_EnableHook ((void *)where##functionName); \ } #define INSTALL_HOOK_DYNAMIC(functionName, location) \ @@ -76,7 +83,9 @@ const HMODULE MODULE_HANDLE = GetModuleHandle (nullptr); #define INSTALL_HOOK_DIRECT(location, locationOfHook) \ { \ LogMessage (LOG_LEVEL_DEBUG, (std::string ("Installing direct hook for ") + #location).c_str ()); \ - directHooks.push_back (safetyhook::create_inline ((void *)location, (void *)locationOfHook)); \ + MH_Initialize (); \ + MH_CreateHook ((void *)(location), (void *)(locationOfHook), NULL); \ + MH_EnableHook ((void *)(location)); \ } #define INSTALL_VTABLE_HOOK(className, object, functionName, functionIndex) \ @@ -92,32 +101,29 @@ const HMODULE MODULE_HANDLE = GetModuleHandle (nullptr); } #define INSTALL_MID_HOOK_DYNAMIC(functionName, location) \ - { \ - where##functionName = (void *)location; \ - INSTALL_MID_HOOK (functionName); \ - } + { mapOf##functionName[location] = safetyhook::create_mid (location, implOf##functionName); } bool sendFlag = false; #define SCENE_RESULT_HOOK(functionName, location) \ HOOK (void, functionName, location, i64 a1, i64 a2, i64 a3) { \ if (TestMode::ReadTestModeValue (L"ModInstantResult") != 1 && TestMode::ReadTestModeValue (L"NumberOfStageItem") <= 4) { \ - original##functionName.call (a1, a2, a3); \ + original##functionName (a1, a2, a3); \ return; \ } \ sendFlag = true; \ - original##functionName.call (a1, a2, a3); \ + original##functionName (a1, a2, a3); \ ExecuteSendResultData (); \ } #define SEND_RESULT_HOOK(functionName, location) \ HOOK (void, functionName, location, i64 a1) { \ if (TestMode::ReadTestModeValue (L"ModInstantResult") != 1 && TestMode::ReadTestModeValue (L"NumberOfStageItem") <= 4) { \ - original##functionName.call (a1); \ + original##functionName (a1); \ return; \ } \ if (sendFlag) { \ sendFlag = false; \ - original##functionName.call (a1); \ + original##functionName (a1); \ } \ } @@ -189,7 +195,6 @@ const std::string readConfigString (toml_table_t *table, const std::string &key, std::vector readConfigIntArray (toml_table_t *table, const std::string &key, std::vector notFoundValue); std::wstring replace (const std::wstring orignStr, const std::wstring oldStr, const std::wstring newStr); std::string replace (const std::string orignStr, const std::string oldStr, const std::string newStr); -std::vector directHooks = {}; const char *GameVersionToString (GameVersion version); const char *languageStr (int language); std::string ConvertWideToUtf8 (const std::wstring &wstr); diff --git a/src/patches/amauth.cpp b/src/patches/amauth.cpp index 9463ccc..941932c 100644 --- a/src/patches/amauth.cpp +++ b/src/patches/amauth.cpp @@ -1,7 +1,7 @@ #include "helpers.h" #include #include -#include +#include #include #include #include @@ -533,7 +533,8 @@ public: virtual HRESULT LockServer (int32_t lock) { return 0; } }; -SafetyHookInline g_origCoCreateInstance{}; +static HRESULT (STDAPICALLTYPE *g_origCoCreateInstance) (const IID *const rclsid, LPUNKNOWN pUnkOuter, DWORD dwClsContext, const IID *const riid, + LPVOID *ppv); static HRESULT STDAPICALLTYPE CoCreateInstanceHook (const IID *const rclsid, LPUNKNOWN pUnkOuter, DWORD dwClsContext, const IID *const riid, LPVOID *ppv) { @@ -548,7 +549,7 @@ CoCreateInstanceHook (const IID *const rclsid, LPUNKNOWN pUnkOuter, DWORD dwClsC auto cauth = new CAuth (); result = cauth->QueryInterface (*riid, ppv); } else { - result = g_origCoCreateInstance.call (rclsid, pUnkOuter, dwClsContext, riid, ppv); + result = g_origCoCreateInstance (rclsid, pUnkOuter, dwClsContext, riid, ppv); } CoTaskMemFree (clsidStr); @@ -560,7 +561,10 @@ void Init () { LogMessage (LOG_LEVEL_DEBUG, "Init AmAuth patches"); - g_origCoCreateInstance = safetyhook::create_inline (PROC_ADDRESS ("ole32.dll", "CoCreateInstance"), CoCreateInstanceHook); + MH_Initialize (); + MH_CreateHookApi (L"ole32.dll", "CoCreateInstance", (LPVOID)CoCreateInstanceHook, + (void **)&g_origCoCreateInstance); // NOLINT(clang-diagnostic-microsoft-cast) + MH_EnableHook (nullptr); struct addrinfo *res = 0; getaddrinfo (server.c_str (), "", 0, &res); diff --git a/src/patches/audio.cpp b/src/patches/audio.cpp index 33b4bb9..c2fa487 100644 --- a/src/patches/audio.cpp +++ b/src/patches/audio.cpp @@ -28,10 +28,10 @@ HOOK_DYNAMIC (i64, NUSCDeviceInit, void *a1, nusc_init_config_t *a2, nusc_init_c a2->device_mode = asio; a2->asio_driver_name = asio ? asioDriver.c_str () : ""; a2->wasapi_exclusive = asio ? 1 : wasapiShared ? 0 : 1; - return originalNUSCDeviceInit.call (a1, a2, a3, a4); + return originalNUSCDeviceInit (a1, a2, a3, a4); } HOOK_DYNAMIC (bool, LoadASIODriver, void *a1, const char *a2) { - auto result = originalLoadASIODriver.call (a1, a2); + auto result = originalLoadASIODriver (a1, a2); if (!result) { LogMessage (LOG_LEVEL_ERROR, (std::string ("Failed to load ASIO driver ") + asioDriver).c_str ()); MessageBoxA (nullptr, "Failed to load ASIO driver", nullptr, MB_OK); diff --git a/src/patches/dxgi.cpp b/src/patches/dxgi.cpp index e3927df..36e372c 100644 --- a/src/patches/dxgi.cpp +++ b/src/patches/dxgi.cpp @@ -10,7 +10,7 @@ #include "dxgi1_5.h" #include "dxgi1_6.h" #include "helpers.h" -#include +#include #include "bnusio.h" #include "patches.h" @@ -22,10 +22,6 @@ namespace patches::Dxgi { -SafetyHookInline g_origCreateDXGIFactory{}; -SafetyHookInline g_origCreateDXGIFactory2{}; -SafetyHookInline g_origD3D11CreateDeviceAndSwapChain{}; - // Local variables static bool FpsLimiterEnable = false; @@ -40,6 +36,13 @@ static HRESULT (STDMETHODCALLTYPE *g_oldPresentWrap) (IDXGISwapChain *pSwapChain static HRESULT (STDMETHODCALLTYPE *g_oldPresent1Wrap) (IDXGISwapChain1 *pSwapChain, UINT SyncInterval, UINT Flags); static HRESULT (STDMETHODCALLTYPE *g_oldCreateSwapChain2) (IDXGIFactory2 *This, IUnknown *pDevice, DXGI_SWAP_CHAIN_DESC *pDesc, IDXGISwapChain **ppSwapChain); +static HRESULT (WINAPI *g_origCreateDXGIFactory2) (UINT Flags, REFIID riid, void **ppFactory); +static HRESULT (WINAPI *g_origCreateDXGIFactory) (REFIID, void **); +static HRESULT (WINAPI *g_origD3D11CreateDeviceAndSwapChain) (IDXGIAdapter *pAdapter, D3D_DRIVER_TYPE DriverType, HMODULE Software, UINT Flags, + const D3D_FEATURE_LEVEL *pFeatureLevels, UINT FeatureLevels, UINT SDKVersion, + /*const*/ DXGI_SWAP_CHAIN_DESC *pSwapChainDesc, IDXGISwapChain **ppSwapChain, + ID3D11Device **ppDevice, D3D_FEATURE_LEVEL *pFeatureLevel, + ID3D11DeviceContext **ppImmediateContext); static HRESULT STDMETHODCALLTYPE CreateSwapChainWrap (IDXGIFactory *This, IUnknown *pDevice, DXGI_SWAP_CHAIN_DESC *pDesc, IDXGISwapChain **ppSwapChain); @@ -133,7 +136,7 @@ CreateSwapChain2Wrap (IDXGIFactory2 *This, IUnknown *pDevice, DXGI_SWAP_CHAIN_DE static HRESULT WINAPI CreateDXGIFactory2Wrap (UINT Flags, REFIID riid, void **ppFactory) { - HRESULT hr = g_origCreateDXGIFactory2.call (Flags, riid, ppFactory); + HRESULT hr = g_origCreateDXGIFactory2 (Flags, riid, ppFactory); if (SUCCEEDED (hr)) { IDXGIFactory2 *factory = (IDXGIFactory2 *)*ppFactory; @@ -147,7 +150,7 @@ CreateDXGIFactory2Wrap (UINT Flags, REFIID riid, void **ppFactory) { static HRESULT WINAPI CreateDXGIFactoryWrap (REFIID riid, _COM_Outptr_ void **ppFactory) { - HRESULT hr = g_origCreateDXGIFactory.call (riid, ppFactory); + HRESULT hr = g_origCreateDXGIFactory (riid, ppFactory); if (SUCCEEDED (hr)) { int factoryType = 0; @@ -183,8 +186,8 @@ D3D11CreateDeviceAndSwapChainWrap (IDXGIAdapter *pAdapter, D3D_DRIVER_TYPE Drive const D3D_FEATURE_LEVEL *pFeatureLevels, UINT FeatureLevels, UINT SDKVersion, /*const*/ DXGI_SWAP_CHAIN_DESC *pSwapChainDesc, IDXGISwapChain **ppSwapChain, ID3D11Device **ppDevice, D3D_FEATURE_LEVEL *pFeatureLevel, ID3D11DeviceContext **ppImmediateContext) { - HRESULT hr = g_origD3D11CreateDeviceAndSwapChain.call (pAdapter, DriverType, Software, Flags, pFeatureLevels, FeatureLevels, SDKVersion, - pSwapChainDesc, ppSwapChain, ppDevice, pFeatureLevel, ppImmediateContext); + HRESULT hr = g_origD3D11CreateDeviceAndSwapChain (pAdapter, DriverType, Software, Flags, pFeatureLevels, FeatureLevels, SDKVersion, + pSwapChainDesc, ppSwapChain, ppDevice, pFeatureLevel, ppImmediateContext); if (ppSwapChain) { if (FpsLimiterEnable) { @@ -211,10 +214,12 @@ Init () { FpsLimiterEnable = fpsLimit > 0; patches::FpsLimiter::Init ((float)fpsLimit); - g_origCreateDXGIFactory = safetyhook::create_inline (PROC_ADDRESS ("dxgi.dll", "CreateDXGIFactory"), CreateDXGIFactoryWrap); - g_origCreateDXGIFactory2 = safetyhook::create_inline (PROC_ADDRESS ("dxgi.dll", "CreateDXGIFactory2"), CreateDXGIFactory2Wrap); - g_origD3D11CreateDeviceAndSwapChain - = safetyhook::create_inline (PROC_ADDRESS ("d3d11.dll", "D3D11CreateDeviceAndSwapChain"), D3D11CreateDeviceAndSwapChainWrap); + MH_Initialize (); + MH_CreateHookApi (L"dxgi.dll", "CreateDXGIFactory", (LPVOID)CreateDXGIFactoryWrap, (void **)&g_origCreateDXGIFactory); + MH_CreateHookApi (L"dxgi.dll", "CreateDXGIFactory2", (LPVOID)CreateDXGIFactory2Wrap, (void **)&g_origCreateDXGIFactory2); + MH_CreateHookApi (L"d3d11.dll", "D3D11CreateDeviceAndSwapChain", (LPVOID)D3D11CreateDeviceAndSwapChainWrap, + (void **)&g_origD3D11CreateDeviceAndSwapChain); + MH_EnableHook (MH_ALL_HOOKS); } } // namespace patches::Dxgi \ No newline at end of file diff --git a/src/patches/layeredfs.cpp b/src/patches/layeredfs.cpp index 923187e..43b53fc 100644 --- a/src/patches/layeredfs.cpp +++ b/src/patches/layeredfs.cpp @@ -2,7 +2,7 @@ #include #include -bool useLayeredFs = false; +bool useLayeredFs = false; std::string datatableKey = "3530304242323633353537423431384139353134383346433246464231354534"; std::string fumenKey = "4434423946383537303842433443383030333843444132343339373531353830"; @@ -278,8 +278,8 @@ HOOK (HANDLE, CreateFileAHook, PROC_ADDRESS ("kernel32.dll", "CreateFileA"), LPC } } - return originalCreateFileAHook.call (currentFileName.c_str (), dwDesiredAccess, dwShareMode, lpSecurityAttributes, dwCreationDisposition, - dwFlagsAndAttributes, hTemplateFile); + return originalCreateFileAHook (currentFileName.c_str (), dwDesiredAccess, dwShareMode, lpSecurityAttributes, dwCreationDisposition, + dwFlagsAndAttributes, hTemplateFile); } // HOOK (HANDLE, CreateFileWHook, PROC_ADDRESS ("kernel32.dll", "CreateFileW"), LPCWSTR lpFileName, DWORD dwDesiredAccess, DWORD dwShareMode, diff --git a/src/patches/testmode.cpp b/src/patches/testmode.cpp index 20f370c..5316470 100644 --- a/src/patches/testmode.cpp +++ b/src/patches/testmode.cpp @@ -180,7 +180,7 @@ HOOK_DYNAMIC (void, TestModeSetMenuHook, u64 testModeLibrary, const wchar_t *lFi } LogMessage (LOG_LEVEL_DEBUG, L"TestModeLibrary load: " + fileName); - originalTestModeSetMenuHook.call (testModeLibrary, fileName.c_str ()); + originalTestModeSetMenuHook (testModeLibrary, fileName.c_str ()); } void diff --git a/src/patches/versions/CHN00.cpp b/src/patches/versions/CHN00.cpp index 65cfa94..d1639f6 100644 --- a/src/patches/versions/CHN00.cpp +++ b/src/patches/versions/CHN00.cpp @@ -50,7 +50,7 @@ HOOK (i64, AvailableMode_Collabo026, ASLR (0x1402BC9B0), i64 a1) { HOOK (i64, GetLanguage, ASLR (0x140023720), i64 a1) { LogMessage (LOG_LEVEL_HOOKS, "GetLanguage was called"); - auto result = originalGetLanguage.call (a1); + auto result = originalGetLanguage (a1); language = *((u32 *)result); return result; } diff --git a/src/patches/versions/JPN39.cpp b/src/patches/versions/JPN39.cpp index 1c2650a..284e344 100644 --- a/src/patches/versions/JPN39.cpp +++ b/src/patches/versions/JPN39.cpp @@ -12,15 +12,15 @@ HOOK_DYNAMIC (char, AMFWTerminate, i64) { HOOK_DYNAMIC (i64, curl_easy_setopt, i64 a1, i64 a2, i64 a3, i64 a4, i64 a5) { LogMessage (LOG_LEVEL_HOOKS, "Garmc curl_easy_setopt was called"); - originalcurl_easy_setopt.call (a1, 64, 0, 0, 0); - originalcurl_easy_setopt.call (a1, 81, 0, 0, 0); - return originalcurl_easy_setopt.call (a1, a2, a3, a4, a5); + originalcurl_easy_setopt (a1, 64, 0, 0, 0); + originalcurl_easy_setopt (a1, 81, 0, 0, 0); + return originalcurl_easy_setopt (a1, a2, a3, a4, a5); } FUNCTION_PTR (i64, GetPlayDataManagerRef, ASLR (0x140024AC0), i64); i64 lua_State = 0; -HOOK (i64, luaL_newstate, PROC_ADDRESS ("lua51.dll", "luaL_newstate")) { return lua_State = originalluaL_newstate.call (); } +HOOK (i64, luaL_newstate, PROC_ADDRESS ("lua51.dll", "luaL_newstate")) { return lua_State = originalluaL_newstate (); } FUNCTION_PTR (void, lua_settop, PROC_ADDRESS ("lua51.dll", "lua_settop"), i64, i32); FUNCTION_PTR (void, lua_replace, PROC_ADDRESS ("lua51.dll", "lua_replace"), i64, i32); FUNCTION_PTR (void, lua_pushcclosure, PROC_ADDRESS ("lua51.dll", "lua_pushcclosure"), i64, i64, i32); @@ -50,7 +50,7 @@ HOOK (i64, DeviceCheck, ASLR (0x140464FC0), i64 a1, i64 a2, i64 a3) { LogMessage (LOG_LEVEL_HOOKS, "DeviceCheck was called"); TestMode::SetupAccessor (a3, RefTestModeMain); componentAccessor = a2; - return originalDeviceCheck.call (a1, a2, a3); + return originalDeviceCheck (a1, a2, a3); } int @@ -65,34 +65,34 @@ GetUserStatus () { HOOK (i64, AvailableMode_Collabo024, ASLR (0x1402DE710), i64 a1) { LogMessage (LOG_LEVEL_HOOKS, "AvailableMode_Collabo024 was called"); int tournamentMode = TestMode::ReadTestModeValue (L"TournamentMode"); - if (tournamentMode == 1) return originalAvailableMode_Collabo024.call (a1); + if (tournamentMode == 1) return originalAvailableMode_Collabo024 (a1); int status = TestMode::ReadTestModeValue (L"ModModeCollabo024"); if (status == 1 && GetUserStatus () == 1) return lua_pushbool (a1, true); - return originalAvailableMode_Collabo024.call (a1); + return originalAvailableMode_Collabo024 (a1); } HOOK (i64, AvailableMode_Collabo025, ASLR (0x1402DE6B0), i64 a1) { LogMessage (LOG_LEVEL_HOOKS, "AvailableMode_Collabo025 was called"); int tournamentMode = TestMode::ReadTestModeValue (L"TournamentMode"); - if (tournamentMode == 1) return originalAvailableMode_Collabo025.call (a1); + if (tournamentMode == 1) return originalAvailableMode_Collabo025 (a1); int status = TestMode::ReadTestModeValue (L"ModModeCollabo025"); if (status == 1 && GetUserStatus () == 1) return lua_pushbool (a1, true); - return originalAvailableMode_Collabo025.call (a1); + return originalAvailableMode_Collabo025 (a1); } HOOK (i64, AvailableMode_Collabo026, ASLR (0x1402DE670), i64 a1) { LogMessage (LOG_LEVEL_HOOKS, "AvailableMode_Collabo026 was called"); int tournamentMode = TestMode::ReadTestModeValue (L"TournamentMode"); - if (tournamentMode == 1) return originalAvailableMode_Collabo026.call (a1); + if (tournamentMode == 1) return originalAvailableMode_Collabo026 (a1); int status = TestMode::ReadTestModeValue (L"ModModeCollabo026"); if (status == 1 && GetUserStatus () == 1) return lua_pushbool (a1, true); - return originalAvailableMode_Collabo026.call (a1); + return originalAvailableMode_Collabo026 (a1); } HOOK (i64, AvailableMode_AprilFool001, ASLR (0x1402DE5B0), i64 a1) { LogMessage (LOG_LEVEL_HOOKS, "AvailableMode_AprilFool001 was called"); int tournamentMode = TestMode::ReadTestModeValue (L"TournamentMode"); - if (tournamentMode == 1) return originalAvailableMode_AprilFool001.call (a1); + if (tournamentMode == 1) return originalAvailableMode_AprilFool001 (a1); int status = TestMode::ReadTestModeValue (L"ModModeAprilFool001"); if (status == 1) return lua_pushbool (a1, true); - return originalAvailableMode_AprilFool001.call (a1); + return originalAvailableMode_AprilFool001 (a1); } i64 __fastcall lua_freeze_timer (i64 a1) { LogMessage (LOG_LEVEL_HOOKS, "lua_freeze_timer was called"); @@ -172,7 +172,7 @@ CHANGE_RESULT_SIZE_HOOK (ChangeResultDataSize_Enso, ASLR (0x140180074), rax); CHANGE_RESULT_SIZE_HOOK (ChangeResultDataSize_AI, ASLR (0x140173774), rax); CHANGE_RESULT_SIZE_HOOK (ChangeResultDataSize_Collabo025_026, ASLR (0x140178244), rax); CHANGE_RESULT_SIZE_HOOK (ChangeResultDataSize_AprilFool, ASLR (0x140176044), rax); - + CHANGE_RESULT_INDEX_HOOK (ChangeResultDataIndex_Enso, ASLR (0x14018074B), rax, 0x34, 0x07); CHANGE_RESULT_INDEX_HOOK (ChangeResultDataIndex_AI, ASLR (0x140173EDD), r13, 0x24, 0x08); CHANGE_RESULT_INDEX_HOOK (ChangeResultDataIndex_Collabo025_026, ASLR (0x1401789AD), r13, 0x24, 0x08); @@ -180,7 +180,7 @@ CHANGE_RESULT_INDEX_HOOK (ChangeResultDataIndex_AprilFool, ASLR (0x140176716), r HOOK (i64, GetLanguage, ASLR (0x140024AC0), i64 a1) { LogMessage (LOG_LEVEL_HOOKS, "GetLanguage was called"); - auto result = originalGetLanguage.call (a1); + auto result = originalGetLanguage (a1); language = *((u32 *)result); return result; } @@ -291,7 +291,7 @@ HOOK (i64, PlaySound, ASLR (0x1404C6DC0), i64 a1) { lua_replace (a1, -3); } } - return originalPlaySound.call (a1); + return originalPlaySound (a1); } HOOK (i64, PlaySoundMulti, ASLR (0x1404C6D60), i64 a1) { @@ -303,7 +303,7 @@ HOOK (i64, PlaySoundMulti, ASLR (0x1404C6D60), i64 a1) { lua_replace (a1, -3); } } - return originalPlaySoundMulti.call (a1); + return originalPlaySoundMulti (a1); } FUNCTION_PTR (u64 *, append_chars_to_basic_string, ASLR (0x140028DA0), u64 *, const char *, size_t); @@ -322,7 +322,7 @@ HOOK (bool, PlaySoundEnso, ASLR (0x1404ED590), u64 *a1, u64 *a2, i64 a3) { std::string bankName = a1[3] > 0x10 ? std::string (*((char **)a1)) : std::string ((char *)a1); if (bankName[0] == 'v') a2 = FixToneNameEnso (a2, bankName); } - return originalPlaySoundEnso.call (a1, a2, a3); + return originalPlaySoundEnso (a1, a2, a3); } HOOK (bool, PlaySoundSpecial, ASLR (0x1404ED230), u64 *a1, u64 *a2) { @@ -331,13 +331,13 @@ HOOK (bool, PlaySoundSpecial, ASLR (0x1404ED230), u64 *a1, u64 *a2) { std::string bankName = a1[3] > 0x10 ? std::string (*((char **)a1)) : std::string ((char *)a1); if (bankName[0] == 'v') a2 = FixToneNameEnso (a2, bankName); } - return originalPlaySoundSpecial.call (a1, a2); + return originalPlaySoundSpecial (a1, a2); } int loaded_fail_count = 0; HOOK (i64, LoadedBankAll, ASLR (0x1404C69F0), i64 a1) { LogMessage (LOG_LEVEL_HOOKS, "LoadedBankAll was called"); - originalLoadedBankAll.call (a1); + originalLoadedBankAll (a1); auto result = lua_toboolean (a1, -1); lua_settop (a1, 0); if (result) { @@ -357,12 +357,12 @@ float soundRate = 1.0F; HOOK (i32, SetMasterVolumeSpeaker, ASLR (0x140160330), i32 a1) { LogMessage (LOG_LEVEL_HOOKS, "SetMasterVolumeSpeaker was called"); soundRate = a1 <= 100 ? 1.0F : a1 / 100.0; - return originalSetMasterVolumeSpeaker.call (a1 > 100 ? 100 : a1); + return originalSetMasterVolumeSpeaker (a1 > 100 ? 100 : a1); } HOOK (u64, NuscBusVolume, ASLR (0x1407B1C30), u64 a1, u64 a2, float a3) { LogMessage (LOG_LEVEL_HOOKS, "NuscBusVolume was called"); - return originalNuscBusVolume.call (a1, a2, a3 * soundRate); + return originalNuscBusVolume (a1, a2, a3 * soundRate); } std::string *fontName = nullptr; @@ -370,13 +370,13 @@ HOOK (u8, SetupFontInfo, ASLR (0x14049D820), u64 a1, u64 a2, size_t a3, u64 a4) LogMessage (LOG_LEVEL_HOOKS, "SetupFontInfo was called"); if (fontName != nullptr) delete fontName; fontName = new std::string (((char *)a1) + 120); - return originalSetupFontInfo.call (a1, a2, a3, a4); + return originalSetupFontInfo (a1, a2, a3, a4); } HOOK (u32, ReadFontInfoInt, ASLR (0x14049EAC0), u64 a1, u64 a2) { LogMessage (LOG_LEVEL_HOOKS, "ReadFontInfoInt was called"); std::string attribute ((char *)a2); - u32 result = originalReadFontInfoInt.call (a1, a2); + u32 result = originalReadFontInfoInt (a1, a2); if (fontName->starts_with ("cn_") && attribute == "offsetV") result += 1; return result; } diff --git a/subprojects/minhook.wrap b/subprojects/minhook.wrap new file mode 100644 index 0000000..467fde3 --- /dev/null +++ b/subprojects/minhook.wrap @@ -0,0 +1,4 @@ +[wrap-git] +url = https://github.com/TsudaKageyu/minhook.git +revision = master +diff_files = minhook.patch \ No newline at end of file diff --git a/subprojects/packagefiles/minhook.patch b/subprojects/packagefiles/minhook.patch new file mode 100644 index 0000000..f194f1c --- /dev/null +++ b/subprojects/packagefiles/minhook.patch @@ -0,0 +1,21 @@ +--- minhook/meson.build ++++ minhook/meson.build +@@ -0,0 +1,18 @@ ++project('minhook', 'c', version: '1.0.0') ++ ++minhook_inc = include_directories('include') ++minhook_lib = static_library( ++ 'minhook', ++ include_directories: minhook_inc, ++ sources: [ ++ 'src/buffer.c', ++ 'src/hook.c', ++ 'src/trampoline.c', ++ 'src/hde/hde32.c', ++ 'src/hde/hde64.c' ++ ] ++) ++minhook_dep = declare_dependency( ++ link_with: minhook_lib, ++ include_directories: minhook_inc, ++)