mirror of
https://github.com/coop-deluxe/sm64coopdx.git
synced 2024-10-19 03:32:41 +00:00
Fixed critical flaw with txEventId/rxEventId, fixed up controllable platform
This commit is contained in:
parent
d76f060af0
commit
8f50ee17c9
6 changed files with 88 additions and 43 deletions
|
@ -1,5 +1,5 @@
|
|||
// controllable_platform.c.inc
|
||||
|
||||
static s8 oldD_80331694 = 0;
|
||||
static s8 D_80331694 = 0;
|
||||
static struct Object* controllablePlatformSubs[4] = { 0 };
|
||||
|
||||
|
@ -55,6 +55,10 @@ void bhv_controllable_platform_sub_loop(void) {
|
|||
o->activeFlags = ACTIVE_FLAG_DEACTIVATED;
|
||||
}
|
||||
|
||||
static void bhv_controllable_platform_on_received_post(UNUSED u8 localIndex) {
|
||||
oldD_80331694 = D_80331694;
|
||||
}
|
||||
|
||||
void bhv_controllable_platform_init(void) {
|
||||
controllablePlatformSubs[0] = spawn_object_rel_with_rot(o, MODEL_HMC_METAL_ARROW_PLATFORM, bhvControllablePlatformSub, 0,
|
||||
51, 204, 0, 0, 0);
|
||||
|
@ -76,31 +80,34 @@ void bhv_controllable_platform_init(void) {
|
|||
|
||||
o->oControllablePlatformUnkFC = o->oPosY;
|
||||
|
||||
network_init_object(o, SYNC_DISTANCE_ONLY_EVENTS);
|
||||
network_init_object_field(o, &o->oPosX);
|
||||
network_init_object_field(o, &o->oPosY);
|
||||
network_init_object_field(o, &o->oPosZ);
|
||||
network_init_object_field(o, &o->oVelX);
|
||||
network_init_object_field(o, &o->oVelY);
|
||||
network_init_object_field(o, &o->oVelZ);
|
||||
network_init_object_field(o, &o->oAction);
|
||||
network_init_object_field(o, &o->oPrevAction);
|
||||
network_init_object_field(o, &o->oTimer);
|
||||
network_init_object_field_with_size(o, &o->activeFlags, 16);
|
||||
network_init_object_field_with_size(o, &D_80331694, 8);
|
||||
network_init_object_field_with_size(o, &o->header.gfx.node.flags, 16);
|
||||
struct SyncObject* so = network_init_object(o, SYNC_DISTANCE_ONLY_EVENTS);
|
||||
if (so != NULL) {
|
||||
so->on_received_post = bhv_controllable_platform_on_received_post;
|
||||
network_init_object_field(o, &o->oPosX);
|
||||
network_init_object_field(o, &o->oPosY);
|
||||
network_init_object_field(o, &o->oPosZ);
|
||||
network_init_object_field(o, &o->oVelX);
|
||||
network_init_object_field(o, &o->oVelY);
|
||||
network_init_object_field(o, &o->oVelZ);
|
||||
network_init_object_field(o, &o->oAction);
|
||||
network_init_object_field(o, &o->oPrevAction);
|
||||
network_init_object_field(o, &o->oTimer);
|
||||
network_init_object_field_with_size(o, &o->activeFlags, 16);
|
||||
network_init_object_field_with_size(o, &D_80331694, 8);
|
||||
network_init_object_field_with_size(o, &o->header.gfx.node.flags, 16);
|
||||
|
||||
network_init_object_field(o, &o->oControllablePlatformUnkF8);
|
||||
network_init_object_field(o, &o->oControllablePlatformUnkFC);
|
||||
network_init_object_field(o, &o->oControllablePlatformUnk100);
|
||||
network_init_object_field(o, &o->oFaceAnglePitch);
|
||||
network_init_object_field(o, &o->oFaceAngleRoll);
|
||||
for (int i = 0; i < 4; i++) {
|
||||
if (controllablePlatformSubs[i] == NULL) { continue; }
|
||||
network_init_object_field(o, &controllablePlatformSubs[i]->oAction);
|
||||
network_init_object_field(o, &controllablePlatformSubs[i]->oPrevAction);
|
||||
network_init_object_field(o, &controllablePlatformSubs[i]->oTimer);
|
||||
network_init_object_field(o, &controllablePlatformSubs[i]->oParentRelativePosY);
|
||||
network_init_object_field(o, &o->oControllablePlatformUnkF8);
|
||||
network_init_object_field(o, &o->oControllablePlatformUnkFC);
|
||||
network_init_object_field(o, &o->oControllablePlatformUnk100);
|
||||
network_init_object_field(o, &o->oFaceAnglePitch);
|
||||
network_init_object_field(o, &o->oFaceAngleRoll);
|
||||
for (int i = 0; i < 4; i++) {
|
||||
if (controllablePlatformSubs[i] == NULL) { continue; }
|
||||
network_init_object_field(o, &controllablePlatformSubs[i]->oAction);
|
||||
network_init_object_field(o, &controllablePlatformSubs[i]->oPrevAction);
|
||||
network_init_object_field(o, &controllablePlatformSubs[i]->oTimer);
|
||||
network_init_object_field(o, &controllablePlatformSubs[i]->oParentRelativePosY);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -208,8 +215,6 @@ void bhv_controllable_platform_loop(void) {
|
|||
o->oVelX = 0;
|
||||
o->oVelZ = 0;
|
||||
|
||||
s8 oldD_80331694 = D_80331694;
|
||||
|
||||
switch (D_80331694) {
|
||||
case 0:
|
||||
o->oFaceAnglePitch /= 2;
|
||||
|
@ -279,7 +284,6 @@ void bhv_controllable_platform_loop(void) {
|
|||
controllablePlatformSubs[i]->oVelX = 0;
|
||||
controllablePlatformSubs[i]->oVelZ = 0;
|
||||
}
|
||||
network_send_object(o);
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
@ -293,4 +297,5 @@ void bhv_controllable_platform_loop(void) {
|
|||
if (network_owns_object(o) && oldD_80331694 != D_80331694) {
|
||||
network_send_object(o);
|
||||
}
|
||||
oldD_80331694 = D_80331694;
|
||||
}
|
||||
|
|
|
@ -1152,8 +1152,6 @@ s32 play_mode_normal(void) {
|
|||
return 0;
|
||||
}
|
||||
|
||||
#include <stdio.h> // DO NOT COMMIT
|
||||
|
||||
s32 play_mode_paused(void) {
|
||||
if (gPauseScreenMode == 0) {
|
||||
set_menu_mode(RENDER_PAUSE_SCREEN);
|
||||
|
|
|
@ -46,7 +46,7 @@ static void debug_warp_level1() {
|
|||
}
|
||||
|
||||
static void debug_warp_level2() {
|
||||
dynos_warp_to_level(LEVEL_LLL, 1, 1);
|
||||
dynos_warp_to_level(LEVEL_HMC, 1, 1);
|
||||
}
|
||||
|
||||
static void debug_grand_star(void) {
|
||||
|
|
|
@ -351,8 +351,25 @@ void network_player_update_course_level(struct NetworkPlayer* np, s16 courseNum,
|
|||
np->currLevelNum = levelNum;
|
||||
np->currAreaIndex = areaIndex;
|
||||
|
||||
if (mismatch && (np == gNetworkPlayerLocal)) {
|
||||
network_send_level_area_inform();
|
||||
if (mismatch) {
|
||||
if (np == gNetworkPlayerLocal) {
|
||||
network_send_level_area_inform();
|
||||
|
||||
for (s32 i = 0; i < MAX_SYNC_OBJECTS; i++) {
|
||||
struct SyncObject* so = &gSyncObjects[i];
|
||||
if (so == NULL) { continue; }
|
||||
so->txEventId = 0;
|
||||
}
|
||||
|
||||
} else {
|
||||
|
||||
for (s32 i = 0; i < MAX_SYNC_OBJECTS; i++) {
|
||||
struct SyncObject* so = &gSyncObjects[i];
|
||||
if (so == NULL) { continue; }
|
||||
so->rxEventId[np->localIndex] = 0;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -338,6 +338,7 @@ static struct SyncObject* packet_read_object_header(struct Packet* p, u8* fromLo
|
|||
gCurrentObject = o;
|
||||
if ((so->ignore_if_true != NULL) && ((*so->ignore_if_true)() != FALSE)) {
|
||||
gCurrentObject = tmp;
|
||||
LOG_INFO("ignored sync object due to callback");
|
||||
return NULL;
|
||||
}
|
||||
gCurrentObject = tmp;
|
||||
|
@ -347,6 +348,7 @@ static struct SyncObject* packet_read_object_header(struct Packet* p, u8* fromLo
|
|||
u16 eventId = 0;
|
||||
packet_read(p, &eventId, sizeof(u16));
|
||||
if (so->rxEventId[*fromLocalIndex] > eventId && (u16)abs(eventId - so->rxEventId[*fromLocalIndex]) < USHRT_MAX / 2) {
|
||||
LOG_INFO("ignored sync object due to eventId");
|
||||
return NULL;
|
||||
}
|
||||
so->rxEventId[*fromLocalIndex] = eventId;
|
||||
|
@ -456,6 +458,7 @@ static void packet_read_object_extra_fields(struct Packet* p, struct Object* o)
|
|||
u8 extraFieldsCount = 0;
|
||||
packet_read(p, &extraFieldsCount, sizeof(u8));
|
||||
if (extraFieldsCount != so->extraFieldCount) {
|
||||
LOG_ERROR("mismatching extra fields count");
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -492,11 +495,11 @@ void network_send_object(struct Object* o) {
|
|||
if (gNetworkType == NT_NONE || gNetworkPlayerLocal == NULL) { return; }
|
||||
|
||||
// sanity check SyncObject
|
||||
if (!network_sync_object_initialized(o)) { return; }
|
||||
if (o->behavior == bhvRespawner) { return; }
|
||||
if (!network_sync_object_initialized(o)) { LOG_ERROR("tried to send uninitialized sync obj"); return; }
|
||||
if (o->behavior == bhvRespawner) { LOG_INFO("tried to send respawner sync obj"); return; }
|
||||
|
||||
struct SyncObject* so = &gSyncObjects[o->oSyncID];
|
||||
if (so == NULL) { return; }
|
||||
if (so == NULL) { LOG_ERROR("tried to send null sync obj"); return; }
|
||||
if (o != so->o) {
|
||||
LOG_ERROR("object mismatch for %d", o->oSyncID);
|
||||
return;
|
||||
|
@ -512,14 +515,25 @@ void network_send_object(struct Object* o) {
|
|||
}
|
||||
|
||||
void network_send_object_reliability(struct Object* o, bool reliable) {
|
||||
if (gNetworkPlayerLocal == NULL || !gNetworkPlayerLocal->currAreaSyncValid) { return; }
|
||||
if (gNetworkPlayerLocal == NULL || !gNetworkPlayerLocal->currAreaSyncValid) {
|
||||
LOG_INFO("tried to send sync obj when area sync invalid");
|
||||
return;
|
||||
}
|
||||
// prevent sending objects during credits sequence
|
||||
if (gCurrActStarNum == 99) { return; }
|
||||
|
||||
// sanity check SyncObject
|
||||
if (!network_sync_object_initialized(o)) { return; }
|
||||
if (!network_sync_object_initialized(o)) {
|
||||
LOG_ERROR("tried to send uninitialized sync obj");
|
||||
return;
|
||||
}
|
||||
|
||||
u8 syncId = o->oSyncID;
|
||||
struct SyncObject* so = &gSyncObjects[syncId];
|
||||
if (so == NULL) { return; }
|
||||
if (so == NULL) {
|
||||
LOG_ERROR("tried to send null sync obj");
|
||||
return;
|
||||
}
|
||||
if (o != so->o) {
|
||||
LOG_ERROR("object mismatch for %d", syncId);
|
||||
return;
|
||||
|
@ -591,9 +605,15 @@ void network_receive_object(struct Packet* p) {
|
|||
// read the header and sanity check the packet
|
||||
u8 fromLocalIndex = 0;
|
||||
struct SyncObject* so = packet_read_object_header(p, &fromLocalIndex);
|
||||
if (so == NULL) { return; }
|
||||
if (so == NULL) {
|
||||
LOG_ERROR("received null sync object");
|
||||
return;
|
||||
}
|
||||
struct Object* o = so->o;
|
||||
if (!network_sync_object_initialized(o)) { return; }
|
||||
if (!network_sync_object_initialized(o)) {
|
||||
LOG_ERROR("received uninitialized sync object");
|
||||
return;
|
||||
}
|
||||
|
||||
// make sure no one can update an object we're holding
|
||||
if (gMarioStates[0].heldObj == o) { return; }
|
||||
|
|
|
@ -190,8 +190,13 @@ void network_receive_spawn_objects(struct Packet* p) {
|
|||
return;
|
||||
}
|
||||
// check if they've allocated one of their reserved sync objects
|
||||
gSyncObjects[o->oSyncID].o = o;
|
||||
gSyncObjects[o->oSyncID].extendedModelId = data.extendedModelId;
|
||||
struct SyncObject* so = &gSyncObjects[o->oSyncID];
|
||||
so->o = o;
|
||||
so->extendedModelId = data.extendedModelId;
|
||||
so->txEventId = 0;
|
||||
for (s32 j = 0; j < MAX_PLAYERS; j++) {
|
||||
so->rxEventId[j] = 0;
|
||||
}
|
||||
}
|
||||
|
||||
spawned[i] = o;
|
||||
|
|
Loading…
Reference in a new issue