From b59c580f6ab260591f383e907d84e34bed0b984e Mon Sep 17 00:00:00 2001 From: TheBrokenRail Date: Wed, 11 May 2022 18:24:03 -0400 Subject: [PATCH] Fix Build On Ubuntu 22.04 & Bug Fixes --- CMakeLists.txt | 15 +++++++ dependencies/CMakeLists.txt | 2 +- dependencies/armhf-sysroot/CMakeLists.txt | 26 +++++------ dependencies/armhf-sysroot/apt/sources.list | 1 - dependencies/glfw/src | 2 +- .../available-feature-flags | 2 +- launcher/src/bootstrap.c | 8 ++-- mods/src/misc/misc.c | 2 + mods/src/options/options.c | 2 + mods/src/options/options.cpp | 4 +- mods/src/server/server.cpp | 7 +++ scripts/package.sh | 2 +- .../generate-appimage-builder-yaml.js | 19 ++++---- scripts/tools/get-apt-sources.sh | 43 +++++++++++++++++++ symbols/include/symbols/minecraft.h | 2 +- 15 files changed, 105 insertions(+), 32 deletions(-) delete mode 100644 dependencies/armhf-sysroot/apt/sources.list rename scripts/{ => tools}/generate-appimage-builder-yaml.js (90%) create mode 100755 scripts/tools/get-apt-sources.sh diff --git a/CMakeLists.txt b/CMakeLists.txt index 1bf8c077..f72db20b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -2,6 +2,9 @@ cmake_minimum_required(VERSION 3.13.0) # Specify Options option(MCPI_IS_MIXED_BUILD "Whether The Architecture-Independent And ARM Code Are Different Architecture" FALSE) +if(MCPI_IS_MIXED_BUILD) + option(MCPI_BUNDLE_ARMHF_SYSROOT "Whether To Include An ARMHF Sysroot" TRUE) +endif() option(MCPI_SERVER_MODE "Server Mode" FALSE) option(MCPI_HEADLESS_MODE "Headless Mode" ${MCPI_SERVER_MODE}) if(NOT MCPI_HEADLESS_MODE) @@ -55,6 +58,11 @@ endif() # Start Project project(minecraft-pi-reborn) +# Sanity Check +if(BUILD_NATIVE_COMPONENTS AND NOT CMAKE_SYSTEM_PROCESSOR MATCHES "^arm" AND NOT MCPI_IS_MIXED_BUILD) + message(FATAL_ERROR "Project is configured as a mixed-buld, but MCPI_IS_MIXED_BUILD is disabled.") +endif() + # Require ARM Compilation if(USE_ARM32_TOOLCHAIN AND NOT CMAKE_SYSTEM_PROCESSOR MATCHES "^arm") message(FATAL_ERROR "ARM-Targeting Compiler Required") @@ -88,6 +96,10 @@ add_subdirectory(dependencies) # Warnings add_compile_options(-Wall -Wextra -Werror -Wpointer-arith -Wshadow -Wnull-dereference) +if(CMAKE_CXX_COMPILER_VERSION VERSION_GREATER 10.0) + # Prevents False Positives + add_compile_options(-Wno-stringop-overflow) +endif() add_link_options(-Wl,--no-undefined) add_definitions(-D_GNU_SOURCE) set(CMAKE_C_STANDARD 99) @@ -103,6 +115,9 @@ endif() if(MCPI_IS_APPIMAGE_BUILD) add_definitions(-DMCPI_IS_APPIMAGE_BUILD) endif() +if(MCPI_BUNDLE_ARMHF_SYSROOT) + add_definitions(-DMCPI_BUNDLE_ARMHF_SYSROOT) +endif() # Version set_property( diff --git a/dependencies/CMakeLists.txt b/dependencies/CMakeLists.txt index c0c1c9a7..d7fd6a5e 100644 --- a/dependencies/CMakeLists.txt +++ b/dependencies/CMakeLists.txt @@ -21,6 +21,6 @@ if(BUILD_NATIVE_COMPONENTS AND NOT MCPI_HEADLESS_MODE) add_subdirectory(zenity) endif() # Sysroot -if(BUILD_ARM_COMPONENTS AND MCPI_IS_MIXED_BUILD) +if(BUILD_ARM_COMPONENTS AND MCPI_BUNDLE_ARMHF_SYSROOT) add_subdirectory(armhf-sysroot) endif() diff --git a/dependencies/armhf-sysroot/CMakeLists.txt b/dependencies/armhf-sysroot/CMakeLists.txt index 2831c8be..bef09ba3 100644 --- a/dependencies/armhf-sysroot/CMakeLists.txt +++ b/dependencies/armhf-sysroot/CMakeLists.txt @@ -9,20 +9,10 @@ else() # Download From APT set(APT_PACKAGES "libc6" "libstdc++6") - # Reconfigure CMake If APT Data Is Changed - file(GLOB_RECURSE APT_FILES "apt/*") - foreach(APT_FILE IN LISTS APT_FILES) - set_property( - DIRECTORY - APPEND - PROPERTY CMAKE_CONFIGURE_DEPENDS "${APT_FILE}" - ) - endforeach() - # Copy To Binary Directory - set(APT_DIR "${CMAKE_CURRENT_BINARY_DIR}/apt-build") + set(APT_DIR "${CMAKE_CURRENT_BINARY_DIR}/apt") file(REMOVE_RECURSE "${APT_DIR}") - file(COPY "${CMAKE_CURRENT_SOURCE_DIR}/apt/." DESTINATION "${APT_DIR}") + file(MAKE_DIRECTORY "${APT_DIR}") # Make Directories file(MAKE_DIRECTORY "${APT_DIR}/apt.conf.d") file(MAKE_DIRECTORY "${APT_DIR}/preferences.d") @@ -30,6 +20,18 @@ else() file(MAKE_DIRECTORY "${APT_DIR}/dpkg") file(TOUCH "${APT_DIR}/dpkg/status") + # Create APT Sources + execute_process( + COMMAND "${CMAKE_SOURCE_DIR}/scripts/tools/get-apt-sources.sh" + OUTPUT_STRIP_TRAILING_WHITESPACE + OUTPUT_VARIABLE APT_SOURCES + RESULT_VARIABLE APT_SOURCES_RESULT + ) + if(NOT APT_SOURCES_RESULT EQUAL 0) + message(FATAL_ERROR "Unable To Get APT Sources For ARMHF Sysroot") + endif() + file(WRITE "${APT_DIR}/sources.list" "${APT_SOURCES}") + # Create APT Config string(CONCAT APT_CONFIG "Dir \"${APT_DIR}\";\n" diff --git a/dependencies/armhf-sysroot/apt/sources.list b/dependencies/armhf-sysroot/apt/sources.list deleted file mode 100644 index 85e47a9e..00000000 --- a/dependencies/armhf-sysroot/apt/sources.list +++ /dev/null @@ -1 +0,0 @@ -deb https://deb.debian.org/debian/ sid main diff --git a/dependencies/glfw/src b/dependencies/glfw/src index 7dfd84c4..62e175ef 160000 --- a/dependencies/glfw/src +++ b/dependencies/glfw/src @@ -1 +1 @@ -Subproject commit 7dfd84c458dfa12b351c932b8281b13faf7b50b9 +Subproject commit 62e175ef9fae75335575964c845a302447c012c7 diff --git a/launcher/data/client/lib/minecraft-pi-reborn-client/available-feature-flags b/launcher/data/client/lib/minecraft-pi-reborn-client/available-feature-flags index 8a63f331..ff29790a 100644 --- a/launcher/data/client/lib/minecraft-pi-reborn-client/available-feature-flags +++ b/launcher/data/client/lib/minecraft-pi-reborn-client/available-feature-flags @@ -29,7 +29,7 @@ TRUE Close Current Screen On Death FALSE Disable Raw Mouse Motion (Not Recommended) TRUE Fix Furnace Not Checking Item Auxiliary TRUE Improved Cursor Rendering -FALSE Disable V-Sync +TRUE Disable V-Sync TRUE Fix Options Screen TRUE Force Touch GUI Inventory TRUE Fix Pause Menu diff --git a/launcher/src/bootstrap.c b/launcher/src/bootstrap.c index ec2223dc..bd82051c 100644 --- a/launcher/src/bootstrap.c +++ b/launcher/src/bootstrap.c @@ -227,7 +227,7 @@ void bootstrap(int argc, char *argv[]) { // Find Linker char *linker = NULL; // Select Linker -#ifndef __arm__ +#ifdef MCPI_BUNDLE_ARMHF_SYSROOT // Use ARM Sysroot Linker safe_asprintf(&linker, "%s/sysroot/lib/ld-linux-armhf.so.3", binary_directory); #else @@ -264,9 +264,9 @@ void bootstrap(int argc, char *argv[]) { // Add Library Directory safe_asprintf(&new_ld_path, "%s/lib", binary_directory); - // Add ARM Sysroot Libraries (Ensure Priority) (Ignroe On Actual ARM System) -#ifndef __arm__ - string_append(&new_ld_path, ":%s/sysroot/lib/arm-linux-gnueabihf:%s/sysroot/usr/lib/arm-linux-gnueabihf", binary_directory, binary_directory); + // Add ARM Sysroot Libraries (Ensure Priority) (Ignore On Actual ARM System) +#ifdef MCPI_BUNDLE_ARMHF_SYSROOT + string_append(&new_ld_path, ":%s/sysroot/lib:%s/sysroot/lib/arm-linux-gnueabihf:%s/sysroot/usr/lib:%s/sysroot/usr/lib/arm-linux-gnueabihf", binary_directory, binary_directory, binary_directory, binary_directory); #endif // Add LD_LIBRARY_PATH diff --git a/mods/src/misc/misc.c b/mods/src/misc/misc.c index beca6ae3..0f2a6c77 100644 --- a/mods/src/misc/misc.c +++ b/mods/src/misc/misc.c @@ -192,6 +192,8 @@ static void GameRenderer_render_injection(unsigned char *game_renderer, float pa // Check If Cursor Should Render if (SDL_WM_GrabInput(SDL_GRAB_QUERY) == SDL_GRAB_OFF) { + // Fix GL Mode + glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); // Get X And Y float x = (*Mouse_getX)() * (*InvGuiScale); float y = (*Mouse_getY)() * (*InvGuiScale); diff --git a/mods/src/options/options.c b/mods/src/options/options.c index 8b6af110..ef2a35f2 100644 --- a/mods/src/options/options.c +++ b/mods/src/options/options.c @@ -51,8 +51,10 @@ static void Options_initDefaultValue_injection(unsigned char *options) { (*Options_initDefaultValue)(options); // Default Graphics Settings +#ifndef MCPI_SERVER_MODE *(options + Options_fancy_graphics_property_offset) = 1; *(options + Options_ambient_occlusion_property_offset) = 1; +#endif // Store stored_options = options; diff --git a/mods/src/options/options.cpp b/mods/src/options/options.cpp index 87579711..99108214 100644 --- a/mods/src/options/options.cpp +++ b/mods/src/options/options.cpp @@ -91,7 +91,7 @@ static char *get_new_options_txt_path() { #endif // Modify Option Toggles -static void OptionsPane_unknown_toggle_creating_function_injection(unsigned char *options_pane, unsigned char *unknown_object, std::string const& name, unsigned char *option) { +static void OptionsPane_unknown_toggle_creating_function_injection(unsigned char *options_pane, uint32_t group_id, std::string const& name, unsigned char *option) { // Modify std::string new_name = name; if (name == "Fancy Graphics") { @@ -116,7 +116,7 @@ static void OptionsPane_unknown_toggle_creating_function_injection(unsigned char } // Call Original Method - (*OptionsPane_unknown_toggle_creating_function)(options_pane, unknown_object, new_name, option); + (*OptionsPane_unknown_toggle_creating_function)(options_pane, group_id, new_name, option); } // Add Missing Options To Options::getBooleanValue diff --git a/mods/src/server/server.cpp b/mods/src/server/server.cpp index 2f9dbd05..01d475b9 100644 --- a/mods/src/server/server.cpp +++ b/mods/src/server/server.cpp @@ -54,6 +54,7 @@ static ServerProperties &get_server_properties() { #define DEFAULT_PORT "19132" #define DEFAULT_SEED "" #define DEFAULT_FORCE_MOB_SPAWNING "false" +#define DEFAULT_PEACEFUL_MODE "false" #define DEFAULT_WORLD_NAME "world" #define DEFAULT_MAX_PLAYERS "4" #define DEFAULT_WHITELIST "false" @@ -72,6 +73,10 @@ static void start_world(unsigned char *minecraft) { // Log INFO("Loading World: %s", world_name.c_str()); + // Peaceful Mode + unsigned char *options = minecraft + Minecraft_options_property_offset; + *(int32_t *) (options + Options_game_difficulty_property_offset) = get_server_properties().get_bool("peaceful-mode", DEFAULT_PEACEFUL_MODE) ? 0 : 2; + // Specify Level Settings LevelSettings settings; settings.game_type = get_server_properties().get_int("game-mode", DEFAULT_GAME_MODE); @@ -461,6 +466,8 @@ static void server_init() { properties_file_output << "seed=" DEFAULT_SEED "\n"; properties_file_output << "# Force Mob Spawning (false = Disabled, true = Enabled)\n"; properties_file_output << "force-mob-spawning=" DEFAULT_FORCE_MOB_SPAWNING "\n"; + properties_file_output << "# Peaceful Mode (false = Disabled, true = Enabled)\n"; + properties_file_output << "peaceful-mode=" DEFAULT_PEACEFUL_MODE "\n"; properties_file_output << "# World To Select\n"; properties_file_output << "world-name=" DEFAULT_WORLD_NAME "\n"; properties_file_output << "# Maximum Player Count\n"; diff --git a/scripts/package.sh b/scripts/package.sh index 15ebbb2d..693ab409 100755 --- a/scripts/package.sh +++ b/scripts/package.sh @@ -3,7 +3,7 @@ set -e # Generate -./scripts/generate-appimage-builder-yaml.js "$1" "$2" +./scripts/tools/generate-appimage-builder-yaml.js "$1" "$2" # Build/Package appimage-builder --recipe AppImageBuilder.yml diff --git a/scripts/generate-appimage-builder-yaml.js b/scripts/tools/generate-appimage-builder-yaml.js similarity index 90% rename from scripts/generate-appimage-builder-yaml.js rename to scripts/tools/generate-appimage-builder-yaml.js index fdb353cc..2e256832 100755 --- a/scripts/generate-appimage-builder-yaml.js +++ b/scripts/tools/generate-appimage-builder-yaml.js @@ -1,5 +1,8 @@ #!/usr/bin/env node +// Child Process +const child_process = require('child_process'); + // Arguments if (process.argv.length < 4) { throw new Error('Invalid Arguments'); @@ -12,8 +15,12 @@ const id = `com.thebrokenrail.MCPIReborn${mode === 'server' ? 'Server' : 'Client const name = `minecraft-pi-reborn-${mode}`; const updateURL = `https://jenkins.thebrokenrail.com/job/minecraft-pi-reborn/job/master/lastSuccessfulBuild/artifact/out/${name}-latest-${arch}.AppImage.zsync`; -// APT Data -const apt_distribution = 'sid'; +// APT Sources +const apt_sources = child_process.execFileSync('./scripts/tools/get-apt-sources.sh', [], {encoding: 'utf-8'}).trim().split('\n'); +const apt_sources_formatted = []; +for (const apt_source of apt_sources) { + apt_sources_formatted.push({sourceline: apt_source}); +} // Version const fs = require('fs'); @@ -58,11 +65,7 @@ const packageExclusions = [ // APT const apt = { arch: arch, - sources: [ - { - sourceline: `deb [arch=${arch}] https://deb.debian.org/debian/ ${apt_distribution} main` - } - ], + sources: apt_sources_formatted, allow_unauthenticated: true, include: packages, exclude: packageExclusions @@ -113,7 +116,7 @@ const runtime = { GTK_PATH: `\${APPDIR}/usr/lib/${triplet}/gtk-3.0`, GTK_DATA_PREFIX: '${APPDIR}', GTK_THEME: 'Default', - XDG_DATA_DIRS: '${APPDIR}/share:${APPDIR}/usr/share', + XDG_DATA_DIRS: '${APPDIR}/share:${APPDIR}/usr/share:/share:/usr/share', APPDIR_LIBRARY_PATH: `\${APPDIR}/usr/lib/${triplet}:\${APPDIR}/usr/${triplet}/lib:\${APPDIR}/lib/${triplet}:\${APPDIR}/usr/lib:\${APPDIR}/usr/lib/${triplet}/gdk-pixbuf-2.0/2.10.0/loaders`, APPDIR_MODULE_DIR: '/tmp/.minecraft-pi-tmp' } : undefined, diff --git a/scripts/tools/get-apt-sources.sh b/scripts/tools/get-apt-sources.sh new file mode 100755 index 00000000..a26dec40 --- /dev/null +++ b/scripts/tools/get-apt-sources.sh @@ -0,0 +1,43 @@ +#!/bin/sh + +set -e + +if [ ! -z "${MCPI_CUSTOM_APT_REPO}" ]; then + echo "${MCPI_CUSTOM_APT_REPO}" + exit 0 +fi + +ID="$(sed -n -e 's/^ID=//p' /etc/os-release)" +ID_LIKE="$(sed -n -e 's/^ID_LIKE=//p' /etc/os-release)" +VERSION_CODENAME="$(sed -n -e 's/^VERSION_CODENAME=//p' /etc/os-release)" + +OUT="" +get_apt_sources() { + if [ "${1}" = "ubuntu" ]; then + OUT="deb [arch=i386,amd64] http://archive.ubuntu.com/ubuntu/ ${VERSION_CODENAME} main restricted +deb [arch=i386,amd64] http://archive.ubuntu.com/ubuntu/ ${VERSION_CODENAME}-updates main restricted +deb [arch=i386,amd64] http://archive.ubuntu.com/ubuntu/ ${VERSION_CODENAME} universe +deb [arch=i386,amd64] http://archive.ubuntu.com/ubuntu/ ${VERSION_CODENAME}-updates universe +deb [arch=armhf,arm64] http://ports.ubuntu.com/ubuntu-ports/ ${VERSION_CODENAME} main restricted +deb [arch=armhf,arm64] http://ports.ubuntu.com/ubuntu-ports/ ${VERSION_CODENAME}-updates main restricted +deb [arch=armhf,arm64] http://ports.ubuntu.com/ubuntu-ports/ ${VERSION_CODENAME} universe +deb [arch=armhf,arm64] http://ports.ubuntu.com/ubuntu-ports/ ${VERSION_CODENAME}-updates universe" + elif [ "${1}" = "debian" ]; then + OUT="deb https://deb.debian.org/debian/ ${VERSION_CODENAME} main" + if [ "${VERSION_CODENAME}" != "sid" ] && [ "${VERSION_CODENAME}" != "unstable" ] && [ "${VERSION_CODENAME}" != "experimental" ]; then + OUT="${OUT} +deb https://deb.debian.org/debian/ ${VERSION_CODENAME}-updates main" + fi + fi +} +get_apt_sources "${ID}" +if [ -z "${OUT}" ]; then + get_apt_sources "${ID_LIKE}" +fi + +if [ ! -z "${OUT}" ]; then + echo "${OUT}" +else + echo "Unsupported Distribution: ${ID}" 1>&2 + exit 1 +fi diff --git a/symbols/include/symbols/minecraft.h b/symbols/include/symbols/minecraft.h index 53f4c97f..169316b9 100644 --- a/symbols/include/symbols/minecraft.h +++ b/symbols/include/symbols/minecraft.h @@ -835,7 +835,7 @@ static uint32_t OptionsFile_options_txt_path_property_offset = 0x0; // std::stri // OptionsPane -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, uint32_t group_id, 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; // Textures