From 578bb1c89f47402d851b58325e40af3f77b1d2ac Mon Sep 17 00:00:00 2001 From: TheBrokenRail Date: Thu, 5 Aug 2021 21:00:41 -0400 Subject: [PATCH] Fix On 64-Bit ARM Systems --- VERSION | 2 +- debian/client-arm | 2 +- debian/client-arm64 | 2 +- debian/client-x86_64 | 2 +- debian/server-arm | 1 + debian/server-arm64 | 2 +- debian/server-x86_64 | 2 +- docs/CHANGELOG.md | 3 ++ launcher/src/bootstrap.c | 30 ++++++------- libreborn/include/libreborn/minecraft.h | 1 + mods/CMakeLists.txt | 7 ++- mods/src/creative/README.md | 2 + mods/src/creative/creative.cpp | 57 +++++++++++++++++++++++++ mods/src/init/init.c | 1 + mods/src/init/init.h | 1 + mods/src/misc/README.md | 1 - mods/src/misc/misc.c | 2 +- mods/src/misc/misc.cpp | 51 +--------------------- 18 files changed, 91 insertions(+), 78 deletions(-) create mode 100644 mods/src/creative/README.md create mode 100644 mods/src/creative/creative.cpp diff --git a/VERSION b/VERSION index 399088bf4..04b10b4f1 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -2.1.6 +2.1.7 diff --git a/debian/client-arm b/debian/client-arm index 16e1e55cd..392fc8f03 100644 --- a/debian/client-arm +++ b/debian/client-arm @@ -4,4 +4,4 @@ Maintainer: TheBrokenRail Description: Fun with Blocks Homepage: https://www.minecraft.net/en-us/edition/pi Architecture: armhf -Depends: zenity, libgles1, libegl1, libglfw3 | libglfw3-wayland, libfreeimage3 +Depends: libc6, libstdc++6, zenity, libgles1, libegl1, libglfw3 | libglfw3-wayland, libfreeimage3 diff --git a/debian/client-arm64 b/debian/client-arm64 index c22112271..95ef9bb38 100644 --- a/debian/client-arm64 +++ b/debian/client-arm64 @@ -4,4 +4,4 @@ Maintainer: TheBrokenRail Description: Fun with Blocks Homepage: https://www.minecraft.net/en-us/edition/pi Architecture: arm64 -Depends: zenity, libgles1, libegl1, libglfw3 | libglfw3-wayland, libfreeimage3, libc6-armhf-cross, libstdc++6-armhf-cross +Depends: libc6, libstdc++6, libc6:armhf, libstdc++6:armhf, zenity, libgles1, libegl1, libglfw3 | libglfw3-wayland, libfreeimage3 diff --git a/debian/client-x86_64 b/debian/client-x86_64 index acbd2a38a..d10adf809 100644 --- a/debian/client-x86_64 +++ b/debian/client-x86_64 @@ -4,4 +4,4 @@ Maintainer: TheBrokenRail Description: Fun with Blocks Homepage: https://www.minecraft.net/en-us/edition/pi Architecture: amd64 -Depends: zenity, libgles1, libegl1, libglfw3 | libglfw3-wayland, libfreeimage3, libc6-armhf-cross, libstdc++6-armhf-cross, qemu-user-static +Depends: libc6, libstdc++6, libc6-armhf-cross, libstdc++6-armhf-cross, zenity, libgles1, libegl1, libglfw3 | libglfw3-wayland, libfreeimage3, qemu-user-static diff --git a/debian/server-arm b/debian/server-arm index 05eef3221..697b4ec37 100644 --- a/debian/server-arm +++ b/debian/server-arm @@ -4,3 +4,4 @@ Maintainer: TheBrokenRail Description: Fun with Blocks Homepage: https://www.minecraft.net/en-us/edition/pi Architecture: armhf +Depends: libc6, libstdc++6 diff --git a/debian/server-arm64 b/debian/server-arm64 index 971ccad2b..5bd4d13f9 100644 --- a/debian/server-arm64 +++ b/debian/server-arm64 @@ -4,4 +4,4 @@ Maintainer: TheBrokenRail Description: Fun with Blocks Homepage: https://www.minecraft.net/en-us/edition/pi Architecture: arm64 -Depends: libc6-armhf-cross, libstdc++6-armhf-cross +Depends: libc6, libstdc++6, libc6:armhf, libstdc++6:armhf diff --git a/debian/server-x86_64 b/debian/server-x86_64 index f6ca68fb0..5c9e71b24 100644 --- a/debian/server-x86_64 +++ b/debian/server-x86_64 @@ -4,4 +4,4 @@ Maintainer: TheBrokenRail Description: Fun with Blocks Homepage: https://www.minecraft.net/en-us/edition/pi Architecture: amd64 -Depends: libc6-armhf-cross, libstdc++6-armhf-cross, qemu-user-static +Depends: libc6, libstdc++6, libc6-armhf-cross, libstdc++6-armhf-cross, qemu-user-static diff --git a/docs/CHANGELOG.md b/docs/CHANGELOG.md index 2472724b5..e3eafaca6 100644 --- a/docs/CHANGELOG.md +++ b/docs/CHANGELOG.md @@ -1,5 +1,8 @@ # Changelog +**2.1.7** +* Fix On 64-Bit ARM Systems + **2.1.6** * Optimize Media Layer Proxy diff --git a/launcher/src/bootstrap.c b/launcher/src/bootstrap.c index 3921fe245..fc7a653a1 100644 --- a/launcher/src/bootstrap.c +++ b/launcher/src/bootstrap.c @@ -181,31 +181,26 @@ void bootstrap(int argc, char *argv[]) { free(new_ld_preload); } - // Free Binary Directory - free(binary_directory); - // Start Game INFO("%s", "Starting Game..."); + + // Use Correct LibC +#ifndef __ARM_ARCH + setenv("QEMU_LD_PREFIX", "/usr/arm-linux-gnueabihf", 1); +#endif + + // Select Executable Interpreter #ifdef __ARM_ARCH - // Create Arguments List - char *new_argv[argc + 1]; - for (int i = 1; i <= argc; i++) { - new_argv[i] = argv[i]; - } - new_argv[0] = NULL; // Updated By safe_execvpe() - // Run - safe_execvpe_relative_to_binary(MCPI_NAME, new_argv, environ); +#define EXE_INTERPRETER "/lib/ld-linux-armhf.so.3" #else // Use Static QEMU So It Isn't Affected By LD_* Variables -#define QEMU_NAME "qemu-arm-static" - // Use Correct LibC - setenv("QEMU_LD_PREFIX", "/usr/arm-linux-gnueabihf", 1); +#define EXE_INTERPRETER "qemu-arm-static" +#endif - // Get Binary Directory - binary_directory = get_binary_directory(); // Create Full Path char *full_path = NULL; safe_asprintf(&full_path, "%s/" MCPI_NAME, binary_directory); + // Free Binary Directory free(binary_directory); @@ -217,6 +212,5 @@ void bootstrap(int argc, char *argv[]) { new_argv[0] = NULL; // Updated By safe_execvpe() new_argv[1] = full_path; // Path To MCPI // Run - safe_execvpe(QEMU_NAME, new_argv, environ); -#endif + safe_execvpe(EXE_INTERPRETER, new_argv, environ); } diff --git a/libreborn/include/libreborn/minecraft.h b/libreborn/include/libreborn/minecraft.h index f2b436484..18c932b25 100644 --- a/libreborn/include/libreborn/minecraft.h +++ b/libreborn/include/libreborn/minecraft.h @@ -35,6 +35,7 @@ static unsigned char **Tile_web = (unsigned char **) 0x181d08; static unsigned char **Tile_topSnow = (unsigned char **) 0x181b30; static unsigned char **Tile_ice = (unsigned char **) 0x181d80; static unsigned char **Tile_invisible_bedrock = (unsigned char **) 0x181d94; +static unsigned char **Tile_netherReactor = (unsigned char **) 0x181dd0; static unsigned char **Tile_leaves = (unsigned char **) 0x18120c; static unsigned char **Tile_leaves_carried = (unsigned char **) 0x181dd8; diff --git a/mods/CMakeLists.txt b/mods/CMakeLists.txt index 1206ed5fe..7a040f0bf 100644 --- a/mods/CMakeLists.txt +++ b/mods/CMakeLists.txt @@ -44,6 +44,9 @@ target_link_libraries(death reborn feature) add_library(misc SHARED src/misc/misc.c src/misc/misc.cpp) target_link_libraries(misc reborn feature) +add_library(creative SHARED src/creative/creative.cpp) +target_link_libraries(creative reborn feature) + add_library(options SHARED src/options/options.c) target_link_libraries(options reborn feature) @@ -69,7 +72,7 @@ add_library(test SHARED src/test/test.c) target_link_libraries(test reborn home) add_library(init SHARED src/init/init.c) -target_link_libraries(init compat game-mode camera input sign misc death options touch textures atlas chat home version test) +target_link_libraries(init compat game-mode camera input sign misc creative death options touch textures atlas chat home version test) if(MCPI_SERVER_MODE) target_link_libraries(init server) else() @@ -77,7 +80,7 @@ else() endif() ## Install Mods -install(TARGETS init compat readdir feature override game-mode camera input sign misc death options touch textures atlas chat home version test DESTINATION "${MCPI_INSTALL_DIR}/mods") +install(TARGETS init compat readdir feature override game-mode camera input sign misc creative death options touch textures atlas chat home version test DESTINATION "${MCPI_INSTALL_DIR}/mods") if(MCPI_SERVER_MODE) install(TARGETS server DESTINATION "${MCPI_INSTALL_DIR}/mods") else() diff --git a/mods/src/creative/README.md b/mods/src/creative/README.md new file mode 100644 index 000000000..b65fe72d6 --- /dev/null +++ b/mods/src/creative/README.md @@ -0,0 +1,2 @@ +# ``creative`` Mod +This mod adds an optional feature flag to add more items to the Creative Mode inventory. diff --git a/mods/src/creative/creative.cpp b/mods/src/creative/creative.cpp new file mode 100644 index 000000000..009f7ee8c --- /dev/null +++ b/mods/src/creative/creative.cpp @@ -0,0 +1,57 @@ +#include +#include + +#include "../init/init.h" +#include "../feature/feature.h" + +// Add Item To Inventory +static void inventory_add_item(unsigned char *inventory, unsigned char *item, bool is_tile) { + ItemInstance *item_instance = new ItemInstance; + ALLOC_CHECK(item_instance); + item_instance = (*(is_tile ? ItemInstance_constructor_tile : ItemInstance_constructor_item))(item_instance, item); + (*FillingContainer_addItem)(inventory, item_instance); +} + +// Expand Creative Inventory +static int32_t Inventory_setupDefault_FillingContainer_addItem_call_injection(unsigned char *filling_container, ItemInstance *item_instance) { + // Call Original + int32_t ret = (*FillingContainer_addItem)(filling_container, item_instance); + + // Add Items + inventory_add_item(filling_container, *Item_flintAndSteel, false); + inventory_add_item(filling_container, *Item_snowball, false); + inventory_add_item(filling_container, *Item_egg, false); + inventory_add_item(filling_container, *Item_shears, false); + // Dyes + for (int i = 0; i < 16; i++) { + if (i == 15) { + // Bonemeal Is Already In The Creative Inventory + continue; + } + ItemInstance *new_item_instance = new ItemInstance; + ALLOC_CHECK(new_item_instance); + new_item_instance = (*ItemInstance_constructor_item_extra)(new_item_instance, *Item_dye_powder, 1, i); + (*FillingContainer_addItem)(filling_container, new_item_instance); + } + inventory_add_item(filling_container, *Item_camera, false); + // Add Tiles + inventory_add_item(filling_container, *Tile_water, true); + inventory_add_item(filling_container, *Tile_lava, true); + inventory_add_item(filling_container, *Tile_calmWater, true); + inventory_add_item(filling_container, *Tile_calmLava, true); + inventory_add_item(filling_container, *Tile_glowingObsidian, true); + inventory_add_item(filling_container, *Tile_web, true); + inventory_add_item(filling_container, *Tile_topSnow, true); + inventory_add_item(filling_container, *Tile_ice, true); + inventory_add_item(filling_container, *Tile_invisible_bedrock, true); + + return ret; +} + +// Init +void init_creative() { + // Add Extra Items To Creative Inventory (Only Replace Specific Function Call) + if (feature_has("Expand Creative Inventory", 0)) { + overwrite_call((void *) 0x8e0fc, (void *) Inventory_setupDefault_FillingContainer_addItem_call_injection); + } +} diff --git a/mods/src/init/init.c b/mods/src/init/init.c index 6c61606d3..be4e30a70 100644 --- a/mods/src/init/init.c +++ b/mods/src/init/init.c @@ -12,6 +12,7 @@ __attribute__((constructor)) static void init() { init_input(); init_sign(); init_misc(); + init_creative(); init_death(); init_camera(); init_options(); diff --git a/mods/src/init/init.h b/mods/src/init/init.h index ecde1af72..062c80f4c 100644 --- a/mods/src/init/init.h +++ b/mods/src/init/init.h @@ -15,6 +15,7 @@ void init_game_mode(); void init_input(); void init_sign(); void init_misc(); +void init_creative(); void init_death(); void init_camera(); void init_options(); diff --git a/mods/src/misc/README.md b/mods/src/misc/README.md index 182bc2326..3b1231b8d 100644 --- a/mods/src/misc/README.md +++ b/mods/src/misc/README.md @@ -4,5 +4,4 @@ This mod has several miscellaneous mods that are too small to be their own mod, * Sanitizing player usernames for invalid characters. * Removing the red background from unobtainable items in the inventory. * Loading the bundled language file. -* Optionally expanding the Creative Inventory. * Printing chat messages to the log. diff --git a/mods/src/misc/misc.c b/mods/src/misc/misc.c index cb2f6f136..920b311a6 100644 --- a/mods/src/misc/misc.c +++ b/mods/src/misc/misc.c @@ -5,9 +5,9 @@ #include #include +#include "../init/init.h" #include "../feature/feature.h" #include "misc.h" -#include "../init/init.h" // Maximum Username Length #define MAX_USERNAME_LENGTH 16 diff --git a/mods/src/misc/misc.cpp b/mods/src/misc/misc.cpp index 8fdc97171..3a1daeea5 100644 --- a/mods/src/misc/misc.cpp +++ b/mods/src/misc/misc.cpp @@ -5,12 +5,11 @@ #include #include +#include #include "../feature/feature.h" #include "misc.h" -#include - // Read Asset File static AppPlatform_readAssetFile_return_value AppPlatform_readAssetFile_injection(__attribute__((unused)) unsigned char *app_platform, std::string const& path) { // Read File @@ -25,49 +24,6 @@ static AppPlatform_readAssetFile_return_value AppPlatform_readAssetFile_injectio return ret; } -// Add Item To Inventory -static void inventory_add_item(unsigned char *inventory, unsigned char *item, bool is_tile) { - ItemInstance *item_instance = new ItemInstance; - ALLOC_CHECK(item_instance); - item_instance = (*(is_tile ? ItemInstance_constructor_tile : ItemInstance_constructor_item))(item_instance, item); - (*FillingContainer_addItem)(inventory, item_instance); -} - -// Expand Creative Inventory -static int32_t Inventory_setupDefault_FillingContainer_addItem_call_injection(unsigned char *filling_container, ItemInstance *item_instance) { - // Call Original - int32_t ret = (*FillingContainer_addItem)(filling_container, item_instance); - - // Add Items - inventory_add_item(filling_container, *Item_flintAndSteel, false); - inventory_add_item(filling_container, *Item_snowball, false); - inventory_add_item(filling_container, *Item_egg, false); - inventory_add_item(filling_container, *Item_shears, false); - for (int i = 0; i < 16; i++) { - if (i == 15) { - // Bonemeal Is Already In The Creative Inventory - continue; - } - ItemInstance *new_item_instance = new ItemInstance; - ALLOC_CHECK(new_item_instance); - new_item_instance = (*ItemInstance_constructor_item_extra)(new_item_instance, *Item_dye_powder, 1, i); - (*FillingContainer_addItem)(filling_container, new_item_instance); - } - inventory_add_item(filling_container, *Item_camera, false); - // Add Tiles - inventory_add_item(filling_container, *Tile_water, true); - inventory_add_item(filling_container, *Tile_lava, true); - inventory_add_item(filling_container, *Tile_calmWater, true); - inventory_add_item(filling_container, *Tile_calmLava, true); - inventory_add_item(filling_container, *Tile_glowingObsidian, true); - inventory_add_item(filling_container, *Tile_web, true); - inventory_add_item(filling_container, *Tile_topSnow, true); - inventory_add_item(filling_container, *Tile_ice, true); - inventory_add_item(filling_container, *Tile_invisible_bedrock, true); - - return ret; -} - // Print Chat To Log static bool Gui_addMessage_recursing = false; static void Gui_addMessage_injection(unsigned char *gui, std::string const& text) { @@ -105,11 +61,6 @@ void _init_misc_cpp() { overwrite((void *) AppPlatform_readAssetFile, (void *) AppPlatform_readAssetFile_injection); } - // Add Extra Items To Creative Inventory (Only Replace Specific Function Call) - if (feature_has("Expand Creative Inventory", 0)) { - overwrite_call((void *) 0x8e0fc, (void *) Inventory_setupDefault_FillingContainer_addItem_call_injection); - } - // Print Chat To Log overwrite_calls((void *) Gui_addMessage, (void *) Gui_addMessage_injection); }