Add Quit Button

This commit is contained in:
TheBrokenRail 2022-09-21 20:15:00 -04:00
parent 6378a18494
commit 16ce586e9c
9 changed files with 104 additions and 55 deletions

View File

@ -32,7 +32,7 @@ TRUE Disable V-Sync
TRUE Fix Options Screen TRUE Fix Options Screen
TRUE Force Touch GUI Inventory TRUE Force Touch GUI Inventory
TRUE Fix Pause Menu TRUE Fix Pause Menu
TRUE Improved Title Background TRUE Improved Title Screen Background
TRUE Force Touch GUI Button Behavior TRUE Force Touch GUI Button Behavior
TRUE Improved Button Hover Behavior TRUE Improved Button Hover Behavior
TRUE Implement Create World Dialog TRUE Implement Create World Dialog
@ -41,3 +41,4 @@ TRUE Add Buckets
TRUE Classic HUD TRUE Classic HUD
TRUE Translucent Toolbar TRUE Translucent Toolbar
FALSE Force EGL FALSE Force EGL
TRUE Improved Classic Title Screen

View File

@ -77,6 +77,9 @@ else()
add_library(atlas SHARED src/atlas/atlas.cpp) add_library(atlas SHARED src/atlas/atlas.cpp)
target_link_libraries(atlas mods-headers reborn-patch symbols feature media-layer-core) target_link_libraries(atlas mods-headers reborn-patch symbols feature media-layer-core)
add_library(title-screen SHARED src/title-screen/title-screen.cpp)
target_link_libraries(title-screen mods-headers reborn-patch symbols feature compat)
add_library(benchmark SHARED src/benchmark/benchmark.cpp) add_library(benchmark SHARED src/benchmark/benchmark.cpp)
target_link_libraries(benchmark mods-headers reborn-patch symbols compat misc media-layer-core) target_link_libraries(benchmark mods-headers reborn-patch symbols compat misc media-layer-core)
endif() endif()
@ -112,7 +115,7 @@ target_link_libraries(init mods-headers reborn-util compat game-mode misc death
if(MCPI_SERVER_MODE) if(MCPI_SERVER_MODE)
target_link_libraries(init server) target_link_libraries(init server)
else() else()
target_link_libraries(init multiplayer sound camera input sign touch textures atlas benchmark) target_link_libraries(init multiplayer sound camera input sign touch textures atlas title-screen benchmark)
endif() endif()
## Install Mods ## Install Mods
@ -120,7 +123,7 @@ set(MODS_TO_INSTALL init compat readdir feature game-mode misc override death op
if(MCPI_SERVER_MODE) if(MCPI_SERVER_MODE)
list(APPEND MODS_TO_INSTALL server) list(APPEND MODS_TO_INSTALL server)
else() else()
list(APPEND MODS_TO_INSTALL multiplayer sound camera input sign touch textures atlas benchmark) list(APPEND MODS_TO_INSTALL multiplayer sound camera input sign touch textures atlas title-screen benchmark)
endif() endif()
if(NOT MCPI_HEADLESS_MODE) if(NOT MCPI_HEADLESS_MODE)
list(APPEND MODS_TO_INSTALL screenshot) list(APPEND MODS_TO_INSTALL screenshot)

View File

@ -20,6 +20,7 @@ void init_camera();
void init_touch(); void init_touch();
void init_textures(); void init_textures();
void init_atlas(); void init_atlas();
void init_title_screen();
#endif #endif
void init_creative(); void init_creative();
void init_game_mode(); void init_game_mode();

View File

@ -20,6 +20,7 @@ __attribute__((constructor)) static void init() {
init_touch(); init_touch();
init_textures(); init_textures();
init_atlas(); init_atlas();
init_title_screen();
#endif #endif
init_creative(); init_creative();
init_game_mode(); init_game_mode();

View File

@ -50,15 +50,6 @@ static void PauseScreen_init_injection(unsigned char *screen) {
} }
} }
// Improved Title Background
static void StartMenuScreen_render_Screen_renderBackground_injection(unsigned char *screen) {
// Draw
unsigned char *minecraft = *(unsigned char **) (screen + Screen_minecraft_property_offset);
unsigned char *textures = *(unsigned char **) (minecraft + Minecraft_textures_property_offset);
(*Textures_loadAndBindTexture)(textures, "gui/titleBG.png");
(*GuiComponent_blit)(screen, 0, 0, 0, 0, *(int32_t *) (screen + Screen_width_property_offset), *(int32_t *) (screen + Screen_height_property_offset), 0x100, 0x100);
}
// Init // Init
void _init_misc_cpp() { void _init_misc_cpp() {
// Implement AppPlatform::readAssetFile So Translations Work // Implement AppPlatform::readAssetFile So Translations Work
@ -71,14 +62,4 @@ void _init_misc_cpp() {
// Add Missing Buttons To Pause Menu // Add Missing Buttons To Pause Menu
patch_address(PauseScreen_init_vtable_addr, (void *) PauseScreen_init_injection); patch_address(PauseScreen_init_vtable_addr, (void *) PauseScreen_init_injection);
} }
// Improved Title Background
if (feature_has("Improved Title Background", server_disabled)) {
// Switch Background
overwrite_call((void *) 0x39528, (void *) StartMenuScreen_render_Screen_renderBackground_injection);
overwrite_call((void *) 0x3dee0, (void *) StartMenuScreen_render_Screen_renderBackground_injection);
// Text Color
patch_address((void *) 0x397ac, (void *) 0xffffffff);
patch_address((void *) 0x3e10c, (void *) 0xffffffff);
}
} }

