Skip to content

Commit

Permalink
Fix Reshade compatibility
Browse files Browse the repository at this point in the history
  • Loading branch information
maximegmd committed Dec 23, 2020
1 parent 3e62cfe commit c17882f
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 6 deletions.
4 changes: 4 additions & 0 deletions src/overlay/Overlay.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ struct ScriptStack;
struct UnknownString;

using TPresentD3D12 = long(IDXGISwapChain3* pSwapChain, UINT SyncInterval, UINT Flags);
using TExecuteCommandLists = void(ID3D12CommandQueue* apCommandQueue, UINT NumCommandLists, ID3D12CommandList* const* ppCommandLists);
using TSetMousePosition = BOOL(void* apThis, HWND Wnd, long X, long Y);
using TClipToCenter = HWND(CGameEngine::UnkC0* apThis);
using TScriptCall = void(ScriptContext*, ScriptStack*, void*, void*);
Expand Down Expand Up @@ -66,6 +67,7 @@ struct Overlay
void DrawImgui(IDXGISwapChain3* apSwapChain);

static long PresentD3D12(IDXGISwapChain3* pSwapChain, UINT SyncInterval, UINT Flags);
static void ExecuteCommandListsD3D12(ID3D12CommandQueue* apCommandQueue, UINT NumCommandLists, ID3D12CommandList* const* ppCommandLists);
static BOOL SetMousePosition(void* apThis, HWND Wnd, long X, long Y);
static BOOL ClipToCenter(CGameEngine::UnkC0* apThis);
static LRESULT APIENTRY WndProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
Expand All @@ -85,10 +87,12 @@ struct Overlay
Overlay();

TPresentD3D12* m_realPresentD3D12{ nullptr };
TExecuteCommandLists* m_realExecuteCommandLists{ nullptr };
std::vector<FrameContext> m_frameContexts;
ID3D12DescriptorHeap* m_pd3dRtvDescHeap = nullptr;
ID3D12DescriptorHeap* m_pd3dSrvDescHeap;
ID3D12GraphicsCommandList* m_pd3dCommandList;
ID3D12CommandQueue* m_pCommandQueue{ nullptr };
TClipToCenter* m_realClipToCenter{nullptr};
TScriptCall* m_realLog{nullptr};
TScriptCall* m_realLogChannel{ nullptr };
Expand Down
6 changes: 1 addition & 5 deletions src/overlay/Overlay_D3D12.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,7 @@
#include <atlcomcli.h>
#include <d3d12.h>
#include <dxgi.h>
#include <Image.h>
#include <imgui.h>
#include <memory>
#include <Pattern.h>
#include <kiero/kiero.h>
#include <spdlog/spdlog.h>
Expand Down Expand Up @@ -139,8 +137,6 @@ void Overlay::Render(IDXGISwapChain3* pSwapChain)
m_pd3dCommandList->ResourceBarrier(1, &barrier);
m_pd3dCommandList->Close();

auto* pCommandQueue = *reinterpret_cast<ID3D12CommandQueue**>(reinterpret_cast<uintptr_t>(pSwapChain) + kiero::getCommandQueueOffset());

pCommandQueue->ExecuteCommandLists(1, reinterpret_cast<ID3D12CommandList**>(&m_pd3dCommandList));
m_pCommandQueue->ExecuteCommandLists(1, reinterpret_cast<ID3D12CommandList**>(&m_pd3dCommandList));
}

18 changes: 17 additions & 1 deletion src/overlay/Overlay_Hooks.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,19 @@ long Overlay::PresentD3D12(IDXGISwapChain3* pSwapChain, UINT SyncInterval, UINT
return Get().m_realPresentD3D12(pSwapChain, SyncInterval, Flags);
}

void Overlay::ExecuteCommandListsD3D12(ID3D12CommandQueue* apCommandQueue, UINT NumCommandLists, ID3D12CommandList* const* ppCommandLists)
{
auto& overlay = Get();
if (overlay.m_pCommandQueue == nullptr)
{
auto desc = apCommandQueue->GetDesc();
if(desc.Type == D3D12_COMMAND_LIST_TYPE_DIRECT)
overlay.m_pCommandQueue = apCommandQueue;
}

overlay.m_realExecuteCommandLists(apCommandQueue, NumCommandLists, ppCommandLists);
}

BOOL Overlay::ClipToCenter(CGameEngine::UnkC0* apThis)
{
const HWND wnd = apThis->Wnd;
Expand Down Expand Up @@ -209,7 +222,10 @@ BOOL Overlay::ClipToCenter(CGameEngine::UnkC0* apThis)
void Overlay::Hook()
{
if (kiero::bind(140, reinterpret_cast<void**>(&m_realPresentD3D12), &PresentD3D12) != kiero::Status::Success)
spdlog::error("\tD3D12 PresentD3D12 Hook failed!");
spdlog::error("\tD3D12 Present Hook failed!");

if (kiero::bind(54, reinterpret_cast<void**>(&m_realExecuteCommandLists), &ExecuteCommandListsD3D12) != kiero::Status::Success)
spdlog::error("\tD3D12 ExecuteCommandLists Hook failed!");

spdlog::info("\tD3D12 hook complete");
}
Expand Down

0 comments on commit c17882f

Please sign in to comment.