From 0fe9003680fd43833584be953abb09a1c84eac52 Mon Sep 17 00:00:00 2001 From: Bari <58800830+TheBarii@users.noreply.github.com> Date: Sun, 4 Aug 2024 21:10:38 +0600 Subject: [PATCH] idk --- src/Client/GUI/Engine/Effects/Blur/blur.cpp | 37 ++++-- .../Engine/Elements/Control/Image/Image.cpp | 2 + .../Shapes/Rect/ShadowRect/ShadowRect.cpp | 88 ++++++-------- .../Hook/Hooks/Render/SwapchainHook.cpp | 59 +++++++++- .../Hook/Hooks/Render/SwapchainHook.hpp | 5 +- .../Modules/MotionBlur/MotionBlurListener.hpp | 110 +----------------- 6 files changed, 129 insertions(+), 172 deletions(-) diff --git a/src/Client/GUI/Engine/Effects/Blur/blur.cpp b/src/Client/GUI/Engine/Effects/Blur/blur.cpp index 67e540b9..9ad7dffe 100644 --- a/src/Client/GUI/Engine/Effects/Blur/blur.cpp +++ b/src/Client/GUI/Engine/Effects/Blur/blur.cpp @@ -164,6 +164,7 @@ ID3D11PixelShader *dbgShader; void Blur::InitializePipeline() { + HRESULT hr; ID3D11DeviceContext* pContext; SwapchainHook::d3d11Device->GetImmediateContext(&pContext); @@ -211,8 +212,9 @@ void Blur::InitializePipeline() sd.AddressW = D3D11_TEXTURE_ADDRESS_CLAMP; SwapchainHook::d3d11Device->CreateSamplerState(&sd, &pSampler); -} + pContext->Release(); +} void Blur::RenderToRTV(ID3D11RenderTargetView *pRenderTargetView, ID3D11ShaderResourceView *pShaderResourceView, XMFLOAT2 rtvSize) { HRESULT hr; @@ -222,7 +224,8 @@ void Blur::RenderToRTV(ID3D11RenderTargetView *pRenderTargetView, ID3D11ShaderRe dsd.DepthEnable = false; dsd.StencilEnable = false; ID3D11DepthStencilState *pDepthStencilState; - SwapchainHook::d3d11Device->CreateDepthStencilState(&dsd, &pDepthStencilState); + hr = SwapchainHook::d3d11Device->CreateDepthStencilState(&dsd, &pDepthStencilState); + if (FAILED(hr)) { pContext->Release(); return; } pContext->OMSetDepthStencilState(pDepthStencilState, 0); void *null = nullptr; @@ -243,7 +246,7 @@ void Blur::RenderToRTV(ID3D11RenderTargetView *pRenderTargetView, ID3D11ShaderRe pContext->VSSetShader(pVertexShader, nullptr, 0); pContext->PSSetSamplers(0, 1, &pSampler); pContext->PSSetConstantBuffers(0, 1, &pConstantBuffer); - D3D11_BLEND_DESC bd; + D3D11_BLEND_DESC bd{}; ZeroMemory(&bd, sizeof(bd)); bd.AlphaToCoverageEnable = false; bd.RenderTarget[0].BlendEnable = true; @@ -255,7 +258,8 @@ void Blur::RenderToRTV(ID3D11RenderTargetView *pRenderTargetView, ID3D11ShaderRe bd.RenderTarget[0].BlendOpAlpha = D3D11_BLEND_OP_ADD; bd.RenderTarget[0].RenderTargetWriteMask = D3D11_COLOR_WRITE_ENABLE_ALL; ID3D11BlendState *pBlendState; - SwapchainHook::d3d11Device->CreateBlendState(&bd, &pBlendState); + hr = SwapchainHook::d3d11Device->CreateBlendState(&bd, &pBlendState); + if (FAILED(hr)) { pContext->Release(); pDepthStencilState->Release(); return; } pContext->OMSetBlendState(pBlendState, NULL, 0xffffffff); D3D11_RASTERIZER_DESC rd{}; rd.FillMode = D3D11_FILL_SOLID; @@ -263,7 +267,8 @@ void Blur::RenderToRTV(ID3D11RenderTargetView *pRenderTargetView, ID3D11ShaderRe rd.DepthClipEnable = false; rd.ScissorEnable = false; ID3D11RasterizerState *pRasterizerState; - SwapchainHook::d3d11Device->CreateRasterizerState(&rd, &pRasterizerState); + hr = SwapchainHook::d3d11Device->CreateRasterizerState(&rd, &pRasterizerState); + if (FAILED(hr)) { pContext->Release(); pDepthStencilState->Release(); pBlendState->Release(); return; } pContext->RSSetState(pRasterizerState); pContext->PSSetShaderResources(0, 1, &pShaderResourceView); @@ -280,26 +285,29 @@ void Blur::RenderToRTV(ID3D11RenderTargetView *pRenderTargetView, ID3D11ShaderRe pContext->Draw(sizeof(quadVertices) / sizeof(quadVertices[0]), 0); ID3D11RenderTargetView* kajgd = nullptr; pContext->OMSetRenderTargets(1, &kajgd, nullptr); + + pDepthStencilState->Release(); + pBlendState->Release(); + pRasterizerState->Release(); + pContext->Release(); } void Blur::RenderBlur(ID3D11RenderTargetView *pDstRenderTargetView, int iterations, float intensity) { - ID3D11Texture2D* tex = MotionBlurListener::GetBackbuffer(); - if(!tex) return; + if (!SwapchainHook::GetBackbuffer()) return; - ID3D11ShaderResourceView *pOrigShaderResourceView = MotionBlurListener::SaveBackbuffer(); - if(!pOrigShaderResourceView) return; + ID3D11ShaderResourceView *pOrigShaderResourceView = MotionBlurListener::BackbufferToSRV(); + if (!pOrigShaderResourceView) return; ID3D11DeviceContext* pContext; SwapchainHook::d3d11Device->GetImmediateContext(&pContext); - HRESULT hr; std::vector framebuffers; std::vector renderTargetViews; std::vector shaderResourceViews; std::vector fbSizes; D3D11_TEXTURE2D_DESC desc; - tex->GetDesc(&desc); + SwapchainHook::GetBackbuffer()->GetDesc(&desc); framebuffers.reserve((size_t)iterations); renderTargetViews.reserve((size_t)iterations); @@ -355,8 +363,13 @@ void Blur::RenderBlur(ID3D11RenderTargetView *pDstRenderTargetView, int iteratio renderTargetViews[i]->Release(); framebuffers[i]->Release(); shaderResourceViews[i]->Release(); + + renderTargetViews.clear(); + framebuffers.clear(); + shaderResourceViews.clear(); + fbSizes.clear(); } - tex->Release(); + pContext->Release(); pOrigShaderResourceView->Release(); } diff --git a/src/Client/GUI/Engine/Elements/Control/Image/Image.cpp b/src/Client/GUI/Engine/Elements/Control/Image/Image.cpp index e0fa7a5a..efa7549a 100644 --- a/src/Client/GUI/Engine/Elements/Control/Image/Image.cpp +++ b/src/Client/GUI/Engine/Elements/Control/Image/Image.cpp @@ -271,6 +271,8 @@ bool FlarialGUI::LoadImageFromResource(int resourceId, D3D12_CPU_DESCRIPTOR_HAND void FlarialGUI::image(int resourceId, D2D1_RECT_F rect, LPCTSTR type, bool shouldadd) { + if(Client::settings.getSettingByName("noicons")->value) return; + if (isInScrollView and shouldadd) { rect.top += scrollpos; rect.bottom += scrollpos; diff --git a/src/Client/GUI/Engine/Elements/Shapes/Rect/ShadowRect/ShadowRect.cpp b/src/Client/GUI/Engine/Elements/Shapes/Rect/ShadowRect/ShadowRect.cpp index 48c04f2b..b27b47ee 100644 --- a/src/Client/GUI/Engine/Elements/Shapes/Rect/ShadowRect/ShadowRect.cpp +++ b/src/Client/GUI/Engine/Elements/Shapes/Rect/ShadowRect/ShadowRect.cpp @@ -1,66 +1,48 @@ #include "../../../../Engine.hpp" #include "../../../../../../Client.hpp" -inline float GetColorComponent(ImU32 color, int shift) { - return ((color >> shift) & 0xFF) / 255.0f; -} void RoundedRectBorder(Vec2 Position, Vec2 Size, ImColor Colour, float Thickness, float Rounding, int Flags) { ImGui::GetBackgroundDrawList()->AddRect(ImVec2(Position.x, Position.y), ImVec2(Position.x + Size.x, Position.y + Size.y), Colour, Rounding, Flags, Thickness); } -void FlarialGUI::ShadowRect(Vec2 pos, Vec2 size, D2D_COLOR_F color, float rounding, int shadowSize) -{ - if (isInScrollView) pos.y += scrollpos; - - ImColor shadowColor = ImColor(color.r, color.g, color.b, color.a); - shadowColor.Value.w *= .5f; - - for (int i = 0; i < shadowSize; i++) - { - float progress = (float)i / shadowSize; - float alphaFactor = (1.0f - progress) * (1.0f - progress); //took help from gpt for alpha factor - - float shadowR = GetColorComponent(shadowColor, IM_COL32_R_SHIFT); - float shadowG = GetColorComponent(shadowColor, IM_COL32_G_SHIFT); - float shadowB = GetColorComponent(shadowColor, IM_COL32_B_SHIFT); - float shadowA = GetColorComponent(shadowColor, IM_COL32_A_SHIFT) * alphaFactor; - - ImU32 fadedShadowColor = ImColor(shadowR, shadowG, shadowB, shadowA); - - Vec2 offset = Vec2(progress * shadowSize, progress * shadowSize); - - //ImGui::GetBackgroundDrawList()->AddRect(ImVec2(pos.x - offset.x, pos.y - offset.y), ImVec2(pos.x + size.x + (offset.x * 2), pos.y + size.y + (offset.y * 2)), fadedShadowColor, rounding + progress * shadowSize, 240, 2); - - RoundedRectBorder(pos - offset, size + offset + offset, fadedShadowColor, 2.0f, rounding + progress * shadowSize, 240); - } - //ImGui::GetBackgroundDrawList()->AddRect(ImVec2(pos.x, pos.y), ImVec2(size.x + pos.y, size.y + pos.y), shadowColor, rounding, 240, 1); - RoundedRectBorder(pos, size, ImColor(color.r, color.g, color.b, color.a), 1, rounding, 240); - - /* - - color.a *= .5f; - - for (int i = 0; i < shadowSize; i++) - { - float progress = (float)i / shadowSize; - float alphaFactor = (1.0f - progress) * (1.0f - progress); //took help from gpt for alpha factor - - ImColor fadedShadowColor = ImColor(color.r, color.g, color.b, color.a * alphaFactor); +void FlarialGUI::ShadowRect(Vec2 pos, Vec2 size, D2D_COLOR_F color, float rounding, int shadowSize) { - Vec2 offset = Vec2(progress * shadowSize, progress * shadowSize); + if (Client::settings.getSettingByName("noshadows")->value) return; - ImGui::GetBackgroundDrawList()->AddRect(ImVec2(pos.x - (offset.x), pos.y - (offset.y)), ImVec2(pos.x + size.x + (offset.x * 2), pos.y + size.y + (offset.y * 2)), fadedShadowColor, rounding + progress * shadowSize, 0, 2); + if (isInScrollView) pos.y += scrollpos; - //FlarialGUI::RoundedHollowRect(pos.x - offset.x, pos.y - offset.y, 2.0f, fadedShadowColor, size.x + offset.x*2, size.y + offset.y*2, rounding + progress * shadowSize, rounding + progress * shadowSize); - - //RoundedRectBorder(pos - offset, size + offset + offset, fadedShadowColor, 2.0f, rounding + progress * shadowSize); + ImColor shadowColor(color.r, color.g, color.b, color.a * 0.5f); + + for (int i = 0; i < shadowSize; i++) { + float progress = static_cast(i) / shadowSize; + float alphaFactor = (1.0f - progress) * (1.0f - progress); + + ImColor fadedShadowColor = ImColor( + shadowColor.Value.x, + shadowColor.Value.y, + shadowColor.Value.z, + shadowColor.Value.w * alphaFactor + ); + + Vec2 offset(progress * shadowSize, progress * shadowSize); + + RoundedRectBorder( + pos - offset, + size + offset + offset, + fadedShadowColor, + 2.0f, + rounding + progress * shadowSize, + 240 + ); } - ImGui::GetBackgroundDrawList()->AddRect(ImVec2(pos.x, pos.y), ImVec2(pos.x + size.x, pos.y + size.y), D2DColorToImColor(color), rounding, 0, 2); - - //FlarialGUI::RoundedHollowRect(pos.x, pos.y, shadowSize, color, size.x, size.y, rounding, rounding); - //RoundedRectBorder(pos, size, color, 1, rounding); - - */ -} \ No newline at end of file + RoundedRectBorder( + pos, + size, + ImColor(color.r, color.g, color.b, color.a), + 1.0f, + rounding, + 240 + ); +} diff --git a/src/Client/Hook/Hooks/Render/SwapchainHook.cpp b/src/Client/Hook/Hooks/Render/SwapchainHook.cpp index a964d083..0638daac 100644 --- a/src/Client/Hook/Hooks/Render/SwapchainHook.cpp +++ b/src/Client/Hook/Hooks/Render/SwapchainHook.cpp @@ -162,6 +162,7 @@ HRESULT SwapchainHook::swapchainCallback(IDXGISwapChain3 *pSwapChain, UINT syncI } else { + SaveBackbuffer(); /* IMPORTANT FONT STUFF */ if (ImGui::GetCurrentContext()) { @@ -419,8 +420,6 @@ HRESULT SwapchainHook::swapchainCallback(IDXGISwapChain3 *pSwapChain, UINT syncI ImGui_ImplWin32_NewFrame(); ImGui::NewFrame(); - - RenderEvent event; event.RTV = mainRenderTargetView; EventHandler::onRender(event); @@ -610,3 +609,59 @@ void SwapchainHook::DX12Init() { init = true; } } + +ID3D11Texture2D* SwapchainHook::GetBackbuffer() +{ + return SavedD3D11BackBuffer; +} + + void SwapchainHook::SaveBackbuffer() + { + + Memory::SafeRelease(SavedD3D11BackBuffer); + + ID3D11DeviceContext* deviceContext; + SwapchainHook::d3d11Device->GetImmediateContext(&deviceContext); + IDXGISurface1* backBuffer = nullptr; + HRESULT hr; + SwapchainHook::swapchain->GetBuffer(0, IID_PPV_ARGS(&backBuffer)); + + ID3D11Texture2D* buffer2D = nullptr; + if(FAILED(backBuffer->QueryInterface(__uuidof(ID3D11Texture2D), reinterpret_cast(&buffer2D)))) std::cout << "failed to get 2d" << std::endl; + + D3D11_TEXTURE2D_DESC desc; + buffer2D->GetDesc(&desc); + + ID3D11Texture2D* stageTex = nullptr; + D3D11_TEXTURE2D_DESC stageDesc = desc; + stageDesc.Usage = D3D11_USAGE_STAGING; + stageDesc.CPUAccessFlags = D3D11_CPU_ACCESS_READ; + stageDesc.BindFlags = 0; + + //desc.Usage = DXGI_USAGE_SHADER_INPUT; + HRESULT r = SwapchainHook::d3d11Device->CreateTexture2D(&stageDesc, nullptr, &stageTex); + deviceContext->CopyResource(stageTex, buffer2D); + + if (FAILED(r)) std::cout << "Failed to create stage texture: " << std::hex << r << std::endl; + + + D3D11_TEXTURE2D_DESC defaultDesc = desc; + defaultDesc.Usage = D3D11_USAGE_DEFAULT; + defaultDesc.BindFlags = D3D11_BIND_SHADER_RESOURCE; + defaultDesc.CPUAccessFlags = 0; + + ID3D11Texture2D* defaultTexture = nullptr; + hr = SwapchainHook::d3d11Device->CreateTexture2D(&defaultDesc, nullptr, &defaultTexture); + if (FAILED(hr)) { + std::cout << "Failed to create def texture: " << std::hex << r << std::endl; + } + + deviceContext->CopyResource(defaultTexture, stageTex); + + stageTex->Release(); + Memory::SafeRelease(backBuffer); + Memory::SafeRelease(buffer2D); + Memory::SafeRelease(deviceContext); + + SavedD3D11BackBuffer = defaultTexture; + } diff --git a/src/Client/Hook/Hooks/Render/SwapchainHook.hpp b/src/Client/Hook/Hooks/Render/SwapchainHook.hpp index 573b5b33..d7cbb4f6 100644 --- a/src/Client/Hook/Hooks/Render/SwapchainHook.hpp +++ b/src/Client/Hook/Hooks/Render/SwapchainHook.hpp @@ -33,6 +33,9 @@ class SwapchainHook : public Hook { static void DX12Init(); + static ID3D11Texture2D* GetBackbuffer(); + static void SaveBackbuffer(); + typedef HRESULT(__thiscall *SwapchainOriginal)(IDXGISwapChain3 *, UINT, UINT); static inline SwapchainOriginal funcOriginal = nullptr; @@ -41,7 +44,7 @@ class SwapchainHook : public Hook { SwapchainHook(); void enableHook() override; - + static inline ID3D11Texture2D* SavedD3D11BackBuffer; static ID3D12CommandQueue *queue; static inline std::vector DXGISurfaces; static inline std::vector D2D1Bitmaps; diff --git a/src/Client/Module/Modules/MotionBlur/MotionBlurListener.hpp b/src/Client/Module/Modules/MotionBlur/MotionBlurListener.hpp index 6087cf8c..5058f49c 100644 --- a/src/Client/Module/Modules/MotionBlur/MotionBlurListener.hpp +++ b/src/Client/Module/Modules/MotionBlur/MotionBlurListener.hpp @@ -40,7 +40,7 @@ class MotionBlurListener : public Listener { previousFrames.erase(previousFrames.begin(), previousFrames.begin() + framesToRemove); } - ID3D11ShaderResourceView* buffer = SaveBackbuffer(); + ID3D11ShaderResourceView* buffer = BackbufferToSRV(); if(buffer) previousFrames.push_back(buffer); @@ -75,119 +75,21 @@ class MotionBlurListener : public Listener { ImGui::SetCursorScreenPos(ImVec2(pos.x + size.x, pos.y)); } - static ID3D11Texture2D* GetBackbuffer() - { + static ID3D11ShaderResourceView* BackbufferToSRV() { - ID3D11DeviceContext* deviceContext; - SwapchainHook::d3d11Device->GetImmediateContext(&deviceContext); - IDXGISurface1* backBuffer = nullptr; HRESULT hr; - SwapchainHook::swapchain->GetBuffer(0, IID_PPV_ARGS(&backBuffer)); - - ID3D11Texture2D* buffer2D = nullptr; - if(FAILED(backBuffer->QueryInterface(__uuidof(ID3D11Texture2D), reinterpret_cast(&buffer2D)))) std::cout << "failed to get 2d" << std::endl; - - D3D11_TEXTURE2D_DESC desc; - buffer2D->GetDesc(&desc); - - ID3D11Texture2D* stageTex = nullptr; - D3D11_TEXTURE2D_DESC stageDesc = desc; - stageDesc.Usage = D3D11_USAGE_STAGING; - stageDesc.CPUAccessFlags = D3D11_CPU_ACCESS_READ; - stageDesc.BindFlags = 0; - - //desc.Usage = DXGI_USAGE_SHADER_INPUT; - HRESULT r = SwapchainHook::d3d11Device->CreateTexture2D(&stageDesc, nullptr, &stageTex); - deviceContext->CopyResource(stageTex, buffer2D); - - if (FAILED(r)) std::cout << "Failed to create stage texture: " << std::hex << r << std::endl; - - - D3D11_TEXTURE2D_DESC defaultDesc = desc; - defaultDesc.Usage = D3D11_USAGE_DEFAULT; - defaultDesc.BindFlags = D3D11_BIND_SHADER_RESOURCE; - defaultDesc.CPUAccessFlags = 0; - - ID3D11Texture2D* defaultTexture = nullptr; - hr = SwapchainHook::d3d11Device->CreateTexture2D(&defaultDesc, nullptr, &defaultTexture); - if (FAILED(hr)) { - std::cout << "Failed to create def texture: " << std::hex << r << std::endl; - } - - deviceContext->CopyResource(defaultTexture, stageTex); - - stageTex->Release(); - - //if(outSRV) std::cout << "Wroekd" << std::endl; - - backBuffer->Release(); - buffer2D->Release(); - - return defaultTexture; - } - - - static ID3D11ShaderResourceView* SaveBackbuffer() - { - - ID3D11DeviceContext* deviceContext; - SwapchainHook::d3d11Device->GetImmediateContext(&deviceContext); - IDXGISurface1* backBuffer = nullptr; - HRESULT hr; - SwapchainHook::swapchain->GetBuffer(0, IID_PPV_ARGS(&backBuffer)); - - ID3D11Texture2D* buffer2D = nullptr; - if(FAILED(backBuffer->QueryInterface(__uuidof(ID3D11Texture2D), reinterpret_cast(&buffer2D)))) std::cout << "failed to get 2d" << std::endl; - - D3D11_TEXTURE2D_DESC desc; - buffer2D->GetDesc(&desc); - - ID3D11Texture2D* stageTex = nullptr; - D3D11_TEXTURE2D_DESC stageDesc = desc; - stageDesc.Usage = D3D11_USAGE_STAGING; - stageDesc.CPUAccessFlags = D3D11_CPU_ACCESS_READ; - stageDesc.BindFlags = 0; - - //desc.Usage = DXGI_USAGE_SHADER_INPUT; - HRESULT r = SwapchainHook::d3d11Device->CreateTexture2D(&stageDesc, nullptr, &stageTex); - deviceContext->CopyResource(stageTex, buffer2D); - - if (FAILED(r)) std::cout << "Failed to create stage texture: " << std::hex << r << std::endl; - - - D3D11_TEXTURE2D_DESC defaultDesc = desc; - defaultDesc.Usage = D3D11_USAGE_DEFAULT; - defaultDesc.BindFlags = D3D11_BIND_SHADER_RESOURCE; - defaultDesc.CPUAccessFlags = 0; - - ID3D11Texture2D* defaultTexture = nullptr; - hr = SwapchainHook::d3d11Device->CreateTexture2D(&defaultDesc, nullptr, &defaultTexture); - if (FAILED(hr)) { - std::cout << "Failed to create def texture: " << std::hex << r << std::endl; - } - - deviceContext->CopyResource(defaultTexture, stageTex); - - stageTex->Release(); - ID3D11ShaderResourceView* outSRV; D3D11_SHADER_RESOURCE_VIEW_DESC srvDesc; - srvDesc.Format = desc.Format; + srvDesc.Format = DXGI_FORMAT_R8G8B8A8_UNORM; srvDesc.ViewDimension = D3D11_SRV_DIMENSION_TEXTURE2D; - srvDesc.Texture2D.MipLevels = desc.MipLevels; + srvDesc.Texture2D.MipLevels = 1; srvDesc.Texture2D.MostDetailedMip = 0; - if (FAILED(hr = SwapchainHook::d3d11Device->CreateShaderResourceView(defaultTexture, &srvDesc, &outSRV))) + if (FAILED(hr = SwapchainHook::d3d11Device->CreateShaderResourceView(SwapchainHook::GetBackbuffer(), &srvDesc, &outSRV))) { std::cout << "Failed to create shader resource view: " << std::hex << hr << std::endl; } - //if(outSRV) std::cout << "Wroekd" << std::endl; - - Memory::SafeRelease(backBuffer); - Memory::SafeRelease(buffer2D); - Memory::SafeRelease(defaultTexture); - return outSRV; } @@ -405,6 +307,6 @@ void InitializeRenderResources(ID3D11Device* device) //context->OMSetRenderTargets(1, nullptr, nullptr); - std::cout << "trolled" << std::endl; + context->Release(); } }; \ No newline at end of file