Separate ptrData from rawData on all platforms
This commit is contained in:
parent
6ab992446d
commit
c0b6590fcd
|
@ -25,17 +25,6 @@
|
|||
#define OBJECT_FIELD_S32(index) rawData.asS32[index]
|
||||
#define OBJECT_FIELD_S16(index, subIndex) rawData.asS16[index][subIndex]
|
||||
#define OBJECT_FIELD_F32(index) rawData.asF32[index]
|
||||
#if !IS_64_BIT
|
||||
#define OBJECT_FIELD_S16P(index) rawData.asS16P[index]
|
||||
#define OBJECT_FIELD_S32P(index) rawData.asS32P[index]
|
||||
#define OBJECT_FIELD_ANIMS(index) rawData.asAnims[index]
|
||||
#define OBJECT_FIELD_WAYPOINT(index) rawData.asWaypoint[index]
|
||||
#define OBJECT_FIELD_CHAIN_SEGMENT(index) rawData.asChainSegment[index]
|
||||
#define OBJECT_FIELD_OBJ(index) rawData.asObject[index]
|
||||
#define OBJECT_FIELD_SURFACE(index) rawData.asSurface[index]
|
||||
#define OBJECT_FIELD_VPTR(index) rawData.asVoidPtr[index]
|
||||
#define OBJECT_FIELD_CVPTR(index) rawData.asConstVoidPtr[index]
|
||||
#else
|
||||
#define OBJECT_FIELD_S16P(index) ptrData.asS16P[index]
|
||||
#define OBJECT_FIELD_S32P(index) ptrData.asS32P[index]
|
||||
#define OBJECT_FIELD_ANIMS(index) ptrData.asAnims[index]
|
||||
|
@ -46,7 +35,6 @@
|
|||
#define OBJECT_FIELD_VPTR(index) ptrData.asVoidPtr[index]
|
||||
#define OBJECT_FIELD_CVPTR(index) ptrData.asConstVoidPtr[index]
|
||||
#endif
|
||||
#endif
|
||||
|
||||
// 0x088 (0x00), the first field, is object-specific and defined below the common fields.
|
||||
/* Common fields */
|
||||
|
|
|
@ -185,19 +185,7 @@ struct Object
|
|||
s32 asS32[0x50];
|
||||
s16 asS16[0x50][2];
|
||||
f32 asF32[0x50];
|
||||
#if !IS_64_BIT
|
||||
s16 *asS16P[0x50];
|
||||
s32 *asS32P[0x50];
|
||||
struct Animation **asAnims[0x50];
|
||||
struct Waypoint *asWaypoint[0x50];
|
||||
struct ChainSegment *asChainSegment[0x50];
|
||||
struct Object *asObject[0x50];
|
||||
struct Surface *asSurface[0x50];
|
||||
void *asVoidPtr[0x50];
|
||||
const void *asConstVoidPtr[0x50];
|
||||
#endif
|
||||
} rawData;
|
||||
#if IS_64_BIT
|
||||
union {
|
||||
s16 *asS16P[0x50];
|
||||
s32 *asS32P[0x50];
|
||||
|
@ -209,7 +197,6 @@ struct Object
|
|||
void *asVoidPtr[0x50];
|
||||
const void *asConstVoidPtr[0x50];
|
||||
} ptrData;
|
||||
#endif
|
||||
/*0x1C8*/ u32 unused1;
|
||||
/*0x1CC*/ const BehaviorScript *curBhvCommand;
|
||||
/*0x1D0*/ u32 bhvStackIndex;
|
||||
|
|
|
@ -262,15 +262,10 @@ struct Object *allocate_object(struct ObjectNode *objList) {
|
|||
obj->collidedObjInteractTypes = 0;
|
||||
obj->numCollidedObjs = 0;
|
||||
|
||||
#if IS_64_BIT
|
||||
for (s32 i = 0; i < 0x50; i++) {
|
||||
obj->rawData.asS32[i] = 0;
|
||||
obj->ptrData.asVoidPtr[i] = NULL;
|
||||
}
|
||||
#else
|
||||
// -O2 needs everything until = on the same line
|
||||
for (s32 i = 0; i < 0x50; i++) obj->rawData.asS32[i] = 0;
|
||||
#endif
|
||||
|
||||
obj->unused1 = 0;
|
||||
obj->bhvStackIndex = 0;
|
||||
|
|
|
@ -331,107 +331,6 @@ static int smlua__get_field(lua_State* L) {
|
|||
return 1;
|
||||
}
|
||||
|
||||
static bool smlua_field_valid(struct LuaObjectField* data, enum LuaObjectType lot, size_t offset) {
|
||||
size_t minimum = MIN(offset, data->valueOffset);
|
||||
size_t maximum = MAX(offset + sizeof(void*), data->valueOffset + sizeof(u32));
|
||||
size_t length = maximum - minimum;
|
||||
size_t maxlength = sizeof(void*) + sizeof(u32);
|
||||
|
||||
if (length < maxlength) {
|
||||
return (data->lot == lot) && (data->valueOffset == offset) && (lot != LOT_NONE);
|
||||
}
|
||||
|
||||
return (length >= maxlength);
|
||||
}
|
||||
|
||||
static bool smlua_is_valid_object_field(struct Object* obj, struct LuaObjectField* data) {
|
||||
enum BehaviorId behaviorId = smlua_get_original_behavior_id(obj->behavior);
|
||||
switch (behaviorId) {
|
||||
case id_bhvBowlingBall:
|
||||
case id_bhvKoopa:
|
||||
case id_bhvMantaRay:
|
||||
case id_bhvMips:
|
||||
case id_bhvPlatformOnTrack:
|
||||
case id_bhvRacingPenguin:
|
||||
case id_bhvSnowmansBottom:
|
||||
case id_bhvUkiki:
|
||||
case id_bhvUnagi:
|
||||
if (!smlua_field_valid(data, LOT_WAYPOINT, offsetof(struct Object, oPathedStartWaypoint))) { return false; }
|
||||
if (!smlua_field_valid(data, LOT_WAYPOINT, offsetof(struct Object, oPathedPrevWaypoint))) { return false; }
|
||||
break;
|
||||
case id_bhvHiddenBlueCoin:
|
||||
if (!smlua_field_valid(data, LOT_OBJECT, offsetof(struct Object, oHiddenBlueCoinSwitch))) { return false; }
|
||||
break;
|
||||
case id_bhvBoo:
|
||||
if (!smlua_field_valid(data, LOT_OBJECT, offsetof(struct Object, oBooParentBigBoo))) { return false; }
|
||||
break;
|
||||
case id_bhvLllBowserPuzzlePiece:
|
||||
if (!smlua_field_valid(data, LOT_NONE, offsetof(struct Object, oBowserPuzzlePieceActionList))) { return false; }
|
||||
if (!smlua_field_valid(data, LOT_NONE, offsetof(struct Object, oBowserPuzzlePieceNextAction))) { return false; }
|
||||
break;
|
||||
case id_bhvChainChomp:
|
||||
for (int i = 0; i < 4; i++) {
|
||||
if (!smlua_field_valid(data, LOT_CHAINSEGMENT, offsetof(struct Object, oChainChompSegments) + sizeof(struct ChainSegment *) * i)) { return false; }
|
||||
}
|
||||
break;
|
||||
case id_bhvBowser:
|
||||
if (!smlua_field_valid(data, LOT_OBJECT, offsetof(struct Object, oFlameBowser))) { return false; }
|
||||
break;
|
||||
case id_bhvHauntedChair:
|
||||
if (!smlua_field_valid(data, LOT_NONE, offsetof(struct Object, oHauntedChairUnk100))) { return false; }
|
||||
break;
|
||||
case id_bhvHiddenStar:
|
||||
case id_bhvHiddenRedCoinStar:
|
||||
case id_bhvBowserCourseRedCoinStar:
|
||||
if (!smlua_field_valid(data, LOT_NONE, offsetof(struct Object, oHiddenStarLastInteractedObject ))) { return false; }
|
||||
break;
|
||||
case id_bhvBreakableBox:
|
||||
case id_bhvHiddenObject:
|
||||
if (!smlua_field_valid(data, LOT_OBJECT, offsetof(struct Object, oHiddenObjectUnkF4))) { return false; }
|
||||
break;
|
||||
case id_bhvBeginningLakitu:
|
||||
if (!smlua_field_valid(data, LOT_OBJECT, offsetof(struct Object, oIntroLakituCloud))) { return false; }
|
||||
break;
|
||||
case id_bhvMontyMole:
|
||||
if (!smlua_field_valid(data, LOT_OBJECT, offsetof(struct Object, oMontyMoleCurrentHole))) { return false; }
|
||||
break;
|
||||
case id_bhvMrBlizzard:
|
||||
if (!smlua_field_valid(data, LOT_OBJECT, offsetof(struct Object, oMrBlizzardHeldObj))) { return false; }
|
||||
break;
|
||||
case id_bhvRespawner:
|
||||
if (!smlua_field_valid(data, LOT_NONE, offsetof(struct Object, oRespawnerBehaviorToRespawn))) { return false; }
|
||||
break;
|
||||
case id_bhvOpenableGrill:
|
||||
if (!smlua_field_valid(data, LOT_OBJECT, offsetof(struct Object, oOpenableGrillUnkF4))) { return false; }
|
||||
break;
|
||||
case id_bhvFallingBowserPlatform:
|
||||
if (!smlua_field_valid(data, LOT_OBJECT, offsetof(struct Object, oPlatformUnkF8))) { return false; }
|
||||
break;
|
||||
case id_bhvJrbSlidingBox:
|
||||
if (!smlua_field_valid(data, LOT_OBJECT, offsetof(struct Object, oJrbSlidingBoxUnkF4))) { return false; }
|
||||
break;
|
||||
case id_bhvToxBox:
|
||||
if (!smlua_field_valid(data, LOT_NONE, offsetof(struct Object, oToxBoxMovementPattern))) { return false; }
|
||||
break;
|
||||
case id_bhvTTCTreadmill:
|
||||
if (!smlua_field_valid(data, LOT_NONE, offsetof(struct Object, oTTCTreadmillBigSurface))) { return false; }
|
||||
if (!smlua_field_valid(data, LOT_NONE, offsetof(struct Object, oTTCTreadmillSmallSurface))) { return false; }
|
||||
break;
|
||||
case id_bhvStrongWindParticle:
|
||||
if (!smlua_field_valid(data, LOT_OBJECT, offsetof(struct Object, oStrongWindParticlePenguinObj))) { return false; }
|
||||
break;
|
||||
case id_bhvWigglerHead:
|
||||
for (int i = 0; i < 3; i++) {
|
||||
if (!smlua_field_valid(data, LOT_CHAINSEGMENT, offsetof(struct Object, oWigglerSegments) + sizeof(struct ChainSegment *) * i)) { return false; }
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
static int smlua__set_field(lua_State* L) {
|
||||
LUA_STACK_CHECK_BEGIN();
|
||||
if (!smlua_functions_valid_param_count(L, 5)) { return 0; }
|
||||
|
@ -480,15 +379,6 @@ static int smlua__set_field(lua_State* L) {
|
|||
return 0;
|
||||
}
|
||||
|
||||
if ((u32)lot == (u32)LOT_OBJECT) {
|
||||
struct Object* obj = (struct Object*)pointer;
|
||||
if (!smlua_is_valid_object_field(obj, data)) {
|
||||
LOG_LUA("_set_field tried to set a custom field that overlapped with a pointer. '%s'", key);
|
||||
smlua_logline();
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
void* valuePointer = NULL;
|
||||
u8* p = ((u8*)(intptr_t)pointer) + data->valueOffset;
|
||||
switch (data->valueType) {
|
||||
|
|
Loading…
Reference in New Issue