From db22caa50fb8234f80c4db4009dc496f90eda58c Mon Sep 17 00:00:00 2001 From: TheBrokenRail Date: Wed, 7 Feb 2024 21:15:48 -0500 Subject: [PATCH] Add Splash Text From MCPIL --- launcher/CMakeLists.txt | 15 +++- launcher/src/client/available-feature-flags | 1 + mods/CMakeLists.txt | 6 ++ mods/include/mods/touch/touch.h | 1 + mods/src/title-screen/splashes.txt | 53 ++++++++++++++ mods/src/title-screen/title-screen.cpp | 80 ++++++++++++++++++++- mods/src/touch/touch.cpp | 2 +- symbols/src/misc/Mth.def | 2 + 8 files changed, 155 insertions(+), 5 deletions(-) create mode 100644 mods/src/title-screen/splashes.txt diff --git a/launcher/CMakeLists.txt b/launcher/CMakeLists.txt index ba796d342..f0e92a9c3 100644 --- a/launcher/CMakeLists.txt +++ b/launcher/CMakeLists.txt @@ -1,12 +1,23 @@ project(launcher) # Launcher -add_executable(launcher src/bootstrap.c src/patchelf.cpp src/util.c src/crash-report.c src/sdk.c src/mods.c) +add_executable(launcher + src/bootstrap.c + src/patchelf.cpp + src/util.c + src/crash-report.c + src/sdk.c + src/mods.c +) if(MCPI_SERVER_MODE) target_sources(launcher PRIVATE src/server/launcher.c) else() embed_resource(launcher src/client/available-feature-flags) - target_sources(launcher PRIVATE src/client/launcher.cpp src/client/cache.cpp) + target_sources(launcher PRIVATE + src/client/launcher.cpp + src/client/cache.cpp + src/client/available-feature-flags # Show In IDE + ) endif() target_link_libraries(launcher reborn-util LIB_LIEF) # RPath diff --git a/launcher/src/client/available-feature-flags b/launcher/src/client/available-feature-flags index 2417c4624..bc1d7b52f 100644 --- a/launcher/src/client/available-feature-flags +++ b/launcher/src/client/available-feature-flags @@ -57,3 +57,4 @@ TRUE Add Cake TRUE Use Java Beta 1.3 Light Ramp TRUE Send Full Level When Hosting Game FALSE Food Overlay +TRUE Add Splashes diff --git a/mods/CMakeLists.txt b/mods/CMakeLists.txt index 78149dfb8..599fc34b1 100644 --- a/mods/CMakeLists.txt +++ b/mods/CMakeLists.txt @@ -90,6 +90,7 @@ else() src/atlas/atlas.cpp # title-screen src/title-screen/title-screen.cpp + src/title-screen/splashes.txt # Show In IDE # skin src/skin/skin.cpp src/skin/loader.cpp @@ -102,6 +103,11 @@ else() src/text-input-box/TextInputBox.cpp src/text-input-box/TextInputScreen.cpp ) + # Install Splashes + install( + FILES "src/title-screen/splashes.txt" + DESTINATION "${MCPI_INSTALL_DIR}/data" + ) endif() # Build diff --git a/mods/include/mods/touch/touch.h b/mods/include/mods/touch/touch.h index e375b4c0f..bba975600 100644 --- a/mods/include/mods/touch/touch.h +++ b/mods/include/mods/touch/touch.h @@ -2,4 +2,5 @@ #include +extern int touch_gui; Button *touch_create_button(int id, std::string text); diff --git a/mods/src/title-screen/splashes.txt b/mods/src/title-screen/splashes.txt new file mode 100644 index 000000000..5d69cc30a --- /dev/null +++ b/mods/src/title-screen/splashes.txt @@ -0,0 +1,53 @@ +(Not) Made by Notch! +@Banana! +As (not) seen on TV! +As seen on Discord! +Awesome community! +Awesome! +BANANA! +Boba was here! +Casual gaming! +Classic! +Create! +Definitely not Minecraft Console! +Didn't remove Herobrine! +Don't look directly at the bugs! +Enhanced! +Exploding Creepers! +FREE! +Fantasy! +I was promised pie! +It's the segment's fault! +Join the Discord! +Keyboard compatible! +Minecraft! +Not Minecraft Java! +Now With Multiplayer! +Now In 3D! +Now without Docker! +Obfuscated! +Oh yeah, that version... +Oh, OK, Pigmen... +Open-source! +Pixels! +Pretty! +RIP MCPIL-Legacy, 2020-2020 +RIP Picraft +Segmentation fault +Segmentation fault (core dumped) +Singleplayer! +Survive! +Teh! +unsigend char! +unsigned char! +Try It! +WDYM discontinued? +Watch out for StevePi! +Waterproof! +We fixed the rail! +Where is my pie? +Who broke the rail? +Who is StevePi? +Why must you hurt me? +Wow! Modded MCPI! +mcpi-revival.github.io! diff --git a/mods/src/title-screen/title-screen.cpp b/mods/src/title-screen/title-screen.cpp index f9f55d4eb..ebaea2aad 100644 --- a/mods/src/title-screen/title-screen.cpp +++ b/mods/src/title-screen/title-screen.cpp @@ -1,18 +1,23 @@ +#include +#include + #include #include +#include #include #include #include +#include // Improved Title Screen Background -static void StartMenuScreen_render_Screen_renderBackground_injection(StartMenuScreen *screen) { +static void StartMenuScreen_render_Screen_renderBackground_injection(Screen *screen) { // Draw Minecraft *minecraft = screen->minecraft; Textures *textures = minecraft->textures; std::string texture = "gui/titleBG.png"; Textures_loadAndBindTexture(textures, &texture); - StartMenuScreen_blit(screen, 0, 0, 0, 0, screen->width, screen->height, 0x100, 0x100); + Screen_blit(screen, 0, 0, 0, 0, screen->width, screen->height, 0x100, 0x100); } // Add Buttons Back To Classic Start Screen @@ -43,6 +48,69 @@ static void StartMenuScreen_buttonClicked_injection(StartMenuScreen *screen, But } } +// Add Splashes +static Screen *last_screen = nullptr; +static std::string current_splash; +static void StartMenuScreen_render_Screen_render_injection(Screen *screen, int x, int y, float param_1) { + // Call Original Method + Screen_render_non_virtual(screen, x, y, param_1); + + // Load Splashes + static std::vector splashes; + static bool splashes_loaded = false; + if (!splashes_loaded) { + // Mark As Loaded + splashes_loaded = true; + // Load + std::ifstream stream("data/splashes.txt"); + if (stream.good()) { + std::string line; + while (std::getline(stream, line)) { + if (line.length() > 0) { + splashes.push_back(line); + } + } + stream.close(); + } else { + WARN("Unable To Load Splashes"); + } + } + + // Display Splash + if (splashes.size() > 0) { + // Pick Splash + if (last_screen != screen) { + last_screen = screen; + current_splash = splashes[rand() % splashes.size()]; + } + // Choose Position + float multiplier = touch_gui ? 0.5f: 1.0f; + float splash_x = (float(screen->width) / 2.0f) + (94.0f * multiplier); + float splash_y = 4.0f + (36.0f * multiplier); + float max_width = 86; + // Draw (From https://github.com/ReMinecraftPE/mcpe/blob/d7a8b6baecf8b3b050538abdbc976f690312aa2d/source/client/gui/screens/StartMenuScreen.cpp#L699-L718) + glPushMatrix(); + // Position + glTranslatef(splash_x, splash_y, 0.0f); + glRotatef(-20.0f, 0.0f, 0.0f, 1.0f); + // Scale + int textWidth = Font_width(screen->font, ¤t_splash); + float timeMS = float(Common_getTimeMs() % 1000) / 1000.0f; + float scale = 2.0f - Mth_abs(0.1f * Mth_sin(2.0f * float(M_PI) * timeMS)); + float real_text_width = textWidth * scale; + if (real_text_width > max_width) { + scale *= max_width / real_text_width; + } + scale *= multiplier; + glScalef(scale, scale, scale); + // Render + static int line_height = 8; + Screen_drawCenteredString(screen, screen->font, ¤t_splash, 0, -(float(line_height) / 2), 0xffff00); + // Finish + glPopMatrix(); + } +} + // Init void init_title_screen() { // Improved Title Screen Background @@ -84,4 +152,12 @@ void init_title_screen() { // Add Functionality To Quit Button patch_address(StartMenuScreen_buttonClicked_vtable_addr, (void *) StartMenuScreen_buttonClicked_injection); } + + // Add Splashes + if (feature_has("Add Splashes", server_disabled)) { + overwrite_call((void *) 0x39764, (void *) StartMenuScreen_render_Screen_render_injection); + overwrite_call((void *) 0x3e0c4, (void *) StartMenuScreen_render_Screen_render_injection); + // Init Random + srand(time(NULL)); + } } diff --git a/mods/src/touch/touch.cpp b/mods/src/touch/touch.cpp index d88352e06..aa72f9367 100644 --- a/mods/src/touch/touch.cpp +++ b/mods/src/touch/touch.cpp @@ -42,7 +42,7 @@ static void LargeImageButton_render_GuiComponent_drawCenteredString_injection(Gu } // Create Button -static int touch_gui = 0; +int touch_gui = 0; Button *touch_create_button(int id, std::string text) { Button *button = nullptr; if (touch_gui) { diff --git a/symbols/src/misc/Mth.def b/symbols/src/misc/Mth.def index a3cc1297b..9dd5c7833 100644 --- a/symbols/src/misc/Mth.def +++ b/symbols/src/misc/Mth.def @@ -3,3 +3,5 @@ static-method float random() = 0x777a4; static-method float sin(float x) = 0x7775c; static-method float cos(float x) = 0x77728; +static-method float abs(float x) = 0x7781c; +static-method float min(float a, float b) = 0x7782c;