From 053bf4aa5fdffa6fb756a8ee1a6d58988bb13799 Mon Sep 17 00:00:00 2001 From: TheBrokenRail Date: Mon, 28 Jun 2021 16:00:52 -0400 Subject: [PATCH] Show Reborn Version In Start Screen --- CMakeLists.txt | 4 +++ docs/CHANGELOG.md | 1 + .../minecraft-pi-reborn-client.desktop | 2 +- launcher/src/client/launcher.cpp | 2 +- libreborn/include/libreborn/minecraft.h | 6 ++++ mods/CMakeLists.txt | 9 +++-- mods/src/chat/ui.c | 2 +- mods/src/compat/compat.c | 6 ++++ mods/src/home/home.c | 12 +++++-- mods/src/home/home.h | 2 +- mods/src/init/init.c | 1 + mods/src/init/init.h | 1 + mods/src/override/override.c | 2 -- mods/src/server/server.cpp | 3 +- mods/src/test/test.c | 1 - mods/src/version/README.md | 2 ++ mods/src/version/version.cpp | 34 +++++++++++++++++++ mods/src/version/version.h | 11 ++++++ 18 files changed, 88 insertions(+), 13 deletions(-) create mode 100644 mods/src/version/README.md create mode 100644 mods/src/version/version.cpp create mode 100644 mods/src/version/version.h diff --git a/CMakeLists.txt b/CMakeLists.txt index eb3d23766..00ccbfb86 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -94,6 +94,10 @@ if(MCPI_SERVER_MODE) add_definitions(-DMCPI_SERVER_MODE) endif() +# Version +file(STRINGS VERSION VERSION) +add_definitions(-DVERSION="${VERSION}") + # Build libreborn add_subdirectory(libreborn) diff --git a/docs/CHANGELOG.md b/docs/CHANGELOG.md index a13da1e73..2ff4c2e20 100644 --- a/docs/CHANGELOG.md +++ b/docs/CHANGELOG.md @@ -1,6 +1,7 @@ # Changelog **2.0.5** +* Show Reborn Version In Start Screen * External Server Support **2.0.4** diff --git a/launcher/client-data/usr/share/applications/minecraft-pi-reborn-client.desktop b/launcher/client-data/usr/share/applications/minecraft-pi-reborn-client.desktop index f96a57229..dfec412f7 100755 --- a/launcher/client-data/usr/share/applications/minecraft-pi-reborn-client.desktop +++ b/launcher/client-data/usr/share/applications/minecraft-pi-reborn-client.desktop @@ -3,7 +3,7 @@ Name=Minecraft: Pi Edition: Reborn Comment=Fun with Blocks Icon=/usr/share/pixmaps/minecraft-pi-reborn-client.png StartupNotify=false -StartupWMClass=Minecraft - Pi edition +StartupWMClass=Minecraft: Pi Edition: Reborn Exec=/usr/bin/minecraft-pi-reborn-client Terminal=false Type=Application diff --git a/launcher/src/client/launcher.cpp b/launcher/src/client/launcher.cpp index bb7a58bc1..6bf366dfc 100644 --- a/launcher/src/client/launcher.cpp +++ b/launcher/src/client/launcher.cpp @@ -106,7 +106,7 @@ static void run_zenity_and_set_env(const char *env_name, std::vector full_command; full_command.push_back("zenity"); full_command.push_back("--class"); - full_command.push_back("Minecraft - Pi edition"); + full_command.push_back("Minecraft: Pi Edition: Reborn"); full_command.insert(full_command.end(), command.begin(), command.end()); // Convert To C Array const char *full_command_array[full_command.size() + 1]; diff --git a/libreborn/include/libreborn/minecraft.h b/libreborn/include/libreborn/minecraft.h index 64e5da57e..38516a9a5 100644 --- a/libreborn/include/libreborn/minecraft.h +++ b/libreborn/include/libreborn/minecraft.h @@ -17,6 +17,7 @@ static renderCursor_t renderCursor = (renderCursor_t) 0x480c4; static char **default_path = (char **) 0xe264; // /.minecraft/ static char **default_username = (char **) 0x18fd4; // StevePi +static char **minecraft_pi_version = (char **) 0x39d94; // v0.1.1 alpha static unsigned char **Item_flintAndSteel = (unsigned char **) 0x17ba70; static unsigned char **Item_snowball = (unsigned char **) 0x17bbb0; @@ -477,6 +478,11 @@ static SelectWorldScreen_getUniqueLevelName_t SelectWorldScreen_getUniqueLevelNa static SelectWorldScreen_getUniqueLevelName_t Touch_SelectWorldScreen_getUniqueLevelName = (SelectWorldScreen_getUniqueLevelName_t) 0x3d82c; +// Common + +typedef std::string (*Common_getGameVersionString_t)(std::string const& version_suffix); +static Common_getGameVersionString_t Common_getGameVersionString = (Common_getGameVersionString_t) 0x15068; + #endif #pragma GCC diagnostic pop diff --git a/mods/CMakeLists.txt b/mods/CMakeLists.txt index 7020850cc..3455e8884 100644 --- a/mods/CMakeLists.txt +++ b/mods/CMakeLists.txt @@ -15,9 +15,12 @@ add_library(readdir SHARED src/readdir/readdir.c) add_library(feature SHARED src/feature/feature.c) target_link_libraries(feature reborn) +add_library(version SHARED src/version/version.cpp) +target_link_libraries(version reborn) + if(MCPI_SERVER_MODE) add_library(server SHARED src/server/server.cpp src/server/server_properties.cpp) - target_link_libraries(server reborn feature home compat dl media-layer-core pthread) + target_link_libraries(server reborn feature home compat version dl media-layer-core pthread) else() add_library(multiplayer SHARED src/multiplayer/multiplayer.cpp) target_link_libraries(multiplayer reborn home) @@ -60,7 +63,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 misc death options touch textures chat home test) +target_link_libraries(init compat game_mode camera input misc death options touch textures chat home version test) if(MCPI_SERVER_MODE) target_link_libraries(init server) else() @@ -68,7 +71,7 @@ else() endif() ## Install Mods -install(TARGETS init compat readdir feature override game_mode camera input misc death options touch textures chat home test DESTINATION "${MCPI_INSTALL_DIR}/mods") +install(TARGETS init compat readdir feature override game_mode camera input misc death options touch textures 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/chat/ui.c b/mods/src/chat/ui.c index 09c574525..8eeddaece 100644 --- a/mods/src/chat/ui.c +++ b/mods/src/chat/ui.c @@ -42,7 +42,7 @@ unsigned int chat_get_counter() { static void *chat_thread(__attribute__((unused)) void *nop) { // Open int return_code; - char *output = run_command("zenity --title \"Chat\" --class \"Minecraft - Pi edition\" --entry --text \"Enter Chat Message:\"", &return_code); + char *output = run_command("zenity --title 'Chat' --class 'Minecraft: Pi Edition: Reborn' --entry --text 'Enter Chat Message:'", &return_code); // Handle Message if (output != NULL) { // Check Return Code diff --git a/mods/src/compat/compat.c b/mods/src/compat/compat.c index 0cd9a2aec..d0f2430ee 100644 --- a/mods/src/compat/compat.c +++ b/mods/src/compat/compat.c @@ -12,6 +12,12 @@ #include "../init/init.h" #include "compat.h" +// Custom Title +HOOK(SDL_WM_SetCaption, void, (__attribute__((unused)) const char *title, const char *icon)) { + ensure_SDL_WM_SetCaption(); + (*real_SDL_WM_SetCaption)("Minecraft: Pi Edition: Reborn", icon); +} + // Mouse Cursor Is Always Invisible In Vanilla MCPI // Because In Vanilla MCPI, The GPU Overlay Covered The Normal Mouse Cursor HOOK(SDL_ShowCursor, int, (int toggle)) { diff --git a/mods/src/home/home.c b/mods/src/home/home.c index ef11fb121..950bf928f 100644 --- a/mods/src/home/home.c +++ b/mods/src/home/home.c @@ -31,10 +31,18 @@ HOOK(getenv, char *, (const char *name)) { // Get MCPI Home Directory char *home_get() { - char *dir = NULL; - safe_asprintf(&dir, "%s/" NEW_PATH, getenv("HOME")); + static char *dir = NULL; + // Load + if (dir == NULL) { + safe_asprintf(&dir, "%s/" NEW_PATH, getenv("HOME")); + } + // Return return dir; } +// Free +__attribute__((destructor)) static void _free_home() { + free(home_get()); +} // Init void init_home() { diff --git a/mods/src/home/home.h b/mods/src/home/home.h index 9f72d65e6..8a3462b4b 100644 --- a/mods/src/home/home.h +++ b/mods/src/home/home.h @@ -4,7 +4,7 @@ extern "C" { #endif -char *home_get(); // Remember To free() +char *home_get(); #ifdef __cplusplus } diff --git a/mods/src/init/init.c b/mods/src/init/init.c index a273f9e48..e5445865e 100644 --- a/mods/src/init/init.c +++ b/mods/src/init/init.c @@ -18,4 +18,5 @@ __attribute__((constructor)) static void init() { init_textures(); init_chat(); init_home(); + init_version(); } diff --git a/mods/src/init/init.h b/mods/src/init/init.h index b52efa599..59fee33f0 100644 --- a/mods/src/init/init.h +++ b/mods/src/init/init.h @@ -21,6 +21,7 @@ void init_touch(); void init_textures(); void init_chat(); void init_home(); +void init_version(); #ifdef __cplusplus } diff --git a/mods/src/override/override.c b/mods/src/override/override.c index c6fe43b30..c1301a7bf 100644 --- a/mods/src/override/override.c +++ b/mods/src/override/override.c @@ -20,8 +20,6 @@ static char *get_override_path(const char *filename) { // Get Asset Override Path char *overrides = NULL; safe_asprintf(&overrides, "%s/overrides", home_path); - // Free Home Path - free(home_path); // Get Data Path char *data = NULL; char *cwd = getcwd(NULL, 0); diff --git a/mods/src/server/server.cpp b/mods/src/server/server.cpp index f285461d4..26ccde47d 100644 --- a/mods/src/server/server.cpp +++ b/mods/src/server/server.cpp @@ -23,6 +23,7 @@ #include "../init/init.h" #include "../home/home.h" #include "../compat/compat.h" +#include "../version/version.h" #include @@ -65,7 +66,7 @@ static std::string get_world_name() { // Create/Start World static void start_world(unsigned char *minecraft) { - INFO("%s", "Starting Minecraft: Pi Edition Dedicated Server"); + INFO("Starting Minecraft: Pi Edition: Dedicated Server (%s)", version_get()); // Specify Level Settings LevelSettings settings; diff --git a/mods/src/test/test.c b/mods/src/test/test.c index ce4ed046f..58faea70d 100644 --- a/mods/src/test/test.c +++ b/mods/src/test/test.c @@ -13,7 +13,6 @@ void run_tests() { char *path = home_get(); int exists = access(path, F_OK) == 0; int can_write = exists ? access(path, R_OK | W_OK) == 0 : 1; - free(path); if (!can_write) { // Failure diff --git a/mods/src/version/README.md b/mods/src/version/README.md new file mode 100644 index 000000000..b53ccc777 --- /dev/null +++ b/mods/src/version/README.md @@ -0,0 +1,2 @@ +# ``version`` Mod +This mod adds the MCPI-Reborn version to the start screen. diff --git a/mods/src/version/version.cpp b/mods/src/version/version.cpp new file mode 100644 index 000000000..ac12b2776 --- /dev/null +++ b/mods/src/version/version.cpp @@ -0,0 +1,34 @@ +#include +#include + +#include "version.h" +#include "../init/init.h" + +// Get New Version +char *version_get() { + static char *version = NULL; + // Load + if (version == NULL) { + safe_asprintf(&version, "%s / Reborn v" VERSION, *minecraft_pi_version); + } + // Return + return version; +} +// Free +__attribute__((destructor)) static void _free_version() { + free(version_get()); +} + +// Injection For Touch GUI Version +static std::string Common_getGameVersionString_injection(__attribute__((unused)) std::string const& version_suffix) { + // Set Version + return version_get(); +} + +// Init +void init_version() { + // Touch GUI + overwrite((void *) Common_getGameVersionString, (void *) Common_getGameVersionString_injection); + // Normal GUI + patch_address((void *) minecraft_pi_version, version_get()); +} diff --git a/mods/src/version/version.h b/mods/src/version/version.h new file mode 100644 index 000000000..dd909f006 --- /dev/null +++ b/mods/src/version/version.h @@ -0,0 +1,11 @@ +#pragma once + +#ifdef __cplusplus +extern "C" { +#endif + +char *version_get(); + +#ifdef __cplusplus +} +#endif