diff --git a/src/Cache.cpp b/src/Cache.cpp index eca7ac6..74c2fea 100644 --- a/src/Cache.cpp +++ b/src/Cache.cpp @@ -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) diff --git a/src/Fixes/FirstPersonAlpha.cpp b/src/Fixes/FirstPersonAlpha.cpp index fa3b07c..eb69ca6 100644 --- a/src/Fixes/FirstPersonAlpha.cpp +++ b/src/Fixes/FirstPersonAlpha.cpp @@ -5,33 +5,24 @@ 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::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 _SetFPAlpha; + static inline REL::Relocation func; }; void Install() { - FirstPersonAlpha::Install(); + REL::Relocation target{ REL_ID(37777, 38722), 0x55 }; + stl::write_thunk_call(target.address()); + logger::info("\t\tInstalled first person alpha fix"sv); } } diff --git a/src/PCH.h b/src/PCH.h index 0ca92ee..cf3f98a 100644 --- a/src/PCH.h +++ b/src/PCH.h @@ -33,13 +33,13 @@ namespace stl asm_replace(a_from, T::size, reinterpret_cast(T::func)); } - template + template 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(a_src, T::thunk); } template