From b71c089fb3086708ab4ee677b475a77af3279d7e Mon Sep 17 00:00:00 2001 From: TheBrokenRail Date: Wed, 18 Dec 2024 02:44:51 -0500 Subject: [PATCH] Fix Hanging When No Valid Spawn Point Exists --- docs/CHANGELOG.md | 1 + .../util/env/flags/available-feature-flags | 1 + mods/src/misc/misc.cpp | 32 +++++++++++++++++++ symbols/src/level/Level.def | 2 ++ 4 files changed, 36 insertions(+) diff --git a/docs/CHANGELOG.md b/docs/CHANGELOG.md index aeb41d42fe..22f0a5afb0 100644 --- a/docs/CHANGELOG.md +++ b/docs/CHANGELOG.md @@ -57,6 +57,7 @@ * `Text Rendering Fixes` (Enabled By Default) * `Close Editor When Sign Is Destroyed` (Enabled By Default) * `Remove Chest Placement Restrictions` (Enabled By Default) + * `Fix Hanging When No Valid Spawn Point Exists` (Enabled By Default) * Existing Functionality (All Enabled By Default) * `Fix Screen Rendering When Hiding HUD` * `Sanitize Usernames` diff --git a/libreborn/src/util/env/flags/available-feature-flags b/libreborn/src/util/env/flags/available-feature-flags index 3e349c36a3..66e3a778c6 100644 --- a/libreborn/src/util/env/flags/available-feature-flags +++ b/libreborn/src/util/env/flags/available-feature-flags @@ -135,6 +135,7 @@ CATEGORY Bug Fixes TRUE Close Current Screen On Death TRUE Fix Reloading Textures On Resize TRUE Fix options.txt Loading/Saving + TRUE Fix Hanging When No Valid Spawn Point Exists CATEGORY Logging FALSE Log FPS TRUE Log Chat Messages diff --git a/mods/src/misc/misc.cpp b/mods/src/misc/misc.cpp index 10859883f4..f20a3706b6 100644 --- a/mods/src/misc/misc.cpp +++ b/mods/src/misc/misc.cpp @@ -468,6 +468,31 @@ static SignTileEntity *SignTileEntity_destructor_injection(SignTileEntity_destru return original(self); } +// Fix Spawn Point Hanging +static constexpr int allowed_spawn_point_tries = 10000; +static constexpr int not_finding_spawn_point = -1; +static int spawn_point_tries = not_finding_spawn_point; +static void Level_setInitialSpawn_or_validateSpawn_injection(Level_setInitialSpawn_t original, Level *self) { + spawn_point_tries = allowed_spawn_point_tries; + original(self); + spawn_point_tries = not_finding_spawn_point; +} +static int Level_getTopTile_injection(Level_getTopTile_t original, Level *self, int x, int z) { + bool actually_check = true; + if (spawn_point_tries == 0) { + // Give Up Searching + actually_check = false; + } else if (spawn_point_tries > 0) { + // Count Down + spawn_point_tries--; + } + if (actually_check) { + return original(self, x, z); + } else { + return Tile::bedrock->id; + } +} + // Init void init_misc() { // Sanitize Username @@ -636,6 +661,13 @@ void init_misc() { overwrite_calls(SignTileEntity_destructor_complete, SignTileEntity_destructor_injection); } + // Fix Hanging When Spawning + if (feature_has("Fix Hanging When No Valid Spawn Point Exists", server_enabled)) { + overwrite_calls(Level_setInitialSpawn, Level_setInitialSpawn_or_validateSpawn_injection); + overwrite_calls(Level_validateSpawn, Level_setInitialSpawn_or_validateSpawn_injection); + overwrite_calls(Level_getTopTile, Level_getTopTile_injection); + } + // Disable overwrite_calls() After Minecraft::init misc_run_on_init([](__attribute__((unused)) Minecraft *minecraft) { thunk_enabler = [](__attribute__((unused)) void *a, __attribute__((unused)) void *b) -> void * { diff --git a/symbols/src/level/Level.def b/symbols/src/level/Level.def index b7f8078306..9a314a7761 100644 --- a/symbols/src/level/Level.def +++ b/symbols/src/level/Level.def @@ -51,6 +51,8 @@ method bool canSeeSky(int x, int y, int z) = 0xa39b8; method bool isDay() = 0xa3d9c; method int getTopTile(int x, int z) = 0xa2cc8; method BiomeSource *getBiomeSource() = 0xa3c64; +method void setInitialSpawn() = 0xa2bf4; +method void validateSpawn() = 0xa2d2c; virtual-method void tick() = 0x28; virtual-method void updateSleepingPlayerList() = 0x2c;