-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
17 changed files
with
293 additions
and
75 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
{ | ||
"debug": true, | ||
"debug": false, | ||
"stat": { | ||
"open_key_combination": [22], | ||
"close_key_combination": [22], | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
#include "hook.h" | ||
#include "hook/menu_control_hook.h" | ||
#include "setting/input_setting.h" | ||
|
||
namespace hook { | ||
void hook::install() { | ||
if (setting::input_setting::is_inventory_menu_enabled()) { | ||
menu_control_hook::install(); | ||
} | ||
} | ||
} // hook |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
#pragma once | ||
|
||
namespace hook { | ||
class hook { | ||
public: | ||
static void install(); | ||
}; | ||
} // hook |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
#include "menu_control_hook.h" | ||
#include "input/menu_key_input_holder.h" | ||
#include "scaleform/menus/stats_inventory_menu.h" | ||
#include "setting/input_setting.h" | ||
#include "util/key_util.h" | ||
|
||
namespace hook { | ||
|
||
void menu_control_hook::install() { | ||
logger::info("Hooking ..."sv); | ||
|
||
REL::Relocation<std::uintptr_t> menu_controls_vtbl{ RE::VTABLE_MenuControls[0] }; | ||
process_event_ = menu_controls_vtbl.write_vfunc(0x1, &menu_control_hook::process_event); | ||
|
||
logger::info("Hooked."sv); | ||
} | ||
|
||
RE::BSEventNotifyControl menu_control_hook::process_event(RE::InputEvent** a_event, | ||
RE::BSTEventSource<RE::InputEvent*>* a_source) { | ||
auto* ui = RE::UI::GetSingleton(); | ||
|
||
if (a_event && *a_event && is_menu_open(ui)) { | ||
auto* inventory_manager = RE::Inventory3DManager::GetSingleton(); | ||
auto* key_input = input::menu_key_input_holder::get_singleton(); | ||
|
||
for (auto* event = *a_event; event; event = event->next) { | ||
if (inventory_manager && inventory_manager->GetRuntimeData().zoomProgress != 0.f) { | ||
scaleform::stats_inventory_menu::close(); | ||
} else if (inventory_manager && inventory_manager->GetRuntimeData().zoomProgress == 0.f && | ||
!scaleform::stats_inventory_menu::is_menu_open() && | ||
!ui->IsMenuOpen(RE::BookMenu::MENU_NAME)) { | ||
if (!key_input->get_menu_manual_close() && | ||
setting::input_setting::auto_open_inventory_menu_inventory() && | ||
ui->IsMenuOpen(RE::InventoryMenu::MENU_NAME) || | ||
setting::input_setting::auto_open_inventory_menu_magic() && | ||
ui->IsMenuOpen(RE::MagicMenu::MENU_NAME)) { | ||
scaleform::stats_inventory_menu::open(); | ||
} | ||
} | ||
|
||
if (event->eventType != RE::INPUT_EVENT_TYPE::kButton && | ||
event->eventType != RE::INPUT_EVENT_TYPE::kThumbstick) { | ||
continue; | ||
} | ||
|
||
if (event->HasIDCode()) { | ||
auto* button = static_cast<RE::ButtonEvent*>(event); | ||
auto key = button->idCode; | ||
util::key_util::get_key_id(button->device.get(), key); | ||
|
||
if (button->IsUp()) { | ||
key_input->remove_key_down(key); | ||
} | ||
|
||
if (!button->IsDown()) { | ||
continue; | ||
} | ||
|
||
if (key_input->get_open_inventory_key_combo().contains(key) || | ||
key_input->get_close_inventory_key_combo().contains(key)) { | ||
key_input->add_key_down(key); | ||
} | ||
|
||
if (key_input->is_down_list_equal(false) && scaleform::stats_inventory_menu::is_menu_open()) { | ||
scaleform::stats_inventory_menu::close(); | ||
key_input->set_menu_manual_close(true); | ||
} | ||
if (key_input->is_down_list_equal(true) && !scaleform::stats_inventory_menu::is_menu_open()) { | ||
scaleform::stats_inventory_menu::open(); | ||
key_input->set_menu_manual_close(false); | ||
} | ||
} | ||
} | ||
} | ||
|
||
return process_event_(this, a_event, a_source); | ||
} | ||
|
||
bool menu_control_hook::is_menu_open(RE::UI*& a_ui) { | ||
return a_ui->IsMenuOpen(RE::InventoryMenu::MENU_NAME) || a_ui->IsMenuOpen(RE::MagicMenu::MENU_NAME); | ||
} | ||
} // hook |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
#pragma once | ||
|
||
namespace hook { | ||
class menu_control_hook : public RE::MenuControls { | ||
public: | ||
static void install(); | ||
|
||
private: | ||
RE::BSEventNotifyControl process_event(RE::InputEvent** a_event, RE::BSTEventSource<RE::InputEvent*>* a_source); | ||
|
||
using process_event_type = | ||
decltype(static_cast<RE::BSEventNotifyControl (RE::MenuControls::*)(RE::InputEvent* const*, | ||
RE::BSTEventSource<RE::InputEvent*>*)>(&RE::MenuControls::ProcessEvent)); | ||
|
||
static inline REL::Relocation<process_event_type> process_event_; | ||
|
||
static bool is_menu_open(RE::UI*& a_ui); | ||
}; | ||
} // hook |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
#include "menu_key_input_holder.h" | ||
#include "setting/input_setting.h" | ||
#include "util/type_util.h" | ||
|
||
namespace input { | ||
|
||
menu_key_input_holder* menu_key_input_holder::get_singleton() { | ||
static menu_key_input_holder singleton; | ||
return std::addressof(singleton); | ||
} | ||
|
||
std::set<uint32_t> menu_key_input_holder::get_open_inventory_key_combo() const { return open_inventory_key_combo_; } | ||
|
||
std::set<uint32_t> menu_key_input_holder::get_close_inventory_key_combo() const { | ||
return close_inventory_key_combo_; | ||
} | ||
|
||
void menu_key_input_holder::set_all() { | ||
open_inventory_key_combo_ = setting::input_setting::get_open_inventory_menu_key_combination(); | ||
close_inventory_key_combo_ = setting::input_setting::get_close_inventory_menu_key_combination(); | ||
} | ||
|
||
void menu_key_input_holder::add_key_down(uint32_t a_key) { | ||
key_down_list_.insert(a_key); | ||
if (!key_down_list_.empty()) { | ||
logger::trace("size {}, down list {}"sv, | ||
key_down_list_.size(), | ||
util::type_util::get_delimited_string(key_down_list_)); | ||
} | ||
} | ||
|
||
void menu_key_input_holder::remove_key_down(uint32_t a_key) { | ||
key_down_list_.erase(a_key); | ||
if (!key_down_list_.empty()) { | ||
logger::trace("size {}, down list {}"sv, | ||
key_down_list_.size(), | ||
util::type_util::get_delimited_string(key_down_list_)); | ||
} | ||
} | ||
|
||
void menu_key_input_holder::set_menu_manual_close(bool a_down) { menu_manual_close = a_down; } | ||
|
||
bool menu_key_input_holder::get_menu_manual_close() const { return menu_manual_close; } | ||
|
||
bool menu_key_input_holder::is_down_list_equal(bool a_open) { | ||
log_combo_set(a_open); | ||
if (a_open) { | ||
return key_down_list_ == open_inventory_key_combo_; | ||
} else { | ||
return key_down_list_ == close_inventory_key_combo_; | ||
} | ||
} | ||
|
||
menu_key_input_holder::menu_key_input_holder() = default; | ||
|
||
void menu_key_input_holder::log_combo_set(bool a_open) { | ||
logger::trace("key combo needed {}, down list {}"sv, | ||
util::type_util::get_delimited_string(a_open ? open_inventory_key_combo_ : close_inventory_key_combo_), | ||
util::type_util::get_delimited_string(key_down_list_)); | ||
} | ||
|
||
} // input |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
#pragma once | ||
|
||
namespace input { | ||
class menu_key_input_holder { | ||
public: | ||
[[nodiscard]] static menu_key_input_holder* get_singleton(); | ||
|
||
[[nodiscard]] std::set<uint32_t> get_open_inventory_key_combo() const; | ||
[[nodiscard]] std::set<uint32_t> get_close_inventory_key_combo() const; | ||
|
||
void set_all(); | ||
|
||
void add_key_down(uint32_t a_key); | ||
void remove_key_down(uint32_t a_key); | ||
|
||
bool is_down_list_equal(bool a_open); | ||
|
||
void set_menu_manual_close(bool a_down); | ||
|
||
[[nodiscard]] bool get_menu_manual_close() const; | ||
|
||
menu_key_input_holder(const menu_key_input_holder&) = delete; | ||
menu_key_input_holder(menu_key_input_holder&&) = delete; | ||
menu_key_input_holder& operator=(const menu_key_input_holder&) = delete; | ||
menu_key_input_holder& operator=(menu_key_input_holder&&) = delete; | ||
|
||
private: | ||
menu_key_input_holder(); | ||
~menu_key_input_holder() = default; | ||
|
||
std::set<uint32_t> key_down_list_; | ||
|
||
std::set<uint32_t> open_inventory_key_combo_; | ||
std::set<uint32_t> close_inventory_key_combo_; | ||
|
||
bool menu_manual_close = false; | ||
|
||
void log_combo_set(bool a_open); | ||
}; | ||
} // input |
Oops, something went wrong.