fix some issues with mario object pointers

This commit is contained in:
Isaac0-dev 2025-02-12 22:20:57 +10:00
parent 29cd4d5e59
commit 2a6cb5c842
3 changed files with 13 additions and 4 deletions

View file

@ -99,7 +99,7 @@ void bhv_idle_water_wave_loop(void) {
}
obj_copy_pos(o, o->parentObj);
u8 index = o->parentObj->oBehParams - 1;
o->oPosY = gMarioStates[index].waterLevel + 5;
if (index < MAX_PLAYERS) { o->oPosY = gMarioStates[index].waterLevel + 5; }
if (!(o->parentObj->oMarioParticleFlags & ACTIVE_PARTICLE_IDLE_WATER_WAVE)) {
o->parentObj->oActiveParticleFlags &= (u16)~ACTIVE_PARTICLE_IDLE_WATER_WAVE;
o->activeFlags = ACTIVE_FLAG_DEACTIVATED;

View file

@ -219,6 +219,15 @@ void unload_object(struct Object *obj) {
obj->header.gfx.node.flags &= ~GRAPH_RENDER_CYLBOARD;
obj->header.gfx.node.flags &= ~GRAPH_RENDER_ACTIVE;
// Clear Mario object pointers
if (obj->behavior == smlua_override_behavior(bhvMario)) {
u8 playerIndex = obj->oBehParams - 1;
if (playerIndex < MAX_PLAYERS) {
gMarioObjects[playerIndex] = NULL;
gMarioStates[playerIndex].marioObj = NULL;
}
}
struct SyncObject* so = sync_object_get(obj->oSyncID);
if (so && gNetworkType != NT_NONE) {
if (so->syncDeathEvent) {

View file

@ -56,12 +56,12 @@ void network_receive_spawn_star(struct Packet* p) {
if (o != NULL) {
packet_read(p, &o->oPosX, sizeof(u32) * 3);
packet_read(p, &o->oHomeX, sizeof(u32) * 3);
// Here we check if we're supposed to play the cutscene or not depending on if
// the global player index sent matches us.
// If the network player index is -1, Then the cutscene will always be skipped.
// This check is vital for objects which are network owned specfically.
// Leaving this the only way to properly set the cutscene flags
// Leaving this the only way to properly set the cutscene flags
// for those who don't own the object.
//printf("network_receive_spawn_star: Network Player Index is %i, Our Global Index is %i.\n", networkPlayerIndex, gNetworkPlayers[0].globalIndex);
if (networkPlayerIndex == gNetworkPlayers[0].globalIndex) {
@ -77,7 +77,7 @@ void network_send_spawn_star_nle(struct Object* o, u32 params) {
u8 globalIndex = UNKNOWN_GLOBAL_INDEX;
if (o->behavior == smlua_override_behavior(bhvMario)) {
u8 localIndex = o->oBehParams - 1;
globalIndex = gNetworkPlayers[localIndex].globalIndex;
if (localIndex < MAX_PLAYERS) { globalIndex = gNetworkPlayers[localIndex].globalIndex; }
}
struct Packet p = { 0 };