Skip to content

Commit

Permalink
fix: fix VR offsets
Browse files Browse the repository at this point in the history
  • Loading branch information
FlayaN committed Jul 5, 2024
1 parent 81a4224 commit 6d24654
Show file tree
Hide file tree
Showing 7 changed files with 31 additions and 22 deletions.
2 changes: 1 addition & 1 deletion src/Deferred.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion src/Features/Skylighting.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<Main_Precipitation_RenderOcclusion>(REL::RelocationID(35560, 36559).address() + REL::Relocate(0x3A1, 0x3A1));
stl::write_thunk_call<Main_Precipitation_RenderOcclusion>(REL::RelocationID(35560, 36559).address() + REL::Relocate(0x3A1, 0x3A1, 0x2FA));
stl::write_vfunc<0x4, BSWaterShader_SetupMaterial>(RE::VTABLE_BSWaterShader[0]);
}
};
Expand Down
25 changes: 13 additions & 12 deletions src/Features/TerrainBlending.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#include "TerrainBlending.h"

#include "State.h"
#include <Util.h>
#include "Util.h"

void TerrainBlending::DrawSettings()
{
Expand Down Expand Up @@ -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) {
Expand All @@ -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;
}
Expand Down Expand Up @@ -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);
}
Expand Down Expand Up @@ -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()
Expand Down
2 changes: 1 addition & 1 deletion src/Features/TerrainBlending.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<Main_RenderDepth>(REL::Relocation<std::uintptr_t>(REL::RelocationID(35560, 36559), 0x395).address());
stl::write_thunk_call<Main_RenderDepth>(REL::RelocationID(35560, 36559).address() + REL::Relocate(0x395, 0x395, 0x2EE));

// To manipulate the depth buffer write, depth testing, alpha blending
stl::write_thunk_call<BSBatchRenderer__RenderPassImmediately>(REL::RelocationID(100852, 107642).address() + REL::Relocate(0x29E, 0x28F));
Expand Down
16 changes: 10 additions & 6 deletions src/Hooks.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include "Menu.h"
#include "ShaderCache.h"
#include "State.h"
#include "Util.h"

#include "ShaderTools/BSShaderHooks.h"

Expand Down Expand Up @@ -395,7 +396,8 @@ namespace Hooks
if (vertexShader) {
state->context->VSSetShader(reinterpret_cast<ID3D11VertexShader*>(vertexShader->shader), NULL, NULL);
auto shadowState = RE::BSGraphics::RendererShadowState::GetSingleton();
shadowState->GetRuntimeData().currentVertexShader = a_vertexShader;
GET_INSTANCE_MEMBER(currentVertexShader, shadowState)
currentVertexShader = a_vertexShader;
return;
}
}
Expand All @@ -421,12 +423,14 @@ namespace Hooks
if (pixelShader) {
state->context->PSSetShader(reinterpret_cast<ID3D11PixelShader*>(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;
}
}
Expand Down Expand Up @@ -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<BSShader__BeginTechnique_SetVertexShader>(REL::RelocationID(101341, 101341).address() + REL::Relocate(0xC3, 0x3F3, 0x548));
stl::write_thunk_call<BSShader__BeginTechnique_SetPixelShader>(REL::RelocationID(101341, 101341).address() + REL::Relocate(0xD7, 0x3F3, 0x548));
stl::write_thunk_call<BSShader__BeginTechnique_SetVertexShader>(REL::RelocationID(101341, 101341).address() + REL::Relocate(0xC3, 0x3F3));
stl::write_thunk_call<BSShader__BeginTechnique_SetPixelShader>(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);
Expand All @@ -489,6 +493,6 @@ namespace Hooks
stl::write_thunk_call<CreateRenderTarget_Snow>(REL::RelocationID(100458, 107175).address() + REL::Relocate(0x406, 0x409));
stl::write_thunk_call<CreateRenderTarget_ShadowMask>(REL::RelocationID(100458, 107175).address() + REL::Relocate(0x555, 0x554, 0x6b9));

stl::write_thunk_call<CreateDepthStencil_PrecipitationMask>(REL::RelocationID(100458, 107175).address() + REL::Relocate(0x1245, 0x554, 0x6b9));
stl::write_thunk_call<CreateDepthStencil_PrecipitationMask>(REL::RelocationID(100458, 107175).address() + REL::Relocate(0x1245, 0x554, 0x1917));
}
}
4 changes: 4 additions & 0 deletions src/XSEPlugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down

0 comments on commit 6d24654

Please sign in to comment.