Switch behavior ID length from 16bit to 32bit

This commit is contained in:
MysterD 2022-03-01 22:55:40 -08:00
parent d578c6a2ce
commit a1dbd4b268
8 changed files with 34 additions and 34 deletions

View file

@ -84,7 +84,7 @@ void network_send_area(struct NetworkPlayer* toNp) {
packet_write(&p, &so->o->oBehParams, sizeof(s32));
packet_write(&p, &so->o->oRespawnerModelToRespawn, sizeof(s32));
packet_write(&p, &so->o->oRespawnerMinSpawnDist, sizeof(f32));
packet_write(&p, &behaviorToRespawn, sizeof(s32));
packet_write(&p, &behaviorToRespawn, sizeof(u32));
packet_write(&p, &so->o->oSyncID, sizeof(u32));
LOG_INFO("tx respawner");
}

View file

@ -11,8 +11,8 @@ static void print_sync_object_table(void) {
LOG_INFO("Sync Object Table");
for (int i = 0; i < MAX_SYNC_OBJECTS; i++) {
if (gSyncObjects[i].o == NULL) { continue; }
u16 behaviorId = get_id_from_behavior(gSyncObjects[i].behavior);
LOG_INFO("%03d: %04X", i, behaviorId);
u32 behaviorId = get_id_from_behavior(gSyncObjects[i].behavior);
LOG_INFO("%03d: %08X", i, behaviorId);
behaviorId = behaviorId; // suppress warning
}
LOG_INFO(" ");

View file

@ -48,11 +48,11 @@ static struct Object* find_nearest_coin(const BehaviorScript *behavior, f32* pos
void network_send_collect_coin(struct Object* o) {
if (gNetworkPlayerLocal == NULL || !gNetworkPlayerLocal->currAreaSyncValid) { return; }
u16 behaviorId = get_id_from_behavior(o->behavior);
u32 behaviorId = get_id_from_behavior(o->behavior);
struct Packet p = { 0 };
packet_init(&p, PACKET_COLLECT_COIN, true, PLMT_LEVEL);
packet_write(&p, &behaviorId, sizeof(u16));
packet_write(&p, &behaviorId, sizeof(u32));
packet_write(&p, &o->oPosX, sizeof(f32) * 3);
packet_write(&p, &gMarioStates[0].numCoins, sizeof(s16));
packet_write(&p, &o->oDamageOrCoinValue, sizeof(s32));
@ -64,13 +64,13 @@ void network_send_collect_coin(struct Object* o) {
void network_receive_collect_coin(struct Packet* p) {
s16 oldNumCoins = gMarioStates[0].numCoins;
u16 behaviorId;
u32 behaviorId;
f32 pos[3] = { 0 };
s16 numCoins = 0;
s32 coinValue = 0;
s16 areaIndex = 0;
packet_read(p, &behaviorId, sizeof(u16));
packet_read(p, &behaviorId, sizeof(u32));
packet_read(p, &pos, sizeof(f32) * 3);
packet_read(p, &numCoins, sizeof(s16));
packet_read(p, &coinValue, sizeof(s32));

View file

@ -42,21 +42,21 @@ static struct Object* find_nearest_item(const BehaviorScript *behavior, f32* pos
void network_send_collect_item(struct Object* o) {
if (gNetworkPlayerLocal == NULL || !gNetworkPlayerLocal->currAreaSyncValid) { return; }
u16 behaviorId = get_id_from_behavior(o->behavior);
u32 behaviorId = get_id_from_behavior(o->behavior);
struct Packet p = { 0 };
packet_init(&p, PACKET_COLLECT_ITEM, true, PLMT_AREA);
packet_write(&p, &behaviorId, sizeof(u16));
packet_write(&p, &behaviorId, sizeof(u32));
packet_write(&p, &o->oPosX, sizeof(f32) * 3);
network_send(&p);
}
void network_receive_collect_item(struct Packet* p) {
u16 behaviorId;
u32 behaviorId;
f32 pos[3] = { 0 };
packet_read(p, &behaviorId, sizeof(u16));
packet_read(p, &behaviorId, sizeof(u32));
packet_read(p, &pos, sizeof(f32) * 3);
const void* behavior = get_behavior_from_id(behaviorId);

View file

@ -45,7 +45,7 @@ static struct Object* find_nearest_star(const BehaviorScript* behavior, f32* pos
}
void network_send_collect_star(struct Object* o, s16 coinScore, s16 starIndex) {
u16 behaviorId = get_id_from_behavior(o->behavior);
u32 behaviorId = get_id_from_behavior(o->behavior);
struct Packet p = { 0 };
packet_init(&p, PACKET_COLLECT_STAR, true, PLMT_NONE);
@ -55,7 +55,7 @@ void network_send_collect_star(struct Object* o, s16 coinScore, s16 starIndex) {
packet_write(&p, &gCurrLevelNum, sizeof(s16));
packet_write(&p, &gCurrAreaIndex, sizeof(s16));
packet_write(&p, &o->oPosX, sizeof(f32) * 3);
packet_write(&p, &behaviorId, sizeof(u16));
packet_write(&p, &behaviorId, sizeof(u32));
packet_write(&p, &coinScore, sizeof(s16));
packet_write(&p, &starIndex, sizeof(s16));
@ -64,7 +64,7 @@ void network_send_collect_star(struct Object* o, s16 coinScore, s16 starIndex) {
void network_receive_collect_star(struct Packet* p) {
f32 pos[3] = { 0 };
u16 behaviorId;
u32 behaviorId;
s16 coinScore, starIndex;
s16 lastSaveFileNum = gCurrSaveFileNum;
s16 lastCourseNum = gCurrCourseNum;
@ -78,7 +78,7 @@ void network_receive_collect_star(struct Packet* p) {
packet_read(p, &gCurrLevelNum, sizeof(s16));
packet_read(p, &gCurrAreaIndex, sizeof(s16));
packet_read(p, &pos, sizeof(f32) * 3);
packet_read(p, &behaviorId, sizeof(u16));
packet_read(p, &behaviorId, sizeof(u32));
packet_read(p, &coinScore, sizeof(s16));
packet_read(p, &starIndex, sizeof(s16));

View file

@ -6,8 +6,8 @@ static void print_sync_object_table(void) {
LOG_INFO("Sync Object Table");
for (int i = 0; i < MAX_SYNC_OBJECTS; i++) {
if (gSyncObjects[i].o == NULL) { continue; }
u16 behaviorId = get_id_from_behavior(gSyncObjects[i].behavior);
LOG_INFO("%03d: %04X", i, behaviorId);
u32 behaviorId = get_id_from_behavior(gSyncObjects[i].behavior);
LOG_INFO("%03d: %08X", i, behaviorId);
behaviorId = behaviorId; // suppress warning
}
LOG_INFO(" ");
@ -25,30 +25,30 @@ void network_send_debug_sync(void) {
packet_write(&p, &objectCount, sizeof(u8));
for (int i = 0; i < MAX_SYNC_OBJECTS; i++) {
if (gSyncObjects[i].o == NULL) { continue; }
u16 behaviorId = get_id_from_behavior((gSyncObjects[i].behavior == NULL) ? gSyncObjects[i].behavior : gSyncObjects[i].o->behavior);
u32 behaviorId = get_id_from_behavior((gSyncObjects[i].behavior == NULL) ? gSyncObjects[i].behavior : gSyncObjects[i].o->behavior);
packet_write(&p, &i, sizeof(u8));
packet_write(&p, &behaviorId, sizeof(u16));
packet_write(&p, &behaviorId, sizeof(u32));
}
network_send(&p);
}
void network_receive_debug_sync(struct Packet* p) {
u8 objectCount = 0;
u16 remoteBehaviorIds[MAX_SYNC_OBJECTS] = { 0 };
u32 remoteBehaviorIds[MAX_SYNC_OBJECTS] = { 0 };
packet_read(p, &objectCount, sizeof(u8));
for (int i = 0; i < objectCount; i++) {
u8 j;
u16 behaviorId;
u32 behaviorId;
packet_read(p, &j, sizeof(u8));
packet_read(p, &behaviorId, sizeof(u16));
packet_read(p, &behaviorId, sizeof(u32));
remoteBehaviorIds[j] = behaviorId;
}
bool hasMismatch = false;
for (int i = 0; i < MAX_SYNC_OBJECTS; i++) {
u16 localBehaviorId = (gSyncObjects[i].o == NULL) ? 0 : get_id_from_behavior(gSyncObjects[i].behavior);
u16 remoteBehaviorId = remoteBehaviorIds[i];
u32 localBehaviorId = (gSyncObjects[i].o == NULL) ? 0 : get_id_from_behavior(gSyncObjects[i].behavior);
u32 remoteBehaviorId = remoteBehaviorIds[i];
if (localBehaviorId != remoteBehaviorId) {
hasMismatch = true;
break;
@ -59,8 +59,8 @@ void network_receive_debug_sync(struct Packet* p) {
LOG_INFO(" ");
LOG_INFO("Sync Object Table Mismatch");
for (int i = 0; i < MAX_SYNC_OBJECTS; i++) {
u16 localBehaviorId = (gSyncObjects[i].o == NULL) ? 0 : get_id_from_behavior(gSyncObjects[i].behavior);
u16 remoteBehaviorId = remoteBehaviorIds[i];
u32 localBehaviorId = (gSyncObjects[i].o == NULL) ? 0 : get_id_from_behavior(gSyncObjects[i].behavior);
u32 remoteBehaviorId = remoteBehaviorIds[i];
if (localBehaviorId == 0 && remoteBehaviorId == 0) { continue; }
LOG_INFO("%03d: %04X %04X %s", i, localBehaviorId, remoteBehaviorId, (localBehaviorId == remoteBehaviorId) ? " " : "<<<");
}

View file

@ -263,13 +263,13 @@ bool network_set_sync_id(struct Object* o) {
static void packet_write_object_header(struct Packet* p, struct Object* o) {
struct SyncObject* so = &gSyncObjects[o->oSyncID];
u16 behaviorId = get_id_from_behavior(o->behavior);
u32 behaviorId = get_id_from_behavior(o->behavior);
packet_write(p, &gNetworkPlayerLocal->globalIndex, sizeof(u8));
packet_write(p, &o->oSyncID, sizeof(u32));
packet_write(p, &so->txEventId, sizeof(u16));
packet_write(p, &so->randomSeed, sizeof(u16));
packet_write(p, &behaviorId, sizeof(u16));
packet_write(p, &behaviorId, sizeof(u32));
}
static bool allowable_behavior_change(struct SyncObject* so, BehaviorScript* behavior) {
@ -333,8 +333,8 @@ static struct SyncObject* packet_read_object_header(struct Packet* p, u8* fromLo
packet_read(p, &so->randomSeed, sizeof(u16));
// make sure the behaviors match
u16 behaviorId;
packet_read(p, &behaviorId, sizeof(u16));
u32 behaviorId;
packet_read(p, &behaviorId, sizeof(u32));
BehaviorScript* behavior = (BehaviorScript*)get_behavior_from_id(behaviorId);
if (behavior == NULL) {

View file

@ -17,7 +17,7 @@
struct SpawnObjectData {
u8 parentId;
u32 model;
u16 behaviorId;
u32 behaviorId;
s16 activeFlags;
s32 rawData[80];
u8 globalPlayerIndex;
@ -73,13 +73,13 @@ void network_send_spawn_objects_to(u8 sendToLocalIndex, struct Object* objects[]
struct Object* o = objects[i];
u32 model = models[i];
u8 parentId = generate_parent_id(objects, i, true);
u16 behaviorId = get_id_from_behavior(o->behavior);
u32 behaviorId = get_id_from_behavior(o->behavior);
u8 extendedModelId = (o->oSyncID != 0 && gSyncObjects[o->oSyncID].o == o)
? gSyncObjects[o->oSyncID].extendedModelId
: 0xFF;
packet_write(&p, &parentId, sizeof(u8));
packet_write(&p, &model, sizeof(u32));
packet_write(&p, &behaviorId, sizeof(u16));
packet_write(&p, &behaviorId, sizeof(u32));
packet_write(&p, &o->activeFlags, sizeof(s16));
packet_write(&p, o->rawData.asU32, sizeof(s32) * 80);
packet_write(&p, &o->header.gfx.scale[0], sizeof(f32));
@ -115,7 +115,7 @@ void network_receive_spawn_objects(struct Packet* p) {
Vec3f scale = { 0 };
packet_read(p, &data.parentId, sizeof(u8));
packet_read(p, &data.model, sizeof(u32));
packet_read(p, &data.behaviorId, sizeof(u16));
packet_read(p, &data.behaviorId, sizeof(u32));
packet_read(p, &data.activeFlags, sizeof(s16));
packet_read(p, &data.rawData, sizeof(s32) * 80);
packet_read(p, &scale[0], sizeof(f32));