diff --git a/docs/lua/tables/rom.inputs.md b/docs/lua/tables/rom.inputs.md new file mode 100644 index 0000000..3735a87 --- /dev/null +++ b/docs/lua/tables/rom.inputs.md @@ -0,0 +1,40 @@ +# Table: rom.inputs + +## Functions (3) + +### `on_key_pressed(keybind, callback)` + +- **Parameters:** + - `keybind` (string): The key binding string representing the key that, when pressed, will trigger the callback function. The format used is the one used by the vanilla game, please check the vanilla scripts using "OnKeyPressed". + - `callback` (function): The function to be called when the specified keybind is pressed. + +**Example Usage:** +```lua +rom.inputs.on_key_pressed(keybind, callback) +``` + +### `let_game_input_go_through_gui_layer(new_value)` + +Allows game input to be processed even when the GUI layer is active. This is useful for scenarios where you need the game to remain responsive to player actions or on key presses callbacks despite overlay interfaces. + +- **Parameters:** + - `new_value` (bool): Optional. Set the backing field to the passed new value. + +**Example Usage:** +```lua +rom.inputs.let_game_input_go_through_gui_layer(new_value) +``` + +### `enable_vanilla_debug_keybinds(new_value)` + +Enables the default debug key bindings used in the vanilla game. + +- **Parameters:** + - `new_value` (bool): Optional. Set the backing field to the passed new value. + +**Example Usage:** +```lua +rom.inputs.enable_vanilla_debug_keybinds(new_value) +``` + + diff --git a/src/gui/gui.cpp b/src/gui/gui.cpp index cda803b..3f10f31 100644 --- a/src/gui/gui.cpp +++ b/src/gui/gui.cpp @@ -11,6 +11,7 @@ #include #include #include +#include #include #include @@ -202,6 +203,8 @@ namespace big editing_gui_keybind = true; } + ImGui::Checkbox("Let Game Input Go Through Gui Layer", &lua::hades::inputs::let_game_input_go_through_gui_layer); + ImGui::EndMenu(); } @@ -256,6 +259,13 @@ namespace big ImGui::EndMenu(); } + if (ImGui::BeginMenu("Debug")) + { + ImGui::Checkbox("Enable Vanilla Debug Keybinds", &lua::hades::inputs::enable_vanilla_debug_keybinds); + + ImGui::EndMenu(); + } + ImGui::EndMainMenuBar(); } diff --git a/src/lua_extensions/bindings/hades/inputs.cpp b/src/lua_extensions/bindings/hades/inputs.cpp new file mode 100644 index 0000000..955ffca --- /dev/null +++ b/src/lua_extensions/bindings/hades/inputs.cpp @@ -0,0 +1,466 @@ +#include "inputs.hpp" + +#include "lua_extensions/bindings/hades/hades_ida.hpp" +#include "lua_extensions/bindings/tolk/tolk.hpp" +#include "string/string.hpp" + +#include +#include +#include + +namespace sgg +{ + enum KeyModifier : int32_t + { + Ctrl = 1 << 0, + Shift = 1 << 1, + Alt = 1 << 2, + }; + + enum KeyboardButtonId : int32_t + { + KeyNone = -1, + KeyEscape = 0x0, + KeyF1 = 0x1, + KeyF2 = 0x2, + KeyF3 = 0x3, + KeyF4 = 0x4, + KeyF5 = 0x5, + KeyF6 = 0x6, + KeyF7 = 0x7, + KeyF8 = 0x8, + KeyF9 = 0x9, + KeyF10 = 0xA, + KeyF11 = 0xB, + KeyF12 = 0xC, + KeyF13 = 0xD, + KeyF14 = 0xE, + KeyF15 = 0xF, + KeyF16 = 0x10, + KeyF17 = 0x11, + KeyF18 = 0x12, + KeyF19 = 0x13, + KeyPrint = 0x14, + KeyScrollLock = 0x15, + KeyBreak = 0x16, + KeySpace = 0x20, + KeyApostrophe = 0x27, + KeyComma = 0x2C, + KeyMinus = 0x2D, + KeyPeriod = 0x2E, + KeySlash = 0x2F, + Key0 = 0x30, + Key1 = 0x31, + Key2 = 0x32, + Key3 = 0x33, + Key4 = 0x34, + Key5 = 0x35, + Key6 = 0x36, + Key7 = 0x37, + Key8 = 0x38, + Key9 = 0x39, + KeySemicolon = 0x3B, + KeyLess = 0x3C, + KeyEqual = 0x3D, + KeyA = 0x41, + KeyB = 0x42, + KeyC = 0x43, + KeyD = 0x44, + KeyE = 0x45, + KeyF = 0x46, + KeyG = 0x47, + KeyH = 0x48, + KeyI = 0x49, + KeyJ = 0x4A, + KeyK = 0x4B, + KeyL = 0x4C, + KeyM = 0x4D, + KeyN = 0x4E, + KeyO = 0x4F, + KeyP = 0x50, + KeyQ = 0x51, + KeyR = 0x52, + KeyS = 0x53, + KeyT = 0x54, + KeyU = 0x55, + KeyV = 0x56, + KeyW = 0x57, + KeyX = 0x58, + KeyY = 0x59, + KeyZ = 0x5A, + KeyBracketLeft = 0x5B, + KeyBackslash = 0x5C, + KeyBracketRight = 0x5D, + KeyGrave = 0x60, + KeyLeft = 0x61, + KeyRight = 0x62, + KeyUp = 0x63, + KeyDown = 0x64, + KeyInsert = 0x65, + KeyHome = 0x66, + KeyDelete = 0x67, + KeyEnd = 0x68, + KeyPageUp = 0x69, + KeyPageDown = 0x6A, + KeyNumLock = 0x6B, + KeyKpEqual = 0x6C, + KeyKpDivide = 0x6D, + KeyKpMultiply = 0x6E, + KeyKpSubtract = 0x6F, + KeyKpAdd = 0x70, + KeyKpEnter = 0x71, + KeyKpInsert = 0x72, + KeyKpEnd = 0x73, + KeyKpDown = 0x74, + KeyKpPageDown = 0x75, + KeyKpLeft = 0x76, + KeyKpBegin = 0x77, + KeyKpRight = 0x78, + KeyKpHome = 0x79, + KeyKpUp = 0x7A, + KeyKpPageUp = 0x7B, + KeyKpDelete = 0x7C, + KeyBackSpace = 0x7D, + KeyTab = 0x7E, + KeyReturn = 0x7F, + KeyCapsLock = 0x80, + KeyShiftL = 0x81, + KeyCtrlL = 0x82, + KeySuperL = 0x83, + KeyAltL = 0x84, + KeyAltR = 0x85, + KeySuperR = 0x86, + KeyMenu = 0x87, + KeyCtrlR = 0x88, + KeyShiftR = 0x89, + KeyBack = 0x8A, + KeySoftLeft = 0x8B, + KeySoftRight = 0x8C, + KeyCall = 0x8D, + KeyEndcall = 0x8E, + KeyStar = 0x8F, + KeyPound = 0x90, + KeyDpadCenter = 0x91, + KeyVolumeUp = 0x92, + KeyVolumeDown = 0x93, + KeyPower = 0x94, + KeyCamera = 0x95, + KeyClear = 0x96, + KeySymbol = 0x97, + KeyExplorer = 0x98, + KeyEnvelope = 0x99, + KeyEquals = 0x9A, + KeyAt = 0x9B, + KeyHeadsethook = 0x9C, + KeyFocus = 0x9D, + KeyPlus = 0x9E, + KeyNotification = 0x9F, + KeySearch = 0xA0, + KeyMediaPlayPause = 0xA1, + KeyMediaStop = 0xA2, + KeyMediaNext = 0xA3, + KeyMediaPrevious = 0xA4, + KeyMediaRewind = 0xA5, + KeyMediaFastForward = 0xA6, + KeyMute = 0xA7, + KeyPictsymbols = 0xA8, + KeySwitchCharset = 0xA9, + KeyForward = 0xAA, + KeyExtra1 = 0xAB, + KeyExtra2 = 0xAC, + KeyExtra3 = 0xAD, + KeyExtra4 = 0xAE, + KeyExtra5 = 0xAF, + KeyExtra6 = 0xB0, + KeyFn = 0xB1, + KeyCircumflex = 0xB2, + KeySsharp = 0xB3, + KeyAcute = 0xB4, + KeyAltGr = 0xB5, + KeyNumbersign = 0xB6, + KeyUdiaeresis = 0xB7, + KeyAdiaeresis = 0xB8, + KeyOdiaeresis = 0xB9, + KeySection = 0xBA, + KeyAring = 0xBB, + KeyDiaeresis = 0xBC, + KeyTwosuperior = 0xBD, + KeyRightParenthesis = 0xBE, + KeyDollar = 0xBF, + KeyUgrave = 0xC0, + KeyAsterisk = 0xC1, + KeyColon = 0xC2, + KeyExclam = 0xC3, + KeyBraceLeft = 0xC4, + KeyBraceRight = 0xC5, + KeySysRq = 0xC6, + KeyNumLck = 0xC7, + KeyCount_ = 0xC8, + }; + + // clang-format off +std::unordered_map key_map = { + { "Escape", sgg::KeyboardButtonId::KeyEscape }, + { "F1", sgg::KeyboardButtonId::KeyF1 }, + { "F2", sgg::KeyboardButtonId::KeyF2 }, + { "F3", sgg::KeyboardButtonId::KeyF3 }, + { "F4", sgg::KeyboardButtonId::KeyF4 }, + { "F5", sgg::KeyboardButtonId::KeyF5 }, + { "F6", sgg::KeyboardButtonId::KeyF6 }, + { "F7", sgg::KeyboardButtonId::KeyF7 }, + { "F8", sgg::KeyboardButtonId::KeyF8 }, + { "F9", sgg::KeyboardButtonId::KeyF9 }, + { "F10", sgg::KeyboardButtonId::KeyF10 }, + { "F11", sgg::KeyboardButtonId::KeyF11 }, + { "F12", sgg::KeyboardButtonId::KeyF12 }, + { "Space", sgg::KeyboardButtonId::KeySpace }, + { "OemQuotes", sgg::KeyboardButtonId::KeyApostrophe }, + { "OemComma", sgg::KeyboardButtonId::KeyComma }, + { "OemMinus", sgg::KeyboardButtonId::KeyKpSubtract }, + { "OemPeriod", sgg::KeyboardButtonId::KeyKpDelete }, + { "D0", sgg::KeyboardButtonId::Key0 }, + { "D1", sgg::KeyboardButtonId::Key1 }, + { "D2", sgg::KeyboardButtonId::Key2 }, + { "D3", sgg::KeyboardButtonId::Key3 }, + { "D4", sgg::KeyboardButtonId::Key4 }, + { "D5", sgg::KeyboardButtonId::Key5 }, + { "D6", sgg::KeyboardButtonId::Key6 }, + { "D7", sgg::KeyboardButtonId::Key7 }, + { "D8", sgg::KeyboardButtonId::Key8 }, + { "D9", sgg::KeyboardButtonId::Key9 }, + { "A", sgg::KeyboardButtonId::KeyA }, + { "B", sgg::KeyboardButtonId::KeyB }, + { "C", sgg::KeyboardButtonId::KeyC }, + { "D", sgg::KeyboardButtonId::KeyD }, + { "E", sgg::KeyboardButtonId::KeyE }, + { "F", sgg::KeyboardButtonId::KeyF }, + { "G", sgg::KeyboardButtonId::KeyG }, + { "H", sgg::KeyboardButtonId::KeyH }, + { "I", sgg::KeyboardButtonId::KeyI }, + { "J", sgg::KeyboardButtonId::KeyJ }, + { "K", sgg::KeyboardButtonId::KeyK }, + { "L", sgg::KeyboardButtonId::KeyL }, + { "M", sgg::KeyboardButtonId::KeyM }, + { "N", sgg::KeyboardButtonId::KeyN }, + { "O", sgg::KeyboardButtonId::KeyO }, + { "P", sgg::KeyboardButtonId::KeyP }, + { "Q", sgg::KeyboardButtonId::KeyQ }, + { "R", sgg::KeyboardButtonId::KeyR }, + { "S", sgg::KeyboardButtonId::KeyS }, + { "T", sgg::KeyboardButtonId::KeyT }, + { "U", sgg::KeyboardButtonId::KeyU }, + { "V", sgg::KeyboardButtonId::KeyV }, + { "W", sgg::KeyboardButtonId::KeyW }, + { "X", sgg::KeyboardButtonId::KeyX }, + { "Y", sgg::KeyboardButtonId::KeyY }, + { "Z", sgg::KeyboardButtonId::KeyZ }, + { "OemPipe", sgg::KeyboardButtonId::KeyBackslash }, + { "Left", sgg::KeyboardButtonId::KeyLeft }, + { "Right", sgg::KeyboardButtonId::KeyRight }, + { "Up", sgg::KeyboardButtonId::KeyUp }, + { "Down", sgg::KeyboardButtonId::KeyDown }, + { "Insert", sgg::KeyboardButtonId::KeyInsert }, + { "Home", sgg::KeyboardButtonId::KeyHome }, + { "Delete", sgg::KeyboardButtonId::KeyDelete }, + { "End", sgg::KeyboardButtonId::KeyEnd }, + { "PageUp", sgg::KeyboardButtonId::KeyPageUp }, + { "PageDown", sgg::KeyboardButtonId::KeyPageDown }, + { "Multiply", sgg::KeyboardButtonId::KeyKpMultiply }, + { "Add", sgg::KeyboardButtonId::KeyKpAdd }, + { "NumPad0", sgg::KeyboardButtonId::KeyKpInsert }, + { "NumPad1", sgg::KeyboardButtonId::KeyKpEnd }, + { "NumPad2", sgg::KeyboardButtonId::KeyKpDown }, + { "NumPad3", sgg::KeyboardButtonId::KeyKpPageDown }, + { "NumPad4", sgg::KeyboardButtonId::KeyKpLeft }, + { "NumPad5", sgg::KeyboardButtonId::KeyKpBegin }, + { "NumPad6", sgg::KeyboardButtonId::KeyKpRight }, + { "NumPad7", sgg::KeyboardButtonId::KeyKpHome }, + { "NumPad8", sgg::KeyboardButtonId::KeyKpUp }, + { "NumPad9", sgg::KeyboardButtonId::KeyKpPageUp }, + { "Back", sgg::KeyboardButtonId::KeyBackSpace }, + { "Tab", sgg::KeyboardButtonId::KeyTab }, + { "Enter", sgg::KeyboardButtonId::KeyReturn }, + { "CapsLock", sgg::KeyboardButtonId::KeyCapsLock }, + { "LeftShift", sgg::KeyboardButtonId::KeyShiftL }, + { "LeftControl", sgg::KeyboardButtonId::KeyCtrlL }, + { "LeftWindows", sgg::KeyboardButtonId::KeySuperL }, + { "LeftAlt", sgg::KeyboardButtonId::KeyAltL }, + { "RightAlt", sgg::KeyboardButtonId::KeyAltR }, + { "RightWindows", sgg::KeyboardButtonId::KeySuperR }, + { "RightControl", sgg::KeyboardButtonId::KeyCtrlR }, + { "RightShift", sgg::KeyboardButtonId::KeyShiftR }, + { "OemPlus", sgg::KeyboardButtonId::KeyPlus }, + { "OemOpenBrackets", sgg::KeyboardButtonId::KeyExtra1 }, + { "OemCloseBrackets", sgg::KeyboardButtonId::KeyExtra2 }, + { "OemQuestion", sgg::KeyboardButtonId::KeyExtra3 }, + { "OemTilde", sgg::KeyboardButtonId::KeyExtra5 }, + { "OemSemicolon", sgg::KeyboardButtonId::KeyExtra6 }, +}; + + // clang-format on +} // namespace sgg + +namespace lua::hades::inputs +{ + bool enable_vanilla_debug_keybinds = false; + bool let_game_input_go_through_gui_layer = true; + + std::unordered_map key_callbacks; + static gmAddress RegisterDebugKey{}; + + static void invoke_key_callback(uintptr_t mCallback) + { + // offset to get mName from DebugAction + eastl_basic_string_view_char *mName = (eastl_basic_string_view_char *)(mCallback - 0x18); + const auto it_callback = key_callbacks.find(mName->get_text()); + if (it_callback != key_callbacks.end()) + { + LOG(DEBUG) << it_callback->first; + it_callback->second(); + } + } + + static void invoke_vanilla_debug_key_callback(uintptr_t mCallback) + { + if (!enable_vanilla_debug_keybinds) + { + return; + } + + invoke_key_callback(mCallback); + } + + static void invoke_plugin_debug_key_callback(uintptr_t mCallback) + { + invoke_key_callback(mCallback); + } + + static void parse_and_register_keybind(const std::string &keybind, const sol::coroutine &callback, auto &RegisterDebugKey, void *invoke_callback) + { + eastl::function funcy; + funcy.mMgrFuncPtr = nullptr; + funcy.mInvokeFuncPtr = (decltype(funcy.mInvokeFuncPtr))invoke_callback; + eastl_basic_string_view_char callback_name{}; + callback_name.mRemainingSizeField = (char)129; + // TODO: this is leaking + callback_name.mpBegin = (char *)malloc(keybind.size()); + memcpy((char *)callback_name.mpBegin, keybind.data(), keybind.size()); + callback_name.mnCount = keybind.size(); + eastl_basic_string_view_char nothing{}; + nothing.mRemainingSizeField = (char)23; + eastl_basic_string_view_char nothing2{}; + nothing2.mRemainingSizeField = (char)23; + + int32_t key_modifier = 0; + int32_t key = 0; + if (keybind.size()) + { + LOG(INFO) << "keybind: " << keybind; + + if (keybind.contains("Control")) + { + key_modifier |= sgg::KeyModifier::Ctrl; + } + if (keybind.contains("Shift")) + { + key_modifier |= sgg::KeyModifier::Shift; + } + if (keybind.contains("Alt")) + { + key_modifier |= sgg::KeyModifier::Alt; + } + + std::string key_str = big::string::split(keybind, ' ')[1]; + auto it_key = sgg::key_map.find(key_str); + if (it_key != sgg::key_map.end()) + { + key = it_key->second; + key_callbacks[keybind] = callback; + } + } + + RegisterDebugKey(key_modifier, key, &funcy, &callback_name, nullptr, nullptr, 0, ¬hing, ¬hing2, 0); + } + + // Lua API: Function + // Table: inputs + // Name: on_key_pressed + // Param: keybind: string: The key binding string representing the key that, when pressed, will trigger the callback function. The format used is the one used by the vanilla game, please check the vanilla scripts using "OnKeyPressed". + // Param: callback: function: The function to be called when the specified keybind is pressed. + static void on_key_pressed(const std::string &keybind, sol::coroutine cb, sol::this_environment env) + { + auto mod = (big::lua_module_ext *)big::lua_module::this_from(env); + if (mod) + { + mod->m_data_ext.m_keybinds.emplace(keybind, cb); + + key_callbacks[keybind] = cb; + + if (RegisterDebugKey) + { + auto RegisterDebugKey_good_type = RegisterDebugKey.as_func *, eastl_basic_string_view_char *, void *, void *, bool, eastl_basic_string_view_char *, eastl_basic_string_view_char *, bool)>(); + parse_and_register_keybind(keybind, cb, RegisterDebugKey_good_type, invoke_plugin_debug_key_callback); + } + } + } + + void bind(sol::state_view &state, sol::table &lua_ext) + { + static auto RegisterDebugKey_ptr = gmAddress::scan("E8 ? ? ? ? 90 48 8B 45 DF", "RegisterDebugKey"); + if (RegisterDebugKey_ptr) + { + RegisterDebugKey = RegisterDebugKey_ptr.get_call(); + } + + state["OnKeyPressed"] = [](sol::table args) + { + auto keybind_opt = args[1].get>(); + auto callback_opt = args[2].get>(); + auto callback_name_opt = args["Name"].get>(); + auto is_safe_opt = args["Safe"].get>(); + + if (RegisterDebugKey) + { + if (keybind_opt.has_value() && keybind_opt->size() && callback_opt.has_value() && callback_opt->valid()) + { + auto RegisterDebugKey_good_type = RegisterDebugKey.as_func *, eastl_basic_string_view_char *, void *, void *, bool, eastl_basic_string_view_char *, eastl_basic_string_view_char *, bool)>(); + parse_and_register_keybind(*keybind_opt, *callback_opt, RegisterDebugKey_good_type, invoke_vanilla_debug_key_callback); + } + } + }; + + auto ns = lua_ext.create_named("inputs"); + + ns.set_function("on_key_pressed", on_key_pressed); + + // Lua API: Function + // Table: inputs + // Name: let_game_input_go_through_gui_layer + // Param: new_value: bool: Optional. Set the backing field to the passed new value. + // Allows game input to be processed even when the GUI layer is active. This is useful for scenarios where you need the game to remain responsive to player actions or on key presses callbacks despite overlay interfaces. + ns["let_game_input_go_through_gui_layer"] = sol::overload( + []() -> bool + { + return let_game_input_go_through_gui_layer; + }, + [](bool new_value) -> void + { + let_game_input_go_through_gui_layer = new_value; + }); + + // Lua API: Function + // Table: inputs + // Name: enable_vanilla_debug_keybinds + // Param: new_value: bool: Optional. Set the backing field to the passed new value. + // Enables the default debug key bindings used in the vanilla game. + ns["enable_vanilla_debug_keybinds"] = sol::overload( + []() -> bool + { + return enable_vanilla_debug_keybinds; + }, + [](bool new_value) -> void + { + enable_vanilla_debug_keybinds = new_value; + }); + } +} // namespace lua::hades::inputs diff --git a/src/lua_extensions/bindings/hades/inputs.hpp b/src/lua_extensions/bindings/hades/inputs.hpp new file mode 100644 index 0000000..a149b37 --- /dev/null +++ b/src/lua_extensions/bindings/hades/inputs.hpp @@ -0,0 +1,11 @@ +#pragma once + +namespace lua::hades::inputs +{ + extern bool enable_vanilla_debug_keybinds; + extern bool let_game_input_go_through_gui_layer; + + extern std::unordered_map key_callbacks; + + void bind(sol::state_view &state, sol::table &lua_ext); +} // namespace lua::hades::inputs diff --git a/src/lua_extensions/lua_manager_extension.cpp b/src/lua_extensions/lua_manager_extension.cpp index 42da0ac..25402d6 100644 --- a/src/lua_extensions/lua_manager_extension.cpp +++ b/src/lua_extensions/lua_manager_extension.cpp @@ -3,18 +3,13 @@ #include "bindings/gui_ext.hpp" #include "bindings/hades/audio.hpp" #include "bindings/hades/data.hpp" +#include "bindings/hades/inputs.hpp" #include "bindings/hades/lz4.hpp" #include "bindings/lpeg.hpp" #include "bindings/luasocket/luasocket.hpp" #include "bindings/paths_ext.hpp" #include "bindings/tolk/tolk.hpp" -#include "file_manager/file_manager.hpp" #include "lua_module_ext.hpp" -#include "string/string.hpp" - -#include -#include -#include namespace big::lua_manager_extension { @@ -22,6 +17,8 @@ namespace big::lua_manager_extension { std::scoped_lock l(g_manager_mutex); + lua::hades::inputs::key_callbacks.clear(); + g_is_lua_state_valid = false; g_lua_manager_instance.reset(); @@ -39,7 +36,7 @@ namespace big::lua_manager_extension void init_lua_manager(sol::state_view& state, sol::table& lua_ext) { init_lua_state(state, lua_ext); - init_lua_api(lua_ext); + init_lua_api(state, lua_ext); } void init_lua_state(sol::state_view& state, sol::table& lua_ext) @@ -63,7 +60,7 @@ namespace big::lua_manager_extension // clang-format on } - void init_lua_api(sol::table& lua_ext) + void init_lua_api(sol::state_view& state, sol::table& lua_ext) { auto on_import_table = lua_ext.create_named("on_import"); @@ -101,6 +98,7 @@ namespace big::lua_manager_extension // Let's keep that list sorted the same as the solution file explorer lua::hades::audio::bind(lua_ext); lua::hades::data::bind(lua_ext); + lua::hades::inputs::bind(state, lua_ext); lua::hades::lz4::bind(lua_ext); lua::luasocket::bind(lua_ext); lua::tolk::bind(lua_ext); diff --git a/src/lua_extensions/lua_manager_extension.hpp b/src/lua_extensions/lua_manager_extension.hpp index ee0f911..1e32efc 100644 --- a/src/lua_extensions/lua_manager_extension.hpp +++ b/src/lua_extensions/lua_manager_extension.hpp @@ -6,7 +6,7 @@ namespace big::lua_manager_extension { void init_lua_manager(sol::state_view& state, sol::table& lua_ext); void init_lua_state(sol::state_view& state, sol::table& lua_ext); - void init_lua_api(sol::table& lua_ext); + void init_lua_api(sol::state_view& state, sol::table& lua_ext); inline std::recursive_mutex g_manager_mutex; inline bool g_is_lua_state_valid = false; diff --git a/src/lua_extensions/lua_module_ext.hpp b/src/lua_extensions/lua_module_ext.hpp index c13926c..eb62e97 100644 --- a/src/lua_extensions/lua_module_ext.hpp +++ b/src/lua_extensions/lua_module_ext.hpp @@ -19,6 +19,8 @@ namespace big }; std::vector m_on_sjson_game_data_read; + + std::unordered_map m_keybinds; }; class lua_module_ext : public lua_module diff --git a/src/main.cpp b/src/main.cpp index f533dbe..07b53ef 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -14,6 +14,7 @@ #include "version.hpp" #include +#include #include #include @@ -163,13 +164,16 @@ static void hook_ReadAllAnimationData() } } -static void hook_HandleInput(void *this_, float elapsedSeconds) +static void hook_PlayerHandleInput(void *this_, float elapsedSeconds, void *input) { - if (!big::g_gui || !big::g_gui->is_open()) + if (big::g_gui && big::g_gui->is_open() && !lua::hades::inputs::let_game_input_go_through_gui_layer) { - big::g_hooking->get_original()(this_, elapsedSeconds); + return; } + big::g_hooking->get_original()(this_, elapsedSeconds, input); +} + struct sgg_config_values_fixed { bool *addr = nullptr; @@ -185,8 +189,8 @@ static void set_sgg_config_values_thread_loop() { if (sgg_config_values_thread_can_loop) { - for (auto &cfg_value : sgg_config_values) - { + for (auto &cfg_value : sgg_config_values) + { *cfg_value.addr = cfg_value.new_value; } } @@ -379,7 +383,8 @@ BOOL APIENTRY DllMain(HMODULE hmod, DWORD reason, PVOID) } { - static auto hook_ = hooking::detour_hook_helper::add("HandleInput Hook", gmAddress::scan("40 53 41 56 41 57 48 83 EC 30", "HandleInput")); + //static auto hook_ = hooking::detour_hook_helper::add("Global HandleInput Hook", gmAddress::scan("40 53 41 56 41 57 48 83 EC 30", "HandleInput")); + static auto hook_ = hooking::detour_hook_helper::add("Player HandleInput Hook", gmAddress::scan("E8 ? ? ? ? 8B 05 ? ? ? ? 90", "Player HandleInput")); } {