enderalse/source/Enderal DLL/src/Patches/TweenMenuPatch.h

40 lines
1.1 KiB
C
Raw Normal View History

2023-12-15 20:39:41 +00:00
#pragma once
inline void OpenMenu(RE::IMenu* tweenMenu, std::int32_t index)
{
using func_t = decltype(&OpenMenu);
REL::Relocation<func_t> func{ REL::RelocationID(51845, 51845) };
return func(tweenMenu, index);
}
class TweenMenuPatch final : public RE::TweenMenu
{
public:
static void Install()
{
REL::Relocation<uintptr_t> vtbl(RE::VTABLE_TweenMenu[0]);
_AcceptFn = vtbl.write_vfunc(0x1, &AcceptEx);
}
private:
void AcceptEx(CallbackProcessor* a_cbReg)
{
_AcceptFn(this, a_cbReg);
fxDelegate->callbacks.Remove("OpenHighlightedMenu");
a_cbReg->Process("OpenHighlightedMenu", [](const RE::FxDelegateArgs& args) {
auto index = args[0].GetSInt();
if (index <= 1) {
RE::BSTSmartPointer<RE::BSScript::IStackCallbackFunctor> stackCallback;
RE::BSScript::Internal::VirtualMachine::GetSingleton()->DispatchStaticCall("_00E_HeroMenu", "Show", RE::MakeFunctionArguments(), stackCallback);
} else if (index <= 4) {
OpenMenu(RE::UI::GetSingleton()->GetMenu(MENU_NAME).get(), index);
}
});
}
using AcceptFn = decltype(&Accept);
inline static REL::Relocation<AcceptFn> _AcceptFn;
};