From 7dd8dfde97f2c1a6569821bb01ecb31e89e96a9d Mon Sep 17 00:00:00 2001 From: Starkku Date: Sat, 23 Aug 2025 21:30:13 +0300 Subject: [PATCH] Add current TeamClass instances to sync logging --- YRpp | 2 +- src/Misc/SyncLogging.cpp | 89 ++++++++++++++++++++++++++++++++++++++++ src/Misc/SyncLogging.h | 8 ++++ 3 files changed, 98 insertions(+), 1 deletion(-) diff --git a/YRpp b/YRpp index 3668c001a4..ad950ad2e6 160000 --- a/YRpp +++ b/YRpp @@ -1 +1 @@ -Subproject commit 3668c001a4b67f82dcfa2c5c2cb02a44680c1416 +Subproject commit ad950ad2e68982594533f1bc80eea662937ec056 diff --git a/src/Misc/SyncLogging.cpp b/src/Misc/SyncLogging.cpp index f169c1f285..5f2fab8f78 100644 --- a/src/Misc/SyncLogging.cpp +++ b/src/Misc/SyncLogging.cpp @@ -13,6 +13,10 @@ int SyncLogger::AnimCreations_HighestX = 0; int SyncLogger::AnimCreations_HighestY = 0; int SyncLogger::AnimCreations_HighestZ = 0; +int SyncLogger::TeamTypeClass_MaxIDLength = 0; +int SyncLogger::ScriptTypeClass_MaxIDLength = 0; +int SyncLogger::HouseTypeClass_MaxIDLength = 0; +int SyncLogger::HouseName_MaxIDLength = 0; SyncLogEventBuffer SyncLogger::RNGCalls; SyncLogEventBuffer SyncLogger::FacingChanges; @@ -128,6 +132,7 @@ void SyncLogger::WriteSyncLog(const char* logFilename) WriteTargetChanges(pLogFile, frameDigits); WriteDestinationChanges(pLogFile, frameDigits); WriteAnimCreations(pLogFile, frameDigits); + WriteTeams(pLogFile); fclose(pLogFile); } @@ -258,6 +263,90 @@ void SyncLogger::WriteAnimCreations(FILE* const pLogFile, int frameDigits) fprintf(pLogFile, "\n"); } +void SyncLogger::WriteTeams(FILE* const pLogFile) +{ + if (TeamClass::Array.Count < 1) + return; + + fprintf(pLogFile, "AI Teams:\n"); + char buffer[0x20]; + size_t count = 0; + + // Set padding for values. + for (auto const& pTeam : TeamClass::Array) + { + SyncLogger::SetTeamLoggingPadding(pTeam); + count++; + } + + for (size_t i = 0; i < count; i++) + { + auto const pTeam = TeamClass::Array[i]; + + fprintf(pLogFile, "#%05d: Type: %*s", + i, SyncLogger::TeamTypeClass_MaxIDLength, pTeam->Type->get_ID()); + + if (pTeam->CurrentScript && pTeam->CurrentScript->Type) + { + sprintf_s(buffer, sizeof(buffer), "%d", pTeam->CurrentScript->CurrentMission); + fprintf(pLogFile, " | Script: %*s | Line: %2s", SyncLogger::ScriptTypeClass_MaxIDLength, pTeam->CurrentScript->Type->get_ID(), buffer); + } + + if (pTeam->Owner) + { + sprintf_s(buffer, sizeof(buffer), "(%s)", pTeam->Owner->PlainName); + fprintf(pLogFile, " | Owner: %d %*s | OwnerHouse: %*s", pTeam->Owner->ArrayIndex, + SyncLogger::HouseName_MaxIDLength, buffer,SyncLogger::HouseTypeClass_MaxIDLength, pTeam->Owner->Type->get_ID()); + } + + if (pTeam->Focus) + { + auto const rtti = pTeam->Focus->WhatAmI(); + fprintf(pLogFile, " | TargetRTTI: %d (%s) | TargetID: %08d", rtti, AbstractClass::GetRTTIName(rtti), pTeam->Focus->UniqueID); + } + + if (pTeam->QueuedFocus) + { + auto const rtti = pTeam->QueuedFocus->WhatAmI(); + fprintf(pLogFile, " | MissionTargetRTTI: %d (%s) | MissionTargetID: %08d", rtti,AbstractClass::GetRTTIName(rtti), + pTeam->QueuedFocus->UniqueID); + } + + fprintf(pLogFile, "\n"); + } + + fprintf(pLogFile, "\n"); +} + +void SyncLogger::SetTeamLoggingPadding(TeamClass* pTeam) +{ + int length = strlen(pTeam->Type->get_ID()); + + if (length <= 24 && SyncLogger::TeamTypeClass_MaxIDLength < length) + SyncLogger::TeamTypeClass_MaxIDLength = length; + + if (pTeam->Type->ScriptType) + { + length = strlen(pTeam->Type->ScriptType->get_ID()); + + if (length <= 24 && SyncLogger::ScriptTypeClass_MaxIDLength < length) + SyncLogger::ScriptTypeClass_MaxIDLength = length; + } + + if (pTeam->Owner) + { + length = strlen(pTeam->Owner->Type->get_ID()); + + if (length <= 24 && SyncLogger::HouseTypeClass_MaxIDLength < length) + SyncLogger::HouseTypeClass_MaxIDLength = length; + + length = strlen(pTeam->Owner->PlainName); + + if (length <= 21 && SyncLogger::HouseName_MaxIDLength < length) + SyncLogger::HouseName_MaxIDLength = length; + } +} + // Hooks. Anim contructor logging is in Ext/Anim/Body.cpp to reduce duplicate hooks // Sync file writing diff --git a/src/Misc/SyncLogging.h b/src/Misc/SyncLogging.h index 0b4b116ab9..b2e954cb62 100644 --- a/src/Misc/SyncLogging.h +++ b/src/Misc/SyncLogging.h @@ -3,6 +3,8 @@ #include #include #include +#include + #include // These determine how many of each type of sync log event are stored in the buffers. @@ -157,10 +159,15 @@ class SyncLogger static void WriteDestinationChanges(FILE* const pLogFile, int frameDigits); static void WriteMissionOverrides(FILE* const pLogFile, int frameDigits); static void WriteAnimCreations(FILE* const pLogFile, int frameDigits); + static void WriteTeams(FILE* const pLogFile); public: static int AnimCreations_HighestX; static int AnimCreations_HighestY; static int AnimCreations_HighestZ; + static int TeamTypeClass_MaxIDLength; + static int ScriptTypeClass_MaxIDLength; + static int HouseTypeClass_MaxIDLength; + static int HouseName_MaxIDLength; static void AddRNGCallSyncLogEvent(Randomizer* pRandomizer, int type, unsigned int callerAddress, int min = 0, int max = 0); static void AddFacingChangeSyncLogEvent(unsigned short facing, unsigned int callerAddress); @@ -169,4 +176,5 @@ class SyncLogger static void AddMissionOverrideSyncLogEvent(AbstractClass* pObject, int mission, unsigned int callerAddress); static void AddAnimCreationSyncLogEvent(const CoordStruct& coords, unsigned int callerAddress); static void WriteSyncLog(const char* logFilename); + static void SetTeamLoggingPadding(TeamClass* pTeam); };