View File

@ -138,19 +138,6 @@ static bool Options_getBooleanValue_injection(unsigned char *options, unsigned c
} }
} }
// Add Options Button Back To Classic Start Screen
static void StartMenuScreen_init_injection(unsigned char *screen) {
// Call Original Method
(*StartMenuScreen_init)(screen);
// Add Button
std::vector<unsigned char *> *rendered_buttons = (std::vector<unsigned char *> *) (screen + Screen_rendered_buttons_property_offset);
std::vector<unsigned char *> *selectable_buttons = (std::vector<unsigned char *> *) (screen + Screen_selectable_buttons_property_offset);
unsigned char *options_button = screen + StartMenuScreen_options_button_property_offset;
rendered_buttons->push_back(options_button);
selectable_buttons->push_back(options_button);
}
// Init C++ // Init C++
void _init_options_cpp() { void _init_options_cpp() {
// NOP // NOP
@ -175,26 +162,6 @@ void _init_options_cpp() {
// Add Missing Options To Options::getBooleanValue // Add Missing Options To Options::getBooleanValue
overwrite_calls((void *) Options_getBooleanValue, (void *) Options_getBooleanValue_injection); overwrite_calls((void *) Options_getBooleanValue, (void *) Options_getBooleanValue_injection);
// Add Options Button Back To Classic Start Screen
patch_address(StartMenuScreen_init_vtable_addr, (void *) StartMenuScreen_init_injection);
// Fix Classic UI Options Button Size
unsigned char classic_options_button_width_patch[4] = {0xa0, 0x00, 0xa0, 0xe3}; // "mov r0, #0xa0"
patch((void *) 0x39a98, classic_options_button_width_patch);
unsigned char classic_options_button_height_patch[4] = {0x18, 0x30, 0xa0, 0xe3}; // "mov r3, #0x18"
patch((void *) 0x39a9c, classic_options_button_height_patch);
// Fix Classic UI Buttons Spacing
{
// Join Button
unsigned char classic_join_button_spacing_patch[4] = {0x12, 0x20, 0x83, 0xe2}; // "add r2, r3, #0x12"
patch((void *) 0x39894, classic_join_button_spacing_patch);
// Start Button
unsigned char classic_start_button_spacing_patch[4] = {0x08, 0x20, 0x43, 0xe2}; // "sub r2, r3, #0x08"
patch((void *) 0x3988c, classic_start_button_spacing_patch);
// Options Button
unsigned char classic_options_button_spacing_patch[4] = {0x2c, 0x30, 0x83, 0xe2}; // "add r3, r3, #0x2c"
patch((void *) 0x39898, classic_options_button_spacing_patch);
}
} }
// Actually Save options.txt // Actually Save options.txt

View File

@ -0,0 +1,2 @@
# ``title-screen`` Mod
This mod improves the title screen.

View File

@ -0,0 +1,86 @@
#include <libreborn/libreborn.h>
#include <symbols/minecraft.h>
#include <mods/feature/feature.h>
#include <mods/init/init.h>
#include <mods/compat/compat.h>
// Improved Title Screen Background
static void StartMenuScreen_render_Screen_renderBackground_injection(unsigned char *screen) {
// Draw
unsigned char *minecraft = *(unsigned char **) (screen + Screen_minecraft_property_offset);
unsigned char *textures = *(unsigned char **) (minecraft + Minecraft_textures_property_offset);
(*Textures_loadAndBindTexture)(textures, "gui/titleBG.png");
(*GuiComponent_blit)(screen, 0, 0, 0, 0, *(int32_t *) (screen + Screen_width_property_offset), *(int32_t *) (screen + Screen_height_property_offset), 0x100, 0x100);
}
// Add Buttons Back To Classic Start Screen
static void StartMenuScreen_init_injection(unsigned char *screen) {
// Call Original Method
(*StartMenuScreen_init)(screen);
// Add Button
std::vector<unsigned char *> *rendered_buttons = (std::vector<unsigned char *> *) (screen + Screen_rendered_buttons_property_offset);
std::vector<unsigned char *> *selectable_buttons = (std::vector<unsigned char *> *) (screen + Screen_selectable_buttons_property_offset);
unsigned char *options_button = screen + StartMenuScreen_options_button_property_offset;
rendered_buttons->push_back(options_button);
selectable_buttons->push_back(options_button);
unsigned char *create_button = screen + StartMenuScreen_create_button_property_offset; // Repurpose Unused "Create" Button As Quit Button
rendered_buttons->push_back(create_button);
selectable_buttons->push_back(create_button);
}
// Add Functionality To Quit Button
static void StartMenuScreen_buttonClicked_injection(unsigned char *screen, unsigned char *button) {
unsigned char *quit_button = screen + StartMenuScreen_create_button_property_offset;
if (button == quit_button) {
// Quit
compat_request_exit();
} else {
// Call Original Method
(*StartMenuScreen_buttonClicked)(screen, button);
}
}
// Init
void init_title_screen() {
// Improved Title Screen Background
if (feature_has("Improved Title Screen Background", server_disabled)) {
// Switch Background
overwrite_call((void *) 0x39528, (void *) StartMenuScreen_render_Screen_renderBackground_injection);
overwrite_call((void *) 0x3dee0, (void *) StartMenuScreen_render_Screen_renderBackground_injection);
// Text Color
patch_address((void *) 0x397ac, (void *) 0xffffffff);
patch_address((void *) 0x3e10c, (void *) 0xffffffff);
}
// Improved Classic Title Screen
if (feature_has("Improved Classic Title Screen", server_disabled)) {
// Add Options Button Back To Classic Start Screen
patch_address(StartMenuScreen_init_vtable_addr, (void *) StartMenuScreen_init_injection);
// Fix Classic UI Button Size
unsigned char classic_button_height_patch[4] = {0x18, 0x30, 0xa0, 0xe3}; // "mov r3, #0x18"
patch((void *) 0x39a9c, classic_button_height_patch);
patch((void *) 0x39ae0, classic_button_height_patch);
// Fix Classic UI Buttons Spacing
{
// Join Button
unsigned char classic_join_button_spacing_patch[4] = {0x12, 0x20, 0x83, 0xe2}; // "add r2, r3, #0x12"
patch((void *) 0x39894, classic_join_button_spacing_patch);
// Start Button
unsigned char classic_start_button_spacing_patch[4] = {0x08, 0x20, 0x43, 0xe2}; // "sub r2, r3, #0x08"
patch((void *) 0x3988c, classic_start_button_spacing_patch);
// Options Button
unsigned char classic_options_button_spacing_patch[4] = {0x2c, 0x30, 0x83, 0xe2}; // "add r3, r3, #0x2c"
patch((void *) 0x39898, classic_options_button_spacing_patch);
}
// Rename "Create" Button To "Quit"
patch_address((void *) classic_create_button_text, (void *) "Quit");
// Add Functionality To Quit Button
patch_address(StartMenuScreen_buttonClicked_vtable_addr, (void *) StartMenuScreen_buttonClicked_injection);
}
}

View File

@ -32,6 +32,7 @@ static char **options_txt_fopen_mode_when_loading = (char **) 0x19d24; // w
static char ***feedback_vibration_options_txt_name_1 = (char ***) 0x198a0; // feedback_vibration static char ***feedback_vibration_options_txt_name_1 = (char ***) 0x198a0; // feedback_vibration
static char ***feedback_vibration_options_txt_name_2 = (char ***) 0x194bc; // feedback_vibration static char ***feedback_vibration_options_txt_name_2 = (char ***) 0x194bc; // feedback_vibration
static char ***gfx_lowquality_options_txt_name = (char ***) 0x194c4; // gfx_lowquality static char ***gfx_lowquality_options_txt_name = (char ***) 0x194c4; // gfx_lowquality
static char **classic_create_button_text = (char **) 0x39bec; // Create
static unsigned char **Material_stone = (unsigned char **) 0x180a9c; // Material static unsigned char **Material_stone = (unsigned char **) 0x180a9c; // Material
@ -574,6 +575,8 @@ static Screen_render_t Screen_render = (Screen_render_t) 0x28a00;
typedef int32_t (*Screen_handleBackEvent_t)(unsigned char *screen, bool param_1); typedef int32_t (*Screen_handleBackEvent_t)(unsigned char *screen, bool param_1);
typedef void (*Screen_buttonClicked_t)(unsigned char *screen, unsigned char *button);
static uint32_t Screen_minecraft_property_offset = 0x14; // Minecraft * static uint32_t Screen_minecraft_property_offset = 0x14; // Minecraft *
static uint32_t Screen_rendered_buttons_property_offset = 0x18; // std::vector<Button *> static uint32_t Screen_rendered_buttons_property_offset = 0x18; // std::vector<Button *>
static uint32_t Screen_selectable_buttons_property_offset = 0x30; // std::vector<Button *> static uint32_t Screen_selectable_buttons_property_offset = 0x30; // std::vector<Button *>
@ -596,7 +599,11 @@ static uint32_t Button_y_property_offset = 0x10; // int32_t
static Screen_init_t StartMenuScreen_init = (Screen_init_t) 0x39cc0; static Screen_init_t StartMenuScreen_init = (Screen_init_t) 0x39cc0;
static void *StartMenuScreen_init_vtable_addr = (void *) 0x105194; static void *StartMenuScreen_init_vtable_addr = (void *) 0x105194;
static Screen_buttonClicked_t StartMenuScreen_buttonClicked = (Screen_buttonClicked_t) 0x397b0;
static void *StartMenuScreen_buttonClicked_vtable_addr = (void *) 0x1051e8;
static uint32_t StartMenuScreen_options_button_property_offset = 0x98; // Button static uint32_t StartMenuScreen_options_button_property_offset = 0x98; // Button
static uint32_t StartMenuScreen_create_button_property_offset = 0xc0; // Button
// PauseScreen // PauseScreen