Some Modernization
This commit is contained in:
parent
cecd61ed72
commit
5e229fb6a8
@ -241,7 +241,7 @@ void setup_crash_report() {
|
|||||||
// Print Exit Code Log Line
|
// Print Exit Code Log Line
|
||||||
safe_write(STDERR_FILENO, exit_code_line.c_str(), strlen(exit_code_line.c_str()));
|
safe_write(STDERR_FILENO, exit_code_line.c_str(), strlen(exit_code_line.c_str()));
|
||||||
// Write Exit Code Log Line
|
// Write Exit Code Log Line
|
||||||
safe_write(reborn_get_debug_fd(), exit_code_line.c_str(), strlen(exit_code_line.c_str()));
|
safe_write(reborn_get_log_fd(), exit_code_line.c_str(), strlen(exit_code_line.c_str()));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Close Log File
|
// Close Log File
|
||||||
|
@ -4,7 +4,7 @@
|
|||||||
extern "C" {
|
extern "C" {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#define ENV(name, ...) extern const char *name##_ENV;
|
#define ENV(name, ...) extern const char *const name##_ENV;
|
||||||
#include "env-list.h"
|
#include "env-list.h"
|
||||||
#undef ENV
|
#undef ENV
|
||||||
|
|
||||||
|
@ -1,38 +1,11 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <stdlib.h>
|
|
||||||
#include <stdio.h>
|
|
||||||
#include <string.h>
|
|
||||||
#include <stdint.h>
|
|
||||||
|
|
||||||
#include "util.h"
|
|
||||||
|
|
||||||
// Set obj To NULL On asprintf() Failure
|
|
||||||
#define safe_asprintf(obj, ...) \
|
|
||||||
{ \
|
|
||||||
if (asprintf(obj, __VA_ARGS__) == -1) { \
|
|
||||||
*obj = NULL; \
|
|
||||||
} \
|
|
||||||
ALLOC_CHECK(*obj); \
|
|
||||||
}
|
|
||||||
|
|
||||||
// Dynamic String Append Macro
|
|
||||||
#define string_append(str, format, ...) \
|
|
||||||
{ \
|
|
||||||
char *old = *str; \
|
|
||||||
safe_asprintf(str, "%s" format, *str == NULL ? "" : *str, ##__VA_ARGS__); \
|
|
||||||
ALLOC_CHECK(*str); \
|
|
||||||
if (old != NULL && old != *str) { \
|
|
||||||
free(old); \
|
|
||||||
} \
|
|
||||||
}
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
extern "C" {
|
extern "C" {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// Sanitize String
|
// Sanitize String
|
||||||
void sanitize_string(char *str, int max_length, unsigned int allow_newlines);
|
void sanitize_string(char *str, int max_length, int allow_newlines);
|
||||||
|
|
||||||
// CP437
|
// CP437
|
||||||
char *to_cp437(const char *input);
|
char *to_cp437(const char *input);
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
#include <libreborn/exec.h>
|
#include <libreborn/exec.h>
|
||||||
|
|
||||||
// Define Constants
|
// Define Constants
|
||||||
#define ENV(name, ...) const char *name##_ENV = #name;
|
#define ENV(name, ...) const char *const name##_ENV = #name;
|
||||||
#include <libreborn/env-list.h>
|
#include <libreborn/env-list.h>
|
||||||
#undef ENV
|
#undef ENV
|
||||||
|
|
||||||
|
@ -127,8 +127,17 @@ char *run_command(const char *const command[], int *exit_status, size_t *output_
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Set obj To NULL On asprintf() Failure
|
||||||
|
#define safe_asprintf(obj, ...) \
|
||||||
|
{ \
|
||||||
|
if (asprintf(obj, __VA_ARGS__) == -1) { \
|
||||||
|
*obj = NULL; \
|
||||||
|
} \
|
||||||
|
ALLOC_CHECK(*obj); \
|
||||||
|
}
|
||||||
|
|
||||||
// Get Exit Status String
|
// Get Exit Status String
|
||||||
void get_exit_status_string(int status, char **out) {
|
void get_exit_status_string(const int status, char **out) {
|
||||||
if (out != NULL) {
|
if (out != NULL) {
|
||||||
*out = NULL;
|
*out = NULL;
|
||||||
if (WIFEXITED(status)) {
|
if (WIFEXITED(status)) {
|
||||||
|
@ -1,7 +1,9 @@
|
|||||||
#include <libreborn/string.h>
|
#include <libreborn/string.h>
|
||||||
|
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
// Sanitize String
|
// Sanitize String
|
||||||
void sanitize_string(char *str, int max_length, unsigned int allow_newlines) {
|
void sanitize_string(char *str, const int max_length, const int allow_newlines) {
|
||||||
// Store Message Length
|
// Store Message Length
|
||||||
size_t length = strlen(str);
|
size_t length = strlen(str);
|
||||||
// Truncate Message
|
// Truncate Message
|
||||||
|
@ -58,6 +58,7 @@ set(SRC
|
|||||||
src/input/toggle.cpp
|
src/input/toggle.cpp
|
||||||
src/input/misc.cpp
|
src/input/misc.cpp
|
||||||
src/input/drop.cpp
|
src/input/drop.cpp
|
||||||
|
src/input/keys.cpp
|
||||||
# sign
|
# sign
|
||||||
src/sign/sign.cpp
|
src/sign/sign.cpp
|
||||||
# atlas
|
# atlas
|
||||||
|
@ -27,4 +27,5 @@ void init_bucket();
|
|||||||
void init_cake();
|
void init_cake();
|
||||||
void init_home();
|
void init_home();
|
||||||
void init_override();
|
void init_override();
|
||||||
|
void init_screenshot();
|
||||||
}
|
}
|
||||||
|
@ -1,16 +1,12 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <symbols/minecraft.h>
|
|
||||||
|
|
||||||
extern "C" {
|
extern "C" {
|
||||||
typedef void (*input_tick_function_t)(Minecraft *minecraft);
|
|
||||||
void input_run_on_tick(input_tick_function_t function);
|
|
||||||
|
|
||||||
void input_set_is_right_click(int val);
|
void input_set_is_right_click(int val);
|
||||||
int input_back();
|
void input_set_is_ctrl(bool val);
|
||||||
void input_drop(int drop_slot);
|
|
||||||
|
|
||||||
void input_set_is_left_click(int val);
|
enum {
|
||||||
|
#define KEY(name, value) MC_KEY_##name = (value),
|
||||||
void input_set_mouse_grab_state(int state);
|
#include "key-list.h"
|
||||||
|
#undef KEY
|
||||||
|
};
|
||||||
}
|
}
|
13
mods/include/mods/input/key-list.h
Normal file
13
mods/include/mods/input/key-list.h
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
// MCPI Seems To Use https://learn.microsoft.com/en-us/windows/win32/inputdev/virtual-key-codes
|
||||||
|
KEY(BACKSPACE, 0x8)
|
||||||
|
KEY(DELETE, 0x2e)
|
||||||
|
KEY(LEFT, 0x25)
|
||||||
|
KEY(RIGHT, 0x27)
|
||||||
|
KEY(F1, 0x70)
|
||||||
|
KEY(F2, 0x71)
|
||||||
|
KEY(F5, 0x74)
|
||||||
|
KEY(F11, 0x7a)
|
||||||
|
KEY(RETURN, 0xd)
|
||||||
|
KEY(t, 0x54)
|
||||||
|
KEY(q, 0x51)
|
||||||
|
KEY(ESCAPE, 0x1b)
|
@ -23,3 +23,4 @@ void misc_run_on_tiles_setup(const std::function<void()> &func);
|
|||||||
void misc_run_on_items_setup(const std::function<void()> &func);
|
void misc_run_on_items_setup(const std::function<void()> &func);
|
||||||
void misc_run_on_language_setup(const std::function<void()> &func);
|
void misc_run_on_language_setup(const std::function<void()> &func);
|
||||||
void misc_run_on_game_key_press(const std::function<bool(Minecraft *, int)> &func);
|
void misc_run_on_game_key_press(const std::function<bool(Minecraft *, int)> &func);
|
||||||
|
void misc_run_on_key_press(const std::function<bool(Minecraft *, int)> &func);
|
||||||
|
@ -1,5 +1,7 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
struct Gui;
|
||||||
|
|
||||||
extern "C" {
|
extern "C" {
|
||||||
void screenshot_take(const char *home);
|
void screenshot_take(Gui *gui);
|
||||||
}
|
}
|
@ -3,12 +3,11 @@
|
|||||||
|
|
||||||
#include <mods/feature/feature.h>
|
#include <mods/feature/feature.h>
|
||||||
#include <mods/screenshot/screenshot.h>
|
#include <mods/screenshot/screenshot.h>
|
||||||
#include <mods/home/home.h>
|
|
||||||
#include <mods/init/init.h>
|
#include <mods/init/init.h>
|
||||||
|
|
||||||
// Take Screenshot Using TripodCamera
|
// Take Screenshot Using TripodCamera
|
||||||
static void AppPlatform_saveScreenshot_injection(__attribute__((unused)) AppPlatform_saveScreenshot_t original, __attribute__((unused)) AppPlatform *app_platform, __attribute__((unused)) std::string *path, __attribute__((unused)) int32_t width, __attribute__((unused)) int32_t height) {
|
static void AppPlatform_saveScreenshot_injection(__attribute__((unused)) AppPlatform_saveScreenshot_t original, __attribute__((unused)) AppPlatform *app_platform, __attribute__((unused)) std::string *path, __attribute__((unused)) int32_t width, __attribute__((unused)) int32_t height) {
|
||||||
screenshot_take(home_get());
|
screenshot_take(nullptr);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Enable TripodCameraRenderer
|
// Enable TripodCameraRenderer
|
||||||
|
@ -1,9 +1,13 @@
|
|||||||
#include "chat-internal.h"
|
#include "chat-internal.h"
|
||||||
|
|
||||||
#include <libreborn/libreborn.h>
|
#include <libreborn/libreborn.h>
|
||||||
|
#include <symbols/minecraft.h>
|
||||||
|
|
||||||
#include <mods/chat/chat.h>
|
#include <mods/chat/chat.h>
|
||||||
#include <mods/text-input-box/TextInputScreen.h>
|
#include <mods/text-input-box/TextInputScreen.h>
|
||||||
#include <mods/misc/misc.h>
|
#include <mods/misc/misc.h>
|
||||||
#include <mods/touch/touch.h>
|
#include <mods/touch/touch.h>
|
||||||
|
#include <mods/input/input.h>
|
||||||
|
|
||||||
static std::vector<std::string> &get_history() {
|
static std::vector<std::string> &get_history() {
|
||||||
static std::vector<std::string> history = {};
|
static std::vector<std::string> history = {};
|
||||||
@ -143,7 +147,7 @@ static Screen *create_chat_screen() {
|
|||||||
// Init
|
// Init
|
||||||
void _init_chat_ui() {
|
void _init_chat_ui() {
|
||||||
misc_run_on_game_key_press([](Minecraft *minecraft, int key) {
|
misc_run_on_game_key_press([](Minecraft *minecraft, int key) {
|
||||||
if (key == 0x54) {
|
if (key == MC_KEY_t) {
|
||||||
if (minecraft->isLevelGenerated() && minecraft->screen == nullptr) {
|
if (minecraft->isLevelGenerated() && minecraft->screen == nullptr) {
|
||||||
minecraft->setScreen(create_chat_screen());
|
minecraft->setScreen(create_chat_screen());
|
||||||
}
|
}
|
||||||
|
@ -14,8 +14,6 @@
|
|||||||
|
|
||||||
#include <mods/input/input.h>
|
#include <mods/input/input.h>
|
||||||
#include <mods/sign/sign.h>
|
#include <mods/sign/sign.h>
|
||||||
#include <mods/chat/chat.h>
|
|
||||||
#include <mods/home/home.h>
|
|
||||||
|
|
||||||
// Custom Title
|
// Custom Title
|
||||||
HOOK(SDL_WM_SetCaption, void, (__attribute__((unused)) const char *title, const char *icon)) {
|
HOOK(SDL_WM_SetCaption, void, (__attribute__((unused)) const char *title, const char *icon)) {
|
||||||
@ -47,24 +45,16 @@ HOOK(SDL_PollEvent, int, (SDL_Event *event)) {
|
|||||||
|
|
||||||
// Handle Events
|
// Handle Events
|
||||||
if (ret == 1 && event != nullptr) {
|
if (ret == 1 && event != nullptr) {
|
||||||
int handled = 0;
|
bool handled = false;
|
||||||
switch (event->type) {
|
switch (event->type) {
|
||||||
case SDL_KEYDOWN: {
|
case SDL_KEYDOWN:
|
||||||
// Handle Key Presses
|
case SDL_KEYUP: {
|
||||||
if (event->key.keysym.sym == SDLK_F11) {
|
// Track Control Key
|
||||||
media_toggle_fullscreen();
|
bool is_ctrl = (event->key.keysym.mod & KMOD_CTRL) != 0;
|
||||||
handled = 1;
|
if (event->type == SDL_KEYUP) {
|
||||||
} else if (event->key.keysym.sym == SDLK_F2) {
|
is_ctrl = false;
|
||||||
screenshot_take(home_get());
|
|
||||||
handled = 1;
|
|
||||||
} else if (event->key.keysym.sym == SDLK_ESCAPE) {
|
|
||||||
// Treat Escape As Back Button Press (This Fixes Issues With Signs)
|
|
||||||
handled = input_back();
|
|
||||||
} else if (event->key.keysym.sym == SDLK_q) {
|
|
||||||
// Drop Item
|
|
||||||
input_drop((event->key.keysym.mod & KMOD_CTRL) != 0);
|
|
||||||
handled = 1;
|
|
||||||
}
|
}
|
||||||
|
input_set_is_ctrl(is_ctrl);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case SDL_MOUSEBUTTONDOWN:
|
case SDL_MOUSEBUTTONDOWN:
|
||||||
@ -72,8 +62,6 @@ HOOK(SDL_PollEvent, int, (SDL_Event *event)) {
|
|||||||
// Track Right-Click State
|
// Track Right-Click State
|
||||||
if (event->button.button == SDL_BUTTON_RIGHT) {
|
if (event->button.button == SDL_BUTTON_RIGHT) {
|
||||||
input_set_is_right_click(event->button.state != SDL_RELEASED);
|
input_set_is_right_click(event->button.state != SDL_RELEASED);
|
||||||
} else if (event->button.button == SDL_BUTTON_LEFT) {
|
|
||||||
input_set_is_left_click(event->button.state != SDL_RELEASED);
|
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -81,7 +69,7 @@ HOOK(SDL_PollEvent, int, (SDL_Event *event)) {
|
|||||||
// SDL_UserEvent Is Never Used In MCPI, So It Is Repurposed For Character Events
|
// SDL_UserEvent Is Never Used In MCPI, So It Is Repurposed For Character Events
|
||||||
if (event->user.code == USER_EVENT_CHARACTER) {
|
if (event->user.code == USER_EVENT_CHARACTER) {
|
||||||
sign_key_press((char) event->user.data1);
|
sign_key_press((char) event->user.data1);
|
||||||
handled = 1;
|
handled = true;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -13,13 +13,17 @@ __attribute__((constructor)) static void init() {
|
|||||||
} else {
|
} else {
|
||||||
init_multiplayer();
|
init_multiplayer();
|
||||||
}
|
}
|
||||||
|
if (!reborn_is_headless()) {
|
||||||
init_sound();
|
init_sound();
|
||||||
|
}
|
||||||
init_input();
|
init_input();
|
||||||
init_sign();
|
init_sign();
|
||||||
init_camera();
|
init_camera();
|
||||||
init_atlas();
|
init_atlas();
|
||||||
init_title_screen();
|
init_title_screen();
|
||||||
|
if (!reborn_is_headless()) {
|
||||||
init_skin();
|
init_skin();
|
||||||
|
}
|
||||||
init_fps();
|
init_fps();
|
||||||
init_touch();
|
init_touch();
|
||||||
init_textures();
|
init_textures();
|
||||||
@ -36,4 +40,7 @@ __attribute__((constructor)) static void init() {
|
|||||||
if (!reborn_is_server()) {
|
if (!reborn_is_server()) {
|
||||||
init_benchmark();
|
init_benchmark();
|
||||||
}
|
}
|
||||||
|
if (!reborn_is_headless()) {
|
||||||
|
init_screenshot();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -3,53 +3,28 @@
|
|||||||
|
|
||||||
#include <mods/feature/feature.h>
|
#include <mods/feature/feature.h>
|
||||||
#include "input-internal.h"
|
#include "input-internal.h"
|
||||||
#include <mods/input/input.h>
|
|
||||||
|
|
||||||
// Store Left Click (0 = Not Pressed, 1 = Pressed)
|
|
||||||
static int is_left_click = 0;
|
|
||||||
void input_set_is_left_click(int val) {
|
|
||||||
if ((is_left_click == 0 && val == 1) || (is_left_click != 0 && val == 0)) {
|
|
||||||
is_left_click = val;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Add Attacking To MouseBuildInput
|
// Add Attacking To MouseBuildInput
|
||||||
static int32_t MouseBuildInput_tickBuild_injection(MouseBuildInput_tickBuild_t original, MouseBuildInput *mouse_build_input, Player *local_player, uint32_t *build_action_intention_return) {
|
#define REMOVE_ATTACK_BAI 0xa
|
||||||
|
#define ATTACK_BAI 0x8
|
||||||
|
static bool MouseBuildInput_tickBuild_injection(MouseBuildInput_tickBuild_t original, MouseBuildInput *mouse_build_input, Player *local_player, uint32_t *build_action_intention_return) {
|
||||||
// Call Original Method
|
// Call Original Method
|
||||||
int32_t ret = original(mouse_build_input, local_player, build_action_intention_return);
|
const bool ret = original(mouse_build_input, local_player, build_action_intention_return);
|
||||||
|
// Convert Remove/Attack Into Attack If A Tile Is Not Selected
|
||||||
// Use Attack/Place BuildActionIntention If No Other Valid BuildActionIntention Was Selected And This Was Not A Repeated Left Click
|
if (ret && *build_action_intention_return == REMOVE_ATTACK_BAI) {
|
||||||
if (ret != 0 && is_left_click == 1 && *build_action_intention_return == 0xa) {
|
|
||||||
// Get Target HitResult
|
|
||||||
Minecraft *minecraft = ((LocalPlayer *) local_player)->minecraft;
|
Minecraft *minecraft = ((LocalPlayer *) local_player)->minecraft;
|
||||||
HitResult *hit_result = &minecraft->hit_result;
|
if (minecraft->hit_result.type != 0) {
|
||||||
int32_t hit_result_type = hit_result->type;
|
*build_action_intention_return = ATTACK_BAI;
|
||||||
// Check if The Target Is An Entity Using HitResult
|
|
||||||
if (hit_result_type == 1) {
|
|
||||||
// Change BuildActionIntention To Attack/Place Mode (Place Will Not Happen Because The HitResult Is An Entity)
|
|
||||||
*build_action_intention_return = 0x8;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Return
|
// Return
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
static void Minecraft_handleBuildAction_injection(Minecraft_handleBuildAction_t original, Minecraft *self, uint *bai) {
|
||||||
// Fix Holding Attack
|
if (*bai == ATTACK_BAI) {
|
||||||
static bool last_player_attack_successful = false;
|
*bai = REMOVE_ATTACK_BAI;
|
||||||
static bool Player_attack_Entity_hurt_injection(Entity *entity, Entity *attacker, int32_t damage) {
|
|
||||||
// Call Original Method
|
|
||||||
last_player_attack_successful = entity->hurt(attacker, damage);
|
|
||||||
return last_player_attack_successful;
|
|
||||||
}
|
}
|
||||||
static ItemInstance *Player_attack_Inventory_getSelected_injection(Inventory *inventory) {
|
original(self, bai);
|
||||||
// Check If Attack Was Successful
|
|
||||||
if (!last_player_attack_successful) {
|
|
||||||
return nullptr;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Call Original Method
|
|
||||||
return inventory->getSelected();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Init
|
// Init
|
||||||
@ -57,9 +32,6 @@ void _init_attack() {
|
|||||||
// Allow Attacking Mobs
|
// Allow Attacking Mobs
|
||||||
if (feature_has("Fix Attacking", server_disabled)) {
|
if (feature_has("Fix Attacking", server_disabled)) {
|
||||||
overwrite_calls(MouseBuildInput_tickBuild, MouseBuildInput_tickBuild_injection);
|
overwrite_calls(MouseBuildInput_tickBuild, MouseBuildInput_tickBuild_injection);
|
||||||
|
overwrite_calls(Minecraft_handleBuildAction, Minecraft_handleBuildAction_injection);
|
||||||
// Fix Holding Attack
|
|
||||||
overwrite_call((void *) 0x8fc1c, (void *) Player_attack_Entity_hurt_injection);
|
|
||||||
overwrite_call((void *) 0x8fc24, (void *) Player_attack_Inventory_getSelected_injection);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -11,23 +11,23 @@ void input_set_is_right_click(int val) {
|
|||||||
is_right_click = val;
|
is_right_click = val;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Enable Bow & Arrow Fix
|
|
||||||
static int fix_bow = 0;
|
|
||||||
|
|
||||||
// Handle Bow & Arrow
|
// Handle Bow & Arrow
|
||||||
static void _handle_bow(Minecraft *minecraft) {
|
static void _handle_bow(Minecraft_tickInput_t original, Minecraft *minecraft) {
|
||||||
if (fix_bow && !is_right_click) {
|
if (!is_right_click) {
|
||||||
GameMode *game_mode = minecraft->game_mode;
|
GameMode *game_mode = minecraft->game_mode;
|
||||||
LocalPlayer *player = minecraft->player;
|
LocalPlayer *player = minecraft->player;
|
||||||
if (player != nullptr && game_mode != nullptr && player->isUsingItem()) {
|
if (player != nullptr && game_mode != nullptr && player->isUsingItem()) {
|
||||||
game_mode->releaseUsingItem((Player *) player);
|
game_mode->releaseUsingItem((Player *) player);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
// Call Original Method
|
||||||
|
original(minecraft);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Init
|
// Init
|
||||||
void _init_bow() {
|
void _init_bow() {
|
||||||
// Enable Bow & Arrow Fix
|
// Enable Bow & Arrow Fix
|
||||||
fix_bow = feature_has("Fix Bow & Arrow", server_disabled);
|
if (feature_has("Fix Bow & Arrow", server_disabled)) {
|
||||||
input_run_on_tick(_handle_bow);
|
overwrite_calls(Minecraft_tickInput, _handle_bow);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -7,25 +7,15 @@
|
|||||||
#include <mods/creative/creative.h>
|
#include <mods/creative/creative.h>
|
||||||
#include <mods/misc/misc.h>
|
#include <mods/misc/misc.h>
|
||||||
|
|
||||||
// Enable Item Dropping
|
// Track Control Key
|
||||||
static int enable_drop = 0;
|
static bool drop_slot = false;
|
||||||
|
void input_set_is_ctrl(const bool val) {
|
||||||
// Store Drop Item Presses
|
drop_slot = val;
|
||||||
static int drop_item_presses = 0;
|
|
||||||
static bool drop_slot_pressed = false;
|
|
||||||
void input_drop(int drop_slot) {
|
|
||||||
if (enable_drop) {
|
|
||||||
if (drop_slot) {
|
|
||||||
drop_slot_pressed = true;
|
|
||||||
} else {
|
|
||||||
drop_item_presses++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Handle Drop Item Presses
|
// Handle Drop Item Presses
|
||||||
static void _handle_drop(Minecraft *minecraft) {
|
static void _handle_drop(Minecraft *minecraft) {
|
||||||
if ((minecraft->screen == nullptr) && (!creative_is_restricted() || !Minecraft_isCreativeMode(minecraft)) && (drop_item_presses > 0 || drop_slot_pressed)) {
|
if (!creative_is_restricted() || !Minecraft_isCreativeMode(minecraft)) {
|
||||||
// Get Player
|
// Get Player
|
||||||
LocalPlayer *player = minecraft->player;
|
LocalPlayer *player = minecraft->player;
|
||||||
if (player != nullptr) {
|
if (player != nullptr) {
|
||||||
@ -43,16 +33,12 @@ static void _handle_drop(Minecraft *minecraft) {
|
|||||||
*dropped_item = *inventory_item;
|
*dropped_item = *inventory_item;
|
||||||
|
|
||||||
// Update Inventory
|
// Update Inventory
|
||||||
if (drop_slot_pressed) {
|
if (drop_slot) {
|
||||||
// Drop Slot
|
// Drop Entire Slot
|
||||||
|
|
||||||
// Empty Slot
|
|
||||||
inventory_item->count = 0;
|
inventory_item->count = 0;
|
||||||
} else {
|
} else {
|
||||||
// Drop Item
|
// Drop Item
|
||||||
|
const int drop_count = 1;
|
||||||
// Set Item Drop Count
|
|
||||||
int drop_count = drop_item_presses < inventory_item->count ? drop_item_presses : inventory_item->count;
|
|
||||||
dropped_item->count = drop_count;
|
dropped_item->count = drop_count;
|
||||||
inventory_item->count -= drop_count;
|
inventory_item->count -= drop_count;
|
||||||
}
|
}
|
||||||
@ -68,13 +54,18 @@ static void _handle_drop(Minecraft *minecraft) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// Reset
|
|
||||||
drop_item_presses = 0;
|
|
||||||
drop_slot_pressed = false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Init
|
// Init
|
||||||
void _init_drop() {
|
void _init_drop() {
|
||||||
enable_drop = feature_has("Bind \"Q\" Key To Item Dropping", server_disabled);
|
if (feature_has("Bind \"Q\" Key To Item Dropping", server_disabled)) {
|
||||||
input_run_on_tick(_handle_drop);
|
misc_run_on_game_key_press([](Minecraft *mc, int key) {
|
||||||
|
if (key == MC_KEY_q) {
|
||||||
|
_handle_drop(mc);
|
||||||
|
return true;
|
||||||
|
} else {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -5,3 +5,4 @@ __attribute__((visibility("internal"))) void _init_bow();
|
|||||||
__attribute__((visibility("internal"))) void _init_misc();
|
__attribute__((visibility("internal"))) void _init_misc();
|
||||||
__attribute__((visibility("internal"))) void _init_toggle();
|
__attribute__((visibility("internal"))) void _init_toggle();
|
||||||
__attribute__((visibility("internal"))) void _init_drop();
|
__attribute__((visibility("internal"))) void _init_drop();
|
||||||
|
__attribute__((visibility("internal"))) void _init_keys();
|
@ -1,7 +1,3 @@
|
|||||||
#include <vector>
|
|
||||||
|
|
||||||
#include <libreborn/libreborn.h>
|
|
||||||
#include <symbols/minecraft.h>
|
|
||||||
#include <media-layer/core.h>
|
#include <media-layer/core.h>
|
||||||
|
|
||||||
#include <mods/feature/feature.h>
|
#include <mods/feature/feature.h>
|
||||||
@ -9,26 +5,6 @@
|
|||||||
#include "input-internal.h"
|
#include "input-internal.h"
|
||||||
#include <mods/input/input.h>
|
#include <mods/input/input.h>
|
||||||
|
|
||||||
// Run Functions On Input Tick
|
|
||||||
static std::vector<input_tick_function_t> &get_input_tick_functions() {
|
|
||||||
static std::vector<input_tick_function_t> functions;
|
|
||||||
return functions;
|
|
||||||
}
|
|
||||||
void input_run_on_tick(input_tick_function_t function) {
|
|
||||||
get_input_tick_functions().push_back(function);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Handle Input Fixes
|
|
||||||
static void Minecraft_tickInput_injection(Minecraft_tickInput_t original, Minecraft *minecraft) {
|
|
||||||
// Call Original Method
|
|
||||||
original(minecraft);
|
|
||||||
|
|
||||||
// Run Input Tick Functions
|
|
||||||
for (input_tick_function_t function : get_input_tick_functions()) {
|
|
||||||
function(minecraft);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Init
|
// Init
|
||||||
void init_input() {
|
void init_input() {
|
||||||
// Miscellaneous
|
// Miscellaneous
|
||||||
@ -43,9 +19,6 @@ void init_input() {
|
|||||||
// Enable Bow & Arrow Fix
|
// Enable Bow & Arrow Fix
|
||||||
_init_bow();
|
_init_bow();
|
||||||
|
|
||||||
// Loop
|
|
||||||
overwrite_calls(Minecraft_tickInput, Minecraft_tickInput_injection);
|
|
||||||
|
|
||||||
// Allow Attacking Mobs
|
// Allow Attacking Mobs
|
||||||
_init_attack();
|
_init_attack();
|
||||||
|
|
||||||
@ -53,4 +26,7 @@ void init_input() {
|
|||||||
if (feature_has("Disable Raw Mouse Motion (Not Recommended)", server_disabled)) {
|
if (feature_has("Disable Raw Mouse Motion (Not Recommended)", server_disabled)) {
|
||||||
media_set_raw_mouse_motion_enabled(0);
|
media_set_raw_mouse_motion_enabled(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Extra Key Codes
|
||||||
|
_init_keys();
|
||||||
}
|
}
|
||||||
|
24
mods/src/input/keys.cpp
Normal file
24
mods/src/input/keys.cpp
Normal file
@ -0,0 +1,24 @@
|
|||||||
|
#include <mods/input/input.h>
|
||||||
|
#include <symbols/minecraft.h>
|
||||||
|
#include <libreborn/libreborn.h>
|
||||||
|
#include <SDL/SDL.h>
|
||||||
|
|
||||||
|
#include "input-internal.h"
|
||||||
|
|
||||||
|
// Translator
|
||||||
|
static int32_t sdl_key_to_minecraft_key_injection(Common_sdl_key_to_minecraft_key_t original, int32_t sdl_key) {
|
||||||
|
switch (sdl_key) {
|
||||||
|
#define KEY(name, value) case SDLK_##name: return MC_KEY_##name;
|
||||||
|
#include <mods/input/key-list.h>
|
||||||
|
#undef KEY
|
||||||
|
default: {
|
||||||
|
// Call Original Method
|
||||||
|
return original(sdl_key);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Init
|
||||||
|
void _init_keys() {
|
||||||
|
overwrite_calls(Common_sdl_key_to_minecraft_key, sdl_key_to_minecraft_key_injection);
|
||||||
|
}
|
@ -1,25 +1,16 @@
|
|||||||
#include <libreborn/libreborn.h>
|
#include <libreborn/libreborn.h>
|
||||||
#include <symbols/minecraft.h>
|
#include <symbols/minecraft.h>
|
||||||
|
#include <SDL/SDL.h>
|
||||||
|
|
||||||
#include "input-internal.h"
|
#include "input-internal.h"
|
||||||
#include <mods/input/input.h>
|
#include <mods/input/input.h>
|
||||||
#include <mods/feature/feature.h>
|
#include <mods/feature/feature.h>
|
||||||
#include <mods/creative/creative.h>
|
#include <mods/creative/creative.h>
|
||||||
|
#include <mods/misc/misc.h>
|
||||||
|
|
||||||
// Enable Miscellaneous Input Fixes
|
// Enable Miscellaneous Input Fixes
|
||||||
static int enable_misc = 0;
|
static int enable_misc = 0;
|
||||||
|
|
||||||
// Store Back Button Presses
|
|
||||||
static int back_button_presses = 0;
|
|
||||||
int input_back() {
|
|
||||||
if (enable_misc) {
|
|
||||||
back_button_presses++;
|
|
||||||
return 1; // Handled
|
|
||||||
} else {
|
|
||||||
return 0; // Not Handled
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Handle Back Button Presses
|
// Handle Back Button Presses
|
||||||
static void _handle_back(Minecraft *minecraft) {
|
static void _handle_back(Minecraft *minecraft) {
|
||||||
// If Minecraft's Level property is initialized, but Minecraft's Player property is nullptr, then Minecraft::handleBack may crash.
|
// If Minecraft's Level property is initialized, but Minecraft's Player property is nullptr, then Minecraft::handleBack may crash.
|
||||||
@ -28,10 +19,7 @@ static void _handle_back(Minecraft *minecraft) {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
// Send Event
|
// Send Event
|
||||||
for (int i = 0; i < back_button_presses; i++) {
|
minecraft->handleBack(false);
|
||||||
minecraft->handleBack(0);
|
|
||||||
}
|
|
||||||
back_button_presses = 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Fix OptionsScreen Ignoring The Back Button
|
// Fix OptionsScreen Ignoring The Back Button
|
||||||
@ -52,32 +40,12 @@ static bool InBedScreen_handleBackEvent_injection(InBedScreen *screen, bool do_n
|
|||||||
// Stop Sleeping
|
// Stop Sleeping
|
||||||
LocalPlayer *player = minecraft->player;
|
LocalPlayer *player = minecraft->player;
|
||||||
if (player != nullptr) {
|
if (player != nullptr) {
|
||||||
player->stopSleepInBed(1, 1, 1);
|
player->stopSleepInBed(true, true, true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Set Mouse Grab State
|
|
||||||
static int mouse_grab_state = 0;
|
|
||||||
void input_set_mouse_grab_state(int state) {
|
|
||||||
mouse_grab_state = state;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Grab/Un-Grab Mouse
|
|
||||||
static void _handle_mouse_grab(Minecraft *minecraft) {
|
|
||||||
if (mouse_grab_state == -1) {
|
|
||||||
// Grab
|
|
||||||
minecraft->grabMouse();
|
|
||||||
} else if (mouse_grab_state == 1) {
|
|
||||||
// Un-Grab
|
|
||||||
minecraft->releaseMouse();
|
|
||||||
}
|
|
||||||
mouse_grab_state = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
#include <SDL/SDL.h>
|
|
||||||
|
|
||||||
// Block UI Interaction When Mouse Is Locked
|
// Block UI Interaction When Mouse Is Locked
|
||||||
static bool Gui_tickItemDrop_Minecraft_isCreativeMode_call_injection(Minecraft *minecraft) {
|
static bool Gui_tickItemDrop_Minecraft_isCreativeMode_call_injection(Minecraft *minecraft) {
|
||||||
bool is_in_game = minecraft->screen == nullptr || minecraft->screen->vtable == (Screen_vtable *) Touch_IngameBlockSelectionScreen_vtable_base;
|
bool is_in_game = minecraft->screen == nullptr || minecraft->screen->vtable == (Screen_vtable *) Touch_IngameBlockSelectionScreen_vtable_base;
|
||||||
@ -86,7 +54,7 @@ static bool Gui_tickItemDrop_Minecraft_isCreativeMode_call_injection(Minecraft *
|
|||||||
return creative_is_restricted() && minecraft->isCreativeMode();
|
return creative_is_restricted() && minecraft->isCreativeMode();
|
||||||
} else {
|
} else {
|
||||||
// Disable Item Drop Ticking
|
// Disable Item Drop Ticking
|
||||||
return 1;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -108,10 +76,16 @@ void _init_misc() {
|
|||||||
patch_vtable(InBedScreen_handleBackEvent, InBedScreen_handleBackEvent_injection);
|
patch_vtable(InBedScreen_handleBackEvent, InBedScreen_handleBackEvent_injection);
|
||||||
// Disable Opening Inventory Using The Cursor When Cursor Is Hidden
|
// Disable Opening Inventory Using The Cursor When Cursor Is Hidden
|
||||||
overwrite_calls(Gui_handleClick, Gui_handleClick_injection);
|
overwrite_calls(Gui_handleClick, Gui_handleClick_injection);
|
||||||
|
// Proper Back Button Handling
|
||||||
|
misc_run_on_key_press([](Minecraft *mc, const int key) {
|
||||||
|
if (key == MC_KEY_ESCAPE) {
|
||||||
|
_handle_back(mc);
|
||||||
|
return true;
|
||||||
|
} else {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
// Disable Item Dropping Using The Cursor When Cursor Is Hidden
|
// Disable Item Dropping Using The Cursor When Cursor Is Hidden
|
||||||
overwrite_call((void *) 0x27800, (void *) Gui_tickItemDrop_Minecraft_isCreativeMode_call_injection);
|
overwrite_call((void *) 0x27800, (void *) Gui_tickItemDrop_Minecraft_isCreativeMode_call_injection);
|
||||||
|
|
||||||
input_run_on_tick(_handle_back);
|
|
||||||
input_run_on_tick(_handle_mouse_grab);
|
|
||||||
}
|
}
|
||||||
|
@ -9,11 +9,11 @@
|
|||||||
// Handle Toggle Options
|
// Handle Toggle Options
|
||||||
static bool _handle_toggle_options(Minecraft *minecraft, int key) {
|
static bool _handle_toggle_options(Minecraft *minecraft, int key) {
|
||||||
Options *options = &minecraft->options;
|
Options *options = &minecraft->options;
|
||||||
if (key == 0x70) {
|
if (key == MC_KEY_F1) {
|
||||||
// Toggle Hide GUI
|
// Toggle Hide GUI
|
||||||
options->hide_gui = options->hide_gui ^ 1;
|
options->hide_gui = options->hide_gui ^ 1;
|
||||||
return true;
|
return true;
|
||||||
} else if (key == 0x74) {
|
} else if (key == MC_KEY_F5) {
|
||||||
// Toggle Third Person
|
// Toggle Third Person
|
||||||
options->third_person = (options->third_person + 1) % 3;
|
options->third_person = (options->third_person + 1) % 3;
|
||||||
return true;
|
return true;
|
||||||
|
@ -89,6 +89,15 @@ void misc_run_on_game_key_press(const std::function<bool(Minecraft *, int)> &fun
|
|||||||
original(self, key);
|
original(self, key);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
void misc_run_on_key_press(const std::function<bool(Minecraft *, int)> &func) {
|
||||||
|
misc_run_on_game_key_press(func);
|
||||||
|
overwrite_calls(Screen_keyPressed, [func](Screen_keyPressed_t original, Screen *self, int key) {
|
||||||
|
if (func(self->minecraft, key)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
original(self, key);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
// Render Fancy Background
|
// Render Fancy Background
|
||||||
void misc_render_background(int color, Minecraft *minecraft, int x, int y, int width, int height) {
|
void misc_render_background(int color, Minecraft *minecraft, int x, int y, int width, int height) {
|
||||||
|
@ -19,9 +19,11 @@
|
|||||||
|
|
||||||
#include <mods/init/init.h>
|
#include <mods/init/init.h>
|
||||||
#include <mods/feature/feature.h>
|
#include <mods/feature/feature.h>
|
||||||
#include "misc-internal.h"
|
#include <mods/input/input.h>
|
||||||
#include <mods/misc/misc.h>
|
#include <mods/misc/misc.h>
|
||||||
|
|
||||||
|
#include "misc-internal.h"
|
||||||
|
|
||||||
// Classic HUD
|
// Classic HUD
|
||||||
#define DEFAULT_HUD_PADDING 2
|
#define DEFAULT_HUD_PADDING 2
|
||||||
#define NEW_HUD_PADDING 1
|
#define NEW_HUD_PADDING 1
|
||||||
@ -134,12 +136,12 @@ static void Gui_renderChatMessages_injection(Gui_renderChatMessages_t original,
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Call Original Method
|
// Call Original Method
|
||||||
if (!hide_chat_messages && !is_in_chat) {
|
if (!hide_chat_messages && (!is_in_chat || disable_fading)) {
|
||||||
original(gui, y_offset, max_messages, disable_fading, font);
|
original(gui, y_offset, max_messages, disable_fading, font);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Render Selected Item Text
|
// Render Selected Item Text
|
||||||
if (render_selected_item_text) {
|
if (render_selected_item_text && !disable_fading) {
|
||||||
// Fix GL Mode
|
// Fix GL Mode
|
||||||
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
||||||
// Calculate Selected Item Text Scale
|
// Calculate Selected Item Text Scale
|
||||||
@ -361,7 +363,7 @@ int32_t misc_get_real_selected_slot(Player *player) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Properly Generate Buffers
|
// Properly Generate Buffers
|
||||||
static void anGenBuffers_injection(int32_t count, uint32_t *buffers) {
|
static void anGenBuffers_injection(__attribute__((unused)) Common_anGenBuffers_t original, const int32_t count, uint32_t *buffers) {
|
||||||
if (!reborn_is_headless()) {
|
if (!reborn_is_headless()) {
|
||||||
glGenBuffers(count, buffers);
|
glGenBuffers(count, buffers);
|
||||||
}
|
}
|
||||||
@ -829,7 +831,7 @@ void init_misc() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Properly Generate Buffers
|
// Properly Generate Buffers
|
||||||
overwrite(Common_anGenBuffers, anGenBuffers_injection);
|
overwrite_calls(Common_anGenBuffers, anGenBuffers_injection);
|
||||||
|
|
||||||
// Fix Graphics Bug When Switching To First-Person While Sneaking
|
// Fix Graphics Bug When Switching To First-Person While Sneaking
|
||||||
patch_vtable(PlayerRenderer_render, PlayerRenderer_render_injection);
|
patch_vtable(PlayerRenderer_render, PlayerRenderer_render_injection);
|
||||||
@ -904,7 +906,9 @@ void init_misc() {
|
|||||||
|
|
||||||
// Replace Block Highlight With Outline
|
// Replace Block Highlight With Outline
|
||||||
if (feature_has("Replace Block Highlight With Outline", server_disabled)) {
|
if (feature_has("Replace Block Highlight With Outline", server_disabled)) {
|
||||||
overwrite(LevelRenderer_renderHitSelect, LevelRenderer_renderHitOutline);
|
overwrite_calls(LevelRenderer_renderHitSelect, [](__attribute__((unused)) LevelRenderer_renderHitSelect_t original, LevelRenderer *self, Player *player, HitResult *hit_result, int i, void *vp, float f) {
|
||||||
|
self->renderHitOutline(player, hit_result, i, vp, f);
|
||||||
|
});
|
||||||
unsigned char fix_outline_patch[4] = {0x00, 0xf0, 0x20, 0xe3}; // "nop"
|
unsigned char fix_outline_patch[4] = {0x00, 0xf0, 0x20, 0xe3}; // "nop"
|
||||||
patch((void *) 0x4d830, fix_outline_patch);
|
patch((void *) 0x4d830, fix_outline_patch);
|
||||||
overwrite_call((void *) 0x4d764, (void *) LevelRenderer_render_AABB_glColor4f_injection);
|
overwrite_call((void *) 0x4d764, (void *) LevelRenderer_render_AABB_glColor4f_injection);
|
||||||
@ -968,6 +972,16 @@ void init_misc() {
|
|||||||
// Don't Wrap Text On '\r' Or '\t' Because THey Are Actual Characters In MCPI
|
// Don't Wrap Text On '\r' Or '\t' Because THey Are Actual Characters In MCPI
|
||||||
patch_address(&Strings::text_wrapping_delimiter, (void *) " \n");
|
patch_address(&Strings::text_wrapping_delimiter, (void *) " \n");
|
||||||
|
|
||||||
|
// Fullscreen
|
||||||
|
misc_run_on_key_press([](__attribute__((unused)) Minecraft *mc, int key) {
|
||||||
|
if (key == MC_KEY_F11) {
|
||||||
|
media_toggle_fullscreen();
|
||||||
|
return true;
|
||||||
|
} else {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
// Init Logging
|
// Init Logging
|
||||||
_init_misc_logging();
|
_init_misc_logging();
|
||||||
_init_misc_api();
|
_init_misc_api();
|
||||||
|
@ -13,7 +13,7 @@
|
|||||||
#include "options-internal.h"
|
#include "options-internal.h"
|
||||||
|
|
||||||
// Force Mob Spawning
|
// Force Mob Spawning
|
||||||
static bool LevelData_getSpawnMobs_injection(__attribute__((unused)) LevelData *level_data) {
|
static bool LevelData_getSpawnMobs_injection(__attribute__((unused)) LevelData_getSpawnMobs_t original, __attribute__((unused)) LevelData *level_data) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -101,7 +101,7 @@ static void Options_save_Options_addOptionToSaveOutput_injection(Options *option
|
|||||||
}
|
}
|
||||||
|
|
||||||
// MCPI's OptionsFile::getOptionStrings is broken, this is the version in v0.7.0
|
// MCPI's OptionsFile::getOptionStrings is broken, this is the version in v0.7.0
|
||||||
static std::vector<std::string> OptionsFile_getOptionStrings_injection(OptionsFile *options_file) {
|
static std::vector<std::string> OptionsFile_getOptionStrings_injection(__attribute__((unused)) OptionsFile_getOptionStrings_t original, OptionsFile *options_file) {
|
||||||
// Get options.txt Path
|
// Get options.txt Path
|
||||||
std::string path = options_file->options_txt_path;
|
std::string path = options_file->options_txt_path;
|
||||||
// Parse
|
// Parse
|
||||||
@ -145,7 +145,7 @@ static const char *get_new_options_txt_path() {
|
|||||||
void init_options() {
|
void init_options() {
|
||||||
// Force Mob Spawning
|
// Force Mob Spawning
|
||||||
if (feature_has("Force Mob Spawning", server_auto)) {
|
if (feature_has("Force Mob Spawning", server_auto)) {
|
||||||
overwrite(LevelData_getSpawnMobs, LevelData_getSpawnMobs_injection);
|
overwrite_calls(LevelData_getSpawnMobs, LevelData_getSpawnMobs_injection);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Render Distance
|
// Render Distance
|
||||||
@ -191,7 +191,7 @@ void init_options() {
|
|||||||
// When Loading, options.txt Should Be Opened In Read Mode
|
// When Loading, options.txt Should Be Opened In Read Mode
|
||||||
patch_address((void *) &Strings::options_txt_fopen_mode_when_loading, (void *) "r");
|
patch_address((void *) &Strings::options_txt_fopen_mode_when_loading, (void *) "r");
|
||||||
// Fix OptionsFile::getOptionStrings
|
// Fix OptionsFile::getOptionStrings
|
||||||
overwrite(OptionsFile_getOptionStrings, OptionsFile_getOptionStrings_injection);
|
overwrite_calls(OptionsFile_getOptionStrings, OptionsFile_getOptionStrings_injection);
|
||||||
|
|
||||||
// Sensitivity Loading/Saving Is Broken, Disable It
|
// Sensitivity Loading/Saving Is Broken, Disable It
|
||||||
patch((void *) 0x1931c, nop_patch);
|
patch((void *) 0x1931c, nop_patch);
|
||||||
|
@ -11,12 +11,22 @@
|
|||||||
|
|
||||||
#include <libreborn/libreborn.h>
|
#include <libreborn/libreborn.h>
|
||||||
#include <GLES/gl.h>
|
#include <GLES/gl.h>
|
||||||
|
#include <symbols/minecraft.h>
|
||||||
|
|
||||||
#include <mods/screenshot/screenshot.h>
|
#include <mods/screenshot/screenshot.h>
|
||||||
|
#include <mods/home/home.h>
|
||||||
|
#include <mods/misc/misc.h>
|
||||||
|
#include <mods/input/input.h>
|
||||||
|
#include <mods/init/init.h>
|
||||||
|
|
||||||
// Ensure Screenshots Folder Exists
|
// Ensure Screenshots Folder Exists
|
||||||
static void ensure_screenshots_folder(const char *screenshots) {
|
static std::string get_screenshot_dir() {
|
||||||
// Check Screenshots Folder
|
std::string dir = std::string(home_get()) + "/screenshots";
|
||||||
ensure_directory(screenshots);
|
ensure_directory(dir.c_str());
|
||||||
|
return dir;
|
||||||
|
}
|
||||||
|
static std::string get_screenshot(const std::string &filename) {
|
||||||
|
return get_screenshot_dir() + '/' + filename;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Take Screenshot
|
// Take Screenshot
|
||||||
@ -27,15 +37,12 @@ static int save_png(const char *filename, unsigned char *pixels, int line_size,
|
|||||||
// Write Image
|
// Write Image
|
||||||
return !stbi_write_png(filename, width, height, 4, pixels, line_size);
|
return !stbi_write_png(filename, width, height, 4, pixels, line_size);
|
||||||
}
|
}
|
||||||
void screenshot_take(const char *home) {
|
void screenshot_take(Gui *gui) {
|
||||||
// Check
|
// Check
|
||||||
if (reborn_is_headless()) {
|
if (reborn_is_headless()) {
|
||||||
IMPOSSIBLE();
|
IMPOSSIBLE();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get Directory
|
|
||||||
const std::string screenshots = std::string(home) + "/screenshots";
|
|
||||||
|
|
||||||
// Get Timestamp
|
// Get Timestamp
|
||||||
time_t raw_time;
|
time_t raw_time;
|
||||||
time(&raw_time);
|
time(&raw_time);
|
||||||
@ -43,16 +50,18 @@ void screenshot_take(const char *home) {
|
|||||||
char time[512];
|
char time[512];
|
||||||
strftime(time, 512, "%Y-%m-%d_%H.%M.%S", time_info);
|
strftime(time, 512, "%Y-%m-%d_%H.%M.%S", time_info);
|
||||||
|
|
||||||
// Ensure Screenshots Folder Exists
|
|
||||||
ensure_screenshots_folder(screenshots.c_str());
|
|
||||||
|
|
||||||
// Prevent Overwriting Screenshots
|
// Prevent Overwriting Screenshots
|
||||||
int num = 1;
|
int num = 0;
|
||||||
std::string file = screenshots + '/' + time + ".png";
|
std::string filename;
|
||||||
while (access(file.c_str(), F_OK) != -1) {
|
do {
|
||||||
file = screenshots + '/' + time + '-' + std::to_string(num) + ".png";
|
filename = std::string(time);
|
||||||
num++;
|
if (num > 0) {
|
||||||
|
filename += '-' + std::to_string(num);
|
||||||
}
|
}
|
||||||
|
filename += ".png";
|
||||||
|
num++;
|
||||||
|
} while (access(get_screenshot(filename).c_str(), F_OK) != -1);
|
||||||
|
const std::string file = get_screenshot(filename);
|
||||||
|
|
||||||
// Get Image Size
|
// Get Image Size
|
||||||
GLint viewport[4];
|
GLint viewport[4];
|
||||||
@ -85,9 +94,29 @@ void screenshot_take(const char *home) {
|
|||||||
if (save_png(file.c_str(), pixels, line_size, width, height)) {
|
if (save_png(file.c_str(), pixels, line_size, width, height)) {
|
||||||
WARN("Screenshot Failed: %s", file.c_str());
|
WARN("Screenshot Failed: %s", file.c_str());
|
||||||
} else {
|
} else {
|
||||||
INFO("Screenshot Saved: %s", file.c_str());
|
std::string msg = "Screenshot Saved: ";
|
||||||
|
INFO("%s%s", msg.c_str(), file.c_str());
|
||||||
|
if (gui) {
|
||||||
|
msg += filename;
|
||||||
|
gui->addMessage(&msg);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Free
|
// Free
|
||||||
free(pixels);
|
free(pixels);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Init
|
||||||
|
void init_screenshot() {
|
||||||
|
// Create Directory
|
||||||
|
get_screenshot_dir();
|
||||||
|
// Take Screenshot On F2
|
||||||
|
misc_run_on_key_press([](Minecraft *mc, int key) {
|
||||||
|
if (key == MC_KEY_F2) {
|
||||||
|
screenshot_take(&mc->gui);
|
||||||
|
return true;
|
||||||
|
} else {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
@ -16,7 +16,6 @@
|
|||||||
#include <symbols/minecraft.h>
|
#include <symbols/minecraft.h>
|
||||||
|
|
||||||
#include <mods/server/server.h>
|
#include <mods/server/server.h>
|
||||||
#include <mods/feature/feature.h>
|
|
||||||
#include <mods/init/init.h>
|
#include <mods/init/init.h>
|
||||||
#include <mods/home/home.h>
|
#include <mods/home/home.h>
|
||||||
#include <mods/compat/compat.h>
|
#include <mods/compat/compat.h>
|
||||||
@ -202,23 +201,6 @@ static void list_callback(Minecraft *minecraft, const std::string &username, Pla
|
|||||||
INFO(" - %s (%s)", username.c_str(), get_player_ip(minecraft, player));
|
INFO(" - %s (%s)", username.c_str(), get_player_ip(minecraft, player));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Handle Server Stop
|
|
||||||
static void handle_server_stop(Minecraft *minecraft) {
|
|
||||||
if (compat_check_exit_requested()) {
|
|
||||||
INFO("Stopping Server");
|
|
||||||
// Save And Exit
|
|
||||||
Level *level = get_level(minecraft);
|
|
||||||
if (level != nullptr) {
|
|
||||||
level->saveLevelData();
|
|
||||||
}
|
|
||||||
minecraft->leaveGame(false);
|
|
||||||
// Stop Game
|
|
||||||
SDL_Event event;
|
|
||||||
event.type = SDL_QUIT;
|
|
||||||
SDL_PushEvent(&event);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Track TPS
|
// Track TPS
|
||||||
#define NANOSECONDS_IN_SECOND 1000000000ll
|
#define NANOSECONDS_IN_SECOND 1000000000ll
|
||||||
static long long int get_time() {
|
static long long int get_time() {
|
||||||
@ -248,52 +230,55 @@ static ServerSideNetworkHandler *get_server_side_network_handler(Minecraft *mine
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Read STDIN Thread
|
// Read STDIN Thread
|
||||||
static volatile bool stdin_buffer_complete = false;
|
static pthread_t read_stdin_thread_obj;
|
||||||
static volatile char *stdin_buffer = nullptr;
|
static volatile bool stdin_line_ready = false;
|
||||||
|
static std::string stdin_line;
|
||||||
static void *read_stdin_thread(__attribute__((unused)) void *data) {
|
static void *read_stdin_thread(__attribute__((unused)) void *data) {
|
||||||
// Loop
|
// Loop
|
||||||
while (true) {
|
char *line = nullptr;
|
||||||
int bytes_available;
|
size_t len = 0;
|
||||||
if (ioctl(fileno(stdin), FIONREAD, &bytes_available) == -1) {
|
while (getline(&line, &len, stdin) != -1) {
|
||||||
bytes_available = 0;
|
stdin_line = line;
|
||||||
}
|
stdin_line_ready = true;
|
||||||
char buffer[bytes_available];
|
// Wait For Line To Be Read
|
||||||
bytes_available = read(fileno(stdin), (void *) buffer, bytes_available);
|
while (stdin_line_ready) {}
|
||||||
for (int i = 0; i < bytes_available; i++) {
|
|
||||||
if (!stdin_buffer_complete) {
|
|
||||||
// Read Data
|
|
||||||
char x = buffer[i];
|
|
||||||
if (x == '\n') {
|
|
||||||
if (stdin_buffer == nullptr) {
|
|
||||||
stdin_buffer = (volatile char *) malloc(1);
|
|
||||||
stdin_buffer[0] = '\0';
|
|
||||||
}
|
|
||||||
stdin_buffer_complete = true;
|
|
||||||
} else {
|
|
||||||
string_append((char **) &stdin_buffer, "%c", (char) x);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
free(line);
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
__attribute__((destructor)) static void _free_stdin_buffer() {
|
|
||||||
if (stdin_buffer != nullptr) {
|
// Handle Server Stop
|
||||||
free((void *) stdin_buffer);
|
static void handle_server_stop(Minecraft *minecraft) {
|
||||||
stdin_buffer = nullptr;
|
if (compat_check_exit_requested()) {
|
||||||
|
INFO("Stopping Server");
|
||||||
|
// Save And Exit
|
||||||
|
Level *level = get_level(minecraft);
|
||||||
|
if (level != nullptr) {
|
||||||
|
level->saveLevelData();
|
||||||
|
}
|
||||||
|
minecraft->leaveGame(false);
|
||||||
|
// Kill Reader Thread
|
||||||
|
pthread_cancel(read_stdin_thread_obj);
|
||||||
|
pthread_join(read_stdin_thread_obj, nullptr);
|
||||||
|
stdin_line_ready = false;
|
||||||
|
// Stop Game
|
||||||
|
SDL_Event event;
|
||||||
|
event.type = SDL_QUIT;
|
||||||
|
SDL_PushEvent(&event);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Handle Commands
|
// Handle Commands
|
||||||
static void handle_commands(Minecraft *minecraft) {
|
static void handle_commands(Minecraft *minecraft) {
|
||||||
// Check If Level Is Generated
|
// Check If Level Is Generated
|
||||||
if (minecraft->isLevelGenerated() && stdin_buffer_complete) {
|
if (minecraft->isLevelGenerated() && stdin_line_ready) {
|
||||||
|
// Read Line
|
||||||
|
std::string data = std::move(stdin_line);
|
||||||
|
data.pop_back(); // Remove Newline
|
||||||
|
stdin_line_ready = false;
|
||||||
// Command Ready; Run It
|
// Command Ready; Run It
|
||||||
if (stdin_buffer != nullptr) {
|
|
||||||
ServerSideNetworkHandler *server_side_network_handler = get_server_side_network_handler(minecraft);
|
ServerSideNetworkHandler *server_side_network_handler = get_server_side_network_handler(minecraft);
|
||||||
if (server_side_network_handler != nullptr) {
|
if (server_side_network_handler != nullptr) {
|
||||||
std::string data((char *) stdin_buffer);
|
|
||||||
|
|
||||||
static std::string ban_command("ban ");
|
static std::string ban_command("ban ");
|
||||||
static std::string say_command("say ");
|
static std::string say_command("say ");
|
||||||
static std::string kill_command("kill ");
|
static std::string kill_command("kill ");
|
||||||
@ -348,12 +333,6 @@ static void handle_commands(Minecraft *minecraft) {
|
|||||||
INFO("Invalid Command: %s", data.c_str());
|
INFO("Invalid Command: %s", data.c_str());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Free
|
|
||||||
free((void *) stdin_buffer);
|
|
||||||
stdin_buffer = nullptr;
|
|
||||||
}
|
|
||||||
stdin_buffer_complete = false;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -577,7 +556,6 @@ static void server_init() {
|
|||||||
misc_run_on_tick(Minecraft_tick_injection);
|
misc_run_on_tick(Minecraft_tick_injection);
|
||||||
|
|
||||||
// Start Reading STDIN
|
// Start Reading STDIN
|
||||||
pthread_t read_stdin_thread_obj;
|
|
||||||
pthread_create(&read_stdin_thread_obj, nullptr, read_stdin_thread, nullptr);
|
pthread_create(&read_stdin_thread_obj, nullptr, read_stdin_thread, nullptr);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,34 +1,12 @@
|
|||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
#include <SDL/SDL.h>
|
|
||||||
#include <libreborn/libreborn.h>
|
#include <libreborn/libreborn.h>
|
||||||
#include <symbols/minecraft.h>
|
#include <symbols/minecraft.h>
|
||||||
|
|
||||||
#include <mods/init/init.h>
|
#include <mods/init/init.h>
|
||||||
#include <mods/feature/feature.h>
|
#include <mods/feature/feature.h>
|
||||||
#include <mods/input/input.h>
|
|
||||||
#include <mods/sign/sign.h>
|
#include <mods/sign/sign.h>
|
||||||
|
|
||||||
// Handle Backspace
|
|
||||||
static int32_t sdl_key_to_minecraft_key_injection(Common_sdl_key_to_minecraft_key_t original, int32_t sdl_key) {
|
|
||||||
if (sdl_key == SDLK_BACKSPACE) {
|
|
||||||
return 0x8;
|
|
||||||
} else if (sdl_key == SDLK_DELETE) {
|
|
||||||
return 0x2e;
|
|
||||||
} else if (sdl_key == SDLK_LEFT) {
|
|
||||||
return 0x25;
|
|
||||||
} else if (sdl_key == SDLK_RIGHT) {
|
|
||||||
return 0x27;
|
|
||||||
} else if (sdl_key == SDLK_F1) {
|
|
||||||
return 0x70;
|
|
||||||
} else if (sdl_key == SDLK_F5) {
|
|
||||||
return 0x74;
|
|
||||||
} else {
|
|
||||||
// Call Original Method
|
|
||||||
return original(sdl_key);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Open Sign Screen
|
// Open Sign Screen
|
||||||
static void LocalPlayer_openTextEdit_injection(LocalPlayer *local_player, TileEntity *sign) {
|
static void LocalPlayer_openTextEdit_injection(LocalPlayer *local_player, TileEntity *sign) {
|
||||||
if (sign->type == 4) {
|
if (sign->type == 4) {
|
||||||
@ -41,7 +19,7 @@ static void LocalPlayer_openTextEdit_injection(LocalPlayer *local_player, TileEn
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Store Text Input
|
// Store Text Input
|
||||||
void sign_key_press(char key) {
|
void sign_key_press(const char key) {
|
||||||
Keyboard::_inputText.push_back(key);
|
Keyboard::_inputText.push_back(key);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -51,7 +29,4 @@ void init_sign() {
|
|||||||
// Fix Signs
|
// Fix Signs
|
||||||
patch_vtable(LocalPlayer_openTextEdit, LocalPlayer_openTextEdit_injection);
|
patch_vtable(LocalPlayer_openTextEdit, LocalPlayer_openTextEdit_injection);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Handle Backspace
|
|
||||||
overwrite_calls(Common_sdl_key_to_minecraft_key, sdl_key_to_minecraft_key_injection);
|
|
||||||
}
|
}
|
||||||
|
@ -79,10 +79,6 @@ static int32_t Textures_loadAndBindTexture_injection(Textures *textures, __attri
|
|||||||
|
|
||||||
// Init
|
// Init
|
||||||
void init_skin() {
|
void init_skin() {
|
||||||
// Not Needed On Headless Mode
|
|
||||||
if (reborn_is_headless()) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
// Check Feature Flag
|
// Check Feature Flag
|
||||||
if (feature_has("Load Custom Skins", server_disabled)) {
|
if (feature_has("Load Custom Skins", server_disabled)) {
|
||||||
// LocalPlayer
|
// LocalPlayer
|
||||||
|
@ -69,15 +69,15 @@ static void play(std::string name, float x, float y, float z, float volume, floa
|
|||||||
media_audio_play(source.c_str(), resolved_name.c_str(), x, y, z, pitch, volume, is_ui);
|
media_audio_play(source.c_str(), resolved_name.c_str(), x, y, z, pitch, volume, is_ui);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
static void SoundEngine_playUI_injection(__attribute__((unused)) SoundEngine *sound_engine, std::string *name, float volume, float pitch) {
|
static void SoundEngine_playUI_injection(__attribute__((unused)) SoundEngine_playUI_t original, __attribute__((unused)) SoundEngine *sound_engine, std::string *name, float volume, float pitch) {
|
||||||
play(*name, 0, 0, 0, volume, pitch, true);
|
play(*name, 0, 0, 0, volume, pitch, true);
|
||||||
}
|
}
|
||||||
static void SoundEngine_play_injection(__attribute__((unused)) SoundEngine *sound_engine, std::string *name, float x, float y, float z, float volume, float pitch) {
|
static void SoundEngine_play_injection(__attribute__((unused)) SoundEngine_play_t original, __attribute__((unused)) SoundEngine *sound_engine, std::string *name, float x, float y, float z, float volume, float pitch) {
|
||||||
play(*name, x, y, z, volume, pitch, false);
|
play(*name, x, y, z, volume, pitch, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Refresh Data
|
// Refresh Data
|
||||||
static void SoundEngine_update_injection(SoundEngine *sound_engine, Mob *listener_mob, __attribute__((unused)) float listener_angle) {
|
static void SoundEngine_update_injection(__attribute__((unused)) SoundEngine_update_t original, SoundEngine *sound_engine, Mob *listener_mob, __attribute__((unused)) float listener_angle) {
|
||||||
// Variables
|
// Variables
|
||||||
static float volume = 0;
|
static float volume = 0;
|
||||||
static float x = 0;
|
static float x = 0;
|
||||||
@ -117,15 +117,11 @@ static void SoundEngine_init_injection(SoundEngine_init_t original, SoundEngine
|
|||||||
|
|
||||||
// Init
|
// Init
|
||||||
void init_sound() {
|
void init_sound() {
|
||||||
// Not Needed On Headless Mode
|
|
||||||
if (reborn_is_headless()) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
// Implement Sound Engine
|
// Implement Sound Engine
|
||||||
if (feature_has("Implement Sound Engine", server_disabled)) {
|
if (feature_has("Implement Sound Engine", server_disabled)) {
|
||||||
overwrite(SoundEngine_playUI, SoundEngine_playUI_injection);
|
overwrite_calls(SoundEngine_playUI, SoundEngine_playUI_injection);
|
||||||
overwrite(SoundEngine_play, SoundEngine_play_injection);
|
overwrite_calls(SoundEngine_play, SoundEngine_play_injection);
|
||||||
overwrite(SoundEngine_update, SoundEngine_update_injection);
|
overwrite_calls(SoundEngine_update, SoundEngine_update_injection);
|
||||||
overwrite_calls(SoundEngine_init, SoundEngine_init_injection);
|
overwrite_calls(SoundEngine_init, SoundEngine_init_injection);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
#include <libreborn/libreborn.h>
|
#include <libreborn/libreborn.h>
|
||||||
|
|
||||||
#include <mods/text-input-box/TextInputBox.h>
|
#include <mods/text-input-box/TextInputBox.h>
|
||||||
|
#include <mods/input/input.h>
|
||||||
|
|
||||||
TextInputBox *TextInputBox::create(const std::string &placeholder, const std::string &text) {
|
TextInputBox *TextInputBox::create(const std::string &placeholder, const std::string &text) {
|
||||||
// Construct
|
// Construct
|
||||||
@ -49,7 +50,7 @@ void TextInputBox::keyPressed(int key) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
switch (key) {
|
switch (key) {
|
||||||
case 0x8: {
|
case MC_KEY_BACKSPACE: {
|
||||||
// Backspace
|
// Backspace
|
||||||
if (m_text.empty()) {
|
if (m_text.empty()) {
|
||||||
return;
|
return;
|
||||||
@ -65,7 +66,7 @@ void TextInputBox::keyPressed(int key) {
|
|||||||
recalculateScroll();
|
recalculateScroll();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case 0x2e: {
|
case MC_KEY_DELETE: {
|
||||||
// Delete
|
// Delete
|
||||||
if (m_text.empty()) {
|
if (m_text.empty()) {
|
||||||
return;
|
return;
|
||||||
@ -79,7 +80,7 @@ void TextInputBox::keyPressed(int key) {
|
|||||||
m_text.erase(m_text.begin() + m_insertHead, m_text.begin() + m_insertHead + 1);
|
m_text.erase(m_text.begin() + m_insertHead, m_text.begin() + m_insertHead + 1);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case 0x25: {
|
case MC_KEY_LEFT: {
|
||||||
// Left
|
// Left
|
||||||
m_insertHead--;
|
m_insertHead--;
|
||||||
if (m_insertHead < 0) {
|
if (m_insertHead < 0) {
|
||||||
@ -88,7 +89,7 @@ void TextInputBox::keyPressed(int key) {
|
|||||||
recalculateScroll();
|
recalculateScroll();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case 0x27: {
|
case MC_KEY_RIGHT: {
|
||||||
// Right
|
// Right
|
||||||
m_insertHead++;
|
m_insertHead++;
|
||||||
if (!m_text.empty()) {
|
if (!m_text.empty()) {
|
||||||
@ -101,7 +102,7 @@ void TextInputBox::keyPressed(int key) {
|
|||||||
recalculateScroll();
|
recalculateScroll();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case 0x0d: {
|
case MC_KEY_RETURN: {
|
||||||
// Enter
|
// Enter
|
||||||
m_bFocused = false;
|
m_bFocused = false;
|
||||||
break;
|
break;
|
||||||
|
@ -7,8 +7,8 @@
|
|||||||
#include <symbols/minecraft.h>
|
#include <symbols/minecraft.h>
|
||||||
|
|
||||||
// Enable Touch GUI
|
// Enable Touch GUI
|
||||||
static int32_t Minecraft_isTouchscreen_injection(__attribute__((unused)) Minecraft *minecraft) {
|
static bool Minecraft_isTouchscreen_injection(__attribute__((unused)) Minecraft_isTouchscreen_t original, __attribute__((unused)) Minecraft *minecraft) {
|
||||||
return 1;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
// IngameBlockSelectionScreen Memory Allocation Override
|
// IngameBlockSelectionScreen Memory Allocation Override
|
||||||
@ -17,7 +17,7 @@ static unsigned char *operator_new_IngameBlockSelectionScreen_injection(__attrib
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Improved Button Hover Behavior
|
// Improved Button Hover Behavior
|
||||||
static int32_t Button_hovered_injection(__attribute__((unused)) Button *button, __attribute__((unused)) Minecraft *minecraft, __attribute__((unused)) int32_t click_x, __attribute__((unused)) int32_t click_y) {
|
static int32_t Button_hovered_injection(__attribute__((unused)) Button_hovered_t original, __attribute__((unused)) Button *button, __attribute__((unused)) Minecraft *minecraft, __attribute__((unused)) int32_t click_x, __attribute__((unused)) int32_t click_y) {
|
||||||
// Get Mouse Position
|
// Get Mouse Position
|
||||||
int32_t x = Mouse::getX() * Gui::InvGuiScale;
|
int32_t x = Mouse::getX() * Gui::InvGuiScale;
|
||||||
int32_t y = Mouse::getY() * Gui::InvGuiScale;
|
int32_t y = Mouse::getY() * Gui::InvGuiScale;
|
||||||
@ -33,7 +33,7 @@ static int32_t Button_hovered_injection(__attribute__((unused)) Button *button,
|
|||||||
}
|
}
|
||||||
static void LargeImageButton_render_GuiComponent_drawCenteredString_injection(GuiComponent *component, Font *font, std::string *text, int32_t x, int32_t y, int32_t color) {
|
static void LargeImageButton_render_GuiComponent_drawCenteredString_injection(GuiComponent *component, Font *font, std::string *text, int32_t x, int32_t y, int32_t color) {
|
||||||
// Change Color On Hover
|
// Change Color On Hover
|
||||||
if (color == 0xe0e0e0 && Button_hovered_injection((Button *) component, nullptr, 0, 0)) {
|
if (color == 0xe0e0e0 && Button_hovered_injection(nullptr, (Button *) component, nullptr, 0, 0)) {
|
||||||
color = 0xffffa0;
|
color = 0xffffa0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -64,7 +64,7 @@ void init_touch() {
|
|||||||
int touch_buttons = touch_gui;
|
int touch_buttons = touch_gui;
|
||||||
if (touch_gui) {
|
if (touch_gui) {
|
||||||
// Main UI
|
// Main UI
|
||||||
overwrite(Minecraft_isTouchscreen, Minecraft_isTouchscreen_injection);
|
overwrite_calls(Minecraft_isTouchscreen, Minecraft_isTouchscreen_injection);
|
||||||
|
|
||||||
// Force Correct Toolbar Size
|
// Force Correct Toolbar Size
|
||||||
unsigned char toolbar_patch[4] = {0x01, 0x00, 0x50, 0xe3}; // "cmp r0, #0x1"
|
unsigned char toolbar_patch[4] = {0x01, 0x00, 0x50, 0xe3}; // "cmp r0, #0x1"
|
||||||
@ -97,7 +97,7 @@ void init_touch() {
|
|||||||
|
|
||||||
// Improved Button Hover Behavior
|
// Improved Button Hover Behavior
|
||||||
if (touch_buttons && feature_has("Improved Button Hover Behavior", server_disabled)) {
|
if (touch_buttons && feature_has("Improved Button Hover Behavior", server_disabled)) {
|
||||||
overwrite(Button_hovered, Button_hovered_injection);
|
overwrite_calls(Button_hovered, Button_hovered_injection);
|
||||||
overwrite_call((void *) 0x1ebd4, (void *) LargeImageButton_render_GuiComponent_drawCenteredString_injection);
|
overwrite_call((void *) 0x1ebd4, (void *) LargeImageButton_render_GuiComponent_drawCenteredString_injection);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -16,7 +16,7 @@ const char *version_get() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Injection For Touch GUI Version
|
// Injection For Touch GUI Version
|
||||||
static std::string Common_getGameVersionString_injection(__attribute__((unused)) std::string *version_suffix) {
|
static std::string Common_getGameVersionString_injection(__attribute__((unused)) Common_getGameVersionString_t original, __attribute__((unused)) std::string *version_suffix) {
|
||||||
// Set Version
|
// Set Version
|
||||||
return version_get();
|
return version_get();
|
||||||
}
|
}
|
||||||
@ -24,7 +24,7 @@ static std::string Common_getGameVersionString_injection(__attribute__((unused))
|
|||||||
// Init
|
// Init
|
||||||
void init_version() {
|
void init_version() {
|
||||||
// Touch GUI
|
// Touch GUI
|
||||||
overwrite(Common_getGameVersionString, Common_getGameVersionString_injection);
|
overwrite_calls(Common_getGameVersionString, Common_getGameVersionString_injection);
|
||||||
// Normal GUI
|
// Normal GUI
|
||||||
patch_address((void *) &Strings::minecraft_pi_version, (void *) version_get());
|
patch_address((void *) &Strings::minecraft_pi_version, (void *) version_get());
|
||||||
|
|
||||||
|
@ -1,3 +1,3 @@
|
|||||||
vtable 0x102540;
|
vtable 0x102540;
|
||||||
|
|
||||||
virtual-method int tickBuild(Player *player, uint *build_action_intention_return) = 0xc;
|
virtual-method bool tickBuild(Player *player, uint *build_action_intention_return) = 0xc;
|
||||||
|
Loading…
Reference in New Issue
Block a user