From 67002006f32967de67f59754f859b96ef2e679b8 Mon Sep 17 00:00:00 2001 From: TheBrokenRail Date: Wed, 13 Jul 2022 11:58:35 -0400 Subject: [PATCH] Vendor PatchELF --- .gitmodules | 3 ++ cmake/toolchain/base-toolchain.cmake | 29 +++++++++++++++++-- .../expanded-creative/expanded-creative.cpp | 7 +---- launcher/CMakeLists.txt | 3 ++ launcher/dependencies/CMakeLists.txt | 4 +++ launcher/dependencies/patchelf/CMakeLists.txt | 14 +++++++++ launcher/dependencies/patchelf/src | 1 + launcher/src/patchelf.c | 5 ++-- media-layer/core/gles/CMakeLists.txt | 24 +++++++-------- media-layer/proxy/CMakeLists.txt | 2 -- 10 files changed, 67 insertions(+), 25 deletions(-) create mode 100644 launcher/dependencies/CMakeLists.txt create mode 100644 launcher/dependencies/patchelf/CMakeLists.txt create mode 160000 launcher/dependencies/patchelf/src diff --git a/.gitmodules b/.gitmodules index e4dfa53..1e3a608 100644 --- a/.gitmodules +++ b/.gitmodules @@ -10,3 +10,6 @@ [submodule "dependencies/zenity/src"] path = dependencies/zenity/src url = https://gitea.thebrokenrail.com/TheBrokenRail/zenity.git +[submodule "launcher/dependencies/patchelf/src"] + path = launcher/dependencies/patchelf/src + url = https://github.com/NixOS/patchelf.git diff --git a/cmake/toolchain/base-toolchain.cmake b/cmake/toolchain/base-toolchain.cmake index e04dd76..ce35216 100644 --- a/cmake/toolchain/base-toolchain.cmake +++ b/cmake/toolchain/base-toolchain.cmake @@ -1,8 +1,31 @@ # Setup Toolchain macro(setup_toolchain target) - # Use ARM Cross-Compiler - set(CMAKE_C_COMPILER "${target}-gcc") - set(CMAKE_CXX_COMPILER "${target}-g++") + # Target Variants + set(target_variants "${target}") + macro(add_target_variant value) + string(REPLACE "-linux" "-${value}-linux" target_variant "${target}") + list(APPEND target_variants "${target_variant}") + endmacro() + add_target_variant(unknown) + add_target_variant(none) + add_target_variant(pc) + # Find Compiler + macro(find_compiler output name) + set(possible_names "") + foreach(possible_target IN LISTS target_variants) + list(APPEND possible_names "${possible_target}-${name}") + endforeach() + find_program( + "${output}" + NAMES ${possible_names} + NO_CACHE + ) + if("${${output}}" STREQUAL "${output}-NOTFOUND") + message(FATAL_ERROR "Unable To Find ${name}") + endif() + endmacro() + find_compiler(CMAKE_C_COMPILER "gcc") + find_compiler(CMAKE_CXX_COMPILER "g++") # Extra set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER) # Custom Search Paths diff --git a/example-mods/expanded-creative/expanded-creative.cpp b/example-mods/expanded-creative/expanded-creative.cpp index 45c562d..bda9462 100644 --- a/example-mods/expanded-creative/expanded-creative.cpp +++ b/example-mods/expanded-creative/expanded-creative.cpp @@ -2,7 +2,6 @@ #include #include -#include #include // The Actual Mod @@ -633,11 +632,7 @@ static void Inventory_setupDefault_FillingContainer_addItem_call_injection(unsig } // Init -HOOK(init_creative, void, ()) { - ensure_init_creative(); - (*real_init_creative)(); - +__attribute__((constructor)) static void init_expanded_creative() { INFO("Loading Expanded Creative Mod"); - misc_run_on_creative_inventory_setup(Inventory_setupDefault_FillingContainer_addItem_call_injection); } diff --git a/launcher/CMakeLists.txt b/launcher/CMakeLists.txt index 5d7d412..3df16eb 100644 --- a/launcher/CMakeLists.txt +++ b/launcher/CMakeLists.txt @@ -1,5 +1,8 @@ project(launcher) +# Dependencies +add_subdirectory(dependencies) + # Launcher add_executable(launcher src/bootstrap.c src/patchelf.c src/crash-report.c) if(MCPI_SERVER_MODE) diff --git a/launcher/dependencies/CMakeLists.txt b/launcher/dependencies/CMakeLists.txt new file mode 100644 index 0000000..19ac04e --- /dev/null +++ b/launcher/dependencies/CMakeLists.txt @@ -0,0 +1,4 @@ +project(launcher-dependencies) + +# PatchELF +add_subdirectory(patchelf) diff --git a/launcher/dependencies/patchelf/CMakeLists.txt b/launcher/dependencies/patchelf/CMakeLists.txt new file mode 100644 index 0000000..3936cdb --- /dev/null +++ b/launcher/dependencies/patchelf/CMakeLists.txt @@ -0,0 +1,14 @@ +project(patchelf) + +# Silence Warnings +add_compile_options(-w) + +## PatchELF + +# Build +add_executable(patchelf src/src/patchelf.cc) +target_compile_definitions(patchelf PRIVATE -D_FILE_OFFSET_BITS=64) +set_target_properties(patchelf PROPERTIES CXX_STANDARD 17) + +# Install +install(TARGETS patchelf DESTINATION "${MCPI_BIN_DIR}") diff --git a/launcher/dependencies/patchelf/src b/launcher/dependencies/patchelf/src new file mode 160000 index 0000000..734daa3 --- /dev/null +++ b/launcher/dependencies/patchelf/src @@ -0,0 +1 @@ +Subproject commit 734daa3d0f79cf1a0c81f927d846ace5d6a2c8e1 diff --git a/launcher/src/patchelf.c b/launcher/src/patchelf.c index df5577e..5111b42 100644 --- a/launcher/src/patchelf.c +++ b/launcher/src/patchelf.c @@ -72,8 +72,9 @@ static void duplicate_mcpi_executable(const char *original_path, char *new_path) "--remove-needed", "libbcm_host.so", \ "--remove-needed", "libX11.so.6", \ "--remove-needed", "libEGL.so", \ - "--replace-needed", "libGLESv2.so", "libGLESv1_CM.so.1", \ - "--replace-needed", "libSDL-1.2.so.0", "libmedia-layer-core.so", \ + "--remove-needed", "libGLESv2.so", \ + "--remove-needed", "libSDL-1.2.so.0", \ + "--add-needed", "libmedia-layer-core.so", \ new_path, \ NULL \ }; \ diff --git a/media-layer/core/gles/CMakeLists.txt b/media-layer/core/gles/CMakeLists.txt index 31aa966..8180687 100644 --- a/media-layer/core/gles/CMakeLists.txt +++ b/media-layer/core/gles/CMakeLists.txt @@ -1,19 +1,19 @@ project(media-layer-gles) # Build -if(NOT MCPI_HEADLESS_MODE) - if(MCPI_USE_GLES1_COMPATIBILITY_LAYER) - # GLESv1_CM Compatibility Layer - set(GLES_SRC src/compatibility-layer/state.c src/compatibility-layer/passthrough.c src/compatibility-layer/matrix.c src/compatibility-layer/draw.c src/compatibility-layer/buffer.cpp) - else() - # Passthrough To glfwGetProcAddress() - set(GLES_SRC src/passthrough.c) - endif() - add_library(GLESv1_CM SHARED ${GLES_SRC}) - target_link_libraries(GLESv1_CM PRIVATE glfw PUBLIC reborn-util PRIVATE dl PRIVATE m) -else() +if(MCPI_HEADLESS_MODE) # Stubs For Headless Mode - add_library(GLESv1_CM SHARED src/stubs.c) + set(GLES_SRC src/stubs.c) +elseif(MCPI_USE_GLES1_COMPATIBILITY_LAYER) + # GLESv1_CM Compatibility Layer + set(GLES_SRC src/compatibility-layer/state.c src/compatibility-layer/passthrough.c src/compatibility-layer/matrix.c src/compatibility-layer/draw.c src/compatibility-layer/buffer.cpp) +else() + # Passthrough To glfwGetProcAddress() + set(GLES_SRC src/passthrough.c) +endif() +add_library(GLESv1_CM SHARED ${GLES_SRC}) +if(NOT MCPI_HEADLESS_MODE) + target_link_libraries(GLESv1_CM PRIVATE glfw PUBLIC reborn-util PRIVATE dl PRIVATE m) endif() # Common diff --git a/media-layer/proxy/CMakeLists.txt b/media-layer/proxy/CMakeLists.txt index 8b2ea5f..3834219 100644 --- a/media-layer/proxy/CMakeLists.txt +++ b/media-layer/proxy/CMakeLists.txt @@ -19,6 +19,4 @@ elseif(BUILD_ARM_COMPONENTS) # Install install(TARGETS media-layer-core DESTINATION "${MCPI_LIB_DIR}") install(TARGETS media-layer-core EXPORT sdk DESTINATION "${MCPI_SDK_LIB_DIR}") - # Symlink GLESv1_CM To Media Layer Proxy Server - install_symlink("libmedia-layer-core.so" "${MCPI_LIB_DIR}/libGLESv1_CM.so.1") endif()