Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove kiero #992

Merged
merged 1 commit into from
Jan 11, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 7 additions & 31 deletions ThirdParty_LICENSES
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
============ imgui ============
============ imgui ============

The MIT License (MIT)

Expand All @@ -22,11 +22,11 @@ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

============ spdlog ============
============ spdlog ============

The MIT License (MIT)

Copyright (c) 2016 Gabi Melman.
Copyright (c) 2016 Gabi Melman.

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand All @@ -52,7 +52,7 @@ and users must comply to its license: https://github.com/fmtlib/fmt/blob/master/

============ nlohmann/json ============

MIT License
MIT License

Copyright (c) 2013-2021 Niels Lohmann

Expand Down Expand Up @@ -98,9 +98,9 @@ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

============ MinHook ============
============ MinHook ============

MinHook - The Minimalistic API Hooking Library for x64/x86
MinHook - The Minimalistic API Hooking Library for x64/x86
Copyright (C) 2009-2017 Tsuda Kageyu.
All rights reserved.

Expand Down Expand Up @@ -323,30 +323,6 @@ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

============ kiero ============

MIT License

Copyright (c) 2014-2020 Rebzzel

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

============ lsqlite3 ============

* lsqlite3 *
Expand Down Expand Up @@ -491,7 +467,7 @@ with others.

