Skip to content

Commit

Permalink
Fix case where ghosting fix could fail on modular builds
Browse files Browse the repository at this point in the history
  • Loading branch information
praydog committed Jun 21, 2023
1 parent a7e465e commit ca86fab
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 6 deletions.
22 changes: 17 additions & 5 deletions shared/sdk/FSceneView.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,12 @@ std::optional<uintptr_t> FSceneView::get_constructor_address() {

// We need to find the string references "vr.InstancedStereo" and "r.TranslucentSortPolicy"
// These two strings will reside together within the same function (the constructor)
const auto instanced_strings = utility::scan_strings(module, L"vr.InstancedStereo");
// ADDENDUM: We are only finding the references for "r.TranslucentSortPolicy" now
// we are still making use of "vr.InstancedStereo" but we are checking whether instructions
// reference data that == L"vr.InstancedStereo" instead of checking for the string reference itself
const auto translucent_strings = utility::scan_strings(module, L"r.TranslucentSortPolicy");

if (instanced_strings.empty() || translucent_strings.empty()) {
if (translucent_strings.empty()) {
SPDLOG_ERROR("[FSceneView] Failed to find string references for FSceneView constructor");
return std::nullopt;
}
Expand Down Expand Up @@ -107,13 +109,23 @@ std::optional<uintptr_t> FSceneView::get_constructor_address() {
return utility::ExhaustionResult::CONTINUE;
}

// Check if the displacement is any of the vr.InstancedStereo strings
for (const auto& instanced_string : instanced_strings) {
if (*displacement == instanced_string) {
// Directly check the data at the displacement instead
// because modular builds have the string in a different DLL
// and hardcoding which DLL its in seems sloppy
try {
const auto potential_string = (wchar_t*)*displacement;

if (IsBadReadPtr(potential_string, sizeof(wchar_t) * 2)) {
return utility::ExhaustionResult::CONTINUE;
}

if (std::wstring_view{ potential_string } == L"vr.InstancedStereo") {
SPDLOG_INFO("[FSceneView] Found correct displacement at 0x{:x}", ip);
is_correct_function = true;
return utility::ExhaustionResult::BREAK;
}
} catch(...) {

}

return utility::ExhaustionResult::CONTINUE;
Expand Down
3 changes: 2 additions & 1 deletion src/mods/vr/FFakeStereoRenderingHook.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4307,7 +4307,8 @@ uint32_t FFakeStereoRenderingHook::get_desired_number_of_views_hook(FFakeStereoR

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() < 2 && g_hook->m_fixed_localplayer_view_count)
g_hook->m_sceneview_data.known_scene_states.size() < 2 && g_hook->m_fixed_localplayer_view_count &&
!!g_hook->m_sceneview_data.constructor_hook)
{
return 2; // We need to know about the second scene state to fix ghosting
}
Expand Down

0 comments on commit ca86fab

Please sign in to comment.