Added HOOK_ON_OBJECT_RENDER

This commit is contained in:
MysterD 2022-04-19 22:36:47 -07:00
parent 1ec9ddeb5d
commit 2347ab61c1
10 changed files with 22 additions and 5 deletions

View file

@ -7846,7 +7846,10 @@ HOOK_GET_STAR_COLLECTION_DIALOG = 17
HOOK_ON_SET_CAMERA_MODE = 18 HOOK_ON_SET_CAMERA_MODE = 18
--- @type LuaHookedEventType --- @type LuaHookedEventType
HOOK_MAX = 19 HOOK_ON_OBJECT_RENDER = 19
--- @type LuaHookedEventType
HOOK_MAX = 20
--- @class ModelExtendedId --- @class ModelExtendedId

View file

@ -732,6 +732,7 @@
--- @field public hitboxDownOffset number --- @field public hitboxDownOffset number
--- @field public hitboxHeight number --- @field public hitboxHeight number
--- @field public hitboxRadius number --- @field public hitboxRadius number
--- @field public hookRender integer
--- @field public hurtboxHeight number --- @field public hurtboxHeight number
--- @field public hurtboxRadius number --- @field public hurtboxRadius number
--- @field public numCollidedObjs integer --- @field public numCollidedObjs integer

View file

