From a1e3a70bf4b5c7f5eb49f88c1adec45b8ad31b13 Mon Sep 17 00:00:00 2001 From: Tim <15017472+doodlum@users.noreply.github.com> Date: Thu, 6 Feb 2025 22:03:17 +0000 Subject: [PATCH 1/2] fix: corrected VR hooks --- src/Features/Skylighting.cpp | 25 ++++++++++++- src/Features/Skylighting.h | 6 ++++ src/Hooks.cpp | 68 +++++++++++++++++------------------- 3 files changed, 63 insertions(+), 36 deletions(-) diff --git a/src/Features/Skylighting.cpp b/src/Features/Skylighting.cpp index a2c7e5679e..7b6942bf42 100644 --- a/src/Features/Skylighting.cpp +++ b/src/Features/Skylighting.cpp @@ -275,7 +275,12 @@ void Skylighting::PostPostLoad() logger::info("[SKYLIGHTING] Hooking BSLightingShaderProperty::GetPrecipitationOcclusionMapRenderPassesImp"); stl::write_vfunc<0x2D, BSLightingShaderProperty_GetPrecipitationOcclusionMapRenderPassesImpl>(RE::VTABLE_BSLightingShaderProperty[0]); stl::write_thunk_call(REL::RelocationID(35560, 36559).address() + REL::Relocate(0x3A1, 0x3A1, 0x2FA)); - stl::write_thunk_call(REL::RelocationID(25643, 26185).address() + REL::Relocate(0x5D9, 0x59D, 0x5DC)); + + if (REL::Module::IsVR()) + stl::write_thunk_call(REL::RelocationID(25643, 26185).address() + REL::Relocate(0x5D9, 0x59D, 0x5DC)); + else + stl::write_thunk_call(REL::RelocationID(25643, 26185).address() + REL::Relocate(0x5D9, 0x59D, 0x5DC)); + MenuOpenCloseEventHandler::Register(); } @@ -463,6 +468,24 @@ void Skylighting::SetViewFrustum::thunk(RE::NiCamera* a_camera, RE::NiFrustum* a func(a_camera, a_frustum); } +void Skylighting::SetViewFrustumVR::thunk(RE::NiCamera* a_camera, RE::NiFrustum* a_frustum, uint a_eyeIndex) +{ + auto skylighting = globals::features::skylighting; + + if (skylighting->inOcclusion) { + uint corner = skylighting->frameCount % 4; + + float frustumSize = a_frustum->fTop; + + a_frustum->fBottom = (corner == 0 || corner == 1) ? -frustumSize : 0.0f; + a_frustum->fLeft = (corner == 0 || corner == 2) ? -frustumSize : 0.0f; + a_frustum->fRight = (corner == 1 || corner == 3) ? frustumSize : 0.0f; + a_frustum->fTop = (corner == 2 || corner == 3) ? frustumSize : 0.0f; + } + + func(a_camera, a_frustum, a_eyeIndex); +} + void Skylighting::RenderOcclusion() { auto shaderCache = globals::shaderCache; diff --git a/src/Features/Skylighting.h b/src/Features/Skylighting.h index 354c9ff28c..a277d414b9 100644 --- a/src/Features/Skylighting.h +++ b/src/Features/Skylighting.h @@ -109,6 +109,12 @@ struct Skylighting : Feature static inline REL::Relocation func; }; + struct SetViewFrustumVR + { + static void thunk(RE::NiCamera* a_camera, RE::NiFrustum* a_frustum, uint a_eyeIndex); + static inline REL::Relocation func; + }; + // Event handler class MenuOpenCloseEventHandler : public RE::BSTEventSink { diff --git a/src/Hooks.cpp b/src/Hooks.cpp index 7e1f749ebb..fe4c2283c2 100644 --- a/src/Hooks.cpp +++ b/src/Hooks.cpp @@ -752,43 +752,41 @@ namespace Hooks logger::info("Hooking BSEffectShader"); stl::write_vfunc<0x6, EffectExtensions::BSEffectShader_SetupGeometry>(RE::VTABLE_BSEffectShader[0]); - if (!REL::Module::IsVR()) { - const auto renderPassCacheCtor = REL::VariantID(100720, 107500, 0x1340330); - const int32_t passCount = 4194240; - const int32_t passCountSE = 4194240 * 16; - - const int32_t passSize = 4194240 * sizeof(RE::BSRenderPass); - const int32_t lightsCount = passCount * 16; - const int32_t lightsSize = lightsCount * sizeof(void*); - const int32_t lastPassIndex = passCount - 1; - const int32_t lastPassOffset = - (passCount - 1) * sizeof(RE::BSRenderPass); - const int32_t lastPassNextOffset = - (passCount - 1) * sizeof(RE::BSRenderPass) + offsetof(RE::BSRenderPass, next); + const auto renderPassCacheCtor = REL::VariantID(100720, 107500, 0x1340330); + const int32_t passCount = 4194240; + const int32_t passCountSE = 4194240 * 16; + + const int32_t passSize = 4194240 * sizeof(RE::BSRenderPass); + const int32_t lightsCount = passCount * 16; + const int32_t lightsSize = lightsCount * sizeof(void*); + const int32_t lastPassIndex = passCount - 1; + const int32_t lastPassOffset = + (passCount - 1) * sizeof(RE::BSRenderPass); + const int32_t lastPassNextOffset = + (passCount - 1) * sizeof(RE::BSRenderPass) + offsetof(RE::BSRenderPass, next); + PatchMemory( + REL::Relocation(renderPassCacheCtor, 0x76).address(), + reinterpret_cast(&lightsSize), 4); + PatchMemory( + REL::Relocation(renderPassCacheCtor, 0xAD).address(), + reinterpret_cast(&passSize), 4); + PatchMemory( + REL::Relocation(renderPassCacheCtor, 0xCB).address(), + reinterpret_cast(&lastPassIndex), 4); + PatchMemory( + REL::Relocation(renderPassCacheCtor, 0xF0).address(), + reinterpret_cast(&lastPassNextOffset), 4); + PatchMemory( + REL::Relocation(renderPassCacheCtor, 0xFD).address(), + reinterpret_cast(&lastPassOffset), 4); + if (REL::Module::IsAE()) { PatchMemory( - REL::Relocation(renderPassCacheCtor, 0x76).address(), - reinterpret_cast(&lightsSize), 4); - PatchMemory( - REL::Relocation(renderPassCacheCtor, 0xAD).address(), - reinterpret_cast(&passSize), 4); - PatchMemory( - REL::Relocation(renderPassCacheCtor, 0xCB).address(), - reinterpret_cast(&lastPassIndex), 4); - PatchMemory( - REL::Relocation(renderPassCacheCtor, 0xF0).address(), - reinterpret_cast(&lastPassNextOffset), 4); + REL::Relocation(renderPassCacheCtor, 0x191).address(), + reinterpret_cast(&passCount), 4); + } else { PatchMemory( - REL::Relocation(renderPassCacheCtor, 0xFD).address(), - reinterpret_cast(&lastPassOffset), 4); - if (REL::Module::IsAE()) { - PatchMemory( - REL::Relocation(renderPassCacheCtor, 0x191).address(), - reinterpret_cast(&passCount), 4); - } else { - PatchMemory( - REL::Relocation(renderPassCacheCtor, 0x191 - 2).address(), - reinterpret_cast(&passCountSE), 4); - } + REL::Relocation(renderPassCacheCtor, 0x191 - 2).address(), + reinterpret_cast(&passCountSE), 4); } } From b8cd7c98d8c2619fbc52f423e371845de343ba6a Mon Sep 17 00:00:00 2001 From: doodlum Date: Thu, 6 Feb 2025 22:04:03 +0000 Subject: [PATCH 2/2] =?UTF-8?q?style:=20=F0=9F=8E=A8=20apply=20clang-forma?= =?UTF-8?q?t=20changes?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Features/Skylighting.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Features/Skylighting.cpp b/src/Features/Skylighting.cpp index 7b6942bf42..8b9545338b 100644 --- a/src/Features/Skylighting.cpp +++ b/src/Features/Skylighting.cpp @@ -275,7 +275,7 @@ void Skylighting::PostPostLoad() logger::info("[SKYLIGHTING] Hooking BSLightingShaderProperty::GetPrecipitationOcclusionMapRenderPassesImp"); stl::write_vfunc<0x2D, BSLightingShaderProperty_GetPrecipitationOcclusionMapRenderPassesImpl>(RE::VTABLE_BSLightingShaderProperty[0]); stl::write_thunk_call(REL::RelocationID(35560, 36559).address() + REL::Relocate(0x3A1, 0x3A1, 0x2FA)); - + if (REL::Module::IsVR()) stl::write_thunk_call(REL::RelocationID(25643, 26185).address() + REL::Relocate(0x5D9, 0x59D, 0x5DC)); else