mirror of
https://git.do.srb2.org/STJr/SRB2.git
synced 2024-11-15 17:22:12 +00:00
Merge branch 'playercmd-kart-port' into 'next'
PlayerCmd Port See merge request STJr/SRB2!1072
This commit is contained in:
commit
faaefd5061
8 changed files with 106 additions and 5 deletions
|
@ -1677,6 +1677,10 @@ void G_BuildTiccmd(ticcmd_t *cmd, INT32 realtics, UINT8 ssplayer)
|
|||
}
|
||||
}
|
||||
|
||||
// Note: Lat originally made the PlayerCmd hook for SRB2 Kart so credit goes to him.
|
||||
if (gamestate == GS_LEVEL)
|
||||
LUAh_PlayerCmd(player, cmd);
|
||||
|
||||
//Reset away view if a command is given.
|
||||
if (ssplayer == 1 && (cmd->forwardmove || cmd->sidemove || cmd->buttons)
|
||||
&& displayplayer != consoleplayer)
|
||||
|
|
|
@ -32,9 +32,12 @@
|
|||
#include "lua_script.h"
|
||||
#include "lua_libs.h"
|
||||
#include "lua_hud.h" // hud_running errors
|
||||
#include "lua_hook.h" // hook_cmd_running errors
|
||||
|
||||
#define NOHUD if (hud_running)\
|
||||
return luaL_error(L, "HUD rendering code should not call this function!");
|
||||
return luaL_error(L, "HUD rendering code should not call this function!");\
|
||||
else if (hook_cmd_running)\
|
||||
return luaL_error(L, "CMD building code should not call this function!");
|
||||
|
||||
boolean luaL_checkboolean(lua_State *L, int narg) {
|
||||
luaL_checktype(L, narg, LUA_TBOOLEAN);
|
||||
|
@ -2608,8 +2611,8 @@ static int lib_sStartSound(lua_State *L)
|
|||
}
|
||||
if (!player || P_IsLocalPlayer(player))
|
||||
{
|
||||
if (hud_running)
|
||||
origin = NULL; // HUD rendering startsound shouldn't have an origin, just remove it instead of having a retarded error.
|
||||
if (hud_running || hook_cmd_running)
|
||||
origin = NULL; // HUD rendering and CMD building startsound shouldn't have an origin, just remove it instead of having a retarded error.
|
||||
|
||||
S_StartSound(origin, sound_id);
|
||||
}
|
||||
|
|
|
@ -59,11 +59,14 @@ enum hook {
|
|||
hook_PlayerThink,
|
||||
hook_ShouldJingleContinue,
|
||||
hook_GameQuit,
|
||||
hook_PlayerCmd,
|
||||
|
||||
hook_MAX // last hook
|
||||
};
|
||||
extern const char *const hookNames[];
|
||||
|
||||
extern boolean hook_cmd_running;
|
||||
|
||||
void LUAh_MapChange(INT16 mapnumber); // Hook for map change (before load)
|
||||
void LUAh_MapLoad(void); // Hook for map load
|
||||
void LUAh_PlayerJoin(int playernum); // Hook for Got_AddPlayer
|
||||
|
@ -113,4 +116,5 @@ boolean LUAh_SeenPlayer(player_t *player, player_t *seenfriend); // Hook for MT_
|
|||
#endif
|
||||
#define LUAh_PlayerThink(player) LUAh_PlayerHook(player, hook_PlayerThink) // Hook for P_PlayerThink
|
||||
boolean LUAh_ShouldJingleContinue(player_t *player, const char *musname); // Hook for whether a jingle of the given music should continue playing
|
||||
void LUAh_GameQuit(void); // Hook for game quitting
|
||||
void LUAh_GameQuit(void); // Hook for game quitting
|
||||
boolean LUAh_PlayerCmd(player_t *player, ticcmd_t *cmd); // Hook for building player's ticcmd struct (Ported from SRB2Kart)
|
||||
|
|
|
@ -71,6 +71,7 @@ const char *const hookNames[hook_MAX+1] = {
|
|||
"PlayerThink",
|
||||
"ShouldJingleContinue",
|
||||
"GameQuit",
|
||||
"PlayerCmd",
|
||||
NULL
|
||||
};
|
||||
|
||||
|
@ -1793,6 +1794,49 @@ void LUAh_GameQuit(void)
|
|||
hookp->error = true;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
lua_pop(gL, 1); // Pop error handler
|
||||
}
|
||||
|
||||
// Hook for building player's ticcmd struct (Ported from SRB2Kart)
|
||||
boolean hook_cmd_running = false;
|
||||
boolean LUAh_PlayerCmd(player_t *player, ticcmd_t *cmd)
|
||||
{
|
||||
hook_p hookp;
|
||||
boolean hooked = false;
|
||||
if (!gL || !(hooksAvailable[hook_PlayerCmd/8] & (1<<(hook_PlayerCmd%8))))
|
||||
return false;
|
||||
|
||||
lua_settop(gL, 0);
|
||||
lua_pushcfunction(gL, LUA_GetErrorMessage);
|
||||
|
||||
hook_cmd_running = true;
|
||||
for (hookp = roothook; hookp; hookp = hookp->next)
|
||||
{
|
||||
if (hookp->type != hook_PlayerCmd)
|
||||
continue;
|
||||
|
||||
if (lua_gettop(gL) == 1)
|
||||
{
|
||||
LUA_PushUserdata(gL, player, META_PLAYER);
|
||||
LUA_PushUserdata(gL, cmd, META_TICCMD);
|
||||
}
|
||||
PushHook(gL, hookp);
|
||||
lua_pushvalue(gL, -3);
|
||||
lua_pushvalue(gL, -3);
|
||||
if (lua_pcall(gL, 2, 1, 1)) {
|
||||
if (!hookp->error || cv_debug & DBG_LUA)
|
||||
CONS_Alert(CONS_WARNING,"%s\n",lua_tostring(gL, -1));
|
||||
lua_pop(gL, 1);
|
||||
hookp->error = true;
|
||||
continue;
|
||||
}
|
||||
if (lua_toboolean(gL, -1))
|
||||
hooked = true;
|
||||
lua_pop(gL, 1);
|
||||
}
|
||||
|
||||
lua_settop(gL, 0);
|
||||
hook_cmd_running = false;
|
||||
return hooked;
|
||||
}
|
||||
|
|
|
@ -25,6 +25,7 @@
|
|||
#include "lua_script.h"
|
||||
#include "lua_libs.h"
|
||||
#include "lua_hud.h" // hud_running errors
|
||||
#include "lua_hook.h" // hook_cmd_running errors
|
||||
|
||||
extern CV_PossibleValue_t Color_cons_t[];
|
||||
extern UINT8 skincolor_modified[];
|
||||
|
@ -165,6 +166,8 @@ static int lib_setSpr2default(lua_State *L)
|
|||
|
||||
if (hud_running)
|
||||
return luaL_error(L, "Do not alter spr2defaults[] in HUD rendering code!");
|
||||
if (hook_cmd_running)
|
||||
return luaL_error(L, "Do not alter spr2defaults[] in CMD building code!");
|
||||
|
||||
// todo: maybe allow setting below first freeslot..? step 1 is toggling this, step 2 is testing to see whether it's net-safe
|
||||
#ifdef SETALLSPR2DEFAULTS
|
||||
|
@ -371,6 +374,8 @@ static int lib_setSpriteInfo(lua_State *L)
|
|||
return luaL_error(L, "Do not alter spriteinfo_t from within a hook or coroutine!");
|
||||
if (hud_running)
|
||||
return luaL_error(L, "Do not alter spriteinfo_t in HUD rendering code!");
|
||||
if (hook_cmd_running)
|
||||
return luaL_error(L, "Do not alter spriteinfo_t in CMD building code!");
|
||||
|
||||
lua_remove(L, 1);
|
||||
{
|
||||
|
@ -455,6 +460,8 @@ static int spriteinfo_set(lua_State *L)
|
|||
return luaL_error(L, "Do not alter spriteinfo_t from within a hook or coroutine!");
|
||||
if (hud_running)
|
||||
return luaL_error(L, "Do not alter spriteinfo_t in HUD rendering code!");
|
||||
if (hook_cmd_running)
|
||||
return luaL_error(L, "Do not alter spriteinfo_t in CMD building code!");
|
||||
|
||||
I_Assert(sprinfo != NULL);
|
||||
|
||||
|
@ -533,6 +540,8 @@ static int pivotlist_set(lua_State *L)
|
|||
return luaL_error(L, "Do not alter spriteframepivot_t from within a hook or coroutine!");
|
||||
if (hud_running)
|
||||
return luaL_error(L, "Do not alter spriteframepivot_t in HUD rendering code!");
|
||||
if (hook_cmd_running)
|
||||
return luaL_error(L, "Do not alter spriteframepivot_t in CMD building code!");
|
||||
|
||||
I_Assert(pivotlist != NULL);
|
||||
|
||||
|
@ -587,6 +596,8 @@ static int framepivot_set(lua_State *L)
|
|||
return luaL_error(L, "Do not alter spriteframepivot_t from within a hook or coroutine!");
|
||||
if (hud_running)
|
||||
return luaL_error(L, "Do not alter spriteframepivot_t in HUD rendering code!");
|
||||
if (hook_cmd_running)
|
||||
return luaL_error(L, "Do not alter spriteframepivot_t in CMD building code!");
|
||||
|
||||
I_Assert(framepivot != NULL);
|
||||
|
||||
|
@ -686,6 +697,8 @@ static int lib_setState(lua_State *L)
|
|||
|
||||
if (hud_running)
|
||||
return luaL_error(L, "Do not alter states in HUD rendering code!");
|
||||
if (hook_cmd_running)
|
||||
return luaL_error(L, "Do not alter states in CMD building code!");
|
||||
|
||||
// clear the state to start with, in case of missing table elements
|
||||
memset(state,0,sizeof(state_t));
|
||||
|
@ -906,6 +919,8 @@ static int state_set(lua_State *L)
|
|||
|
||||
if (hud_running)
|
||||
return luaL_error(L, "Do not alter states in HUD rendering code!");
|
||||
if (hook_cmd_running)
|
||||
return luaL_error(L, "Do not alter states in CMD building code!");
|
||||
|
||||
if (fastcmp(field,"sprite")) {
|
||||
value = luaL_checknumber(L, 3);
|
||||
|
@ -1006,6 +1021,8 @@ static int lib_setMobjInfo(lua_State *L)
|
|||
|
||||
if (hud_running)
|
||||
return luaL_error(L, "Do not alter mobjinfo in HUD rendering code!");
|
||||
if (hook_cmd_running)
|
||||
return luaL_error(L, "Do not alter mobjinfo in CMD building code!");
|
||||
|
||||
// clear the mobjinfo to start with, in case of missing table elements
|
||||
memset(info,0,sizeof(mobjinfo_t));
|
||||
|
@ -1173,6 +1190,8 @@ static int mobjinfo_set(lua_State *L)
|
|||
|
||||
if (hud_running)
|
||||
return luaL_error(L, "Do not alter mobjinfo in HUD rendering code!");
|
||||
if (hook_cmd_running)
|
||||
return luaL_error(L, "Do not alter mobjinfo in CMD building code!");
|
||||
|
||||
I_Assert(info != NULL);
|
||||
I_Assert(info >= mobjinfo);
|
||||
|
@ -1295,6 +1314,8 @@ static int lib_setSfxInfo(lua_State *L)
|
|||
|
||||
if (hud_running)
|
||||
return luaL_error(L, "Do not alter sfxinfo in HUD rendering code!");
|
||||
if (hook_cmd_running)
|
||||
return luaL_error(L, "Do not alter sfxinfo in CMD building code!");
|
||||
|
||||
lua_pushnil(L);
|
||||
while (lua_next(L, 1)) {
|
||||
|
@ -1376,6 +1397,8 @@ static int sfxinfo_set(lua_State *L)
|
|||
|
||||
if (hud_running)
|
||||
return luaL_error(L, "Do not alter S_sfx in HUD rendering code!");
|
||||
if (hook_cmd_running)
|
||||
return luaL_error(L, "Do not alter S_sfx in CMD building code!");
|
||||
|
||||
I_Assert(sfx != NULL);
|
||||
|
||||
|
@ -1443,6 +1466,8 @@ static int lib_setluabanks(lua_State *L)
|
|||
|
||||
if (hud_running)
|
||||
return luaL_error(L, "Do not alter luabanks[] in HUD rendering code!");
|
||||
if (hook_cmd_running)
|
||||
return luaL_error(L, "Do not alter luabanks[] in CMD building code!");
|
||||
|
||||
lua_remove(L, 1); // don't care about luabanks[] dummy userdata.
|
||||
|
||||
|
@ -1523,6 +1548,8 @@ static int lib_setSkinColor(lua_State *L)
|
|||
|
||||
if (hud_running)
|
||||
return luaL_error(L, "Do not alter skincolors in HUD rendering code!");
|
||||
if (hook_cmd_running)
|
||||
return luaL_error(L, "Do not alter skincolors in CMD building code!");
|
||||
|
||||
// clear the skincolor to start with, in case of missing table elements
|
||||
memset(info,0,sizeof(skincolor_t));
|
||||
|
@ -1711,6 +1738,8 @@ static int colorramp_set(lua_State *L)
|
|||
return luaL_error(L, LUA_QL("skincolor_t") " field 'ramp' index %d out of range (0 - %d)", n, COLORRAMPSIZE-1);
|
||||
if (hud_running)
|
||||
return luaL_error(L, "Do not alter skincolor_t in HUD rendering code!");
|
||||
if (hook_cmd_running)
|
||||
return luaL_error(L, "Do not alter skincolor_t in CMD building code!");
|
||||
colorramp[n] = i;
|
||||
skincolor_modified[cnum] = true;
|
||||
return 0;
|
||||
|
|
|
@ -21,6 +21,7 @@
|
|||
#include "lua_script.h"
|
||||
#include "lua_libs.h"
|
||||
#include "lua_hud.h" // hud_running errors
|
||||
#include "lua_hook.h" // hook_cmd_running errors
|
||||
|
||||
#include "dehacked.h"
|
||||
#include "fastcmp.h"
|
||||
|
@ -585,6 +586,8 @@ static int sector_set(lua_State *L)
|
|||
|
||||
if (hud_running)
|
||||
return luaL_error(L, "Do not alter sector_t in HUD rendering code!");
|
||||
if (hook_cmd_running)
|
||||
return luaL_error(L, "Do not alter sector_t in CMD building code!");
|
||||
|
||||
switch(field)
|
||||
{
|
||||
|
@ -1772,6 +1775,8 @@ static int ffloor_set(lua_State *L)
|
|||
|
||||
if (hud_running)
|
||||
return luaL_error(L, "Do not alter ffloor_t in HUD rendering code!");
|
||||
if (hook_cmd_running)
|
||||
return luaL_error(L, "Do not alter ffloor_t in CMD building code!");
|
||||
|
||||
switch(field)
|
||||
{
|
||||
|
@ -1896,6 +1901,8 @@ static int slope_set(lua_State *L)
|
|||
|
||||
if (hud_running)
|
||||
return luaL_error(L, "Do not alter pslope_t in HUD rendering code!");
|
||||
if (hook_cmd_running)
|
||||
return luaL_error(L, "Do not alter pslope_t in CMD building code!");
|
||||
|
||||
switch(field) // todo: reorganize this shit
|
||||
{
|
||||
|
|
|
@ -20,6 +20,7 @@
|
|||
#include "lua_script.h"
|
||||
#include "lua_libs.h"
|
||||
#include "lua_hud.h" // hud_running errors
|
||||
#include "lua_hook.h" // hook_cmd_running errors
|
||||
|
||||
static const char *const array_opt[] ={"iterate",NULL};
|
||||
|
||||
|
@ -437,6 +438,8 @@ static int mobj_set(lua_State *L)
|
|||
|
||||
if (hud_running)
|
||||
return luaL_error(L, "Do not alter mobj_t in HUD rendering code!");
|
||||
if (hook_cmd_running)
|
||||
return luaL_error(L, "Do not alter mobj_t in CMD building code!");
|
||||
|
||||
switch(field)
|
||||
{
|
||||
|
@ -878,6 +881,8 @@ static int mapthing_set(lua_State *L)
|
|||
|
||||
if (hud_running)
|
||||
return luaL_error(L, "Do not alter mapthing_t in HUD rendering code!");
|
||||
if (hook_cmd_running)
|
||||
return luaL_error(L, "Do not alter mapthing_t in CMD building code!");
|
||||
|
||||
if(fastcmp(field,"x"))
|
||||
mt->x = (INT16)luaL_checkinteger(L, 3);
|
||||
|
|
|
@ -20,6 +20,7 @@
|
|||
#include "lua_script.h"
|
||||
#include "lua_libs.h"
|
||||
#include "lua_hud.h" // hud_running errors
|
||||
#include "lua_hook.h" // hook_cmd_running errors
|
||||
|
||||
static int lib_iteratePlayers(lua_State *L)
|
||||
{
|
||||
|
@ -400,6 +401,8 @@ static int player_set(lua_State *L)
|
|||
|
||||
if (hud_running)
|
||||
return luaL_error(L, "Do not alter player_t in HUD rendering code!");
|
||||
if (hook_cmd_running)
|
||||
return luaL_error(L, "Do not alter player_t in CMD building code!");
|
||||
|
||||
if (fastcmp(field,"mo") || fastcmp(field,"realmo")) {
|
||||
mobj_t *newmo = *((mobj_t **)luaL_checkudata(L, 3, META_MOBJ));
|
||||
|
@ -770,6 +773,8 @@ static int power_set(lua_State *L)
|
|||
return luaL_error(L, LUA_QL("powertype_t") " cannot be %d", (INT16)p);
|
||||
if (hud_running)
|
||||
return luaL_error(L, "Do not alter player_t in HUD rendering code!");
|
||||
if (hook_cmd_running)
|
||||
return luaL_error(L, "Do not alter player_t in CMD building code!");
|
||||
powers[p] = i;
|
||||
return 0;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue