Add Improved Title Background

This commit is contained in:
TheBrokenRail 2022-04-22 19:38:15 -04:00
parent 89c29f14b1
commit 4a35935daf
14 changed files with 130 additions and 57 deletions

View File

@ -123,3 +123,8 @@ endif()
if(BUILD_ARM_COMPONENTS) if(BUILD_ARM_COMPONENTS)
add_subdirectory(mods) add_subdirectory(mods)
endif() endif()
# Include Images
if(BUILD_NATIVE_COMPONENTS)
add_subdirectory(images)
endif()

10
images/CMakeLists.txt Normal file
View File

@ -0,0 +1,10 @@
project(images)
# Title Background
if(NOT MCPI_SERVER_MODE)
install(
FILES "background.png"
DESTINATION "${MCPI_INSTALL_DIR}/data/images/gui"
RENAME "titleBG.png"
)
endif()

BIN
images/background.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 283 KiB

View File

@ -33,3 +33,4 @@ FALSE Disable V-Sync
TRUE Fix Options Screen TRUE Fix Options Screen
FALSE Force Touch Inventory FALSE Force Touch Inventory
TRUE Fix Pause Menu TRUE Fix Pause Menu
TRUE Improved Title Background

View File

@ -209,11 +209,24 @@ void bootstrap(int argc, char *argv[]) {
// Set MCPI_EXECUTABLE_PATH // Set MCPI_EXECUTABLE_PATH
set_and_print_env("MCPI_EXECUTABLE_PATH", resolved_path); set_and_print_env("MCPI_EXECUTABLE_PATH", resolved_path);
// Set MCPI_DIRECTORY // Set MCPI_VANILLA_ASSETS_PATH
{
chop_last_component(&resolved_path); chop_last_component(&resolved_path);
set_and_print_env("MCPI_DIRECTORY", resolved_path); string_append(&resolved_path, "/data");
set_and_print_env("MCPI_VANILLA_ASSETS_PATH", resolved_path);
free(resolved_path); free(resolved_path);
} }
}
// Set MCPI_REBORN_ASSETS_PATH
{
char *assets_path = realpath("/proc/self/exe", NULL);
ALLOC_CHECK(assets_path);
chop_last_component(&assets_path);
string_append(&assets_path, "/data");
set_and_print_env("MCPI_REBORN_ASSETS_PATH", assets_path);
free(assets_path);
}
// Fix MCPI Dependencies // Fix MCPI Dependencies
{ {

View File

@ -26,9 +26,6 @@ char *get_binary_directory();
// Safe execvpe() Relative To Binary // Safe execvpe() Relative To Binary
__attribute__((noreturn)) void safe_execvpe_relative_to_binary(const char *const argv[], const char *const envp[]); __attribute__((noreturn)) void safe_execvpe_relative_to_binary(const char *const argv[], const char *const envp[]);
// Get MCPI Directory
char *get_mcpi_directory();
// Run Command And Get Output // Run Command And Get Output
char *run_command(const char *const command[], int *return_code); char *run_command(const char *const command[], int *return_code);

View File

@ -19,7 +19,7 @@
#define string_append(str, format, ...) \ #define string_append(str, format, ...) \
{ \ { \
char *old = *str; \ char *old = *str; \
safe_asprintf(str, "%s" format, *str == NULL ? "" : *str, __VA_ARGS__); \ safe_asprintf(str, "%s" format, *str == NULL ? "" : *str, ##__VA_ARGS__); \
ALLOC_CHECK(*str); \ ALLOC_CHECK(*str); \
if (old != NULL && old != *str) { \ if (old != NULL && old != *str) { \
free(old); \ free(old); \

View File

@ -57,11 +57,6 @@ __attribute__((noreturn)) void safe_execvpe_relative_to_binary(const char *const
safe_execvpe(new_argv, envp); safe_execvpe(new_argv, envp);
} }
// Get MCPI Directory
char *get_mcpi_directory() {
return getenv("MCPI_DIRECTORY");
}
// Run Command And Get Output // Run Command And Get Output
char *run_command(const char *const command[], int *return_code) { char *run_command(const char *const command[], int *return_code) {
// Store Output // Store Output

View File

@ -26,11 +26,8 @@ void init_home() {
// Store Data In ~/.minecraft-pi Instead Of ~/.minecraft // Store Data In ~/.minecraft-pi Instead Of ~/.minecraft
patch_address((void *) default_path, (void *) HOME_SUBDIRECTORY_FOR_GAME_DATA); patch_address((void *) default_path, (void *) HOME_SUBDIRECTORY_FOR_GAME_DATA);
// Change Directory To Binary Directory Manually // The override code resolves assets manually,
// making changing directory redundant.
unsigned char nop_patch[4] = {0x00, 0xf0, 0x20, 0xe3}; // "nop" unsigned char nop_patch[4] = {0x00, 0xf0, 0x20, 0xe3}; // "nop"
patch((void *) 0xe0ac, nop_patch); patch((void *) 0xe0ac, nop_patch);
char *binary_directory = get_mcpi_directory();
if (chdir(binary_directory) != 0) {
ERR("Unable To Change Directory: %s", strerror(errno));
}
} }

View File

@ -70,6 +70,15 @@ 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
@ -85,4 +94,14 @@ 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

@ -50,13 +50,6 @@ static void Options_initDefaultValue_injection(unsigned char *options) {
// Call Original Method // Call Original Method
(*Options_initDefaultValue)(options); (*Options_initDefaultValue)(options);
// Enable Crosshair In Touch GUI
*(options + Options_split_controls_property_offset) = 1;
// 3D Anaglyph
*(options + Options_3d_anaglyph_property_offset) = anaglyph;
// Render Distance
*(int32_t *) (options + Options_render_distance_property_offset) = render_distance;
// Default Graphics Settings // Default Graphics Settings
*(options + Options_fancy_graphics_property_offset) = 1; *(options + Options_fancy_graphics_property_offset) = 1;
*(options + Options_ambient_occlusion_property_offset) = 1; *(options + Options_ambient_occlusion_property_offset) = 1;
@ -64,6 +57,18 @@ static void Options_initDefaultValue_injection(unsigned char *options) {
// Store // Store
stored_options = options; stored_options = options;
} }
static void Minecraft_init_injection(unsigned char *minecraft) {
// Call Original Method
(*Minecraft_init)(minecraft);
unsigned char *options = minecraft + Minecraft_options_property_offset;
// Enable Crosshair In Touch GUI
*(options + Options_split_controls_property_offset) = 1;
// 3D Anaglyph
*(options + Options_3d_anaglyph_property_offset) = anaglyph;
// Render Distance
*(int32_t *) (options + Options_render_distance_property_offset) = render_distance;
}
// Smooth Lighting // Smooth Lighting
static void TileRenderer_tesselateBlockInWorld_injection(unsigned char *tile_renderer, unsigned char *tile, int32_t x, int32_t y, int32_t z) { static void TileRenderer_tesselateBlockInWorld_injection(unsigned char *tile_renderer, unsigned char *tile, int32_t x, int32_t y, int32_t z) {
@ -93,6 +98,7 @@ void init_options() {
// Set Options // Set Options
overwrite_calls((void *) Options_initDefaultValue, (void *) Options_initDefaultValue_injection); overwrite_calls((void *) Options_initDefaultValue, (void *) Options_initDefaultValue_injection);
overwrite_calls((void *) Minecraft_init, (void *) Minecraft_init_injection);
// Change Username // Change Username
const char *username = get_username(); const char *username = get_username();

View File

@ -8,8 +8,23 @@
#include <libreborn/libreborn.h> #include <libreborn/libreborn.h>
#include "override.h"
#include "../home/home.h" #include "../home/home.h"
// Hook access
HOOK(access, int, (const char *pathname, int mode)) {
char *new_path = override_get_path(pathname);
// Open File
ensure_access();
int ret = (*real_access)(new_path != NULL ? new_path : pathname, mode);
// Free Data
if (new_path != NULL) {
free(new_path);
}
// Return
return ret;
}
// Get Override Path For File (If It Exists) // Get Override Path For File (If It Exists)
char *override_get_path(const char *filename) { char *override_get_path(const char *filename) {
// Get MCPI Home Path // Get MCPI Home Path
@ -18,43 +33,45 @@ char *override_get_path(const char *filename) {
char *overrides = NULL; char *overrides = NULL;
safe_asprintf(&overrides, "%s/overrides", home_path); safe_asprintf(&overrides, "%s/overrides", home_path);
// Get Data Path // Data Prefiix
char *data = NULL; char *data_prefix = "data/";
char *binary_directory = get_mcpi_directory(); int data_prefix_length = strlen(data_prefix);
safe_asprintf(&data, "%s/data", binary_directory);
int data_length = strlen(data);
// Get Full Path // Folders To Check
char *full_path; char *asset_folders[] = {
if (strlen(filename) > 0 && filename[0] == '/') { overrides,
// Absolute Path getenv("MCPI_REBORN_ASSETS_PATH"),
full_path = strdup(filename); getenv("MCPI_VANILLA_ASSETS_PATH"),
} else { NULL
// Relative Path };
full_path = realpath(filename, NULL);
}
// Check For Override // Check For Override
char *new_path = NULL; char *new_path = NULL;
if (full_path != NULL) { if (starts_with(filename, data_prefix)) {
if (starts_with(full_path, data)) { // Test Asset Folders
safe_asprintf(&new_path, "%s%s", overrides, &full_path[data_length]); for (int i = 0; asset_folders[i] != NULL; i++) {
if (access(new_path, F_OK) == -1) { safe_asprintf(&new_path, "%s/%s", asset_folders[i], &filename[data_prefix_length]);
ensure_access();
if ((*real_access)(new_path, F_OK) == -1) {
// Not Found In Asset Folder
free(new_path); free(new_path);
new_path = NULL; new_path = NULL;
continue;
} else {
// Found
break;
} }
} }
free(full_path);
} }
// Free Variables // Free
free(overrides); free(overrides);
free(data);
// Return // Return
return new_path; return new_path;
} }
// Hook fopen
HOOK(fopen, FILE *, (const char *filename, const char *mode)) { HOOK(fopen, FILE *, (const char *filename, const char *mode)) {
char *new_path = override_get_path(filename); char *new_path = override_get_path(filename);
// Open File // Open File
@ -68,6 +85,7 @@ HOOK(fopen, FILE *, (const char *filename, const char *mode)) {
return file; return file;
} }
// Hook fopen64
HOOK(fopen64, FILE *, (const char *filename, const char *mode)) { HOOK(fopen64, FILE *, (const char *filename, const char *mode)) {
char *new_path = override_get_path(filename); char *new_path = override_get_path(filename);
// Open File // Open File

View File

@ -22,31 +22,29 @@ std::string _sound_get_source_file() {
} else { } else {
// Resolve // Resolve
// Get Binary Directory // Get Path
char *binary_directory = get_mcpi_directory(); char *path = strdup(SOURCE_FILE_BASE);
// Get Full Path ALLOC_CHECK(path);
char *full_path = NULL;
safe_asprintf(&full_path, "%s/" SOURCE_FILE_BASE, binary_directory);
// Handle Overrides // Handle Overrides
char *overridden_full_path = override_get_path(full_path); char *overridden_full_path = override_get_path(path);
if (overridden_full_path != NULL) { if (overridden_full_path != NULL) {
free(full_path); free(path);
full_path = overridden_full_path; path = overridden_full_path;
} }
// Check If Sound Exists // Check If Sound Exists
if (access(full_path, F_OK) == -1) { if (access(path, F_OK) == -1) {
// Fail // Fail
WARN("Audio Source File Doesn't Exist: " SOURCE_FILE_BASE); WARN("Audio Source File Doesn't Exist: " SOURCE_FILE_BASE);
source.assign(""); source.assign("");
} else { } else {
// Set // Set
source.assign(full_path); source.assign(path);
} }
// Free // Free
free(full_path); free(path);
// Mark As Loaded // Mark As Loaded
source_loaded = true; source_loaded = true;

View File

@ -467,6 +467,11 @@ static uint32_t FurnaceScreen_tile_entity_property_offset = 0x1d0; // FurnaceTil
typedef ItemInstance *(*FurnaceTileEntity_getItem_t)(unsigned char *furnace_tile_entity, int32_t slot); typedef ItemInstance *(*FurnaceTileEntity_getItem_t)(unsigned char *furnace_tile_entity, int32_t slot);
static uint32_t FurnaceTileEntity_getItem_vtable_offset = 0x2c; static uint32_t FurnaceTileEntity_getItem_vtable_offset = 0x2c;
// GuiComponent
typedef void (*GuiComponent_blit_t)(unsigned char *component, int32_t param_1, int32_t param_2, int32_t param_3, int32_t param_4, int32_t param_5, int32_t param_6, int32_t param_7, int32_t param_8);
static GuiComponent_blit_t GuiComponent_blit = (GuiComponent_blit_t) 0x282a4;
// Screen // Screen
typedef void (*Screen_updateEvents_t)(unsigned char *screen); typedef void (*Screen_updateEvents_t)(unsigned char *screen);
@ -482,11 +487,15 @@ typedef void (*Screen_init_t)(unsigned char *screen);
typedef void (*Screen_tick_t)(unsigned char *screen); typedef void (*Screen_tick_t)(unsigned char *screen);
typedef void (*Screen_render_t)(unsigned char *screen, int32_t param_1, int32_t param_2, float param_3);
typedef int32_t (*Screen_handleBackEvent_t)(unsigned char *screen, bool param_1); typedef int32_t (*Screen_handleBackEvent_t)(unsigned char *screen, bool param_1);
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 *>
static uint32_t Screen_width_property_offset = 0x8; // int32_t
static uint32_t Screen_height_property_offset = 0xc; // int32_t
// StartMenuScreen // StartMenuScreen
@ -809,6 +818,11 @@ static uint32_t OptionsFile_options_txt_path_property_offset = 0x0; // std::stri
typedef void (*OptionsPane_unknown_toggle_creating_function_t)(unsigned char *options_pane, unsigned char *unknown_object, std::string const& name, unsigned char *option); typedef void (*OptionsPane_unknown_toggle_creating_function_t)(unsigned char *options_pane, unsigned char *unknown_object, std::string const& name, unsigned char *option);
static OptionsPane_unknown_toggle_creating_function_t OptionsPane_unknown_toggle_creating_function = (OptionsPane_unknown_toggle_creating_function_t) 0x24470; static OptionsPane_unknown_toggle_creating_function_t OptionsPane_unknown_toggle_creating_function = (OptionsPane_unknown_toggle_creating_function_t) 0x24470;
// Textures
typedef void (*Textures_loadAndBindTexture_t)(unsigned char *textures, std::string const& name);
static Textures_loadAndBindTexture_t Textures_loadAndBindTexture = (Textures_loadAndBindTexture_t) 0x539cc;
#endif #endif
#pragma GCC diagnostic pop #pragma GCC diagnostic pop