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