Skip to content

Commit afae87f

Browse files
committed
VR: Fix case where compiler optimizations could cause heuristic failures
1 parent 18801f9 commit afae87f

File tree

1 file changed

+22
-2
lines changed

1 file changed

+22
-2
lines changed

src/mods/vr/FFakeStereoRenderingHook.cpp

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -739,6 +739,26 @@ bool FFakeStereoRenderingHook::standard_fake_stereo_hook(uintptr_t vtable) {
739739
return false;
740740
}
741741

742+
// Some compiler optimizations cause 31 C0 (xor eax, eax) to be used.
743+
bool uses_33_c0 = false;
744+
745+
for (size_t i = 0; i < 30; ++i) try {
746+
const auto fn = ((uintptr_t*)vtable)[i];
747+
748+
if (fn == 0 || IsBadReadPtr((void*)fn, sizeof(void*))) {
749+
SPDLOG_WARN("Found null function pointer at index {}", i);
750+
break;
751+
}
752+
753+
if (sdk::is_vfunc_pattern(fn, "33 C0")) {
754+
uses_33_c0 = true;
755+
SPDLOG_INFO("Found 33 C0 pattern at index {}", i);
756+
break;
757+
}
758+
} catch(...) {
759+
760+
}
761+
742762
const auto stereo_projection_matrix_index = *stereo_view_offset_index + 1;
743763
const auto is_4_18_or_lower = *stereo_view_offset_index <= 6;
744764

@@ -806,7 +826,7 @@ bool FFakeStereoRenderingHook::standard_fake_stereo_hook(uintptr_t vtable) {
806826
return false;
807827
}
808828

809-
if (sdk::is_vfunc_pattern(*(uintptr_t*)get_render_target_manager_func_ptr, "33 C0")) {
829+
if (sdk::is_vfunc_pattern(*(uintptr_t*)get_render_target_manager_func_ptr, "33 C0") || (!uses_33_c0 && sdk::is_vfunc_pattern(*(uintptr_t*)get_render_target_manager_func_ptr, "31 C0"))) {
810830
const auto distance_from_rendertexture_fn = render_target_manager_vtable_index - rendertexture_fn_vtable_index;
811831

812832
// means it's 4.17 I think. 12 means 4.11.
@@ -840,7 +860,7 @@ bool FFakeStereoRenderingHook::standard_fake_stereo_hook(uintptr_t vtable) {
840860
break;
841861
}
842862

843-
if (!sdk::is_vfunc_pattern(func, "33 C0")) {
863+
if (!sdk::is_vfunc_pattern(func, "33 C0") && !sdk::is_vfunc_pattern(func, "31 C0")) {
844864
SPDLOG_INFO("Reached end of double check at index {}, {} appears to be the correct index.", i, render_target_manager_vtable_index);
845865
break;
846866
}

0 commit comments

Comments
 (0)