Move Some Stuff Around

This commit is contained in:
TheBrokenRail 2024-11-22 00:47:38 -05:00
parent 596ff01f75
commit 66d2e43f55
23 changed files with 162 additions and 182 deletions

View File

@ -70,6 +70,7 @@
* `Screenshot Support` * `Screenshot Support`
* `Fix Camera Functionality` * `Fix Camera Functionality`
* `Property Scale Animated Textures` * `Property Scale Animated Textures`
* `Enable Text Input`
* Split Up `Remove Creative Mode Restrictions` Feature Flag * Split Up `Remove Creative Mode Restrictions` Feature Flag
* `Remove Creative Mode Restrictions` (Disabled By Default) * `Remove Creative Mode Restrictions` (Disabled By Default)
* `Display Slot Count In Creative Mode` (Disabled By Default) * `Display Slot Count In Creative Mode` (Disabled By Default)
@ -79,6 +80,7 @@
* Rename Feature Flags * Rename Feature Flags
* `Disable Buggy Held Item Caching` To `Fix Held Item Caching` * `Disable Buggy Held Item Caching` To `Fix Held Item Caching`
* `Disable 'gui_blocks' Atlas` To `Regenerate "gui_blocks" Atlas` * `Disable 'gui_blocks' Atlas` To `Regenerate "gui_blocks" Atlas`
* `Fix Sign Placement` To `Enable Sign Screen`
* Add Milk Buckets * Add Milk Buckets
* Included In The `Add Buckets` Feature Flag * Included In The `Add Buckets` Feature Flag
* Removed `Property Scale Animated Textures` Feature Flag * Removed `Property Scale Animated Textures` Feature Flag

View File

@ -1,11 +1,11 @@
#pragma once #pragma once
// GLFW Helpers // GLFW Helpers
#ifdef GLFW_VERSION_MAJOR #ifndef GLFW_VERSION_MAJOR
#error "Missing GLFW"
#endif
void init_glfw(); void init_glfw();
GLFWwindow *create_glfw_window(const char *title, int width, int height); GLFWwindow *create_glfw_window(const char *title, int width, int height);
void cleanup_glfw(GLFWwindow *window); void cleanup_glfw(GLFWwindow *window);
void get_glfw_scale(GLFWwindow *window, float *x_scale, float *y_scale); void get_glfw_scale(GLFWwindow *window, float *x_scale, float *y_scale);
#endif

View File

@ -1,10 +0,0 @@
#pragma once
#include <libreborn/config.h>
#include "env.h"
#include "log.h"
#include "util.h"
#include "string.h"
#include "exec.h"
#include "patch.h"
#include "glfw.h"

View File

@ -3,7 +3,9 @@
#include "log.h" #include "log.h"
// Patching Functions // Patching Functions
#ifdef REBORN_HAS_PATCH_CODE #ifndef REBORN_HAS_PATCH_CODE
#error "Missing Patching Functions"
#endif
// Init // Init
void reborn_init_patch(); void reborn_init_patch();
@ -50,5 +52,3 @@ void patch_vtable(const T *start, typename T::ptr_type target) {
} }
patch_address((void *) start->get_vtable_addr(), (void *) target); patch_address((void *) start->get_vtable_addr(), (void *) target);
} }
#endif

View File

@ -26,6 +26,7 @@ CATEGORY User Interface
TRUE Implement Create World Dialog TRUE Implement Create World Dialog
TRUE Display Date In Select World Screen TRUE Display Date In Select World Screen
TRUE Add Welcome Screen TRUE Add Welcome Screen
TRUE Enable Sign Screen
CATEGORY HUD CATEGORY HUD
TRUE Classic HUD TRUE Classic HUD
TRUE Translucent Toolbar TRUE Translucent Toolbar
@ -84,6 +85,7 @@ CATEGORY Input
FALSE Disable Raw Mouse Motion (Not Recommended) FALSE Disable Raw Mouse Motion (Not Recommended)
FALSE Disable Speed Bridging FALSE Disable Speed Bridging
FALSE Disable Creative Mode Mining Delay FALSE Disable Creative Mode Mining Delay
TRUE Enable Text Input
CATEGORY Multiplayer CATEGORY Multiplayer
CATEGORY Chat CATEGORY Chat
TRUE Implement Chat TRUE Implement Chat
@ -96,7 +98,6 @@ CATEGORY Gameplay
TRUE Implement Death Messages TRUE Implement Death Messages
TRUE Implement Game-Mode Switching TRUE Implement Game-Mode Switching
FALSE Force Mob Spawning FALSE Force Mob Spawning
TRUE Fix Sign Placement
TRUE Add Buckets TRUE Add Buckets
TRUE Load Custom Skins TRUE Load Custom Skins
TRUE Add Cake TRUE Add Cake

