From 3937f8808490e879ccf8b9d2f2797aacb9a0730f Mon Sep 17 00:00:00 2001 From: TheBrokenRail Date: Thu, 7 Jul 2022 00:37:53 -0400 Subject: [PATCH] More Fixes --- CMakeLists.txt | 11 +++++++++++ cmake/{ => toolchain}/amd64-toolchain.cmake | 0 cmake/{ => toolchain}/arm64-toolchain.cmake | 0 cmake/{ => toolchain}/armhf-toolchain.cmake | 0 cmake/{ => toolchain}/base-toolchain.cmake | 0 cmake/{ => toolchain}/i386-toolchain.cmake | 0 dependencies/libpng/CMakeLists.txt | 2 +- images/CMakeLists.txt | 4 ++-- launcher/CMakeLists.txt | 7 +++---- libreborn/src/patch/patch.c | 21 +++++++++++++-------- media-layer/gles/CMakeLists.txt | 2 +- scripts/package.sh | 20 +++++++++++++------- scripts/setup.sh | 4 ++-- 13 files changed, 46 insertions(+), 25 deletions(-) rename cmake/{ => toolchain}/amd64-toolchain.cmake (100%) rename cmake/{ => toolchain}/arm64-toolchain.cmake (100%) rename cmake/{ => toolchain}/armhf-toolchain.cmake (100%) rename cmake/{ => toolchain}/base-toolchain.cmake (100%) rename cmake/{ => toolchain}/i386-toolchain.cmake (100%) diff --git a/CMakeLists.txt b/CMakeLists.txt index bb0c90829..d5557f4ed 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -6,12 +6,15 @@ set(MCPI_BUILD_MODE "native" CACHE STRING "\"arm\" = Build Only Code That Must B set_property(CACHE MCPI_BUILD_MODE PROPERTY STRINGS "arm" "native") option(MCPI_OPEN_SOURCE_ONLY "Only Install Open-Source Code (Will Result In Broken Install)" FALSE) option(MCPI_IS_APPIMAGE_BUILD "AppImage Build" FALSE) + # Server/Headless Builds option(MCPI_SERVER_MODE "Server Mode" FALSE) option(MCPI_HEADLESS_MODE "Headless Mode" ${MCPI_SERVER_MODE}) + # ARMHF Sysroot option(MCPI_BUNDLE_ARMHF_SYSROOT "Whether To Include An ARMHF Sysroot" ${MCPI_IS_MIXED_BUILD}) set(MCPI_CUSTOM_BUNDLED_ARMHF_SYSROOT "" CACHE PATH "Custom Bundled ARMHF Sysroot") + # Media Layer if(NOT MCPI_HEADLESS_MODE) option(MCPI_USE_MEDIA_LAYER_PROXY "Whether To Enable The Media Layer Proxy" ${MCPI_IS_MIXED_BUILD}) @@ -20,6 +23,7 @@ else() set(MCPI_USE_MEDIA_LAYER_PROXY FALSE) set(MCPI_USE_GLES1_COMPATIBILITY_LAYER FALSE) endif() + # App ID set(DEFAULT_APP_ID "com.thebrokenrail.MCPIReborn") if(MCPI_SERVER_MODE) @@ -28,6 +32,7 @@ else() string(APPEND DEFAULT_APP_ID "Client") endif() set(MCPI_APP_ID "${DEFAULT_APP_ID}" CACHE STRING "App ID") + # App Title set(DEFAULT_APP_TITLE "Minecraft: Pi Edition: Reborn") if(MCPI_SERVER_MODE) @@ -76,6 +81,12 @@ elseif(BUILD_NATIVE_COMPONENTS) string(APPEND MCPI_LIB_DIR "/native") endif() +# Share Directory +set(MCPI_SHARE_DIR "share") +if(MCPI_IS_APPIMAGE_BUILD) + string(PREPEND MCPI_SHARE_DIR "usr/") +endif() + # Build Mode if(NOT CMAKE_BUILD_TYPE) set(CMAKE_BUILD_TYPE "Release") diff --git a/cmake/amd64-toolchain.cmake b/cmake/toolchain/amd64-toolchain.cmake similarity index 100% rename from cmake/amd64-toolchain.cmake rename to cmake/toolchain/amd64-toolchain.cmake diff --git a/cmake/arm64-toolchain.cmake b/cmake/toolchain/arm64-toolchain.cmake similarity index 100% rename from cmake/arm64-toolchain.cmake rename to cmake/toolchain/arm64-toolchain.cmake diff --git a/cmake/armhf-toolchain.cmake b/cmake/toolchain/armhf-toolchain.cmake similarity index 100% rename from cmake/armhf-toolchain.cmake rename to cmake/toolchain/armhf-toolchain.cmake diff --git a/cmake/base-toolchain.cmake b/cmake/toolchain/base-toolchain.cmake similarity index 100% rename from cmake/base-toolchain.cmake rename to cmake/toolchain/base-toolchain.cmake diff --git a/cmake/i386-toolchain.cmake b/cmake/toolchain/i386-toolchain.cmake similarity index 100% rename from cmake/i386-toolchain.cmake rename to cmake/toolchain/i386-toolchain.cmake diff --git a/dependencies/libpng/CMakeLists.txt b/dependencies/libpng/CMakeLists.txt index d07b22c08..a77779b17 100644 --- a/dependencies/libpng/CMakeLists.txt +++ b/dependencies/libpng/CMakeLists.txt @@ -16,7 +16,7 @@ set(PNG_SHARED TRUE CACHE BOOL "" FORCE) # Download set(ZLIB_LIBRARY zlibstatic) -set(ZLIB_INCLUDE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/../zlib/src" "${CMAKE_CURRENT_BINARY_DIR}/../zlib/src") +set(ZLIB_INCLUDE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/zlib/src" "${CMAKE_CURRENT_BINARY_DIR}/zlib/src") set(CMAKE_POLICY_DEFAULT_CMP0054 OLD) # Silence Warning set(CMAKE_POLICY_DEFAULT_CMP0003 NEW) # Silence Warning set(CMAKE_POLICY_DEFAULT_CMP0022 NEW) # Fix Error diff --git a/images/CMakeLists.txt b/images/CMakeLists.txt index d1dfeb142..2432b6a90 100644 --- a/images/CMakeLists.txt +++ b/images/CMakeLists.txt @@ -12,12 +12,12 @@ endif() # Icon install( FILES "icon.png" - DESTINATION "share/icons/hicolor/scalable/apps" + DESTINATION "${MCPI_SHARE_DIR}/icons/hicolor/scalable/apps" RENAME "${MCPI_APP_ID}.png" ) # AppImage if(MCPI_IS_APPIMAGE_BUILD) - install_symlink("share/icons/hicolor/scalable/apps/${MCPI_APP_ID}.png" "${MCPI_APP_ID}.png") + install_symlink("${MCPI_SHARE_DIR}/icons/hicolor/scalable/apps/${MCPI_APP_ID}.png" "${MCPI_APP_ID}.png") install_symlink("${MCPI_APP_ID}.png" ".DirIcon") endif() diff --git a/launcher/CMakeLists.txt b/launcher/CMakeLists.txt index 5e6c0d940..5d7d412d2 100644 --- a/launcher/CMakeLists.txt +++ b/launcher/CMakeLists.txt @@ -44,7 +44,7 @@ else() endif() install( FILES "${CMAKE_CURRENT_BINARY_DIR}/launcher.desktop" - DESTINATION "share/applications" + DESTINATION "${MCPI_SHARE_DIR}/applications" RENAME "${MCPI_APP_ID}.desktop" ) @@ -107,13 +107,12 @@ file(APPEND "${CMAKE_CURRENT_BINARY_DIR}/appstream.xml" ) install( FILES "${CMAKE_CURRENT_BINARY_DIR}/appstream.xml" - DESTINATION "share/metainfo" + DESTINATION "${MCPI_SHARE_DIR}/metainfo" RENAME "${MCPI_APP_ID}.appdata.xml" ) # AppImage if(MCPI_IS_APPIMAGE_BUILD) install_symlink("bin/${MCPI_VARIANT_NAME}" "AppRun") - install_symlink("share/applications/${MCPI_APP_ID}.desktop" "${MCPI_APP_ID}.desktop") - install_symlink("." "usr") + install_symlink("${MCPI_SHARE_DIR}/applications/${MCPI_APP_ID}.desktop" "${MCPI_APP_ID}.desktop") endif() diff --git a/libreborn/src/patch/patch.c b/libreborn/src/patch/patch.c index cef815690..50ac4ea9c 100644 --- a/libreborn/src/patch/patch.c +++ b/libreborn/src/patch/patch.c @@ -72,6 +72,12 @@ static unsigned char *code_block = NULL; #define CODE_SIZE 8 static int code_block_remaining = CODE_BLOCK_SIZE; +static void _long_overwrite(void *start, void *target) { + unsigned char patch_data[4] = {0x04, 0xf0, 0x1f, 0xe5}; // "ldr pc, [pc, #-0x4]" + + _patch(NULL, -1, start, patch_data); + _patch_address(NULL, -1, (void *) (((unsigned char *) start) + 4), target); +} static void update_code_block(void *target) { // BL Instructions Can Only Access A Limited Portion of Memory, So This Allocates Memory Closer To The Original Instruction, That When Run, Will Jump Into The Actual Target if (code_block == NULL) { @@ -84,7 +90,7 @@ static void update_code_block(void *target) { if (code_block_remaining < CODE_SIZE) { ERR("Maximum Amount Of overwrite_calls() Uses Reached"); } - _overwrite(NULL, -1, code_block, target); + _long_overwrite(code_block, target); } static void increment_code_block() { code_block = code_block + CODE_SIZE; @@ -92,18 +98,21 @@ static void increment_code_block() { } // Overwrite Specific B(L) Instruction -void _overwrite_call(const char *file, int line, void *start, void *target) { +static void _overwrite_call_internal(const char *file, int line, void *start, void *target, int use_b_instruction) { // Add New Target To Code Block update_code_block(target); // Patch - int use_b_instruction = ((unsigned char *) start)[3] == B_INSTRUCTION; uint32_t new_instruction = generate_bl_instruction(start, code_block, use_b_instruction); _patch(file, line, start, (unsigned char *) &new_instruction); // Increment Code Block Position increment_code_block(); } +void _overwrite_call(const char *file, int line, void *start, void *target) { + int use_b_instruction = ((unsigned char *) start)[3] == B_INSTRUCTION; + _overwrite_call_internal(file, line, start, target, use_b_instruction); +} // Overwrite All B(L) Intrusctions That Target The Specified Address void _overwrite_calls(const char *file, int line, void *start, void *target) { @@ -144,12 +153,8 @@ void *extract_from_bl_instruction(unsigned char *from) { } // Overwrite Function -// NOTE: "start" Must Be At Least 8 Bytes Long void _overwrite(const char *file, int line, void *start, void *target) { - unsigned char patch_data[4] = {0x04, 0xf0, 0x1f, 0xe5}; // "ldr pc, [pc, #-0x4]" - - _patch(file, line, start, patch_data); - _patch_address(file, line, (void *) (((unsigned char *) start) + 4), target); + _overwrite_call_internal(file, line, start, target, 1); } // Print Patch Debug Data diff --git a/media-layer/gles/CMakeLists.txt b/media-layer/gles/CMakeLists.txt index 131f6ecf5..c1fdfd630 100644 --- a/media-layer/gles/CMakeLists.txt +++ b/media-layer/gles/CMakeLists.txt @@ -1,4 +1,4 @@ -project(media-layer-stubs) +project(media-layer-gles) # Stubs Only Needed For ARM if(NOT MCPI_HEADLESS_MODE AND ((BUILD_NATIVE_COMPONENTS AND MCPI_USE_MEDIA_LAYER_PROXY) OR (BUILD_ARM_COMPONENTS AND NOT MCPI_USE_MEDIA_LAYER_PROXY))) diff --git a/scripts/package.sh b/scripts/package.sh index c698bafcf..9e85e065b 100755 --- a/scripts/package.sh +++ b/scripts/package.sh @@ -11,19 +11,25 @@ BRANCH='master' ./scripts/build.sh "$1" "$2" # Download Runtime -case "$2" in - 'armhf') RUNTIME_ARCH='armhf';; - 'arm64') RUNTIME_ARCH='aarch64';; - 'i386') RUNTIME_ARCH='i686';; - 'amd64') RUNTIME_ARCH='x86_64';; -esac mkdir -p build/appimage if [ ! -f "build/appimage/runtime-$2" ]; then + case "$2" in + 'armhf') RUNTIME_ARCH='armhf';; + 'arm64') RUNTIME_ARCH='aarch64';; + 'i386') RUNTIME_ARCH='i686';; + 'amd64') RUNTIME_ARCH='x86_64';; + esac wget -O "build/appimage/runtime-$2" "https://github.com/AppImage/AppImageKit/releases/download/continuous/runtime-${RUNTIME_ARCH}" fi # Package -ARCH="${RUNTIME_ARCH}" appimagetool \ +case "$2" in + 'armhf') APPIMAGE_ARCH='arm';; + 'arm64') APPIMAGE_ARCH='arm_aarch64';; + 'i386') APPIMAGE_ARCH='i686';; + 'amd64') APPIMAGE_ARCH='x86_64';; +esac +ARCH="${APPIMAGE_ARCH}" appimagetool \ --updateinformation "zsync|https://jenkins.thebrokenrail.com/job/minecraft-pi-reborn/job/${BRANCH}/lastSuccessfulBuild/artifact/out/${NAME}-latest-$2.AppImage.zsync" \ --runtime-file "build/appimage/runtime-$2" \ --comp xz \ diff --git a/scripts/setup.sh b/scripts/setup.sh index 8951039e2..3b85bcc04 100755 --- a/scripts/setup.sh +++ b/scripts/setup.sh @@ -3,12 +3,12 @@ set -e # ARM Toolchain File -ARM_TOOLCHAIN_FILE="$(pwd)/cmake/armhf-toolchain.cmake" +ARM_TOOLCHAIN_FILE="$(pwd)/cmake/toolchain/armhf-toolchain.cmake" # Setup setup() { # Find Toolchain - local toolchain_file="$(pwd)/cmake/${ARCH}-toolchain.cmake" + local toolchain_file="$(pwd)/cmake/toolchain/${ARCH}-toolchain.cmake" if [ ! -f "${toolchain_file}" ]; then echo "Invalid Architecture: ${ARCH}" > /dev/stderr exit 1