diff --git a/include/types.h b/include/types.h index defad47e..1ce0b95e 100644 --- a/include/types.h +++ b/include/types.h @@ -416,9 +416,10 @@ struct TextureInfo #define MAX_PLAYERS 16 -#define COOP_OBJ_FLAG_NETWORK (1 << 0) -#define COOP_OBJ_FLAG_LUA (1 << 1) -#define COOP_OBJ_FLAG_NON_SYNC (1 << 2) +#define COOP_OBJ_FLAG_NETWORK (1 << 0) +#define COOP_OBJ_FLAG_LUA (1 << 1) +#define COOP_OBJ_FLAG_NON_SYNC (1 << 2) +#define COOP_OBJ_FLAG_INITIALIZED (1 << 3) #include "src/game/characters.h" #include "data/dynos.c.h" diff --git a/src/game/area.c b/src/game/area.c index 0887a658..a8167567 100644 --- a/src/game/area.c +++ b/src/game/area.c @@ -251,7 +251,9 @@ void load_area(s32 index) { if (gCurrentArea == NULL && gAreaData[index].unk04 != NULL) { gCurrentArea = &gAreaData[index]; gCurrentArea->localAreaTimer = 0; - gCurrentArea->nextSyncID = 10; + if (gCurrentArea->objectSpawnInfos) { + gCurrentArea->nextSyncID = gCurrentArea->objectSpawnInfos->syncID + 10; + } gCurrAreaIndex = gCurrentArea->index; if (gCurrentArea->terrainData != NULL) { diff --git a/src/pc/lua/utils/smlua_obj_utils.c b/src/pc/lua/utils/smlua_obj_utils.c index dd1dad3c..9b86ab0f 100644 --- a/src/pc/lua/utils/smlua_obj_utils.c +++ b/src/pc/lua/utils/smlua_obj_utils.c @@ -51,7 +51,8 @@ static struct Object* spawn_object_internal(enum BehaviorId behaviorId, enum Mod obj->oHomeY = y; obj->oHomeZ = z; - obj->coopFlags = COOP_OBJ_FLAG_LUA; + obj->coopFlags = COOP_OBJ_FLAG_LUA | (obj->coopFlags & COOP_OBJ_FLAG_INITIALIZED); + if (!doSync) { obj->coopFlags |= COOP_OBJ_FLAG_NON_SYNC; } if (objSetupFunction != 0) { diff --git a/src/pc/network/network_player.c b/src/pc/network/network_player.c index 088425cd..da815d4e 100644 --- a/src/pc/network/network_player.c +++ b/src/pc/network/network_player.c @@ -148,6 +148,9 @@ void network_player_palette_to_color(struct NetworkPlayer *np, enum PlayerParts void network_player_update(void) { for (s32 i = 0; i < MAX_PLAYERS; i++) { struct NetworkPlayer *np = &gNetworkPlayers[i]; + if (np->connected && gMarioStates[np->localIndex].interactObj) { + //LOG_INFO("%u :: %u", np->globalIndex, gMarioStates[np->localIndex].interactObj->oSyncID); // DO NOT COMMIT + } if (!np->connected && i > 0) { continue; } network_player_update_model(i); diff --git a/src/pc/network/packets/packet_debug_sync.c b/src/pc/network/packets/packet_debug_sync.c index d83c3f35..a5b9fb61 100644 --- a/src/pc/network/packets/packet_debug_sync.c +++ b/src/pc/network/packets/packet_debug_sync.c @@ -1,6 +1,7 @@ #include "../network.h" #include "behavior_table.h" #include "pc/debuglog.h" +#include "object_fields.h" void print_sync_object_table(void) { LOG_INFO("Sync Object Table"); @@ -11,6 +12,9 @@ void print_sync_object_table(void) { char* behaviorName = (char*)get_behavior_name_from_id(behaviorId); if (!behaviorName) { behaviorName = "UNKNOWN"; } LOG_INFO("%04d: %08X :: %s", so->id, behaviorId, behaviorName); + if (so->o->oSyncID != so->id) { + LOG_INFO("^^^^^^^^^^^^^^^^^^^^^ %u != %u", so->o->oSyncID, so->id); + } behaviorId = behaviorId; // suppress warning } LOG_INFO(" "); diff --git a/src/pc/network/packets/packet_object.c b/src/pc/network/packets/packet_object.c index 74367e6e..3178c8ee 100644 --- a/src/pc/network/packets/packet_object.c +++ b/src/pc/network/packets/packet_object.c @@ -273,7 +273,7 @@ void network_send_object(struct Object* o) { // sanity check SyncObject if (!sync_object_is_initialized(o->oSyncID)) { - LOG_ERROR("tried to send uninitialized sync obj"); + //LOG_ERROR("tried to send uninitialized sync obj"); return; } if (o->behavior == smlua_override_behavior(bhvRespawner)) { @@ -307,7 +307,7 @@ void network_send_object_reliability(struct Object* o, bool reliable) { // sanity check SyncObject if (!sync_object_is_initialized(o->oSyncID)) { - LOG_ERROR("tried to send uninitialized sync obj"); + //LOG_ERROR("tried to send uninitialized sync obj"); return; } diff --git a/src/pc/network/packets/packet_ping.c b/src/pc/network/packets/packet_ping.c index 974d5291..87f8d2b6 100644 --- a/src/pc/network/packets/packet_ping.c +++ b/src/pc/network/packets/packet_ping.c @@ -1,7 +1,6 @@ #include #include "../network.h" #include "pc/utils/misc.h" -#define DISABLE_MODULE_LOG 1 #include "pc/debuglog.h" void network_send_ping(struct NetworkPlayer* toNp) { @@ -15,11 +14,11 @@ void network_send_ping(struct NetworkPlayer* toNp) { packet_write(&p, ×tamp, sizeof(f64)); network_send_to(toNp->localIndex, &p); - LOG_INFO("tx ping"); + //LOG_INFO("tx ping"); } void network_receive_ping(struct Packet* p) { - LOG_INFO("rx ping"); + //LOG_INFO("rx ping"); u8 globalIndex; f64 timestamp; @@ -52,5 +51,5 @@ void network_receive_pong(struct Packet* p) { u32 ping = (now - timestamp) * 1000; np->ping = np->ping * 0.5f + ping * 0.5f; if (np->ping > 1000) { np->ping = 1000; } - LOG_INFO("rx pong from %u: %u", globalIndex, ping); + //LOG_INFO("rx pong from %u: %u", globalIndex, ping); } diff --git a/src/pc/network/sync_object.c b/src/pc/network/sync_object.c index 7aee05f9..22f39920 100644 --- a/src/pc/network/sync_object.c +++ b/src/pc/network/sync_object.c @@ -158,6 +158,11 @@ struct SyncObject* sync_object_init(struct Object *o, float maxSyncDistance) { LOG_ERROR("Failed to get sync object in init"); return NULL; } + + if (o->coopFlags & COOP_OBJ_FLAG_INITIALIZED) { + return so; + } + so->id = id; so->o = o; so->maxSyncDistance = maxSyncDistance; @@ -191,6 +196,7 @@ struct SyncObject* sync_object_init(struct Object *o, float maxSyncDistance) { memset(so->extraFieldsSize, 0, sizeof(u8) * MAX_SYNC_OBJECT_FIELDS); so->lastReliablePacket.error = true; + o->coopFlags |= COOP_OBJ_FLAG_INITIALIZED; return so; } @@ -256,8 +262,8 @@ struct Object* sync_object_get_object(u32 syncId) { bool sync_object_is_initialized(u32 syncId) { if (syncId == 0) { return false; } struct SyncObject* so = sync_object_get(syncId); - if (so == NULL || so->behavior == NULL) { return false; } - return true; + if (so == NULL || so->o == NULL) { return false; } + return so->o->coopFlags & COOP_OBJ_FLAG_INITIALIZED; } bool sync_object_is_owned_locally(u32 syncId) { @@ -403,10 +409,11 @@ bool sync_object_set_id(struct Object* o) { if (!so) { so = calloc(1, sizeof(struct SyncObject)); - so->id = syncId; so->extendedModelId = 0xFFFF; hmap_put(sSoMap, syncId, so); LOG_INFO("Allocated sync object @ %u, size %ld", syncId, hmap_len(sSoMap)); + } else if (so->o != o) { + LOG_INFO("Already exists..."); } if (!so) { @@ -414,6 +421,9 @@ bool sync_object_set_id(struct Object* o) { return false; } + so->id = syncId; + so->o = o; + so->behavior = (BehaviorScript*) o->behavior; o->oSyncID = syncId; if (gNetworkAreaLoaded) {