View File

@ -4,12 +4,12 @@ project(mods)
add_library(mods SHARED add_library(mods SHARED
# compat # compat
src/compat/compat.cpp src/compat/compat.cpp
src/compat/egl.cpp src/compat/readdir.cpp
src/compat/x11.cpp
src/compat/bcm_host.cpp
src/compat/sdl.cpp src/compat/sdl.cpp
# readdir src/compat/stubs/egl.cpp
src/readdir/readdir.cpp src/compat/stubs/x11.cpp
src/compat/stubs/bcm_host.cpp
src/compat/stubs/sdl.cpp
# feature # feature
src/feature/feature.cpp src/feature/feature.cpp
# version # version
@ -63,8 +63,6 @@ add_library(mods SHARED
src/input/misc.cpp src/input/misc.cpp
src/input/drop.cpp src/input/drop.cpp
src/input/keys.cpp src/input/keys.cpp
# sign
src/sign/sign.cpp
# atlas # atlas
src/atlas/atlas.cpp src/atlas/atlas.cpp
# title-screen # title-screen

View File

@ -8,7 +8,6 @@ void init_multiplayer();
void init_benchmark(); void init_benchmark();
void init_sound(); void init_sound();
void init_input(); void init_input();
void init_sign();
void init_camera(); void init_camera();
void init_atlas(); void init_atlas();
void init_title_screen(); void init_title_screen();

View File

@ -1,5 +0,0 @@
#pragma once
extern "C" {
void sign_key_press(char key);
}

View File

@ -1,2 +1,2 @@
# `compat` Mod # `compat` Mod
This utility mod sends keyboard input to other mods. It also patches out all EGL and X11 calls. This utility mod ensures compatibility with the host system. This includes fixing events, handling signals, and patching out bad function calls.

View File

@ -1,6 +1,10 @@
#pragma once #pragma once
// Stubs
__attribute__((visibility("internal"))) void _patch_egl_calls(); __attribute__((visibility("internal"))) void _patch_egl_calls();
__attribute__((visibility("internal"))) void _patch_x11_calls(); __attribute__((visibility("internal"))) void _patch_x11_calls();
__attribute__((visibility("internal"))) void _patch_bcm_host_calls(); __attribute__((visibility("internal"))) void _patch_bcm_host_calls();
__attribute__((visibility("internal"))) void _patch_sdl_calls(); __attribute__((visibility("internal"))) void _patch_sdl_calls();
// Functionality
__attribute__((visibility("internal"))) void _init_compat_sdl();

View File

@ -1,92 +1,19 @@
#include <unistd.h> #include <unistd.h>
#include <csignal> #include <csignal>
#include <cerrno>
#include <mods/compat/compat.h> #include <mods/compat/compat.h>
#include <mods/init/init.h> #include <mods/init/init.h>
#include "compat-internal.h" #include "compat-internal.h"
#include <libreborn/log.h>
#include <libreborn/util.h>
#include <libreborn/config.h>
#include <SDL/SDL.h>
#include <media-layer/core.h>
#include <mods/input/input.h>
#include <mods/sign/sign.h>
// Custom Title
HOOK(media_SDL_WM_SetCaption, void, (__attribute__((unused)) const char *title, const char *icon)) {
real_media_SDL_WM_SetCaption()(MCPI_APP_TITLE, icon);
}
// Mouse Cursor Is Always Invisible In Vanilla MCPI
// Because In Vanilla MCPI, The GPU Overlay Covered The Normal Mouse Cursor
HOOK(media_SDL_ShowCursor, int, (int toggle)) {
return real_media_SDL_ShowCursor()(toggle == SDL_QUERY ? SDL_QUERY : SDL_DISABLE);
}
// Intercept SDL Events
HOOK(media_SDL_PollEvent, int, (SDL_Event *event)) {
// In Server Mode, Exit Requests Are Handled In src/server/server.cpp
// Check If Exit Is Requested
if (!reborn_is_server() && compat_check_exit_requested()) {
// Send SDL_QUIT
SDL_Event new_event;
new_event.type = SDL_QUIT;
media_SDL_PushEvent(&new_event);
}
// Poll Events
int ret = real_media_SDL_PollEvent()(event);
// Handle Events
if (ret == 1 && event != nullptr) {
bool handled = false;
switch (event->type) {
case SDL_KEYDOWN:
case SDL_KEYUP: {
// Track Control Key
bool is_ctrl = (event->key.keysym.mod & KMOD_CTRL) != 0;
if (event->type == SDL_KEYUP) {
is_ctrl = false;
}
input_set_is_ctrl(is_ctrl);
break;
}
case SDL_MOUSEBUTTONDOWN:
case SDL_MOUSEBUTTONUP: {
// Track Right-Click State
if (event->button.button == SDL_BUTTON_RIGHT) {
input_set_is_right_click(event->button.state != SDL_RELEASED);
}
break;
}
case SDL_USEREVENT: {
// SDL_UserEvent Is Never Used In MCPI, So It Is Repurposed For Character Events
if (event->user.code == USER_EVENT_CHARACTER) {
sign_key_press((char) event->user.data1);
handled = true;
}
break;
}
}
if (handled) {
// Event Was Handled
return media_SDL_PollEvent(event);
}
}
return ret;
}
// Exit Handler // Exit Handler
static void exit_handler(__attribute__((unused)) int data) { static void exit_handler(__attribute__((unused)) int data) {
// Request Exit // Request Exit
compat_request_exit(); compat_request_exit();
} }
void init_compat() { void init_compat() {
// SDL
_init_compat_sdl();
// Install Signal Handlers // Install Signal Handlers
struct sigaction act_sigint = {}; struct sigaction act_sigint = {};
act_sigint.sa_flags = SA_RESTART; act_sigint.sa_flags = SA_RESTART;

View File

@ -1,43 +1,85 @@
#include <SDL/SDL.h> #include <SDL/SDL.h>
#include <media-layer/core.h> #include <media-layer/core.h>
#include <libreborn/patch.h>
#include <libreborn/util.h>
#include <libreborn/config.h>
#include <symbols/minecraft.h>
#include <mods/compat/compat.h>
#include <mods/input/input.h>
#include <mods/feature/feature.h>
#include "compat-internal.h" #include "compat-internal.h"
// SDL Stub // Custom Title
static void *SDL_SetVideoMode_injection(__attribute__((unused)) int width, __attribute__((unused)) int height, __attribute__((unused)) int bpp, __attribute__((unused)) uint32_t flags) { HOOK(media_SDL_WM_SetCaption, void, (__attribute__((unused)) const char *title, const char *icon)) {
// Return Value Is Only Used For A NULL-Check real_media_SDL_WM_SetCaption()(MCPI_APP_TITLE, icon);
return (void *) 1;
} }
// Window Information // Mouse Cursor Is Always Invisible In Vanilla MCPI
static void x11_nop() { // Because In Vanilla MCPI, The GPU Overlay Covered The Normal Mouse Cursor
// NOP HOOK(media_SDL_ShowCursor, int, (int toggle)) {
} return real_media_SDL_ShowCursor()(toggle == SDL_QUERY ? SDL_QUERY : SDL_DISABLE);
static int SDL_GetWMInfo_injection(SDL_SysWMinfo *info) {
// Return Fake Lock Functions Since XLib Isn't Directly Used
SDL_SysWMinfo ret;
ret.info.x11.lock_func = x11_nop;
ret.info.x11.unlock_func = x11_nop;
ret.info.x11.display = nullptr;
ret.info.x11.window = 0;
ret.info.x11.wmwindow = ret.info.x11.window;
*info = ret;
return 1;
} }
// Quit // Intercept SDL Events
static void SDL_Quit_injection() { static bool enable_text_events;
// Cleanup Media Layer HOOK(media_SDL_PollEvent, int, (SDL_Event *event)) {
media_cleanup(); // In Server Mode, Exit Requests Are Handled In src/server/server.cpp
// Exit // Check If Exit Is Requested
INFO("Stopped"); if (!reborn_is_server() && compat_check_exit_requested()) {
// Send SDL_QUIT
SDL_Event new_event;
new_event.type = SDL_QUIT;
media_SDL_PushEvent(&new_event);
}
// Poll Events
int ret = real_media_SDL_PollEvent()(event);
// Handle Events
if (ret == 1 && event != nullptr) {
bool handled = false;
switch (event->type) {
case SDL_KEYDOWN:
case SDL_KEYUP: {
// Track Control Key
bool is_ctrl = (event->key.keysym.mod & KMOD_CTRL) != 0;
if (event->type == SDL_KEYUP) {
is_ctrl = false;
}
input_set_is_ctrl(is_ctrl);
break;
}
case SDL_MOUSEBUTTONDOWN:
case SDL_MOUSEBUTTONUP: {
// Track Right-Click State
if (event->button.button == SDL_BUTTON_RIGHT) {
input_set_is_right_click(event->button.state != SDL_RELEASED);
}
break;
}
case SDL_USEREVENT: {
// SDL_UserEvent Is Never Used In MCPI, So It Is Repurposed For Character Events
if (event->user.code == USER_EVENT_CHARACTER) {
if (enable_text_events) {
Keyboard::_inputText.push_back(char(event->user.data1));
}
handled = true;
}
break;
}
}
if (handled) {
// Event Was Handled
return media_SDL_PollEvent(event);
}
}
return ret;
} }
// Patch SDL Calls // Init
void _patch_sdl_calls() { void _init_compat_sdl() {
// Disable SDL Calls enable_text_events = feature_has("Enable Text Input", server_disabled);
overwrite_call((void *) 0xe020, (void *) SDL_SetVideoMode_injection); }
overwrite_call((void *) 0x13284, (void *) SDL_GetWMInfo_injection);
overwrite_call((void *) 0x12410, (void *) SDL_Quit_injection);
}

View File

@ -1,5 +1,5 @@
#include <libreborn/patch.h> #include <libreborn/patch.h>
#include "compat-internal.h" #include "../compat-internal.h"
// Do Nothing Function // Do Nothing Function
static void do_nothing() { static void do_nothing() {

View File

@ -2,7 +2,7 @@
#include <libreborn/patch.h> #include <libreborn/patch.h>
#include <media-layer/core.h> #include <media-layer/core.h>
#include "compat-internal.h" #include "../compat-internal.h"
// Functions That Have Their Return Values Used // Functions That Have Their Return Values Used
static EGLSurface eglCreateWindowSurface_injection(__attribute__((unused)) EGLDisplay display, __attribute__((unused)) EGLConfig config, __attribute__((unused)) NativeWindowType native_window, __attribute__((unused)) EGLint const *attrib_list) { static EGLSurface eglCreateWindowSurface_injection(__attribute__((unused)) EGLDisplay display, __attribute__((unused)) EGLConfig config, __attribute__((unused)) NativeWindowType native_window, __attribute__((unused)) EGLint const *attrib_list) {

View File

@ -0,0 +1,43 @@
#include <SDL/SDL.h>
#include <media-layer/core.h>
#include <libreborn/patch.h>
#include "../compat-internal.h"
// SDL Stub
static void *SDL_SetVideoMode_injection(__attribute__((unused)) int width, __attribute__((unused)) int height, __attribute__((unused)) int bpp, __attribute__((unused)) uint32_t flags) {
// Return Value Is Only Used For A NULL-Check
return (void *) 1;
}
// Window Information
static void x11_nop() {
// NOP
}
static int SDL_GetWMInfo_injection(SDL_SysWMinfo *info) {
// Return Fake Lock Functions Since XLib Isn't Directly Used
SDL_SysWMinfo ret;
ret.info.x11.lock_func = x11_nop;
ret.info.x11.unlock_func = x11_nop;
ret.info.x11.display = nullptr;
ret.info.x11.window = 0;
ret.info.x11.wmwindow = ret.info.x11.window;
*info = ret;
return 1;
}
// Quit
static void SDL_Quit_injection() {
// Cleanup Media Layer
media_cleanup();
// Exit
INFO("Stopped");
}
// Patch SDL Calls
void _patch_sdl_calls() {
// Disable SDL Calls
overwrite_call((void *) 0xe020, (void *) SDL_SetVideoMode_injection);
overwrite_call((void *) 0x13284, (void *) SDL_GetWMInfo_injection);
overwrite_call((void *) 0x12410, (void *) SDL_Quit_injection);
}

View File

@ -2,7 +2,7 @@
#include <libreborn/patch.h> #include <libreborn/patch.h>
#include <media-layer/core.h> #include <media-layer/core.h>
#include "compat-internal.h" #include "../compat-internal.h"
// Functions That Have Their Return Values Used // Functions That Have Their Return Values Used
static int XTranslateCoordinates_injection(__attribute__((unused)) void *display, __attribute__((unused)) XID src_w, __attribute__((unused)) XID dest_w, int src_x, int src_y, int *dest_x_return, int *dest_y_return, __attribute__((unused)) XID *child_return) { static int XTranslateCoordinates_injection(__attribute__((unused)) void *display, __attribute__((unused)) XID src_w, __attribute__((unused)) XID dest_w, int src_x, int src_y, int *dest_x_return, int *dest_y_return, __attribute__((unused)) XID *child_return) {

View File

@ -18,7 +18,6 @@ __attribute__((constructor)) static void init() {
init_shading(); init_shading();
} }
init_input(); init_input();
init_sign();
init_camera(); init_camera();
if (!reborn_is_headless()) { if (!reborn_is_headless()) {
init_atlas(); init_atlas();

View File

@ -6,4 +6,4 @@ This mod has several miscellaneous mods that are too small to be their own mod,
* Loading the bundled language file. * Loading the bundled language file.
* Printing chat messages to the log. * Printing chat messages to the log.
* Implementing crafting remainders. * Implementing crafting remainders.
* Correct the profile directory. * Correcting the profile directory.

View File

@ -236,6 +236,16 @@ static void Minecraft_handleMouseDown_injection(Minecraft_handleMouseDown_t orig
} }
} }
// Open Sign Screen
static void LocalPlayer_openTextEdit_injection(__attribute__((unused)) LocalPlayer_openTextEdit_t original, LocalPlayer *local_player, TileEntity *sign) {
if (sign->type == 4) {
Minecraft *minecraft = local_player->minecraft;
TextEditScreen *screen = TextEditScreen::allocate();
screen = screen->constructor((SignTileEntity *) sign);
minecraft->setScreen((Screen *) screen);
}
}
// Init // Init
void _init_misc_ui() { void _init_misc_ui() {
// Food Overlay // Food Overlay
@ -327,4 +337,10 @@ void _init_misc_ui() {
overwrite_calls(Minecraft_grabMouse, Minecraft_grabMouse_injection); overwrite_calls(Minecraft_grabMouse, Minecraft_grabMouse_injection);
overwrite_calls(Minecraft_handleMouseDown, Minecraft_handleMouseDown_injection); overwrite_calls(Minecraft_handleMouseDown, Minecraft_handleMouseDown_injection);
} }
// Signs
if (feature_has("Enable Sign Screen", server_disabled)) {
// Fix Signs
overwrite_calls(LocalPlayer_openTextEdit, LocalPlayer_openTextEdit_injection);
}
} }

View File

@ -1,2 +0,0 @@
# `readdir` Mod
This mod fixes a small bug where the contents of directories cannot be read on a 64-bit filesystem. This notably broke the world selection screen.

View File

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

View File

@ -1,32 +0,0 @@
#include <vector>
#include <libreborn/patch.h>
#include <symbols/minecraft.h>
#include <mods/init/init.h>
#include <mods/feature/feature.h>
#include <mods/sign/sign.h>
// Open Sign Screen
static void LocalPlayer_openTextEdit_injection(__attribute__((unused)) LocalPlayer_openTextEdit_t original, LocalPlayer *local_player, TileEntity *sign) {
if (sign->type == 4) {
Minecraft *minecraft = local_player->minecraft;
TextEditScreen *screen = TextEditScreen::allocate();
screen = screen->constructor((SignTileEntity *) sign);
minecraft->setScreen((Screen *) screen);
}
}
// Store Text Input
void sign_key_press(const char key) {
Keyboard::_inputText.push_back(key);
}
// Init
void init_sign() {
if (feature_has("Fix Sign Placement", server_disabled)) {
// Fix Signs
overwrite_calls(LocalPlayer_openTextEdit, LocalPlayer_openTextEdit_injection);
}
}