add some bounds checks

This commit is contained in:
Isaac0-dev 2024-11-13 13:29:50 +10:00
parent 4ba9970972
commit 3e39f5651a
4 changed files with 13 additions and 6 deletions

View file

@ -253,6 +253,10 @@ void bhv_normal_cap_loop(void) {
if (cap_set_hitbox() == 1) if (cap_set_hitbox() == 1)
save_file_clear_flags(SAVE_FLAG_CAP_ON_GROUND); save_file_clear_flags(SAVE_FLAG_CAP_ON_GROUND);
if (o->globalPlayerIndex >= MAX_PLAYERS) {
o->globalPlayerIndex = 0;
}
obj_set_model(o, gMarioStates[network_local_index_from_global(o->globalPlayerIndex)].character->capModelId); obj_set_model(o, gMarioStates[network_local_index_from_global(o->globalPlayerIndex)].character->capModelId);
} }

View file

@ -110,6 +110,8 @@ void network_receive_network_players(struct Packet *p) {
packet_read(p, &playerName, sizeof(u8) * MAX_CONFIG_STRING); packet_read(p, &playerName, sizeof(u8) * MAX_CONFIG_STRING);
packet_read(p, &discordId, sizeof(u8) * 64); packet_read(p, &discordId, sizeof(u8) * 64);
if (globalIndex > MAX_PLAYERS) { continue; }
u8 localIndex = network_player_connected(npType, globalIndex, modelIndex, &palette, playerName, discordId); u8 localIndex = network_player_connected(npType, globalIndex, modelIndex, &palette, playerName, discordId);
LOG_INFO("received network player [%d == %d] (%d)", globalIndex, npType, localIndex); LOG_INFO("received network player [%d == %d] (%d)", globalIndex, npType, localIndex);
if (localIndex != UNKNOWN_GLOBAL_INDEX) { if (localIndex != UNKNOWN_GLOBAL_INDEX) {

View file

@ -159,6 +159,8 @@ void network_receive_spawn_objects(struct Packet* p) {
name = gNetworkPlayers[p->localIndex].name; name = gNetworkPlayers[p->localIndex].name;
} }
const char *bhvName = get_behavior_name_from_id(data.behaviorId);
// Don't overwrite existing sync objects // Don't overwrite existing sync objects
{ {
u32 syncID = data.rawData[0x04]; // o->oSyncID u32 syncID = data.rawData[0x04]; // o->oSyncID
@ -167,15 +169,15 @@ void network_receive_spawn_objects(struct Packet* p) {
if (so->o->behavior == get_behavior_from_id(data.behaviorId)) { if (so->o->behavior == get_behavior_from_id(data.behaviorId)) {
LOG_ERROR("recieved duplicate sync object with id %d from %s (%s)", syncID, name, id); LOG_ERROR("recieved duplicate sync object with id %d from %s (%s)", syncID, name, id);
} else { } else {
LOG_ERROR("recieved duplicate sync object with id %d with different behavior %s from %s (%s)", syncID, get_behavior_name_from_id(data.behaviorId), name, id); LOG_ERROR("recieved duplicate sync object with id %d with different behavior %s from %s (%s)", syncID, bhvName, name, id);
} }
continue; continue;
} }
} }
LOG_INFO("rx spawn object %s from %s (%s)", get_behavior_name_from_id(data.behaviorId), name, id); LOG_INFO("rx spawn object %s from %s (%s)", bhvName, name, id);
LOG_CONSOLE("rx spawn object %s from %s\\#dcdcdc\\ (%s)", get_behavior_name_from_id(data.behaviorId), name, id); LOG_CONSOLE("rx spawn object %s from %s\\#dcdcdc\\ (%s)", bhvName, name, id);
snprintf(gLastRemoteBhv, 256, "%s %s (%s)", get_behavior_name_from_id(data.behaviorId), name, id); snprintf(gLastRemoteBhv, 256, "%s %s (%s)", bhvName, name, id);
struct Object* parentObj = NULL; struct Object* parentObj = NULL;
if (data.parentId == (u32)-1) { if (data.parentId == (u32)-1) {

View file

@ -351,6 +351,7 @@ void* main_game_init(UNUSED void* dummy) {
audio_init(); audio_init();
sound_init(); sound_init();
network_player_init(); network_player_init();
mumble_init();
gGameInited = true; gGameInited = true;
} }
@ -465,8 +466,6 @@ int main(int argc, char *argv[]) {
network_init(NT_NONE, false); network_init(NT_NONE, false);
} }
mumble_init();
// main loop // main loop
while (true) { while (true) {
debug_context_reset(); debug_context_reset();