add HOOK_ON_CHAT_MESSAGE (#220)

includes the message string and the mario state of the player
return false to prevent the message from showing (might be possible to make a chat flter with this?)
This commit is contained in:
Isaac0-dev 2022-10-31 10:34:50 +10:00 committed by GitHub
parent 1e2a230d51
commit d806c2d8c2
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
9 changed files with 54 additions and 6 deletions

View file

@ -8128,7 +8128,10 @@ HOOK_ON_SCREEN_TRANSITION = 25
HOOK_ALLOW_HAZARD_SURFACE = 26 HOOK_ALLOW_HAZARD_SURFACE = 26
--- @type LuaHookedEventType --- @type LuaHookedEventType
HOOK_MAX = 27 HOOK_ON_CHAT_MESSAGE = 27
--- @type LuaHookedEventType
HOOK_MAX = 28
--- @class HudDisplayFlags --- @class HudDisplayFlags

View file

@ -629,7 +629,7 @@
--- @field public exitCastleArea integer --- @field public exitCastleArea integer
--- @field public exitCastleLevel LevelNum --- @field public exitCastleLevel LevelNum
--- @field public exitCastleWarpNode integer --- @field public exitCastleWarpNode integer
--- @field public fixCollisionBugs integer --- @field public fixCollisionBugs boolean
--- @field public floorLowerLimit integer --- @field public floorLowerLimit integer
--- @field public floorLowerLimitMisc integer --- @field public floorLowerLimitMisc integer
--- @field public floorLowerLimitShadow integer --- @field public floorLowerLimitShadow integer

View file

@ -2878,7 +2878,8 @@
| HOOK_ON_CHANGE_CAMERA_ANGLE | 24 | | HOOK_ON_CHANGE_CAMERA_ANGLE | 24 |
| HOOK_ON_SCREEN_TRANSITION | 25 | | HOOK_ON_SCREEN_TRANSITION | 25 |
| HOOK_ALLOW_HAZARD_SURFACE | 26 | | HOOK_ALLOW_HAZARD_SURFACE | 26 |
| HOOK_MAX | 27 | | HOOK_ON_CHAT_MESSAGE | 27 |
| HOOK_MAX | 28 |
[:arrow_up_small:](#) [:arrow_up_small:](#)

View file

@ -924,7 +924,7 @@
| exitCastleArea | `integer` | | | exitCastleArea | `integer` | |
| exitCastleLevel | [enum LevelNum](constants.md#enum-LevelNum) | | | exitCastleLevel | [enum LevelNum](constants.md#enum-LevelNum) | |
| exitCastleWarpNode | `integer` | | | exitCastleWarpNode | `integer` | |
| fixCollisionBugs | `integer` | | | fixCollisionBugs | `boolean` | |
| floorLowerLimit | `integer` | | | floorLowerLimit | `integer` | |
| floorLowerLimitMisc | `integer` | | | floorLowerLimitMisc | `integer` | |
| floorLowerLimitShadow | `integer` | | | floorLowerLimitShadow | `integer` | |

View file

@ -6,6 +6,7 @@
#include "game/mario_misc.h" #include "game/mario_misc.h"
#include "djui.h" #include "djui.h"
#include "pc/debuglog.h" #include "pc/debuglog.h"
#include "pc/lua/smlua_hooks.h"
#define DJUI_CHAT_LIFE_TIME 10.0f #define DJUI_CHAT_LIFE_TIME 10.0f
@ -51,6 +52,12 @@ void djui_chat_message_create_from(u8 globalIndex, const char* message) {
return; return;
} }
bool returnValue = true;
smlua_call_event_hooks_on_chat_message(HOOK_ON_CHAT_MESSAGE, &gMarioStates[np->localIndex], message, &returnValue);
if (!returnValue) {
return;
}
char* playerColorString = network_get_player_text_color_string(np->localIndex); char* playerColorString = network_get_player_text_color_string(np->localIndex);
char chatMsg[256] = { 0 }; char chatMsg[256] = { 0 };
snprintf(chatMsg, 256, "%s%s:\\#dcdcdc\\ %s", playerColorString, (np != NULL) ? np->name : "Player", message); snprintf(chatMsg, 256, "%s%s:\\#dcdcdc\\ %s", playerColorString, (np != NULL) ? np->name : "Player", message);

View file

@ -734,7 +734,7 @@ static struct LuaObjectField sLevelValuesFields[LUA_LEVEL_VALUES_FIELD_COUNT] =
{ "exitCastleArea", LVT_S16, offsetof(struct LevelValues, exitCastleArea), false, LOT_NONE }, { "exitCastleArea", LVT_S16, offsetof(struct LevelValues, exitCastleArea), false, LOT_NONE },
{ "exitCastleLevel", LVT_S32, offsetof(struct LevelValues, exitCastleLevel), false, LOT_NONE }, { "exitCastleLevel", LVT_S32, offsetof(struct LevelValues, exitCastleLevel), false, LOT_NONE },
{ "exitCastleWarpNode", LVT_U8, offsetof(struct LevelValues, exitCastleWarpNode), false, LOT_NONE }, { "exitCastleWarpNode", LVT_U8, offsetof(struct LevelValues, exitCastleWarpNode), false, LOT_NONE },
{ "fixCollisionBugs", LVT_U8, offsetof(struct LevelValues, fixCollisionBugs), false, LOT_NONE }, { "fixCollisionBugs", LVT_BOOL, offsetof(struct LevelValues, fixCollisionBugs), false, LOT_NONE },
{ "floorLowerLimit", LVT_S16, offsetof(struct LevelValues, floorLowerLimit), false, LOT_NONE }, { "floorLowerLimit", LVT_S16, offsetof(struct LevelValues, floorLowerLimit), false, LOT_NONE },
{ "floorLowerLimitMisc", LVT_S16, offsetof(struct LevelValues, floorLowerLimitMisc), false, LOT_NONE }, { "floorLowerLimitMisc", LVT_S16, offsetof(struct LevelValues, floorLowerLimitMisc), false, LOT_NONE },
{ "floorLowerLimitShadow", LVT_S16, offsetof(struct LevelValues, floorLowerLimitShadow), false, LOT_NONE }, { "floorLowerLimitShadow", LVT_S16, offsetof(struct LevelValues, floorLowerLimitShadow), false, LOT_NONE },

View file

@ -2885,7 +2885,8 @@ char gSmluaConstants[] = ""
"HOOK_ON_CHANGE_CAMERA_ANGLE = 24\n" "HOOK_ON_CHANGE_CAMERA_ANGLE = 24\n"
"HOOK_ON_SCREEN_TRANSITION = 25\n" "HOOK_ON_SCREEN_TRANSITION = 25\n"
"HOOK_ALLOW_HAZARD_SURFACE = 26\n" "HOOK_ALLOW_HAZARD_SURFACE = 26\n"
"HOOK_MAX = 27\n" "HOOK_ON_CHAT_MESSAGE = 27\n"
"HOOK_MAX = 28\n"
"ACTION_HOOK_EVERY_FRAME = 0\n" "ACTION_HOOK_EVERY_FRAME = 0\n"
"ACTION_HOOK_GRAVITY = 1\n" "ACTION_HOOK_GRAVITY = 1\n"
"ACTION_HOOK_MAX = 2\n" "ACTION_HOOK_MAX = 2\n"

View file

@ -581,6 +581,39 @@ void smlua_call_event_hooks_use_act_select(enum LuaHookedEventType hookType, int
} }
} }
void smlua_call_event_hooks_on_chat_message(enum LuaHookedEventType hookType, struct MarioState* m, const char* message, bool* returnValue) {
lua_State* L = gLuaState;
if (L == NULL) { return; }
struct LuaHookedEvent* hook = &sHookedEvents[hookType];
for (int i = 0; i < hook->count; i++) {
s32 prevTop = lua_gettop(L);
// push the callback onto the stack
lua_rawgeti(L, LUA_REGISTRYINDEX, hook->reference[i]);
// push mario state
lua_getglobal(L, "gMarioStates");
lua_pushinteger(L, m->playerIndex);
lua_gettable(L, -2);
lua_remove(L, -2);
// push the string
lua_pushstring(L, message);
// call the callback
if (0 != smlua_call_hook(L, 2, 1, 0, hook->mod[i])) {
LOG_LUA("Failed to call the callback: %u", hookType);
continue;
}
// output the return value
if (lua_type(L, -1) == LUA_TBOOLEAN) {
*returnValue = smlua_to_boolean(L, -1);
}
lua_settop(L, prevTop);
}
}
//////////////////// ////////////////////
// hooked actions // // hooked actions //
//////////////////// ////////////////////