@ -2753,7 +2753,8 @@
| HOOK_ON_PAUSE_EXIT | 16 | | HOOK_ON_PAUSE_EXIT | 16 |
| HOOK_GET_STAR_COLLECTION_DIALOG | 17 | | HOOK_GET_STAR_COLLECTION_DIALOG | 17 |
| HOOK_ON_SET_CAMERA_MODE | 18 | | HOOK_ON_SET_CAMERA_MODE | 18 |
| HOOK_MAX | 19 | | HOOK_ON_OBJECT_RENDER | 19 |
| HOOK_MAX | 20 |
[:arrow_up_small:](#) [:arrow_up_small:](#)

View file

@ -105,6 +105,7 @@ The lua functions sent to `hook_event()` will be automatically called by SM64 wh
| HOOK_ON_PAUSE_EXIT | Called when the local player exits through the pause screen, return `false` to prevent the exit | `boolean` usedExitToCastle | | HOOK_ON_PAUSE_EXIT | Called when the local player exits through the pause screen, return `false` to prevent the exit | `boolean` usedExitToCastle |
| HOOK_GET_STAR_COLLECTION_DIALOG | Called when the local player collects a star, return a [DialogId](constants.md#enum-DialogId) to show a message | None | | HOOK_GET_STAR_COLLECTION_DIALOG | Called when the local player collects a star, return a [DialogId](constants.md#enum-DialogId) to show a message | None |
| HOOK_ON_SET_CAMERA_MODE | Called when the camera mode gets set, return `false` to prevent the camera mode from being set | [Camera](structs.md#Camera), `integer` mode, `integer` frames | | HOOK_ON_SET_CAMERA_MODE | Called when the camera mode gets set, return `false` to prevent the camera mode from being set | [Camera](structs.md#Camera), `integer` mode, `integer` frames |
| HOOK_ON_OBJECT_RENDER | Called right before an object is rendered. **Note:** You must set the `hookRender` field of the object to a non-zero value | [Object](structs.md#Object) |
### Parameters ### Parameters

View file

@ -1043,6 +1043,7 @@
| hitboxDownOffset | `number` | | | hitboxDownOffset | `number` | |
| hitboxHeight | `number` | | | hitboxHeight | `number` | |
| hitboxRadius | `number` | | | hitboxRadius | `number` | |
| hookRender | `integer` | |
| hurtboxHeight | `number` | | | hurtboxHeight | `number` | |
| hurtboxRadius | `number` | | | hurtboxRadius | `number` | |
| numCollidedObjs | `integer` | | | numCollidedObjs | `integer` | |

View file

@ -219,6 +219,7 @@ struct Object
/*?????*/ void (*areaTimerRunOnceCallback)(void); /*?????*/ void (*areaTimerRunOnceCallback)(void);
/*?????*/ u8 globalPlayerIndex; /*?????*/ u8 globalPlayerIndex;
/*?????*/ struct Object* usingObj; /*?????*/ struct Object* usingObj;
/*?????*/ u8 hookRender;
}; };
struct ObjectHitbox struct ObjectHitbox

View file

@ -11,6 +11,7 @@
#include "shadow.h" #include "shadow.h"
#include "sm64.h" #include "sm64.h"
#include "game/level_update.h" #include "game/level_update.h"
#include "pc/lua/smlua_hooks.h"
/** /**
* This file contains the code that processes the scene graph for rendering. * This file contains the code that processes the scene graph for rendering.
@ -1078,7 +1079,11 @@ static void geo_process_object(struct Object *node) {
Mat4 mtxf; Mat4 mtxf;
s32 hasAnimation = (node->header.gfx.node.flags & GRAPH_RENDER_HAS_ANIMATION) != 0; s32 hasAnimation = (node->header.gfx.node.flags & GRAPH_RENDER_HAS_ANIMATION) != 0;
Vec3f scaleInterpolated; Vec3f scaleInterpolated;
if (node->hookRender) {
smlua_call_event_hooks_object_param(HOOK_ON_OBJECT_RENDER, node);
}
if (node->header.gfx.node.flags & GRAPH_RENDER_PLAYER) { if (node->header.gfx.node.flags & GRAPH_RENDER_PLAYER) {
gCurGraphNodeMarioState = NULL; gCurGraphNodeMarioState = NULL;
for (s32 i = 0; i < MAX_PLAYERS; i++) { for (s32 i = 0; i < MAX_PLAYERS; i++) {

View file

@ -830,7 +830,7 @@ static struct LuaObjectField sNetworkPlayerFields[LUA_NETWORK_PLAYER_FIELD_COUNT
{ "type", LVT_U8, offsetof(struct NetworkPlayer, type), true, LOT_NONE }, { "type", LVT_U8, offsetof(struct NetworkPlayer, type), true, LOT_NONE },
}; };
#define LUA_OBJECT_FIELD_COUNT 752 #define LUA_OBJECT_FIELD_COUNT 753
static struct LuaObjectField sObjectFields[LUA_OBJECT_FIELD_COUNT] = { static struct LuaObjectField sObjectFields[LUA_OBJECT_FIELD_COUNT] = {
{ "activeFlags", LVT_S16, offsetof(struct Object, activeFlags), false, LOT_NONE }, { "activeFlags", LVT_S16, offsetof(struct Object, activeFlags), false, LOT_NONE },
{ "areaTimer", LVT_U32, offsetof(struct Object, areaTimer), false, LOT_NONE }, { "areaTimer", LVT_U32, offsetof(struct Object, areaTimer), false, LOT_NONE },
@ -852,6 +852,7 @@ static struct LuaObjectField sObjectFields[LUA_OBJECT_FIELD_COUNT] = {
{ "hitboxDownOffset", LVT_F32, offsetof(struct Object, hitboxDownOffset), false, LOT_NONE }, { "hitboxDownOffset", LVT_F32, offsetof(struct Object, hitboxDownOffset), false, LOT_NONE },
{ "hitboxHeight", LVT_F32, offsetof(struct Object, hitboxHeight), false, LOT_NONE }, { "hitboxHeight", LVT_F32, offsetof(struct Object, hitboxHeight), false, LOT_NONE },
{ "hitboxRadius", LVT_F32, offsetof(struct Object, hitboxRadius), false, LOT_NONE }, { "hitboxRadius", LVT_F32, offsetof(struct Object, hitboxRadius), false, LOT_NONE },
{ "hookRender", LVT_U8, offsetof(struct Object, hookRender), false, LOT_NONE },
{ "hurtboxHeight", LVT_F32, offsetof(struct Object, hurtboxHeight), false, LOT_NONE }, { "hurtboxHeight", LVT_F32, offsetof(struct Object, hurtboxHeight), false, LOT_NONE },
{ "hurtboxRadius", LVT_F32, offsetof(struct Object, hurtboxRadius), false, LOT_NONE }, { "hurtboxRadius", LVT_F32, offsetof(struct Object, hurtboxRadius), false, LOT_NONE },
{ "numCollidedObjs", LVT_S16, offsetof(struct Object, numCollidedObjs), false, LOT_NONE }, { "numCollidedObjs", LVT_S16, offsetof(struct Object, numCollidedObjs), false, LOT_NONE },

View file

@ -2796,7 +2796,8 @@ char gSmluaConstants[] = ""
"HOOK_ON_PAUSE_EXIT = 16\n" "HOOK_ON_PAUSE_EXIT = 16\n"
"HOOK_GET_STAR_COLLECTION_DIALOG = 17\n" "HOOK_GET_STAR_COLLECTION_DIALOG = 17\n"
"HOOK_ON_SET_CAMERA_MODE = 18\n" "HOOK_ON_SET_CAMERA_MODE = 18\n"
"HOOK_MAX = 19\n" "HOOK_ON_OBJECT_RENDER = 19\n"
"HOOK_MAX = 20\n"
"E_MODEL_NONE = 0\n" "E_MODEL_NONE = 0\n"
"E_MODEL_MARIO = 1\n" "E_MODEL_MARIO = 1\n"
"E_MODEL_SMOKE = 2\n" "E_MODEL_SMOKE = 2\n"

View file

@ -27,6 +27,7 @@ enum LuaHookedEventType {
HOOK_ON_PAUSE_EXIT, HOOK_ON_PAUSE_EXIT,
HOOK_GET_STAR_COLLECTION_DIALOG, HOOK_GET_STAR_COLLECTION_DIALOG,
HOOK_ON_SET_CAMERA_MODE, HOOK_ON_SET_CAMERA_MODE,
HOOK_ON_OBJECT_RENDER,
HOOK_MAX, HOOK_MAX,
}; };
@ -50,6 +51,7 @@ static char* LuaHookedEventTypeName[] = {
"HOOK_ON_PAUSE_EXIT", "HOOK_ON_PAUSE_EXIT",
"HOOK_GET_STAR_COLLECTION_DIALOG", "HOOK_GET_STAR_COLLECTION_DIALOG",
"HOOK_ON_SET_CAMERA_MODE", "HOOK_ON_SET_CAMERA_MODE",
"HOOK_ON_OBJECT_RENDER",
"HOOK_MAX" "HOOK_MAX"
}; };