From 1025ac59bd411feeda293670d8a47ef2c56d22a7 Mon Sep 17 00:00:00 2001 From: GenericHeroGuy Date: Mon, 3 Mar 2025 18:58:28 +0100 Subject: [PATCH] Translate MapLoad/MapChange and implicit gamemap argument --- src/g_game.c | 2 +- src/lua_baselib.c | 4 ++-- src/lua_hook.h | 1 + src/lua_hooklib.c | 28 ++++++++++++++++++++++++++++ src/p_setup.c | 2 +- 5 files changed, 33 insertions(+), 4 deletions(-) diff --git a/src/g_game.c b/src/g_game.c index 10bc93010..d30d47f6c 100644 --- a/src/g_game.c +++ b/src/g_game.c @@ -5003,7 +5003,7 @@ void G_InitNew(UINT8 pencoremode, INT32 map, boolean resetplayer, boolean skippr F_StartCustomCutscene(mapheaderinfo[gamemap-1]->precutscenenum-1, true, resetplayer); else { - LUA_HookInt(gamemap, HOOK(MapChange)); + LUA_HookGamemap(HOOK(MapChange)); G_DoLoadLevel(resetplayer); } diff --git a/src/lua_baselib.c b/src/lua_baselib.c index 474fe9b32..8467652da 100644 --- a/src/lua_baselib.c +++ b/src/lua_baselib.c @@ -3164,7 +3164,7 @@ static int lib_gAddGametype(lua_State *L) static int Lcheckmapnumber (lua_State *L, int idx, const char *fun) { if (ISINLEVEL) - return luaL_optinteger(L, idx, gamemap); + return luaL_optinteger(L, idx, lua_compatmode ? G_NativeMapToKart(gamemap-1)+1 : gamemap); else { if (lua_isnoneornil(L, idx)) @@ -3370,7 +3370,7 @@ static int lib_gExitLevel(lua_State *L) static int lib_gIsSpecialStage(lua_State *L) { - INT32 mapnum = luaL_optinteger(L, 1, gamemap); + INT32 mapnum = Lcheckmapnumber(L, 1, "G_IsSpecialStage"); //HUDSAFE INLEVEL lua_pushboolean(L, G_IsSpecialStage(lua_compatmode ? G_KartMapToNative(mapnum-1)+1 : mapnum)); diff --git a/src/lua_hook.h b/src/lua_hook.h index 5f4984850..ea0dedd0c 100644 --- a/src/lua_hook.h +++ b/src/lua_hook.h @@ -132,6 +132,7 @@ void LUA_HookHUD(huddrawlist_h, int hook); int LUA_HookMobj(mobj_t *, int hook); int LUA_Hook2Mobj(mobj_t *, mobj_t *, int hook); void LUA_HookInt(INT32 integer, int hook); +void LUA_HookGamemap(int hook); void LUA_HookBool(boolean value, int hook); int LUA_HookPlayer(player_t *, int hook); int LUA_HookTiccmd(player_t *, ticcmd_t *, int hook); diff --git a/src/lua_hooklib.c b/src/lua_hooklib.c index d1b76fd99..a900f2331 100644 --- a/src/lua_hooklib.c +++ b/src/lua_hooklib.c @@ -501,6 +501,20 @@ static int call_mapped_hud(Hook_State *hook, const hook_t *map) return map->numHooks; } +static int call_mapped_gamemap(Hook_State *hook, const hook_t *map) +{ + int k; + + for (k = 0; k < map->numHooks; ++k) + { + get_hook(hook, map->ids, k); + lua_pushvalue(gL, hook->top - !lua_compatmode); + call_single_hook_no_copy(hook); + } + + return map->numHooks; +} + static int call_string_hooks(Hook_State *hook) { const stringhook_t *map = &stringHooks[hook->hook_type]; @@ -627,6 +641,20 @@ void LUA_HookInt(INT32 number, int hook_type) } } +void LUA_HookGamemap(int hook_type) +{ + Hook_State hook; + if (prepare_hook(&hook, 0, hook_type)) + { + lua_pushinteger(gL, gamemap); + lua_pushinteger(gL, G_NativeMapToKart(gamemap-1)+1); + init_hook_call(&hook, 0, res_none); + hook.values = 1; + call_mapped_gamemap(&hook, &hookIds[hook.hook_type]); + lua_settop(gL, 0); + } +} + void LUA_HookBool(boolean value, int hook_type) { Hook_State hook; diff --git a/src/p_setup.c b/src/p_setup.c index 403107bef..506d4365b 100644 --- a/src/p_setup.c +++ b/src/p_setup.c @@ -8879,7 +8879,7 @@ void P_PostLoadLevel(void) } ACS_RunLevelStartScripts(); - LUA_HookInt(gamemap, HOOK(MapLoad)); + LUA_HookGamemap(HOOK(MapLoad)); UINT8 i; for (i = 0; i < MAXPLAYERS; i++)