View file

@ -38,6 +38,7 @@ enum LuaHookedEventType {
HOOK_ON_CHANGE_CAMERA_ANGLE, HOOK_ON_CHANGE_CAMERA_ANGLE,
HOOK_ON_SCREEN_TRANSITION, HOOK_ON_SCREEN_TRANSITION,
HOOK_ALLOW_HAZARD_SURFACE, HOOK_ALLOW_HAZARD_SURFACE,
HOOK_ON_CHAT_MESSAGE,
HOOK_MAX, HOOK_MAX,
}; };
@ -69,6 +70,7 @@ static const char* LuaHookedEventTypeName[] = {
"HOOK_ON_CHANGE_CAMERA_ANGLE", "HOOK_ON_CHANGE_CAMERA_ANGLE",
"HOOK_ON_SCREEN_TRANSITION", "HOOK_ON_SCREEN_TRANSITION",
"HOOK_ALLOW_HAZARD_SURFACE", "HOOK_ALLOW_HAZARD_SURFACE",
"HOOK_ON_CHAT_MESSAGE",
"HOOK_MAX" "HOOK_MAX"
}; };
@ -104,6 +106,7 @@ void smlua_call_event_hooks_int_params_ret_bool(enum LuaHookedEventType hookType
void smlua_call_event_hooks_value_param(enum LuaHookedEventType hookType, int modIndex, int valueIndex); void smlua_call_event_hooks_value_param(enum LuaHookedEventType hookType, int modIndex, int valueIndex);
void smlua_call_event_hooks_use_act_select(enum LuaHookedEventType hookType, int value, bool* foundHook, bool* returnValue); void smlua_call_event_hooks_use_act_select(enum LuaHookedEventType hookType, int value, bool* foundHook, bool* returnValue);
void smlua_call_event_hooks_ret_bool(enum LuaHookedEventType hookType, bool* returnValue); void smlua_call_event_hooks_ret_bool(enum LuaHookedEventType hookType, bool* returnValue);
void smlua_call_event_hooks_on_chat_message(enum LuaHookedEventType hookType, struct MarioState* m, const char* message, bool* returnValue);
enum BehaviorId smlua_get_original_behavior_id(const BehaviorScript* behavior); enum BehaviorId smlua_get_original_behavior_id(const BehaviorScript* behavior);
const BehaviorScript* smlua_override_behavior(const BehaviorScript* behavior); const BehaviorScript* smlua_override_behavior(const BehaviorScript* behavior);