From 34fa9771928961196c46d2e7dbaec46d28bdcfb2 Mon Sep 17 00:00:00 2001
From: Monster Iestyn <iestynjealous@ntlworld.com>
Date: Mon, 26 Apr 2021 19:07:11 +0100
Subject: [PATCH] move the old "can't load the level" error to its proper
 place, added specific error messages for all the times that unarchiving Lua
 banks can fail

---
 src/d_clisrv.c |  1 -
 src/p_saveg.c  | 18 ++++++++++++++----
 2 files changed, 14 insertions(+), 5 deletions(-)

diff --git a/src/d_clisrv.c b/src/d_clisrv.c
index 7c2dec6a1..89077ad6c 100644
--- a/src/d_clisrv.c
+++ b/src/d_clisrv.c
@@ -1567,7 +1567,6 @@ static void CL_LoadReceivedSavegame(boolean reloading)
 	}
 	else
 	{
-		CONS_Alert(CONS_ERROR, M_GetText("Can't load the level!\n"));
 		Z_Free(savebuffer);
 		save_p = NULL;
 		if (unlink(tmpsave) == -1)
diff --git a/src/p_saveg.c b/src/p_saveg.c
index 03229e740..818596cac 100644
--- a/src/p_saveg.c
+++ b/src/p_saveg.c
@@ -4190,7 +4190,10 @@ static inline boolean P_NetUnArchiveMisc(boolean reloading)
 	tokenlist = READUINT32(save_p);
 
 	if (!P_LoadLevel(true, reloading))
+	{
+		CONS_Alert(CONS_ERROR, M_GetText("Can't load the level!\n"));
 		return false;
+	}
 
 	// get the time
 	leveltime = READUINT32(save_p);
@@ -4268,19 +4271,26 @@ static inline boolean P_UnArchiveLuabanksAndConsistency(void)
 {
 	switch (READUINT8(save_p))
 	{
-		case 0xb7:
+		case 0xb7: // luabanks marker
 			{
 				UINT8 i, banksinuse = READUINT8(save_p);
 				if (banksinuse > NUM_LUABANKS)
+				{
+					CONS_Alert(CONS_ERROR, M_GetText("Corrupt Luabanks! (Too many banks in use)\n"));
 					return false;
+				}
 				for (i = 0; i < banksinuse; i++)
 					luabanks[i] = READINT32(save_p);
-				if (READUINT8(save_p) != 0x1d)
+				if (READUINT8(save_p) != 0x1d) // consistency marker
+				{
+					CONS_Alert(CONS_ERROR, M_GetText("Corrupt Luabanks! (Failed consistency check)\n"));
 					return false;
+				}
 			}
-		case 0x1d:
+		case 0x1d: // consistency marker
 			break;
-		default:
+		default: // anything else is nonsense
+			CONS_Alert(CONS_ERROR, M_GetText("Failed consistency check (???)\n"));
 			return false;
 	}
 
-- 
GitLab