Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 22 additions & 2 deletions src/mods/vr/FFakeStereoRenderingHook.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7278,9 +7278,18 @@ bool VRRenderTargetManager_Base::create_scene_capture() try {
auto viewport = rtm != nullptr ? rtm->get_viewport() : nullptr;

if (viewport != nullptr) {
return viewport->get_display_gamma();
const auto gamma = viewport->get_display_gamma();

// Logged because the two branches look the same on screen. A viewport reporting 2.2 and a
// missing viewport falling back to 2.2 give the same picture, but only this one follows the
// game's own gamma setting.
SPDLOG_INFO_ONCE("[FRenderTarget] Matching the scene capture's display gamma to the viewport's, currently {}", gamma);

return gamma;
}

SPDLOG_WARN_ONCE("[FRenderTarget] No viewport to read the display gamma from, assuming 2.2");

return 2.2f;
};

Expand All @@ -7295,7 +7304,18 @@ bool VRRenderTargetManager_Base::create_scene_capture() try {
auto& vtable = *(void**)frt;
memcpy(original_frender_target_vtable.data(), vtable, original_frender_target_vtable.size() * sizeof(uintptr_t));

if (auto display_gamma_index = sdk::FRenderTarget::get_display_gamma_index(); display_gamma_index != 0) {
// has_value(), not != 0.
//
// An empty std::optional compares as less than any number, so "index != 0" was true exactly when
// the index had not been found. Dereferencing it wrote gamma_increase_fn at whatever slot that
// produced, and the vtable was swapped to that copy. In the log it shows up as a failed search
// with "Hooked FRenderTarget!" on the next line.
if (const auto display_gamma_index = sdk::FRenderTarget::get_display_gamma_index(); display_gamma_index.has_value()) {
if (*display_gamma_index >= original_frender_target_vtable.size()) {
SPDLOG_WARN("[FRenderTarget] Gamma index {} is out of range, can't hook!", *display_gamma_index);
return;
}

original_frender_target_vtable[*display_gamma_index] = (uintptr_t)gamma_increase_fn;
vtable = original_frender_target_vtable.data();
SPDLOG_INFO("[FRenderTarget] Hooked FRenderTarget!");
Expand Down
Loading