diff --git a/source/Minecraft.cpp b/source/Minecraft.cpp index a15cd12..e2d6750 100644 --- a/source/Minecraft.cpp +++ b/source/Minecraft.cpp @@ -420,7 +420,7 @@ void Minecraft::tickInput() #define MAX_ITEMS (C_MAX_HOTBAR_ITEMS - 2) #endif - if (Mouse::getEventButtonState() > 0) // @NOTE: Scroll up + if (Mouse::getEventButtonState() <= 0) // @NOTE: Scroll up { if (slot-- == 0) { @@ -498,9 +498,9 @@ void Minecraft::tickInput() if (getTimeMs() - field_2B4 <= 200) { - if (m_options.m_keyBinds[Options::DESTROY].value == keyCode && bPressed) + if (m_options.getKey(KM_DESTROY) == keyCode && bPressed) handleMouseClick(1); - if (m_options.m_keyBinds[Options::PLACE].value == keyCode && bPressed) + if (m_options.getKey(KM_PLACE) == keyCode && bPressed) handleMouseClick(2); } } @@ -513,7 +513,7 @@ void Minecraft::tickInput() if (!Mouse::isButtonDown(Mouse::ButtonType::LEFT) || bIsInGUI) goto label_12; } - else if (Keyboard::isKeyDown(m_options.m_keyBinds[Options::DESTROY].value)) + else if (Keyboard::isKeyDown(m_options.getKey(KM_DESTROY))) { goto label_12; } diff --git a/source/client/gui/screens/SelectWorldScreen.cpp b/source/client/gui/screens/SelectWorldScreen.cpp index 984da65..b3f5278 100644 --- a/source/client/gui/screens/SelectWorldScreen.cpp +++ b/source/client/gui/screens/SelectWorldScreen.cpp @@ -59,7 +59,7 @@ bool SelectWorldScreen::isInGameScreen() void SelectWorldScreen::keyPressed(int code) { #ifndef ORIGINAL_CODE - if (m_pMinecraft->m_options.m_keyBinds[Options::MENU_OK].value == code) + if (m_pMinecraft->m_options.getKey(KM_MENU_OK) == code) m_pWorldSelectionList->selectItem(m_pWorldSelectionList->getItemAtPosition(m_width / 2, m_height / 2), false); m_btnUnknown.field_36 = true; @@ -67,10 +67,10 @@ void SelectWorldScreen::keyPressed(int code) if (m_btnUnknown.field_36) { - if (m_pMinecraft->m_options.m_keyBinds[Options::LEFT].value == code) + if (m_pMinecraft->m_options.getKey(KM_LEFT) == code) m_pWorldSelectionList->stepLeft(); - if (m_pMinecraft->m_options.m_keyBinds[Options::RIGHT].value == code) + if (m_pMinecraft->m_options.getKey(KM_RIGHT) == code) m_pWorldSelectionList->stepRight(); } diff --git a/source/client/player/input/KeyboardInput.cpp b/source/client/player/input/KeyboardInput.cpp index bf0441c..6c25b04 100644 --- a/source/client/player/input/KeyboardInput.cpp +++ b/source/client/player/input/KeyboardInput.cpp @@ -32,12 +32,12 @@ void KeyboardInput::setKey(int keyCode, bool b) { int index = -1; - if (m_pOptions->m_keyBinds[0].value == keyCode) index = 0; - if (m_pOptions->m_keyBinds[2].value == keyCode) index = 1; - if (m_pOptions->m_keyBinds[1].value == keyCode) index = 2; - if (m_pOptions->m_keyBinds[3].value == keyCode) index = 3; - if (m_pOptions->m_keyBinds[4].value == keyCode) index = 4; - if (m_pOptions->m_keyBinds[9].value == keyCode) index = 5; + if (m_pOptions->getKey(KM_FORWARD) == keyCode) index = 0; + if (m_pOptions->getKey(KM_BACK) == keyCode) index = 1; + if (m_pOptions->getKey(KM_LEFT) == keyCode) index = 2; + if (m_pOptions->getKey(KM_RIGHT) == keyCode) index = 3; + if (m_pOptions->getKey(KM_JUMP) == keyCode) index = 4; + if (m_pOptions->getKey(KM_SNEAK) == keyCode) index = 5; if (index == -1) return; diff --git a/source/common/Options.cpp b/source/common/Options.cpp index e7e652a..72921c6 100644 --- a/source/common/Options.cpp +++ b/source/common/Options.cpp @@ -54,22 +54,22 @@ void Options::initDefaultValues() m_bServerVisibleDefault = true; m_bDebugText = false; - m_keyBinds[0] = KeyBind("key.forward", 'W'); - m_keyBinds[1] = KeyBind("key.left", 'A'); - m_keyBinds[2] = KeyBind("key.back", 'S'); - m_keyBinds[3] = KeyBind("key.right", 'D'); - m_keyBinds[4] = KeyBind("key.jump", ' '); - m_keyBinds[5] = KeyBind("key.inventory", 'E'); - m_keyBinds[6] = KeyBind("key.drop", 'Q'); - m_keyBinds[7] = KeyBind("key.chat", 'T'); - m_keyBinds[8] = KeyBind("key.fog", 'F'); - m_keyBinds[9] = KeyBind("key.sneak", '\n'); - m_keyBinds[10] = KeyBind("key.destroy", 'X'); - m_keyBinds[11] = KeyBind("key.place", 'C'); - m_keyBinds[12] = KeyBind("key.menu.next", '('); - m_keyBinds[13] = KeyBind("key.menu.previous", '&'); - m_keyBinds[14] = KeyBind("key.menu.ok", '\r'); - m_keyBinds[15] = KeyBind("key.menu.cancel", '\b'); + m_keyMappings[0] = KeyMapping("key.forward", 'W'); + m_keyMappings[1] = KeyMapping("key.left", 'A'); + m_keyMappings[2] = KeyMapping("key.back", 'S'); + m_keyMappings[3] = KeyMapping("key.right", 'D'); + m_keyMappings[4] = KeyMapping("key.jump", ' '); + m_keyMappings[5] = KeyMapping("key.inventory", 'E'); + m_keyMappings[6] = KeyMapping("key.drop", 'Q'); + m_keyMappings[7] = KeyMapping("key.chat", 'T'); + m_keyMappings[8] = KeyMapping("key.fog", 'F'); + m_keyMappings[9] = KeyMapping("key.sneak", '\n'); + m_keyMappings[10] = KeyMapping("key.destroy", 'X'); + m_keyMappings[11] = KeyMapping("key.place", 'C'); + m_keyMappings[12] = KeyMapping("key.menu.next", '('); + m_keyMappings[13] = KeyMapping("key.menu.previous", '&'); + m_keyMappings[14] = KeyMapping("key.menu.ok", '\r'); + m_keyMappings[15] = KeyMapping("key.menu.cancel", '\b'); #ifdef ORIGINAL_CODE m_rotY = 2; @@ -79,20 +79,20 @@ void Options::initDefaultValues() m_bFancyGraphics = 1; // keybind now reprograms some the keybinds. // For the restoration, we don't actually need them - m_keyBinds[0].value = AKEYCODE_DPAD_UP; - m_keyBinds[1].value = AKEYCODE_DPAD_LEFT; - m_keyBinds[2].value = AKEYCODE_DPAD_DOWN; - m_keyBinds[3].value = AKEYCODE_DPAD_RIGHT; - m_keyBinds[4].value = AKEYCODE_DPAD_CENTER; // lmao, how stupid. - m_keyBinds[10].value = AKEYCODE_BUTTON_L1; - m_keyBinds[11].value = AKEYCODE_BUTTON_R1; - m_keyBinds[12].value = AKEYCODE_DPAD_DOWN; - m_keyBinds[13].value = AKEYCODE_DPAD_UP; - m_keyBinds[14].value = AKEYCODE_DPAD_CENTER; - m_keyBinds[15].value = AKEYCODE_BACK; + m_keyMappings[0].value = AKEYCODE_DPAD_UP; + m_keyMappings[1].value = AKEYCODE_DPAD_LEFT; + m_keyMappings[2].value = AKEYCODE_DPAD_DOWN; + m_keyMappings[3].value = AKEYCODE_DPAD_RIGHT; + m_keyMappings[4].value = AKEYCODE_DPAD_CENTER; // lmao, how stupid. + m_keyMappings[10].value = AKEYCODE_BUTTON_L1; + m_keyMappings[11].value = AKEYCODE_BUTTON_R1; + m_keyMappings[12].value = AKEYCODE_DPAD_DOWN; + m_keyMappings[13].value = AKEYCODE_DPAD_UP; + m_keyMappings[14].value = AKEYCODE_DPAD_CENTER; + m_keyMappings[15].value = AKEYCODE_BACK; #ifndef ORIGINAL_CODE - m_keyBinds[9].value = AKEYCODE_SHIFT_LEFT; + m_keyMappings[9].value = AKEYCODE_SHIFT_LEFT; #endif } diff --git a/source/common/Options.hpp b/source/common/Options.hpp index 9c0d81d..261018c 100644 --- a/source/common/Options.hpp +++ b/source/common/Options.hpp @@ -13,6 +13,36 @@ #include #include +enum eKeyMappingIndex +{ + KM_FORWARD, + KM_LEFT, + KM_BACK, + KM_RIGHT, + KM_JUMP, + KM_INVENTORY, + KM_DROP, + KM_CHAT, + KM_FOG, + KM_SNEAK, + KM_DESTROY, + KM_PLACE, + KM_MENU_NEXT, + KM_MENU_PREVIOUS, + KM_MENU_OK, + KM_MENU_CANCEL, + KM_COUNT, +}; + +struct KeyMapping +{ + std::string key; + int value; + + KeyMapping() {} + KeyMapping(const char* keyName, int keyCode) : key(keyName), value(keyCode) {} +}; + class Options { public: @@ -34,34 +64,6 @@ public: static std::string saveInt(int i); public: - enum KeyBindIndex - { - FORWARD, - LEFT, - BACK, - RIGHT, - JUMP, - INVENTORY, - DROP, - CHAT, - FOG, - SNEAK, - DESTROY, - PLACE, - MENU_NEXT, - MENU_PREVIOUS, - MENU_OK, - MENU_CANCEL, - }; - - struct KeyBind { - std::string key; - int value; - - KeyBind() {} - KeyBind(const char* keyName, int keyCode) : key(keyName), value(keyCode) {} - }; - struct Option { bool field_0; @@ -85,6 +87,11 @@ public: static Option GUI_SCALE; }; + int getKey(eKeyMappingIndex idx) + { + return m_keyMappings[idx].value; + } + public: float field_0; float m_fMasterVolume; @@ -98,8 +105,7 @@ public: bool m_bAmbientOcclusion; uint8_t field_19; std::string field_1C; - KeyBind m_keyBinds[16]; - + KeyMapping m_keyMappings[KM_COUNT]; int field_238; bool m_bDontRenderGui; bool m_bThirdPerson;