Skip to content

Commit

Permalink
Graphics: Add "replace shader"
Browse files Browse the repository at this point in the history
  • Loading branch information
praydog committed May 15, 2024
1 parent 7bd947d commit 399eaab
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
15 changes: 14 additions & 1 deletion src/mods/Graphics.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down Expand Up @@ -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<decltype(find_pipeline_state_hook)>();
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;
Expand All @@ -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) {
Expand Down
8 changes: 8 additions & 0 deletions src/mods/Graphics.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<InterceptedShader, 8> m_intercepted_shaders{};
Expand Down

0 comments on commit 399eaab

Please sign in to comment.