mirror of
https://github.com/coop-deluxe/sm64coopdx.git
synced 2024-11-22 03:55:11 +00:00
Added HOOK_ON_OBJECT_UNLOAD, HOOK_ON_SYNC_OBJECT_UNLOAD
This commit is contained in:
parent
799e1e9f81
commit
11649ce1d8
7 changed files with 43 additions and 3 deletions
|
@ -5294,7 +5294,13 @@ HOOK_ON_WARP = 12
|
|||
HOOK_ON_SYNC_VALID = 13
|
||||
|
||||
--- @type LuaHookedEventType
|
||||
HOOK_MAX = 14
|
||||
HOOK_ON_OBJECT_UNLOAD = 14
|
||||
|
||||
--- @type LuaHookedEventType
|
||||
HOOK_ON_SYNC_OBJECT_UNLOAD = 15
|
||||
|
||||
--- @type LuaHookedEventType
|
||||
HOOK_MAX = 16
|
||||
|
||||
--- @class ModelExtendedId
|
||||
|
||||
|
|
|
@ -1862,7 +1862,9 @@
|
|||
| HOOK_ON_LEVEL_INIT | 11 |
|
||||
| HOOK_ON_WARP | 12 |
|
||||
| HOOK_ON_SYNC_VALID | 13 |
|
||||
| HOOK_MAX | 14 |
|
||||
| HOOK_ON_OBJECT_UNLOAD | 14 |
|
||||
| HOOK_ON_SYNC_OBJECT_UNLOAD | 15 |
|
||||
| HOOK_MAX | 16 |
|
||||
|
||||
[:arrow_up_small:](#)
|
||||
|
||||
|
|
|
@ -100,6 +100,8 @@ The lua functions sent to `hook_event()` will be automatically called by SM64 wh
|
|||
| HOOK_ON_LEVEL_INIT | Called when the level is initialized | None |
|
||||
| HOOK_ON_WARP | Called when the local player warps | None |
|
||||
| HOOK_ON_SYNC_VALID | Called when the current area is synchronized | None |
|
||||
| HOOK_ON_OBJECT_UNLOAD | Called when any object is unloaded | [Object](structs.md#Object) unloadedObject |
|
||||
| HOOK_ON_SYNC_OBJECT_UNLOAD | Called when any networked object is unloaded | [Object](structs.md#Object) unloadedObject |
|
||||
|
||||
### Parameters
|
||||
|
||||
|
|
|
@ -214,8 +214,11 @@ void unload_object(struct Object *obj) {
|
|||
} else {
|
||||
network_send_reservation_release(obj->oSyncID);
|
||||
}
|
||||
smlua_call_event_hooks_object_param(HOOK_ON_SYNC_OBJECT_UNLOAD, obj);
|
||||
}
|
||||
|
||||
smlua_call_event_hooks_object_param(HOOK_ON_OBJECT_UNLOAD, obj);
|
||||
|
||||
deallocate_object(&gFreeObjectList, &obj->header);
|
||||
}
|
||||
|
||||
|
|
|
@ -1904,7 +1904,9 @@ char gSmluaConstants[] = ""
|
|||
"HOOK_ON_LEVEL_INIT = 11\n"
|
||||
"HOOK_ON_WARP = 12\n"
|
||||
"HOOK_ON_SYNC_VALID = 13\n"
|
||||
"HOOK_MAX = 14\n"
|
||||
"HOOK_ON_OBJECT_UNLOAD = 14\n"
|
||||
"HOOK_ON_SYNC_OBJECT_UNLOAD = 15\n"
|
||||
"HOOK_MAX = 16\n"
|
||||
"E_MODEL_NONE = 0\n"
|
||||
"E_MODEL_MARIO = 1\n"
|
||||
"E_MODEL_SMOKE = 2\n"
|
||||
|
|
|
@ -192,6 +192,26 @@ void smlua_call_event_hooks_interact_params(enum LuaHookedEventType hookType, st
|
|||
}
|
||||
}
|
||||
|
||||
void smlua_call_event_hooks_object_param(enum LuaHookedEventType hookType, struct Object* obj) {
|
||||
lua_State* L = gLuaState;
|
||||
if (L == NULL) { return; }
|
||||
struct LuaHookedEvent* hook = &sHookedEvents[hookType];
|
||||
for (int i = 0; i < hook->count; i++) {
|
||||
// push the callback onto the stack
|
||||
lua_rawgeti(L, LUA_REGISTRYINDEX, hook->reference[i]);
|
||||
|
||||
// push object
|
||||
smlua_push_object(L, LOT_OBJECT, obj);
|
||||
|
||||
// call the callback
|
||||
if (0 != smlua_call_hook(L, 1, 0, 0, hook->mod[i])) {
|
||||
LOG_LUA("Failed to call the callback: %u, %s", hookType, lua_tostring(L, -1));
|
||||
smlua_logline();
|
||||
continue;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void smlua_call_event_hooks_network_player_param(enum LuaHookedEventType hookType, struct NetworkPlayer* np) {
|
||||
lua_State* L = gLuaState;
|
||||
if (L == NULL) { return; }
|
||||
|
|
|
@ -19,6 +19,8 @@ enum LuaHookedEventType {
|
|||
HOOK_ON_LEVEL_INIT,
|
||||
HOOK_ON_WARP,
|
||||
HOOK_ON_SYNC_VALID,
|
||||
HOOK_ON_OBJECT_UNLOAD,
|
||||
HOOK_ON_SYNC_OBJECT_UNLOAD,
|
||||
HOOK_MAX,
|
||||
};
|
||||
|
||||
|
@ -37,6 +39,8 @@ static char* LuaHookedEventTypeName[] = {
|
|||
"HOOK_ON_LEVEL_INIT",
|
||||
"HOOK_ON_WARP",
|
||||
"HOOK_ON_SYNC_VALID",
|
||||
"HOOK_ON_OBJECT_UNLOAD",
|
||||
"HOOK_ON_SYNC_OBJECT_UNLOAD",
|
||||
"HOOK_MAX"
|
||||
};
|
||||
|
||||
|
@ -47,6 +51,7 @@ void smlua_call_event_hooks_mario_param(enum LuaHookedEventType hookType, struct
|
|||
void smlua_call_event_hooks_mario_params(enum LuaHookedEventType hookType, struct MarioState* m1, struct MarioState* m2);
|
||||
void smlua_call_event_hooks_mario_params_ret_bool(enum LuaHookedEventType hookType, struct MarioState* m1, struct MarioState* m2, bool* returnValue);
|
||||
void smlua_call_event_hooks_interact_params(enum LuaHookedEventType hookType, struct MarioState* m, struct Object* obj, u32 interactType, bool interactValue);
|
||||
void smlua_call_event_hooks_object_param(enum LuaHookedEventType hookType, struct Object* obj);
|
||||
|
||||
const BehaviorScript* smlua_override_behavior(const BehaviorScript* behavior);
|
||||
const BehaviorScript* get_lua_behavior_from_id(enum BehaviorId id, bool returnOriginal);
|
||||
|
|
Loading…
Reference in a new issue