From 99985d1a5590d2094646dd0a33b6f208160056f4 Mon Sep 17 00:00:00 2001 From: praydog Date: Fri, 23 Feb 2024 07:13:15 -0800 Subject: [PATCH] Fix shadow, light issues, weird green stuff --- src/Plugin.cpp | 49 ++++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 46 insertions(+), 3 deletions(-) diff --git a/src/Plugin.cpp b/src/Plugin.cpp index 69918de..0a2fac2 100644 --- a/src/Plugin.cpp +++ b/src/Plugin.cpp @@ -7,6 +7,7 @@ #include #include #include +#include #include @@ -63,7 +64,11 @@ class FF7Plugin final : public uevr::Plugin { } data; }; - void on_initialize() override { + virtual ~FF7Plugin() { + m_light_flagspatch.reset(); + } + + bool resolve_system_resolution() { // Find some horrible code that hardcodes a check against 1920 // so we can find the GSystemResolution const auto game = utility::get_executable(); @@ -71,13 +76,49 @@ class FF7Plugin final : public uevr::Plugin { if (!result) { API::get()->log_error("Failed to find GSystemResolution"); - return; + return false; } const auto addr = utility::calculate_absolute(result.value() + 2, 8); m_system_resolution = (int32_t*)addr; API::get()->log_info("Found GSystemResolution at 0x%p", (void*)m_system_resolution); + return true; + } + + bool render_lights_patch() { + // FDeferredShadingSceneRenderer::RenderLights + const auto game = utility::get_executable(); + const auto render_lights_fn = utility::find_function_from_string_ref(game, L"ScreenShadowMaskTexture"); + + if (!render_lights_fn) { + API::get()->log_error("Failed to find FDeferredShadingSceneRenderer::RenderLights"); + return false; + } + + // const auto light_flag_bit_manip = utility::scan_disasm(*render_lights_fn, 0x500, "83 E1 BF"); + const auto light_flag_bit_manip = utility::scan_disasm(*render_lights_fn, 0x500, "? 40 00 00 00"); + + if (!light_flag_bit_manip) { + API::get()->log_error("Failed to find light flag bit manipulation"); + return false; + } + + API::get()->log_info("Found light flag bit manipulation at 0x%p", (void*)light_flag_bit_manip.value()); + + // Patch it to OR ECX, -1 (0xFFFFFFFF) + // m_light_flagspatch = Patch::create(*light_flag_bit_manip, {0x83, 0xC9, 0xFF}, true); + // I was originally going to do that (set all the flags), but it's safer to add the 0x20 flag + const auto original_register = *(uint8_t*)light_flag_bit_manip.value(); + m_light_flagspatch = Patch::create(*light_flag_bit_manip, {(uint16_t)original_register, 0x40 | 0x20}, true); + API::get()->log_info("Patched light flag bit manipulation"); + + return true; + } + + void on_initialize() override { + resolve_system_resolution(); + render_lights_patch(); } void on_present() { @@ -253,6 +294,8 @@ class FF7Plugin final : public uevr::Plugin { } private: + Patch::Ptr m_light_flagspatch{}; + std::recursive_mutex m_present_mutex{}; API::FRHITexture2D* m_last_engine_ui_tex{nullptr}; // The engine's render target @@ -306,4 +349,4 @@ class FF7Plugin final : public uevr::Plugin { }; -std::unique_ptr g_plugin{new FF7Plugin()}; \ No newline at end of file +std::unique_ptr g_plugin{std::make_unique()}; \ No newline at end of file