From 11230c120d644960675f828a3b9633f0f635d15e Mon Sep 17 00:00:00 2001 From: TheBrokenRail Date: Sat, 11 Nov 2023 00:44:26 -0500 Subject: [PATCH] Remove LibPNG + Clean Up --- .gitmodules | 14 +- CMakeLists.txt | 5 + dependencies/CMakeLists.txt | 14 +- .../gles-compatibility-layer/CMakeLists.txt | 4 +- .../gles-compatibility-layer/src | 0 .../glfw/CMakeLists.txt | 3 - .../dependencies => dependencies}/glfw/src | 0 dependencies/libpng/CMakeLists.txt | 33 --- dependencies/libpng/libpng.vers | 208 ------------------ dependencies/libpng/src | 1 - dependencies/libpng/zlib/CMakeLists.txt | 16 -- dependencies/libpng/zlib/src | 1 - dependencies/minecraft-pi/CMakeLists.txt | 8 + dependencies/stb_image/CMakeLists.txt | 28 +++ dependencies/stb_image/include | 1 + dependencies/stb_image/src/stb_image_impl.c | 5 + launcher/src/bootstrap.c | 2 +- launcher/src/client/launcher.cpp | 2 +- libreborn/CMakeLists.txt | 14 ++ libreborn/include/libreborn/exec.h | 2 +- libreborn/src/util/exec.c | 9 +- media-layer/CMakeLists.txt | 4 +- media-layer/core/CMakeLists.txt | 18 +- media-layer/core/dependencies/CMakeLists.txt | 6 - media-layer/core/gles/CMakeLists.txt | 11 - .../core/gles/dependencies/CMakeLists.txt | 6 - media-layer/include/GLES | 2 +- media-layer/proxy/CMakeLists.txt | 4 +- mods/CMakeLists.txt | 25 ++- mods/include/mods/init/init.h | 2 +- mods/src/chat/ui.c | 2 +- mods/src/game-mode/ui.cpp | 2 +- mods/src/init/init.c | 2 +- mods/src/misc/misc.cpp | 11 +- mods/src/screenshot/screenshot.c | 68 +----- mods/src/skin/loader.cpp | 50 +---- mods/src/textures/headless.cpp | 14 ++ mods/src/textures/textures.cpp | 37 ++++ symbols/include/symbols/minecraft.h | 16 ++ 39 files changed, 215 insertions(+), 435 deletions(-) rename {media-layer/core/gles/dependencies => dependencies}/gles-compatibility-layer/CMakeLists.txt (53%) rename {media-layer/core/gles/dependencies => dependencies}/gles-compatibility-layer/src (100%) rename {media-layer/core/dependencies => dependencies}/glfw/CMakeLists.txt (88%) rename {media-layer/core/dependencies => dependencies}/glfw/src (100%) delete mode 100644 dependencies/libpng/CMakeLists.txt delete mode 100644 dependencies/libpng/libpng.vers delete mode 160000 dependencies/libpng/src delete mode 100644 dependencies/libpng/zlib/CMakeLists.txt delete mode 160000 dependencies/libpng/zlib/src create mode 100644 dependencies/stb_image/CMakeLists.txt create mode 160000 dependencies/stb_image/include create mode 100644 dependencies/stb_image/src/stb_image_impl.c delete mode 100644 media-layer/core/dependencies/CMakeLists.txt delete mode 100644 media-layer/core/gles/dependencies/CMakeLists.txt create mode 100644 mods/src/textures/headless.cpp diff --git a/.gitmodules b/.gitmodules index f0a1e923..0e102ee4 100644 --- a/.gitmodules +++ b/.gitmodules @@ -1,12 +1,5 @@ -[submodule "dependencies/libpng/src"] - path = dependencies/libpng/src - url = https://gitea.thebrokenrail.com/minecraft-pi-reborn/libpng.git -[submodule "dependencies/zlib/src"] - path = dependencies/libpng/zlib/src - url = https://github.com/madler/zlib.git - ignore = dirty [submodule "dependencies/glfw/src"] - path = media-layer/core/dependencies/glfw/src + path = dependencies/glfw/src url = https://github.com/glfw/glfw.git [submodule "dependencies/zenity/src"] path = dependencies/zenity/src @@ -19,5 +12,8 @@ url = https://gitlab.com/qemu-project/qemu.git ignore = dirty [submodule "media-layer/core/gles/dependencies/gles-compatibility-layer"] - path = media-layer/core/gles/dependencies/gles-compatibility-layer/src + path = dependencies/gles-compatibility-layer/src url = https://gitea.thebrokenrail.com/minecraft-pi-reborn/gles-compatibility-layer.git +[submodule "dependencies/stb_image/include"] + path = dependencies/stb_image/include + url = https://github.com/nothings/stb.git diff --git a/CMakeLists.txt b/CMakeLists.txt index 1d79e268..b789e76c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -37,6 +37,11 @@ option(MCPI_USE_MEDIA_LAYER_PROXY "Whether To Enable The Media Layer Proxy" ${DE if(NOT MCPI_HEADLESS_MODE) option(MCPI_USE_GLES1_COMPATIBILITY_LAYER "Whether To Enable The GLESv1_CM Compatibility Layer" TRUE) endif() +if(MCPI_USE_MEDIA_LAYER_PROXY) + set(BUILD_MEDIA_LAYER_CORE "${BUILD_NATIVE_COMPONENTS}") +else() + set(BUILD_MEDIA_LAYER_CORE "${BUILD_ARM_COMPONENTS}") +endif() # App ID set(DEFAULT_APP_ID "com.thebrokenrail.MCPIReborn") diff --git a/dependencies/CMakeLists.txt b/dependencies/CMakeLists.txt index 69db2ce5..1e919a43 100644 --- a/dependencies/CMakeLists.txt +++ b/dependencies/CMakeLists.txt @@ -1,8 +1,8 @@ project(dependencies) -# LibPNG -if(BUILD_ARM_COMPONENTS) - add_subdirectory(libpng) +# stb_image +if(BUILD_ARM_COMPONENTS AND NOT MCPI_HEADLESS_MODE) + add_subdirectory(stb_image) endif() # Minecraft: Pi Edition if(BUILD_ARM_COMPONENTS AND NOT MCPI_OPEN_SOURCE_ONLY) @@ -20,3 +20,11 @@ endif() if(BUILD_NATIVE_COMPONENTS AND NOT (CMAKE_SYSTEM_PROCESSOR MATCHES "arm*" OR CMAKE_SYSTEM_PROCESSOR STREQUAL "aarch64")) add_subdirectory(qemu) endif() +# GLFW +if(BUILD_MEDIA_LAYER_CORE AND NOT MCPI_HEADLESS_MODE) + add_subdirectory(glfw) +endif() +# GLES Compatibility Layer +if(BUILD_NATIVE_COMPONENTS AND NOT MCPI_HEADLESS_MODE AND MCPI_USE_GLES1_COMPATIBILITY_LAYER) + add_subdirectory(gles-compatibility-layer) +endif() diff --git a/media-layer/core/gles/dependencies/gles-compatibility-layer/CMakeLists.txt b/dependencies/gles-compatibility-layer/CMakeLists.txt similarity index 53% rename from media-layer/core/gles/dependencies/gles-compatibility-layer/CMakeLists.txt rename to dependencies/gles-compatibility-layer/CMakeLists.txt index cc916635..73bb0668 100644 --- a/media-layer/core/gles/dependencies/gles-compatibility-layer/CMakeLists.txt +++ b/dependencies/gles-compatibility-layer/CMakeLists.txt @@ -1,9 +1,7 @@ -project(media-layer-core-gles-dependencies-gles-compatibility-layer) +project(gles-compatibility-layer) # GLES Compatibility Layer -set(GLES_COMPATIBILITY_LAYER_USE_DEFAULT_INCLUDE_PATH FALSE CACHE BOOL "" FORCE) set(GLES_COMPATIBILITY_LAYER_USE_ES3 FALSE CACHE BOOL "" FORCE) set(GLES_COMPATIBILITY_LAYER_USE_SDL FALSE CACHE BOOL "" FORCE) set(GLES_COMPATIBILITY_LAYER_DEPENDENCY glfw CACHE STRING "" FORCE) add_subdirectory(src) -target_link_libraries(gles-compatibility-layer media-layer-headers) diff --git a/media-layer/core/gles/dependencies/gles-compatibility-layer/src b/dependencies/gles-compatibility-layer/src similarity index 100% rename from media-layer/core/gles/dependencies/gles-compatibility-layer/src rename to dependencies/gles-compatibility-layer/src diff --git a/media-layer/core/dependencies/glfw/CMakeLists.txt b/dependencies/glfw/CMakeLists.txt similarity index 88% rename from media-layer/core/dependencies/glfw/CMakeLists.txt rename to dependencies/glfw/CMakeLists.txt index 3d9aa60f..23afb217 100644 --- a/media-layer/core/dependencies/glfw/CMakeLists.txt +++ b/dependencies/glfw/CMakeLists.txt @@ -23,9 +23,6 @@ add_custom_target(glfw-build ALL DEPENDS glfw) # Install install(TARGETS glfw DESTINATION "${MCPI_LIB_DIR}") -if(BUILD_ARM_COMPONENTS) - install(TARGETS glfw EXPORT sdk DESTINATION "${MCPI_SDK_LIB_DIR}") -endif() # License install(FILES src/LICENSE.md DESTINATION "${MCPI_LEGAL_DIR}/glfw") diff --git a/media-layer/core/dependencies/glfw/src b/dependencies/glfw/src similarity index 100% rename from media-layer/core/dependencies/glfw/src rename to dependencies/glfw/src diff --git a/dependencies/libpng/CMakeLists.txt b/dependencies/libpng/CMakeLists.txt deleted file mode 100644 index 9545e8c8..00000000 --- a/dependencies/libpng/CMakeLists.txt +++ /dev/null @@ -1,33 +0,0 @@ -project(libpng) - -# ZLib (Needed By libpng) -add_subdirectory(zlib) - -# Silence Warnings -add_compile_options(-w) - -## LibPNG - -# Options -set(PNG_TESTS FALSE CACHE BOOL "" FORCE) -set(PNG_NO_STDIO FALSE CACHE BOOL "" FORCE) -set(PNG_BUILD_ZLIB TRUE CACHE BOOL "" FORCE) - -# Download -set(ZLIB_LIBRARY zlibstatic) -set(ZLIB_INCLUDE_DIRS "${CMAKE_CURRENT_SOURCE_DIR}/zlib/src" "${CMAKE_CURRENT_BINARY_DIR}/zlib/src") -add_subdirectory(src EXCLUDE_FROM_ALL) - -# Use Symbol Versioning -set_target_properties(png12 PROPERTIES LINK_OPTIONS "LINKER:--version-script=${CMAKE_CURRENT_SOURCE_DIR}/libpng.vers") - -# Ensure Build -add_custom_target(png12-build ALL DEPENDS png12) -# Install -install(TARGETS png12 DESTINATION "${MCPI_LIB_DIR}") -if(BUILD_ARM_COMPONENTS) - install(TARGETS png12 zlibstatic EXPORT sdk DESTINATION "${MCPI_SDK_LIB_DIR}") -endif() - -# License -install(FILES src/LICENSE DESTINATION "${MCPI_LEGAL_DIR}/libpng") diff --git a/dependencies/libpng/libpng.vers b/dependencies/libpng/libpng.vers deleted file mode 100644 index 2511df87..00000000 --- a/dependencies/libpng/libpng.vers +++ /dev/null @@ -1,208 +0,0 @@ -PNG12_0 {global: -png_libpng_ver; -png_pass_start; -png_pass_inc; -png_pass_ystart; -png_pass_yinc; -png_pass_mask; -png_pass_dsp_mask; -png_access_version_number; -png_set_sig_bytes; -png_sig_cmp; -png_check_sig; -png_create_read_struct; -png_create_write_struct; -png_get_compression_buffer_size; -png_set_compression_buffer_size; -png_reset_zstream; -png_create_read_struct_2; -png_create_write_struct_2; -png_write_chunk; -png_write_chunk_start; -png_write_chunk_data; -png_write_chunk_end; -png_create_info_struct; -png_info_init; -png_info_init_3; -png_write_info_before_PLTE; -png_write_info; -png_read_info; -png_convert_to_rfc1123; -png_convert_from_struct_tm; -png_convert_from_time_t; -png_set_expand; -png_set_expand_gray_1_2_4_to_8; -png_set_palette_to_rgb; -png_set_tRNS_to_alpha; -png_set_gray_1_2_4_to_8; -png_set_bgr; -png_set_gray_to_rgb; -png_set_rgb_to_gray; -png_set_rgb_to_gray_fixed; -png_get_rgb_to_gray_status; -png_build_grayscale_palette; -png_set_strip_alpha; -png_set_swap_alpha; -png_set_invert_alpha; -png_set_filler; -png_set_add_alpha; -png_set_swap; -png_set_packing; -png_set_packswap; -png_set_shift; -png_set_interlace_handling; -png_set_invert_mono; -png_set_background; -png_set_strip_16; -png_set_dither; -png_set_gamma; -png_permit_empty_plte; -png_set_flush; -png_write_flush; -png_start_read_image; -png_read_update_info; -png_read_rows; -png_read_row; -png_read_image; -png_write_row; -png_write_rows; -png_write_image; -png_write_end; -png_read_end; -png_destroy_info_struct; -png_destroy_read_struct; -png_destroy_write_struct; -png_set_crc_action; -png_set_filter; -png_set_filter_heuristics; -png_set_compression_level; -png_set_compression_mem_level; -png_set_compression_strategy; -png_set_compression_window_bits; -png_set_compression_method; -png_init_io; -png_set_error_fn; -png_get_error_ptr; -png_set_write_fn; -png_set_read_fn; -png_get_io_ptr; -png_set_read_status_fn; -png_set_write_status_fn; -png_set_mem_fn; -png_get_mem_ptr; -png_set_read_user_transform_fn; -png_set_write_user_transform_fn; -png_set_user_transform_info; -png_get_user_transform_ptr; -png_set_read_user_chunk_fn; -png_get_user_chunk_ptr; -png_set_progressive_read_fn; -png_get_progressive_ptr; -png_process_data; -png_progressive_combine_row; -png_malloc; -png_malloc_warn; -png_free; -png_free_data; -png_data_freer; -png_malloc_default; -png_free_default; -png_memcpy_check; -png_memset_check; -png_error; -png_chunk_error; -png_warning; -png_chunk_warning; -png_get_valid; -png_get_rowbytes; -png_get_rows; -png_set_rows; -png_get_channels; -png_get_image_width; -png_get_image_height; -png_get_bit_depth; -png_get_color_type; -png_get_filter_type; -png_get_interlace_type; -png_get_compression_type; -png_get_pixels_per_meter; -png_get_x_pixels_per_meter; -png_get_y_pixels_per_meter; -png_get_pixel_aspect_ratio; -png_get_x_offset_pixels; -png_get_y_offset_pixels; -png_get_x_offset_microns; -png_get_y_offset_microns; -png_get_signature; -png_get_bKGD; -png_set_bKGD; -png_get_cHRM; -png_get_cHRM_fixed; -png_set_cHRM; -png_set_cHRM_fixed; -png_get_gAMA; -png_get_gAMA_fixed; -png_set_gAMA; -png_set_gAMA_fixed; -png_get_hIST; -png_set_hIST; -png_get_IHDR; -png_set_IHDR; -png_get_oFFs; -png_set_oFFs; -png_get_pCAL; -png_set_pCAL; -png_get_pHYs; -png_set_pHYs; -png_get_PLTE; -png_set_PLTE; -png_get_sBIT; -png_set_sBIT; -png_get_sRGB; -png_set_sRGB; -png_set_sRGB_gAMA_and_cHRM; -png_get_iCCP; -png_set_iCCP; -png_get_sPLT; -png_set_sPLT; -png_get_text; -png_set_text; -png_get_tIME; -png_set_tIME; -png_get_tRNS; -png_set_tRNS; -png_get_sCAL; -png_set_sCAL; -png_set_keep_unknown_chunks; -png_handle_as_unknown; -png_set_unknown_chunks; -png_set_unknown_chunk_location; -png_get_unknown_chunks; -png_set_invalid; -png_read_png; -png_write_png; -png_get_copyright; -png_get_header_ver; -png_get_header_version; -png_get_libpng_ver; -png_permit_mng_features; -png_get_mmx_flagmask; -png_get_asm_flagmask; -png_get_asm_flags; -png_get_mmx_bitdepth_threshold; -png_get_mmx_rowbytes_threshold; -png_set_asm_flags; -png_set_mmx_thresholds; -png_mmx_support; -png_set_strip_error_numbers; -png_set_user_limits; -png_get_user_width_max; -png_get_user_height_max; -png_get_uint_32; -png_get_uint_16; -png_get_int_32; -png_get_uint_31; -png_save_uint_32; -png_save_int_32; -png_save_uint_16; -local: *; }; diff --git a/dependencies/libpng/src b/dependencies/libpng/src deleted file mode 160000 index 6c445538..00000000 --- a/dependencies/libpng/src +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 6c445538879f9e916f8e62723d2ac7cd77d96191 diff --git a/dependencies/libpng/zlib/CMakeLists.txt b/dependencies/libpng/zlib/CMakeLists.txt deleted file mode 100644 index ff4e6e39..00000000 --- a/dependencies/libpng/zlib/CMakeLists.txt +++ /dev/null @@ -1,16 +0,0 @@ -project(zlib) - -# Silence Warnings -add_compile_options(-w) - -## zlib - -# Download -set(CMAKE_POLICY_DEFAULT_CMP0022 NEW) # Fix Error -add_subdirectory(src EXCLUDE_FROM_ALL) - -# Ensure Build -add_custom_target(zlib-build ALL DEPENDS zlibstatic) - -# License -install(FILES src/LICENSE DESTINATION "${MCPI_LEGAL_DIR}/zlib") diff --git a/dependencies/libpng/zlib/src b/dependencies/libpng/zlib/src deleted file mode 160000 index 09155eaa..00000000 --- a/dependencies/libpng/zlib/src +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 09155eaa2f9270dc4ed1fa13e2b4b2613e6e4851 diff --git a/dependencies/minecraft-pi/CMakeLists.txt b/dependencies/minecraft-pi/CMakeLists.txt index b7c4f724..76017fb4 100644 --- a/dependencies/minecraft-pi/CMakeLists.txt +++ b/dependencies/minecraft-pi/CMakeLists.txt @@ -17,5 +17,13 @@ install( DESTINATION "${MCPI_INSTALL_DIR}/game" USE_SOURCE_PERMISSIONS REGEX "api" EXCLUDE + REGEX "data" EXCLUDE ) +if(NOT MCPI_HEADLESS_MODE) + install( + DIRECTORY "${minecraft-pi_SOURCE_DIR}/data/" + DESTINATION "${MCPI_INSTALL_DIR}/game/data" + USE_SOURCE_PERMISSIONS + ) +endif() install_symlink("game/minecraft-pi" "${MCPI_INSTALL_DIR}/minecraft-pi") diff --git a/dependencies/stb_image/CMakeLists.txt b/dependencies/stb_image/CMakeLists.txt new file mode 100644 index 00000000..3dca232e --- /dev/null +++ b/dependencies/stb_image/CMakeLists.txt @@ -0,0 +1,28 @@ +project(stb_image) + +# Silence Warnings +add_compile_options(-w) + +## stb_image + +# Build +add_library(stb_image SHARED src/stb_image_impl.c) +target_include_directories( + stb_image + PUBLIC + "$" + "$" +) +target_link_libraries(stb_image PRIVATE m) +target_compile_definitions(stb_image PUBLIC STBI_ONLY_PNG) + +# Install +install(TARGETS stb_image DESTINATION "${MCPI_LIB_DIR}") +install( + DIRECTORY "include/" + DESTINATION "${MCPI_SDK_INCLUDE_DIR}/stb_image" +) +install(TARGETS stb_image EXPORT sdk DESTINATION "${MCPI_SDK_LIB_DIR}") + +# License +install(FILES include/LICENSE DESTINATION "${MCPI_LEGAL_DIR}/stb_image") diff --git a/dependencies/stb_image/include b/dependencies/stb_image/include new file mode 160000 index 00000000..beebb24b --- /dev/null +++ b/dependencies/stb_image/include @@ -0,0 +1 @@ +Subproject commit beebb24b945efdea3b9bba23affb8eb3ba8982e7 diff --git a/dependencies/stb_image/src/stb_image_impl.c b/dependencies/stb_image/src/stb_image_impl.c new file mode 100644 index 00000000..8162df0f --- /dev/null +++ b/dependencies/stb_image/src/stb_image_impl.c @@ -0,0 +1,5 @@ +#define STB_IMAGE_IMPLEMENTATION +#define STB_IMAGE_WRITE_IMPLEMENTATION + +#include "stb_image.h" +#include "stb_image_write.h" diff --git a/launcher/src/bootstrap.c b/launcher/src/bootstrap.c index 75598c9d..b62d7f8b 100644 --- a/launcher/src/bootstrap.c +++ b/launcher/src/bootstrap.c @@ -186,7 +186,7 @@ void pre_bootstrap(int argc, char *argv[]) { // Copy SDK Into ~/.minecraft-pi void run_simple_command(const char *const command[], const char *error) { int status = 0; - char *output = run_command(command, &status); + char *output = run_command(command, &status, NULL); if (output != NULL) { free(output); } diff --git a/launcher/src/client/launcher.cpp b/launcher/src/client/launcher.cpp index ec24a19f..2f303dd2 100644 --- a/launcher/src/client/launcher.cpp +++ b/launcher/src/client/launcher.cpp @@ -85,7 +85,7 @@ static void run_command_and_set_env(const char *env_name, const char *command[]) if (getenv(env_name) == NULL) { // Run int return_code; - char *output = run_command(command, &return_code); + char *output = run_command(command, &return_code, NULL); if (output != NULL) { // Trim int length = strlen(output); diff --git a/libreborn/CMakeLists.txt b/libreborn/CMakeLists.txt index 9462a00b..9fbe54cf 100644 --- a/libreborn/CMakeLists.txt +++ b/libreborn/CMakeLists.txt @@ -32,3 +32,17 @@ if(BUILD_ARM_COMPONENTS) # SDK install(TARGETS reborn-patch EXPORT sdk DESTINATION "${MCPI_SDK_LIB_DIR}") endif() + +# Fake LibPNG To Satisy Symbol Versioning Requirement +if(BUILD_ARM_COMPONENTS) + file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/fake-libpng.c" "") + file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/fake-libpng.vers" "PNG12_0 { global: *; };") + add_library(fake-libpng SHARED "${CMAKE_CURRENT_BINARY_DIR}/fake-libpng.c") + set_target_properties(fake-libpng PROPERTIES + OUTPUT_NAME "png12" + SOVERSION 0 + LINK_OPTIONS "LINKER:--version-script=${CMAKE_CURRENT_BINARY_DIR}/fake-libpng.vers" + ) + # Install + install(TARGETS fake-libpng DESTINATION "${MCPI_LIB_DIR}") +endif() diff --git a/libreborn/include/libreborn/exec.h b/libreborn/include/libreborn/exec.h index 3e54259c..31146038 100644 --- a/libreborn/include/libreborn/exec.h +++ b/libreborn/include/libreborn/exec.h @@ -36,7 +36,7 @@ char *get_binary_directory(); #define CHILD_PROCESS_TAG "(Child Process) " // Run Command And Get Output -char *run_command(const char *const command[], int *exit_status); +char *run_command(const char *const command[], int *exit_status, size_t *output_size); #define is_exit_status_success(status) (WIFEXITED(status) && WEXITSTATUS(status) == 0) // Get Exit Status String diff --git a/libreborn/src/util/exec.c b/libreborn/src/util/exec.c index 2fd1ef15..a07d3f8e 100644 --- a/libreborn/src/util/exec.c +++ b/libreborn/src/util/exec.c @@ -68,7 +68,7 @@ char *get_binary_directory() { } // Run Command And Get Output -char *run_command(const char *const command[], int *exit_status) { +char *run_command(const char *const command[], int *exit_status, size_t *output_size) { // Store Output int output_pipe[2]; safe_pipe2(output_pipe, 0); @@ -149,7 +149,12 @@ char *run_command(const char *const command[], int *exit_status) { output = new_output; } } - output[position] = '\0'; + output[position++] = '\0'; + + // Return Output Size + if (output_size != NULL) { + *output_size = position; + } // Get Return Code int status; diff --git a/media-layer/CMakeLists.txt b/media-layer/CMakeLists.txt index 8477eb77..cf2b2d6b 100644 --- a/media-layer/CMakeLists.txt +++ b/media-layer/CMakeLists.txt @@ -29,11 +29,11 @@ endif() add_subdirectory(extras) # Add Core -if((BUILD_NATIVE_COMPONENTS AND MCPI_USE_MEDIA_LAYER_PROXY) OR (BUILD_ARM_COMPONENTS AND NOT MCPI_USE_MEDIA_LAYER_PROXY)) +if(BUILD_MEDIA_LAYER_CORE) add_subdirectory(core) endif() # Add Proxy -if(MCPI_USE_MEDIA_LAYER_PROXY) +if(MCPI_USE_MEDIA_LAYER_PROXY OR BUILD_ARM_COMPONENTS) add_subdirectory(proxy) endif() diff --git a/media-layer/core/CMakeLists.txt b/media-layer/core/CMakeLists.txt index cd13c737..c53228f4 100644 --- a/media-layer/core/CMakeLists.txt +++ b/media-layer/core/CMakeLists.txt @@ -1,8 +1,5 @@ project(media-layer-core) -# Dependencies -add_subdirectory(dependencies) - # OpenGL add_subdirectory(gles) @@ -15,18 +12,19 @@ else() endif() # Build -add_library(media-layer-core SHARED ${CORE_SRC}) # Dependencies Are Setup Later -# Install -install(TARGETS media-layer-core DESTINATION "${MCPI_LIB_DIR}") -if(BUILD_ARM_COMPONENTS) - install(TARGETS media-layer-core EXPORT sdk DESTINATION "${MCPI_SDK_LIB_DIR}") +add_library(media-layer-core-real SHARED ${CORE_SRC}) # Dependencies Are Setup Later +set_target_properties(media-layer-core-real PROPERTIES OUTPUT_NAME "media-layer-core") +if(BUILD_NATIVE_COMPONENTS) + add_library(media-layer-core ALIAS media-layer-core-real) endif() +# Install +install(TARGETS media-layer-core-real DESTINATION "${MCPI_LIB_DIR}") # Link -target_link_libraries(media-layer-core PUBLIC media-layer-headers PUBLIC reborn-util PUBLIC GLESv1_CM PUBLIC dl) +target_link_libraries(media-layer-core-real PUBLIC media-layer-headers PUBLIC reborn-util PUBLIC GLESv1_CM PUBLIC dl) if(NOT MCPI_HEADLESS_MODE) # OpenAL find_library(OPENAL_LIBRARY NAMES openal REQUIRED) # Link - target_link_libraries(media-layer-core PRIVATE "${OPENAL_LIBRARY}" PRIVATE m PRIVATE glfw PRIVATE LIB_LIEF) + target_link_libraries(media-layer-core-real PRIVATE "${OPENAL_LIBRARY}" PRIVATE m PRIVATE glfw PRIVATE LIB_LIEF) endif() diff --git a/media-layer/core/dependencies/CMakeLists.txt b/media-layer/core/dependencies/CMakeLists.txt deleted file mode 100644 index e228c06c..00000000 --- a/media-layer/core/dependencies/CMakeLists.txt +++ /dev/null @@ -1,6 +0,0 @@ -project(media-layer-core-dependencies) - -# GLFW -if(NOT MCPI_HEADLESS_MODE) - add_subdirectory(glfw) -endif() diff --git a/media-layer/core/gles/CMakeLists.txt b/media-layer/core/gles/CMakeLists.txt index 87adf799..16ed2140 100644 --- a/media-layer/core/gles/CMakeLists.txt +++ b/media-layer/core/gles/CMakeLists.txt @@ -1,8 +1,5 @@ project(media-layer-gles) -# Dependencies -add_subdirectory(dependencies) - # Build if(MCPI_HEADLESS_MODE) # Stubs For Headless Mode @@ -17,11 +14,3 @@ else() add_library(GLESv1_CM OBJECT src/passthrough.c) target_link_libraries(GLESv1_CM PRIVATE glfw media-layer-headers) endif() - -# SDK -if(BUILD_ARM_COMPONENTS) - install(TARGETS GLESv1_CM EXPORT sdk DESTINATION "${MCPI_SDK_LIB_DIR}") - if(MCPI_USE_GLES1_COMPATIBILITY_LAYER) - install(TARGETS gles-compatibility-layer EXPORT sdk DESTINATION "${MCPI_SDK_LIB_DIR}") - endif() -endif() diff --git a/media-layer/core/gles/dependencies/CMakeLists.txt b/media-layer/core/gles/dependencies/CMakeLists.txt deleted file mode 100644 index 90cae9fb..00000000 --- a/media-layer/core/gles/dependencies/CMakeLists.txt +++ /dev/null @@ -1,6 +0,0 @@ -project(media-layer-core-gles-dependencies) - -# GLES Compatibility Layer -if(NOT MCPI_HEADLESS_MODE AND MCPI_USE_GLES1_COMPATIBILITY_LAYER) - add_subdirectory(gles-compatibility-layer) -endif() diff --git a/media-layer/include/GLES b/media-layer/include/GLES index acbe0420..7e8bbe4c 120000 --- a/media-layer/include/GLES +++ b/media-layer/include/GLES @@ -1 +1 @@ -../core/gles/dependencies/gles-compatibility-layer/src/include/GLES \ No newline at end of file +../../dependencies/gles-compatibility-layer/src/include/GLES \ No newline at end of file diff --git a/media-layer/proxy/CMakeLists.txt b/media-layer/proxy/CMakeLists.txt index 38342194..dfc742e4 100644 --- a/media-layer/proxy/CMakeLists.txt +++ b/media-layer/proxy/CMakeLists.txt @@ -17,6 +17,8 @@ elseif(BUILD_ARM_COMPONENTS) target_link_libraries(media-layer-core media-layer-headers reborn-util) target_compile_definitions(media-layer-core PRIVATE -DMEDIA_LAYER_PROXY_SERVER) # Install - install(TARGETS media-layer-core DESTINATION "${MCPI_LIB_DIR}") + if(MCPI_USE_MEDIA_LAYER_PROXY) + install(TARGETS media-layer-core DESTINATION "${MCPI_LIB_DIR}") + endif() install(TARGETS media-layer-core EXPORT sdk DESTINATION "${MCPI_SDK_LIB_DIR}") endif() diff --git a/mods/CMakeLists.txt b/mods/CMakeLists.txt index 783d4481..f8c6876b 100644 --- a/mods/CMakeLists.txt +++ b/mods/CMakeLists.txt @@ -71,9 +71,6 @@ else() add_library(touch SHARED src/touch/touch.cpp) target_link_libraries(touch mods-headers reborn-patch symbols feature) - add_library(textures SHARED src/textures/textures.cpp) - target_link_libraries(textures mods-headers reborn-patch symbols media-layer-core feature misc) - add_library(atlas SHARED src/atlas/atlas.cpp) target_link_libraries(atlas mods-headers reborn-patch symbols feature media-layer-core) @@ -81,12 +78,22 @@ else() target_link_libraries(title-screen mods-headers reborn-patch symbols feature compat) add_library(skin SHARED src/skin/skin.cpp src/skin/loader.cpp) - target_link_libraries(skin mods-headers reborn-patch symbols feature misc textures media-layer-core png12) + target_link_libraries(skin mods-headers reborn-patch symbols feature misc textures media-layer-core) add_library(benchmark SHARED src/benchmark/benchmark.cpp) target_link_libraries(benchmark mods-headers reborn-patch symbols compat misc media-layer-core) endif() +if(NOT MCPI_HEADLESS_MODE) + add_library(textures SHARED src/textures/textures.cpp) +else() + add_library(textures SHARED src/textures/headless.cpp) +endif() +target_link_libraries(textures mods-headers reborn-patch symbols) +if(NOT MCPI_HEADLESS_MODE) + target_link_libraries(textures media-layer-core feature misc stb_image) +endif() + add_library(override SHARED src/override/override.c) target_link_libraries(override mods-headers reborn-patch symbols dl home) @@ -104,7 +111,7 @@ target_link_libraries(bucket mods-headers reborn-patch symbols feature misc) if(NOT MCPI_HEADLESS_MODE) add_library(screenshot SHARED src/screenshot/screenshot.c) - target_link_libraries(screenshot mods-headers reborn-util media-layer-core png12) + target_link_libraries(screenshot mods-headers reborn-util media-layer-core stb_image) endif() add_library(home SHARED src/home/home.c) @@ -114,19 +121,19 @@ add_library(test SHARED src/test/test.c) target_link_libraries(test mods-headers reborn-patch home) add_library(init SHARED src/init/init.c) -target_link_libraries(init mods-headers reborn-util compat game-mode misc death options chat creative bucket home version test media-layer-core) +target_link_libraries(init mods-headers reborn-util compat game-mode misc death options chat creative bucket textures home version test media-layer-core) if(MCPI_SERVER_MODE) target_link_libraries(init server) else() - target_link_libraries(init multiplayer sound camera input sign touch textures atlas title-screen skin benchmark) + target_link_libraries(init multiplayer sound camera input sign touch atlas title-screen skin benchmark) endif() ## Install Mods -set(MODS_TO_INSTALL init compat readdir feature game-mode misc override death options chat creative bucket home version test) +set(MODS_TO_INSTALL init compat readdir feature game-mode misc override death options chat creative bucket textures home version test) if(MCPI_SERVER_MODE) list(APPEND MODS_TO_INSTALL server) else() - list(APPEND MODS_TO_INSTALL multiplayer sound camera input sign touch textures atlas title-screen skin benchmark) + list(APPEND MODS_TO_INSTALL multiplayer sound camera input sign touch atlas title-screen skin benchmark) endif() if(NOT MCPI_HEADLESS_MODE) list(APPEND MODS_TO_INSTALL screenshot) diff --git a/mods/include/mods/init/init.h b/mods/include/mods/init/init.h index 2d12f4c7..3ba0fb21 100644 --- a/mods/include/mods/init/init.h +++ b/mods/include/mods/init/init.h @@ -18,11 +18,11 @@ void init_input(); void init_sign(); void init_camera(); void init_touch(); -void init_textures(); void init_atlas(); void init_title_screen(); void init_skin(); #endif +void init_textures(); void init_creative(); void init_game_mode(); void init_misc(); diff --git a/mods/src/chat/ui.c b/mods/src/chat/ui.c index b0a6650f..de023115 100644 --- a/mods/src/chat/ui.c +++ b/mods/src/chat/ui.c @@ -34,7 +34,7 @@ static void *chat_thread(__attribute__((unused)) void *nop) { "--text", "Enter Chat Message:", NULL }; - char *output = run_command(command, &return_code); + char *output = run_command(command, &return_code, NULL); // Handle Message if (output != NULL) { // Check Return Code diff --git a/mods/src/game-mode/ui.cpp b/mods/src/game-mode/ui.cpp index ffba4cc6..9ca899fa 100644 --- a/mods/src/game-mode/ui.cpp +++ b/mods/src/game-mode/ui.cpp @@ -19,7 +19,7 @@ static char *run_command_proper(const char *command[], bool allow_empty) { // Run int return_code; - char *output = run_command(command, &return_code); + char *output = run_command(command, &return_code, NULL); // Handle Message if (output != NULL) { diff --git a/mods/src/init/init.c b/mods/src/init/init.c index cb70f234..a89bc1ce 100644 --- a/mods/src/init/init.c +++ b/mods/src/init/init.c @@ -18,11 +18,11 @@ __attribute__((constructor)) static void init() { init_sign(); init_camera(); init_touch(); - init_textures(); init_atlas(); init_title_screen(); init_skin(); #endif + init_textures(); init_creative(); init_game_mode(); init_misc(); diff --git a/mods/src/misc/misc.cpp b/mods/src/misc/misc.cpp index 2c484184..b32a5e7c 100644 --- a/mods/src/misc/misc.cpp +++ b/mods/src/misc/misc.cpp @@ -13,12 +13,21 @@ // Read Asset File static AppPlatform_readAssetFile_return_value AppPlatform_readAssetFile_injection(__attribute__((unused)) unsigned char *app_platform, std::string const& path) { - // Read File + // Open File std::ifstream stream("data/" + path, std::ios_base::binary | std::ios_base::ate); + if (!stream) { + // Does Not Exist + AppPlatform_readAssetFile_return_value ret; + ret.length = -1; + ret.data = NULL; + return ret; + } + // Read File long len = stream.tellg(); char *buf = new char[len]; stream.seekg(0, stream.beg); stream.read(buf, len); + stream.close(); // Return String AppPlatform_readAssetFile_return_value ret; ret.length = len; diff --git a/mods/src/screenshot/screenshot.c b/mods/src/screenshot/screenshot.c index af4a37bf..c967fbce 100644 --- a/mods/src/screenshot/screenshot.c +++ b/mods/src/screenshot/screenshot.c @@ -6,7 +6,8 @@ #include #include -#include +#include "stb_image.h" +#include "stb_image_write.h" #include #include @@ -31,68 +32,11 @@ static void ensure_screenshots_folder(char *screenshots) { // Take Screenshot static int save_png(const char *filename, unsigned char *pixels, int line_size, int width, int height) { - // Return value - int ret = 0; + // Setup + stbi_flip_vertically_on_write(1); - // Variables - png_structp png = NULL; - png_infop info = NULL; - FILE *file = NULL; - png_colorp palette = NULL; - png_bytep rows[height]; - for (int i = 0; i < height; ++i) { - rows[height - i - 1] = (png_bytep) (&pixels[i * line_size]); - } - - // Init - png = png_create_write_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL); - if (!png) { - ret = 1; - goto ret; - } - info = png_create_info_struct(png); - if (!info) { - ret = 1; - goto ret; - } - - // Open File - file = fopen(filename, "wb"); - if (!file) { - ret = 1; - goto ret; - } - - // Prepare To Write - png_init_io(png, file); - png_set_IHDR(png, info, width, height, 8 /* Depth */, PNG_COLOR_TYPE_RGB_ALPHA, PNG_INTERLACE_NONE, PNG_COMPRESSION_TYPE_BASE, PNG_FILTER_TYPE_BASE); - palette = (png_colorp) png_malloc(png, PNG_MAX_PALETTE_LENGTH * sizeof(png_color)); - if (!palette) { - ret = 1; - goto ret; - } - png_set_PLTE(png, info, palette, PNG_MAX_PALETTE_LENGTH); - png_write_info(png, info); - png_set_packing(png); - - // Write - png_write_image(png, rows); - png_write_end(png, info); - - ret: - // Free - if (palette != NULL) { - png_free(png, palette); - } - if (file != NULL) { - fclose(file); - } - if (png != NULL) { - png_destroy_write_struct(&png, &info); - } - - // Return - return ret; + // Write Image + return !stbi_write_png(filename, width, height, 4, pixels, line_size); } void screenshot_take(char *home) { // Get Directory diff --git a/mods/src/skin/loader.cpp b/mods/src/skin/loader.cpp index 21462ebe..6caefc7d 100644 --- a/mods/src/skin/loader.cpp +++ b/mods/src/skin/loader.cpp @@ -4,13 +4,14 @@ #include #include -#include #include #include #include #include "skin-internal.h" +#include "stb_image.h" + // Constants #define SKIN_WIDTH 64 #define SKIN_HEIGHT 32 @@ -19,68 +20,35 @@ struct pending_skin { int32_t texture_id; char *data; + int size; }; static std::vector &get_pending_skins() { static std::vector pending_skins; return pending_skins; } static pthread_mutex_t pending_skins_lock = PTHREAD_MUTEX_INITIALIZER; -static void read_from_png(png_structp pngPtr, png_bytep data, png_size_t length) { - char **src = (char **) png_get_io_ptr(pngPtr); - memcpy(data, *src, length); - *src += length; -} static void load_pending_skins(__attribute__((unused)) unsigned char *minecraft) { // Lock pthread_mutex_lock(&pending_skins_lock); // Loop for (pending_skin &skin : get_pending_skins()) { - // Init LibPNG - png_structp pngPtr = png_create_read_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL); - if (!pngPtr) { - continue; - } - png_infop infoPtr = png_create_info_struct(pngPtr); - if (!infoPtr) { - png_destroy_read_struct(&pngPtr, NULL, NULL); - continue; - } - // Read PNG Info - char *cursor = skin.data; - png_set_read_fn(pngPtr, (png_voidp) &cursor, read_from_png); - png_read_info(pngPtr, infoPtr); - int width = png_get_image_width(pngPtr, infoPtr); - int height = png_get_image_height(pngPtr, infoPtr); - if (png_get_color_type(pngPtr, infoPtr) != PNG_COLOR_TYPE_RGBA) { - continue; - } + int width = 0, height = 0, channels = 0; + stbi_uc *img = stbi_load_from_memory((unsigned char *) skin.data, skin.size, &width, &height, &channels, STBI_rgb_alpha); if (width != SKIN_WIDTH || height != SKIN_HEIGHT) { continue; } - int pixelSize = 4; - - // Read Image - png_bytep *rowPtrs = new png_bytep[height]; - unsigned char *data = new unsigned char[pixelSize * width * height]; - int rowStrideBytes = pixelSize * width; - for (int i = 0; i < height; i++) { - rowPtrs[i] = (png_bytep) &data[i * rowStrideBytes]; - } - png_read_image(pngPtr, rowPtrs); // Load Texture GLint last_texture; glGetIntegerv(GL_TEXTURE_BINDING_2D, &last_texture); glBindTexture(GL_TEXTURE_2D, skin.texture_id); - glTexSubImage2D_with_scaling(GL_TEXTURE_2D, 0, 0, 0, width, height, SKIN_WIDTH, SKIN_HEIGHT, GL_RGBA, GL_UNSIGNED_BYTE, data); + glTexSubImage2D_with_scaling(GL_TEXTURE_2D, 0, 0, 0, width, height, SKIN_WIDTH, SKIN_HEIGHT, GL_RGBA, GL_UNSIGNED_BYTE, img); glBindTexture(GL_TEXTURE_2D, last_texture); // Free - delete[] data; - png_destroy_read_struct(&pngPtr, &infoPtr, (png_infopp) 0); - delete[] rowPtrs; + stbi_image_free(img); } // Free @@ -118,7 +86,8 @@ static void *loader_thread(void *user_data) { std::string url = get_skin_server() + '/' + data->name + ".png"; int return_code; const char *command[] = {"wget", "-O", "-", url.c_str(), NULL}; - char *output = run_command(command, &return_code); + size_t output_size = 0; + char *output = run_command(command, &return_code, &output_size); // Check Success if (output != NULL && is_exit_status_success(return_code)) { @@ -129,6 +98,7 @@ static void *loader_thread(void *user_data) { pending_skin skin; skin.texture_id = data->texture_id; skin.data = output; + skin.size = (int) output_size; pthread_mutex_lock(&pending_skins_lock); get_pending_skins().push_back(skin); pthread_mutex_unlock(&pending_skins_lock); diff --git a/mods/src/textures/headless.cpp b/mods/src/textures/headless.cpp new file mode 100644 index 00000000..afaccc59 --- /dev/null +++ b/mods/src/textures/headless.cpp @@ -0,0 +1,14 @@ +#include +#include +#include + +// Disable Texture Loading +static Texture AppPlatform_linux_loadTexture_injection(__attribute__((unused)) unsigned char *app_platform, __attribute__((unused)) std::string const& path, __attribute__((unused)) bool b) { + return Texture(); +} + +// Init +void init_textures() { + // Disable Texture Loading + overwrite((void *) AppPlatform_linux_loadTexture, (void *) AppPlatform_linux_loadTexture_injection); +} diff --git a/mods/src/textures/textures.cpp b/mods/src/textures/textures.cpp index c87da6c9..2f5045a3 100644 --- a/mods/src/textures/textures.cpp +++ b/mods/src/textures/textures.cpp @@ -12,6 +12,8 @@ #include #include +#include "stb_image.h" + // Animated Water static void Minecraft_tick_injection(unsigned char *minecraft) { // Tick Dynamic Textures @@ -166,6 +168,38 @@ static void Textures_tick_glTexSubImage2D_injection(GLenum target, GLint level, glTexSubImage2D_with_scaling(target, level, xoffset, yoffset, width, height, 256, 256, format, type, pixels); } +// Load Textures +static Texture AppPlatform_linux_loadTexture_injection(__attribute__((unused)) unsigned char *app_platform, std::string const& path, bool b) { + Texture out; + std::string real_path = path; + if (b) { + real_path = "data/images/" + real_path; + } + + // Read Image + int width = 0, height = 0, channels = 0; + stbi_uc *img = stbi_load(real_path.c_str(), &width, &height, &channels, STBI_rgb_alpha); + if (!img) + { + // Failed To Parse Image + WARN("Unable To Load Texture: %s", real_path.c_str()); + return out; + } + + // Copy Image + unsigned char *img2 = new unsigned char[width * height * channels]; + memcpy(img2, img, width * height * channels); + stbi_image_free(img); + + // Create Texture + out.width = width; + out.height = height; + out.data = img2; + + // Return + return out; +} + // Init void init_textures() { // Tick Dynamic Textures (Animated Water) @@ -175,4 +209,7 @@ void init_textures() { // Scale Animated Textures overwrite_call((void *) 0x53274, (void *) Textures_tick_glTexSubImage2D_injection); + + // Load Textures + overwrite((void *) AppPlatform_linux_loadTexture, (void *) AppPlatform_linux_loadTexture_injection); } diff --git a/symbols/include/symbols/minecraft.h b/symbols/include/symbols/minecraft.h index 7e0bd01c..0ef788db 100644 --- a/symbols/include/symbols/minecraft.h +++ b/symbols/include/symbols/minecraft.h @@ -947,6 +947,22 @@ struct ConnectedClient { long time; }; +struct Texture { + int32_t width = 0; + int32_t height = 0; + unsigned char *data = NULL; + int32_t field3_0xc = 0; + bool field4_0x10 = true; + bool field5_0x11 = false; + int32_t field6_0x14 = 0; + int32_t field7_0x18 = -1; +}; + +// AppPlatform_linux + +typedef Texture (*AppPlatform_linux_loadTexture_t)(unsigned char *app_platform, std::string const& path, bool b); +static AppPlatform_linux_loadTexture_t AppPlatform_linux_loadTexture = (AppPlatform_linux_loadTexture_t) 0x12c20; + // Tile typedef unsigned char *(*Tile_setDescriptionId_t)(unsigned char *tile, std::string const& description_id);