Skip to content

Commit

Permalink
replace minhook with safetyhook
Browse files Browse the repository at this point in the history
  • Loading branch information
ThirteenAG committed Jan 29, 2024
1 parent ed78e82 commit 8988c3b
Show file tree
Hide file tree
Showing 8 changed files with 55 additions and 43 deletions.
32 changes: 12 additions & 20 deletions premake5.lua
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,9 @@ workspace "XboxRainDroplets"
includedirs { "external/hooking" }
includedirs { "external/injector/include" }
includedirs { "external/FusionDxHook/includes" }
includedirs { "external/FusionDxHook/minhook" }
includedirs { "external/FusionDxHook/minhook/include" }
includedirs { "external/FusionDxHook/minhook/src" }
includedirs { "external/FusionDxHook/includes/safetyhook" }
includedirs { "external/sire" }
files { "external/FusionDxHook/includes/minhook/include/*.*" }
files { "external/FusionDxHook/includes/minhook/src/*.*" }
files { "external/FusionDxHook/includes/minhook/src/hde/*.*" }
files { "external/FusionDxHook/includes/safetyhook/*.*" }
files { "external/sire/sire.h" }
local dxsdk = os.getenv "DXSDK_DIR"
if dxsdk then
Expand Down Expand Up @@ -73,10 +69,10 @@ workspace "XboxRainDroplets"
targetdir ("bin")
end

prebuildcommands {
"for /R \"../source/resources/shaders/ps/\" %%f in (*.hlsl) do (\"../source/dxsdk/lib/x86/fxc.exe\" /T ps_3_0 /nologo /E main /Fo \"../source/resources/%%~nf.cso\" %%f)",
"for /R \"../source/resources/shaders/vs/\" %%f in (*.hlsl) do (\"../source/dxsdk/lib/x86/fxc.exe\" /T vs_3_0 /nologo /E main /Fo \"../source/resources/%%~nf.cso\" %%f)",
}
prebuildcommands {
"for /R \"../source/resources/shaders/ps/\" %%f in (*.hlsl) do (\"../source/dxsdk/lib/x86/fxc.exe\" /T ps_3_0 /nologo /E main /Fo \"../source/resources/%%~nf.cso\" %%f)",
"for /R \"../source/resources/shaders/vs/\" %%f in (*.hlsl) do (\"../source/dxsdk/lib/x86/fxc.exe\" /T vs_3_0 /nologo /E main /Fo \"../source/resources/%%~nf.cso\" %%f)",
}

filter "configurations:Debug"
defines { "DEBUG" }
Expand Down Expand Up @@ -148,16 +144,12 @@ workspace "XboxRainDropletsWrapper"
includedirs { "external/hooking" }
includedirs { "external/injector/include" }
includedirs { "external/FusionDxHook/includes" }
includedirs { "external/FusionDxHook/minhook" }
includedirs { "external/FusionDxHook/minhook/include" }
includedirs { "external/FusionDxHook/minhook/src" }
includedirs { "external/FusionDxHook/includes/safetyhook" }
includedirs { "external/sire" }
includedirs { "source/dxsdk/dx8" }
libdirs { "source/dxsdk/dx8" }

files { "external/FusionDxHook/includes/minhook/include/*.*" }
files { "external/FusionDxHook/includes/minhook/src/*.*" }
files { "external/FusionDxHook/includes/minhook/src/hde/*.*" }
files { "external/FusionDxHook/includes/safetyhook/*.*" }
files { "external/sire/sire.h" }


Expand All @@ -171,14 +163,14 @@ workspace "XboxRainDropletsWrapper"

filter "platforms:Win32"
architecture "x32"
includedirs { "source/dxsdk" }
libdirs { "source/dxsdk/lib/x86" }
includedirs { "source/dxsdk" }
libdirs { "source/dxsdk/lib/x86" }

filter "platforms:Win64"
architecture "x64"
targetname "%{prj.name}64"
includedirs { "source/dxsdk" }
libdirs { "source/dxsdk/lib/x64" }
includedirs { "source/dxsdk" }
libdirs { "source/dxsdk/lib/x64" }

project "XboxRainDropletsWrapper"
setpaths("Z:/WFP/Games/PPSSPP/", "PPSSPPWindows.exe")
Expand Down
2 changes: 1 addition & 1 deletion source/MaxPayne3.XboxRainDroplets.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
#define FUSIONDXHOOK_INCLUDE_D3D10 1
#define FUSIONDXHOOK_INCLUDE_D3D10_1 1
#define FUSIONDXHOOK_INCLUDE_D3D11 1
#define FUSIONDXHOOK_USE_MINHOOK 1
#define FUSIONDXHOOK_USE_SAFETYHOOK 1
#define DELAYED_BIND 2000ms
#include "FusionDxHook.h"

Expand Down
2 changes: 1 addition & 1 deletion source/PCSX2F.XboxRainDroplets.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
#define FUSIONDXHOOK_INCLUDE_D3D12 1
#define FUSIONDXHOOK_INCLUDE_OPENGL 0
#define FUSIONDXHOOK_INCLUDE_VULKAN 0
#define FUSIONDXHOOK_USE_MINHOOK 1
#define FUSIONDXHOOK_USE_SAFETYHOOK 1
#define DELAYED_BIND 2000ms
#include "FusionDxHook.h"

