Skip to content

Commit

Permalink
Fix shadow, light issues, weird green stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
praydog committed Feb 23, 2024
1 parent 14c778e commit 99985d1
Showing 1 changed file with 46 additions and 3 deletions.
49 changes: 46 additions & 3 deletions src/Plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include <d3d12.h>
#include <utility/Scan.hpp>
#include <utility/Module.hpp>
#include <utility/Patch.hpp>

#include <GraphicsMemory.h>

Expand Down Expand Up @@ -63,21 +64,61 @@ 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();
const auto result = utility::scan(game, "81 3D ? ? ? ? 80 07 00 00");

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() {
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -306,4 +349,4 @@ class FF7Plugin final : public uevr::Plugin {
};


std::unique_ptr<FF7Plugin> g_plugin{new FF7Plugin()};
std::unique_ptr<FF7Plugin> g_plugin{std::make_unique<FF7Plugin>()};

0 comments on commit 99985d1

Please sign in to comment.