Skip to content

Commit

Permalink
Merge pull request #14 from ForestJ316/Fix1stPerson
Browse files Browse the repository at this point in the history
Fix for SetAlpha not working correctly for first person
  • Loading branch information
powerof3 authored May 6, 2024
2 parents 884c0c3 + 85b6d15 commit 94004c7
Show file tree
Hide file tree
Showing 6 changed files with 48 additions and 0 deletions.
1 change: 1 addition & 0 deletions cmake/sourcelist.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 3 additions & 0 deletions src/Fixes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,9 @@ void Fixes::PostLoad::Install()
if (fixes.loadEditorIDs) {
CacheFormEditorIDs::Install();
}
if (fixes.firstPersonAlpha) {
FirstPersonAlpha::Install();
}
//UnderWaterCamera::Install(); tbd
}

Expand Down
5 changes: 5 additions & 0 deletions src/Fixes.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,11 @@ namespace Fixes
void Install();
}

namespace FirstPersonAlpha
{
void Install();
}

namespace FlagSpellsAsNoAbsorb
{
void Install();
Expand Down
37 changes: 37 additions & 0 deletions src/Fixes/FirstPersonAlpha.cpp
Original file line number Diff line number Diff line change
@@ -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<std::uintptr_t> target { REL_ID(37777, 38722), 0x55 };

auto& trampoline = SKSE::GetTrampoline();
SKSE::AllocTrampoline(14);

_SetFPAlpha = trampoline.write_call<6>(target.address(), SetFPAlpha);
}

private:
static RE::NiAVObject* SetFPAlpha(RE::PlayerCharacter* 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;
}
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<decltype(SetFPAlpha)> _SetFPAlpha;
};

void Install()
{
FirstPersonAlpha::Install();
logger::info("\t\tInstalled first person alpha fix"sv);
}
}
1 change: 1 addition & 0 deletions src/Settings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions src/Settings.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ class Settings : public ISingleton<Settings>
bool breathingSounds{ true };
bool validateScreenshotFolder{ true };
bool loadEditorIDs{ true };
bool firstPersonAlpha{ true };
#ifdef SKYRIMVR
bool fixVRCrosshairRefEvent{ true };
#endif
Expand Down

0 comments on commit 94004c7

Please sign in to comment.