Add object animations to Lua, add CPointer allowlist

This commit is contained in:
MysterD 2022-03-03 18:31:45 -08:00
parent 3ad6c721dc
commit 3bc80ad7be
13 changed files with 1213 additions and 836 deletions

View file

@ -2,7 +2,7 @@ import os
usf_types = ['u8', 'u16', 'u32', 'u64', 's8', 's16', 's32', 's64', 'f32']
vec3_types = ['Vec3s', 'Vec3f']
typedef_pointers = ['BehaviorScript']
typedef_pointers = ['BehaviorScript', 'ObjectAnimPointer']
exclude_structs = [
'SPTask',

View file

@ -14,7 +14,8 @@ in_files = [
'src/pc/network/network_player.h',
'src/pc/djui/djui_hud_utils.h',
'src/game/object_helpers.h',
'src/game/mario_step.h'
'src/game/mario_step.h',
'src/pc/lua/smlua_anim_utils.h',
]
smlua_cobject_autogen = 'src/pc/lua/smlua_cobject_autogen'
@ -55,6 +56,7 @@ override_field_names = {
override_field_types = {
"Surface": { "normal": "Vec3f" },
"Object": { "oAnimations": "ObjectAnimPointer*"}
}
override_field_immutable = {
@ -63,6 +65,7 @@ override_field_immutable = {
"NetworkPlayer": [ "*" ],
"TextureInfo": [ "*" ],
"Object": ["oSyncID", "createdThroughNetwork"],
"GlobalObjectAnimations": [ "*"],
}
sLuaManuallyDefinedStructs = [

View file

@ -16,6 +16,7 @@
- [CutsceneSplinePoint](#CutsceneSplinePoint)
- [CutsceneVariable](#CutsceneVariable)
- [FloorGeometry](#FloorGeometry)
- [GlobalObjectAnimations](#GlobalObjectAnimations)
- [GlobalTextures](#GlobalTextures)
- [GraphNode](#GraphNode)
- [GraphNodeObject](#GraphNodeObject)
@ -354,6 +355,68 @@
<br />
## [GlobalObjectAnimations](#GlobalObjectAnimations)
| Field | Type | Access |
| ----- | ---- | ------ |
| amp_seg8_anims_08004034 | Pointer <ObjectAnimPointer> | read-only |
| birds_seg5_anims_050009E8 | Pointer <ObjectAnimPointer> | read-only |
| blue_fish_seg3_anims_0301C2B0 | Pointer <ObjectAnimPointer> | read-only |
| bobomb_seg8_anims_0802396C | Pointer <ObjectAnimPointer> | read-only |
| bookend_seg5_anims_05002540 | Pointer <ObjectAnimPointer> | read-only |
| bowser_key_seg3_anims_list | Pointer <ObjectAnimPointer> | read-only |
| bowser_seg6_anims_06057690 | Pointer <ObjectAnimPointer> | read-only |
| bub_seg6_anims_06012354 | Pointer <ObjectAnimPointer> | read-only |
| bully_seg5_anims_0500470C | Pointer <ObjectAnimPointer> | read-only |
| butterfly_seg3_anims_030056B0 | Pointer <ObjectAnimPointer> | read-only |
| castle_grounds_seg7_anims_flags | Pointer <ObjectAnimPointer> | read-only |
| chain_chomp_seg6_anims_06025178 | Pointer <ObjectAnimPointer> | read-only |
| chair_seg5_anims_05005784 | Pointer <ObjectAnimPointer> | read-only |
| chilly_chief_seg6_anims_06003994 | Pointer <ObjectAnimPointer> | read-only |
| chuckya_seg8_anims_0800C070 | Pointer <ObjectAnimPointer> | read-only |
| clam_shell_seg5_anims_05001744 | Pointer <ObjectAnimPointer> | read-only |
| door_seg3_anims_030156C0 | Pointer <ObjectAnimPointer> | read-only |
| dorrie_seg6_anims_0600F638 | Pointer <ObjectAnimPointer> | read-only |
| eyerok_seg5_anims_050116E4 | Pointer <ObjectAnimPointer> | read-only |
| flyguy_seg8_anims_08011A64 | Pointer <ObjectAnimPointer> | read-only |
| goomba_seg8_anims_0801DA4C | Pointer <ObjectAnimPointer> | read-only |
| heave_ho_seg5_anims_0501534C | Pointer <ObjectAnimPointer> | read-only |
| hoot_seg5_anims_05005768 | Pointer <ObjectAnimPointer> | read-only |
| king_bobomb_seg5_anims_0500FE30 | Pointer <ObjectAnimPointer> | read-only |
| klepto_seg5_anims_05008CFC | Pointer <ObjectAnimPointer> | read-only |
| koopa_flag_seg6_anims_06001028 | Pointer <ObjectAnimPointer> | read-only |
| koopa_seg6_anims_06011364 | Pointer <ObjectAnimPointer> | read-only |
| lakitu_enemy_seg5_anims_050144D4 | Pointer <ObjectAnimPointer> | read-only |
| lakitu_seg6_anims_060058F8 | Pointer <ObjectAnimPointer> | read-only |
| mad_piano_seg5_anims_05009B14 | Pointer <ObjectAnimPointer> | read-only |
| manta_seg5_anims_05008EB4 | Pointer <ObjectAnimPointer> | read-only |
| mips_seg6_anims_06015634 | Pointer <ObjectAnimPointer> | read-only |
| moneybag_seg6_anims_06005E5C | Pointer <ObjectAnimPointer> | read-only |
| monty_mole_seg5_anims_05007248 | Pointer <ObjectAnimPointer> | read-only |
| peach_seg5_anims_0501C41C | Pointer <ObjectAnimPointer> | read-only |
| penguin_seg5_anims_05008B74 | Pointer <ObjectAnimPointer> | read-only |
| piranha_plant_seg6_anims_0601C31C | Pointer <ObjectAnimPointer> | read-only |
| scuttlebug_seg6_anims_06015064 | Pointer <ObjectAnimPointer> | read-only |
| seaweed_seg6_anims_0600A4D4 | Pointer <ObjectAnimPointer> | read-only |
| skeeter_seg6_anims_06007DE0 | Pointer <ObjectAnimPointer> | read-only |
| snowman_seg5_anims_0500D118 | Pointer <ObjectAnimPointer> | read-only |
| spindrift_seg5_anims_05002D68 | Pointer <ObjectAnimPointer> | read-only |
| spiny_seg5_anims_05016EAC | Pointer <ObjectAnimPointer> | read-only |
| sushi_seg5_anims_0500AE54 | Pointer <ObjectAnimPointer> | read-only |
| swoop_seg6_anims_060070D0 | Pointer <ObjectAnimPointer> | read-only |
| toad_seg6_anims_0600FB58 | Pointer <ObjectAnimPointer> | read-only |
| ukiki_seg5_anims_05015784 | Pointer <ObjectAnimPointer> | read-only |
| unagi_seg5_anims_05012824 | Pointer <ObjectAnimPointer> | read-only |
| water_ring_seg6_anims_06013F7C | Pointer <ObjectAnimPointer> | read-only |
| whomp_seg6_anims_06020A04 | Pointer <ObjectAnimPointer> | read-only |
| wiggler_seg5_anims_0500C874 | Pointer <ObjectAnimPointer> | read-only |
| wiggler_seg5_anims_0500EC8C | Pointer <ObjectAnimPointer> | read-only |
| yoshi_seg5_anims_05024100 | Pointer <ObjectAnimPointer> | read-only |
[:arrow_up_small:](#)
<br />
## [GlobalTextures](#GlobalTextures)
| Field | Type | Access |
@ -733,6 +796,7 @@
| oAngleVelPitch | integer | |
| oAngleVelYaw | integer | |
| oAngleVelRoll | integer | |
| oAnimations | Pointer <ObjectAnimPointer> | |
| oHeldState | integer | |
| oWallHitboxRadius | number | |
| oDragStrength | number | |

View file

@ -61,6 +61,7 @@ static void smlua_load_script(char* path, u16 remoteIndex) {
void smlua_init(void) {
smlua_shutdown();
smlua_cobject_allowlist_init();
smlua_cpointer_allowlist_init();
gLuaState = luaL_newstate();
lua_State* L = gLuaState;
@ -108,6 +109,7 @@ void smlua_update(void) {
void smlua_shutdown(void) {
smlua_cobject_allowlist_shutdown();
smlua_cpointer_allowlist_shutdown();
lua_State* L = gLuaState;
if (L != NULL) {
lua_close(L);

View file

@ -0,0 +1,86 @@
#include "types.h"
#include "smlua.h"
#include "smlua_anim_utils.h"
#include "pc/debuglog.h"
// models
#include "actors/common0.h"
#include "actors/common1.h"
#include "actors/custom0.h"
#include "actors/group0.h"
#include "actors/group1.h"
#include "actors/group2.h"
#include "actors/group3.h"
#include "actors/group4.h"
#include "actors/group5.h"
#include "actors/group6.h"
#include "actors/group7.h"
#include "actors/group8.h"
#include "actors/group9.h"
#include "actors/group10.h"
#include "actors/group11.h"
#include "actors/group12.h"
#include "actors/group13.h"
#include "actors/group14.h"
#include "actors/group15.h"
#include "actors/group16.h"
#include "actors/group17.h"
#include "actors/zcustom0.h"
#include "levels/castle_grounds/header.h"
struct GlobalObjectAnimations gGlobalObjectAnimations = {
.amp_seg8_anims_08004034 = (struct Animation**) amp_seg8_anims_08004034,
.birds_seg5_anims_050009E8 = (struct Animation**) birds_seg5_anims_050009E8,
.blue_fish_seg3_anims_0301C2B0 = (struct Animation**) blue_fish_seg3_anims_0301C2B0,
.bobomb_seg8_anims_0802396C = (struct Animation**) bobomb_seg8_anims_0802396C,
.bookend_seg5_anims_05002540 = (struct Animation**) bookend_seg5_anims_05002540,
.bowser_key_seg3_anims_list = (struct Animation**) bowser_key_seg3_anims_list,
.bowser_seg6_anims_06057690 = (struct Animation**) bowser_seg6_anims_06057690,
.bub_seg6_anims_06012354 = (struct Animation**) bub_seg6_anims_06012354,
.bully_seg5_anims_0500470C = (struct Animation**) bully_seg5_anims_0500470C,
.butterfly_seg3_anims_030056B0 = (struct Animation**) butterfly_seg3_anims_030056B0,
.castle_grounds_seg7_anims_flags = (struct Animation**) castle_grounds_seg7_anims_flags,
.chain_chomp_seg6_anims_06025178 = (struct Animation**) chain_chomp_seg6_anims_06025178,
.chair_seg5_anims_05005784 = (struct Animation**) chair_seg5_anims_05005784,
.chilly_chief_seg6_anims_06003994 = (struct Animation**) chilly_chief_seg6_anims_06003994,
.chuckya_seg8_anims_0800C070 = (struct Animation**) chuckya_seg8_anims_0800C070,
.clam_shell_seg5_anims_05001744 = (struct Animation**) clam_shell_seg5_anims_05001744,
.door_seg3_anims_030156C0 = (struct Animation**) door_seg3_anims_030156C0,
.dorrie_seg6_anims_0600F638 = (struct Animation**) dorrie_seg6_anims_0600F638,
.eyerok_seg5_anims_050116E4 = (struct Animation**) eyerok_seg5_anims_050116E4,
.flyguy_seg8_anims_08011A64 = (struct Animation**) flyguy_seg8_anims_08011A64,
.goomba_seg8_anims_0801DA4C = (struct Animation**) goomba_seg8_anims_0801DA4C,
.heave_ho_seg5_anims_0501534C = (struct Animation**) heave_ho_seg5_anims_0501534C,
.hoot_seg5_anims_05005768 = (struct Animation**) hoot_seg5_anims_05005768,
.king_bobomb_seg5_anims_0500FE30 = (struct Animation**) king_bobomb_seg5_anims_0500FE30,
.klepto_seg5_anims_05008CFC = (struct Animation**) klepto_seg5_anims_05008CFC,
.koopa_flag_seg6_anims_06001028 = (struct Animation**) koopa_flag_seg6_anims_06001028,
.koopa_seg6_anims_06011364 = (struct Animation**) koopa_seg6_anims_06011364,
.lakitu_enemy_seg5_anims_050144D4 = (struct Animation**) lakitu_enemy_seg5_anims_050144D4,
.lakitu_seg6_anims_060058F8 = (struct Animation**) lakitu_seg6_anims_060058F8,
.mad_piano_seg5_anims_05009B14 = (struct Animation**) mad_piano_seg5_anims_05009B14,
.manta_seg5_anims_05008EB4 = (struct Animation**) manta_seg5_anims_05008EB4,
.mips_seg6_anims_06015634 = (struct Animation**) mips_seg6_anims_06015634,
.moneybag_seg6_anims_06005E5C = (struct Animation**) moneybag_seg6_anims_06005E5C,
.monty_mole_seg5_anims_05007248 = (struct Animation**) monty_mole_seg5_anims_05007248,
.peach_seg5_anims_0501C41C = (struct Animation**) peach_seg5_anims_0501C41C,
.penguin_seg5_anims_05008B74 = (struct Animation**) penguin_seg5_anims_05008B74,
.piranha_plant_seg6_anims_0601C31C= (struct Animation**) piranha_plant_seg6_anims_0601C31C,
.scuttlebug_seg6_anims_06015064 = (struct Animation**) scuttlebug_seg6_anims_06015064,
.seaweed_seg6_anims_0600A4D4 = (struct Animation**) seaweed_seg6_anims_0600A4D4,
.skeeter_seg6_anims_06007DE0 = (struct Animation**) skeeter_seg6_anims_06007DE0,
.snowman_seg5_anims_0500D118 = (struct Animation**) snowman_seg5_anims_0500D118,
.spindrift_seg5_anims_05002D68 = (struct Animation**) spindrift_seg5_anims_05002D68,
.spiny_seg5_anims_05016EAC = (struct Animation**) spiny_seg5_anims_05016EAC,
.sushi_seg5_anims_0500AE54 = (struct Animation**) sushi_seg5_anims_0500AE54,
.swoop_seg6_anims_060070D0 = (struct Animation**) swoop_seg6_anims_060070D0,
.toad_seg6_anims_0600FB58 = (struct Animation**) toad_seg6_anims_0600FB58,
.ukiki_seg5_anims_05015784 = (struct Animation**) ukiki_seg5_anims_05015784,
.unagi_seg5_anims_05012824 = (struct Animation**) unagi_seg5_anims_05012824,
.water_ring_seg6_anims_06013F7C = (struct Animation**) water_ring_seg6_anims_06013F7C,
.whomp_seg6_anims_06020A04 = (struct Animation**) whomp_seg6_anims_06020A04,
.wiggler_seg5_anims_0500C874 = (struct Animation**) wiggler_seg5_anims_0500C874,
.wiggler_seg5_anims_0500EC8C = (struct Animation**) wiggler_seg5_anims_0500EC8C,
.yoshi_seg5_anims_05024100 = (struct Animation**) yoshi_seg5_anims_05024100,
};

View file

@ -0,0 +1,63 @@
#ifndef SMLUA_ANIM_UTILS_H
#define SMLUA_ANIM_UTILS_H
typedef struct Animation* ObjectAnimPointer;
struct GlobalObjectAnimations {
ObjectAnimPointer* amp_seg8_anims_08004034;
ObjectAnimPointer* birds_seg5_anims_050009E8;
ObjectAnimPointer* blue_fish_seg3_anims_0301C2B0;
ObjectAnimPointer* bobomb_seg8_anims_0802396C;
ObjectAnimPointer* bookend_seg5_anims_05002540;
ObjectAnimPointer* bowser_key_seg3_anims_list;
ObjectAnimPointer* bowser_seg6_anims_06057690;
ObjectAnimPointer* bub_seg6_anims_06012354;
ObjectAnimPointer* bully_seg5_anims_0500470C;
ObjectAnimPointer* butterfly_seg3_anims_030056B0;
ObjectAnimPointer* castle_grounds_seg7_anims_flags;
ObjectAnimPointer* chain_chomp_seg6_anims_06025178;
ObjectAnimPointer* chair_seg5_anims_05005784;
ObjectAnimPointer* chilly_chief_seg6_anims_06003994;
ObjectAnimPointer* chuckya_seg8_anims_0800C070;
ObjectAnimPointer* clam_shell_seg5_anims_05001744;
ObjectAnimPointer* door_seg3_anims_030156C0;
ObjectAnimPointer* dorrie_seg6_anims_0600F638;
ObjectAnimPointer* eyerok_seg5_anims_050116E4;
ObjectAnimPointer* flyguy_seg8_anims_08011A64;
ObjectAnimPointer* goomba_seg8_anims_0801DA4C;
ObjectAnimPointer* heave_ho_seg5_anims_0501534C;
ObjectAnimPointer* hoot_seg5_anims_05005768;
ObjectAnimPointer* king_bobomb_seg5_anims_0500FE30;
ObjectAnimPointer* klepto_seg5_anims_05008CFC;
ObjectAnimPointer* koopa_flag_seg6_anims_06001028;
ObjectAnimPointer* koopa_seg6_anims_06011364;
ObjectAnimPointer* lakitu_enemy_seg5_anims_050144D4;
ObjectAnimPointer* lakitu_seg6_anims_060058F8;
ObjectAnimPointer* mad_piano_seg5_anims_05009B14;
ObjectAnimPointer* manta_seg5_anims_05008EB4;
ObjectAnimPointer* mips_seg6_anims_06015634;
ObjectAnimPointer* moneybag_seg6_anims_06005E5C;
ObjectAnimPointer* monty_mole_seg5_anims_05007248;
ObjectAnimPointer* peach_seg5_anims_0501C41C;
ObjectAnimPointer* penguin_seg5_anims_05008B74;
ObjectAnimPointer* piranha_plant_seg6_anims_0601C31C;
ObjectAnimPointer* scuttlebug_seg6_anims_06015064;
ObjectAnimPointer* seaweed_seg6_anims_0600A4D4;
ObjectAnimPointer* skeeter_seg6_anims_06007DE0;
ObjectAnimPointer* snowman_seg5_anims_0500D118;
ObjectAnimPointer* spindrift_seg5_anims_05002D68;
ObjectAnimPointer* spiny_seg5_anims_05016EAC;
ObjectAnimPointer* sushi_seg5_anims_0500AE54;
ObjectAnimPointer* swoop_seg6_anims_060070D0;
ObjectAnimPointer* toad_seg6_anims_0600FB58;
ObjectAnimPointer* ukiki_seg5_anims_05015784;
ObjectAnimPointer* unagi_seg5_anims_05012824;
ObjectAnimPointer* water_ring_seg6_anims_06013F7C;
ObjectAnimPointer* whomp_seg6_anims_06020A04;
ObjectAnimPointer* wiggler_seg5_anims_0500C874;
ObjectAnimPointer* wiggler_seg5_anims_0500EC8C;
ObjectAnimPointer* yoshi_seg5_anims_05024100;
};
extern struct GlobalObjectAnimations gGlobalObjectAnimations;
#endif

View file

@ -6,6 +6,7 @@
#include "audio/external.h"
#include "object_fields.h"
#include "pc/djui/djui_hud_utils.h"
#include "pc/lua/smlua_anim_utils.h"
#define LUA_VEC3S_FIELD_COUNT 3
static struct LuaObjectField sVec3sFields[LUA_VEC3S_FIELD_COUNT] = {
@ -64,6 +65,10 @@ bool smlua_valid_lot(u16 lot) {
return false;
}
bool smlua_valid_lvt(u16 lvt) {
return (lvt < LVT_MAX);
}
static int smlua__get_field(lua_State* L) {
if (!smlua_functions_valid_param_count(L, 3)) { return 0; }
@ -116,6 +121,7 @@ static int smlua__get_field(lua_State* L) {
case LVT_STRING: lua_pushstring(L, (char*)p); break;
case LVT_STRING_P: lua_pushstring(L, *(char**)p); break;
case LVT_BEHAVIORSCRIPT: lua_pushinteger(L, *(s32*)p); break;
case LVT_OBJECTANIMPOINTER: lua_pushinteger(L, *(s32*)p); break;
// pointers
case LVT_U8_P:
@ -126,6 +132,7 @@ static int smlua__get_field(lua_State* L) {
case LVT_S32_P:
case LVT_F32_P:
case LVT_BEHAVIORSCRIPT_P:
case LVT_OBJECTANIMPOINTER_P:
smlua_push_pointer(L, data->valueType, *(u8**)p);
break;
@ -200,6 +207,22 @@ static int smlua__set_field(lua_State* L) {
}
break;
// pointers
case LVT_U8_P:
case LVT_U16_P:
case LVT_U32_P:
case LVT_S8_P:
case LVT_S16_P:
case LVT_S32_P:
case LVT_F32_P:
case LVT_BEHAVIORSCRIPT_P:
case LVT_OBJECTANIMPOINTER_P:
valuePointer = smlua_to_cpointer(L, -1, data->valueType);
if (gSmLuaConvertSuccess) {
*(u8**)p = valuePointer;
}
break;
default:
LOG_LUA("_set_field on unimplemented type '%d', key '%s'", data->valueType, key);
smlua_logline();
@ -255,6 +278,11 @@ void smlua_cobject_init_globals(void) {
lua_setglobal(L, "gTextures");
}
{
smlua_push_object(L, LOT_GLOBALOBJECTANIMATIONS, &gGlobalObjectAnimations);
lua_setglobal(L, "gObjectAnimations");
}
}
void smlua_bind_cobject(void) {

View file

@ -23,8 +23,11 @@ enum LuaValueType {
LVT_STRING_P,
LVT_BEHAVIORSCRIPT,
LVT_BEHAVIORSCRIPT_P,
LVT_OBJECTANIMPOINTER,
LVT_OBJECTANIMPOINTER_P,
LVT_LUAFUNCTION,
LVT_POINTER,
LVT_MAX,
};
enum LuaObjectType {
@ -50,6 +53,7 @@ struct LuaObjectTable {
};
bool smlua_valid_lot(u16 lot);
bool smlua_valid_lvt(u16 lvt);
void smlua_cobject_init_globals(void);
void smlua_bind_cobject(void);

View file

@ -1,14 +1,14 @@
#include <stdio.h>
#include "smlua.h"
struct CObjectAllowListNode {
struct CAllowListNode {
u64 pointer;
struct CObjectAllowListNode* next;
struct CAllowListNode* next;
};
#define LOT_COUNT (LOT_MAX + (LOT_AUTOGEN_MAX - LOT_AUTOGEN_MIN))
static struct CObjectAllowListNode* sAllowList[LOT_COUNT] = { 0 };
static u16 sCachedAllowed[LOT_COUNT] = { 0 };
static struct CAllowListNode* sObjectAllowList[LOT_COUNT] = { 0 };
static u16 sCachedObjectAllowed[LOT_COUNT] = { 0 };
static u16 smlua_lot_mapping(u16 lot) {
if (lot >= LOT_MAX) {
@ -24,14 +24,14 @@ void smlua_cobject_allowlist_init(void) {
void smlua_cobject_allowlist_shutdown(void) {
for (int i = 0; i < LOT_COUNT; i++) {
sCachedAllowed[i] = 0;
struct CObjectAllowListNode* node = sAllowList[i];
sCachedObjectAllowed[i] = 0;
struct CAllowListNode* node = sObjectAllowList[i];
while (node != NULL) {
struct CObjectAllowListNode* nextNode = node->next;
struct CAllowListNode* nextNode = node->next;
free(node);
node = nextNode;
}
sAllowList[i] = NULL;
sObjectAllowList[i] = NULL;
}
}
@ -40,11 +40,11 @@ void smlua_cobject_allowlist_add(u16 lot, u64 pointer) {
if (!smlua_valid_lot(lot)) { return; }
u16 m = smlua_lot_mapping(lot);
if (sCachedAllowed[m] == pointer) { return; }
sCachedAllowed[m] = pointer;
if (sCachedObjectAllowed[m] == pointer) { return; }
sCachedObjectAllowed[m] = pointer;
struct CObjectAllowListNode* curNode = sAllowList[m];
struct CObjectAllowListNode* prevNode = NULL;
struct CAllowListNode* curNode = sObjectAllowList[m];
struct CAllowListNode* prevNode = NULL;
while (curNode != NULL) {
if (pointer == curNode->pointer) { return; }
if (pointer < curNode->pointer) { break; }
@ -52,11 +52,11 @@ void smlua_cobject_allowlist_add(u16 lot, u64 pointer) {
curNode = curNode->next;
}
struct CObjectAllowListNode* node = malloc(sizeof(struct CObjectAllowListNode));
struct CAllowListNode* node = malloc(sizeof(struct CAllowListNode));
node->pointer = pointer;
node->next = curNode;
if (prevNode == NULL) {
sAllowList[m] = node;
sObjectAllowList[m] = node;
} else {
prevNode->next = node;
}
@ -67,9 +67,72 @@ bool smlua_cobject_allowlist_contains(u16 lot, u64 pointer) {
if (!smlua_valid_lot(lot)) { return false; }
u16 m = smlua_lot_mapping(lot);
if (sCachedAllowed[m] == pointer) { return true; }
if (sCachedObjectAllowed[m] == pointer) { return true; }
struct CObjectAllowListNode* node = sAllowList[m];
struct CAllowListNode* node = sObjectAllowList[m];
while (node != NULL) {
if (pointer == node->pointer) { return true; }
if (pointer < node->pointer) { return false; }
node = node->next;
}
return false;
}
/////////////////////////////
static struct CAllowListNode* sPointerAllowList[LVT_MAX] = { 0 };
static u16 sCachedPointerAllowed[LVT_MAX] = { 0 };
void smlua_cpointer_allowlist_init(void) {
smlua_cpointer_allowlist_shutdown();
}
void smlua_cpointer_allowlist_shutdown(void) {
for (int i = 0; i < LVT_MAX; i++) {
sCachedPointerAllowed[i] = 0;
struct CAllowListNode* node = sPointerAllowList[i];
while (node != NULL) {
struct CAllowListNode* nextNode = node->next;
free(node);
node = nextNode;
}
sPointerAllowList[i] = NULL;
}
}
void smlua_cpointer_allowlist_add(u16 lvt, u64 pointer) {
if (pointer == 0) { return; }
if (!smlua_valid_lvt(lvt)) { return; }
if (sCachedPointerAllowed[lvt] == pointer) { return; }
sCachedPointerAllowed[lvt] = pointer;
struct CAllowListNode* curNode = sPointerAllowList[lvt];
struct CAllowListNode* prevNode = NULL;
while (curNode != NULL) {
if (pointer == curNode->pointer) { return; }
if (pointer < curNode->pointer) { break; }
prevNode = curNode;
curNode = curNode->next;
}
struct CAllowListNode* node = malloc(sizeof(struct CAllowListNode));
node->pointer = pointer;
node->next = curNode;
if (prevNode == NULL) {
sPointerAllowList[lvt] = node;
} else {
prevNode->next = node;
}
}
bool smlua_cpointer_allowlist_contains(u16 lvt, u64 pointer) {
if (pointer == 0) { return false; }
if (!smlua_valid_lvt(lvt)) { return false; }
if (sCachedPointerAllowed[lvt] == pointer) { return true; }
struct CAllowListNode* node = sPointerAllowList[lvt];
while (node != NULL) {
if (pointer == node->pointer) { return true; }
if (pointer < node->pointer) { return false; }

View file

@ -6,4 +6,9 @@ void smlua_cobject_allowlist_shutdown(void);
void smlua_cobject_allowlist_add(u16 lot, u64 pointer);
bool smlua_cobject_allowlist_contains(u16 lot, u64 pointer);
void smlua_cpointer_allowlist_init(void);
void smlua_cpointer_allowlist_shutdown(void);
void smlua_cpointer_allowlist_add(u16 lvt, u64 pointer);
bool smlua_cpointer_allowlist_contains(u16 lvt, u64 pointer);
#endif

File diff suppressed because it is too large Load diff

View file

@ -20,6 +20,7 @@ enum LuaObjectAutogenType {
LOT_CUTSCENESPLINEPOINT,
LOT_CUTSCENEVARIABLE,
LOT_FLOORGEOMETRY,
LOT_GLOBALOBJECTANIMATIONS,
LOT_GLOBALTEXTURES,
LOT_GRAPHNODE,
LOT_GRAPHNODEOBJECT,

View file

@ -175,12 +175,11 @@ void* smlua_to_cpointer(lua_State* L, int index, u16 lvt) {
lua_pop(L, 1);
if (!gSmLuaConvertSuccess) { return NULL; }
// TODO: check allowlist
/*if (!smlua_cobject_allowlist_contains(lot, (u64)(intptr_t)pointer)) {
LOG_LUA("smlua_to_cobject received a pointer not in allow list. '%u', '%llu", lot, (u64)(intptr_t)pointer);
if (!smlua_cpointer_allowlist_contains(lvt, (u64)(intptr_t)pointer)) {
LOG_LUA("smlua_to_cpointer received a pointer not in allow list. '%u', '%llu", lvt, (u64)(intptr_t)pointer);
gSmLuaConvertSuccess = false;
return NULL;
}*/
}
if (pointer == NULL) {
LOG_LUA("smlua_to_cpointer received null pointer.");
@ -275,8 +274,8 @@ void smlua_push_pointer(lua_State* L, u16 lvt, void* p) {
lua_pushnil(L);
return;
}
// TODO: add to allowlist
//smlua_cobject_allowlist_add(lot, (u64)(intptr_t)p);
smlua_cpointer_allowlist_add(lvt, (u64)(intptr_t)p);
lua_newtable(L);
int t = lua_gettop(L);