Skip to content

Commit

Permalink
Merge branch 'mainRepo' into NewFeatures
Browse files Browse the repository at this point in the history
  • Loading branch information
FreezeEngine committed Aug 5, 2024
2 parents 47bd1c5 + c7183dc commit 9db19aa
Show file tree
Hide file tree
Showing 11 changed files with 78 additions and 115 deletions.
2 changes: 1 addition & 1 deletion CMakeSettings.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
{
"name": "x64-Release",
"generator": "Ninja",
"configurationType": "Release",
"configurationType": "RelWithDebInfo",
"buildRoot": "${projectDir}\\out\\build\\${name}",
"installRoot": "${projectDir}\\out\\install\\${name}",
"cmakeCommandArgs": "",
Expand Down
119 changes: 40 additions & 79 deletions src/Client/GUI/Engine/Effects/Blur/blur.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,54 +78,53 @@ float4 main(float4 screenSpace : SV_Position) : SV_TARGET
const char *upsampleShaderSrc = R"(
cbuffer BlurInputBuffer : register(b0)
{
float intensity;
float2 resolution;
float2 offset;
float2 halfPixel;
};
sampler sampler0 : register(s0);
Texture2D texture0 : register(t0);
Texture2D inputTexture : register(t0);
float4 main(float4 screenSpace : SV_Position) : SV_TARGET
{
float2 uv = screenSpace.xy / resolution;
float4 colorSum = float4(0.0, 0.0, 0.0, 0.0);
static const float2 offsets[9] = {
float2(-1.0, -1.0) * halfPixel * offset,
float2(0.0, -1.0) * halfPixel * offset,
float2(1.0, -1.0) * halfPixel * offset,
float2(-1.0, 0.0) * halfPixel * offset,
float2(0.0, 0.0) * halfPixel * offset,
float2(1.0, 0.0) * halfPixel * offset,
float2(-1.0, 1.0) * halfPixel * offset,
float2(0.0, 1.0) * halfPixel * offset,
float2(1.0, 1.0) * halfPixel * offset
};
static const float weights[9] = {
0.06136, 0.12245, 0.06136,
0.12245, 0.24477, 0.12245,
0.06136, 0.12245, 0.06136
float2 texSize = resolution;
float2 texelSize = 1.0f / texSize;
float2 texCoord = screenSpace.xy / texSize;
// Scale offsets with a larger factor for more noticeable blur
float2 offsets[9] = {
float2(-1.0f, -1.0f), float2(0.0f, -1.0f), float2(1.0f, -1.0f),
float2(-1.0f, 0.0f), float2(0.0f, 0.0f), float2(1.0f, 0.0f),
float2(-1.0f, 1.0f), float2(0.0f, 1.0f), float2(1.0f, 1.0f)
};
float weightSum = 0.0;
float weights[9];
float sum = 0.0f;
float sigma = intensity * 2.0f; // Scale intensity for more noticeable blur
for (int i = 0; i < 9; i++)
{
weightSum += weights[i];
float2 offset = offsets[i] * texelSize * sigma;
weights[i] = exp(-dot(offset, offset) / (2.0f * sigma * sigma));
sum += weights[i];
}
float4 color = float4(0.0f, 0.0f, 0.0f, 0.0f);
for (int i = 0; i < 9; i++)
{
colorSum += texture0.Sample(sampler0, uv + offsets[i]) * (weights[i] / weightSum);
float2 offset = offsets[i] * texelSize * sigma;
color += inputTexture.Sample(sampler0, texCoord + offset) * weights[i];
}
return colorSum;
color /= sum;
return color;
}
)";




const char *dbgDrawTextureShaderSrc = "cbuffer BlurInputBuffer : register(b0)\
{\
float2 resolution;\
Expand All @@ -146,20 +145,25 @@ float4 main(PS_INPUT input, float4 screenSpace : SV_Position) : SV_TARGET {\
ID3DBlob *TryCompileShader(const char *pSrcData, const char *pTarget)
{
HRESULT hr;
ID3DBlob *shaderBlob = nullptr;
ID3DBlob *errorBlob = nullptr;

ID3DBlob *shaderBlob;
ID3DBlob *errorBlob;
hr = D3DCompile(pSrcData, strlen(pSrcData), nullptr, nullptr, nullptr, "main", pTarget, 0, 0, &shaderBlob, &errorBlob);

if (FAILED(hr))
{
Logger::error("[Blur] Failed to compile shader");
errorBlob->Release();
if (errorBlob)
{
Logger::error(std::format("[Blur] Failed to compile shader: {}", static_cast<char*>(errorBlob->GetBufferPointer())));
errorBlob->Release();
}
throw std::logic_error("Failed to compile shader!");
}

return shaderBlob;
}


ID3D11PixelShader *dbgShader;

void Blur::InitializePipeline()
Expand Down Expand Up @@ -232,8 +236,6 @@ void Blur::RenderToRTV(ID3D11RenderTargetView *pRenderTargetView, ID3D11ShaderRe
pContext->PSSetShaderResources(0, 1, (ID3D11ShaderResourceView **)&null);
pContext->OMSetRenderTargets(1, &pRenderTargetView, nullptr);

constantBuffer.resolution = rtvSize;
constantBuffer.halfpixel = XMFLOAT2(0.5 / rtvSize.x, 0.5 / rtvSize.y);
pContext->UpdateSubresource(pConstantBuffer, 0, nullptr, &constantBuffer, 0, 0);

pContext->IASetInputLayout(pInputLayout);
Expand Down Expand Up @@ -294,6 +296,8 @@ void Blur::RenderToRTV(ID3D11RenderTargetView *pRenderTargetView, ID3D11ShaderRe

void Blur::RenderBlur(ID3D11RenderTargetView *pDstRenderTargetView, int iterations, float intensity)
{
if(intensity < 1) return;

if (!SwapchainHook::GetBackbuffer()) return;

ID3D11ShaderResourceView *pOrigShaderResourceView = MotionBlurListener::BackbufferToSRV();
Expand All @@ -319,56 +323,13 @@ void Blur::RenderBlur(ID3D11RenderTargetView *pDstRenderTargetView, int iteratio

desc.BindFlags |= D3D11_BIND_RENDER_TARGET;

for (int i = 0; i <= iterations; i++)
{
ID3D11Texture2D *pFrameBuffer;
ID3D11RenderTargetView *pRenderTargetView;
ID3D11ShaderResourceView *pShaderResourceView;

SwapchainHook::d3d11Device->CreateTexture2D(&desc, nullptr, &pFrameBuffer);
if (i == 0)
pRenderTargetView = pDstRenderTargetView;
else
SwapchainHook::d3d11Device->CreateRenderTargetView(pFrameBuffer, nullptr, &pRenderTargetView);
SwapchainHook::d3d11Device->CreateShaderResourceView(pFrameBuffer, nullptr, &pShaderResourceView);

framebuffers.push_back(pFrameBuffer);
renderTargetViews.push_back(pRenderTargetView);
shaderResourceViews.push_back(pShaderResourceView);
fbSizes.push_back(XMFLOAT2(desc.Width, desc.Height));

desc.Width /= 2;
desc.Height /= 2;
}
XMFLOAT2 fbSize = XMFLOAT2(desc.Width, desc.Height);

constantBuffer.offset = XMFLOAT2(intensity, intensity);
pContext->PSSetShader(pDownsampleShader, nullptr, 0);
RenderToRTV(renderTargetViews[1], pOrigShaderResourceView, fbSizes[1]);

for (int i = 1; i < iterations; i++)
{
RenderToRTV(renderTargetViews[i + 1], shaderResourceViews[i], fbSizes[i + 1]);
}
constantBuffer.intensity = intensity;
constantBuffer.resolution = fbSize;

pContext->PSSetShader(pUpsampleShader, nullptr, 0);

for (int i = iterations; i > 0; i--)
{
RenderToRTV(renderTargetViews[i - 1], shaderResourceViews[i], fbSizes[i - 1]);
}

for (int i = 0; i < iterations; i++)
{
if (i != 0)
renderTargetViews[i]->Release();
framebuffers[i]->Release();
shaderResourceViews[i]->Release();

renderTargetViews.clear();
framebuffers.clear();
shaderResourceViews.clear();
fbSizes.clear();
}
RenderToRTV(pDstRenderTargetView, pOrigShaderResourceView, fbSize);

pContext->Release();
pOrigShaderResourceView->Release();
Expand Down
18 changes: 9 additions & 9 deletions src/Client/GUI/Engine/Engine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -765,39 +765,39 @@ std::string FlarialGUI::FlarialTextWithFont(float x, float y, const wchar_t *tex

//std::cout << weightedName << std::endl;


float sizeMultiplier = 1.0f;
if(hasEnding(weightedName, "2.0")) sizeMultiplier = 0.6f;

ImGui::PushFont(FontMap[weightedName]);
float fSize = (fontSize / 135) * sizeMultiplier;

ImGui::SetWindowFontScale(fSize);

std::string stringText = WideToNarrow(text).c_str();
ImVec2 size = ImGui::CalcTextSize(stringText.c_str());
std::string fontedName = weightedName + std::to_string(fSize);


switch (alignment) {
case DWRITE_TEXT_ALIGNMENT_LEADING:
break;

case DWRITE_TEXT_ALIGNMENT_CENTER: {
x += (width / 2) - (ImGui::CalcTextSize(WideToNarrow(text).c_str()).x / 2);
x += (width / 2) - (size.x / 2);
break;
}

case DWRITE_TEXT_ALIGNMENT_TRAILING: {
x += (width - ImGui::CalcTextSize(WideToNarrow(text).c_str()).x);
x += (width - size.x);
break;
}
}

TextSizes[weightedName + std::to_string(fSize)] = ImGui::CalcTextSize(WideToNarrow(text).c_str()).x;

y += (height / 2) - (ImGui::CalcTextSize(WideToNarrow(text).c_str()).y / 2);
ImGui::GetBackgroundDrawList()->AddText(ImVec2(x, y), ImColor(color.r, color.g, color.b, color.a), WideToNarrow(text).c_str());
TextSizes[fontedName] = size.x;
y += (height / 2) - (size.y / 2);
ImGui::GetBackgroundDrawList()->AddText(ImVec2(x, y), ImColor(color.r, color.g, color.b, color.a), stringText.c_str());
ImGui::PopFont();

return weightedName + std::to_string(fSize);
return fontedName;
}

void FlarialGUI::LoadFont(int resourceId) {
Expand Down
5 changes: 2 additions & 3 deletions src/Client/GUI/Engine/Engine.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,9 @@ using namespace DirectX;

struct BlurInputBuffer
{
FLOAT intensity;
XMFLOAT2 resolution;
XMFLOAT2 offset;
XMFLOAT2 halfpixel;
XMFLOAT2 _dummy;
FLOAT padding[1];
};


Expand Down
36 changes: 17 additions & 19 deletions src/Client/Hook/Hooks/Render/SwapchainHook.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -620,7 +620,7 @@ ID3D11Texture2D* SwapchainHook::GetBackbuffer()
void SwapchainHook::SaveBackbuffer()
{

Memory::SafeRelease(SavedD3D11BackBuffer);
if(SwapchainHook::queue) return;

ID3D11DeviceContext* deviceContext;
SwapchainHook::d3d11Device->GetImmediateContext(&deviceContext);
Expand All @@ -633,37 +633,35 @@ ID3D11Texture2D* SwapchainHook::GetBackbuffer()

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);
HRESULT r;

if(!stageTex) {
D3D11_TEXTURE2D_DESC stageDesc = desc;
stageDesc.Usage = D3D11_USAGE_STAGING;
stageDesc.CPUAccessFlags = D3D11_CPU_ACCESS_READ;
stageDesc.BindFlags = 0;
r = SwapchainHook::d3d11Device->CreateTexture2D(&stageDesc, nullptr, &stageTex);
if (FAILED(r)) std::cout << "Failed to create stage texture: " << std::hex << r << std::endl;
}
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;
if(!SavedD3D11BackBuffer) {
hr = SwapchainHook::d3d11Device->CreateTexture2D(&defaultDesc, nullptr, &SavedD3D11BackBuffer);
if (FAILED(hr)) {
std::cout << "Failed to create def texture: " << std::hex << r << std::endl;
}
}

deviceContext->CopyResource(defaultTexture, stageTex);
deviceContext->CopyResource(SavedD3D11BackBuffer, stageTex);

stageTex->Release();
Memory::SafeRelease(backBuffer);
Memory::SafeRelease(buffer2D);
Memory::SafeRelease(deviceContext);

SavedD3D11BackBuffer = defaultTexture;
}
1 change: 1 addition & 0 deletions src/Client/Hook/Hooks/Render/SwapchainHook.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ class SwapchainHook : public Hook {
static inline ID3D12GraphicsCommandList* DX12CommandLists;
static bool hasResized;
static int currentBitmap;
static inline ID3D11Texture2D* stageTex;

static inline ID3D12Device5* d3d12Device5 = nullptr;

Expand Down
1 change: 1 addition & 0 deletions src/Client/Module/Modules/ArmorHUD/ArmorHUDListener.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,7 @@ class ArmorHUDListener : public Listener {
}

void onSetupAndRender(SetupAndRenderEvent &event) override {
if(this->module->isEnabled())
if (ClientInstance::getTopScreenName() == "hud_screen") {
auto muirc = event.getMuirc();
BaseActorRenderContext barc(muirc->screenContext, muirc->clientInstance,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,8 @@ class InventoryHUDListener : public Listener {
}

void onSetupAndRender(SetupAndRenderEvent &event) override {

if(this->module->isEnabled())
if (ClientInstance::getTopScreenName() == "hud_screen") {
auto muirc = event.getMuirc();
BaseActorRenderContext barc(muirc->screenContext, muirc->clientInstance,
Expand Down
3 changes: 1 addition & 2 deletions src/Client/Module/Modules/MotionBlur/MotionBlurListener.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -263,8 +263,7 @@ void InitializeRenderResources(ID3D11Device* device)
void RenderSRV(ID3D11ShaderResourceView* srv, float width, float height, float opacity)
{

ID3D11DeviceContext* context;
SwapchainHook::d3d11Device->GetImmediateContext(&context);
ID3D11DeviceContext* context = SwapchainHook::context;


context->OMSetRenderTargets(1, &gRTV, gDSV);
Expand Down
2 changes: 2 additions & 0 deletions src/Client/Module/Modules/MovableChat/MovableChatListener.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,8 @@ class MovableChatListener : public Listener {

void onSetupAndRender(SetupAndRenderEvent &event) override {

if(this->module->isEnabled())


if (SDK::screenView->VisualTree->root->LayerName == "hud_screen") {

Expand Down
4 changes: 2 additions & 2 deletions src/Client/Module/Modules/PaperDoll/DollListener.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,9 @@ class DollListener : public Listener {
}

void onSetupAndRender(SetupAndRenderEvent &event) override {
if(SDK::currentScreen == "hud_screen") {

if(this->module->isEnabled())
if(SDK::currentScreen == "hud_screen") {
SDK::screenView->VisualTree->root->forEachControl([this](std::shared_ptr<UIControl>& control) {

if (control->LayerName == "hud_player") {
Expand All @@ -101,7 +102,6 @@ class DollListener : public Listener {

return; // dont go through other controls
}

});
}
}
Expand Down

0 comments on commit 9db19aa

Please sign in to comment.