mirror of
https://github.com/EricPlayZ/EGameTools.git
synced 2025-09-19 21:16:07 +08:00
Merge branch 'dev'
This commit is contained in:
@ -6,6 +6,43 @@ namespace impl {
|
|||||||
namespace d3d11 {
|
namespace d3d11 {
|
||||||
ID3D11Device* d3d11Device = nullptr;
|
ID3D11Device* d3d11Device = nullptr;
|
||||||
static ID3D11DeviceContext* d3d11DeviceContext = nullptr;
|
static ID3D11DeviceContext* d3d11DeviceContext = nullptr;
|
||||||
|
static ID3D11RenderTargetView* d3d11RenderTargetView = nullptr;
|
||||||
|
|
||||||
|
static std::mutex resourceMutex{};
|
||||||
|
static std::vector<IUnknown*> resources{};
|
||||||
|
|
||||||
|
static void ReleaseResources() {
|
||||||
|
resourceMutex.lock();
|
||||||
|
for (auto resource : resources)
|
||||||
|
resource->Release();
|
||||||
|
resources.clear();
|
||||||
|
d3d11RenderTargetView = nullptr;
|
||||||
|
resourceMutex.unlock();
|
||||||
|
}
|
||||||
|
// Create custom render target view because DX11 color space issue with ImGui bruh
|
||||||
|
static ID3D11RenderTargetView* CreateRenderTargetView(IDXGISwapChain* swapChain) {
|
||||||
|
ID3D11Device* device = nullptr;
|
||||||
|
ID3D11Texture2D* backBuffer = nullptr;
|
||||||
|
ID3D11RenderTargetView* renderTarget = nullptr;
|
||||||
|
|
||||||
|
swapChain->GetBuffer(0, __uuidof(ID3D11Texture2D), reinterpret_cast<LPVOID*>(&backBuffer));
|
||||||
|
swapChain->GetDevice(IID_PPV_ARGS(&device));
|
||||||
|
|
||||||
|
if (device && backBuffer) {
|
||||||
|
D3D11_RENDER_TARGET_VIEW_DESC desc{};
|
||||||
|
memset(&desc, 0, sizeof(desc));
|
||||||
|
desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
|
||||||
|
desc.ViewDimension = D3D11_RTV_DIMENSION_TEXTURE2D;
|
||||||
|
|
||||||
|
if (device->CreateRenderTargetView(backBuffer, &desc, &renderTarget) == S_OK) {
|
||||||
|
resourceMutex.lock();
|
||||||
|
resources.push_back(renderTarget);
|
||||||
|
resourceMutex.unlock();
|
||||||
|
}
|
||||||
|
backBuffer->Release();
|
||||||
|
}
|
||||||
|
return renderTarget;
|
||||||
|
}
|
||||||
|
|
||||||
HRESULT(__stdcall* oPresent)(IDXGISwapChain*, UINT, UINT);
|
HRESULT(__stdcall* oPresent)(IDXGISwapChain*, UINT, UINT);
|
||||||
HRESULT __stdcall hkPresent11(IDXGISwapChain* pSwapChain, UINT SyncInterval, UINT Flags) {
|
HRESULT __stdcall hkPresent11(IDXGISwapChain* pSwapChain, UINT SyncInterval, UINT Flags) {
|
||||||
@ -18,6 +55,8 @@ namespace impl {
|
|||||||
pSwapChain->GetDevice(__uuidof(ID3D11Device), (void**)&d3d11Device);
|
pSwapChain->GetDevice(__uuidof(ID3D11Device), (void**)&d3d11Device);
|
||||||
d3d11Device->GetImmediateContext(&d3d11DeviceContext);
|
d3d11Device->GetImmediateContext(&d3d11DeviceContext);
|
||||||
|
|
||||||
|
d3d11RenderTargetView = CreateRenderTargetView(pSwapChain);
|
||||||
|
|
||||||
#ifndef LLMH_IMPL_DISABLE_DEBUG
|
#ifndef LLMH_IMPL_DISABLE_DEBUG
|
||||||
std::thread([&desc]() { impl::win32::init(desc.OutputWindow); }).detach();
|
std::thread([&desc]() { impl::win32::init(desc.OutputWindow); }).detach();
|
||||||
#else
|
#else
|
||||||
@ -45,13 +84,26 @@ namespace impl {
|
|||||||
|
|
||||||
ImGui::EndFrame();
|
ImGui::EndFrame();
|
||||||
ImGui::Render();
|
ImGui::Render();
|
||||||
|
|
||||||
|
if (d3d11RenderTargetView)
|
||||||
|
d3d11DeviceContext->OMSetRenderTargets(1, &d3d11RenderTargetView, nullptr);
|
||||||
ImGui_ImplDX11_RenderDrawData(ImGui::GetDrawData());
|
ImGui_ImplDX11_RenderDrawData(ImGui::GetDrawData());
|
||||||
|
|
||||||
return oPresent(pSwapChain, SyncInterval, Flags);
|
return oPresent(pSwapChain, SyncInterval, Flags);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
HRESULT(__stdcall* oResizeBuffers)(IDXGISwapChain*, UINT, UINT, UINT, DXGI_FORMAT, UINT);
|
||||||
|
HRESULT __stdcall hkResizeBuffers11(IDXGISwapChain* pSwapChain, UINT BufferCount, UINT Width, UINT Height, DXGI_FORMAT NewFormat, UINT SwapChainFlags) {
|
||||||
|
ReleaseResources();
|
||||||
|
HRESULT result = oResizeBuffers(pSwapChain, BufferCount, Width, Height, NewFormat, SwapChainFlags);
|
||||||
|
d3d11RenderTargetView = CreateRenderTargetView(pSwapChain);
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
void init() {
|
void init() {
|
||||||
assert(kiero::bind(8, (LPVOID*)&oPresent, hkPresent11) == kiero::Status::Success);
|
assert(kiero::bind(8, (LPVOID*)&oPresent, hkPresent11) == kiero::Status::Success);
|
||||||
|
assert(kiero::bind(13, (LPVOID*)&oResizeBuffers, hkResizeBuffers11) == kiero::Status::Success);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -269,6 +269,8 @@ namespace Menu {
|
|||||||
io.FontDefault = io.Fonts->AddFontFromMemoryTTF((void*)g_FontRudaBold, sizeof(g_FontRudaBold), 12.0f + 6.0f, &fontConfig);
|
io.FontDefault = io.Fonts->AddFontFromMemoryTTF((void*)g_FontRudaBold, sizeof(g_FontRudaBold), 12.0f + 6.0f, &fontConfig);
|
||||||
io.Fonts->Build();
|
io.Fonts->Build();
|
||||||
|
|
||||||
|
spdlog::warn("Loading EGameTools logo texture");
|
||||||
EGTLogoTexture = Utils::Texture::LoadImGuiTexture(g_EGTWhiteLogo, sizeof(g_EGTWhiteLogo));
|
EGTLogoTexture = Utils::Texture::LoadImGuiTexture(g_EGTWhiteLogo, sizeof(g_EGTWhiteLogo));
|
||||||
|
spdlog::info("Loaded EGameTools logo");
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -19,7 +19,7 @@ namespace Utils {
|
|||||||
namespace Texture {
|
namespace Texture {
|
||||||
static int descriptor_index = 1;
|
static int descriptor_index = 1;
|
||||||
|
|
||||||
ImTextureID LoadImGuiTextureD3D11(const unsigned char* rawData, const int rawSize) {
|
static ImTextureID LoadImGuiTextureD3D11(const unsigned char* rawData, const int rawSize) {
|
||||||
int image_width = 0;
|
int image_width = 0;
|
||||||
int image_height = 0;
|
int image_height = 0;
|
||||||
unsigned char* image_data = stbi_load_from_memory(rawData, rawSize, &image_width, &image_height, nullptr, 4);
|
unsigned char* image_data = stbi_load_from_memory(rawData, rawSize, &image_width, &image_height, nullptr, 4);
|
||||||
@ -62,7 +62,7 @@ namespace Utils {
|
|||||||
|
|
||||||
return static_cast<ImTextureID>(my_texture);
|
return static_cast<ImTextureID>(my_texture);
|
||||||
}
|
}
|
||||||
ImTextureID LoadImGuiTextureD3D12(const unsigned char* rawData, const int rawSize) {
|
static ImTextureID LoadImGuiTextureD3D12(const unsigned char* rawData, const int rawSize) {
|
||||||
int image_width = 0;
|
int image_width = 0;
|
||||||
int image_height = 0;
|
int image_height = 0;
|
||||||
unsigned char* image_data = stbi_load_from_memory(rawData, rawSize, &image_width, &image_height, nullptr, 4);
|
unsigned char* image_data = stbi_load_from_memory(rawData, rawSize, &image_width, &image_height, nullptr, 4);
|
||||||
|
Reference in New Issue
Block a user