Skip to content

Commit

Permalink
Standardize hook
Browse files Browse the repository at this point in the history
  • Loading branch information
powerof3 committed Jun 8, 2024
1 parent 3ae9596 commit 9bff4d7
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 20 deletions.
2 changes: 1 addition & 1 deletion src/Cache.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ namespace Cache
void EditorID::CacheEditorID(const RE::TESForm* a_form, const char* a_editorID)
{
Locker locker(_lock);
_formIDToEditorIDMap.emplace(a_form->GetFormID(), a_editorID);
_formIDToEditorIDMap.try_emplace(a_form->GetFormID(), a_editorID);
}

const std::string& EditorID::GetEditorID(RE::FormID a_formID)
Expand Down
25 changes: 8 additions & 17 deletions src/Fixes/FirstPersonAlpha.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,33 +5,24 @@ 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)
static RE::NiAVObject* thunk(RE::PlayerCharacter* a_player, float a_alpha)
{
// fade == false -> alpha_value = 2 to 3
// fade == true -> alpha_value = 0 to 1
if (alpha_value >= 2) {
alpha_value -= 2;
if (a_alpha >= 2) {
a_alpha -= 2;
}
player->Get3D(true)->UpdateMaterialAlpha(alpha_value, false);
a_player->Get3D(true)->UpdateMaterialAlpha(a_alpha, false);
return nullptr; // Return null so that the original fade function for 1st person doesn't execute
}
static inline REL::Relocation<decltype(SetFPAlpha)> _SetFPAlpha;
static inline REL::Relocation<decltype(thunk)> func;
};

void Install()
{
FirstPersonAlpha::Install();
REL::Relocation<std::uintptr_t> target{ REL_ID(37777, 38722), 0x55 };
stl::write_thunk_call<FirstPersonAlpha, 6>(target.address());

logger::info("\t\tInstalled first person alpha fix"sv);
}
}
4 changes: 2 additions & 2 deletions src/PCH.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,13 @@ namespace stl
asm_replace(a_from, T::size, reinterpret_cast<std::uintptr_t>(T::func));
}

template <class T>
template <class T, size_t N = 5>
void write_thunk_call(std::uintptr_t a_src)
{
auto& trampoline = SKSE::GetTrampoline();
SKSE::AllocTrampoline(14);

T::func = trampoline.write_call<5>(a_src, T::thunk);
T::func = trampoline.write_call<N>(a_src, T::thunk);
}

template <class F, size_t offset, class T>
Expand Down

0 comments on commit 9bff4d7

Please sign in to comment.