From 65190afe73b72bc76e591c0bafb9689dd368464d Mon Sep 17 00:00:00 2001 From: TheBrokenRail Date: Mon, 23 Sep 2024 21:22:43 -0400 Subject: [PATCH] Fix Rare Segfault --- docs/CHANGELOG.md | 1 + launcher/src/client/available-feature-flags | 3 ++- mods/src/misc/misc.cpp | 14 ++++++++++++++ symbols/src/level/Level.def | 1 + 4 files changed, 18 insertions(+), 1 deletion(-) diff --git a/docs/CHANGELOG.md b/docs/CHANGELOG.md index d2fa489f5a..073570429a 100644 --- a/docs/CHANGELOG.md +++ b/docs/CHANGELOG.md @@ -44,6 +44,7 @@ * `Improved Classic Title Positioning` (Enabled By Default) * `Use Updated Title` (Enabled By Default) * `Hide Block Outline When GUI Is Hidden` (Enabled By Default) + * `Fix Crash When Generating Certain Seed` (Enabled By Default) * Existing Functionality (All Enabled By Default) * `Fix Screen Rendering When Hiding HUD` * `Sanitize Usernames` diff --git a/launcher/src/client/available-feature-flags b/launcher/src/client/available-feature-flags index 8e5c0db08e..f100b2cf08 100644 --- a/launcher/src/client/available-feature-flags +++ b/launcher/src/client/available-feature-flags @@ -106,4 +106,5 @@ TRUE Property Scale Animated Textures TRUE Allow High-Resolution Title TRUE Improved Classic Title Positioning TRUE Use Updated Title -TRUE Hide Block Outline When GUI Is Hidden \ No newline at end of file +TRUE Hide Block Outline When GUI Is Hidden +TRUE Fix Crash When Generating Certain Seed \ No newline at end of file diff --git a/mods/src/misc/misc.cpp b/mods/src/misc/misc.cpp index fe7afdd97d..783b13e540 100644 --- a/mods/src/misc/misc.cpp +++ b/mods/src/misc/misc.cpp @@ -434,6 +434,15 @@ static void Player_tick_injection(Player_tick_t original, Player *self) { original(self); } +// Rare Segfault +static int Dimension_isValidSpawn_Level_getTopTile_injection(Level *self, int x, int z) { + int ret = self->getTopTile(x, z); + if (ret == 0) { + ret = Tile::invisible_bedrock->id; + } + return ret; +} + // Init void init_misc() { // Sanitize Username @@ -579,6 +588,11 @@ void init_misc() { overwrite_calls(Player_tick, Player_tick_injection); } + // Rare Segfault + if (feature_has("Fix Crash When Generating Certain Seed", server_enabled)) { + overwrite_call((void *) 0xb198c, (void *) Dimension_isValidSpawn_Level_getTopTile_injection); + } + // Init Other Components _init_misc_tinting(); _init_misc_ui(); diff --git a/symbols/src/level/Level.def b/symbols/src/level/Level.def index e80d72ab2c..c5cde735fe 100644 --- a/symbols/src/level/Level.def +++ b/symbols/src/level/Level.def @@ -49,6 +49,7 @@ method bool hasDirectSignal(int x, int y, int z) = 0xa5d88; method bool getDirectSignal(int x, int y, int z, int direction) = 0xa5d2c; method bool canSeeSky(int x, int y, int z) = 0xa39b8; method bool isDay() = 0xa3d9c; +method int getTopTile(int x, int z) = 0xa2cc8; virtual-method void tick() = 0x28; virtual-method void updateSleepingPlayerList() = 0x2c;