From 9bdde40f3f36828d446f349e0229bf95000c7d89 Mon Sep 17 00:00:00 2001 From: TheBrokenRail Date: Sun, 29 Sep 2024 00:49:03 -0400 Subject: [PATCH] Click Buttons On Mouse Down --- docs/CHANGELOG.md | 1 + launcher/src/client/available-feature-flags | 3 +- mods/src/misc/ui.cpp | 43 +++++++++++++++++++++ symbols/src/game/Minecraft.def | 6 ++- symbols/src/gui/components/Button.def | 4 ++ symbols/src/gui/screens/Screen.def | 2 + 6 files changed, 56 insertions(+), 3 deletions(-) diff --git a/docs/CHANGELOG.md b/docs/CHANGELOG.md index 073570429a..4bcf634147 100644 --- a/docs/CHANGELOG.md +++ b/docs/CHANGELOG.md @@ -45,6 +45,7 @@ * `Use Updated Title` (Enabled By Default) * `Hide Block Outline When GUI Is Hidden` (Enabled By Default) * `Fix Crash When Generating Certain Seed` (Enabled By Default) + * `Click Buttons On Mouse Down` (Enabled By Default) * Existing Functionality (All Enabled By Default) * `Fix Screen Rendering When Hiding HUD` * `Sanitize Usernames` diff --git a/launcher/src/client/available-feature-flags b/launcher/src/client/available-feature-flags index f100b2cf08..b12436da7d 100644 --- a/launcher/src/client/available-feature-flags +++ b/launcher/src/client/available-feature-flags @@ -107,4 +107,5 @@ TRUE Allow High-Resolution Title TRUE Improved Classic Title Positioning TRUE Use Updated Title TRUE Hide Block Outline When GUI Is Hidden -TRUE Fix Crash When Generating Certain Seed \ No newline at end of file +TRUE Fix Crash When Generating Certain Seed +TRUE Click Buttons On Mouse Down \ No newline at end of file diff --git a/mods/src/misc/ui.cpp b/mods/src/misc/ui.cpp index 1dd4f9b578..df08d6183a 100644 --- a/mods/src/misc/ui.cpp +++ b/mods/src/misc/ui.cpp @@ -199,6 +199,41 @@ static void PauseScreen_init_injection(PauseScreen_init_t original, PauseScreen } } +// Click Buttons On Mouse Down +static void Screen_mouseClicked_injection(__attribute__((unused)) Screen_mouseClicked_t original, Screen *self, int x, int y, const int param_1) { + if (param_1 == 1) { + for (Button *button : self->rendered_buttons) { + if (button->clicked(self->minecraft, x, y)) { + // Click + button->setPressed(); + self->clicked_button = button; + self->buttonClicked(button); + // Play Sound + self->minecraft->sound_engine->playUI("random.click", 1, 1); + } + } + } +} +static void Screen_mouseReleased_injection(__attribute__((unused)) Screen_mouseReleased_t original, Screen *self, int x, int y, const int param_1) { + if (param_1 == 1 && self->clicked_button) { + self->clicked_button->released(x, y); + self->clicked_button = nullptr; + } +} +// Fix Exiting Pause Screen +static void Minecraft_grabMouse_injection(Minecraft_grabMouse_t original, Minecraft *self) { + original(self); + self->miss_time = 10000; +} +static void Minecraft_handleMouseDown_injection(Minecraft_handleMouseDown_t original, Minecraft *self, int param_1, bool can_destroy) { + // Call Original Method + original(self, param_1, can_destroy); + // Reset Miss Time + if (!can_destroy) { + self->miss_time = 0; + } +} + // Init void _init_misc_ui() { // Food Overlay @@ -288,4 +323,12 @@ void _init_misc_ui() { uchar set_true_patch[] = {0x01, 0x30, 0xa0, 0x03}; // "moveq r3, #0x1" patch((void *) 0x4b93c, set_true_patch); } + + // Click Buttons On Mouse Down + if (feature_has("Click Buttons On Mouse Down", server_disabled)) { + overwrite_calls(Screen_mouseClicked, Screen_mouseClicked_injection); + overwrite_calls(Screen_mouseReleased, Screen_mouseReleased_injection); + overwrite_calls(Minecraft_grabMouse, Minecraft_grabMouse_injection); + overwrite_calls(Minecraft_handleMouseDown, Minecraft_handleMouseDown_injection); + } } diff --git a/symbols/src/game/Minecraft.def b/symbols/src/game/Minecraft.def index 018a30f137..54dbd6a27b 100644 --- a/symbols/src/game/Minecraft.def +++ b/symbols/src/game/Minecraft.def @@ -26,8 +26,8 @@ virtual-method void selectLevel(const std::string &level_dir, const std::string property int screen_width = 0x20; property int screen_height = 0x24; property Options options = 0x3c; -property LevelRenderer *levelrenderer = 0x150; -property GameRenderer *gamerenderer = 0x154; +property LevelRenderer *level_renderer = 0x150; +property GameRenderer *game_renderer = 0x154; property GameMode *game_mode = 0x160; property Textures *textures = 0x164; property ScreenChooser screen_chooser = 0x168; @@ -45,6 +45,8 @@ property int ticks_per_update = 0xc70; property bool is_creative_mode = 0xcb5; property PerfRenderer *perf_renderer = 0xcbc; property CommandServer *command_server = 0xcc0; +property SoundEngine *sound_engine = 0x15c; +property int miss_time = 0xca0; // Smooth Lighting static-property bool useAmbientOcclusion = 0x136b90; diff --git a/symbols/src/gui/components/Button.def b/symbols/src/gui/components/Button.def index 32f211e55d..79c8f8622f 100644 --- a/symbols/src/gui/components/Button.def +++ b/symbols/src/gui/components/Button.def @@ -5,6 +5,10 @@ constructor (int id, const std::string &text) = 0x1bc54; method int hovered(Minecraft *minecraft, int click_x, int click_y) = 0x1be2c; +virtual-method bool clicked(Minecraft *minecraft, int click_x, int click_y) = 0x20; +virtual-method void setPressed() = 0x28; +virtual-method bool released(int click_x, int click_y) = 0x24; + property int width = 0x14; property int height = 0x18; property int x = 0xc; diff --git a/symbols/src/gui/screens/Screen.def b/symbols/src/gui/screens/Screen.def index 0842c954d3..a3d6397449 100644 --- a/symbols/src/gui/screens/Screen.def +++ b/symbols/src/gui/screens/Screen.def @@ -16,6 +16,7 @@ virtual-method void removed() = 0x2c; virtual-method void renderBackground() = 0x30; virtual-method void buttonClicked(Button *button) = 0x60; virtual-method void mouseClicked(int x, int y, int param_1) = 0x64; +virtual-method void mouseReleased(int x, int y, int param_1) = 0x68; virtual-method void keyPressed(int key) = 0x6c; virtual-method void keyboardNewChar(char key) = 0x70; @@ -26,3 +27,4 @@ property Minecraft *minecraft = 0x14; property std::vector