Skip to content

Commit

Permalink
fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
ThirteenAG committed Nov 29, 2024
1 parent bca23d7 commit 4f61dd6
Show file tree
Hide file tree
Showing 6 changed files with 67 additions and 17 deletions.
2 changes: 1 addition & 1 deletion external/FusionDxHook
2 changes: 1 addition & 1 deletion external/sire
Submodule sire updated 1 files
+17 −0 sire.h
42 changes: 36 additions & 6 deletions source/GTASADE.XboxRainDroplets.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@
#include <safetyhook.hpp>
#include <utility/Scan.hpp>

#define FUSIONDXHOOK_INCLUDE_D3D12 1
#define FUSIONDXHOOK_USE_SAFETYHOOK 0
#include "FusionDxHook.h"

namespace CWeather
{
GameRef<float> Rain;
Expand Down Expand Up @@ -168,6 +172,8 @@ uintptr_t ResolveDisplacement(hook::pattern& pattern, ptrdiff_t offset = 0)

void Init()
{
FusionDxHook::Init(); // For DX12 compat, no hooks applied

WaterDrops::ReadIniSettings();
static DXGI_FORMAT gFormat = DXGI_FORMAT_R10G10B10A2_UNORM;

Expand Down Expand Up @@ -202,14 +208,11 @@ void Init()
pattern = hook::pattern("48 8D 0D ? ? ? ? E8 ? ? ? ? 80 3D ? ? ? ? ? 48 8D 1D");
TheCamera.SetAddress(ResolveDisplacement(pattern)); //0x1453E23D0

pattern = hook::pattern("48 8B 4B ? 48 8B 01 FF 50 ? 8B F0");
static auto FD3D11ViewportPresentCheckedHook = safetyhook::create_mid(pattern.get_first(), [](SafetyHookContext& regs) //0x141F5A4F5
static auto PresentHook = [](IDXGISwapChain* pSwapChain)
{
if (gGameState < 9)
return;

auto pSwapChain = *(IDXGISwapChain**)(regs.rbx + 0x78);


Sire::Init(Sire::SIRE_RENDERER_DX11, pSwapChain);
Sire::SetTextureFormat(Sire::GetCurrentRenderer(), gFormat);

Expand Down Expand Up @@ -238,10 +241,37 @@ void Init()
WaterDrops::Render();
}
}
};

pattern = hook::pattern("48 8B 4B ? 48 8B 01 FF 50 ? 8B F0");
static auto FD3D11ViewportPresentCheckedHook = safetyhook::create_mid(pattern.get_first(), [](SafetyHookContext& regs) //0x141F5A4F5
{
auto pSwapChain = *(IDXGISwapChain**)(regs.rbx + 0x78);
PresentHook(pSwapChain);
});

pattern = hook::pattern("48 8B 01 44 8B C3 8B D5");
static auto FD3D12ViewportPresentCheckedHook = safetyhook::create_mid(pattern.get_first(), [](SafetyHookContext& regs) //0x141FD5E67
{
auto pSwapChain = (IDXGISwapChain*)(regs.rcx);
Sire::SetCommandQueue(FusionDxHook::D3D12::GetCommandQueueFromSwapChain(pSwapChain));
PresentHook(pSwapChain);
});

pattern = hook::pattern("89 44 24 ? 41 FF 52 ? BA 00 00 00 80");
static auto onBeforeResizeHook = safetyhook::create_mid(pattern.get_first(), [](SafetyHookContext& regs) //0x141F5A0BC
static auto onBeforeResizeHookD3D11 = safetyhook::create_mid(pattern.get_first(), [](SafetyHookContext& regs) //0x141F5A0BC
{
//IDXGISwapChain* pSwapChain = (IDXGISwapChain*)regs.rcx;
//UINT Width = regs.r8;
//UINT Height = regs.r9;
gFormat = (DXGI_FORMAT)regs.rax;

WaterDrops::Reset();
Sire::Shutdown();
});

pattern = hook::pattern("44 89 74 24 ? 89 44 24 ? 41 FF 52");
static auto onBeforeResizeHookD3D12 = safetyhook::create_mid(pattern.get_first(), [](SafetyHookContext& regs) //0x141FEA673
{
//IDXGISwapChain* pSwapChain = (IDXGISwapChain*)regs.rcx;
//UINT Width = regs.r8;
Expand Down
23 changes: 18 additions & 5 deletions source/PCSX2F.XboxRainDroplets.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
#define FUSIONDXHOOK_INCLUDE_OPENGL 0
#define FUSIONDXHOOK_INCLUDE_VULKAN 0
#define FUSIONDXHOOK_USE_SAFETYHOOK 1
#define DELAYED_BIND 2000ms
#define DELAYED_BIND 10000ms
#include "FusionDxHook.h"

#pragma pack(push, 1)
Expand Down Expand Up @@ -245,6 +245,17 @@ extern "C" __declspec(dllexport) void InitializeASI()
}
};

FusionDxHook::D3D11::onBeforeResizeEvent += [](IDXGISwapChain* pSwapChain, UINT BufferCount, UINT Width, UINT Height, DXGI_FORMAT NewFormat, UINT SwapChainFlags)
{
#ifdef SIRE_INCLUDE_DX11ON12
if (!d3d11on12::isD3D11on12)
#endif
{
WaterDrops::Reset();
Sire::Shutdown();
}
};

FusionDxHook::D3D11::onAfterResizeEvent += [](IDXGISwapChain* pSwapChain, UINT BufferCount, UINT Width, UINT Height, DXGI_FORMAT NewFormat, UINT SwapChainFlags)
{

Expand All @@ -266,17 +277,19 @@ extern "C" __declspec(dllexport) void InitializeASI()
#if FUSIONDXHOOK_INCLUDE_D3D12
FusionDxHook::D3D12::onPresentEvent += [](IDXGISwapChain* pSwapChain)
{
Sire::SetCommandQueue(FusionDxHook::D3D12::GetCommandQueueFromSwapChain(pSwapChain));
Sire::Init(Sire::SIRE_RENDERER_DX11, pSwapChain);
RenderDroplets();
};

#ifdef SIRE_INCLUDE_DX11ON12
FusionDxHook::D3D12::onExecuteCommandListsEvent += [](ID3D12CommandQueue* pCommandQueue, UINT NumCommandLists, const ID3D12CommandList** ppCommandLists)
{
if (pCommandQueue->GetDesc().Type == D3D12_COMMAND_LIST_TYPE_DIRECT)
{
Sire::SetCommandQueue(pCommandQueue);
}
//FusionDxHook::D3D12::GetCommandQueueFromSwapChain(pSwapChain) is more reliable
//if (pCommandQueue->GetDesc().Type == D3D12_COMMAND_LIST_TYPE_DIRECT)
//{
// Sire::SetCommandQueue(pCommandQueue);
//}
};
#endif

Expand Down
10 changes: 6 additions & 4 deletions source/XboxRainDropletsWrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@ extern "C" __declspec(dllexport) void InitializeASI()
#if FUSIONDXHOOK_INCLUDE_D3D12
FusionDxHook::D3D12::onPresentEvent += [](IDXGISwapChain* pSwapChain)
{
Sire::SetCommandQueue(FusionDxHook::D3D12::GetCommandQueueFromSwapChain(pSwapChain));
Sire::Init(Sire::SIRE_RENDERER_DX11, pSwapChain);

WaterDrops::Process();
Expand All @@ -142,10 +143,11 @@ extern "C" __declspec(dllexport) void InitializeASI()
#ifdef SIRE_INCLUDE_DX11ON12
FusionDxHook::D3D12::onExecuteCommandListsEvent += [](ID3D12CommandQueue* pCommandQueue, UINT NumCommandLists, const ID3D12CommandList** ppCommandLists)
{
if (pCommandQueue->GetDesc().Type == D3D12_COMMAND_LIST_TYPE_DIRECT)
{
Sire::SetCommandQueue(pCommandQueue);
}
//FusionDxHook::D3D12::GetCommandQueueFromSwapChain(pSwapChain) is more reliable
//if (pCommandQueue->GetDesc().Type == D3D12_COMMAND_LIST_TYPE_DIRECT)
//{
// Sire::SetCommandQueue(pCommandQueue);
//}
};
#endif

Expand Down
5 changes: 5 additions & 0 deletions source/xrd11.h
Original file line number Diff line number Diff line change
Expand Up @@ -550,6 +550,11 @@ class WaterDrops
ms_splashDistance = 0;
ms_splashPoint = { 0 };

if (ms_tex)
ms_tex.Release();
if (ms_maskTex)
ms_maskTex.Release();

ms_initialised = 0;
}

Expand Down

0 comments on commit 4f61dd6

Please sign in to comment.