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

View File

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

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"
// Patching Functions
#ifdef REBORN_HAS_PATCH_CODE
#ifndef REBORN_HAS_PATCH_CODE
#error "Missing Patching Functions"
#endif
// Init
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);
}
#endif

View File

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

View File

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

View File

@ -8,7 +8,6 @@ void init_multiplayer();
void init_benchmark();
void init_sound();
void init_input();
void init_sign();
void init_camera();
void init_atlas();
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
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
// Stubs
__attribute__((visibility("internal"))) void _patch_egl_calls();
__attribute__((visibility("internal"))) void _patch_x11_calls();
__attribute__((visibility("internal"))) void _patch_bcm_host_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 <csignal>
#include <cerrno>
#include <mods/compat/compat.h>
#include <mods/init/init.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
static void exit_handler(__attribute__((unused)) int data) {
// Request Exit
compat_request_exit();
}
void init_compat() {
// SDL
_init_compat_sdl();
// Install Signal Handlers
struct sigaction act_sigint = {};
act_sigint.sa_flags = SA_RESTART;

View File

@ -1,43 +1,85 @@
#include <SDL/SDL.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"
// 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;
// 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);
}
// 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;
// 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);
}
// Quit
static void SDL_Quit_injection() {
// Cleanup Media Layer
media_cleanup();
// Exit
INFO("Stopped");
// Intercept SDL Events
static bool enable_text_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) {
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
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);
}
// Init
void _init_compat_sdl() {
enable_text_events = feature_has("Enable Text Input", server_disabled);
}

View File

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

View File

@ -2,7 +2,7 @@
#include <libreborn/patch.h>
#include <media-layer/core.h>
#include "compat-internal.h"
#include "../compat-internal.h"
// 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) {

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 <media-layer/core.h>
#include "compat-internal.h"
#include "../compat-internal.h"
// 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) {

View File

@ -18,7 +18,6 @@ __attribute__((constructor)) static void init() {
init_shading();
}
init_input();
init_sign();
init_camera();
if (!reborn_is_headless()) {
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.
* Printing chat messages to the log.
* 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
void _init_misc_ui() {
// Food Overlay
@ -327,4 +337,10 @@ void _init_misc_ui() {
overwrite_calls(Minecraft_grabMouse, Minecraft_grabMouse_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);
}
}