From 14199102b7d1ba1d58e8b905c6a55442d576d00a Mon Sep 17 00:00:00 2001
From: LJ Sonic <lamr@free.fr>
Date: Tue, 3 Dec 2024 19:57:29 +0100
Subject: [PATCH] Fix AddonLoaded hook

---
 src/p_setup.c |  6 ++----
 src/w_wad.c   | 10 ++++++++++
 2 files changed, 12 insertions(+), 4 deletions(-)

diff --git a/src/p_setup.c b/src/p_setup.c
index 4356e05744..cf549680f6 100644
--- a/src/p_setup.c
+++ b/src/p_setup.c
@@ -530,7 +530,7 @@ UINT32 P_GetScoreForGradeOverall(INT16 map, UINT8 grade)
 void P_AddNiGHTSTimes(INT16 i, char *gtext)
 {
 	char *spos = gtext;
-	
+
 	for (UINT8 n = 0; n < 8; n++)
 	{
 		if (spos != NULL)
@@ -3075,7 +3075,7 @@ static void P_LoadTextmap(void)
 			// TODO: remove this limitation in a backwards-compatible way (UDMF versioning?)
 			UINT8 lightalpha = (textmap_colormap.lightalpha * 102) / 10;
 			UINT8 fadealpha = (textmap_colormap.fadealpha * 102) / 10;
-			
+
 			INT32 rgba = P_ColorToRGBA(textmap_colormap.lightcolor, lightalpha);
 			INT32 fadergba = P_ColorToRGBA(textmap_colormap.fadecolor, fadealpha);
 			sc->extra_colormap = sc->spawn_extra_colormap = R_CreateColormap(rgba, fadergba, textmap_colormap.fadestart, textmap_colormap.fadeend, textmap_colormap.flags);
@@ -8464,8 +8464,6 @@ static boolean P_LoadAddon(UINT16 numlumps)
 			SendNetXCmd(XD_EXITLEVEL, NULL, 0);
 	}
 
-	LUA_HookVoid(HOOK(AddonLoaded));
-
 	return true;
 }
 
diff --git a/src/w_wad.c b/src/w_wad.c
index 6964f24aa2..57dd09de61 100644
--- a/src/w_wad.c
+++ b/src/w_wad.c
@@ -65,6 +65,7 @@
 #include "i_video.h" // rendermode
 #include "md5.h"
 #include "lua_script.h"
+#include "lua_hook.h"
 #ifdef SCANTHINGS
 #include "p_setup.h" // P_ScanThings
 #endif
@@ -1009,6 +1010,10 @@ UINT16 W_InitFile(const char *filename, boolean mainfile, boolean startup)
 		break;
 	}
 
+	lua_lumploading++;
+	LUA_HookVoid(HOOK(AddonLoaded));
+	lua_lumploading--;
+
 	W_InvalidateLumpnumCache();
 	return wadfile->numlumps;
 }
@@ -1169,6 +1174,11 @@ UINT16 W_InitFolder(const char *path, boolean mainfile, boolean startup)
 	W_ReadFileShaders(wadfile);
 	W_LoadTrnslateLumps(numwadfiles - 1);
 	W_LoadDehackedLumpsPK3(numwadfiles - 1, mainfile);
+
+	lua_lumploading++;
+	LUA_HookVoid(HOOK(AddonLoaded));
+	lua_lumploading--;
+
 	W_InvalidateLumpnumCache();
 
 	return wadfile->numlumps;
-- 
GitLab