diff --git a/DL2GameOverhaulScript/DL2GameOverhaulScript.vcxproj b/DL2GameOverhaulScript/DL2GameOverhaulScript.vcxproj index 6ec7677..0ddca83 100644 --- a/DL2GameOverhaulScript/DL2GameOverhaulScript.vcxproj +++ b/DL2GameOverhaulScript/DL2GameOverhaulScript.vcxproj @@ -18,7 +18,6 @@ - @@ -51,7 +50,6 @@ - diff --git a/DL2GameOverhaulScript/DL2GameOverhaulScript.vcxproj.filters b/DL2GameOverhaulScript/DL2GameOverhaulScript.vcxproj.filters index 45df78a..15791ae 100644 --- a/DL2GameOverhaulScript/DL2GameOverhaulScript.vcxproj.filters +++ b/DL2GameOverhaulScript/DL2GameOverhaulScript.vcxproj.filters @@ -59,9 +59,6 @@ menu - - ImGuiHotkeys - ImGuiHotkeys @@ -158,9 +155,6 @@ ImGuiHotkeys - - ImGuiHotkeys - diff --git a/DL2GameOverhaulScript/source/ImGui/imconfig.h b/DL2GameOverhaulScript/source/ImGui/imconfig.h index 0375054..f05dec0 100644 --- a/DL2GameOverhaulScript/source/ImGui/imconfig.h +++ b/DL2GameOverhaulScript/source/ImGui/imconfig.h @@ -28,7 +28,7 @@ //---- Don't define obsolete functions/enums/behaviors. Consider enabling from time to time after updating to clean your code of obsolete function/names. #define IMGUI_DISABLE_OBSOLETE_FUNCTIONS -//#define IMGUI_DISABLE_OBSOLETE_KEYIO // 1.87: disable legacy io.KeyMap[]+io.KeysDown[] in favor io.AddKeyEvent(). This will be folded into IMGUI_DISABLE_OBSOLETE_FUNCTIONS in a few versions. +#define IMGUI_DISABLE_OBSOLETE_KEYIO // 1.87: disable legacy io.KeyMap[]+io.KeysDown[] in favor io.AddKeyEvent(). This will be folded into IMGUI_DISABLE_OBSOLETE_FUNCTIONS in a few versions. //---- Disable all of Dear ImGui or don't implement standard windows/tools. // It is very strongly recommended to NOT disable the demo windows and debug tool during development. They are extremely useful in day to day work. Please read comments in imgui_demo.cpp. diff --git a/DL2GameOverhaulScript/source/ImGui/impl/d3d11_impl.cpp b/DL2GameOverhaulScript/source/ImGui/impl/d3d11_impl.cpp index 45c72a0..b3348ac 100644 --- a/DL2GameOverhaulScript/source/ImGui/impl/d3d11_impl.cpp +++ b/DL2GameOverhaulScript/source/ImGui/impl/d3d11_impl.cpp @@ -38,7 +38,7 @@ HRESULT __stdcall hkPresent11(IDXGISwapChain* pSwapChain, UINT SyncInterval, UIN ImGui_ImplWin32_NewFrame(); ImGui::NewFrame(); - if (Menu::isOpen) + if (Menu::menuToggle.IsEnabled()) Menu::Render(); ImGui::EndFrame(); diff --git a/DL2GameOverhaulScript/source/ImGui/impl/d3d12_impl.cpp b/DL2GameOverhaulScript/source/ImGui/impl/d3d12_impl.cpp index a0fbc9e..a6c23fb 100644 --- a/DL2GameOverhaulScript/source/ImGui/impl/d3d12_impl.cpp +++ b/DL2GameOverhaulScript/source/ImGui/impl/d3d12_impl.cpp @@ -104,7 +104,7 @@ static void RenderImGui_DX12(IDXGISwapChain3* pSwapChain) { ImGui_ImplWin32_NewFrame(); ImGui::NewFrame(); - if (Menu::isOpen) + if (Menu::menuToggle.IsEnabled()) Menu::Render(); ImGui::Render(); diff --git a/DL2GameOverhaulScript/source/ImGui/impl/win32_impl.cpp b/DL2GameOverhaulScript/source/ImGui/impl/win32_impl.cpp index 6cb93fb..dde7e74 100644 --- a/DL2GameOverhaulScript/source/ImGui/impl/win32_impl.cpp +++ b/DL2GameOverhaulScript/source/ImGui/impl/win32_impl.cpp @@ -2,7 +2,9 @@ #include #include #include +#include "..\..\core.h" #include "..\..\menu\menu.h" +#include "..\config\config.h" #include "..\..\sigscan\offsets.h" #include "..\..\game_classes.h" #include "..\..\kiero.h" @@ -10,57 +12,30 @@ static WNDPROC oWndProc = NULL; static bool toggledMenu = false; -static bool wasAnyKeyPressed = false; extern IMGUI_IMPL_API LRESULT ImGui_ImplWin32_WndProcHandler(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam); LRESULT __stdcall hkWindowProc(_In_ HWND hwnd, _In_ UINT uMsg, _In_ WPARAM wParam, _In_ LPARAM lParam) { switch (uMsg) { case WM_KEYDOWN: - if (ImGui::isAnyHotkeyBtnPressed || !ImGui::timeSinceHotkeyBtnPressed.GetTimePassed() || wasAnyKeyPressed) + if (ImGui::isAnyHotkeyBtnPressed || !ImGui::timeSinceHotkeyBtnPressed.GetTimePassed() || KeyBindOption::wasAnyKeyPressed) break; - if (wParam == Menu::toggleKey.toInt()) { - wasAnyKeyPressed = true; - Menu::isOpen = !Menu::isOpen; - } - else if (wParam == Menu::Player::godModeToggleKey.toInt()) { - wasAnyKeyPressed = true; - Menu::Player::godModeEnabled.value = !Menu::Player::godModeEnabled.value; - } - else if (wParam == Menu::Player::freezePlayerToggleKey.toInt()) { - wasAnyKeyPressed = true; - Menu::Player::freezePlayerEnabled.value = !Menu::Player::freezePlayerEnabled.value; - } - else if (wParam == Menu::Camera::freeCamToggleKey.toInt()) { - wasAnyKeyPressed = true; - Menu::Camera::freeCamEnabled.value = !Menu::Camera::freeCamEnabled.value; - } - else if (wParam == Menu::Camera::teleportPlayerToCameraToggleKey.toInt()) { - wasAnyKeyPressed = true; - Menu::Camera::teleportPlayerToCameraEnabled = !Menu::Camera::teleportPlayerToCameraEnabled; - } - else if (wParam == Menu::Camera::thirdPersonCameraToggleKey.toInt()) { - wasAnyKeyPressed = true; - Menu::Camera::thirdPersonCameraEnabled.value = !Menu::Camera::thirdPersonCameraEnabled.value; - } - else if (wParam == Menu::Camera::tpUseTPPModelToggleKey.toInt()) { - wasAnyKeyPressed = true; - Menu::Camera::tpUseTPPModelEnabled.value = !Menu::Camera::tpUseTPPModelEnabled.value; + for (auto& option : KeyBindOption::GetInstances()) { + if (wParam == option->GetKeyBind()) { + KeyBindOption::wasAnyKeyPressed = true; + option->Toggle(); + } } break; case WM_KEYUP: - if (!wasAnyKeyPressed) + if (!KeyBindOption::wasAnyKeyPressed) break; - if (wParam == Menu::toggleKey.toInt() || - wParam == Menu::Player::godModeToggleKey.toInt() || - wParam == Menu::Player::freezePlayerToggleKey.toInt() || - wParam == Menu::Camera::freeCamToggleKey.toInt() || - wParam == Menu::Camera::teleportPlayerToCameraToggleKey.toInt() || - wParam == Menu::Camera::thirdPersonCameraToggleKey.toInt() || - wParam == Menu::Camera::tpUseTPPModelToggleKey.toInt()) - wasAnyKeyPressed = false; + for (auto& option : KeyBindOption::GetInstances()) { + if (wParam == option->GetKeyBind()) + KeyBindOption::wasAnyKeyPressed = false; + } break; } @@ -68,10 +43,10 @@ LRESULT __stdcall hkWindowProc(_In_ HWND hwnd, _In_ UINT uMsg, _In_ WPARAM wPara if (!pCInput) return CallWindowProc(oWndProc, hwnd, uMsg, wParam, lParam); - ImGui::GetIO().MouseDrawCursor = Menu::isOpen; + ImGui::GetIO().MouseDrawCursor = Menu::menuToggle.IsEnabled(); ImGui_ImplWin32_WndProcHandler(hwnd, uMsg, wParam, lParam); - if (Menu::isOpen) { + if (Menu::menuToggle.IsEnabled()) { if (!toggledMenu) pCInput->BlockGameInput(); diff --git a/DL2GameOverhaulScript/source/ImGuiHotkeys/Hotkey.cpp b/DL2GameOverhaulScript/source/ImGuiHotkeys/Hotkey.cpp index 180a591..dc4ac9b 100644 --- a/DL2GameOverhaulScript/source/ImGuiHotkeys/Hotkey.cpp +++ b/DL2GameOverhaulScript/source/ImGuiHotkeys/Hotkey.cpp @@ -1,18 +1,16 @@ #define IMGUI_DEFINE_MATH_OPERATORS -#include #include #include "Hotkey.h" bool ImGui::isAnyHotkeyBtnPressed = false; Utils::Timer ImGui::timeSinceHotkeyBtnPressed{ 250 }; -void ImGui::Hotkey(std::string_view label, KeyBind& key, float samelineOffset, const ImVec2& size) noexcept -{ +void ImGui::Hotkey(std::string_view label, KeyBindOption& key, float samelineOffset, const ImVec2& size) { const auto id = ImGui::GetID(label.data()); ImGui::PushID(label.data()); if (!label.contains("##")) - ImGui::TextUnformatted(label.data()); + ImGui::Text(label.data()); ImGui::SameLine(samelineOffset); if (ImGui::GetActiveID() == id) { @@ -21,7 +19,7 @@ void ImGui::Hotkey(std::string_view label, KeyBind& key, float samelineOffset, c ImGui::PopStyleColor(); ImGui::GetCurrentContext()->ActiveIdAllowOverlap = true; - if ((!ImGui::IsItemHovered() && ImGui::GetIO().MouseClicked[0]) || key.setToPressedKey()) { + if ((!ImGui::IsItemHovered() && ImGui::GetIO().MouseClicked[0]) || key.SetToPressedKey()) { timeSinceHotkeyBtnPressed = Utils::Timer(250); isAnyHotkeyBtnPressed = false; ImGui::ClearActiveID(); @@ -29,7 +27,7 @@ void ImGui::Hotkey(std::string_view label, KeyBind& key, float samelineOffset, c else ImGui::SetActiveID(id, ImGui::GetCurrentWindow()); } - else if (ImGui::Button(key.toString(), size)) { + else if (ImGui::Button(key.ToString(), size)) { isAnyHotkeyBtnPressed = true; ImGui::SetActiveID(id, ImGui::GetCurrentWindow()); } diff --git a/DL2GameOverhaulScript/source/ImGuiHotkeys/Hotkey.h b/DL2GameOverhaulScript/source/ImGuiHotkeys/Hotkey.h index b3b8cab..f5a83f1 100644 --- a/DL2GameOverhaulScript/source/ImGuiHotkeys/Hotkey.h +++ b/DL2GameOverhaulScript/source/ImGuiHotkeys/Hotkey.h @@ -1,12 +1,11 @@ #pragma once #include -#include -#include "../utils.h" +#include "..\..\core.h" +#include "..\utils.h" -namespace ImGui -{ +namespace ImGui { extern bool isAnyHotkeyBtnPressed; extern Utils::Timer timeSinceHotkeyBtnPressed; - void Hotkey(std::string_view label, KeyBind& key, float samelineOffset = 0.0f, const ImVec2& size = {0.0f, 0.0f}) noexcept; + void Hotkey(std::string_view label, KeyBindOption& key, float samelineOffset = 0.0f, const ImVec2& size = { 0.0f, 0.0f }); } \ No newline at end of file diff --git a/DL2GameOverhaulScript/source/ImGuiHotkeys/InputUtil.cpp b/DL2GameOverhaulScript/source/ImGuiHotkeys/InputUtil.cpp deleted file mode 100644 index 28186c7..0000000 --- a/DL2GameOverhaulScript/source/ImGuiHotkeys/InputUtil.cpp +++ /dev/null @@ -1,242 +0,0 @@ -#include -#include -#include -#include - -#include - -#include "InputUtil.h" - -struct Key { - constexpr Key(std::string_view name, int code) : name{ name }, code{ code } { } - - std::string_view name; - int code; -}; - -// indices must match KeyBind::KeyCode enum -static constexpr auto keyMap = std::to_array({ - { "'", VK_OEM_7 }, - { ",", VK_OEM_COMMA }, - { "-", VK_OEM_MINUS }, - { ".", VK_OEM_PERIOD }, - { "/", VK_OEM_2 }, - { "0", '0' }, - { "1", '1' }, - { "2", '2' }, - { "3", '3' }, - { "4", '4' }, - { "5", '5' }, - { "6", '6' }, - { "7", '7' }, - { "8", '8' }, - { "9", '9' }, - { ";", VK_OEM_1 }, - { "=", VK_OEM_PLUS }, - { "A", 'A' }, - { "ADD", VK_ADD }, - { "B", 'B' }, - { "BACKSPACE", VK_BACK }, - { "C", 'C' }, - { "CAPSLOCK", VK_CAPITAL }, - { "D", 'D' }, - { "DECIMAL", VK_DECIMAL }, - { "DELETE", VK_DELETE }, - { "DIVIDE", VK_DIVIDE }, - { "DOWN", VK_DOWN }, - { "E", 'E' }, - { "END", VK_END }, - { "ENTER", VK_RETURN }, - { "F", 'F' }, - { "F1", VK_F1 }, - { "F10", VK_F10 }, - { "F11", VK_F11 }, - { "F12", VK_F12 }, - { "F2", VK_F2 }, - { "F3", VK_F3 }, - { "F4", VK_F4 }, - { "F5", VK_F5 }, - { "F6", VK_F6 }, - { "F7", VK_F7 }, - { "F8", VK_F8 }, - { "F9", VK_F9 }, - { "G", 'G' }, - { "H", 'H' }, - { "HOME", VK_HOME }, - { "I", 'I' }, - { "INSERT", VK_INSERT }, - { "J", 'J' }, - { "K", 'K' }, - { "L", 'L' }, - { "LALT", VK_LMENU }, - { "LCTRL", VK_LCONTROL }, - { "LEFT", VK_LEFT }, - { "LSHIFT", VK_LSHIFT }, - { "M", 'M' }, - { "MOUSE1", 0 }, - { "MOUSE2", 1 }, - { "MOUSE3", 2 }, - { "MOUSE4", 3 }, - { "MOUSE5", 4 }, - { "MULTIPLY", VK_MULTIPLY }, - { "MWHEEL_DOWN", 0 }, - { "MWHEEL_UP", 0 }, - { "N", 'N' }, - { "NONE", 0 }, - { "NUMPAD_0", VK_NUMPAD0 }, - { "NUMPAD_1", VK_NUMPAD1 }, - { "NUMPAD_2", VK_NUMPAD2 }, - { "NUMPAD_3", VK_NUMPAD3 }, - { "NUMPAD_4", VK_NUMPAD4 }, - { "NUMPAD_5", VK_NUMPAD5 }, - { "NUMPAD_6", VK_NUMPAD6 }, - { "NUMPAD_7", VK_NUMPAD7 }, - { "NUMPAD_8", VK_NUMPAD8 }, - { "NUMPAD_9", VK_NUMPAD9 }, - { "O", 'O' }, - { "P", 'P' }, - { "PAGE_DOWN", VK_NEXT }, - { "PAGE_UP", VK_PRIOR }, - { "Q", 'Q' }, - { "R", 'R' }, - { "RALT", VK_RMENU }, - { "RCTRL", VK_RCONTROL }, - { "RIGHT", VK_RIGHT }, - { "RSHIFT", VK_RSHIFT }, - { "S", 'S' }, - { "SPACE", VK_SPACE }, - { "SUBTRACT", VK_SUBTRACT }, - { "T", 'T' }, - { "TAB", VK_TAB }, - { "U", 'U' }, - { "UP", VK_UP }, - { "V", 'V' }, - { "W", 'W' }, - { "X", 'X' }, - { "Y", 'Y' }, - { "Z", 'Z' }, - { "[", VK_OEM_4 }, - { "\\", VK_OEM_5 }, - { "]", VK_OEM_6 }, - { "`", VK_OEM_3 } - }); - -static_assert(keyMap.size() == KeyBind::MAX); -static_assert(std::ranges::is_sorted(keyMap, {}, & Key::name)); - -KeyBind::KeyBind(KeyCode keyCode) noexcept : keyCode{ static_cast(keyCode) < keyMap.size() ? keyCode : KeyCode::NONE } {} - -KeyBind::KeyBind(const char* keyName) noexcept -{ - if (const auto it = std::ranges::lower_bound(keyMap, keyName, {}, &Key::name); it != keyMap.end() && it->name == keyName) - keyCode = static_cast(std::distance(keyMap.begin(), it)); - else - keyCode = KeyCode::NONE; -} - -const char* KeyBind::toString() const noexcept -{ - return keyMap[static_cast(keyCode) < keyMap.size() ? keyCode : KeyCode::NONE].name.data(); -} - -const int KeyBind::toInt() const noexcept -{ - return keyMap[static_cast(keyCode) < keyMap.size() ? keyCode : KeyCode::NONE].code; //Key::code -} - -bool KeyBind::isPressed() const noexcept -{ - if (keyCode == KeyCode::NONE) - return false; - - if (keyCode == KeyCode::MOUSEWHEEL_DOWN) - return ImGui::GetIO().MouseWheel < 0.0f; - - if (keyCode == KeyCode::MOUSEWHEEL_UP) - return ImGui::GetIO().MouseWheel > 0.0f; - - if (keyCode >= KeyCode::MOUSE1 && keyCode <= KeyCode::MOUSE5) - return ImGui::IsMouseClicked(keyMap[keyCode].code); - - return static_cast(keyCode) < keyMap.size() && ImGui::IsKeyPressed(static_cast(keyMap[keyCode].code), false); -} - -bool KeyBind::isDown() const noexcept -{ - if (keyCode == KeyCode::NONE) - return false; - - if (keyCode == KeyCode::MOUSEWHEEL_DOWN) - return ImGui::GetIO().MouseWheel < 0.0f; - - if (keyCode == KeyCode::MOUSEWHEEL_UP) - return ImGui::GetIO().MouseWheel > 0.0f; - - if (keyCode >= KeyCode::MOUSE1 && keyCode <= KeyCode::MOUSE5) - return ImGui::IsMouseDown(keyMap[keyCode].code); - - return static_cast(keyCode) < keyMap.size() && ImGui::IsKeyDown(static_cast(keyMap[keyCode].code)); -} - -bool KeyBind::setToPressedKey() noexcept -{ - if (ImGui::IsKeyPressed(ImGuiKey_Escape)) { - keyCode = KeyCode::NONE; - return true; - } - else if (ImGui::GetIO().MouseWheel < 0.0f) { - keyCode = KeyCode::MOUSEWHEEL_DOWN; - return true; - } - else if (ImGui::GetIO().MouseWheel > 0.0f) { - keyCode = KeyCode::MOUSEWHEEL_UP; - return true; - } - else if (GetKeyState(keyMap[LSHIFT].code) & 0x8000) { - keyCode = KeyCode::LSHIFT; - return true; - } - else if (GetKeyState(keyMap[LALT].code) & 0x8000) { - keyCode = KeyCode::LALT; - return true; - } - else if (GetKeyState(keyMap[LCTRL].code) & 0x8000) { - keyCode = KeyCode::LCTRL; - return true; - } - else if (GetKeyState(keyMap[MOUSE4].code) & 0x8000) { - keyCode = KeyCode::MOUSE4; - return true; - } - else if (GetKeyState(keyMap[MOUSE5].code) & 0x8000) { - keyCode = KeyCode::MOUSE5; - return true; - } - - for (int i = 0; i < IM_ARRAYSIZE(ImGui::GetIO().MouseDown); ++i) { - if (ImGui::IsMouseClicked(i)) { - keyCode = KeyCode(KeyCode::MOUSE1 + i); - return true; - } - } - - for (int i = 0; i < ImGuiKey_NamedKey_BEGIN; ++i) { - if (!ImGui::IsKeyPressed(static_cast(i))) - continue; - - if (const auto it = std::ranges::find(keyMap, i, &Key::code); it != keyMap.end()) { - keyCode = static_cast(std::distance(keyMap.begin(), it)); - // Treat AltGr as RALT - if (keyCode == KeyCode::LCTRL && ImGui::IsKeyPressed(static_cast(keyMap[KeyCode::RALT].code))) - keyCode = KeyCode::RALT; - return true; - } - } - return false; -} - -void KeyBindToggle::handleToggle() noexcept -{ - if (isPressed()) - toggledOn = !toggledOn; -} diff --git a/DL2GameOverhaulScript/source/ImGuiHotkeys/InputUtil.h b/DL2GameOverhaulScript/source/ImGuiHotkeys/InputUtil.h deleted file mode 100644 index efa1a6f..0000000 --- a/DL2GameOverhaulScript/source/ImGuiHotkeys/InputUtil.h +++ /dev/null @@ -1,144 +0,0 @@ -#pragma once -#include - -class KeyBind { -public: - KeyBind() : keybind{ "" } {}; - KeyBind(std::string _keybind) : keybind{ _keybind } {}; - std::string keybind; - - enum KeyCode : unsigned char { - APOSTROPHE = 0, - COMMA, - MINUS, - PERIOD, - SLASH, - KEY_0, - KEY_1, - KEY_2, - KEY_3, - KEY_4, - KEY_5, - KEY_6, - KEY_7, - KEY_8, - KEY_9, - SEMICOLON, - EQUALS, - A, - ADD, - B, - BACKSPACE, - C, - CAPSLOCK, - D, - DECIMAL, - DEL, - DIVIDE, - DOWN, - E, - END, - ENTER, - F, - F1, - F10, - F11, - F12, - F2, - F3, - F4, - F5, - F6, - F7, - F8, - F9, - G, - H, - HOME, - I, - INSERT, - J, - K, - L, - LALT, - LCTRL, - LEFT, - LSHIFT, - M, - MOUSE1, - MOUSE2, - MOUSE3, - MOUSE4, - MOUSE5, - MULTIPLY, - MOUSEWHEEL_DOWN, - MOUSEWHEEL_UP, - N, - NONE, - NUMPAD_0, - NUMPAD_1, - NUMPAD_2, - NUMPAD_3, - NUMPAD_4, - NUMPAD_5, - NUMPAD_6, - NUMPAD_7, - NUMPAD_8, - NUMPAD_9, - O, - P, - PAGE_DOWN, - PAGE_UP, - Q, - R, - RALT, - RCTRL, - RIGHT, - RSHIFT, - S, - SPACE, - SUBTRACT, - T, - TAB, - U, - UP, - V, - W, - X, - Y, - Z, - LEFTBRACKET, - BACKSLASH, - RIGHTBRACKET, - BACKTICK, - - MAX - }; - - //KeyBind() = default; - explicit KeyBind(KeyCode keyCode) noexcept; - explicit KeyBind(const char* keyName) noexcept; - - bool operator==(KeyCode keyCode) const noexcept { return this->keyCode == keyCode; } - friend bool operator==(const KeyBind& a, const KeyBind& b) noexcept { return a.keyCode == b.keyCode; } - - [[nodiscard]] const char* toString() const noexcept; - [[nodiscard]] const int toInt() const noexcept; - [[nodiscard]] bool isPressed() const noexcept; - [[nodiscard]] bool isDown() const noexcept; - [[nodiscard]] bool isSet() const noexcept { return keyCode != KeyCode::NONE; } - - bool setToPressedKey() noexcept; -private: - KeyCode keyCode = KeyCode::NONE; -}; - -class KeyBindToggle : public KeyBind { -public: - using KeyBind::KeyBind; - - void handleToggle() noexcept; - [[nodiscard]] bool isToggled() const noexcept { return toggledOn; } -private: - bool toggledOn = true; -}; \ No newline at end of file diff --git a/DL2GameOverhaulScript/source/config/config.cpp b/DL2GameOverhaulScript/source/config/config.cpp index 78ed6bd..836935d 100644 --- a/DL2GameOverhaulScript/source/config/config.cpp +++ b/DL2GameOverhaulScript/source/config/config.cpp @@ -1,162 +1,169 @@ #include #include +#include #include -#include +#include "config.h" #include "..\menu\menu.h" #include "..\utils.h" #include "..\print.h" #include "ini.h" namespace Config { - static const std::vector> virtualKeyCodes = { + struct VKey { + constexpr VKey(std::string_view name, int code) : name(name), code(code) {} + + std::string_view name; + int code; + }; + static constexpr auto virtualKeyCodes = std::to_array({ // Function keys - { "VK_F1", KeyBind::F1 }, - { "VK_F2", KeyBind::F2 }, - { "VK_F3", KeyBind::F3 }, - { "VK_F4", KeyBind::F4 }, - { "VK_F5", KeyBind::F5 }, - { "VK_F6", KeyBind::F6 }, - { "VK_F7", KeyBind::F7 }, - { "VK_F8", KeyBind::F8 }, - { "VK_F9", KeyBind::F9 }, - { "VK_F10", KeyBind::F10 }, - { "VK_F11", KeyBind::F11 }, - { "VK_F12", KeyBind::F12 }, + { "VK_F1", VK_F1 }, + { "VK_F2", VK_F2 }, + { "VK_F3", VK_F3 }, + { "VK_F4", VK_F4 }, + { "VK_F5", VK_F5 }, + { "VK_F6", VK_F6 }, + { "VK_F7", VK_F7 }, + { "VK_F8", VK_F8 }, + { "VK_F9", VK_F9 }, + { "VK_F10", VK_F10 }, + { "VK_F11", VK_F11 }, + { "VK_F12", VK_F12 }, // Number keys - { "VK_0", KeyBind::KEY_0 }, - { "VK_1", KeyBind::KEY_1 }, - { "VK_2", KeyBind::KEY_2 }, - { "VK_3", KeyBind::KEY_3 }, - { "VK_4", KeyBind::KEY_4 }, - { "VK_5", KeyBind::KEY_5 }, - { "VK_6", KeyBind::KEY_6 }, - { "VK_7", KeyBind::KEY_7 }, - { "VK_8", KeyBind::KEY_8 }, - { "VK_9", KeyBind::KEY_9 }, - { "0", KeyBind::KEY_0 }, - { "1", KeyBind::KEY_1 }, - { "2", KeyBind::KEY_2 }, - { "3", KeyBind::KEY_3 }, - { "4", KeyBind::KEY_4 }, - { "5", KeyBind::KEY_5 }, - { "6", KeyBind::KEY_6 }, - { "7", KeyBind::KEY_7 }, - { "8", KeyBind::KEY_8 }, - { "9", KeyBind::KEY_9 }, + { "VK_0", '0' }, + { "VK_1", '1' }, + { "VK_2", '2' }, + { "VK_3", '3' }, + { "VK_4", '4' }, + { "VK_5", '5' }, + { "VK_6", '6' }, + { "VK_7", '7' }, + { "VK_8", '8' }, + { "VK_9", '9' }, + { "0", '0' }, + { "1", '1' }, + { "2", '2' }, + { "3", '3' }, + { "4", '4' }, + { "5", '5' }, + { "6", '6' }, + { "7", '7' }, + { "8", '8' }, + { "9", '9' }, // Alphabetic keys - { "VK_A", KeyBind::A }, - { "VK_B", KeyBind::B }, - { "VK_C", KeyBind::C }, - { "VK_D", KeyBind::D }, - { "VK_E", KeyBind::E }, - { "VK_F", KeyBind::F }, - { "VK_G", KeyBind::G }, - { "VK_H", KeyBind::H }, - { "VK_I", KeyBind::I }, - { "VK_J", KeyBind::J }, - { "VK_K", KeyBind::K }, - { "VK_L", KeyBind::L }, - { "VK_M", KeyBind::M }, - { "VK_N", KeyBind::N }, - { "VK_O", KeyBind::O }, - { "VK_P", KeyBind::P }, - { "VK_Q", KeyBind::Q }, - { "VK_R", KeyBind::R }, - { "VK_S", KeyBind::S }, - { "VK_T", KeyBind::T }, - { "VK_U", KeyBind::U }, - { "VK_V", KeyBind::V }, - { "VK_W", KeyBind::W }, - { "VK_X", KeyBind::X }, - { "VK_Y", KeyBind::Y }, - { "VK_Z", KeyBind::Z }, - { "A", KeyBind::A }, - { "B", KeyBind::B }, - { "C", KeyBind::C }, - { "D", KeyBind::D }, - { "E", KeyBind::E }, - { "F", KeyBind::F }, - { "G", KeyBind::G }, - { "H", KeyBind::H }, - { "I", KeyBind::I }, - { "J", KeyBind::J }, - { "K", KeyBind::K }, - { "L", KeyBind::L }, - { "M", KeyBind::M }, - { "N", KeyBind::N }, - { "O", KeyBind::O }, - { "P", KeyBind::P }, - { "Q", KeyBind::Q }, - { "R", KeyBind::R }, - { "S", KeyBind::S }, - { "T", KeyBind::T }, - { "U", KeyBind::U }, - { "V", KeyBind::V }, - { "W", KeyBind::W }, - { "X", KeyBind::X }, - { "Y", KeyBind::Y }, - { "Z", KeyBind::Z }, + { "VK_A", 'A' }, + { "VK_B", 'B' }, + { "VK_C", 'C' }, + { "VK_D", 'D' }, + { "VK_E", 'E' }, + { "VK_F", 'F' }, + { "VK_G", 'G' }, + { "VK_H", 'H' }, + { "VK_I", 'I' }, + { "VK_J", 'J' }, + { "VK_K", 'K' }, + { "VK_L", 'L' }, + { "VK_M", 'M' }, + { "VK_N", 'N' }, + { "VK_O", 'O' }, + { "VK_P", 'P' }, + { "VK_Q", 'Q' }, + { "VK_R", 'R' }, + { "VK_S", 'S' }, + { "VK_T", 'T' }, + { "VK_U", 'U' }, + { "VK_V", 'V' }, + { "VK_W", 'W' }, + { "VK_X", 'X' }, + { "VK_Y", 'Y' }, + { "VK_Z", 'Z' }, + { "A", 'A' }, + { "B", 'B' }, + { "C", 'C' }, + { "D", 'D' }, + { "E", 'E' }, + { "F", 'F' }, + { "G", 'G' }, + { "H", 'H' }, + { "I", 'I' }, + { "J", 'J' }, + { "K", 'K' }, + { "L", 'L' }, + { "M", 'M' }, + { "N", 'N' }, + { "O", 'O' }, + { "P", 'P' }, + { "Q", 'Q' }, + { "R", 'R' }, + { "S", 'S' }, + { "T", 'T' }, + { "U", 'U' }, + { "V", 'V' }, + { "W", 'W' }, + { "X", 'X' }, + { "Y", 'Y' }, + { "Z", 'Z' }, // Special keys - {"VK_BACK", KeyBind::BACKSPACE }, - {"VK_TAB", KeyBind::TAB }, - {"VK_RETURN", KeyBind::ENTER }, - {"VK_CAPITAL", KeyBind::CAPSLOCK }, - {"VK_SPACE", KeyBind::SPACE }, - {"VK_PRIOR", KeyBind::PAGE_UP }, - {"VK_NEXT", KeyBind::PAGE_DOWN }, - {"VK_END", KeyBind::END }, - {"VK_HOME", KeyBind::HOME }, - {"VK_LEFT", KeyBind::LEFT }, - {"VK_UP", KeyBind::UP }, - {"VK_RIGHT", KeyBind::RIGHT }, - {"VK_DOWN", KeyBind::DOWN }, - {"VK_INSERT", KeyBind::INSERT }, - {"VK_DELETE", KeyBind::DEL }, + {"VK_BACK", VK_BACK }, + {"VK_TAB", VK_TAB }, + {"VK_RETURN", VK_RETURN }, + {"VK_CAPITAL", VK_CAPITAL }, + {"VK_SPACE", VK_SPACE }, + {"VK_PRIOR", VK_PRIOR }, + {"VK_NEXT", VK_NEXT }, + {"VK_END", VK_END }, + {"VK_HOME", VK_HOME }, + {"VK_LEFT", VK_LEFT }, + {"VK_UP", VK_UP }, + {"VK_RIGHT", VK_RIGHT }, + {"VK_DOWN", VK_DOWN }, + {"VK_INSERT", VK_INSERT }, + {"VK_DELETE", VK_DELETE }, // Numpad keys - { "VK_NUMPAD0", KeyBind::NUMPAD_0 }, - { "VK_NUMPAD1", KeyBind::NUMPAD_1 }, - { "VK_NUMPAD2", KeyBind::NUMPAD_2 }, - { "VK_NUMPAD3", KeyBind::NUMPAD_3 }, - { "VK_NUMPAD4", KeyBind::NUMPAD_4 }, - { "VK_NUMPAD5", KeyBind::NUMPAD_5 }, - { "VK_NUMPAD6", KeyBind::NUMPAD_6 }, - { "VK_NUMPAD7", KeyBind::NUMPAD_7 }, - { "VK_NUMPAD8", KeyBind::NUMPAD_8 }, - { "VK_NUMPAD9", KeyBind::NUMPAD_9 }, - { "VK_MULTIPLY", KeyBind::MULTIPLY }, - { "VK_ADD", KeyBind::ADD }, - { "VK_SUBTRACT", KeyBind::SUBTRACT }, - { "VK_DECIMAL", KeyBind::DECIMAL }, - { "VK_DIVIDE", KeyBind::DIVIDE }, + { "VK_NUMPAD0", VK_NUMPAD0 }, + { "VK_NUMPAD1", VK_NUMPAD1 }, + { "VK_NUMPAD2", VK_NUMPAD2 }, + { "VK_NUMPAD3", VK_NUMPAD3 }, + { "VK_NUMPAD4", VK_NUMPAD4 }, + { "VK_NUMPAD5", VK_NUMPAD5 }, + { "VK_NUMPAD6", VK_NUMPAD6 }, + { "VK_NUMPAD7", VK_NUMPAD7 }, + { "VK_NUMPAD8", VK_NUMPAD8 }, + { "VK_NUMPAD9", VK_NUMPAD9 }, + { "VK_MULTIPLY", VK_MULTIPLY }, + { "VK_ADD", VK_ADD }, + { "VK_SUBTRACT", VK_SUBTRACT }, + { "VK_DECIMAL", VK_DECIMAL }, + { "VK_DIVIDE", VK_DIVIDE }, // Modifier keys - { "VK_SHIFT", KeyBind::LSHIFT }, - { "VK_LSHIFT", KeyBind::LSHIFT }, - { "VK_RSHIFT", KeyBind::RSHIFT }, - { "VK_CONTROL", KeyBind::LCTRL }, - { "VK_LCONTROL", KeyBind::LCTRL }, - { "VK_RCONTROL", KeyBind::RCTRL }, - { "VK_MENU", KeyBind::LALT }, - { "VK_LMENU", KeyBind::LALT }, - { "VK_RMENU", KeyBind::RALT }, + { "VK_SHIFT", VK_LSHIFT }, + { "VK_LSHIFT", VK_LSHIFT }, + { "VK_RSHIFT", VK_RSHIFT }, + { "VK_CONTROL", VK_LCONTROL }, + { "VK_LCONTROL", VK_LCONTROL }, + { "VK_RCONTROL", VK_RCONTROL }, + { "VK_MENU", VK_LMENU }, + { "VK_LMENU", VK_LMENU }, + { "VK_RMENU", VK_RMENU }, // Other keys - { "VK_OEM_1", KeyBind::SEMICOLON }, - { "VK_OEM_PLUS", KeyBind::EQUALS }, - { "VK_OEM_COMMA", KeyBind::COMMA }, - { "VK_OEM_MINUS", KeyBind::MINUS }, - { "VK_OEM_PERIOD", KeyBind::PERIOD }, - { "VK_OEM_2", KeyBind::SLASH }, - { "VK_OEM_3", KeyBind::BACKTICK }, - { "VK_OEM_4", KeyBind::LEFTBRACKET }, - { "VK_OEM_5", KeyBind::BACKSLASH }, - { "VK_OEM_6", KeyBind::RIGHTBRACKET }, - { "VK_OEM_7", KeyBind::APOSTROPHE } - }; + { "VK_OEM_1", VK_OEM_1 }, + { "VK_OEM_PLUS", VK_OEM_PLUS }, + { "VK_OEM_COMMA", VK_OEM_COMMA }, + { "VK_OEM_MINUS", VK_OEM_MINUS }, + { "VK_OEM_PERIOD", VK_OEM_PERIOD }, + { "VK_OEM_2", VK_OEM_2 }, + { "VK_OEM_3", VK_OEM_3 }, + { "VK_OEM_4", VK_OEM_4 }, + { "VK_OEM_5", VK_OEM_5 }, + { "VK_OEM_6", VK_OEM_6 }, + { "VK_OEM_7", VK_OEM_7 } + }); extern const char playerVars[]; const char playerVars[] = { 0x41, 0x67, 0x67, 0x72, 0x65, 0x73, 0x69, 0x6F, 0x6E, 0x50, 0x65, 0x72, 0x48, 0x69, 0x74, 0x3A, @@ -4001,42 +4008,36 @@ namespace Config { 0x3A, 0x66, 0x6C, 0x6F, 0x61, 0x74 }; - enum ValueType { - Float, - Bool, - String - }; struct ConfigEntry { std::string_view section; std::string_view key; std::any value; - LPVOID valuePtr; + LPVOID optionPtr; ValueType type; }; - - static const std::vector configVariablesDefault = { + static const auto configVariablesDefault = std::to_array({ { "Menu", "Transparency", 99.0f, &Menu::transparency, Float }, - { "Menu:Keybinds", "MenuToggleKey", std::string("VK_F5"), &Menu::toggleKey, String}, - { "Menu:Keybinds", "GodModeToggleKey", std::string("VK_F6"), &Menu::Player::godModeToggleKey, String}, - { "Menu:Keybinds", "FreezePlayerToggleKey", std::string("VK_F7"), &Menu::Player::freezePlayerToggleKey, String}, - { "Menu:Keybinds", "FreeCamToggleKey", std::string("VK_F3"), &Menu::Camera::freeCamToggleKey, String}, - { "Menu:Keybinds", "TeleportPlayerToCameraToggleKey", std::string("VK_F4"), &Menu::Camera::teleportPlayerToCameraToggleKey, String}, - { "Menu:Keybinds", "ThirdPersonToggleKey", std::string("VK_F1"), &Menu::Camera::thirdPersonCameraToggleKey, String}, - { "Menu:Keybinds", "UseTPPModelToggleKey", std::string("VK_F2"), &Menu::Camera::tpUseTPPModelToggleKey, String}, - { "Player:Misc", "GodMode", false, &Menu::Player::godModeEnabled.value, Bool }, - { "Player:PlayerVariables", "Enabled", false, &Menu::Player::playerVariablesEnabled, Bool }, + { "Menu:Keybinds", "MenuToggleKey", std::string("VK_F5"), &Menu::menuToggle, String}, + { "Menu:Keybinds", "GodModeToggleKey", std::string("VK_F6"), &Menu::Player::godMode, String}, + { "Menu:Keybinds", "FreezePlayerToggleKey", std::string("VK_F7"), &Menu::Player::freezePlayer, String}, + { "Menu:Keybinds", "FreeCamToggleKey", std::string("VK_F3"), &Menu::Camera::freeCam, String}, + { "Menu:Keybinds", "TeleportPlayerToCameraToggleKey", std::string("VK_F4"), &Menu::Camera::teleportPlayerToCamera, String}, + { "Menu:Keybinds", "ThirdPersonToggleKey", std::string("VK_F1"), &Menu::Camera::thirdPersonCamera, String}, + { "Menu:Keybinds", "UseTPPModelToggleKey", std::string("VK_F2"), &Menu::Camera::tpUseTPPModel, String}, + { "Player:Misc", "GodMode", false, &Menu::Player::godMode, OPTION }, + { "Player:PlayerVariables", "Enabled", false, &Menu::Player::playerVariables, OPTION }, { "Player:PlayerVariables", "LastSaveSCRPath", std::string(), &Menu::Player::saveSCRPath, String }, { "Player:PlayerVariables", "LastLoadSCRFilePath", std::string(), &Menu::Player::loadSCRFilePath, String }, { "Camera:FreeCam", "Speed", 2.0f, &Menu::Camera::freeCamSpeed, Float }, - { "Camera:FreeCam", "TeleportPlayerToCamera", false, &Menu::Camera::teleportPlayerToCameraEnabled, Bool }, - { "Camera:ThirdPerson", "Enabled", false, &Menu::Camera::thirdPersonCameraEnabled.value, Bool }, - { "Camera:ThirdPerson", "UseTPPModel", true, &Menu::Camera::tpUseTPPModelEnabled.value, Bool }, + { "Camera:FreeCam", "TeleportPlayerToCamera", false, &Menu::Camera::teleportPlayerToCamera, OPTION }, + { "Camera:ThirdPerson", "Enabled", false, &Menu::Camera::thirdPersonCamera, OPTION }, + { "Camera:ThirdPerson", "UseTPPModel", true, &Menu::Camera::tpUseTPPModel, OPTION }, { "Camera:ThirdPerson", "DistanceBehindPlayer", 2.0f, &Menu::Camera::tpDistanceBehindPlayer, Float }, { "Camera:ThirdPerson", "HeightAbovePlayer", 1.35f, &Menu::Camera::tpHeightAbovePlayer, Float }, - { "Camera:Misc", "DisablePhotoModeLimits", true, &Menu::Camera::disablePhotoModeLimitsEnabled.value, Bool }, - { "Camera:Misc", "DisableSafezoneFOVReduction", true, &Menu::Camera::disableSafezoneFOVReductionEnabled.value, Bool } - }; - std::vector configVariables = configVariablesDefault; + { "Camera:Misc", "DisablePhotoModeLimits", true, &Menu::Camera::disablePhotoModeLimits, OPTION }, + { "Camera:Misc", "DisableSafezoneFOVReduction", true, &Menu::Camera::disableSafezoneFOVReduction, OPTION } + }); + std::vector configVariables(configVariablesDefault.begin(), configVariablesDefault.end()); static const char* configFileName = "EGameTools.ini"; static std::filesystem::file_time_type configPreviousWriteTime{}; static std::filesystem::file_time_type configLastWriteTime{}; @@ -4049,12 +4050,12 @@ namespace Config { static void UpdateEntry(const ConfigEntry& entry) { switch (entry.type) { + case OPTION: + reader.UpdateEntry(entry.section.data(), entry.key.data(), std::any_cast(entry.value)); + break; case Float: reader.UpdateEntry(entry.section.data(), entry.key.data(), std::any_cast(entry.value)); break; - case Bool: - reader.UpdateEntry(entry.section.data(), entry.key.data(), std::any_cast(entry.value)); - break; case String: reader.UpdateEntry(entry.section.data(), entry.key.data(), std::any_cast(entry.value)); break; @@ -4082,18 +4083,17 @@ namespace Config { } else if (entry.section == "Menu:Keybinds") { const std::string toggleKey = std::any_cast(entry.value); - auto it = std::find_if(virtualKeyCodes.begin(), virtualKeyCodes.end(), [&toggleKey](const auto& pair) { return pair.first == toggleKey; }); - if (it != virtualKeyCodes.end()) - *reinterpret_cast(entry.valuePtr) = KeyBindToggle(it->second); + if (const auto it = std::ranges::find(virtualKeyCodes, toggleKey, &Config::VKey::name); it != virtualKeyCodes.end()) + reinterpret_cast(entry.optionPtr)->ChangeKeyBind(it->code); } switch (entry.type) { + case OPTION: + reader.InsertEntry(entry.section.data(), entry.key.data(), std::any_cast(entry.value)); + break; case Float: reader.InsertEntry(entry.section.data(), entry.key.data(), std::any_cast(entry.value)); break; - case Bool: - reader.InsertEntry(entry.section.data(), entry.key.data(), std::any_cast(entry.value)); - break; case String: reader.InsertEntry(entry.section.data(), entry.key.data(), std::any_cast(entry.value)); break; @@ -4131,18 +4131,17 @@ namespace Config { std::string strValue{}; for (auto& entry : configVariablesDefault) { switch (entry.type) { - case Float: - *reinterpret_cast(entry.valuePtr) = reader.Get(entry.section.data(), entry.key.data(), std::any_cast(entry.value)); + case OPTION: + reinterpret_cast(entry.optionPtr)->Change(reader.Get(entry.section.data(), entry.key.data(), std::any_cast(entry.value))); break; - case Bool: - *reinterpret_cast(entry.valuePtr) = reader.Get(entry.section.data(), entry.key.data(), std::any_cast(entry.value)); + case Float: + *reinterpret_cast(entry.optionPtr) = reader.Get(entry.section.data(), entry.key.data(), std::any_cast(entry.value)); break; case String: strValue = reader.Get(entry.section.data(), entry.key.data(), std::any_cast(entry.value)); if (entry.section == "Menu:Keybinds") { - auto it = std::find_if(virtualKeyCodes.begin(), virtualKeyCodes.end(), [&strValue](const auto& pair) { return pair.first == strValue; }); - if (it != virtualKeyCodes.end()) - *reinterpret_cast(entry.valuePtr) = KeyBindToggle(it->second); + if (const auto it = std::ranges::find(virtualKeyCodes, strValue, &Config::VKey::name); it != virtualKeyCodes.end()) + reinterpret_cast(entry.optionPtr)->ChangeKeyBind(it->code); break; } else if (entry.key == "LastSaveSCRPath") { @@ -4166,7 +4165,7 @@ namespace Config { break; } - *reinterpret_cast(entry.valuePtr) = strValue; + *reinterpret_cast(entry.optionPtr) = strValue; break; } } @@ -4182,21 +4181,22 @@ namespace Config { void SaveConfig() { for (auto& entry : configVariables) { switch (entry.type) { - case Float: - entry.value = *reinterpret_cast(entry.valuePtr); + case OPTION: + entry.value = reinterpret_cast(entry.optionPtr)->IsEnabled(); break; - case Bool: - entry.value = *reinterpret_cast(entry.valuePtr); + case Float: + entry.value = *reinterpret_cast(entry.optionPtr); break; case String: if (entry.section == "Menu:Keybinds") { - auto it = std::find_if(virtualKeyCodes.begin(), virtualKeyCodes.end(), [&entry](const auto& pair) { return pair.second == *reinterpret_cast(entry.valuePtr); }); - if (it != virtualKeyCodes.end()) - entry.value = std::string(it->first); + KeyBindOption* option = reinterpret_cast(entry.optionPtr); + + if (const auto it = std::ranges::find(virtualKeyCodes, option->GetKeyBind(), &Config::VKey::code); it != virtualKeyCodes.end()) + entry.value = std::string(it->name); break; } - entry.value = *reinterpret_cast(entry.valuePtr); + entry.value = *reinterpret_cast(entry.optionPtr); break; } diff --git a/DL2GameOverhaulScript/source/config/config.h b/DL2GameOverhaulScript/source/config/config.h index 25eb10a..3b929be 100644 --- a/DL2GameOverhaulScript/source/config/config.h +++ b/DL2GameOverhaulScript/source/config/config.h @@ -1,6 +1,14 @@ #pragma once +#include + namespace Config { extern const char playerVars[]; + + enum ValueType { + OPTION, + Float, + String + }; extern void SaveConfig(); extern void InitConfig(); diff --git a/DL2GameOverhaulScript/source/core.cpp b/DL2GameOverhaulScript/source/core.cpp index 50c1d54..9ebbbb8 100644 --- a/DL2GameOverhaulScript/source/core.cpp +++ b/DL2GameOverhaulScript/source/core.cpp @@ -10,7 +10,18 @@ #include "sigscan\offsets.h" #include "config\config.h" #include "hook.h" -#include "utils.h" + +#pragma region Option +std::set Option::instances{}; +std::set Option::GetInstances() { return instances; }; +#pragma endregion + +#pragma region KeyBindOption +bool KeyBindOption::wasAnyKeyPressed = false; + +std::set KeyBindOption::instances{}; +std::set KeyBindOption::GetInstances() { return instances; }; +#pragma endregion namespace Core { // Console stuff diff --git a/DL2GameOverhaulScript/source/core.h b/DL2GameOverhaulScript/source/core.h index 8d9455b..a47074f 100644 --- a/DL2GameOverhaulScript/source/core.h +++ b/DL2GameOverhaulScript/source/core.h @@ -1,40 +1,239 @@ #pragma once #include +#include +#include +#include +#include +#include "utils.h" +#ifndef VK_NONE +#define VK_NONE -1 +#define VK_MWHEELDOWN 0x100 +#define VK_MWHEELUP 0x101 +#endif -struct SMART_BOOL { - bool previousValue; - bool value; +struct Key { + constexpr Key(std::string_view name, int code, ImGuiKey imGuiCode) : name(name), code(code), imGuiCode(imGuiCode) {} - SMART_BOOL() { - changed = false; + std::string_view name; + int code; + ImGuiKey imGuiCode; +}; - previousValue = false; - value = false; - } +class Option { +public: + Option() { instances.insert(this); }; + ~Option() { instances.erase(this); } + static std::set GetInstances(); - bool Change(bool newValue) { - if (changed && newValue == value) - return false; + bool value = false; - if (!changed) - previousValue = value; + void Toggle() { value = !value; } + void Set(bool newValue) { value = newValue; } + void SetPreviousVal(bool newValue) { previousValue = newValue; } + constexpr bool IsEnabled() const { return value; } + constexpr bool WasEnabled() const { return previousValue; } + constexpr bool HasChanged() const { return previousValue != value; } + constexpr bool HasChangedTo(bool toValue) const { return previousValue != value && value == toValue; } - changed = true; - value = newValue; - return true; - } - bool Restore() { - if (!changed) - return false; + constexpr bool Change(bool newValue) { + if (changed) + return false; - changed = false; + previousValue = value; - value = previousValue; - return true; - } + changed = true; + value = newValue; + return true; + } + constexpr bool Restore(bool noValChange = false) { + if (!changed) + return false; + changed = false; + + if (noValChange) { + previousValue = value; + return true; + } + value = previousValue; + return true; + } private: - bool changed; + bool previousValue = false; + bool changed = false; + + static std::set instances; +}; +class KeyBindOption : public Option { +public: + static bool wasAnyKeyPressed; + + KeyBindOption(int keyCode) : keyCode(keyCode) { instances.insert(this); }; + ~KeyBindOption() { instances.erase(this); } + static std::set GetInstances(); + + const char* ToString() { + if (const auto it = std::ranges::find(keyMap, keyCode, &Key::code); it != keyMap.end()) + return it->name.data(); + return "NONE"; + } + constexpr int GetKeyBind() const { return keyCode; } + void ChangeKeyBind(int newKeyBind) { keyCode = newKeyBind; } + + bool SetToPressedKey() { + if (ImGui::IsKeyPressed(ImGuiKey_Escape)) { + ChangeKeyBind(VK_NONE); + return true; + } else if (!Utils::are_same(ImGui::GetIO().MouseWheel, 0.0f)) { + ChangeKeyBind(ImGui::GetIO().MouseWheel < 0.0f ? VK_MWHEELDOWN : VK_MWHEELUP); + return true; + } else if (GetKeyState(VK_LSHIFT) & 0x8000) { + ChangeKeyBind(VK_LSHIFT); + return true; + } else if (GetKeyState(VK_LMENU) & 0x8000) { + ChangeKeyBind(VK_LMENU); + return true; + } else if (GetKeyState(VK_LCONTROL) & 0x8000) { + ChangeKeyBind(VK_LCONTROL); + return true; + } else if (GetKeyState(VK_XBUTTON1) & 0x8000) { + ChangeKeyBind(VK_XBUTTON1); + return true; + } else if (GetKeyState(VK_XBUTTON2) & 0x8000) { + ChangeKeyBind(VK_XBUTTON2); + return true; + } + + for (int i = 0; i < IM_ARRAYSIZE(ImGui::GetIO().MouseDown); ++i) { + if (ImGui::IsMouseClicked(i)) { + ChangeKeyBind(i + 1); + return true; + } + } + + for (int i = ImGuiKey_NamedKey_BEGIN; i < ImGuiKey_NamedKey_END; ++i) { + if (!ImGui::IsKeyPressed(static_cast(i))) + continue; + + if (const auto it = std::ranges::find(keyMap, i, &Key::imGuiCode); it != keyMap.end()) { + ChangeKeyBind(it->code); + // Treat AltGr as RALT + if (GetKeyBind() == VK_LCONTROL && ImGui::IsKeyPressed(static_cast(VK_RMENU))) + ChangeKeyBind(VK_RMENU); + return true; + } + } + return false; + } +private: + int keyCode = 0; + static constexpr auto keyMap = std::to_array({ + { "'", VK_OEM_7, ImGuiKey_Apostrophe }, + { ",", VK_OEM_COMMA, ImGuiKey_Comma }, + { "-", VK_OEM_MINUS, ImGuiKey_Minus }, + { ".", VK_OEM_PERIOD, ImGuiKey_Period }, + { "/", VK_OEM_2, ImGuiKey_Slash }, + { "0", '0', ImGuiKey_0 }, + { "1", '1', ImGuiKey_1 }, + { "2", '2', ImGuiKey_2 }, + { "3", '3', ImGuiKey_3 }, + { "4", '4', ImGuiKey_4 }, + { "5", '5', ImGuiKey_5 }, + { "6", '6', ImGuiKey_6 }, + { "7", '7', ImGuiKey_7 }, + { "8", '8', ImGuiKey_8 }, + { "9", '9', ImGuiKey_9 }, + { ";", VK_OEM_1, ImGuiKey_Semicolon }, + { "=", VK_OEM_PLUS, ImGuiKey_Equal }, + { "A", 'A', ImGuiKey_A }, + { "ADD", VK_ADD, ImGuiKey_KeypadAdd }, + { "B", 'B', ImGuiKey_B }, + { "BACKSPACE", VK_BACK, ImGuiKey_Backspace }, + { "C", 'C', ImGuiKey_C }, + { "CAPSLOCK", VK_CAPITAL, ImGuiKey_CapsLock }, + { "D", 'D', ImGuiKey_D }, + { "DECIMAL", VK_DECIMAL, ImGuiKey_KeypadDecimal }, + { "DELETE", VK_DELETE, ImGuiKey_Delete }, + { "DIVIDE", VK_DIVIDE, ImGuiKey_KeypadDivide }, + { "DOWN", VK_DOWN, ImGuiKey_DownArrow }, + { "E", 'E', ImGuiKey_E }, + { "END", VK_END, ImGuiKey_End }, + { "ENTER", VK_RETURN, ImGuiKey_Enter }, + { "F", 'F', ImGuiKey_F }, + { "F1", VK_F1, ImGuiKey_F1 }, + { "F10", VK_F10, ImGuiKey_F10 }, + { "F11", VK_F11, ImGuiKey_F11 }, + { "F12", VK_F12, ImGuiKey_F12 }, + { "F2", VK_F2, ImGuiKey_F2 }, + { "F3", VK_F3, ImGuiKey_F3 }, + { "F4", VK_F4, ImGuiKey_F4 }, + { "F5", VK_F5, ImGuiKey_F5 }, + { "F6", VK_F6, ImGuiKey_F6 }, + { "F7", VK_F7, ImGuiKey_F7 }, + { "F8", VK_F8, ImGuiKey_F8 }, + { "F9", VK_F9, ImGuiKey_F9 }, + { "G", 'G', ImGuiKey_G }, + { "H", 'H', ImGuiKey_H }, + { "HOME", VK_HOME, ImGuiKey_Home }, + { "I", 'I', ImGuiKey_I }, + { "INSERT", VK_INSERT, ImGuiKey_Insert }, + { "J", 'J', ImGuiKey_J }, + { "K", 'K', ImGuiKey_K }, + { "L", 'L', ImGuiKey_L }, + { "LALT", VK_LMENU, ImGuiKey_LeftAlt }, + { "LCTRL", VK_LCONTROL, ImGuiKey_LeftCtrl }, + { "LEFT", VK_LEFT, ImGuiKey_LeftArrow }, + { "LSHIFT", VK_LSHIFT, ImGuiKey_LeftShift }, + { "M", 'M', ImGuiKey_M }, + { "MOUSE1", VK_LBUTTON, ImGuiKey_MouseLeft }, + { "MOUSE2", VK_RBUTTON, ImGuiKey_MouseRight }, + { "MOUSE3", VK_MBUTTON, ImGuiKey_MouseMiddle }, + { "MOUSE4", VK_XBUTTON1, ImGuiKey_MouseX1 }, + { "MOUSE5", VK_XBUTTON2, ImGuiKey_MouseX2 }, + { "MULTIPLY", VK_MULTIPLY, ImGuiKey_KeypadMultiply }, + { "MWHEEL_DOWN", VK_MWHEELDOWN, ImGuiKey_MouseWheelY }, + { "MWHEEL_UP", VK_MWHEELUP, ImGuiKey_MouseWheelY }, + { "N", 'N', ImGuiKey_N }, + { "NONE", VK_NONE, ImGuiKey_None }, + { "NUMPAD_0", VK_NUMPAD0, ImGuiKey_Keypad0 }, + { "NUMPAD_1", VK_NUMPAD1, ImGuiKey_Keypad1 }, + { "NUMPAD_2", VK_NUMPAD2, ImGuiKey_Keypad2 }, + { "NUMPAD_3", VK_NUMPAD3, ImGuiKey_Keypad3 }, + { "NUMPAD_4", VK_NUMPAD4, ImGuiKey_Keypad4 }, + { "NUMPAD_5", VK_NUMPAD5, ImGuiKey_Keypad5 }, + { "NUMPAD_6", VK_NUMPAD6, ImGuiKey_Keypad6 }, + { "NUMPAD_7", VK_NUMPAD7, ImGuiKey_Keypad7 }, + { "NUMPAD_8", VK_NUMPAD8, ImGuiKey_Keypad8 }, + { "NUMPAD_9", VK_NUMPAD9, ImGuiKey_Keypad9 }, + { "O", 'O', ImGuiKey_O }, + { "P", 'P', ImGuiKey_P }, + { "PAGE_DOWN", VK_NEXT, ImGuiKey_PageDown }, + { "PAGE_UP", VK_PRIOR, ImGuiKey_PageUp }, + { "Q", 'Q', ImGuiKey_Q }, + { "R", 'R', ImGuiKey_R }, + { "RALT", VK_RMENU, ImGuiKey_RightAlt }, + { "RCTRL", VK_RCONTROL, ImGuiKey_RightCtrl }, + { "RIGHT", VK_RIGHT, ImGuiKey_RightArrow }, + { "RSHIFT", VK_RSHIFT, ImGuiKey_RightShift }, + { "S", 'S', ImGuiKey_S }, + { "SPACE", VK_SPACE, ImGuiKey_Space }, + { "SUBTRACT", VK_SUBTRACT, ImGuiKey_KeypadSubtract }, + { "T", 'T', ImGuiKey_T }, + { "TAB", VK_TAB, ImGuiKey_Tab }, + { "U", 'U', ImGuiKey_U }, + { "UP", VK_UP, ImGuiKey_UpArrow }, + { "V", 'V', ImGuiKey_V }, + { "W", 'W', ImGuiKey_W }, + { "X", 'X', ImGuiKey_X }, + { "Y", 'Y', ImGuiKey_Y }, + { "Z", 'Z', ImGuiKey_Z }, + { "[", VK_OEM_4, ImGuiKey_LeftBracket }, + { "\\", VK_OEM_5, ImGuiKey_Backslash }, + { "]", VK_OEM_6, ImGuiKey_RightBracket }, + { "`", VK_OEM_3, ImGuiKey_GraveAccent } + }); + + static std::set instances; }; namespace Core { diff --git a/DL2GameOverhaulScript/source/game_classes.cpp b/DL2GameOverhaulScript/source/game_classes.cpp index 151c5bb..fc16af2 100644 --- a/DL2GameOverhaulScript/source/game_classes.cpp +++ b/DL2GameOverhaulScript/source/game_classes.cpp @@ -66,7 +66,7 @@ namespace GamePH { static DWORD64(*pCalculateFreeCamCollision)(LPVOID pFreeCamera, float* finalPos) = nullptr; static DWORD64(*oCalculateFreeCamCollision)(LPVOID pFreeCamera, float* finalPos) = nullptr; DWORD64 detourCalculateFreeCamCollision(LPVOID pFreeCamera, float* finalPos) { - if (!Menu::Camera::freeCamEnabled.value && !Menu::Camera::disablePhotoModeLimitsEnabled.value) + if (!Menu::Camera::freeCam.IsEnabled() && !Menu::Camera::disablePhotoModeLimits.IsEnabled()) return oCalculateFreeCamCollision(pFreeCamera, finalPos); return 0; @@ -89,7 +89,7 @@ namespace GamePH { static void(*pLifeSetHealth)(float* pLifeHealth, float health) = nullptr; static void(*oLifeSetHealth)(float* pLifeHealth, float health) = nullptr; void detourLifeSetHealth(float* pLifeHealth, float health) { - if (!Menu::Player::godModeEnabled.value) + if (!Menu::Player::godMode.IsEnabled()) return oLifeSetHealth(pLifeHealth, health); GamePH::PlayerHealthModule* playerHealthModule = GamePH::PlayerHealthModule::Get(); @@ -122,9 +122,9 @@ namespace GamePH { static void(*pTogglePhotoMode)(LPVOID guiPhotoModeData, bool enabled) = nullptr; static void(*oTogglePhotoMode)(LPVOID guiPhotoModeData, bool enabled) = nullptr; void detourTogglePhotoMode(LPVOID guiPhotoModeData, bool enabled) { - Menu::Camera::photoModeEnabled.value = enabled; + Menu::Camera::photoMode.Set(enabled); - if (!Menu::Camera::freeCamEnabled.value) + if (!Menu::Camera::freeCam.IsEnabled()) return oTogglePhotoMode(guiPhotoModeData, enabled); GamePH::GameDI_PH* pGameDI_PH = GamePH::GameDI_PH::Get(); if (!pGameDI_PH) @@ -162,37 +162,37 @@ namespace GamePH { gen_TPPModel* pgen_TPPModel = gen_TPPModel::Get(); if (pgen_TPPModel) { - if (Menu::Camera::photoModeEnabled.previousValue != Menu::Camera::photoModeEnabled.value && !Menu::Camera::photoModeEnabled.value) { - Menu::Camera::tpUseTPPModelEnabled.previousValue = !Menu::Camera::tpUseTPPModelEnabled.value; - Menu::Camera::thirdPersonCameraEnabled.previousValue = Menu::Camera::thirdPersonCameraEnabled.value; + if (Menu::Camera::photoMode.HasChangedTo(false)) { + Menu::Camera::tpUseTPPModel.SetPreviousVal(!Menu::Camera::tpUseTPPModel.IsEnabled()); + Menu::Camera::thirdPersonCamera.SetPreviousVal(Menu::Camera::thirdPersonCamera.IsEnabled()); } - if (!Menu::Camera::photoModeEnabled.value && !Menu::Camera::freeCamEnabled.value) { - if ((Menu::Camera::tpUseTPPModelEnabled.previousValue != Menu::Camera::tpUseTPPModelEnabled.value && !Menu::Camera::tpUseTPPModelEnabled.value && Menu::Camera::thirdPersonCameraEnabled.value) || (Menu::Camera::thirdPersonCameraEnabled.previousValue != Menu::Camera::thirdPersonCameraEnabled.value && !Menu::Camera::thirdPersonCameraEnabled.value)) { + if (!Menu::Camera::photoMode.IsEnabled() && !Menu::Camera::freeCam.IsEnabled()) { + if ((Menu::Camera::tpUseTPPModel.HasChangedTo(false) && Menu::Camera::thirdPersonCamera.IsEnabled()) || (Menu::Camera::thirdPersonCamera.HasChangedTo(false))) { pgen_TPPModel->enableTPPModel2 = true; pgen_TPPModel->enableTPPModel1 = true; } - ShowTPPModel(Menu::Camera::tpUseTPPModelEnabled.value && Menu::Camera::thirdPersonCameraEnabled.value); - if (Menu::Camera::tpUseTPPModelEnabled.previousValue == Menu::Camera::tpUseTPPModelEnabled.value && Menu::Camera::thirdPersonCameraEnabled.previousValue == Menu::Camera::thirdPersonCameraEnabled.value && (Menu::Camera::tpUseTPPModelEnabled.value && Menu::Camera::thirdPersonCameraEnabled.value)) { + ShowTPPModel(Menu::Camera::tpUseTPPModel.IsEnabled() && Menu::Camera::thirdPersonCamera.IsEnabled()); + if (!Menu::Camera::tpUseTPPModel.HasChanged() && !Menu::Camera::thirdPersonCamera.HasChanged() && (Menu::Camera::tpUseTPPModel.IsEnabled() && Menu::Camera::thirdPersonCamera.IsEnabled())) { pgen_TPPModel->enableTPPModel2 = false; pgen_TPPModel->enableTPPModel1 = false; } - Menu::Camera::tpUseTPPModelEnabled.previousValue = Menu::Camera::tpUseTPPModelEnabled.value; - Menu::Camera::thirdPersonCameraEnabled.previousValue = Menu::Camera::thirdPersonCameraEnabled.value; + Menu::Camera::tpUseTPPModel.SetPreviousVal(Menu::Camera::tpUseTPPModel.IsEnabled()); + Menu::Camera::thirdPersonCamera.SetPreviousVal(Menu::Camera::thirdPersonCamera.IsEnabled()); } - if (Menu::Camera::photoModeEnabled.previousValue != Menu::Camera::photoModeEnabled.value && Menu::Camera::photoModeEnabled.value) { + if (Menu::Camera::photoMode.HasChangedTo(true)) { pgen_TPPModel->enableTPPModel2 = false; pgen_TPPModel->enableTPPModel1 = false; } - else if (Menu::Camera::photoModeEnabled.previousValue == Menu::Camera::photoModeEnabled.value && Menu::Camera::photoModeEnabled.value) { - ShowTPPModel(Menu::Camera::photoModeEnabled.value); + else if (!Menu::Camera::photoMode.HasChanged() && Menu::Camera::photoMode.IsEnabled()) { + ShowTPPModel(Menu::Camera::photoMode.IsEnabled()); } - Menu::Camera::photoModeEnabled.previousValue = Menu::Camera::photoModeEnabled.value; + Menu::Camera::photoMode.SetPreviousVal(Menu::Camera::photoMode.IsEnabled()); } - if (!Menu::Camera::thirdPersonCameraEnabled.value || Menu::Camera::photoModeEnabled.value || Menu::Camera::freeCamEnabled.value || !pos) + if (!Menu::Camera::thirdPersonCamera.IsEnabled() || Menu::Camera::photoMode.IsEnabled() || Menu::Camera::freeCam.IsEnabled() || !pos) return oMoveCameraFromForwardUpPos(pCBaseCamera, a3, a4, pos); CameraFPPDI* viewCam = static_cast(iLevel->GetViewCamera()); diff --git a/DL2GameOverhaulScript/source/menu/camera.cpp b/DL2GameOverhaulScript/source/menu/camera.cpp index cefe004..79fb8bc 100644 --- a/DL2GameOverhaulScript/source/menu/camera.cpp +++ b/DL2GameOverhaulScript/source/menu/camera.cpp @@ -1,4 +1,5 @@ #include +#include #include "..\sigscan\offsets.h" #include "..\game_classes.h" #include "..\core.h" @@ -8,30 +9,25 @@ namespace Menu { namespace Camera { int FOV = 57; - SMART_BOOL photoModeEnabled; + Option photoMode{}; - SMART_BOOL freeCamEnabled{}; - KeyBindToggle freeCamToggleKey = KeyBindToggle(KeyBind::F3); + KeyBindOption freeCam{ VK_F3 }; float freeCamSpeed = 2.0f; - bool teleportPlayerToCameraEnabled = false; - KeyBindToggle teleportPlayerToCameraToggleKey = KeyBindToggle(KeyBind::F4); + KeyBindOption teleportPlayerToCamera{ VK_F4 }; - SMART_BOOL thirdPersonCameraEnabled; - KeyBindToggle thirdPersonCameraToggleKey = KeyBindToggle(KeyBind::F1); - SMART_BOOL tpUseTPPModelEnabled; - KeyBindToggle tpUseTPPModelToggleKey = KeyBindToggle(KeyBind::F2); + KeyBindOption thirdPersonCamera{ VK_F1 }; + KeyBindOption tpUseTPPModel{ VK_F2 }; float tpDistanceBehindPlayer = 2.0f; float tpHeightAbovePlayer = 1.35f; - SMART_BOOL disablePhotoModeLimitsEnabled{}; - SMART_BOOL disableSafezoneFOVReductionEnabled{}; + Option disablePhotoModeLimits{}; + Option disableSafezoneFOVReduction{}; static const int baseFOV = 57; static const float baseSafezoneFOVReduction = -10.0f; - static LPVOID previousViewCam = nullptr; static void UpdateFOVWhileMenuClosed() { - if (Menu::isOpen) + if (Menu::menuToggle.IsEnabled()) return; Engine::CVideoSettings* videoSettings = Engine::CVideoSettings::Get(); @@ -41,7 +37,7 @@ namespace Menu { Menu::Camera::FOV = static_cast(videoSettings->extraFOV) + Menu::Camera::baseFOV; } static void FreeCamUpdate() { - if (photoModeEnabled.value) + if (photoMode.IsEnabled()) return; GamePH::LevelDI* iLevel = GamePH::LevelDI::Get(); if (!iLevel || !iLevel->IsLoaded()) @@ -56,7 +52,7 @@ namespace Menu { if (!pFreeCam) return; - if (freeCamEnabled.value) { + if (freeCam.IsEnabled()) { if (viewCam == pFreeCam) { pFreeCam->enableSpeedMultiplier1 = true; pFreeCam->speedMultiplier = freeCamSpeed; @@ -73,7 +69,7 @@ namespace Menu { GamePH::ShowTPPModel(true); } else { - if (freeCamEnabled.previousValue) { + if (freeCam.WasEnabled()) { pFreeCam->enableSpeedMultiplier1 = false; pFreeCam->speedMultiplier = 0.1f; } @@ -91,25 +87,25 @@ namespace Menu { if (!GamePH::PlayerVariables::gotPlayerVars) return; - if (disableSafezoneFOVReductionEnabled.value) { + if (disableSafezoneFOVReduction.IsEnabled()) { GamePH::PlayerVariables::ChangePlayerVar("CameraDefaultFOVReduction", 0.0f); - disableSafezoneFOVReductionEnabled.previousValue = true; - } else if (disableSafezoneFOVReductionEnabled.previousValue != disableSafezoneFOVReductionEnabled.value) { - disableSafezoneFOVReductionEnabled.previousValue = false; + disableSafezoneFOVReduction.Change(true); + } else if (disableSafezoneFOVReduction.WasEnabled()) { + disableSafezoneFOVReduction.Restore(true); GamePH::PlayerVariables::ChangePlayerVar("CameraDefaultFOVReduction", baseSafezoneFOVReduction); } } void Update() { - if (photoModeEnabled.value) - freeCamEnabled.Change(false); + if (photoMode.IsEnabled()) + freeCam.Change(false); else - freeCamEnabled.Restore(); + freeCam.Restore(); - if (freeCamEnabled.value) - disablePhotoModeLimitsEnabled.Change(true); + if (freeCam.IsEnabled()) + disablePhotoModeLimits.Change(true); else - disablePhotoModeLimitsEnabled.Restore(); + disablePhotoModeLimits.Restore(); UpdateFOVWhileMenuClosed(); FreeCamUpdate(); @@ -118,26 +114,26 @@ namespace Menu { void Render() { ImGui::SeparatorText("Free Camera"); - ImGui::BeginDisabled(photoModeEnabled.value); { - ImGui::Checkbox("Enabled##FreeCam", &freeCamEnabled.value); + ImGui::BeginDisabled(photoMode.IsEnabled()); { + ImGui::Checkbox("Enabled##FreeCam", &freeCam.value); ImGui::EndDisabled(); } - ImGui::Hotkey("##FreeCamToggleKey", freeCamToggleKey); + ImGui::Hotkey("##FreeCamToggleKey", freeCam); ImGui::SliderFloat("Speed##FreeCam", &freeCamSpeed, 0.0f, 100.0f); - ImGui::Checkbox("Teleport Player to Camera", &teleportPlayerToCameraEnabled); - ImGui::Hotkey("##TeleportPlayerToCamToggleKey", teleportPlayerToCameraToggleKey); + ImGui::Checkbox("Teleport Player to Camera", &teleportPlayerToCamera.value); + ImGui::Hotkey("##TeleportPlayerToCamToggleKey", teleportPlayerToCamera); ImGui::SeparatorText("Third Person Camera"); - ImGui::BeginDisabled(freeCamEnabled.value || photoModeEnabled.value); { - ImGui::Checkbox("Enabled##ThirdPerson", &thirdPersonCameraEnabled.value); + ImGui::BeginDisabled(freeCam.IsEnabled() || photoMode.IsEnabled()); { + ImGui::Checkbox("Enabled##ThirdPerson", &thirdPersonCamera.value); ImGui::EndDisabled(); } - ImGui::Hotkey("##ThirdPersonToggleKey", thirdPersonCameraToggleKey); - ImGui::BeginDisabled(freeCamEnabled.value || photoModeEnabled.value); { - ImGui::Checkbox("Use Third Person Player (TPP) Model", &tpUseTPPModelEnabled.value); + ImGui::Hotkey("##ThirdPersonToggleKey", thirdPersonCamera); + ImGui::BeginDisabled(freeCam.IsEnabled() || photoMode.IsEnabled()); { + ImGui::Checkbox("Use Third Person Player (TPP) Model", &tpUseTPPModel.value); ImGui::EndDisabled(); } - ImGui::Hotkey("##TPPModelToggleKey", tpUseTPPModelToggleKey); + ImGui::Hotkey("##TPPModelToggleKey", tpUseTPPModel); ImGui::SliderFloat("Distance behind player", &tpDistanceBehindPlayer, 1.0f, 10.0f); ImGui::SliderFloat("Height above player", &tpHeightAbovePlayer, 1.0f, 3.0f); @@ -150,11 +146,11 @@ namespace Menu { FOV = static_cast(pCVideoSettings->extraFOV) + Menu::Camera::baseFOV; ImGui::EndDisabled(); } - ImGui::BeginDisabled(freeCamEnabled.value); { - ImGui::Checkbox("Disable Photo Mode Limits", &disablePhotoModeLimitsEnabled.value); + ImGui::BeginDisabled(freeCam.IsEnabled()); { + ImGui::Checkbox("Disable Photo Mode Limits", &disablePhotoModeLimits.value); ImGui::EndDisabled(); } - ImGui::Checkbox("Disable Safezone FOV Reduction", &disableSafezoneFOVReductionEnabled.value); + ImGui::Checkbox("Disable Safezone FOV Reduction", &disableSafezoneFOVReduction.value); } } } \ No newline at end of file diff --git a/DL2GameOverhaulScript/source/menu/camera.h b/DL2GameOverhaulScript/source/menu/camera.h index a05d844..f3b4a15 100644 --- a/DL2GameOverhaulScript/source/menu/camera.h +++ b/DL2GameOverhaulScript/source/menu/camera.h @@ -1,28 +1,23 @@ #pragma once -#include #include "..\core.h" namespace Menu { namespace Camera { extern int FOV; - extern SMART_BOOL photoModeEnabled; + extern Option photoMode; - extern SMART_BOOL freeCamEnabled; - extern KeyBindToggle freeCamToggleKey; + extern KeyBindOption freeCam; extern float freeCamSpeed; - extern bool teleportPlayerToCameraEnabled; - extern KeyBindToggle teleportPlayerToCameraToggleKey; + extern KeyBindOption teleportPlayerToCamera; - extern SMART_BOOL thirdPersonCameraEnabled; - extern KeyBindToggle thirdPersonCameraToggleKey; - extern SMART_BOOL tpUseTPPModelEnabled; - extern KeyBindToggle tpUseTPPModelToggleKey; + extern KeyBindOption thirdPersonCamera; + extern KeyBindOption tpUseTPPModel; extern float tpDistanceBehindPlayer; extern float tpHeightAbovePlayer; - extern SMART_BOOL disablePhotoModeLimitsEnabled; - extern SMART_BOOL disableSafezoneFOVReductionEnabled; + extern Option disablePhotoModeLimits; + extern Option disableSafezoneFOVReduction; extern void Update(); extern void Render(); diff --git a/DL2GameOverhaulScript/source/menu/menu.cpp b/DL2GameOverhaulScript/source/menu/menu.cpp index 3dd371a..bd3cf87 100644 --- a/DL2GameOverhaulScript/source/menu/menu.cpp +++ b/DL2GameOverhaulScript/source/menu/menu.cpp @@ -1,5 +1,6 @@ #include #include +#include "menu.h" #include "camera.h" #include "player.h" #include "world.h" @@ -9,8 +10,7 @@ namespace Menu { static const ImVec2 minWndSize = ImVec2(0.0f, 0.0f); static const ImVec2 maxWndSize = ImVec2(900.0f, 675.0f); - KeyBindToggle toggleKey = KeyBindToggle(KeyBind::F5); - bool isOpen = false; + KeyBindOption menuToggle = KeyBindOption(VK_F5); float transparency = 99.0f; void Render() { @@ -18,7 +18,7 @@ namespace Menu { style->Colors[ImGuiCol_WindowBg] = ImVec4(style->Colors[ImGuiCol_WindowBg].x, style->Colors[ImGuiCol_WindowBg].y, style->Colors[ImGuiCol_WindowBg].z, static_cast(transparency) / 100.0f); ImGui::SetNextWindowSizeConstraints(minWndSize, maxWndSize); - ImGui::Begin("EGameTools", &Menu::isOpen, windowFlags); { + ImGui::Begin("EGameTools", &menuToggle.value, windowFlags); { if (ImGui::BeginTabBar("##MainTabBar")) { if (ImGui::BeginTabItem("Player")) { Menu::Player::Render(); @@ -37,7 +37,7 @@ namespace Menu { ImGui::Separator(); - ImGui::Hotkey("Menu Toggle Key", toggleKey); + ImGui::Hotkey("Menu Toggle Key", menuToggle); ImGui::SliderFloat("Menu Transparency", &transparency, 0.0f, 100.0f, "%.1f%%", ImGuiSliderFlags_AlwaysClamp); ImGui::End(); } diff --git a/DL2GameOverhaulScript/source/menu/menu.h b/DL2GameOverhaulScript/source/menu/menu.h index 593ca48..993c036 100644 --- a/DL2GameOverhaulScript/source/menu/menu.h +++ b/DL2GameOverhaulScript/source/menu/menu.h @@ -1,12 +1,11 @@ #pragma once -#include +#include "..\core.h" #include "camera.h" #include "player.h" #include "world.h" namespace Menu { - extern KeyBindToggle toggleKey; - extern bool isOpen; + extern KeyBindOption menuToggle; extern float transparency; extern void Render(); diff --git a/DL2GameOverhaulScript/source/menu/player.cpp b/DL2GameOverhaulScript/source/menu/player.cpp index 56f73f6..711b4e1 100644 --- a/DL2GameOverhaulScript/source/menu/player.cpp +++ b/DL2GameOverhaulScript/source/menu/player.cpp @@ -5995,11 +5995,9 @@ namespace Menu { 0x41, 0x75, 0x64, 0x69, 0x6F, 0x45, 0x76, 0x65, 0x6E, 0x74, 0x44, 0x69, 0x73, 0x74, 0x61, 0x6E, 0x63, 0x65, 0x22, 0x2C, 0x20, 0x22, 0x38, 0x22, 0x29, 0x3B, 0x0D, 0x0A, 0x7D, 0x0D, 0x0A }; - SMART_BOOL godModeEnabled{}; - KeyBindToggle godModeToggleKey = KeyBindToggle(KeyBind::F6); - SMART_BOOL freezePlayerEnabled{}; - KeyBindToggle freezePlayerToggleKey = KeyBindToggle(KeyBind::F7); - bool playerVariablesEnabled = false; + KeyBindOption godMode{ VK_F6 }; + KeyBindOption freezePlayer{ VK_F7 }; + Option playerVariables{}; std::string saveSCRPath{}; std::string loadSCRFilePath{}; @@ -6169,14 +6167,14 @@ namespace Menu { if (!playerCharacter) return; - if (Menu::Player::freezePlayerEnabled.value) { + if (freezePlayer.IsEnabled()) { playerCharacter->FreezeCharacter(); return; } Engine::CBulletPhysicsCharacter::posBeforeFreeze = playerCharacter->playerPos; - if (!Menu::Camera::freeCamEnabled.value || !Menu::Camera::teleportPlayerToCameraEnabled) + if (!Menu::Camera::freeCam.IsEnabled() || !Menu::Camera::teleportPlayerToCamera.IsEnabled()) return; GamePH::FreeCamera* freeCam = GamePH::FreeCamera::Get(); @@ -6192,7 +6190,7 @@ namespace Menu { } static void UpdatePlayerVars() { - if (!playerVariablesEnabled) + if (!playerVariables.IsEnabled()) return; auto bgn = GamePH::PlayerVariables::playerVars.begin(); @@ -6219,15 +6217,15 @@ namespace Menu { } void Update() { - if (Menu::Camera::freeCamEnabled.value) - godModeEnabled.Change(true); + if (Menu::Camera::freeCam.IsEnabled()) + godMode.Change(true); else - godModeEnabled.Restore(); + godMode.Restore(); - if (Menu::Camera::freeCamEnabled.value) - freezePlayerEnabled.Change(!Menu::Camera::teleportPlayerToCameraEnabled); + if (Menu::Camera::freeCam.IsEnabled()) + freezePlayer.Change(!Menu::Camera::teleportPlayerToCamera.IsEnabled()); else - freezePlayerEnabled.Restore(); + freezePlayer.Restore(); PlayerPositionUpdate(); UpdatePlayerVars(); @@ -6235,21 +6233,21 @@ namespace Menu { void Render() { ImGui::SeparatorText("Misc"); - ImGui::BeginDisabled(Menu::Camera::freeCamEnabled.value); { - ImGui::Checkbox("God Mode", &godModeEnabled.value); + ImGui::BeginDisabled(Menu::Camera::freeCam.IsEnabled()); { + ImGui::Checkbox("God Mode", &godMode.value); ImGui::EndDisabled(); } - ImGui::Hotkey("##GodModeToggleKey", godModeToggleKey); + ImGui::Hotkey("##GodModeToggleKey", godMode); ImGui::SameLine(); - ImGui::BeginDisabled(!Engine::CBulletPhysicsCharacter::Get() || Menu::Camera::freeCamEnabled.value); { - ImGui::Checkbox("Freeze Player", &freezePlayerEnabled.value); + ImGui::BeginDisabled(!Engine::CBulletPhysicsCharacter::Get() || Menu::Camera::freeCam.IsEnabled()); { + ImGui::Checkbox("Freeze Player", &freezePlayer.value); ImGui::EndDisabled(); } - ImGui::Hotkey("##FreezePlayerToggleKey", freezePlayerToggleKey); + ImGui::Hotkey("##FreezePlayerToggleKey", freezePlayer); ImGui::SeparatorText("Player Variables"); - ImGui::Checkbox("Enabled##PlayerVars", &playerVariablesEnabled); - if (!playerVariablesEnabled) + ImGui::Checkbox("Enabled##PlayerVars", &playerVariables.value); + if (!playerVariables.IsEnabled()) return; ImGui::BeginDisabled(!GamePH::PlayerVariables::gotPlayerVars); { diff --git a/DL2GameOverhaulScript/source/menu/player.h b/DL2GameOverhaulScript/source/menu/player.h index d34caae..7922972 100644 --- a/DL2GameOverhaulScript/source/menu/player.h +++ b/DL2GameOverhaulScript/source/menu/player.h @@ -1,15 +1,12 @@ #pragma once #include -#include #include "..\core.h" namespace Menu { namespace Player { - extern SMART_BOOL godModeEnabled; - extern KeyBindToggle godModeToggleKey; - extern SMART_BOOL freezePlayerEnabled; - extern KeyBindToggle freezePlayerToggleKey; - extern bool playerVariablesEnabled; + extern KeyBindOption godMode; + extern KeyBindOption freezePlayer; + extern Option playerVariables; extern std::string saveSCRPath; extern std::string loadSCRFilePath;