From c5a46a83330ff5f675f2cf577f79559df3ca63f3 Mon Sep 17 00:00:00 2001
From: Lactozilla <jp6781615@gmail.com>
Date: Sat, 15 Feb 2025 20:26:46 -0300
Subject: [PATCH] Allow using the hub as the next map even if not unlocked

---
 src/g_game.c | 24 +++++++++++++++++++++---
 1 file changed, 21 insertions(+), 3 deletions(-)

diff --git a/src/g_game.c b/src/g_game.c
index b831c5dcd2..75f40c8ee2 100644
--- a/src/g_game.c
+++ b/src/g_game.c
@@ -3868,16 +3868,24 @@ boolean G_CompetitionGametype(void)
 	return ((gametyperules & GTR_RACE) && (gametyperules & GTR_LIVES));
 }
 
+static boolean G_IsHubMapValid(INT16 mapnum)
+{
+	if (!hubmapenabled || mapnum == 0)
+		return false;
+
+	return mapheaderinfo[mapnum-1] && mapheaderinfo[mapnum-1]->typeoflevel & TOL_HUB;
+}
+
 // Returns true if the current hub level can be warped to.
 boolean G_IsHubAvailable(void)
 {
 	if (marathonmode || modeattacking)
 		return false;
 
-	if (!hubmapenabled || currenthubmap == 0 || M_MapLocked(currenthubmap, serverGamedata))
+	if (M_MapLocked(currenthubmap, serverGamedata))
 		return false;
 
-	return mapheaderinfo[currenthubmap-1] && mapheaderinfo[currenthubmap-1]->typeoflevel & TOL_HUB;
+	return G_IsHubMapValid(currenthubmap);
 }
 
 /** Get the typeoflevel flag needed to indicate support of a gametype.
@@ -4061,6 +4069,16 @@ static void G_HandleSaveLevel(void)
 	}
 }
 
+// Returns true if the hub is a valid next map.
+static boolean G_IsHubValidNextMap(void)
+{
+	if (marathonmode || modeattacking)
+		return false;
+
+	// The hub is a valid next map even if it's not unlocked.
+	return G_IsHubMapValid(currenthubmap);
+}
+
 //
 // G_GetNextMap
 //
@@ -4082,7 +4100,7 @@ INT16 G_GetNextMap(boolean ignoretokens, boolean silent)
 
 		if (newmapnum == 1104-1) // Going back to the hub
 		{
-			if (G_IsHubAvailable()) // Should handle Marathon Mode.
+			if (G_IsHubValidNextMap()) // Should handle Marathon Mode.
 				newmapnum = currenthubmap-1;
 			else
 			{
-- 
GitLab