From 1df46f732b9cafb458404dc089906a420b2c1286 Mon Sep 17 00:00:00 2001 From: NepDisk Date: Sat, 5 Jul 2025 20:34:41 -0400 Subject: [PATCH] Grand Prix Rank Points Hook Yes this is my own MR lmao https://git.do.srb2.org/KartKrew/RingRacers/-/merge_requests/122 --- src/k_grandprix.c | 3 +++ src/lua_hook.h | 2 ++ src/lua_hooklib.c | 24 ++++++++++++++++++++++++ 3 files changed, 29 insertions(+) diff --git a/src/k_grandprix.c b/src/k_grandprix.c index a573383e6..74bfd4776 100644 --- a/src/k_grandprix.c +++ b/src/k_grandprix.c @@ -19,6 +19,7 @@ #include "k_kart.h" #include "m_random.h" #include "r_things.h" +#include "lua_hook.h" // LUA_HookGPRankPoints struct grandprixinfo grandprixinfo; @@ -67,6 +68,8 @@ INT16 K_CalculateGPRankPoints(UINT8 position, UINT8 numplayers) points = 0; } + LUA_HookGPRankPoints(position, numplayers, &points); + return points; } diff --git a/src/lua_hook.h b/src/lua_hook.h index ea0dedd0c..eb0db2a0f 100644 --- a/src/lua_hook.h +++ b/src/lua_hook.h @@ -82,6 +82,7 @@ automatically. X (PlayerCmd),/* building the player's ticcmd struct */\ X (MusicChange),\ X (VoteThinker),/* Y_VoteTicker */\ + X (GPRankPoints),/* K_CalculateGPRankPoints */\ X (AddonLoaded),\ #define STRING_HOOK_LIST(X) \ @@ -163,6 +164,7 @@ int LUA_HookNameChange(player_t *plr, const char *name); int LUA_HookTeamSwitch(player_t *, int newteam, boolean fromspectators, boolean tryingautobalance, boolean tryingscramble); int LUA_HookViewpointSwitch(player_t *player, player_t *newdisplayplayer, boolean forced); int LUA_HookSeenPlayer(player_t *player, player_t *seenfriend); +int LUA_HookGPRankPoints(UINT8 position, UINT8 numplayers, INT16 *points); int LUA_HookShouldJingleContinue(player_t *, const char *musname); int LUA_HookMusicChange(const char *oldname, struct MusicChange *); diff --git a/src/lua_hooklib.c b/src/lua_hooklib.c index d4ab6412a..7c7c06a82 100644 --- a/src/lua_hooklib.c +++ b/src/lua_hooklib.c @@ -1138,6 +1138,30 @@ int LUA_HookShouldJingleContinue(player_t *player, const char *musname) return hook.status; } +static void res_gprankpoints(Hook_State *hook) +{ + if (!lua_isnil(gL, -1)) + { + INT16 *points = (INT16*)hook->userdata; + *points = lua_tointeger(gL, -1); + hook->status = true; + } +} + +int LUA_HookGPRankPoints(UINT8 position, UINT8 numplayers, INT16 *points) +{ + Hook_State hook; + if (prepare_hook(&hook, 0, HOOK(GPRankPoints))) + { + hook.userdata = points; + lua_pushinteger(gL, position); + lua_pushinteger(gL, numplayers); + lua_pushinteger(gL, *points); + call_hooks(&hook, 1, res_gprankpoints); + } + return hook.status; +} + boolean hook_cmd_running = false; static void update_music_name(struct MusicChange *musicchange)