From 85c1cc1b0ca2dd77f47855d2cc69c414a5ef63f7 Mon Sep 17 00:00:00 2001 From: Eddoursul Date: Wed, 20 Dec 2023 16:27:06 +0100 Subject: [PATCH] Implemented health bar fix with DLL, removed custom hudmenu.swf and .gfx --- SKSE/Plugins/EnderalSE.dll | 4 +- interface/exported/hudmenu.gfx | 3 -- interface/hudmenu.swf | 3 -- source/Enderal DLL/src/Main.cpp | 2 + source/Enderal DLL/src/Patches/HUDMenuPatch.h | 45 +++++++++++++++++++ .../Enderal DLL/src/Patches/HeroMenuPatch.cpp | 8 +++- 6 files changed, 55 insertions(+), 10 deletions(-) delete mode 100644 interface/exported/hudmenu.gfx delete mode 100644 interface/hudmenu.swf create mode 100644 source/Enderal DLL/src/Patches/HUDMenuPatch.h diff --git a/SKSE/Plugins/EnderalSE.dll b/SKSE/Plugins/EnderalSE.dll index f3275206..976944bf 100644 --- a/SKSE/Plugins/EnderalSE.dll +++ b/SKSE/Plugins/EnderalSE.dll @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:c7bf01547071c10496b6bf64ed446f7e8ab6572b62b10aae26b34d93292b7417 -size 750080 +oid sha256:368b4dcbf1e1d3a8cd8cf062ba175a1fdcf0d9d0e072f0fcbf0d66810da776f5 +size 751616 diff --git a/interface/exported/hudmenu.gfx b/interface/exported/hudmenu.gfx deleted file mode 100644 index fcf3acd8..00000000 --- a/interface/exported/hudmenu.gfx +++ /dev/null @@ -1,3 +0,0 @@ -version https://git-lfs.github.com/spec/v1 -oid sha256:aad45ec8060665514c758733baacfd55d46044ed5117fcf449aa89ddb888b1bd -size 169886 diff --git a/interface/hudmenu.swf b/interface/hudmenu.swf deleted file mode 100644 index f90e826b..00000000 --- a/interface/hudmenu.swf +++ /dev/null @@ -1,3 +0,0 @@ -version https://git-lfs.github.com/spec/v1 -oid sha256:dce11b85e5ee0ac5d3c7e772808dccc421cf7ccac79fd794438a41895b14f764 -size 372484 diff --git a/source/Enderal DLL/src/Main.cpp b/source/Enderal DLL/src/Main.cpp index cce768c4..4997a5e4 100644 --- a/source/Enderal DLL/src/Main.cpp +++ b/source/Enderal DLL/src/Main.cpp @@ -9,6 +9,7 @@ #include "DialogueMenuPatch.h" #include "Patches/TweenMenuPatch.h" #include "Patches/HeroMenuPatch.h" +#include "Patches/HUDMenuPatch.h" using namespace SKSE; @@ -173,6 +174,7 @@ SKSEPluginLoad(const LoadInterface* skse) { DialogueMenuPatch::Install(); HeroMenuPatch::Install(); TweenMenuPatch::Install(); + HUDMenuPatch::Install(); if (g_settings.at("VideoInterruptPatch")) { logger::info("Making videos interruptible..."); diff --git a/source/Enderal DLL/src/Patches/HUDMenuPatch.h b/source/Enderal DLL/src/Patches/HUDMenuPatch.h new file mode 100644 index 00000000..adde79d1 --- /dev/null +++ b/source/Enderal DLL/src/Patches/HUDMenuPatch.h @@ -0,0 +1,45 @@ +#pragma once + +inline std::time_t lastUpdate; + +class HUDMenuPatch final : public RE::ActorValueMeter +{ +public: + static void Install() + { + REL::Relocation vtbl(RE::VTABLE_ActorValueMeter[0]); + _ProcessMessage = vtbl.write_vfunc(0x2, &ProcessMessageEx); + } + +private: + bool ProcessMessageEx(RE::UIMessage* a_message) + { + if (this->actorValue == RE::ActorValue::kHealth && a_message->type == RE::UI_MESSAGE_TYPE::kScaleformEvent) { + std::time_t currentTime = std::time(nullptr); + if (currentTime > lastUpdate) { + // Ping the health bar every second + lastUpdate = currentTime; + auto playerAV = RE::PlayerCharacter::GetSingleton()->AsActorValueOwner(); + auto currentHealth = playerAV->GetActorValue(RE::ActorValue::kHealth); + + if (currentHealth < playerAV->GetBaseActorValue(RE::ActorValue::kHealth) && currentHealth > 0) { + auto uiMovie = RE::UI::GetSingleton()->GetMovieView(RE::HUDMenu::MENU_NAME); + + if (uiMovie) { + RE::GFxValue va; + uiMovie->GetVariable(&va, "HUDMovieBaseInstance.HealthMeterAnim._currentframe"); + + RE::GFxValue args[1]; + args[0].SetNumber(va.GetNumber()); + + uiMovie->Invoke("HUDMovieBaseInstance.HealthMeterAnim.PlayForward", nullptr, args, 1); + } + } + } + } + + return _ProcessMessage(this, a_message); + } + + inline static REL::Relocation _ProcessMessage; +}; diff --git a/source/Enderal DLL/src/Patches/HeroMenuPatch.cpp b/source/Enderal DLL/src/Patches/HeroMenuPatch.cpp index 2120a9fa..c1f01fab 100644 --- a/source/Enderal DLL/src/Patches/HeroMenuPatch.cpp +++ b/source/Enderal DLL/src/Patches/HeroMenuPatch.cpp @@ -57,8 +57,12 @@ void HeroMenuPatch::FillMenuValues() public: void operator()(RE::BSScript::Variable a_result) { - auto uiMovie = RE::UI::GetSingleton()->GetMovieView("CustomMenu"); - uiMovie->SetVariable("_root.heromenu_mc.stats.playerclass.stat_value.text", a_result.GetString()); + if (a_result.IsString()) { + auto uiMovie = RE::UI::GetSingleton()->GetMovieView("CustomMenu"); + if (uiMovie) { + uiMovie->SetVariable("_root.heromenu_mc.stats.playerclass.stat_value.text", a_result.GetString()); + } + } } bool CanSave() { return false; } void SetObject(const RE::BSTSmartPointer&) {}