From 13f2804d4b5e259f25d1bbbf86a3f0dbfa1528e5 Mon Sep 17 00:00:00 2001 From: ForestJ316 <91183260+ForestJ316@users.noreply.github.com> Date: Sun, 24 Mar 2024 03:59:39 +0000 Subject: [PATCH 1/4] Fix for SetAlpha not working correctly for first person --- cmake/sourcelist.cmake | 1 + src/Fixes.cpp | 3 +++ src/Fixes.h | 5 +++++ src/Fixes/FirstPersonAlpha.cpp | 37 ++++++++++++++++++++++++++++++++++ src/Settings.cpp | 1 + src/Settings.h | 1 + 6 files changed, 48 insertions(+) create mode 100644 src/Fixes/FirstPersonAlpha.cpp diff --git a/cmake/sourcelist.cmake b/cmake/sourcelist.cmake index b9125f3..33511b5 100644 --- a/cmake/sourcelist.cmake +++ b/cmake/sourcelist.cmake @@ -14,6 +14,7 @@ set(sources ${sources} src/Fixes/CrosshairRefEventVR.cpp src/Fixes/DistantRefLoadCrash.cpp src/Fixes/EffectShaderZBuffer.cpp + src/Fixes/FirstPersonAlpha.cpp src/Fixes/FlagSpellsAsNoAbsorb.cpp src/Fixes/IsFurnitureAnimTypeForFurniture.cpp src/Fixes/MapMarkerPlacement.cpp diff --git a/src/Fixes.cpp b/src/Fixes.cpp index c1aa0c9..cbb7428 100644 --- a/src/Fixes.cpp +++ b/src/Fixes.cpp @@ -64,6 +64,9 @@ void Fixes::PostLoad::Install() if (fixes.loadEditorIDs) { CacheFormEditorIDs::Install(); } + if (fixes.firstPersonAlpha) { + FirstPersonAlpha::Install(); + } //UnderWaterCamera::Install(); tbd } diff --git a/src/Fixes.h b/src/Fixes.h index fb4d0c3..52f3d14 100644 --- a/src/Fixes.h +++ b/src/Fixes.h @@ -62,6 +62,11 @@ namespace Fixes void Install(); } + namespace FirstPersonAlpha + { + void Install(); + } + namespace FlagSpellsAsNoAbsorb { void Install(); diff --git a/src/Fixes/FirstPersonAlpha.cpp b/src/Fixes/FirstPersonAlpha.cpp new file mode 100644 index 0000000..52ed896 --- /dev/null +++ b/src/Fixes/FirstPersonAlpha.cpp @@ -0,0 +1,37 @@ +#include "Fixes.h" + +//Bandaid fix for SetAlpha not working properly for first person +namespace Fixes::FirstPersonAlpha +{ + struct FirstPersonAlpha + { + static void Install() + { + REL::Relocation target { REL_ID(37777, 38722), 0x55 }; + + auto& trampoline = SKSE::GetTrampoline(); + SKSE::AllocTrampoline(14); + + _SetFPAlpha = trampoline.write_call<6>(target.address(), SetFPAlpha); + } + + private: + static RE::BSFadeNode* SetFPAlpha(RE::Character* a, float alpha_value) + { + // fade == false -> alpha_value = 2 to 3 + // fade == true -> alpha_value = 0 to 1 + if (alpha_value >= 2) { + alpha_value -= 2; + } + a->Get3D(true)->UpdateMaterialAlpha(alpha_value, false); + return nullptr; // Return null so that the original fade function for 1st person doesn't execute + } + static inline REL::Relocation _SetFPAlpha; + }; + + void Install() + { + FirstPersonAlpha::Install(); + logger::info("\t\tInstalled first person alpha fix"sv); + } +} diff --git a/src/Settings.cpp b/src/Settings.cpp index 7db0bdd..3d35dff 100644 --- a/src/Settings.cpp +++ b/src/Settings.cpp @@ -69,6 +69,7 @@ void Settings::Fixes::Load(CSimpleIniA& a_ini) get_value(a_ini, breathingSounds, section, "Breathing Sounds", ";Fix creature breathing sounds persisting after cell change"); get_value(a_ini, validateScreenshotFolder, section, "Validate Screenshot Location", ";Validates game screenshot location.\n;Defaults to Skyrim root directory if sScreenshotBaseName ini setting is empty or folder path does not exist"); get_value(a_ini, loadEditorIDs, section, "Load EditorIDs", ";Loads editorIDs for skipped forms at runtime"); + get_value(a_ini, firstPersonAlpha, section, "First Person SetAlpha Fix", ";Fixes SetAlpha function making hands invisible for first person"); #ifdef SKYRIMVR get_value(a_ini, fixVRCrosshairRefEvent, section, "VR CrosshairRefEvent Fix", "; Trigger CrossHairRefEvent with hand selection (normally requires game controller to enable crosshair events)"); #endif diff --git a/src/Settings.h b/src/Settings.h index 1364300..9903a3c 100644 --- a/src/Settings.h +++ b/src/Settings.h @@ -27,6 +27,7 @@ class Settings : public ISingleton bool breathingSounds{ true }; bool validateScreenshotFolder{ true }; bool loadEditorIDs{ true }; + bool firstPersonAlpha{ true }; #ifdef SKYRIMVR bool fixVRCrosshairRefEvent{ true }; #endif From 5c5b0ff210bbae4d9c16f670cd7a2b0fca124e40 Mon Sep 17 00:00:00 2001 From: ForestJ316 <91183260+ForestJ316@users.noreply.github.com> Date: Sun, 24 Mar 2024 06:03:14 +0000 Subject: [PATCH 2/4] Update FirstPersonAlpha.cpp --- src/Fixes/FirstPersonAlpha.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Fixes/FirstPersonAlpha.cpp b/src/Fixes/FirstPersonAlpha.cpp index 52ed896..2ecfd81 100644 --- a/src/Fixes/FirstPersonAlpha.cpp +++ b/src/Fixes/FirstPersonAlpha.cpp @@ -16,14 +16,14 @@ namespace Fixes::FirstPersonAlpha } private: - static RE::BSFadeNode* SetFPAlpha(RE::Character* a, float alpha_value) + static RE::BSFadeNode* SetFPAlpha(RE::Character* player, float alpha_value) { // fade == false -> alpha_value = 2 to 3 // fade == true -> alpha_value = 0 to 1 if (alpha_value >= 2) { alpha_value -= 2; } - a->Get3D(true)->UpdateMaterialAlpha(alpha_value, false); + player->Get3D(true)->UpdateMaterialAlpha(alpha_value, false); return nullptr; // Return null so that the original fade function for 1st person doesn't execute } static inline REL::Relocation _SetFPAlpha; From 795eff601a186f760f59e4f93e687330d5d0a87d Mon Sep 17 00:00:00 2001 From: ForestJ316 <91183260+ForestJ316@users.noreply.github.com> Date: Sun, 24 Mar 2024 06:03:51 +0000 Subject: [PATCH 3/4] Update FirstPersonAlpha.cpp --- src/Fixes/FirstPersonAlpha.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Fixes/FirstPersonAlpha.cpp b/src/Fixes/FirstPersonAlpha.cpp index 2ecfd81..39e20db 100644 --- a/src/Fixes/FirstPersonAlpha.cpp +++ b/src/Fixes/FirstPersonAlpha.cpp @@ -16,7 +16,7 @@ namespace Fixes::FirstPersonAlpha } private: - static RE::BSFadeNode* SetFPAlpha(RE::Character* player, float alpha_value) + static RE::BSFadeNode* SetFPAlpha(RE::PlayerCharacter* player, float alpha_value) { // fade == false -> alpha_value = 2 to 3 // fade == true -> alpha_value = 0 to 1 From 85b6d15c1aed5cc6268f4ee3a512ee8c5b1a3bf8 Mon Sep 17 00:00:00 2001 From: ForestJ316 <91183260+ForestJ316@users.noreply.github.com> Date: Fri, 19 Apr 2024 19:04:30 +0100 Subject: [PATCH 4/4] Fix return type --- src/Fixes/FirstPersonAlpha.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Fixes/FirstPersonAlpha.cpp b/src/Fixes/FirstPersonAlpha.cpp index 39e20db..91f563b 100644 --- a/src/Fixes/FirstPersonAlpha.cpp +++ b/src/Fixes/FirstPersonAlpha.cpp @@ -16,7 +16,7 @@ namespace Fixes::FirstPersonAlpha } private: - static RE::BSFadeNode* SetFPAlpha(RE::PlayerCharacter* player, float alpha_value) + static RE::NiAVObject* SetFPAlpha(RE::PlayerCharacter* player, float alpha_value) { // fade == false -> alpha_value = 2 to 3 // fade == true -> alpha_value = 0 to 1