From 6d246542b5eadea7037e6dabdf87e512513cd176 Mon Sep 17 00:00:00 2001 From: FlayaN Date: Thu, 4 Jul 2024 18:47:32 +0200 Subject: [PATCH] fix: fix VR offsets --- extern/CommonLibSSE-NG | 2 +- src/Deferred.cpp | 2 +- src/Features/Skylighting.h | 2 +- src/Features/TerrainBlending.cpp | 25 +++++++++++++------------ src/Features/TerrainBlending.h | 2 +- src/Hooks.cpp | 16 ++++++++++------ src/XSEPlugin.cpp | 4 ++++ 7 files changed, 31 insertions(+), 22 deletions(-) diff --git a/extern/CommonLibSSE-NG b/extern/CommonLibSSE-NG index e83b23bdd..735fa6dae 160000 --- a/extern/CommonLibSSE-NG +++ b/extern/CommonLibSSE-NG @@ -1 +1 @@ -Subproject commit e83b23bddb893d44b8f3cf3e6379b9087ad25cc9 +Subproject commit 735fa6dae8ec72966ee02673dd689c6516d49f71 diff --git a/src/Deferred.cpp b/src/Deferred.cpp index da2db23f0..bc481e4c4 100644 --- a/src/Deferred.cpp +++ b/src/Deferred.cpp @@ -524,7 +524,7 @@ void Deferred::EndDeferred() } for (uint i = 4; i < 8; i++) { - shadowState->GetRuntimeData().renderTargets[i] = RE::RENDER_TARGET::kNONE; + renderTargets[i] = RE::RENDER_TARGET::kNONE; } auto& context = State::GetSingleton()->context; diff --git a/src/Features/Skylighting.h b/src/Features/Skylighting.h index c89a03d8e..64340d601 100644 --- a/src/Features/Skylighting.h +++ b/src/Features/Skylighting.h @@ -452,7 +452,7 @@ struct Skylighting : Feature { 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)); + stl::write_thunk_call(REL::RelocationID(35560, 36559).address() + REL::Relocate(0x3A1, 0x3A1, 0x2FA)); stl::write_vfunc<0x4, BSWaterShader_SetupMaterial>(RE::VTABLE_BSWaterShader[0]); } }; diff --git a/src/Features/TerrainBlending.cpp b/src/Features/TerrainBlending.cpp index 710fbe1ab..ca68bc4d4 100644 --- a/src/Features/TerrainBlending.cpp +++ b/src/Features/TerrainBlending.cpp @@ -1,7 +1,7 @@ #include "TerrainBlending.h" #include "State.h" -#include +#include "Util.h" void TerrainBlending::DrawSettings() { @@ -160,9 +160,6 @@ struct BlendStates ID3D11BlendState* a[7][2][13][2]; }; -#define GET_INSTANCE_MEMBER(a_value, a_source) \ - auto& a_value = !REL::Module::IsVR() ? a_source->GetRuntimeData().a_value : a_source->GetVRRuntimeData().a_value; - void TerrainBlending::TerrainShaderHacks() { if (renderTerrainDepth) { @@ -176,7 +173,8 @@ void TerrainBlending::TerrainShaderHacks() auto dsv = terrainDepth.views[0]; context->OMSetRenderTargets(0, nullptr, dsv); auto shadowState = RE::BSGraphics::RendererShadowState::GetSingleton(); - context->VSSetShader((ID3D11VertexShader*)shadowState->GetRuntimeData().currentVertexShader->shader, NULL, NULL); + GET_INSTANCE_MEMBER(currentVertexShader, shadowState) + context->VSSetShader((ID3D11VertexShader*)currentVertexShader->shader, NULL, NULL); } renderAltTerrain = !renderAltTerrain; } @@ -239,11 +237,12 @@ void TerrainBlending::ResetTerrainDepth() auto& mainDepth = renderer->GetDepthStencilData().depthStencils[RE::RENDER_TARGETS_DEPTHSTENCIL::kMAIN]; - auto state = RE::BSGraphics::RendererShadowState::GetSingleton(); - state->GetRuntimeData().stateUpdateFlags.set(RE::BSGraphics::ShaderFlags::DIRTY_RENDERTARGET); - auto shadowState = RE::BSGraphics::RendererShadowState::GetSingleton(); - context->VSSetShader((ID3D11VertexShader*)shadowState->GetRuntimeData().currentVertexShader->shader, NULL, NULL); + GET_INSTANCE_MEMBER(stateUpdateFlags, shadowState) + stateUpdateFlags.set(RE::BSGraphics::ShaderFlags::DIRTY_RENDERTARGET); + + GET_INSTANCE_MEMBER(currentVertexShader, shadowState) + context->VSSetShader((ID3D11VertexShader*)currentVertexShader->shader, NULL, NULL); context->CopyResource(terrainDepthTexture->resource.get(), mainDepth.texture); } @@ -289,14 +288,16 @@ void TerrainBlending::BlendPrepassDepths() context->CSSetShader(shader, nullptr, 0); auto state = RE::BSGraphics::RendererShadowState::GetSingleton(); - state->GetRuntimeData().stateUpdateFlags.set(RE::BSGraphics::ShaderFlags::DIRTY_RENDERTARGET); + GET_INSTANCE_MEMBER(stateUpdateFlags, state) + stateUpdateFlags.set(RE::BSGraphics::ShaderFlags::DIRTY_RENDERTARGET); } void TerrainBlending::ResetTerrainWorld() { auto state = RE::BSGraphics::RendererShadowState::GetSingleton(); - state->GetRuntimeData().stateUpdateFlags.set(RE::BSGraphics::ShaderFlags::DIRTY_ALPHA_BLEND); - state->GetRuntimeData().stateUpdateFlags.set(RE::BSGraphics::ShaderFlags::DIRTY_DEPTH_MODE); + GET_INSTANCE_MEMBER(stateUpdateFlags, state) + stateUpdateFlags.set(RE::BSGraphics::ShaderFlags::DIRTY_ALPHA_BLEND); + stateUpdateFlags.set(RE::BSGraphics::ShaderFlags::DIRTY_DEPTH_MODE); } void TerrainBlending::ClearShaderCache() diff --git a/src/Features/TerrainBlending.h b/src/Features/TerrainBlending.h index d6f73237f..a6408b14b 100644 --- a/src/Features/TerrainBlending.h +++ b/src/Features/TerrainBlending.h @@ -181,7 +181,7 @@ struct TerrainBlending : Feature static void Install() { // To know when we are rendering z-prepass depth vs shadows depth - stl::write_thunk_call(REL::Relocation(REL::RelocationID(35560, 36559), 0x395).address()); + stl::write_thunk_call(REL::RelocationID(35560, 36559).address() + REL::Relocate(0x395, 0x395, 0x2EE)); // To manipulate the depth buffer write, depth testing, alpha blending stl::write_thunk_call(REL::RelocationID(100852, 107642).address() + REL::Relocate(0x29E, 0x28F)); diff --git a/src/Hooks.cpp b/src/Hooks.cpp index e4a3bee5c..b135538db 100644 --- a/src/Hooks.cpp +++ b/src/Hooks.cpp @@ -5,6 +5,7 @@ #include "Menu.h" #include "ShaderCache.h" #include "State.h" +#include "Util.h" #include "ShaderTools/BSShaderHooks.h" @@ -395,7 +396,8 @@ namespace Hooks if (vertexShader) { state->context->VSSetShader(reinterpret_cast(vertexShader->shader), NULL, NULL); auto shadowState = RE::BSGraphics::RendererShadowState::GetSingleton(); - shadowState->GetRuntimeData().currentVertexShader = a_vertexShader; + GET_INSTANCE_MEMBER(currentVertexShader, shadowState) + currentVertexShader = a_vertexShader; return; } } @@ -421,12 +423,14 @@ namespace Hooks if (pixelShader) { state->context->PSSetShader(reinterpret_cast(pixelShader->shader), NULL, NULL); auto shadowState = RE::BSGraphics::RendererShadowState::GetSingleton(); - shadowState->GetRuntimeData().currentPixelShader = a_pixelShader; + GET_INSTANCE_MEMBER(currentPixelShader, shadowState) + currentPixelShader = a_pixelShader; return; } } else { auto shadowState = RE::BSGraphics::RendererShadowState::GetSingleton(); - shadowState->GetRuntimeData().currentPixelShader = a_pixelShader; + GET_INSTANCE_MEMBER(currentPixelShader, shadowState) + currentPixelShader = a_pixelShader; return; } } @@ -462,8 +466,8 @@ namespace Hooks logger::info("Hooking BSShader::BeginTechnique"); *(uintptr_t*)&ptr_BSShader_BeginTechnique = Detours::X64::DetourFunction(REL::RelocationID(101341, 108328).address(), (uintptr_t)&hk_BSShader_BeginTechnique); - stl::write_thunk_call(REL::RelocationID(101341, 101341).address() + REL::Relocate(0xC3, 0x3F3, 0x548)); - stl::write_thunk_call(REL::RelocationID(101341, 101341).address() + REL::Relocate(0xD7, 0x3F3, 0x548)); + stl::write_thunk_call(REL::RelocationID(101341, 101341).address() + REL::Relocate(0xC3, 0x3F3)); + stl::write_thunk_call(REL::RelocationID(101341, 101341).address() + REL::Relocate(0xD7, 0x3F3)); logger::info("Hooking BSGraphics::SetDirtyStates"); *(uintptr_t*)&ptr_BSGraphics_SetDirtyStates = Detours::X64::DetourFunction(REL::RelocationID(75580, 77386).address(), (uintptr_t)&hk_BSGraphics_SetDirtyStates); @@ -489,6 +493,6 @@ namespace Hooks stl::write_thunk_call(REL::RelocationID(100458, 107175).address() + REL::Relocate(0x406, 0x409)); stl::write_thunk_call(REL::RelocationID(100458, 107175).address() + REL::Relocate(0x555, 0x554, 0x6b9)); - stl::write_thunk_call(REL::RelocationID(100458, 107175).address() + REL::Relocate(0x1245, 0x554, 0x6b9)); + stl::write_thunk_call(REL::RelocationID(100458, 107175).address() + REL::Relocate(0x1245, 0x554, 0x1917)); } } \ No newline at end of file diff --git a/src/XSEPlugin.cpp b/src/XSEPlugin.cpp index bc09fc393..35d890bc4 100644 --- a/src/XSEPlugin.cpp +++ b/src/XSEPlugin.cpp @@ -148,6 +148,10 @@ bool Load() return true; } + if (REL::Module::IsVR()) { + REL::IDDatabase::get().IsVRAddressLibraryAtLeastVersion("0.138.0", true); + } + auto messaging = SKSE::GetMessagingInterface(); messaging->RegisterListener("SKSE", MessageHandler);