The OFL allows the licensed fonts to be used, studied, modified and
redistributed freely as long as they are not sold by themselves. The
fonts, including any derivative works, can be bundled, embedded,
fonts, including any derivative works, can be bundled, embedded,
redistributed and/or sold with any software provided that any reserved
names are not used by derivative works. The fonts and derivatives,
however, cannot be released under any other type of license. The
Expand Down
2 changes: 1 addition & 1 deletion src/d3d12/D3D12.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ D3D12::D3D12(Window& aWindow, Paths& aPaths, Options& aOptions)
, m_window(aWindow)
, m_options(aOptions)
{
HookGame();
Hook();

// add repeated task which prepares next ImGui frame for update
GameMainThread::Get().AddGenericTask(
Expand Down
21 changes: 1 addition & 20 deletions src/d3d12/D3D12.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,6 @@
#include "common/D3D12Downlevel.h"
#include "window/Window.h"

using TPresentD3D12Downlevel = HRESULT(ID3D12CommandQueueDownlevel*, ID3D12GraphicsCommandList*, ID3D12Resource*, HWND, D3D12_DOWNLEVEL_PRESENT_FLAGS);
using TCreateCommittedResource =
HRESULT(ID3D12Device*, const D3D12_HEAP_PROPERTIES*, D3D12_HEAP_FLAGS, const D3D12_RESOURCE_DESC*, D3D12_RESOURCE_STATES, const D3D12_CLEAR_VALUE*, const IID*, void**);
using TExecuteCommandLists = void(ID3D12CommandQueue*, UINT, ID3D12CommandList* const*);
using TCRenderNode_Present_InternalPresent = void*(int32_t*, uint8_t, UINT);
using TCRenderGlobal_Resize = void*(uint32_t a1, uint32_t a2, uint32_t a3, uint8_t a4, int32_t* a5);
using TCRenderGlobal_Shutdown = void*(uint64_t a1, uint64_t a2, uint64_t a3, uint64_t a4);
Expand Down Expand Up @@ -35,7 +31,6 @@ struct D3D12

protected:
void Hook();
void HookGame();

struct FrameContext
{
Expand All @@ -44,39 +39,25 @@ struct D3D12
D3D12_CPU_DESCRIPTOR_HANDLE MainRenderTargetDescriptor{0};
};

bool ResetState(const bool acClearDownlevelBackbuffers = true, const bool acDestroyContext = false);
bool ResetState(const bool acDestroyContext = false);
bool Initialize();
bool InitializeDownlevel(ID3D12CommandQueue* apCommandQueue, ID3D12Resource* apSourceTex2D, HWND ahWindow);
bool InitializeImGui(size_t aBuffersCounts);

void PrepareUpdate();
void Update();

static HRESULT PresentDownlevel(
ID3D12CommandQueueDownlevel* apCommandQueueDownlevel, ID3D12GraphicsCommandList* apOpenCommandList, ID3D12Resource* apSourceTex2D, HWND ahWindow,
D3D12_DOWNLEVEL_PRESENT_FLAGS aFlags);
static HRESULT CreateCommittedResource(
ID3D12Device* apDevice, const D3D12_HEAP_PROPERTIES* acpHeapProperties, D3D12_HEAP_FLAGS aHeapFlags, const D3D12_RESOURCE_DESC* acpDesc,
D3D12_RESOURCE_STATES aInitialResourceState, const D3D12_CLEAR_VALUE* acpOptimizedClearValue, const IID* acpRIID, void** appvResource);
static void ExecuteCommandLists(ID3D12CommandQueue* apCommandQueue, UINT aNumCommandLists, ID3D12CommandList* const* apcpCommandLists);

static void* CRenderNode_Present_InternalPresent(int32_t* apSomeInt, uint8_t aSomeSync, UINT aSyncInterval);
static void* CRenderGlobal_Resize(uint32_t a1, uint32_t a2, uint32_t a3, uint8_t a4, int32_t* a5);
static void* CRenderGlobal_Shutdown(uint64_t a1, uint64_t a2, uint64_t a3, uint64_t a4);

private:
TPresentD3D12Downlevel* m_realPresentD3D12Downlevel{nullptr};
TCreateCommittedResource* m_realCreateCommittedResource{nullptr};
TExecuteCommandLists* m_realExecuteCommandLists{nullptr};
TCRenderNode_Present_InternalPresent* m_realInternalPresent{nullptr};
TCRenderGlobal_Resize* m_realInternalResize{nullptr};
TCRenderGlobal_Shutdown* m_realInternalShutdown{nullptr};

bool m_initialized{false};

TiltedPhoques::Vector<FrameContext> m_frameContexts;
TiltedPhoques::Vector<Microsoft::WRL::ComPtr<ID3D12Resource>> m_downlevelBackbuffers;
uint32_t m_downlevelBufferIndex{0};

Microsoft::WRL::ComPtr<ID3D12Device> m_pd3d12Device{};
Microsoft::WRL::ComPtr<ID3D12DescriptorHeap> m_pd3dRtvDescHeap{};
Expand Down
141 changes: 3 additions & 138 deletions src/d3d12/D3D12_Functions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
#include <imgui_impl/win32.h>
#include <window/window.h>

bool D3D12::ResetState(const bool acClearDownlevelBackbuffers, const bool acDestroyContext)
bool D3D12::ResetState(const bool acDestroyContext)
{
if (m_initialized)
{
Expand All @@ -32,10 +32,6 @@ bool D3D12::ResetState(const bool acClearDownlevelBackbuffers, const bool acDest
m_frameContexts.clear();
m_outSize = {0, 0};

if (acClearDownlevelBackbuffers)
m_downlevelBackbuffers.clear();
m_downlevelBufferIndex = 0;

m_pd3d12Device.Reset();
m_pd3dRtvDescHeap.Reset();
m_pd3dSrvDescHeap.Reset();
Expand Down Expand Up @@ -144,137 +140,6 @@ bool D3D12::Initialize()
return true;
}

bool D3D12::InitializeDownlevel(ID3D12CommandQueue* apCommandQueue, ID3D12Resource* apSourceTex2D, HWND ahWindow)
{
if (!apCommandQueue || !apSourceTex2D)
return false;

const HWND hWnd = m_window.GetWindow();
if (!hWnd)
{
Log::Warn("D3D12::InitializeDownlevel() - window not yet hooked!");
return false;
}

if (m_initialized)
{
if (hWnd != ahWindow)
Log::Warn(
"D3D12::InitializeDownlevel() - current output window does not match hooked window! Currently hooked "
"to {} while current output window is {}.",
reinterpret_cast<void*>(hWnd), reinterpret_cast<void*>(ahWindow));

return true;
}

const auto cmdQueueDesc = apCommandQueue->GetDesc();
if (cmdQueueDesc.Type != D3D12_COMMAND_LIST_TYPE_DIRECT)
{
Log::Warn("D3D12::InitializeDownlevel() - ignoring command queue - invalid type of command list!");
return false;
}

m_pCommandQueue = apCommandQueue;

const auto st2DDesc = apSourceTex2D->GetDesc();
m_outSize = {static_cast<LONG>(st2DDesc.Width), static_cast<LONG>(st2DDesc.Height)};

if (hWnd != ahWindow)
Log::Warn(
"D3D12::InitializeDownlevel() - current output window does not match hooked window! Currently hooked to {} "
"while current output window is {}.",
reinterpret_cast<void*>(hWnd), reinterpret_cast<void*>(ahWindow));

if (FAILED(apSourceTex2D->GetDevice(IID_PPV_ARGS(&m_pd3d12Device))))
{
Log::Error("D3D12::InitializeDownlevel() - failed to get device!");
return ResetState();
}

const size_t buffersCounts = m_downlevelBackbuffers.size();
m_frameContexts.resize(buffersCounts);
if (buffersCounts == 0)
{
Log::Error("D3D12::InitializeDownlevel() - no backbuffers were found!");
return ResetState();
}
if (buffersCounts < g_numDownlevelBackbuffersRequired)
{
Log::Info("D3D12::InitializeDownlevel() - backbuffer list is not complete yet; assuming window was resized");
return false;
}

D3D12_DESCRIPTOR_HEAP_DESC rtvdesc;
rtvdesc.Type = D3D12_DESCRIPTOR_HEAP_TYPE_RTV;
rtvdesc.NumDescriptors = static_cast<UINT>(buffersCounts);
rtvdesc.Flags = D3D12_DESCRIPTOR_HEAP_FLAG_NONE;
rtvdesc.NodeMask = 1;
if (FAILED(m_pd3d12Device->CreateDescriptorHeap(&rtvdesc, IID_PPV_ARGS(&m_pd3dRtvDescHeap))))
{
Log::Error("D3D12::InitializeDownlevel() - failed to create RTV descriptor heap!");
return ResetState();
}

const SIZE_T rtvDescriptorSize = m_pd3d12Device->GetDescriptorHandleIncrementSize(D3D12_DESCRIPTOR_HEAP_TYPE_RTV);
D3D12_CPU_DESCRIPTOR_HANDLE rtvHandle = m_pd3dRtvDescHeap->GetCPUDescriptorHandleForHeapStart();
for (auto& context : m_frameContexts)
{
context.MainRenderTargetDescriptor = rtvHandle;
rtvHandle.ptr += rtvDescriptorSize;
}

D3D12_DESCRIPTOR_HEAP_DESC srvdesc = {};
srvdesc.Type = D3D12_DESCRIPTOR_HEAP_TYPE_CBV_SRV_UAV;
srvdesc.NumDescriptors = 2;
srvdesc.Flags = D3D12_DESCRIPTOR_HEAP_FLAG_SHADER_VISIBLE;
if (FAILED(m_pd3d12Device->CreateDescriptorHeap(&srvdesc, IID_PPV_ARGS(&m_pd3dSrvDescHeap))))
{
Log::Error("D3D12::InitializeDownlevel() - failed to create SRV descriptor heap!");
return ResetState();
}

for (auto& context : m_frameContexts)
{
if (FAILED(m_pd3d12Device->CreateCommandAllocator(D3D12_COMMAND_LIST_TYPE_DIRECT, IID_PPV_ARGS(&context.CommandAllocator))))
{
Log::Error("D3D12::InitializeDownlevel() - failed to create command allocator!");
return ResetState();
}
}

if (FAILED(m_pd3d12Device->CreateCommandList(0, D3D12_COMMAND_LIST_TYPE_DIRECT, m_frameContexts[0].CommandAllocator.Get(), nullptr, IID_PPV_ARGS(&m_pd3dCommandList))))
{
Log::Error("D3D12::InitializeDownlevel() - failed to create command list!");
return ResetState();
}

if (FAILED(m_pd3dCommandList->Close()))
{
Log::Error("D3D12::InitializeDownlevel() - failed to close command list!");
return ResetState();
}

for (size_t i = 0; i < buffersCounts; i++)
{
auto& context = m_frameContexts[i];
context.BackBuffer = m_downlevelBackbuffers[i];
m_pd3d12Device->CreateRenderTargetView(context.BackBuffer.Get(), nullptr, context.MainRenderTargetDescriptor);
}

if (!InitializeImGui(buffersCounts))
{
Log::Error("D3D12::InitializeDownlevel() - failed to initialize ImGui!");
return ResetState();
}

Log::Info("D3D12::InitializeDownlevel() - initialization successful!");
m_initialized = true;

OnInitialized.Emit();

return true;
}

void D3D12::ReloadFonts()
{
std::lock_guard _(m_imguiLock);
Expand Down Expand Up @@ -525,8 +390,8 @@ void D3D12::Update()
if (!m_imguiDrawDataBuffers[0].Valid)
return;

const auto bufferIndex = m_pdxgiSwapChain != nullptr ? m_pdxgiSwapChain->GetCurrentBackBufferIndex() : m_downlevelBufferIndex;
auto& frameContext = m_frameContexts[bufferIndex];
assert(m_pdxgiSwapChain);
auto& frameContext = m_frameContexts[m_pdxgiSwapChain->GetCurrentBackBufferIndex()];
frameContext.CommandAllocator->Reset();

D3D12_RESOURCE_BARRIER barrier;
Expand Down
Loading