Expand Down
31 changes: 23 additions & 8 deletions source/PPSSPP.XboxRainDroplets.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
#define FUSIONDXHOOK_INCLUDE_D3D12 0
#define FUSIONDXHOOK_INCLUDE_OPENGL 1
#define FUSIONDXHOOK_INCLUDE_VULKAN 1
#define FUSIONDXHOOK_USE_MINHOOK 1
#define FUSIONDXHOOK_USE_SAFETYHOOK 1
#define DELAYED_BIND 2000ms
#include "FusionDxHook.h"

Expand Down Expand Up @@ -63,10 +63,17 @@ struct XRData {
#ifdef __cplusplus
bool Enabled(uint64_t ptr)
{
if (p_enabled)
return *(uint32_t*)(ptr + p_enabled);
else
return ms_enabled != 0;
__try
{
if (p_enabled)
return *(uint32_t*)(ptr + p_enabled);
else
return ms_enabled != 0;
}
__except ((GetExceptionCode() == EXCEPTION_ACCESS_VIOLATION) ? EXCEPTION_EXECUTE_HANDLER : EXCEPTION_CONTINUE_SEARCH)
{
}
return false;
}

float GetRainIntensity(uint64_t ptr)
Expand Down Expand Up @@ -196,8 +203,15 @@ void RenderDroplets()

static XRData* pXRData = nullptr;

if (SendMessage(hWndPPSSPP, WM_USER_GET_EMULATION_STATE, 0, 0))
DWORD_PTR dwResult = 0;
if (SendMessageTimeout(hWndPPSSPP, WM_USER_GET_EMULATION_STATE, 0, 0, SMTO_NORMAL, 10L, &dwResult))
{
if (!dwResult)
{
pXRData = nullptr;
return;
}

enum
{
lo, // Lower 32 bits of pointer to the base of emulated memory
Expand All @@ -206,8 +220,9 @@ void RenderDroplets()
p_hi, // Upper 32 bits of pointer to the pointer to the base of emulated memory
};

uint32_t high = SendMessage(hWndPPSSPP, WM_USER_GET_BASE_POINTER, 0, hi);
uint32_t low = SendMessage(hWndPPSSPP, WM_USER_GET_BASE_POINTER, 0, lo);
DWORD_PTR high, low = 0;
SendMessageTimeout(hWndPPSSPP, WM_USER_GET_BASE_POINTER, 0, hi, SMTO_NORMAL, 10L, &high);
SendMessageTimeout(hWndPPSSPP, WM_USER_GET_BASE_POINTER, 0, lo, SMTO_NORMAL, 10L, &low);
uint64_t ptr = (uint64_t(high) << 32 | low); // +0x08804000;

if (ptr)
Expand Down
2 changes: 1 addition & 1 deletion source/XboxRainDropletsWrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
#define FUSIONDXHOOK_INCLUDE_D3D12 1
#define FUSIONDXHOOK_INCLUDE_OPENGL 1
#define FUSIONDXHOOK_INCLUDE_VULKAN 1
#define FUSIONDXHOOK_USE_MINHOOK 1
#define FUSIONDXHOOK_USE_SAFETYHOOK 1
#define DELAYED_BIND 2000ms
#include "FusionDxHook.h"

Expand Down
25 changes: 15 additions & 10 deletions source/xrd11.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#include <map>
#include <iomanip>
#include <random>
#include <stacktrace>
#include "inireader/IniReader.h"
#include "Hooking.Patterns.h"
#include "includes/ModuleList.hpp"
Expand Down Expand Up @@ -930,16 +931,20 @@ class CallbackHandler
static inline std::map<std::wstring, std::function<void()>> functions;
};

bool IsUALPresent()
bool IsModuleUAL(HMODULE mod)
{
ModuleList dlls;
dlls.Enumerate(ModuleList::SearchLocation::LocalOnly);
for (auto& e : dlls.m_moduleList)
{
if (GetProcAddress(std::get<HMODULE>(e), "DirectInput8Create") != NULL &&
GetProcAddress(std::get<HMODULE>(e), "DirectSoundCreate8") != NULL &&
GetProcAddress(std::get<HMODULE>(e), "InternetOpenA") != NULL)
return true;
}
if (GetProcAddress(mod, "IsUltimateASILoader") != NULL || (GetProcAddress(mod, "DirectInput8Create") != NULL && GetProcAddress(mod, "DirectSoundCreate8") != NULL && GetProcAddress(mod, "InternetOpenA") != NULL))
return true;
return false;
}

bool IsUALPresent() {
for (const auto& entry : std::stacktrace::current()) {
HMODULE hModule = NULL;
if (GetModuleHandleExA(GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS | GET_MODULE_HANDLE_EX_FLAG_UNCHANGED_REFCOUNT, (LPCSTR)entry.native_handle(), &hModule)) {
if (IsModuleUAL(hModule))
return true;
}
}
return false;
}

0 comments on commit 8988c3b

Please sign in to comment.