Initial custom behavior commit

This commit is contained in:
MysterD 2022-03-03 01:04:15 -08:00
parent 6783ef0b7f
commit 3ad6c721dc
21 changed files with 5743 additions and 40 deletions

View File

@ -24,6 +24,8 @@ in_files = [
"src/pc/lua/smlua_model_utils.h",
"include/object_constants.h",
"include/mario_geo_switch_case_ids.h",
"src/game/object_list_processor.h",
"src/engine/graph_node.h",
]
exclude_constants = {
@ -31,7 +33,7 @@ exclude_constants = {
}
include_constants = {
"include/object_constants.h" : [ "^ACTIVE_FLAG_", "^ACTIVE_PARTICLE_", "^HELD_", "^OBJ_FLAG_", "^RESPAWN_INFO_", ],
"include/object_constants.h" : [ "^ACTIVE_FLAG_", "^ACTIVE_PARTICLE_", "^HELD_", "^OBJ_FLAG_", "^RESPAWN_INFO_", "^OBJ_MOVE_" ],
}
pretend_find = [

View File

@ -66,7 +66,7 @@ override_disallowed_functions = {
"src/game/sound_init.h": [ "_loop_", "thread4_", "set_sound_mode" ],
"src/pc/network/network_utils.h": [ "network_get_player_text_color[^_]" ],
"src/pc/network/network_player.h": [ "_init", "_connected[^_]", "_shutdown", "_disconnected", "_update" ],
"src/game/object_helpers.c": [ "spawn_obj" ],
"src/game/object_helpers.c": [ "spawn_obj", "^bhv_", "abs[fi]", "^bit_shift", "_debug$", "^stub_" ],
"src/game/obj_behaviors.c": [ "debug_" ],
"src/game/obj_behaviors_2.c": [ "wiggler_jumped_on_attack_handler", "huge_goomba_weakly_attacked" ],
}

View File

@ -13,7 +13,8 @@ in_files = [
'src/engine/surface_collision.h',
'src/pc/network/network_player.h',
'src/pc/djui/djui_hud_utils.h',
'src/game/object_helpers.h'
'src/game/object_helpers.h',
'src/game/mario_step.h'
]
smlua_cobject_autogen = 'src/pc/lua/smlua_cobject_autogen'

View File

@ -2,6 +2,19 @@ import os
import re
import sys
replacements = {
'BAD_RETURN(s8)': 'void',
'BAD_RETURN(s16)': 'void',
'BAD_RETURN(s32)': 'void',
'BAD_RETURN(s64)': 'void',
'BAD_RETURN(u8)': 'void',
'BAD_RETURN(u16)': 'void',
'BAD_RETURN(u32)': 'void',
'BAD_RETURN(u64)': 'void',
'BAD_RETURN(f32)': 'void',
'BAD_RETURN(f64)': 'void',
}
def extract_functions(filename):
with open(filename) as file:
lines = file.readlines()
@ -19,6 +32,9 @@ def extract_functions(filename):
if not gobbling:
txt += line + '\n'
for replacement in replacements:
txt = txt.replace(replacement, replacements[replacement])
# strip directives and comments
in_directive = False
tmp = txt

View File

@ -6657,4 +6657,3 @@ const BehaviorScript bhvIntroScene[] = {
CALL_NATIVE(bhv_intro_scene_loop),
END_LOOP(),
};

View File

@ -1,5 +1,6 @@
#include <assert.h>
#include "behavior_table.h"
#include "pc/lua/smlua_hooks.h"
const BehaviorScript* gBehaviorTable[id_bhv_max_count] = {
[id_bhvStarDoor] = bhvStarDoor,
@ -525,8 +526,12 @@ enum BehaviorId get_id_from_behavior(const BehaviorScript* behavior) {
}
const BehaviorScript* get_behavior_from_id(enum BehaviorId id) {
const BehaviorScript* behavior = get_lua_behavior_from_id(id);
if (behavior != NULL) { return behavior; }
if (id < 0 || id >= id_bhv_max_count) {
return NULL;
}
return gBehaviorTable[id];
}

View File

@ -11,6 +11,7 @@
- [djui_hud_utils.h](#djui_hud_utils.h)
- [DjuiFontType](#DjuiFontType)
- [HudUtilsResolution](#HudUtilsResolution)
- [graph_node.h](#graph_node.h)
- [interaction.c](#interaction.c)
- [InteractionFlag](#InteractionFlag)
- [interaction.h](#interaction.h)
@ -25,6 +26,8 @@
- [network_player.h](#network_player.h)
- [NetworkPlayerType](#NetworkPlayerType)
- [object_constants.h](#object_constants.h)
- [object_list_processor.h](#object_list_processor.h)
- [ObjectList](#ObjectList)
- [os_cont.h](#os_cont.h)
- [sm64.h](#sm64.h)
- [smlua_hooks.h](#smlua_hooks.h)
@ -1299,6 +1302,49 @@
<br />
## [graph_node.h](#graph_node.h)
- GEO_CONTEXT_AREA_INIT
- GEO_CONTEXT_AREA_LOAD
- GEO_CONTEXT_AREA_UNLOAD
- GEO_CONTEXT_CREATE
- GEO_CONTEXT_HELD_OBJ
- GEO_CONTEXT_RENDER
- GFX_NUM_MASTER_LISTS
- GRAPH_NODE_TYPE_400
- GRAPH_NODE_TYPE_ANIMATED_PART
- GRAPH_NODE_TYPE_BACKGROUND
- GRAPH_NODE_TYPE_BILLBOARD
- GRAPH_NODE_TYPE_CAMERA
- GRAPH_NODE_TYPE_CULLING_RADIUS
- GRAPH_NODE_TYPE_DISPLAY_LIST
- GRAPH_NODE_TYPE_FUNCTIONAL
- GRAPH_NODE_TYPE_GENERATED_LIST
- GRAPH_NODE_TYPE_HELD_OBJ
- GRAPH_NODE_TYPE_LEVEL_OF_DETAIL
- GRAPH_NODE_TYPE_MASTER_LIST
- GRAPH_NODE_TYPE_OBJECT
- GRAPH_NODE_TYPE_OBJECT_PARENT
- GRAPH_NODE_TYPE_ORTHO_PROJECTION
- GRAPH_NODE_TYPE_PERSPECTIVE
- GRAPH_NODE_TYPE_ROOT
- GRAPH_NODE_TYPE_ROTATION
- GRAPH_NODE_TYPE_SCALE
- GRAPH_NODE_TYPE_SHADOW
- GRAPH_NODE_TYPE_START
- GRAPH_NODE_TYPE_SWITCH_CASE
- GRAPH_NODE_TYPE_TRANSLATION
- GRAPH_NODE_TYPE_TRANSLATION_ROTATION
- GRAPH_RENDER_ACTIVE
- GRAPH_RENDER_BILLBOARD
- GRAPH_RENDER_CHILDREN_FIRST
- GRAPH_RENDER_CYLBOARD
- GRAPH_RENDER_HAS_ANIMATION
- GRAPH_RENDER_INVISIBLE
- GRAPH_RENDER_PLAYER
- GRAPH_RENDER_Z_BUFFER
<br />
## [interaction.c](#interaction.c)
- INT_ANY_ATTACK
- INT_ATTACK_NOT_FROM_BELOW
@ -1728,6 +1774,23 @@
- OBJ_FLAG_SET_THROW_MATRIX_FROM_TRANSFORM
- OBJ_FLAG_TRANSFORM_RELATIVE_TO_PARENT
- OBJ_FLAG_UPDATE_GFX_POS_AND_ANGLE
- OBJ_MOVE_ABOVE_DEATH_BARRIER
- OBJ_MOVE_ABOVE_LAVA
- OBJ_MOVE_AT_WATER_SURFACE
- OBJ_MOVE_BOUNCE
- OBJ_MOVE_ENTERED_WATER
- OBJ_MOVE_HIT_EDGE
- OBJ_MOVE_HIT_WALL
- OBJ_MOVE_IN_AIR
- OBJ_MOVE_LANDED
- OBJ_MOVE_LEAVING_WATER
- OBJ_MOVE_LEFT_GROUND
- OBJ_MOVE_MASK_IN_WATER
- OBJ_MOVE_MASK_ON_GROUND
- OBJ_MOVE_ON_GROUND
- OBJ_MOVE_OUT_SCOPE
- OBJ_MOVE_UNDERWATER_OFF_GROUND
- OBJ_MOVE_UNDERWATER_ON_GROUND
- RESPAWN_INFO_DONT_RESPAWN
- RESPAWN_INFO_TYPE_16
- RESPAWN_INFO_TYPE_32
@ -1735,6 +1798,36 @@
<br />
## [object_list_processor.h](#object_list_processor.h)
- OBJECT_POOL_CAPACITY
- TIME_STOP_ACTIVE
- TIME_STOP_ALL_OBJECTS
- TIME_STOP_DIALOG
- TIME_STOP_ENABLED
- TIME_STOP_MARIO_AND_DOORS
- TIME_STOP_MARIO_OPENED_DOOR
- TIME_STOP_UNKNOWN_0
### [enum ObjectList](#ObjectList)
| Identifier | Value |
| :--------- | :---- |
| OBJ_LIST_PLAYER | 0 |
| OBJ_LIST_UNUSED_1 | 1 |
| OBJ_LIST_DESTRUCTIVE | 2 |
| OBJ_LIST_UNUSED_3 | 3 |
| OBJ_LIST_GENACTOR | 4 |
| OBJ_LIST_PUSHABLE | 5 |
| OBJ_LIST_LEVEL | 6 |
| OBJ_LIST_UNUSED_7 | 7 |
| OBJ_LIST_DEFAULT | 8 |
| OBJ_LIST_SURFACE | 9 |
| OBJ_LIST_POLELIKE | 10 |
| OBJ_LIST_SPAWNER | 11 |
| OBJ_LIST_UNIMPORTANT | 12 |
| NUM_OBJ_LISTS | 13 |
<br />
## [os_cont.h](#os_cont.h)
- A_BUTTON
- B_BUTTON

File diff suppressed because it is too large Load Diff

View File

@ -4,6 +4,7 @@
- [AnimInfo](#AnimInfo)
- [Animation](#Animation)
- [Area](#Area)
- [BullyCollisionData](#BullyCollisionData)
- [Camera](#Camera)
- [CameraFOVStatus](#CameraFOVStatus)
- [CameraStoredInfo](#CameraStoredInfo)
@ -119,6 +120,21 @@
<br />
## [BullyCollisionData](#BullyCollisionData)
| Field | Type | Access |
| ----- | ---- | ------ |
| conversionRatio | number | |
| posX | number | |
| posZ | number | |
| radius | number | |
| velX | number | |
| velZ | number | |
[:arrow_up_small:](#)
<br />
## [Camera](#Camera)
| Field | Type | Access |

View File

@ -167,7 +167,7 @@
#define ACT_FLAG_PAUSE_EXIT /* 0x08000000 */ (1 << 27)
#define ACT_FLAG_SWIMMING_OR_FLYING /* 0x10000000 */ (1 << 28)
#define ACT_FLAG_WATER_OR_TEXT /* 0x20000000 */ (1 << 29)
#define ACT_FLAG_THROWING /* 0x80000000 */ ((u32)1 << 31)
#define ACT_FLAG_THROWING /* 0x80000000 */ (1 << 31)
#define ACT_UNINITIALIZED 0x00000000 // (0x000)

View File

@ -7,7 +7,7 @@
#define AI_LEN_REG 0x04500004
#define AI_CONTROL_REG 0x04500008
#define AI_STATUS_REG 0x0450000C
#define AI_STATUS_AI_FULL ((u32)1 << 31)
#define AI_STATUS_AI_FULL (1 << 31)
#define AI_STATUS_AI_BUSY (1 << 30)
#define AI_DACRATE_REG 0x04500010
#define AI_BITRATE_REG 0x04500014

View File

@ -14,6 +14,7 @@
#include "graph_node.h"
#include "surface_collision.h"
#include "pc/network/network.h"
#include "pc/lua/smlua_hooks.h"
#include "game/rng_position.h"
// Macros for retrieving arguments from behavior scripts.
@ -1022,12 +1023,14 @@ cur_obj_update_begin:;
// Execute the behavior script.
gCurBhvCommand = gCurrentObject->curBhvCommand;
u8 skipBehavior = smlua_call_behavior_hook(&gCurBhvCommand, gCurrentObject);
do {
bhvCmdProc = BehaviorCmdTable[*gCurBhvCommand >> 24];
bhvProcResult = bhvCmdProc();
} while (bhvProcResult == BHV_PROC_CONTINUE);
if (!skipBehavior) {
do {
bhvCmdProc = BehaviorCmdTable[*gCurBhvCommand >> 24];
bhvProcResult = bhvCmdProc();
} while (bhvProcResult == BHV_PROC_CONTINUE);
}
gCurrentObject->curBhvCommand = gCurBhvCommand;
// Increment the object's timer.

View File

@ -37,7 +37,7 @@ enum InteractionType {
INTERACT_SNUFIT_BULLET = /* 0x10000000 */ (1 << 28),
INTERACT_SHOCK = /* 0x20000000 */ (1 << 29),
INTERACT_IGLOO_BARRIER = /* 0x40000000 */ (1 << 30),
INTERACT_PLAYER = /* 0x80000000 */ ((u32)1 << 31),
INTERACT_PLAYER = /* 0x80000000 */ (1 << 31),
};
// INTERACT_WARP

View File

@ -35,10 +35,17 @@ s8 D_8032F0A0[] = { -8, 8, -4, 4 };
s16 D_8032F0A4[] = { 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80 };
static s8 sLevelsWithRooms[] = { LEVEL_BBH, LEVEL_CASTLE, LEVEL_HMC, -1 };
static s32 clear_move_flag(u32 *, s32);
#define o gCurrentObject
s32 clear_move_flag(u32 *bitSet, s32 flag) {
if (*bitSet & flag) {
*bitSet &= flag ^ 0xFFFFFFFF;
return TRUE;
} else {
return FALSE;
}
}
Gfx *geo_update_projectile_pos_from_parent(s32 callContext, UNUSED struct GraphNode *node, Mat4 mtx) {
Mat4 sp20;
struct Object *sp1C;
@ -640,7 +647,7 @@ struct Object *spawn_object_with_scale(struct Object *parent, s32 model, const B
return obj;
}
static void obj_build_relative_transform(struct Object *obj) {
void obj_build_relative_transform(struct Object *obj) {
obj_build_transform_from_pos_and_angle(obj, O_PARENT_RELATIVE_POS_INDEX, O_FACE_ANGLE_INDEX);
obj_translate_local(obj, O_POS_INDEX, O_PARENT_RELATIVE_POS_INDEX);
}
@ -1056,7 +1063,7 @@ struct Object *cur_obj_find_nearby_held_actor(const BehaviorScript *behavior, f3
return foundObj;
}
static void cur_obj_reset_timer_and_subaction(void) {
void cur_obj_reset_timer_and_subaction(void) {
o->oTimer = 0;
o->oSubAction = 0;
}
@ -1185,7 +1192,7 @@ void cur_obj_unrender_and_reset_state(s32 sp18, s32 sp1C) {
o->oAction = sp1C;
}
static void cur_obj_move_after_thrown_or_dropped(f32 forwardVel, f32 velY) {
void cur_obj_move_after_thrown_or_dropped(f32 forwardVel, f32 velY) {
o->oMoveFlags = 0;
o->oFloorHeight = find_floor_height(o->oPosX, o->oPosY + 160.0f, o->oPosZ);
@ -1300,7 +1307,7 @@ struct Surface *cur_obj_update_floor_height_and_get_floor(void) {
return floor;
}
static void apply_drag_to_value(f32 *value, f32 dragStrength) {
void apply_drag_to_value(f32 *value, f32 dragStrength) {
f32 decel;
if (*value != 0) {
@ -1326,7 +1333,7 @@ void cur_obj_apply_drag_xz(f32 dragStrength) {
apply_drag_to_value(&o->oVelZ, dragStrength);
}
static s32 cur_obj_move_xz(f32 steepSlopeNormalY, s32 careAboutEdgesAndSteepSlopes) {
s32 cur_obj_move_xz(f32 steepSlopeNormalY, s32 careAboutEdgesAndSteepSlopes) {
struct Surface *intendedFloor = NULL;
f32 intendedX = o->oPosX + o->oVelX;
@ -1385,7 +1392,7 @@ static s32 cur_obj_move_xz(f32 steepSlopeNormalY, s32 careAboutEdgesAndSteepSlop
return FALSE;
}
static void cur_obj_move_update_underwater_flags(void) {
void cur_obj_move_update_underwater_flags(void) {
f32 decelY = (f32)(sqrtf(o->oVelY * o->oVelY) * (o->oDragStrength * 7.0f)) / 100.0L;
if (o->oVelY > 0) {
@ -1402,7 +1409,7 @@ static void cur_obj_move_update_underwater_flags(void) {
}
}
static void cur_obj_move_update_ground_air_flags(UNUSED f32 gravity, f32 bounciness) {
void cur_obj_move_update_ground_air_flags(UNUSED f32 gravity, f32 bounciness) {
o->oMoveFlags &= ~OBJ_MOVE_BOUNCE;
if (o->oPosY < o->oFloorHeight) {
@ -1437,7 +1444,7 @@ static void cur_obj_move_update_ground_air_flags(UNUSED f32 gravity, f32 bouncin
o->oMoveFlags &= ~OBJ_MOVE_MASK_IN_WATER;
}
static f32 cur_obj_move_y_and_get_water_level(f32 gravity, f32 buoyancy) {
f32 cur_obj_move_y_and_get_water_level(f32 gravity, f32 buoyancy) {
f32 waterLevel;
o->oVelY += gravity + buoyancy;
@ -1508,15 +1515,6 @@ void cur_obj_move_y(f32 gravity, f32 bounciness, f32 buoyancy) {
static void stub_obj_helpers_1(void) {
}
static s32 clear_move_flag(u32 *bitSet, s32 flag) {
if (*bitSet & flag) {
*bitSet &= flag ^ 0xFFFFFFFF;
return TRUE;
} else {
return FALSE;
}
}
void cur_obj_unused_resolve_wall_collisions(f32 offsetY, f32 radius) {
if (radius > 0.1L) {
f32_find_wall_collision(&o->oPosX, &o->oPosY, &o->oPosZ, offsetY, radius);
@ -1730,7 +1728,7 @@ void cur_obj_set_hurtbox_radius_and_height(f32 radius, f32 height) {
o->hurtboxHeight = height;
}
static void obj_spawn_loot_coins(struct Object *obj, s32 numCoins, f32 sp30,
void obj_spawn_loot_coins(struct Object *obj, s32 numCoins, f32 sp30,
const BehaviorScript *coinBehavior,
s16 posJitter, s16 model) {
s32 i;
@ -1809,7 +1807,7 @@ s32 cur_obj_advance_looping_anim(void) {
return result;
}
static s32 cur_obj_detect_steep_floor(s16 steepAngleDegrees) {
s32 cur_obj_detect_steep_floor(s16 steepAngleDegrees) {
struct Surface *intendedFloor;
f32 intendedX, intendedFloorHeight, intendedZ;
f32 deltaFloorHeight;
@ -1870,7 +1868,7 @@ s32 cur_obj_resolve_wall_collisions(void) {
return FALSE;
}
static void cur_obj_update_floor(void) {
void cur_obj_update_floor(void) {
struct Surface *floor = cur_obj_update_floor_height_and_get_floor();
o->oFloor = floor;
@ -1893,7 +1891,7 @@ static void cur_obj_update_floor(void) {
}
}
static void cur_obj_update_floor_and_resolve_wall_collisions(s16 steepSlopeDegrees) {
void cur_obj_update_floor_and_resolve_wall_collisions(s16 steepSlopeDegrees) {
#ifdef VERSION_JP
o->oMoveFlags &= ~OBJ_MOVE_ABOVE_LAVA;
#else
@ -1969,7 +1967,7 @@ void cur_obj_move_standard(s16 steepSlopeAngleDegrees) {
}
}
static s32 cur_obj_within_12k_bounds(void) {
s32 cur_obj_within_12k_bounds(void) {
if (o->oPosX < -12000.0f || 12000.0f < o->oPosX) {
return FALSE;
}
@ -2203,7 +2201,7 @@ void obj_translate_xz_random(struct Object *obj, f32 rangeLength) {
obj->oPosZ += random_float() * rangeLength - rangeLength * 0.5f;
}
static void obj_build_vel_from_transform(struct Object *a0) {
void obj_build_vel_from_transform(struct Object *a0) {
f32 spC = a0->oUnkC0;
f32 sp8 = a0->oUnkBC;
f32 sp4 = a0->oForwardVel;
@ -2500,7 +2498,7 @@ void cur_obj_call_action_function(void (*actionFunctions[])(void)) {
actionFunction();
}
static struct Object *spawn_star_with_no_lvl_exit(s32 sp20, s32 sp24) {
struct Object *spawn_star_with_no_lvl_exit(s32 sp20, s32 sp24) {
struct Object *sp1C = spawn_object(o, MODEL_STAR, bhvSpawnedStarNoLevelExit);
if (sp1C == NULL) { return NULL; }
sp1C->oSparkleSpawnUnk1B0 = sp24;
@ -2742,7 +2740,7 @@ s32 cur_obj_can_mario_activate_textbox_2(struct MarioState* m, f32 radius, f32 h
return cur_obj_can_mario_activate_textbox(m, radius, height, 0x1000);
}
static void cur_obj_end_dialog(struct MarioState* m, s32 dialogFlags, s32 dialogResult) {
void cur_obj_end_dialog(struct MarioState* m, s32 dialogFlags, s32 dialogResult) {
if (m->playerIndex != 0) { return; }
o->oDialogResponse = dialogResult;

View File

@ -14,6 +14,7 @@
#include "types.h"
#include "pc/network/network.h"
#include "pc/network/reservation_area.h"
#include "pc/lua/smlua_hooks.h"
/**
* An unused linked list struct that seems to have been replaced by ObjectNode.
@ -334,6 +335,7 @@ struct Object *create_object(const BehaviorScript *bhvScript) {
s32 objListIndex;
struct Object *obj;
struct ObjectNode *objList;
bhvScript = smlua_override_behavior(bhvScript);
const BehaviorScript *behavior = bhvScript;
// If the first behavior script command is "begin <object list>", then

View File

@ -9,6 +9,7 @@
#include "src/pc/network/network_player.h"
#include "src/pc/djui/djui_hud_utils.h"
#include "src/game/object_helpers.h"
#include "src/game/mario_step.h"
#include "include/object_fields.h"
@ -63,6 +64,16 @@ static struct LuaObjectField sAreaFields[LUA_AREA_FIELD_COUNT] = {
// { "whirlpools", LOT_???, offsetof(struct Area, whirlpools), false, LOT_??? }, <--- UNIMPLEMENTED
};
#define LUA_BULLY_COLLISION_DATA_FIELD_COUNT 6
static struct LuaObjectField sBullyCollisionDataFields[LUA_BULLY_COLLISION_DATA_FIELD_COUNT] = {
{ "conversionRatio", LVT_F32, offsetof(struct BullyCollisionData, conversionRatio), false, LOT_NONE },
{ "posX", LVT_F32, offsetof(struct BullyCollisionData, posX), false, LOT_NONE },
{ "posZ", LVT_F32, offsetof(struct BullyCollisionData, posZ), false, LOT_NONE },
{ "radius", LVT_F32, offsetof(struct BullyCollisionData, radius), false, LOT_NONE },
{ "velX", LVT_F32, offsetof(struct BullyCollisionData, velX), false, LOT_NONE },
{ "velZ", LVT_F32, offsetof(struct BullyCollisionData, velZ), false, LOT_NONE },
};
#define LUA_CAMERA_FIELD_COUNT 12
static struct LuaObjectField sCameraFields[LUA_CAMERA_FIELD_COUNT] = {
{ "areaCenX", LVT_F32, offsetof(struct Camera, areaCenX), false, LOT_NONE },
@ -1487,6 +1498,7 @@ struct LuaObjectTable sLuaObjectAutogenTable[LOT_AUTOGEN_MAX - LOT_AUTOGEN_MIN]
{ LOT_ANIMINFO, sAnimInfoFields, LUA_ANIM_INFO_FIELD_COUNT },
{ LOT_ANIMATION, sAnimationFields, LUA_ANIMATION_FIELD_COUNT },
{ LOT_AREA, sAreaFields, LUA_AREA_FIELD_COUNT },
{ LOT_BULLYCOLLISIONDATA, sBullyCollisionDataFields, LUA_BULLY_COLLISION_DATA_FIELD_COUNT },
{ LOT_CAMERA, sCameraFields, LUA_CAMERA_FIELD_COUNT },
{ LOT_CAMERAFOVSTATUS, sCameraFOVStatusFields, LUA_CAMERA_FOVSTATUS_FIELD_COUNT },
{ LOT_CAMERASTOREDINFO, sCameraStoredInfoFields, LUA_CAMERA_STORED_INFO_FIELD_COUNT },

View File

@ -8,6 +8,7 @@ enum LuaObjectAutogenType {
LOT_ANIMINFO,
LOT_ANIMATION,
LOT_AREA,
LOT_BULLYCOLLISIONDATA,
LOT_CAMERA,
LOT_CAMERAFOVSTATUS,
LOT_CAMERASTOREDINFO,

View File

@ -1367,6 +1367,45 @@ char gSmluaConstants[] = ""
"FONT_MENU = 1\n"
"FONT_HUD = 2\n"
"FONT_COUNT = 3\n"
"GRAPH_RENDER_ACTIVE = (1 << 0)\n"
"GRAPH_RENDER_CHILDREN_FIRST = (1 << 1)\n"
"GRAPH_RENDER_BILLBOARD = (1 << 2)\n"
"GRAPH_RENDER_Z_BUFFER = (1 << 3)\n"
"GRAPH_RENDER_INVISIBLE = (1 << 4)\n"
"GRAPH_RENDER_HAS_ANIMATION = (1 << 5)\n"
"GRAPH_RENDER_CYLBOARD = (1 << 6)\n"
"GRAPH_RENDER_PLAYER = (1 << 7)\n"
"GRAPH_NODE_TYPE_FUNCTIONAL = 0x100\n"
"GRAPH_NODE_TYPE_400 = 0x400\n"
"GRAPH_NODE_TYPE_ROOT = 0x001\n"
"GRAPH_NODE_TYPE_ORTHO_PROJECTION = 0x002\n"
"GRAPH_NODE_TYPE_PERSPECTIVE = (0x003 | GRAPH_NODE_TYPE_FUNCTIONAL)\n"
"GRAPH_NODE_TYPE_MASTER_LIST = 0x004\n"
"GRAPH_NODE_TYPE_START = 0x00A\n"
"GRAPH_NODE_TYPE_LEVEL_OF_DETAIL = 0x00B\n"
"GRAPH_NODE_TYPE_SWITCH_CASE = (0x00C | GRAPH_NODE_TYPE_FUNCTIONAL)\n"
"GRAPH_NODE_TYPE_CAMERA = (0x014 | GRAPH_NODE_TYPE_FUNCTIONAL)\n"
"GRAPH_NODE_TYPE_TRANSLATION_ROTATION = 0x015\n"
"GRAPH_NODE_TYPE_TRANSLATION = 0x016\n"
"GRAPH_NODE_TYPE_ROTATION = 0x017\n"
"GRAPH_NODE_TYPE_OBJECT = 0x018\n"
"GRAPH_NODE_TYPE_ANIMATED_PART = 0x019\n"
"GRAPH_NODE_TYPE_BILLBOARD = 0x01A\n"
"GRAPH_NODE_TYPE_DISPLAY_LIST = 0x01B\n"
"GRAPH_NODE_TYPE_SCALE = 0x01C\n"
"GRAPH_NODE_TYPE_SHADOW = 0x028\n"
"GRAPH_NODE_TYPE_OBJECT_PARENT = 0x029\n"
"GRAPH_NODE_TYPE_GENERATED_LIST = (0x02A | GRAPH_NODE_TYPE_FUNCTIONAL)\n"
"GRAPH_NODE_TYPE_BACKGROUND = (0x02C | GRAPH_NODE_TYPE_FUNCTIONAL)\n"
"GRAPH_NODE_TYPE_HELD_OBJ = (0x02E | GRAPH_NODE_TYPE_FUNCTIONAL)\n"
"GRAPH_NODE_TYPE_CULLING_RADIUS = 0x02F\n"
"GFX_NUM_MASTER_LISTS = 8\n"
"GEO_CONTEXT_CREATE = 0\n"
"GEO_CONTEXT_RENDER = 1\n"
"GEO_CONTEXT_AREA_UNLOAD = 2\n"
"GEO_CONTEXT_AREA_LOAD = 3\n"
"GEO_CONTEXT_AREA_INIT = 4\n"
"GEO_CONTEXT_HELD_OBJ = 5\n"
"INT_GROUND_POUND_OR_TWIRL = (1 << 0)\n"
"INT_PUNCH = (1 << 1)\n"
"INT_KICK = (1 << 2)\n"
@ -1727,6 +1766,23 @@ char gSmluaConstants[] = ""
"HELD_HELD = 1\n"
"HELD_THROWN = 2\n"
"HELD_DROPPED = 3\n"
"OBJ_MOVE_LANDED = (1 << 0)\n"
"OBJ_MOVE_ON_GROUND = (1 << 1)\n"
"OBJ_MOVE_LEFT_GROUND = (1 << 2)\n"
"OBJ_MOVE_ENTERED_WATER = (1 << 3)\n"
"OBJ_MOVE_AT_WATER_SURFACE = (1 << 4)\n"
"OBJ_MOVE_UNDERWATER_OFF_GROUND = (1 << 5)\n"
"OBJ_MOVE_UNDERWATER_ON_GROUND = (1 << 6)\n"
"OBJ_MOVE_IN_AIR = (1 << 7)\n"
"OBJ_MOVE_OUT_SCOPE = (1 << 8)\n"
"OBJ_MOVE_HIT_WALL = (1 << 9)\n"
"OBJ_MOVE_HIT_EDGE = (1 << 10)\n"
"OBJ_MOVE_ABOVE_LAVA = (1 << 11)\n"
"OBJ_MOVE_LEAVING_WATER = (1 << 12)\n"
"OBJ_MOVE_BOUNCE = (1 << 13)\n"
"OBJ_MOVE_ABOVE_DEATH_BARRIER = (1 << 14)\n"
"OBJ_MOVE_MASK_ON_GROUND = (OBJ_MOVE_LANDED | OBJ_MOVE_ON_GROUND)\n"
"OBJ_MOVE_MASK_IN_WATER = ( OBJ_MOVE_ENTERED_WATER | OBJ_MOVE_AT_WATER_SURFACE | OBJ_MOVE_UNDERWATER_OFF_GROUND | OBJ_MOVE_UNDERWATER_ON_GROUND)\n"
"ACTIVE_PARTICLE_DUST = (1 << 0)\n"
"ACTIVE_PARTICLE_UNUSED_1 = (1 << 1)\n"
"ACTIVE_PARTICLE_UNUSED_2 = (1 << 2)\n"
@ -1747,6 +1803,28 @@ char gSmluaConstants[] = ""
"ACTIVE_PARTICLE_BREATH = (1 << 17)\n"
"ACTIVE_PARTICLE_V_STAR = (1 << 18)\n"
"ACTIVE_PARTICLE_TRIANGLE = (1 << 19)\n"
"TIME_STOP_UNKNOWN_0 = (1 << 0)\n"
"TIME_STOP_ENABLED = (1 << 1)\n"
"TIME_STOP_DIALOG = (1 << 2)\n"
"TIME_STOP_MARIO_AND_DOORS = (1 << 3)\n"
"TIME_STOP_ALL_OBJECTS = (1 << 4)\n"
"TIME_STOP_MARIO_OPENED_DOOR = (1 << 5)\n"
"TIME_STOP_ACTIVE = (1 << 6)\n"
"OBJECT_POOL_CAPACITY = 960\n"
"OBJ_LIST_PLAYER = 0\n"
"OBJ_LIST_UNUSED_1 = 1\n"
"OBJ_LIST_DESTRUCTIVE = 2\n"
"OBJ_LIST_UNUSED_3 = 3\n"
"OBJ_LIST_GENACTOR = 4\n"
"OBJ_LIST_PUSHABLE = 5\n"
"OBJ_LIST_LEVEL = 6\n"
"OBJ_LIST_UNUSED_7 = 7\n"
"OBJ_LIST_DEFAULT = 8\n"
"OBJ_LIST_SURFACE = 9\n"
"OBJ_LIST_POLELIKE = 10\n"
"OBJ_LIST_SPAWNER = 11\n"
"OBJ_LIST_UNIMPORTANT = 12\n"
"NUM_OBJ_LISTS = 13\n"
"CONT_NO_RESPONSE_ERROR = 0x8\n"
"CONT_OVERRUN_ERROR = 0x4\n"
"CONT_FRAME_ERROR = 0x2\n"

File diff suppressed because it is too large Load Diff

View File

@ -1,7 +1,9 @@
#include "smlua.h"
#include "src/game/object_list_processor.h"
#include "pc/djui/djui_chat_message.h"
#define MAX_HOOKED_REFERENCES 64
#define LUA_BEHAVIOR_FLAG (1 << 15)
struct LuaHookedEvent {
int reference[MAX_HOOKED_REFERENCES];
@ -177,7 +179,7 @@ struct LuaHookedMarioAction {
int reference;
};
#define MAX_HOOKED_ACTIONS 64
#define MAX_HOOKED_ACTIONS 128
static struct LuaHookedMarioAction sHookedMarioActions[MAX_HOOKED_ACTIONS] = { 0 };
static int sHookedMarioActionsCount = 0;
@ -275,6 +277,148 @@ u32 smlua_get_action_interaction_type(struct MarioState* m) {
return interactionType;
}
//////////////////////
// hooked behaviors //
//////////////////////
struct LuaHookedBehavior {
u32 behaviorId;
BehaviorScript behavior[2];
int initReference;
int loopReference;
};
#define MAX_HOOKED_BEHAVIORS 256
static struct LuaHookedBehavior sHookedBehaviors[MAX_HOOKED_BEHAVIORS] = { 0 };
static int sHookedBehaviorsCount = 0;
const BehaviorScript* smlua_override_behavior(const BehaviorScript* behavior) {
enum BehaviorId id = get_id_from_behavior(behavior);
const BehaviorScript* luaBehavior = get_lua_behavior_from_id(id);
if (luaBehavior != NULL) { return luaBehavior; }
return behavior;
}
const BehaviorScript* get_lua_behavior_from_id(enum BehaviorId id) {
lua_State* L = gLuaState;
if (L == NULL) { return false; }
for (int i = 0; i < sHookedBehaviorsCount; i++) {
struct LuaHookedBehavior* hooked = &sHookedBehaviors[i];
if (hooked->behaviorId != id) { continue; }
return hooked->behavior;
}
return NULL;
}
int smlua_hook_behavior(lua_State* L) {
if (L == NULL) { return 0; }
if (!smlua_functions_valid_param_count(L, 4)) { return 0; }
if (sHookedBehaviorsCount >= MAX_HOOKED_BEHAVIORS) {
LOG_LUA("Hooked behaviors exceeded maximum references!");
smlua_logline();
return 0;
}
lua_Integer overrideBehaviorId = smlua_to_integer(L, 1);
if (!gSmLuaConvertSuccess) {
LOG_LUA("Hook behavior: tried to override invalid behavior: %lld, %u", overrideBehaviorId, gSmLuaConvertSuccess);
smlua_logline();
return 0;
}
lua_Integer objectList = smlua_to_integer(L, 2);
if (objectList <= 0 || objectList >= NUM_OBJ_LISTS || !gSmLuaConvertSuccess) {
LOG_LUA("Hook behavior: tried use invalid object list: %lld, %u", objectList, gSmLuaConvertSuccess);
smlua_logline();
return 0;
}
int initReference = 0;
int initReferenceType = lua_type(L, 3);
if (initReferenceType == LUA_TNIL) {
// nothing
} else if (initReferenceType == LUA_TFUNCTION) {
// get reference
lua_pushvalue(L, 3);
initReference = luaL_ref(L, LUA_REGISTRYINDEX);
} else {
LOG_LUA("Hook behavior: tried to reference non-function for init");
smlua_logline();
return 0;
}
int loopReference = 0;
int loopReferenceType = lua_type(L, 4);
if (loopReferenceType == LUA_TNIL) {
// nothing
} else if (loopReferenceType == LUA_TFUNCTION) {
// get reference
lua_pushvalue(L, 4);
loopReference = luaL_ref(L, LUA_REGISTRYINDEX);
} else {
LOG_LUA("Hook behavior: tried to reference non-function for loop");
smlua_logline();
return 0;
}
struct LuaHookedBehavior* hooked = &sHookedBehaviors[sHookedBehaviorsCount];
u16 customBehaviorId = (sHookedBehaviorsCount & 0xFFFF) | LUA_BEHAVIOR_FLAG;
hooked->behaviorId = overrideBehaviorId != 0 ? overrideBehaviorId : customBehaviorId;
hooked->behavior[0] = (((unsigned int) (((unsigned int)(0x00) & ((0x01 << (8)) - 1)) << (24))) | ((unsigned int) (((unsigned int)(objectList) & ((0x01 << (8)) - 1)) << (16)))); // gross. this is BEGIN(objectList)
hooked->behavior[1] = (((unsigned int) (((unsigned int)(0x39) & ((0x01 << (8)) - 1)) << (24))) | ((unsigned int) (((unsigned int)(customBehaviorId) & ((0x01 << (16)) - 1)) << (0)))); // gross. this is ID(customBehaviorId)
hooked->initReference = initReference;
hooked->loopReference = loopReference;
sHookedBehaviorsCount++;
// return behavior ID
lua_pushinteger(L, customBehaviorId);
return 1;
}
bool smlua_call_behavior_hook(const BehaviorScript** behavior, struct Object* object) {
lua_State* L = gLuaState;
if (L == NULL) { return false; }
for (int i = 0; i < sHookedBehaviorsCount; i++) {
struct LuaHookedBehavior* hooked = &sHookedBehaviors[i];
// find behavior
if (object->behavior != hooked->behavior) {
continue;
}
// retrieve and remember first run
bool firstRun = (*behavior == hooked->behavior);
if (firstRun) { *behavior = &hooked->behavior[1]; }
// get function and null check it
int reference = firstRun ? hooked->initReference : hooked->loopReference;
if (reference == 0) {
return true;
}
// push the callback onto the stack
lua_rawgeti(L, LUA_REGISTRYINDEX, reference);
// push object
smlua_push_object(L, LOT_OBJECT, object);
// call the callback
if (0 != lua_pcall(L, 1, 0, 0)) {
LOG_LUA("Failed to call the behavior callback: %u, %s", hooked->behaviorId, lua_tostring(L, -1));
smlua_logline();
return true;
}
return true;
}
return false;
}
/////////////////////////
// hooked chat command //
/////////////////////////
@ -473,6 +617,16 @@ static void smlua_clear_hooks(void) {
sHookedChatCommands[i].reference = 0;
}
sHookedChatCommandsCount = 0;
for (int i = 0; i < sHookedBehaviorsCount; i++) {
struct LuaHookedBehavior* hooked = &sHookedBehaviors[i];
hooked->behaviorId = 0;
hooked->behavior[0] = 0;
hooked->behavior[1] = 0;
hooked->initReference = 0;
hooked->loopReference = 0;
}
sHookedBehaviorsCount = 0;
}
void smlua_bind_hooks(void) {
@ -483,4 +637,5 @@ void smlua_bind_hooks(void) {
smlua_bind_function(L, "hook_mario_action", smlua_hook_mario_action);
smlua_bind_function(L, "hook_chat_command", smlua_hook_chat_command);
smlua_bind_function(L, "hook_on_sync_table_change", smlua_hook_on_sync_table_change);
smlua_bind_function(L, "hook_behavior", smlua_hook_behavior);
}

View File

@ -2,6 +2,7 @@
#define SMLUA_HOOKS_H
#include <stdbool.h>
#include "include/behavior_table.h"
enum LuaHookedEventType {
HOOK_UPDATE,
@ -36,6 +37,10 @@ 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_interact_params(enum LuaHookedEventType hookType, struct MarioState* m, struct Object* obj, u32 interactType, bool interactValue);
const BehaviorScript* smlua_override_behavior(const BehaviorScript* behavior);
const BehaviorScript* get_lua_behavior_from_id(enum BehaviorId id);
bool smlua_call_behavior_hook(const BehaviorScript** behavior, struct Object* object);
bool smlua_call_action_hook(struct MarioState* m, s32* returnValue);
u32 smlua_get_action_interaction_type(struct MarioState* m);