From 399eaabde2164e67cf881aea16646a7e368e94fb Mon Sep 17 00:00:00 2001 From: praydog Date: Wed, 15 May 2024 05:56:52 -0700 Subject: [PATCH] Graphics: Add "replace shader" --- src/mods/Graphics.cpp | 15 ++++++++++++++- src/mods/Graphics.hpp | 8 ++++++++ 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/src/mods/Graphics.cpp b/src/mods/Graphics.cpp index 0a31248e1..d24a960c7 100644 --- a/src/mods/Graphics.cpp +++ b/src/mods/Graphics.cpp @@ -177,6 +177,10 @@ void Graphics::on_draw_ui() { } if (interception_node_open) { + if (ImGui::InputText(std::format("Replace Shader", i).c_str(), intercepted.replace_with_name.data(), intercepted.replace_with_name.size())) { + intercepted.replace_with_hash = sdk::murmur_hash::calc32_as_utf8(intercepted.replace_with_name.data()); + } + for (auto& replacement : intercepted.replacement_shaders) { i++; ImGui::PushID(std::format("Shader {}", i).c_str()); @@ -1110,7 +1114,7 @@ sdk::renderer::PipelineState* Graphics::find_pipeline_state_hook(void* shader_re auto& graphics = Graphics::get(); const auto og = graphics->m_find_pipeline_state_hook->get_original(); - const auto result = og(shader_resource, murmur_hash, unk); + auto result = og(shader_resource, murmur_hash, unk); if (!graphics->m_shader_playground->value()) { return result; @@ -1135,6 +1139,15 @@ sdk::renderer::PipelineState* Graphics::find_pipeline_state_hook(void* shader_re if (intercepted_shader == nullptr) { return result; } + + if (intercepted_shader->replace_with_hash != 0 || std::string_view{intercepted_shader->replace_with_name} == "None") { + const auto replacement = og(shader_resource, intercepted_shader->replace_with_hash, unk); + + if (replacement != nullptr) { + result = replacement; + } + } + uint32_t i = 1; for (auto& replacement_shader : intercepted_shader->replacement_shaders) { diff --git a/src/mods/Graphics.hpp b/src/mods/Graphics.hpp index 1964d45d0..1f14fb4fb 100644 --- a/src/mods/Graphics.hpp +++ b/src/mods/Graphics.hpp @@ -97,6 +97,14 @@ class Graphics : public Mod { }(); uint32_t hash{ 0 }; + + std::string replace_with_name = []() { + std::string result{}; + result.resize(1024); + return result; + }(); + + uint32_t replace_with_hash{ 0 }; }; std::array m_intercepted_shaders{};