From 8c9c9ef6b74c5a4ee29c132e745ac56a1a79ebc3 Mon Sep 17 00:00:00 2001 From: Joaquin <67109235+Taiga74164@users.noreply.github.com> Date: Thu, 25 Apr 2024 16:33:32 -0600 Subject: [PATCH] fix: Hotkey not registered after load --- .github/workflows/main.yml | 2 +- cheat/SoloLevelling.vcxproj | 2 +- cheat/src/ConfigEntry.hpp | 9 + cheat/src/ConfigManager.hpp | 2 +- cheat/src/Hotkey.cpp | 225 +++++++++--------- .../{HotkeyManager.h => HotkeyManager.hpp} | 0 cheat/src/Render/Gui/utils/gui-util.hpp | 2 +- cheat/src/cheat/cheat.cpp | 2 +- 8 files changed, 129 insertions(+), 115 deletions(-) rename cheat/src/{HotkeyManager.h => HotkeyManager.hpp} (100%) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 3510b62..2916872 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -33,5 +33,5 @@ jobs: uses: actions/upload-artifact@v3.1.0 with: name: build-artifact - path: .cheat/bin/Release-x64/SLA_Cheeto.dll + path: ./cheat/bin/Release-x64/SLA_Cheeto.dll if-no-files-found: error \ No newline at end of file diff --git a/cheat/SoloLevelling.vcxproj b/cheat/SoloLevelling.vcxproj index 6580f39..d648760 100644 --- a/cheat/SoloLevelling.vcxproj +++ b/cheat/SoloLevelling.vcxproj @@ -121,7 +121,7 @@ - + diff --git a/cheat/src/ConfigEntry.hpp b/cheat/src/ConfigEntry.hpp index 2664c52..0263b1c 100644 --- a/cheat/src/ConfigEntry.hpp +++ b/cheat/src/ConfigEntry.hpp @@ -18,6 +18,9 @@ class ConfigEntry { value_ = ConfigManager::GetInstance().Get(name, defaultValue, true); hotkey_ = ConfigManager::GetInstance().GetHotkey(name + "Hotkey", defaultHotkey); + + if constexpr (std::is_same_v) + RegisterHotkey(); } T& value() @@ -56,6 +59,12 @@ class ConfigEntry ConfigManager::GetInstance().SetHotkey(name_ + "Hotkey", hotkey_); } + void RegisterHotkey() + { + if constexpr (std::is_same_v) + HotkeyManager::GetInstance().RegisterKey(hotkey_, &value_); + } + ConfigEntry& operator=(const T& newValue) { SetValue(newValue); diff --git a/cheat/src/ConfigManager.hpp b/cheat/src/ConfigManager.hpp index 7ffeaaa..649906c 100644 --- a/cheat/src/ConfigManager.hpp +++ b/cheat/src/ConfigManager.hpp @@ -6,7 +6,7 @@ #include "Singleton.h" #include "Hotkey.h" -#include "HotkeyManager.h" +#include "HotkeyManager.hpp" #include "Utils.h" using json = nlohmann::json; diff --git a/cheat/src/Hotkey.cpp b/cheat/src/Hotkey.cpp index 1515cf0..66d7111 100644 --- a/cheat/src/Hotkey.cpp +++ b/cheat/src/Hotkey.cpp @@ -524,117 +524,122 @@ std::string Trim(const std::string& str) // Temporary. IDK why magic_enum::enum_cast is returning 0 ImGuiKey StringToImGuiKey_1(const std::string& keyName) { - switch (hash(keyName.c_str())) + static std::unordered_map keyMap = { - case hash("ImGuiKey_Tab"): return ImGuiKey_Tab; - case hash("ImGuiKey_LeftArrow"): return ImGuiKey_LeftArrow; - case hash("ImGuiKey_RightArrow"): return ImGuiKey_RightArrow; - case hash("ImGuiKey_UpArrow"): return ImGuiKey_UpArrow; - case hash("ImGuiKey_DownArrow"): return ImGuiKey_DownArrow; - case hash("ImGuiKey_PageUp"): return ImGuiKey_PageUp; - case hash("ImGuiKey_PageDown"): return ImGuiKey_PageDown; - case hash("ImGuiKey_Home"): return ImGuiKey_Home; - case hash("ImGuiKey_End"): return ImGuiKey_End; - case hash("ImGuiKey_Insert"): return ImGuiKey_Insert; - case hash("ImGuiKey_Delete"): return ImGuiKey_Delete; - case hash("ImGuiKey_Backspace"): return ImGuiKey_Backspace; - case hash("ImGuiKey_Space"): return ImGuiKey_Space; - case hash("ImGuiKey_Enter"): return ImGuiKey_Enter; - case hash("ImGuiKey_Escape"): return ImGuiKey_Escape; - case hash("ImGuiKey_Apostrophe"): return ImGuiKey_Apostrophe; - case hash("ImGuiKey_Comma"): return ImGuiKey_Comma; - case hash("ImGuiKey_Minus"): return ImGuiKey_Minus; - case hash("ImGuiKey_Period"): return ImGuiKey_Period; - case hash("ImGuiKey_Slash"): return ImGuiKey_Slash; - case hash("ImGuiKey_Semicolon"): return ImGuiKey_Semicolon; - case hash("ImGuiKey_Equal"): return ImGuiKey_Equal; - case hash("ImGuiKey_LeftBracket"): return ImGuiKey_LeftBracket; - case hash("ImGuiKey_Backslash"): return ImGuiKey_Backslash; - case hash("ImGuiKey_RightBracket"): return ImGuiKey_RightBracket; - case hash("ImGuiKey_GraveAccent"): return ImGuiKey_GraveAccent; - case hash("ImGuiKey_CapsLock"): return ImGuiKey_CapsLock; - case hash("ImGuiKey_ScrollLock"): return ImGuiKey_ScrollLock; - case hash("ImGuiKey_NumLock"): return ImGuiKey_NumLock; - case hash("ImGuiKey_PrintScreen"): return ImGuiKey_PrintScreen; - case hash("ImGuiKey_Pause"): return ImGuiKey_Pause; - case hash("ImGuiKey_Keypad0"): return ImGuiKey_Keypad0; - case hash("ImGuiKey_Keypad1"): return ImGuiKey_Keypad1; - case hash("ImGuiKey_Keypad2"): return ImGuiKey_Keypad2; - case hash("ImGuiKey_Keypad3"): return ImGuiKey_Keypad3; - case hash("ImGuiKey_Keypad4"): return ImGuiKey_Keypad4; - case hash("ImGuiKey_Keypad5"): return ImGuiKey_Keypad5; - case hash("ImGuiKey_Keypad6"): return ImGuiKey_Keypad6; - case hash("ImGuiKey_Keypad7"): return ImGuiKey_Keypad7; - case hash("ImGuiKey_Keypad8"): return ImGuiKey_Keypad8; - case hash("ImGuiKey_Keypad9"): return ImGuiKey_Keypad9; - case hash("ImGuiKey_KeypadDecimal"): return ImGuiKey_KeypadDecimal; - case hash("ImGuiKey_KeypadDivide"): return ImGuiKey_KeypadDivide; - case hash("ImGuiKey_KeypadMultiply"): return ImGuiKey_KeypadMultiply; - case hash("ImGuiKey_KeypadSubtract"): return ImGuiKey_KeypadSubtract; - case hash("ImGuiKey_KeypadAdd"): return ImGuiKey_KeypadAdd; - case hash("ImGuiKey_KeypadEnter"): return ImGuiKey_KeypadEnter; - case hash("ImGuiKey_LeftShift"): return ImGuiKey_LeftShift; - case hash("ImGuiKey_LeftCtrl"): return ImGuiKey_LeftCtrl; - case hash("ImGuiKey_LeftAlt"): return ImGuiKey_LeftAlt; - case hash("ImGuiKey_LeftSuper"): return ImGuiKey_LeftSuper; - case hash("ImGuiKey_RightShift"): return ImGuiKey_RightShift; - case hash("ImGuiKey_RightCtrl"): return ImGuiKey_RightCtrl; - case hash("ImGuiKey_RightAlt"): return ImGuiKey_RightAlt; - case hash("ImGuiKey_RightSuper"): return ImGuiKey_RightSuper; - case hash("ImGuiKey_Menu"): return ImGuiKey_Menu; - case hash("ImGuiKey_0"): return ImGuiKey_0; - case hash("ImGuiKey_1"): return ImGuiKey_1; - case hash("ImGuiKey_2"): return ImGuiKey_2; - case hash("ImGuiKey_3"): return ImGuiKey_3; - case hash("ImGuiKey_4"): return ImGuiKey_4; - case hash("ImGuiKey_5"): return ImGuiKey_5; - case hash("ImGuiKey_6"): return ImGuiKey_6; - case hash("ImGuiKey_7"): return ImGuiKey_7; - case hash("ImGuiKey_8"): return ImGuiKey_8; - case hash("ImGuiKey_9"): return ImGuiKey_9; - case hash("ImGuiKey_A"): return ImGuiKey_A; - case hash("ImGuiKey_B"): return ImGuiKey_B; - case hash("ImGuiKey_C"): return ImGuiKey_C; - case hash("ImGuiKey_D"): return ImGuiKey_D; - case hash("ImGuiKey_E"): return ImGuiKey_E; - case hash("ImGuiKey_F"): return ImGuiKey_F; - case hash("ImGuiKey_G"): return ImGuiKey_G; - case hash("ImGuiKey_H"): return ImGuiKey_H; - case hash("ImGuiKey_I"): return ImGuiKey_I; - case hash("ImGuiKey_J"): return ImGuiKey_J; - case hash("ImGuiKey_K"): return ImGuiKey_K; - case hash("ImGuiKey_L"): return ImGuiKey_L; - case hash("ImGuiKey_M"): return ImGuiKey_M; - case hash("ImGuiKey_N"): return ImGuiKey_N; - case hash("ImGuiKey_O"): return ImGuiKey_O; - case hash("ImGuiKey_P"): return ImGuiKey_P; - case hash("ImGuiKey_Q"): return ImGuiKey_Q; - case hash("ImGuiKey_R"): return ImGuiKey_R; - case hash("ImGuiKey_S"): return ImGuiKey_S; - case hash("ImGuiKey_T"): return ImGuiKey_T; - case hash("ImGuiKey_U"): return ImGuiKey_U; - case hash("ImGuiKey_V"): return ImGuiKey_V; - case hash("ImGuiKey_W"): return ImGuiKey_W; - case hash("ImGuiKey_X"): return ImGuiKey_X; - case hash("ImGuiKey_Y"): return ImGuiKey_Y; - case hash("ImGuiKey_Z"): return ImGuiKey_Z; - case hash("ImGuiKey_F1"): return ImGuiKey_F1; - case hash("ImGuiKey_F2"): return ImGuiKey_F2; - case hash("ImGuiKey_F3"): return ImGuiKey_F3; - case hash("ImGuiKey_F4"): return ImGuiKey_F4; - case hash("ImGuiKey_F5"): return ImGuiKey_F5; - case hash("ImGuiKey_F6"): return ImGuiKey_F6; - case hash("ImGuiKey_F7"): return ImGuiKey_F7; - case hash("ImGuiKey_F8"): return ImGuiKey_F8; - case hash("ImGuiKey_F9"): return ImGuiKey_F9; - case hash("ImGuiKey_F10"): return ImGuiKey_F10; - case hash("ImGuiKey_F11"): return ImGuiKey_F11; - case hash("ImGuiKey_F12"): return ImGuiKey_F12; - case hash("ImGuiMouseButton_Left"): return ImGuiMouseButton_Left; - case hash("ImGuiMouseButton_Right"): return ImGuiMouseButton_Right; - case hash("ImGuiMouseButton_Middle"): return ImGuiMouseButton_Middle; - default: return ImGuiKey_None; - } + { "ImGuiKey_Tab", ImGuiKey_Tab }, + { "ImGuiKey_LeftArrow", ImGuiKey_LeftArrow }, + { "ImGuiKey_RightArrow", ImGuiKey_RightArrow }, + { "ImGuiKey_UpArrow", ImGuiKey_UpArrow }, + { "ImGuiKey_DownArrow", ImGuiKey_DownArrow }, + { "ImGuiKey_PageUp", ImGuiKey_PageUp }, + { "ImGuiKey_PageDown", ImGuiKey_PageDown }, + { "ImGuiKey_Home", ImGuiKey_Home }, + { "ImGuiKey_End", ImGuiKey_End }, + { "ImGuiKey_Insert", ImGuiKey_Insert }, + { "ImGuiKey_Delete", ImGuiKey_Delete }, + { "ImGuiKey_Backspace", ImGuiKey_Backspace }, + { "ImGuiKey_Space", ImGuiKey_Space }, + { "ImGuiKey_Enter", ImGuiKey_Enter }, + { "ImGuiKey_Escape", ImGuiKey_Escape }, + { "ImGuiKey_Apostrophe", ImGuiKey_Apostrophe }, + { "ImGuiKey_Comma", ImGuiKey_Comma }, + { "ImGuiKey_Minus", ImGuiKey_Minus }, + { "ImGuiKey_Period", ImGuiKey_Period }, + { "ImGuiKey_Slash", ImGuiKey_Slash }, + { "ImGuiKey_Semicolon", ImGuiKey_Semicolon }, + { "ImGuiKey_Equal", ImGuiKey_Equal }, + { "ImGuiKey_LeftBracket", ImGuiKey_LeftBracket }, + { "ImGuiKey_Backslash", ImGuiKey_Backslash }, + { "ImGuiKey_RightBracket", ImGuiKey_RightBracket }, + { "ImGuiKey_GraveAccent", ImGuiKey_GraveAccent }, + { "ImGuiKey_CapsLock", ImGuiKey_CapsLock }, + { "ImGuiKey_ScrollLock", ImGuiKey_ScrollLock }, + { "ImGuiKey_NumLock", ImGuiKey_NumLock }, + { "ImGuiKey_PrintScreen", ImGuiKey_PrintScreen }, + { "ImGuiKey_Pause", ImGuiKey_Pause }, + { "ImGuiKey_Keypad0", ImGuiKey_Keypad0 }, + { "ImGuiKey_Keypad1", ImGuiKey_Keypad1 }, + { "ImGuiKey_Keypad2", ImGuiKey_Keypad2 }, + { "ImGuiKey_Keypad3", ImGuiKey_Keypad3 }, + { "ImGuiKey_Keypad4", ImGuiKey_Keypad4 }, + { "ImGuiKey_Keypad5", ImGuiKey_Keypad5 }, + { "ImGuiKey_Keypad6", ImGuiKey_Keypad6 }, + { "ImGuiKey_Keypad7", ImGuiKey_Keypad7 }, + { "ImGuiKey_Keypad8", ImGuiKey_Keypad8 }, + { "ImGuiKey_Keypad9", ImGuiKey_Keypad9 }, + { "ImGuiKey_KeypadDecimal", ImGuiKey_KeypadDecimal }, + { "ImGuiKey_KeypadDivide", ImGuiKey_KeypadDivide }, + { "ImGuiKey_KeypadMultiply", ImGuiKey_KeypadMultiply }, + { "ImGuiKey_KeypadSubtract", ImGuiKey_KeypadSubtract }, + { "ImGuiKey_KeypadAdd", ImGuiKey_KeypadAdd }, + { "ImGuiKey_KeypadEnter", ImGuiKey_KeypadEnter }, + { "ImGuiKey_LeftShift", ImGuiKey_LeftShift }, + { "ImGuiKey_LeftCtrl", ImGuiKey_LeftCtrl }, + { "ImGuiKey_LeftAlt", ImGuiKey_LeftAlt }, + { "ImGuiKey_LeftSuper", ImGuiKey_LeftSuper }, + { "ImGuiKey_RightShift", ImGuiKey_RightShift }, + { "ImGuiKey_RightCtrl", ImGuiKey_RightCtrl }, + { "ImGuiKey_RightAlt", ImGuiKey_RightAlt }, + { "ImGuiKey_RightSuper", ImGuiKey_RightSuper }, + { "ImGuiKey_Menu", ImGuiKey_Menu }, + { "ImGuiKey_0", ImGuiKey_0 }, + { "ImGuiKey_1", ImGuiKey_1 }, + { "ImGuiKey_2", ImGuiKey_2 }, + { "ImGuiKey_3", ImGuiKey_3 }, + { "ImGuiKey_4", ImGuiKey_4 }, + { "ImGuiKey_5", ImGuiKey_5 }, + { "ImGuiKey_6", ImGuiKey_6 }, + { "ImGuiKey_7", ImGuiKey_7 }, + { "ImGuiKey_8", ImGuiKey_8 }, + { "ImGuiKey_9", ImGuiKey_9 }, + { "ImGuiKey_A", ImGuiKey_A }, + { "ImGuiKey_B", ImGuiKey_B }, + { "ImGuiKey_C", ImGuiKey_C }, + { "ImGuiKey_D", ImGuiKey_D }, + { "ImGuiKey_E", ImGuiKey_E }, + { "ImGuiKey_F", ImGuiKey_F }, + { "ImGuiKey_G", ImGuiKey_G }, + { "ImGuiKey_H", ImGuiKey_H }, + { "ImGuiKey_I", ImGuiKey_I }, + { "ImGuiKey_J", ImGuiKey_J }, + { "ImGuiKey_K", ImGuiKey_K }, + { "ImGuiKey_L", ImGuiKey_L }, + { "ImGuiKey_M", ImGuiKey_M }, + { "ImGuiKey_N", ImGuiKey_N }, + { "ImGuiKey_O", ImGuiKey_O }, + { "ImGuiKey_P", ImGuiKey_P }, + { "ImGuiKey_Q", ImGuiKey_Q }, + { "ImGuiKey_R", ImGuiKey_R }, + { "ImGuiKey_S", ImGuiKey_S }, + { "ImGuiKey_T", ImGuiKey_T }, + { "ImGuiKey_U", ImGuiKey_U }, + { "ImGuiKey_V", ImGuiKey_V }, + { "ImGuiKey_W", ImGuiKey_W }, + { "ImGuiKey_X", ImGuiKey_X }, + { "ImGuiKey_Y", ImGuiKey_Y }, + { "ImGuiKey_Z", ImGuiKey_Z }, + { "ImGuiKey_F1", ImGuiKey_F1 }, + { "ImGuiKey_F2", ImGuiKey_F2 }, + { "ImGuiKey_F3", ImGuiKey_F3 }, + { "ImGuiKey_F4", ImGuiKey_F4 }, + { "ImGuiKey_F5", ImGuiKey_F5 }, + { "ImGuiKey_F6", ImGuiKey_F6 }, + { "ImGuiKey_F7", ImGuiKey_F7 }, + { "ImGuiKey_F8", ImGuiKey_F8 }, + { "ImGuiKey_F9", ImGuiKey_F9 }, + { "ImGuiKey_F10", ImGuiKey_F10 }, + { "ImGuiKey_F11", ImGuiKey_F11 }, + { "ImGuiKey_F12", ImGuiKey_F12 }, + { "ImGuiMouseButton_Left", ImGuiMouseButton_Left }, + { "ImGuiMouseButton_Right", ImGuiMouseButton_Right }, + { "ImGuiMouseButton_Middle", ImGuiMouseButton_Middle }, + }; + + auto it = keyMap.find(keyName); + if (it != keyMap.end()) + return it->second; + + return ImGuiKey_None; } ImGuiKey StringToImGuiKey(const std::string& keyName) diff --git a/cheat/src/HotkeyManager.h b/cheat/src/HotkeyManager.hpp similarity index 100% rename from cheat/src/HotkeyManager.h rename to cheat/src/HotkeyManager.hpp diff --git a/cheat/src/Render/Gui/utils/gui-util.hpp b/cheat/src/Render/Gui/utils/gui-util.hpp index a548cd4..641d913 100644 --- a/cheat/src/Render/Gui/utils/gui-util.hpp +++ b/cheat/src/Render/Gui/utils/gui-util.hpp @@ -11,7 +11,7 @@ #include "color.hpp" #include "ConfigEntry.hpp" #include "Hotkey.h" -#include "HotkeyManager.h" +#include "HotkeyManager.hpp" #pragma warning(disable: 26812 26815) diff --git a/cheat/src/cheat/cheat.cpp b/cheat/src/cheat/cheat.cpp index e0f9709..8e8a91f 100644 --- a/cheat/src/cheat/cheat.cpp +++ b/cheat/src/cheat/cheat.cpp @@ -2,7 +2,7 @@ #include "global.h" #include "HookManager.h" #include "events.h" -#include "HotkeyManager.h" +#include "HotkeyManager.hpp" #include "features/PlayerSpeed.h" #include "features/NoCooldown.h"