Fix Various Input Bugs

This commit is contained in:
TheBrokenRail 2021-06-28 22:59:24 -04:00
parent 989dd7983b
commit 0c0a61cd23
15 changed files with 71 additions and 33 deletions

View File

@ -1 +1 @@
2.0.6
2.0.7

View File

@ -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

View File

@ -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 *

View File

@ -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()

View File

@ -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;
}

View File

@ -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);
}

View File

@ -10,6 +10,7 @@ __attribute__((constructor)) static void init() {
#endif
init_game_mode();
init_input();
init_sign();
init_misc();
init_death();
init_camera();

View File

@ -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();

View File

@ -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.

View File

@ -1,11 +1,10 @@
#include <libreborn/libreborn.h>
#include <libreborn/minecraft.h>
#include "../feature/feature.h"
#include "input.h"
#include "../init/init.h"
#include "../chat/chat.h"
#include <libreborn/minecraft.h>
#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 <SDL/SDL.h>
// 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();
}

View File

@ -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

View File

@ -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);
}

2
mods/src/sign/README.md Normal file
View File

@ -0,0 +1,2 @@
# ``sign`` Mod
This mod fixes sign placement.

View File

@ -1,12 +1,12 @@
#include <vector>
#include <libreborn/libreborn.h>
#include "../feature/feature.h"
#include "input.h"
#include <libreborn/minecraft.h>
#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<char> 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,10 +52,11 @@ 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);

12
mods/src/sign/sign.h Normal file
View File

@ -0,0 +1,12 @@
#pragma once
#ifdef __cplusplus
extern "C" {
#endif
void sign_key_press(char key);
void sign_clear_input();
#ifdef __cplusplus
}
#endif