Migrate hooking library to safetyhook
This commit is contained in:
parent
a57bf3049e
commit
c1d3bdf1ba
1
.gitignore
vendored
1
.gitignore
vendored
@ -3,7 +3,6 @@ xpacks/
|
||||
compile_commands.json
|
||||
package.json
|
||||
.cache
|
||||
subprojects/minhook
|
||||
subprojects/packagecache
|
||||
subprojects/tomlc99
|
||||
subprojects/SDL2-2.26.5
|
||||
|
@ -28,7 +28,6 @@ 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'])
|
||||
@ -48,7 +47,6 @@ libtomcrypt_dep = libtomcrypt.get_variable('tomcrypt_dep')
|
||||
library(
|
||||
'bnusio',
|
||||
link_with: [
|
||||
minhook.get_variable('minhook_lib'),
|
||||
tomlc99.get_variable('tomlc99_lib'),
|
||||
sdl2.get_variable('sdl2'),
|
||||
xxhash.get_variable('xxhash'),
|
||||
@ -58,7 +56,6 @@ 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'),
|
||||
|
@ -183,7 +183,7 @@ bnusio_GetAnalogIn (u8 which) {
|
||||
}
|
||||
}
|
||||
|
||||
u16 __fastcall bnusio_GetCoin (i32 a1) { return coin_count; }
|
||||
u16 bnusio_GetCoin (i32 a1) { return coin_count; }
|
||||
}
|
||||
|
||||
FUNCTION_PTR (i64, bnusio_Open_Original, PROC_ADDRESS ("bnusio_original.dll", "bnusio_Open"));
|
||||
@ -240,7 +240,7 @@ HOOK (i32, bngrw_ReqSendUrl, PROC_ADDRESS ("bngrw.dll", "BngRwReqSendUrlTo")) {
|
||||
HOOK (u64, bngrw_ReqLed, PROC_ADDRESS ("bngrw.dll", "BngRwReqLed")) { return 1; }
|
||||
HOOK (u64, bngrw_ReqBeep, PROC_ADDRESS ("bngrw.dll", "BngRwReqBeep")) { return 1; }
|
||||
HOOK (u64, bngrw_ReqAction, PROC_ADDRESS ("bngrw.dll", "BngRwReqAction")) { return 1; }
|
||||
HOOK (u64, bngrw_ReqSetLedPower, PROC_ADDRESS ("bngrw.dll", "BngRwReqSetLedPower")) { return 0; }
|
||||
HOOK (u64, bngrw_SetLedPower, PROC_ADDRESS ("bngrw.dll", "BngRwSetLedPower")) { return 0; }
|
||||
HOOK (u64, bngrw_GetRetryCount, PROC_ADDRESS ("bngrw.dll", "BngRwGetTotalRetryCount")) { return 0; }
|
||||
HOOK (u64, bngrw_GetFwVersion, PROC_ADDRESS ("bngrw.dll", "BngRwGetFwVersion")) { return 0; }
|
||||
HOOK (u64, bngrw_ReqFwVersionUp, PROC_ADDRESS ("bngrw.dll", "BngRwReqFwVersionUp")) { return 1; }
|
||||
@ -379,7 +379,7 @@ Init () {
|
||||
INSTALL_HOOK (bngrw_ReqLed);
|
||||
INSTALL_HOOK (bngrw_ReqBeep);
|
||||
INSTALL_HOOK (bngrw_ReqAction);
|
||||
INSTALL_HOOK (bngrw_ReqSetLedPower);
|
||||
INSTALL_HOOK (bngrw_SetLedPower);
|
||||
INSTALL_HOOK (bngrw_GetRetryCount);
|
||||
INSTALL_HOOK (bngrw_GetFwVersion);
|
||||
INSTALL_HOOK (bngrw_ReqFwVersionUp);
|
||||
|
@ -32,7 +32,7 @@ std::string datatableKey = "0000000000000000000000000000000000000000000000000000
|
||||
std::string fumenKey = "0000000000000000000000000000000000000000000000000000000000000000";
|
||||
|
||||
HWND hGameWnd;
|
||||
HOOK (i32, ShowMouse, PROC_ADDRESS ("user32.dll", "ShowCursor"), bool) { return originalShowMouse (true); }
|
||||
HOOK (i32, ShowMouse, PROC_ADDRESS ("user32.dll", "ShowCursor"), bool) { return originalShowMouse.call<i32> (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) {
|
||||
@ -40,12 +40,13 @@ 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 (dwExStyle, lpClassName, lpWindowName, dwStyle, X, Y, nWidth, nHeight, hWndParent, hMenu, hInstance, lpParam);
|
||||
hGameWnd = originalCreateWindow.call<HWND> (dwExStyle, lpClassName, lpWindowName, dwStyle, X, Y, nWidth, nHeight, hWndParent, hMenu,
|
||||
hInstance, lpParam);
|
||||
return hGameWnd;
|
||||
}
|
||||
}
|
||||
return originalCreateWindow (dwExStyle, lpClassName, lpWindowName, dwStyle, X, Y, nWidth, nHeight, hWndParent, hMenu, hInstance, lpParam);
|
||||
return originalCreateWindow.call<HWND> (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,
|
||||
u32 uFlags) {
|
||||
@ -56,12 +57,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 (hWnd, hWndInsertAfter, X, Y, cx, cy, uFlags);
|
||||
return originalSetWindowPosition.call<bool> (hWnd, hWndInsertAfter, X, Y, cx, cy, uFlags);
|
||||
}
|
||||
|
||||
HOOK (void, ExitProcessHook, PROC_ADDRESS ("kernel32.dll", "ExitProcess"), u32 uExitCode) {
|
||||
bnusio::Close ();
|
||||
originalExitProcessHook (uExitCode);
|
||||
originalExitProcessHook.call<void> (uExitCode);
|
||||
}
|
||||
|
||||
HOOK (i32, XinputGetState, PROC_ADDRESS ("xinput9_1_0.dll", "XInputGetState")) { return ERROR_DEVICE_NOT_CONNECTED; }
|
||||
@ -78,7 +79,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 (server.c_str (), service, hints, out);
|
||||
return originalws2_getaddrinfo.call<i32> (server.c_str (), service, hints, out);
|
||||
}
|
||||
|
||||
void
|
||||
|
@ -1,6 +1,9 @@
|
||||
#pragma once
|
||||
#include <MinHook.h>
|
||||
#include <atomic>
|
||||
#include <bits/stdc++.h>
|
||||
#include <map>
|
||||
#include <mutex>
|
||||
#include <safetyhook.hpp>
|
||||
#include <stdbool.h>
|
||||
#include <stddef.h>
|
||||
#include <stdint.h>
|
||||
@ -8,10 +11,6 @@
|
||||
#include <stdlib.h>
|
||||
#include <toml.h>
|
||||
#include <windows.h>
|
||||
#include <map>
|
||||
#include <mutex>
|
||||
#include <atomic>
|
||||
#include <safetyhook.hpp>
|
||||
|
||||
typedef int8_t i8;
|
||||
typedef int16_t i16;
|
||||
@ -27,8 +26,8 @@ typedef double f64;
|
||||
#define FUNCTION_PTR(returnType, function, location, ...) returnType (*function) (__VA_ARGS__) = (returnType (*) (__VA_ARGS__)) (location)
|
||||
#define FUNCTION_PTR_H(returnType, function, ...) extern returnType (*function) (__VA_ARGS__)
|
||||
|
||||
#define PROC_ADDRESS(libraryName, procName) GetProcAddress (LoadLibrary (TEXT (libraryName)), procName)
|
||||
#define PROC_ADDRESS_OFFSET(libraryName, offset) (u64)((u64)GetModuleHandle (TEXT (libraryName)) + offset)
|
||||
#define PROC_ADDRESS(libraryName, procName) GetProcAddress (LoadLibrary (TEXT (libraryName)), procName)
|
||||
#define PROC_ADDRESS_OFFSET(libraryName, offset) (u64) ((u64)GetModuleHandle (TEXT (libraryName)) + offset)
|
||||
|
||||
#define BASE_ADDRESS 0x140000000
|
||||
#ifdef BASE_ADDRESS
|
||||
@ -36,47 +35,33 @@ const HMODULE MODULE_HANDLE = GetModuleHandle (nullptr);
|
||||
#define ASLR(address) ((u64)MODULE_HANDLE + (u64)address - (u64)BASE_ADDRESS)
|
||||
#endif
|
||||
|
||||
#define HOOK(returnType, functionName, location, ...) \
|
||||
typedef returnType (*functionName) (__VA_ARGS__); \
|
||||
functionName original##functionName = NULL; \
|
||||
void *where##functionName = (void *)(location); \
|
||||
#define HOOK(returnType, functionName, location, ...) \
|
||||
SafetyHookInline original##functionName{}; \
|
||||
void *where##functionName = (void *)location; \
|
||||
returnType implOf##functionName (__VA_ARGS__)
|
||||
|
||||
#define HOOK_DYNAMIC(returnType, callingConvention, functionName, ...) \
|
||||
typedef returnType callingConvention (*functionName) (__VA_ARGS__); \
|
||||
functionName original##functionName = NULL; \
|
||||
void *where##functionName = NULL; \
|
||||
returnType callingConvention implOf##functionName (__VA_ARGS__)
|
||||
#define HOOK_DYNAMIC(returnType, functionName, ...) \
|
||||
SafetyHookInline original##functionName{}; \
|
||||
void *where##functionName = NULL; \
|
||||
returnType implOf##functionName (__VA_ARGS__)
|
||||
|
||||
#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; \
|
||||
#define VTABLE_HOOK(returnType, className, functionName, ...) \
|
||||
SafetyHookInline original##className##functionName{}; \
|
||||
void *where##className##functionName = NULL; \
|
||||
returnType implOf##className##functionName (className *This, __VA_ARGS__)
|
||||
|
||||
#define HOOK_MID(functionName, location, ...) \
|
||||
SafetyHookMid midHook##functionName{}; \
|
||||
u64 where##functionName = (location); \
|
||||
#define MID_HOOK(functionName, location, ...) \
|
||||
SafetyHookMid midHook##functionName{}; \
|
||||
void *where##functionName = (void *)location; \
|
||||
void implOf##functionName (SafetyHookContext &ctx)
|
||||
|
||||
#define HOOK_MID_DYNAMIC(functionName, location, ...) \
|
||||
SafetyHookMid midHook##functionName{}; \
|
||||
u64 where##functionName = (location); \
|
||||
#define MID_HOOK_DYNAMIC(functionName, ...) \
|
||||
SafetyHookMid midHook##functionName{}; \
|
||||
void *where##functionName = NULL; \
|
||||
void implOf##functionName (SafetyHookContext &ctx)
|
||||
|
||||
#define INSTALL_HOOK(functionName) \
|
||||
{ \
|
||||
MH_Initialize (); \
|
||||
MH_CreateHook ((void *)where##functionName, (void *)implOf##functionName, (void **)(&original##functionName)); \
|
||||
MH_EnableHook ((void *)where##functionName); \
|
||||
}
|
||||
|
||||
#define INSTALL_HOOK_DIRECT(location, locationOfHook) \
|
||||
{ \
|
||||
MH_Initialize (); \
|
||||
MH_CreateHook ((void *)(location), (void *)(locationOfHook), NULL); \
|
||||
MH_EnableHook ((void *)(location)); \
|
||||
}
|
||||
#define INSTALL_HOOK(functionName) \
|
||||
{ original##functionName = safetyhook::create_inline (where##functionName, implOf##functionName); }
|
||||
|
||||
#define INSTALL_HOOK_DYNAMIC(functionName, location) \
|
||||
{ \
|
||||
@ -84,25 +69,22 @@ const HMODULE MODULE_HANDLE = GetModuleHandle (nullptr);
|
||||
INSTALL_HOOK (functionName); \
|
||||
}
|
||||
|
||||
#define INSTALL_HOOK_DIRECT(location, locationOfHook) \
|
||||
{ directHooks.push_back (safetyhook::create_inline ((void *)location, (void *)locationOfHook)); }
|
||||
|
||||
#define INSTALL_VTABLE_HOOK(className, object, functionName, functionIndex) \
|
||||
{ \
|
||||
where##className##functionName = (*(className##functionName ***)object)[functionIndex]; \
|
||||
INSTALL_HOOK (className##functionName); \
|
||||
}
|
||||
|
||||
#define INSTALL_HOOK_MID(functionName) \
|
||||
{ \
|
||||
midHook##functionName = safetyhook::create_mid(where##functionName, implOf##functionName); \
|
||||
}
|
||||
#define INSTALL_MID_HOOK(functionName) \
|
||||
{ midHook##functionName = safetyhook::create_mid (where##functionName, implOf##functionName); }
|
||||
|
||||
#define INSTALL_HOOK_MID_DYNAMIC(functionName, address) \
|
||||
{ \
|
||||
midHook##functionName = safetyhook::create_mid(address, implOf##functionName); \
|
||||
}
|
||||
|
||||
#define UNINSTALL_HOOK_MID(functionName) \
|
||||
{ \
|
||||
midHook##functionName = {}; \
|
||||
#define INSTALL_MID_HOOK_DYNAMIC(functionName, location) \
|
||||
{ \
|
||||
where##functionName = (void *)location; \
|
||||
INSTALL_MID_HOOK (functionName); \
|
||||
}
|
||||
|
||||
#define READ_MEMORY(location, type) *(type *)location
|
||||
@ -158,4 +140,5 @@ bool readConfigBool (toml_table_t *table, const std::string &key, bool notFoundV
|
||||
int64_t readConfigInt (toml_table_t *table, const std::string &key, int64_t notFoundValue);
|
||||
const std::string readConfigString (toml_table_t *table, const std::string &key, const std::string ¬FoundValue);
|
||||
std::vector<int64_t> readConfigIntArray (toml_table_t *table, const std::string &key, std::vector<int64_t> notFoundValue);
|
||||
void printColour (int colour, const char *format, ...);
|
||||
void printColour (int colour, const char *format, ...);
|
||||
std::vector<SafetyHookInline> directHooks = {};
|
@ -1,6 +1,7 @@
|
||||
#include <MinHook.h>
|
||||
#include "helpers.h"
|
||||
#include <bits/stdc++.h>
|
||||
#include <format>
|
||||
#include <safetyhook.hpp>
|
||||
#include <stdbool.h>
|
||||
#include <stddef.h>
|
||||
#include <stdint.h>
|
||||
@ -613,8 +614,7 @@ public:
|
||||
virtual HRESULT LockServer (int32_t lock) { return 0; }
|
||||
};
|
||||
|
||||
static HRESULT (STDAPICALLTYPE *g_origCoCreateInstance) (const IID *const rclsid, LPUNKNOWN pUnkOuter, DWORD dwClsContext, const IID *const riid,
|
||||
LPVOID *ppv);
|
||||
SafetyHookInline g_origCoCreateInstance{};
|
||||
|
||||
static HRESULT STDAPICALLTYPE
|
||||
CoCreateInstanceHook (const IID *const rclsid, LPUNKNOWN pUnkOuter, DWORD dwClsContext, const IID *const riid, LPVOID *ppv) {
|
||||
@ -629,7 +629,7 @@ CoCreateInstanceHook (const IID *const rclsid, LPUNKNOWN pUnkOuter, DWORD dwClsC
|
||||
auto cauth = new CAuth ();
|
||||
result = cauth->QueryInterface (*riid, ppv);
|
||||
} else {
|
||||
result = g_origCoCreateInstance (rclsid, pUnkOuter, dwClsContext, riid, ppv);
|
||||
result = g_origCoCreateInstance.call<HRESULT> (rclsid, pUnkOuter, dwClsContext, riid, ppv);
|
||||
}
|
||||
|
||||
CoTaskMemFree (clsidStr);
|
||||
@ -639,10 +639,7 @@ CoCreateInstanceHook (const IID *const rclsid, LPUNKNOWN pUnkOuter, DWORD dwClsC
|
||||
|
||||
void
|
||||
Init () {
|
||||
MH_Initialize ();
|
||||
MH_CreateHookApi (L"ole32.dll", "CoCreateInstance", (LPVOID)CoCreateInstanceHook,
|
||||
(void **)&g_origCoCreateInstance); // NOLINT(clang-diagnostic-microsoft-cast)
|
||||
MH_EnableHook (nullptr);
|
||||
g_origCoCreateInstance = safetyhook::create_inline (PROC_ADDRESS ("ole32.dll", "CoCreateInstance"), CoCreateInstanceHook);
|
||||
|
||||
struct addrinfo *res = 0;
|
||||
getaddrinfo (server.c_str (), "", 0, &res);
|
||||
|
@ -22,14 +22,14 @@ bool wasapiShared = true;
|
||||
bool asio = false;
|
||||
std::string asioDriver = "";
|
||||
|
||||
HOOK_DYNAMIC (i64, __fastcall, NUSCDeviceInit, void *a1, nusc_init_config_t *a2, nusc_init_config_t *a3, void *a4) {
|
||||
HOOK_DYNAMIC (i64, NUSCDeviceInit, void *a1, nusc_init_config_t *a2, nusc_init_config_t *a3, void *a4) {
|
||||
a2->device_mode = asio;
|
||||
a2->asio_driver_name = asio ? asioDriver.c_str () : "";
|
||||
a2->wasapi_exclusive = asio ? 1 : wasapiShared ? 0 : 1;
|
||||
return originalNUSCDeviceInit (a1, a2, a3, a4);
|
||||
return originalNUSCDeviceInit.call<i64> (a1, a2, a3, a4);
|
||||
}
|
||||
HOOK_DYNAMIC (bool, __fastcall, LoadASIODriver, void *a1, const char *a2) {
|
||||
auto result = originalLoadASIODriver (a1, a2);
|
||||
HOOK_DYNAMIC (bool, LoadASIODriver, void *a1, const char *a2) {
|
||||
auto result = originalLoadASIODriver.call<bool> (a1, a2);
|
||||
if (!result) {
|
||||
MessageBoxA (nullptr, "Failed to load ASIO driver", nullptr, MB_OK);
|
||||
ExitProcess (0);
|
||||
|
@ -10,7 +10,7 @@
|
||||
#include "dxgi1_5.h"
|
||||
#include "dxgi1_6.h"
|
||||
#include "helpers.h"
|
||||
#include <MinHook.h>
|
||||
#include <safetyhook.hpp>
|
||||
|
||||
#include "bnusio.h"
|
||||
#include "patches.h"
|
||||
@ -22,6 +22,10 @@
|
||||
|
||||
namespace patches::Dxgi {
|
||||
|
||||
SafetyHookInline g_origCreateDXGIFactory{};
|
||||
SafetyHookInline g_origCreateDXGIFactory2{};
|
||||
SafetyHookInline g_origD3D11CreateDeviceAndSwapChain{};
|
||||
|
||||
// Local variables
|
||||
static bool FpsLimiterEnable = false;
|
||||
|
||||
@ -36,13 +40,6 @@ 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);
|
||||
@ -136,7 +133,7 @@ CreateSwapChain2Wrap (IDXGIFactory2 *This, IUnknown *pDevice, DXGI_SWAP_CHAIN_DE
|
||||
|
||||
static HRESULT WINAPI
|
||||
CreateDXGIFactory2Wrap (UINT Flags, REFIID riid, void **ppFactory) {
|
||||
HRESULT hr = g_origCreateDXGIFactory2 (Flags, riid, ppFactory);
|
||||
HRESULT hr = g_origCreateDXGIFactory2.call<HRESULT> (Flags, riid, ppFactory);
|
||||
|
||||
if (SUCCEEDED (hr)) {
|
||||
IDXGIFactory2 *factory = (IDXGIFactory2 *)*ppFactory;
|
||||
@ -150,7 +147,7 @@ CreateDXGIFactory2Wrap (UINT Flags, REFIID riid, void **ppFactory) {
|
||||
|
||||
static HRESULT WINAPI
|
||||
CreateDXGIFactoryWrap (REFIID riid, _COM_Outptr_ void **ppFactory) {
|
||||
HRESULT hr = g_origCreateDXGIFactory (riid, ppFactory);
|
||||
HRESULT hr = g_origCreateDXGIFactory.call<HRESULT> (riid, ppFactory);
|
||||
|
||||
if (SUCCEEDED (hr)) {
|
||||
int factoryType = 0;
|
||||
@ -186,8 +183,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 (pAdapter, DriverType, Software, Flags, pFeatureLevels, FeatureLevels, SDKVersion,
|
||||
pSwapChainDesc, ppSwapChain, ppDevice, pFeatureLevel, ppImmediateContext);
|
||||
HRESULT hr = g_origD3D11CreateDeviceAndSwapChain.call<HRESULT> (pAdapter, DriverType, Software, Flags, pFeatureLevels, FeatureLevels, SDKVersion,
|
||||
pSwapChainDesc, ppSwapChain, ppDevice, pFeatureLevel, ppImmediateContext);
|
||||
|
||||
if (ppSwapChain) {
|
||||
if (FpsLimiterEnable) {
|
||||
@ -213,12 +210,10 @@ Init () {
|
||||
FpsLimiterEnable = fpsLimit > 0;
|
||||
patches::FpsLimiter::Init ((float)fpsLimit);
|
||||
|
||||
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);
|
||||
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);
|
||||
}
|
||||
|
||||
} // namespace patches::Dxgi
|
@ -181,8 +181,8 @@ HOOK (HANDLE, CreateFileAHook, PROC_ADDRESS ("kernel32.dll", "CreateFileA"), LPC
|
||||
if (std::filesystem::exists (newPath)) { // If a file exists in the datamod folder
|
||||
if (IsFumenEncrypted (newPath)) { // And if it's an encrypted fumen or a different type of file, use it.
|
||||
std::cout << "Redirecting " << std::filesystem::relative (path).string () << std::endl;
|
||||
return originalCreateFileAHook (newPath.c_str (), dwDesiredAccess, dwShareMode, lpSecurityAttributes, dwCreationDisposition,
|
||||
dwFlagsAndAttributes, hTemplateFile);
|
||||
return originalCreateFileAHook.call<HANDLE> (newPath.c_str (), dwDesiredAccess, dwShareMode, lpSecurityAttributes,
|
||||
dwCreationDisposition, dwFlagsAndAttributes, hTemplateFile);
|
||||
} else { // Otherwise if it's an unencrypted fumen.
|
||||
if (!std::filesystem::exists (encPath)) { // We check if we don't already have a cached file.
|
||||
if (fumenKey.length () == 64) {
|
||||
@ -197,8 +197,8 @@ HOOK (HANDLE, CreateFileAHook, PROC_ADDRESS ("kernel32.dll", "CreateFileA"), LPC
|
||||
encPath = path.string ();
|
||||
}
|
||||
} else std::cout << "Using cached file for " << std::filesystem::relative (newPath) << std::endl;
|
||||
return originalCreateFileAHook (encPath.c_str (), dwDesiredAccess, dwShareMode, lpSecurityAttributes, dwCreationDisposition,
|
||||
dwFlagsAndAttributes, hTemplateFile);
|
||||
return originalCreateFileAHook.call<HANDLE> (encPath.c_str (), dwDesiredAccess, dwShareMode, lpSecurityAttributes,
|
||||
dwCreationDisposition, dwFlagsAndAttributes, hTemplateFile);
|
||||
}
|
||||
}
|
||||
|
||||
@ -230,13 +230,13 @@ HOOK (HANDLE, CreateFileAHook, PROC_ADDRESS ("kernel32.dll", "CreateFileA"), LPC
|
||||
} else
|
||||
std::cout << "Using cached file for " << std::filesystem::relative (json_path)
|
||||
<< std::endl; // Otherwise use the already encrypted file.
|
||||
return originalCreateFileAHook (encPath.c_str (), dwDesiredAccess, dwShareMode, lpSecurityAttributes, dwCreationDisposition,
|
||||
dwFlagsAndAttributes, hTemplateFile);
|
||||
return originalCreateFileAHook.call<HANDLE> (encPath.c_str (), dwDesiredAccess, dwShareMode, lpSecurityAttributes, dwCreationDisposition,
|
||||
dwFlagsAndAttributes, hTemplateFile);
|
||||
}
|
||||
}
|
||||
|
||||
return originalCreateFileAHook (lpFileName, dwDesiredAccess, dwShareMode, lpSecurityAttributes, dwCreationDisposition, dwFlagsAndAttributes,
|
||||
hTemplateFile);
|
||||
return originalCreateFileAHook.call<HANDLE> (lpFileName, dwDesiredAccess, dwShareMode, lpSecurityAttributes, dwCreationDisposition,
|
||||
dwFlagsAndAttributes, hTemplateFile);
|
||||
}
|
||||
|
||||
// HOOK (HANDLE, CreateFileWHook, PROC_ADDRESS ("kernel32.dll", "CreateFileW"), LPCWSTR lpFileName, DWORD dwDesiredAccess, DWORD dwShareMode,
|
||||
|
@ -38,29 +38,29 @@ std::string accessCode;
|
||||
std::vector<HMODULE> qrPlugins;
|
||||
bool qrPluginRegistered = false;
|
||||
|
||||
HOOK_DYNAMIC (char, __fastcall, QrInit, i64) { return 1; }
|
||||
HOOK_DYNAMIC (char, __fastcall, QrClose, i64) { return 1; }
|
||||
HOOK_DYNAMIC (char, __fastcall, QrRead, i64 a1) {
|
||||
HOOK_DYNAMIC (char, QrInit, i64) { return 1; }
|
||||
HOOK_DYNAMIC (char, QrClose, i64) { return 1; }
|
||||
HOOK_DYNAMIC (char, QrRead, i64 a1) {
|
||||
*(DWORD *)(a1 + 40) = 1;
|
||||
*(DWORD *)(a1 + 16) = 1;
|
||||
*(BYTE *)(a1 + 112) = 0;
|
||||
return 1;
|
||||
}
|
||||
HOOK_DYNAMIC (i64, __fastcall, CallQrUnknown, i64) { return 1; }
|
||||
HOOK_DYNAMIC (bool, __fastcall, Send1, i64 a1) {
|
||||
HOOK_DYNAMIC (i64, CallQrUnknown, i64) { return 1; }
|
||||
HOOK_DYNAMIC (bool, Send1, i64 a1) {
|
||||
*(BYTE *)(a1 + 88) = 1;
|
||||
*(i64 *)(a1 + 32) = *(i64 *)(a1 + 24);
|
||||
*(WORD *)(a1 + 89) = 0;
|
||||
return true;
|
||||
}
|
||||
HOOK_DYNAMIC (bool, __fastcall, Send2, i64 a1) {
|
||||
HOOK_DYNAMIC (bool, Send2, i64 a1) {
|
||||
*(WORD *)(a1 + 88) = 0;
|
||||
*(BYTE *)(a1 + 90) = 0;
|
||||
return true;
|
||||
}
|
||||
HOOK_DYNAMIC (bool, __fastcall, Send3, i64, char) { return true; }
|
||||
HOOK_DYNAMIC (bool, __fastcall, Send4, i64, const void *, i64) { return true; }
|
||||
HOOK_DYNAMIC (i64, __fastcall, CopyData, i64, void *dest, int length) {
|
||||
HOOK_DYNAMIC (bool, Send3, i64, char) { return true; }
|
||||
HOOK_DYNAMIC (bool, Send4, i64, const void *, i64) { return true; }
|
||||
HOOK_DYNAMIC (i64, CopyData, i64, void *dest, int length) {
|
||||
if (gState == State::CopyWait) {
|
||||
std::cout << "Copy data, length: " << length << std::endl;
|
||||
|
||||
|
@ -51,7 +51,7 @@ languageStr () {
|
||||
}
|
||||
}
|
||||
HOOK (i64, GetLanguage, ASLR (0x140023720), i64 a1) {
|
||||
auto result = originalGetLanguage (a1);
|
||||
auto result = originalGetLanguage.call<i64> (a1);
|
||||
language = *((u32 *)result);
|
||||
return result;
|
||||
}
|
||||
@ -66,7 +66,7 @@ HOOK (i64, GetCabinetLanguage, ASLR (0x1401AF270), i64, i64 a2) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
HOOK_DYNAMIC (char, __fastcall, AMFWTerminate, i64) { return 0; }
|
||||
HOOK_DYNAMIC (char, AMFWTerminate, i64) { return 0; }
|
||||
|
||||
const i32 datatableBufferSize = 1024 * 1024 * 12;
|
||||
safetyhook::Allocation datatableBuffer1;
|
||||
|
@ -13,7 +13,7 @@ extern void *song_data;
|
||||
|
||||
namespace patches::JPN00 {
|
||||
|
||||
HOOK_DYNAMIC (char, __fastcall, AMFWTerminate, i64) { return 0; }
|
||||
HOOK_DYNAMIC (char, AMFWTerminate, i64) { return 0; }
|
||||
|
||||
const i32 datatableBufferSize = 1024 * 1024 * 12;
|
||||
safetyhook::Allocation datatableBuffer;
|
||||
|
@ -13,7 +13,7 @@ extern void *song_data;
|
||||
|
||||
namespace patches::JPN08 {
|
||||
|
||||
HOOK_DYNAMIC (char, __fastcall, AMFWTerminate, i64) { return 0; }
|
||||
HOOK_DYNAMIC (char, AMFWTerminate, i64) { return 0; }
|
||||
|
||||
const i32 datatableBufferSize = 1024 * 1024 * 12;
|
||||
safetyhook::Allocation datatableBuffer;
|
||||
|
@ -3,16 +3,15 @@
|
||||
#include <iostream>
|
||||
#include <safetyhook.hpp>
|
||||
|
||||
|
||||
namespace patches::JPN39 {
|
||||
|
||||
HOOK_DYNAMIC (char, __fastcall, AMFWTerminate, i64) { return 0; }
|
||||
HOOK_DYNAMIC (char, AMFWTerminate, i64) { return 0; }
|
||||
|
||||
HOOK_DYNAMIC (i64, __fastcall, curl_easy_setopt, i64 a1, i64 a2, i64 a3, i64 a4, i64 a5) {
|
||||
HOOK_DYNAMIC (i64, curl_easy_setopt, i64 a1, i64 a2, i64 a3, i64 a4, i64 a5) {
|
||||
// printf ("garmc curl_easy_setopt\n");
|
||||
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);
|
||||
originalcurl_easy_setopt.call<i64> (a1, 64, 0, 0, 0);
|
||||
originalcurl_easy_setopt.call<i64> (a1, 81, 0, 0, 0);
|
||||
return originalcurl_easy_setopt.call<i64> (a1, a2, a3, a4, a5);
|
||||
}
|
||||
|
||||
FUNCTION_PTR (i64, lua_settop, PROC_ADDRESS ("lua51.dll", "lua_settop"), u64, u64);
|
||||
@ -65,14 +64,17 @@ ReplaceLeaBufferAddress (const std::vector<uintptr_t> &bufferAddresses, void *ne
|
||||
|
||||
// -------------- MidHook Area --------------
|
||||
|
||||
HOOK_MID (ChangeLanguageType, ASLR (0x1400B2016), SafetyHookContext &ctx) {
|
||||
MID_HOOK (ChangeLanguageType, ASLR (0x1400B2016), SafetyHookContext &ctx) {
|
||||
int *pFontType = (int *)ctx.rax;
|
||||
if (*pFontType == 4) *pFontType = 2;
|
||||
}
|
||||
|
||||
i64 __fastcall lua_freeze_timer (i64 a1) { return lua_pushtrue (a1); }
|
||||
i64
|
||||
lua_freeze_timer (i64 a1) {
|
||||
return lua_pushtrue (a1);
|
||||
}
|
||||
|
||||
HOOK_MID (FreezeTimer, ASLR (0x14019FF51), SafetyHookContext &ctx) {
|
||||
MID_HOOK (FreezeTimer, ASLR (0x14019FF51), SafetyHookContext &ctx) {
|
||||
auto a1 = ctx.rdi;
|
||||
int v9 = (int)(ctx.rax + 1);
|
||||
lua_pushcclosure (a1, reinterpret_cast<i64> (&lua_freeze_timer), v9);
|
||||
@ -127,7 +129,7 @@ check_voice_tail (std::string bankName, uint8_t *pBinfBlock, std::map<std::strin
|
||||
}
|
||||
}
|
||||
|
||||
HOOK_MID (GenNus3bankId, ASLR (0x1407B97BD), SafetyHookContext &ctx) {
|
||||
MID_HOOK (GenNus3bankId, ASLR (0x1407B97BD), SafetyHookContext &ctx) {
|
||||
std::lock_guard<std::mutex> lock (nus3bankMtx);
|
||||
if ((uint8_t **)(ctx.rcx + 8) != nullptr) {
|
||||
uint8_t *pNus3bankFile = *((uint8_t **)(ctx.rcx + 8));
|
||||
@ -157,7 +159,7 @@ languageStr () {
|
||||
}
|
||||
}
|
||||
HOOK (i64, GetLanguage, ASLR (0x140024AC0), i64 a1) {
|
||||
auto result = originalGetLanguage (a1);
|
||||
auto result = originalGetLanguage.call<i64> (a1);
|
||||
language = *((u32 *)result);
|
||||
return result;
|
||||
}
|
||||
@ -189,7 +191,7 @@ HOOK (i64, PlaySound, ASLR (0x1404C6DC0), i64 a1) {
|
||||
lua_replace (a1, -3);
|
||||
}
|
||||
}
|
||||
return originalPlaySound (a1);
|
||||
return originalPlaySound.call<i64> (a1);
|
||||
}
|
||||
|
||||
HOOK (i64, PlaySoundMulti, ASLR (0x1404C6D60), i64 a1) {
|
||||
@ -200,16 +202,15 @@ HOOK (i64, PlaySoundMulti, ASLR (0x1404C6D60), i64 a1) {
|
||||
lua_replace (a1, -3);
|
||||
}
|
||||
}
|
||||
return originalPlaySoundMulti (a1);
|
||||
return originalPlaySoundMulti.call<i64> (a1);
|
||||
}
|
||||
|
||||
FUNCTION_PTR (u64 *, append_chars_to_basic_string, ASLR (0x140028DA0), u64 *, char *, size_t);
|
||||
FUNCTION_PTR (u64 *, append_chars_to_basic_string, ASLR (0x140028DA0), u64 *, const char *, size_t);
|
||||
|
||||
u64 *
|
||||
FixToneNameEnso (u64 *Src, std::string &bankName) {
|
||||
if (language == 2 || language == 4) {
|
||||
if (voiceCnExist.find (bankName) != voiceCnExist.end () && voiceCnExist[bankName])
|
||||
Src = append_chars_to_basic_string (Src, (const char *)"_cn", 3);
|
||||
if (voiceCnExist.find (bankName) != voiceCnExist.end () && voiceCnExist[bankName]) Src = append_chars_to_basic_string (Src, "_cn", 3);
|
||||
}
|
||||
return Src;
|
||||
}
|
||||
@ -219,7 +220,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 (a1, a2, a3);
|
||||
return originalPlaySoundEnso.call<bool> (a1, a2, a3);
|
||||
}
|
||||
|
||||
HOOK (bool, PlaySoundSpecial, ASLR (0x1404ED230), u64 *a1, u64 *a2) {
|
||||
@ -227,12 +228,12 @@ 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 (a1, a2);
|
||||
return originalPlaySoundSpecial.call<bool> (a1, a2);
|
||||
}
|
||||
|
||||
int loaded_fail_count = 0;
|
||||
HOOK (i64, LoadedBankAll, ASLR (0x1404C69F0), i64 a1) {
|
||||
originalLoadedBankAll (a1);
|
||||
originalLoadedBankAll.call<i64> (a1);
|
||||
auto result = lua_toboolean (a1, -1);
|
||||
lua_settop (a1, 0);
|
||||
if (result) {
|
||||
@ -349,7 +350,7 @@ Init () {
|
||||
}
|
||||
|
||||
// Freeze Timer
|
||||
if (freezeTimer) INSTALL_HOOK_MID (FreezeTimer);
|
||||
if (freezeTimer) INSTALL_MID_HOOK (FreezeTimer);
|
||||
|
||||
// Use chs font/wordlist instead of cht
|
||||
if (chsPatch) {
|
||||
@ -367,7 +368,7 @@ Init () {
|
||||
WRITE_MEMORY (ASLR (0x140CD1AF8), char, "cn_30");
|
||||
WRITE_MEMORY (ASLR (0x140C946A0), char, "chineseSText");
|
||||
WRITE_MEMORY (ASLR (0x140C946B0), char, "chineseSFontType");
|
||||
INSTALL_HOOK_MID (ChangeLanguageType);
|
||||
INSTALL_MID_HOOK (ChangeLanguageType);
|
||||
}
|
||||
}
|
||||
|
||||
@ -394,7 +395,7 @@ Init () {
|
||||
if (modeAprilFool001) INSTALL_HOOK (AvailableMode_AprilFool001);
|
||||
|
||||
// Fix normal song play after passing through silent song
|
||||
INSTALL_HOOK_MID (GenNus3bankId);
|
||||
INSTALL_MID_HOOK (GenNus3bankId);
|
||||
INSTALL_HOOK (LoadedBankAll);
|
||||
|
||||
// Disable live check
|
||||
|
@ -1,4 +0,0 @@
|
||||
[wrap-git]
|
||||
url = https://github.com/TsudaKageyu/minhook.git
|
||||
revision = master
|
||||
diff_files = minhook.patch
|
@ -1,21 +0,0 @@
|
||||
--- 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,
|
||||
+)
|
Loading…
x
Reference in New Issue
Block a user