Adds some sanity checks to network_receive_area, And add LOG_DEBUG (#10)

This commit is contained in:
Prince Frizzy 2022-03-04 23:07:35 -05:00 committed by GitHub
parent b4507319b9
commit 6f911738cf
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 33 additions and 6 deletions

View file

@ -43,12 +43,15 @@ static void _debuglog_print_log(char* logType, char* filename) {
}
#if defined(DEBUG) && defined(DISABLE_MODULE_LOG)
#define LOG_DEBUG(...)
#define LOG_INFO(...)
#define LOG_ERROR(...) ( _debuglog_print_log("ERROR", __FILE__), printf(__VA_ARGS__), printf("\n") )
#elif defined(DEBUG) && !defined(DISABLE_MODULE_LOG)
#define LOG_INFO(...) ( _debuglog_print_log("INFO ", __FILE__), printf(__VA_ARGS__), printf("\n") )
#define LOG_DEBUG(...) ( _debuglog_print_log("DEBUG", __FILE__), printf(__VA_ARGS__), printf("\n") )
#define LOG_INFO(...) ( _debuglog_print_log("INFO", __FILE__), printf(__VA_ARGS__), printf("\n") )
#define LOG_ERROR(...) ( _debuglog_print_log("ERROR", __FILE__), printf(__VA_ARGS__), printf("\n") )
#else
#define LOG_DEBUG(...)
#define LOG_INFO(...)
#define LOG_ERROR(...)
#endif

View file

@ -59,13 +59,16 @@ static void _logfile_print_log(enum LogFileType logFileType, char* logType, char
}
#if defined(DEBUG) && defined(DISABLE_MODULE_LOG)
#define LOGFILE_INFO(_LFT, ...) ( _logfile_print_log(_LFT, "INFO ", __FILE__, __LINE__), fprintf(gLogFiles[_LFT].file, __VA_ARGS__), fprintf(gLogFiles[_LFT].file, "\n"))
#define LOGFILE_DEBUG(_LFT, ...) ( _logfile_print_log(_LFT, "DEBUG", __FILE__, __LINE__), fprintf(gLogFiles[_LFT].file, __VA_ARGS__), fprintf(gLogFiles[_LFT].file, "\n"))
#define LOGFILE_INFO(_LFT, ...) ( _logfile_print_log(_LFT, "INFO", __FILE__, __LINE__), fprintf(gLogFiles[_LFT].file, __VA_ARGS__), fprintf(gLogFiles[_LFT].file, "\n"))
#define LOGFILE_ERROR(_LFT, ...) ( _logfile_print_log(_LFT, "ERROR", __FILE__, __LINE__), fprintf(gLogFiles[_LFT].file, __VA_ARGS__), fprintf(gLogFiles[_LFT].file, "\n"), LOG_ERROR(__VA_ARGS__))
#elif defined(DEBUG) && !defined(DISABLE_MODULE_LOG)
#define LOGFILE_INFO(_LFT, ...) ( _logfile_print_log(_LFT, "INFO ", __FILE__, __LINE__), fprintf(gLogFiles[_LFT].file, __VA_ARGS__), fprintf(gLogFiles[_LFT].file, "\n"), LOG_INFO (__VA_ARGS__))
#define LOGFILE_DEBUG(_LFT, ...) ( _logfile_print_log(_LFT, "DEBUG", __FILE__, __LINE__), fprintf(gLogFiles[_LFT].file, __VA_ARGS__), fprintf(gLogFiles[_LFT].file, "\n"), LOG_DEBUG(__VA_ARGS__))
#define LOGFILE_INFO(_LFT, ...) ( _logfile_print_log(_LFT, "INFO", __FILE__, __LINE__), fprintf(gLogFiles[_LFT].file, __VA_ARGS__), fprintf(gLogFiles[_LFT].file, "\n"), LOG_INFO (__VA_ARGS__))
#define LOGFILE_ERROR(_LFT, ...) ( _logfile_print_log(_LFT, "ERROR", __FILE__, __LINE__), fprintf(gLogFiles[_LFT].file, __VA_ARGS__), fprintf(gLogFiles[_LFT].file, "\n"), LOG_ERROR(__VA_ARGS__))
#else
#define LOGFILE_INFO(_LFT, ...) ( _logfile_print_log(_LFT, "INFO ", __FILE__, __LINE__), fprintf(gLogFiles[_LFT].file, __VA_ARGS__), fprintf(gLogFiles[_LFT].file, "\n"))
#define LOGFILE_DEBUG(_LFT, ...) ( _logfile_print_log(_LFT, "DEBUG", __FILE__, __LINE__), fprintf(gLogFiles[_LFT].file, __VA_ARGS__), fprintf(gLogFiles[_LFT].file, "\n"))
#define LOGFILE_INFO(_LFT, ...) ( _logfile_print_log(_LFT, "INFO", __FILE__, __LINE__), fprintf(gLogFiles[_LFT].file, __VA_ARGS__), fprintf(gLogFiles[_LFT].file, "\n"))
#define LOGFILE_ERROR(_LFT, ...) ( _logfile_print_log(_LFT, "ERROR", __FILE__, __LINE__), fprintf(gLogFiles[_LFT].file, __VA_ARGS__), fprintf(gLogFiles[_LFT].file, "\n"))
#endif

View file

@ -136,6 +136,11 @@ void network_send_area(struct NetworkPlayer* toNp) {
void network_receive_area(struct Packet* p) {
LOG_INFO("rx area");
if (p == NULL) {
LOG_ERROR("rx area: the packet was NULL, failed to recieve the area.");
return;
}
// read level location
s16 courseNum, actNum, levelNum, areaIndex;
@ -172,7 +177,7 @@ void network_receive_area(struct Packet* p) {
// read removed sync ids
area_remove_sync_ids_clear();
packet_read(p, &sRemoveSyncIdsIndex, sizeof(u8));
for (int i = 0; i < sRemoveSyncIdsIndex; i++) {
for (s32 i = 0; i < sRemoveSyncIdsIndex; i++) {
packet_read(p, &sRemoveSyncIds[i], sizeof(u8));
struct SyncObject* so = &gSyncObjects[sRemoveSyncIds[i]];
if (so->o != NULL) {
@ -187,7 +192,7 @@ void network_receive_area(struct Packet* p) {
packet_read(p, &respawnerCount, sizeof(u8));
// read respawners
for (int i = 0; i < respawnerCount; i++) {
for (s32 i = 0; i < respawnerCount; i++) {
f32 posX, posY, posZ;
packet_read(p, &posX, sizeof(f32));
packet_read(p, &posY, sizeof(f32));
@ -205,6 +210,22 @@ void network_receive_area(struct Packet* p) {
packet_read(p, &syncId, sizeof(u32));
struct SyncObject* so = &gSyncObjects[syncId];
if (so == NULL) {
LOG_ERROR("rx area: Sync object was NULL, Skipping respawner.");
LOG_DEBUG("rx area debug: Sync Object DEBUG:\n\n \
POS X: %f\n \
POS Y: %f\n \
POS Z: %f\n \
BEHAVIOR PARAMS: 0x%X\n \
RESPAWN MODEL: %i\n \
MIN RESPAWN DIST: %f\n \
RESPAWN BEHAVIOR: %u\n \
SYNC ID: %u\n\n",
posX, posY, posZ, behParams, respawnerModelToRespawn,
respawnerMinSpawnDist, behaviorToRespawn, syncId);
continue;
}
LOG_INFO("rx respawner");
if (syncId < RESERVED_IDS_SYNC_OBJECT_OFFSET) {