Skip to content

Commit

Permalink
Merge branch 'master' into csharp-api
Browse files Browse the repository at this point in the history
  • Loading branch information
praydog committed May 15, 2024
2 parents 6c001da + 440cca9 commit 303af01
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 4 deletions.
4 changes: 2 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -131,13 +131,13 @@ FetchContent_Declare(
)
FetchContent_MakeAvailable(directxtk12)

message(STATUS "Fetching safetyhook (4faf792c2d66cbf06f2c942561d053aafd79006b)...")
message(STATUS "Fetching safetyhook (b046e123dc69821f2c375161e0adef3c6d9c9db4)...")
FetchContent_Declare(
safetyhook
GIT_REPOSITORY
https://github.com/cursey/safetyhook
GIT_TAG
4faf792c2d66cbf06f2c942561d053aafd79006b
b046e123dc69821f2c375161e0adef3c6d9c9db4
)
FetchContent_MakeAvailable(safetyhook)

Expand Down
2 changes: 1 addition & 1 deletion cmake.toml
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ condition = "build-framework-dependencies"

[fetch-content.safetyhook]
git = "https://github.com/cursey/safetyhook"
tag = "4faf792c2d66cbf06f2c942561d053aafd79006b"
tag = "b046e123dc69821f2c375161e0adef3c6d9c9db4"

[target.imgui]
type = "static"
Expand Down
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 303af01

Please sign in to comment.