From 0c0a61cd2341c1ff12e78dcf74f3c335b8d8a674 Mon Sep 17 00:00:00 2001 From: TheBrokenRail Date: Mon, 28 Jun 2021 22:59:24 -0400 Subject: [PATCH] Fix Various Input Bugs --- VERSION | 2 +- docs/CHANGELOG.md | 4 +++ libreborn/include/libreborn/minecraft.h | 3 +++ mods/CMakeLists.txt | 13 +++++---- mods/src/compat/compat.c | 7 ++++- mods/src/game-mode/game-mode.cpp | 1 + mods/src/init/init.c | 1 + mods/src/init/init.h | 1 + mods/src/input/README.md | 1 - mods/src/input/input.c | 30 ++++++++++++++------- mods/src/input/input.h | 6 +---- mods/src/misc/misc.cpp | 2 +- mods/src/sign/README.md | 2 ++ mods/src/{input/input.cpp => sign/sign.cpp} | 19 ++++++------- mods/src/sign/sign.h | 12 +++++++++ 15 files changed, 71 insertions(+), 33 deletions(-) create mode 100644 mods/src/sign/README.md rename mods/src/{input/input.cpp => sign/sign.cpp} (92%) create mode 100644 mods/src/sign/sign.h diff --git a/VERSION b/VERSION index 157e54f3e..f1547e6d1 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -2.0.6 +2.0.7 diff --git a/docs/CHANGELOG.md b/docs/CHANGELOG.md index e13e9acc9..f4b147e93 100644 --- a/docs/CHANGELOG.md +++ b/docs/CHANGELOG.md @@ -1,5 +1,9 @@ # Changelog +**2.0.7** +* Fix Sign Text Not Updating In Multiplayer When Exiting Editing UI Using Escape Button +* Fix Item Dropping Not Working + **2.0.6** * Fix Toolbar Size In Normal GUI diff --git a/libreborn/include/libreborn/minecraft.h b/libreborn/include/libreborn/minecraft.h index 38516a9a5..f689de50b 100644 --- a/libreborn/include/libreborn/minecraft.h +++ b/libreborn/include/libreborn/minecraft.h @@ -110,6 +110,9 @@ static Minecraft_grabMouse_t Minecraft_grabMouse = (Minecraft_grabMouse_t) 0x15d typedef void (*Minecraft_leaveGame_t)(unsigned char *minecraft, bool save_remote_level); static Minecraft_leaveGame_t Minecraft_leaveGame = (Minecraft_leaveGame_t) 0x15ea0; +typedef void (*Minecraft_handleBack_t)(unsigned char *minecraft, bool param_1); +static uint32_t Minecraft_handleBack_vtable_offset = 0x34; + static uint32_t Minecraft_screen_width_property_offset = 0x20; // int32_t static uint32_t Minecraft_network_handler_property_offset = 0x174; // NetEventCallback * static uint32_t Minecraft_rak_net_instance_property_offset = 0x170; // RakNetInstance * diff --git a/mods/CMakeLists.txt b/mods/CMakeLists.txt index 9056a5e8c..322ce4c92 100644 --- a/mods/CMakeLists.txt +++ b/mods/CMakeLists.txt @@ -8,7 +8,7 @@ add_definitions(-D_GLIBCXX_USE_CXX11_ABI=0) ## Mods add_library(compat SHARED src/compat/compat.c src/compat/egl.c src/compat/x11.c) -target_link_libraries(compat feature input media-layer-core dl) +target_link_libraries(compat feature input sign media-layer-core dl) add_library(readdir SHARED src/readdir/readdir.c) @@ -32,8 +32,11 @@ target_link_libraries(camera reborn media-layer-core) add_library(game-mode SHARED src/game-mode/game-mode.c src/game-mode/game-mode.cpp) target_link_libraries(game-mode reborn) -add_library(input SHARED src/input/input.c src/input/input.cpp) -target_link_libraries(input reborn feature media-layer-core chat) +add_library(sign SHARED src/sign/sign.cpp) +target_link_libraries(sign reborn feature) + +add_library(input SHARED src/input/input.c) +target_link_libraries(input reborn feature media-layer-core chat sign) add_library(death SHARED src/death/death.cpp) target_link_libraries(death reborn) @@ -63,7 +66,7 @@ add_library(test SHARED src/test/test.c) target_link_libraries(test reborn home) add_library(init SHARED src/init/init.c) -target_link_libraries(init compat game-mode camera input misc death options touch textures chat home version test) +target_link_libraries(init compat game-mode camera input sign misc death options touch textures chat home version test) if(MCPI_SERVER_MODE) target_link_libraries(init server) else() @@ -71,7 +74,7 @@ else() endif() ## Install Mods -install(TARGETS init compat readdir feature override game-mode camera input misc death options touch textures chat home version test DESTINATION "${MCPI_INSTALL_DIR}/mods") +install(TARGETS init compat readdir feature override game-mode camera input sign misc death options touch textures chat home version test DESTINATION "${MCPI_INSTALL_DIR}/mods") if(MCPI_SERVER_MODE) install(TARGETS server DESTINATION "${MCPI_INSTALL_DIR}/mods") else() diff --git a/mods/src/compat/compat.c b/mods/src/compat/compat.c index d0f2430ee..d5fb5efb1 100644 --- a/mods/src/compat/compat.c +++ b/mods/src/compat/compat.c @@ -8,6 +8,7 @@ #include "../feature/feature.h" #include "../input/input.h" +#include "../sign/sign.h" #include "../chat/chat.h" #include "../init/init.h" #include "compat.h" @@ -71,6 +72,10 @@ HOOK(SDL_PollEvent, int, (SDL_Event *event)) { } // Mark Handled handled = 1; + } else if (event->key.keysym.sym == SDLK_ESCAPE) { + // Treat Escape As Back Button Press (This Fixes Issues With Signs) + input_back(); + handled = 1; } break; } @@ -86,7 +91,7 @@ HOOK(SDL_PollEvent, int, (SDL_Event *event)) { } case SDL_USEREVENT: { // SDL_UserEvent Is Never Used In MCPI, So It Is Repurposed For Character Events - input_key_press((char) event->user.code); + sign_key_press((char) event->user.code); handled = 1; break; } diff --git a/mods/src/game-mode/game-mode.cpp b/mods/src/game-mode/game-mode.cpp index 81dceb636..1d39e341c 100644 --- a/mods/src/game-mode/game-mode.cpp +++ b/mods/src/game-mode/game-mode.cpp @@ -55,4 +55,5 @@ void _init_game_mode_cpp() { // Make The SimpleChooseLevelScreen Back Button Go To SelectWorldScreen Instead Of StartMenuScreen unsigned char simple_choose_level_screen_back_button_patch[4] = {0x05, 0x10, 0xa0, 0xe3}; // "mov r1, #0x5" patch((void *) 0x31144, simple_choose_level_screen_back_button_patch); + patch((void *) 0x3134c, simple_choose_level_screen_back_button_patch); } diff --git a/mods/src/init/init.c b/mods/src/init/init.c index e5445865e..65c7ae8f3 100644 --- a/mods/src/init/init.c +++ b/mods/src/init/init.c @@ -10,6 +10,7 @@ __attribute__((constructor)) static void init() { #endif init_game_mode(); init_input(); + init_sign(); init_misc(); init_death(); init_camera(); diff --git a/mods/src/init/init.h b/mods/src/init/init.h index 59fee33f0..95e6668db 100644 --- a/mods/src/init/init.h +++ b/mods/src/init/init.h @@ -13,6 +13,7 @@ void init_multiplayer(); #endif void init_game_mode(); void init_input(); +void init_sign(); void init_misc(); void init_death(); void init_camera(); diff --git a/mods/src/input/README.md b/mods/src/input/README.md index bcd70232d..5ecb7b0e5 100644 --- a/mods/src/input/README.md +++ b/mods/src/input/README.md @@ -3,7 +3,6 @@ This mod fixes various input-related bugs, including: - Bows being broken. - The cursor interacting with the hotbar while the it is locked. - Being unable to attack mobs. -- Being unable to specify sign text. It also adds various features, including: - Hide GUI and third person toggle keys. diff --git a/mods/src/input/input.c b/mods/src/input/input.c index fffb9bd00..747802714 100644 --- a/mods/src/input/input.c +++ b/mods/src/input/input.c @@ -1,11 +1,10 @@ #include +#include #include "../feature/feature.h" -#include "input.h" #include "../init/init.h" #include "../chat/chat.h" - -#include +#include "../sign/sign.h" // Store Right-Click Status static int is_right_click = 0; @@ -26,12 +25,18 @@ void input_third_person() { third_person_toggle++; } -// Set mouse Grab State +// Set Mouse Grab State static int mouse_grab_state = 0; void input_set_mouse_grab_state(int state) { mouse_grab_state = state; } +// Store Back Button Presses +static int back_button_presses =0; +void input_back() { + back_button_presses++; +} + // Handle Input Fixes static void Minecraft_tickInput_injection(unsigned char *minecraft) { // Call Original Method @@ -50,7 +55,7 @@ static void Minecraft_tickInput_injection(unsigned char *minecraft) { } // Clear Unused Sign Input - input_clear_input(); + sign_clear_input(); // Handle Functions unsigned char *options = minecraft + Minecraft_options_property_offset; @@ -77,13 +82,21 @@ static void Minecraft_tickInput_injection(unsigned char *minecraft) { (*Minecraft_releaseMouse)(minecraft); } mouse_grab_state = 0; + + // Handle Back Button + unsigned char *minecraft_vtable = *(unsigned char **) minecraft; + Minecraft_handleBack_t Minecraft_handleBack = *(Minecraft_handleBack_t *) (minecraft_vtable + Minecraft_handleBack_vtable_offset); + for (int i = 0; i < back_button_presses; i++) { + (*Minecraft_handleBack)(minecraft, 0); + } + back_button_presses = 0; } #include // Block UI Interaction When Mouse Is Locked static bool Gui_tickItemDrop_Minecraft_isCreativeMode_call_injection(unsigned char *minecraft) { - if (SDL_ShowCursor(SDL_QUERY) == SDL_ENABLE) { + if (SDL_WM_GrabInput(SDL_GRAB_QUERY) == SDL_GRAB_OFF) { // Call Original Method return (*Minecraft_isCreativeMode)(minecraft); } else { @@ -94,7 +107,7 @@ static bool Gui_tickItemDrop_Minecraft_isCreativeMode_call_injection(unsigned ch // Block UI Interaction When Mouse Is Locked static void Gui_handleClick_injection(unsigned char *this, int32_t param_2, int32_t param_3, int32_t param_4) { - if (SDL_ShowCursor(SDL_QUERY) == SDL_ENABLE) { + if (SDL_WM_GrabInput(SDL_GRAB_QUERY) == SDL_GRAB_OFF) { // Call Original Method (*Gui_handleClick)(this, param_2, param_3, param_4); } @@ -147,7 +160,4 @@ void init_input() { // Allow Attacking Mobs patch_address(MouseBuildInput_tickBuild_vtable_addr, (void *) MouseBuildInput_tickBuild_injection); } - - // Init C++ - _init_input_cpp(); } diff --git a/mods/src/input/input.h b/mods/src/input/input.h index 0e2f3f40a..40d9cc313 100644 --- a/mods/src/input/input.h +++ b/mods/src/input/input.h @@ -4,19 +4,15 @@ extern "C" { #endif -void input_key_press(char key); -void input_clear_input(); - void input_set_is_right_click(int val); void input_hide_gui(); void input_third_person(); +void input_back(); void input_set_is_left_click(int val); void input_set_mouse_grab_state(int state); -__attribute__((visibility("internal"))) void _init_input_cpp(); - #ifdef __cplusplus } #endif diff --git a/mods/src/misc/misc.cpp b/mods/src/misc/misc.cpp index eaeb311dc..31e85ee0a 100644 --- a/mods/src/misc/misc.cpp +++ b/mods/src/misc/misc.cpp @@ -103,8 +103,8 @@ void _init_misc_cpp() { // Implement AppPlatform::readAssetFile So Translations Work overwrite((void *) AppPlatform_readAssetFile, (void *) AppPlatform_readAssetFile_injection); + // Add Extra Items To Creative Inventory (Only Replace Specific Function Call) if (feature_has("Expand Creative Inventory")) { - // Add Extra Items To Creative Inventory (Only Replace Specific Function Call) overwrite_call((void *) 0x8e0fc, (void *) Inventory_setupDefault_FillingContainer_addItem_call_injection); } diff --git a/mods/src/sign/README.md b/mods/src/sign/README.md new file mode 100644 index 000000000..1f706602a --- /dev/null +++ b/mods/src/sign/README.md @@ -0,0 +1,2 @@ +# ``sign`` Mod +This mod fixes sign placement. diff --git a/mods/src/input/input.cpp b/mods/src/sign/sign.cpp similarity index 92% rename from mods/src/input/input.cpp rename to mods/src/sign/sign.cpp index ed995f98f..3bdf12f5d 100644 --- a/mods/src/input/input.cpp +++ b/mods/src/sign/sign.cpp @@ -1,12 +1,12 @@ #include #include - -#include "../feature/feature.h" -#include "input.h" - #include +#include "../init/init.h" +#include "../feature/feature.h" +#include "sign.h" + // Open Sign Screen static void LocalPlayer_openTextEdit_injection(unsigned char *local_player, unsigned char *sign) { if (*(int32_t *) (sign + TileEntity_id_property_offset) == 4) { @@ -26,12 +26,12 @@ static int is_valid_key(char key) { // Store Text Input std::vector input; -void input_key_press(char key) { +void sign_key_press(char key) { if (is_valid_key(key)) { input.push_back(key); } } -void input_clear_input() { +void sign_clear_input() { input.clear(); } @@ -52,13 +52,14 @@ static void TextEditScreen_updateEvents_injection(unsigned char *screen) { } } } - input_clear_input(); + sign_clear_input(); } -void _init_input_cpp() { +// Init +void init_sign() { if (feature_has("Fix Sign Placement")) { // Fix Signs patch_address(LocalPlayer_openTextEdit_vtable_addr, (void *) LocalPlayer_openTextEdit_injection); patch_address(TextEditScreen_updateEvents_vtable_addr, (void *) TextEditScreen_updateEvents_injection); } -} \ No newline at end of file +} diff --git a/mods/src/sign/sign.h b/mods/src/sign/sign.h new file mode 100644 index 000000000..2775fb0f3 --- /dev/null +++ b/mods/src/sign/sign.h @@ -0,0 +1,12 @@ +#pragma once + +#ifdef __cplusplus +extern "C" { +#endif + +void sign_key_press(char key); +void sign_clear_input(); + +#ifdef __cplusplus +} +#endif