Skip to content

Commit

Permalink
Fix two scene states sometimes not getting created
Browse files Browse the repository at this point in the history
  • Loading branch information
praydog committed Jun 19, 2023
1 parent 3c99a61 commit b43cdd7
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
12 changes: 11 additions & 1 deletion src/mods/vr/FFakeStereoRenderingHook.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2574,6 +2574,8 @@ sdk::FSceneView* FFakeStereoRenderingHook::sceneview_constructor(sdk::FSceneView
if (init_options_scene_state != nullptr && !g_hook->m_sceneview_data.known_scene_states.contains(init_options_scene_state)) {
SPDLOG_INFO("Inserting new scene state {:x}", (uintptr_t)init_options_scene_state);
known_scene_states.insert(init_options_scene_state);
} else if (init_options_scene_state == nullptr) {
SPDLOG_ERROR_ONCE("Scene state passed to FSceneView constructor is null");
}

if (init_options_scene_state != nullptr && vr->is_ghosting_fix_enabled() && known_scene_states.size() > 1 && vr->is_using_afr() && true_index == 1) {
Expand Down Expand Up @@ -4303,9 +4305,13 @@ uint32_t FFakeStereoRenderingHook::get_desired_number_of_views_hook(FFakeStereoR

auto& vr = VR::get();

if (g_hook->m_sceneview_data.inside_post_init_properties) {
return 2;
}

if (!is_stereo_enabled || (vr->is_using_afr() && !vr->is_splitscreen_compatibility_enabled())) {
if (is_stereo_enabled && vr->is_ghosting_fix_enabled() && vr->is_using_afr() &&
g_hook->m_sceneview_data.known_scene_states.size() == 1 && g_hook->m_fixed_localplayer_view_count)
g_hook->m_sceneview_data.known_scene_states.size() < 2 && g_hook->m_fixed_localplayer_view_count)
{
return 2; // We need to know about the second scene state to fix ghosting
}
Expand Down Expand Up @@ -4734,7 +4740,10 @@ void FFakeStereoRenderingHook::post_init_properties(uintptr_t localplayer) {
};

const auto exception_handler = AddVectoredExceptionHandler(1, seh_handler);

m_sceneview_data.inside_post_init_properties = true;
post_init_properties(localplayer);
m_sceneview_data.inside_post_init_properties = false;

SPDLOG_INFO("PostInitProperties called!");

Expand All @@ -4743,6 +4752,7 @@ void FFakeStereoRenderingHook::post_init_properties(uintptr_t localplayer) {
peb->BeingDebugged = old;
}

g_hook->m_sceneview_data.known_scene_states.clear();
g_hook->m_fixed_localplayer_view_count = true;
}

Expand Down
1 change: 1 addition & 0 deletions src/mods/vr/FFakeStereoRenderingHook.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -343,6 +343,7 @@ class FFakeStereoRenderingHook : public ModComponent {
struct {
safetyhook::InlineHook constructor_hook{};
std::unordered_set<void*> known_scene_states;
bool inside_post_init_properties{false};
} m_sceneview_data;

safetyhook::InlineHook m_localplayer_get_viewpoint_hook{};
Expand Down

0 comments on commit b43cdd7

Please sign in to comment.