diff --git a/Source/LifePlay/LPSessionLogSubsystem.cpp b/Source/LifePlay/LPSessionLogSubsystem.cpp index 16d7243..b1ecb38 100644 --- a/Source/LifePlay/LPSessionLogSubsystem.cpp +++ b/Source/LifePlay/LPSessionLogSubsystem.cpp @@ -6,7 +6,11 @@ #include "GeneralProjectSettings.h" #include "HAL/FileManager.h" #include "HAL/IConsoleManager.h" +#include "Engine/GameInstance.h" #include "Misc/App.h" +#include "Misc/CommandLine.h" +#include "Misc/Parse.h" +#include "UObject/UnrealType.h" #include "Misc/EngineVersion.h" #include "Misc/OutputDevice.h" #include "Misc/Paths.h" @@ -124,10 +128,56 @@ void ULPSessionLogSubsystem::Initialize(FSubsystemCollectionBase& Collection) } LogStartupSummary(); + DumpRequestedVariables(TEXT("demarrage")); +} + +void ULPSessionLogSubsystem::DumpRequestedVariables(const TCHAR* When) const +{ + FString List; + if (!FParse::Value(FCommandLine::Get(), TEXT("LPDumpVars="), List, false)) + { + return; + } + const UGameInstance* GI = GetGameInstance(); + if (!GI) + { + return; + } + + TArray Names; + List.ParseIntoArray(Names, TEXT(","), true); + for (const FString& Name : Names) + { + const FProperty* Prop = GI->GetClass()->FindPropertyByName(FName(*Name)); + if (!Prop) + { + UE_LOG(LogLifePlay, Warning, TEXT("[dump %s] %s : variable introuvable sur %s"), When, *Name, *GI->GetClass()->GetName()); + continue; + } + + if (const FArrayProperty* ArrayProp = CastField(Prop)) + { + FScriptArrayHelper Helper(ArrayProp, ArrayProp->ContainerPtrToValuePtr(GI)); + UE_LOG(LogLifePlay, Display, TEXT("[dump %s] %s : %d element(s)"), When, *Name, Helper.Num()); + for (int32 i = 0; i < Helper.Num(); ++i) + { + FString Text; + ArrayProp->Inner->ExportTextItem_Direct(Text, Helper.GetRawPtr(i), nullptr, const_cast(GI), PPF_None); + UE_LOG(LogLifePlay, Display, TEXT("[dump %s] %s[%d] = %s"), When, *Name, i, *Text.Left(600)); + } + } + else + { + FString Text; + Prop->ExportTextItem_Direct(Text, Prop->ContainerPtrToValuePtr(GI), nullptr, const_cast(GI), PPF_None); + UE_LOG(LogLifePlay, Display, TEXT("[dump %s] %s = %s"), When, *Name, *Text.Left(600)); + } + } } void ULPSessionLogSubsystem::Deinitialize() { + DumpRequestedVariables(TEXT("fin")); LogSessionSummary(); if (Counter.IsValid()) diff --git a/Source/LifePlay/LPSessionLogSubsystem.h b/Source/LifePlay/LPSessionLogSubsystem.h index 279bf96..592d633 100644 --- a/Source/LifePlay/LPSessionLogSubsystem.h +++ b/Source/LifePlay/LPSessionLogSubsystem.h @@ -31,6 +31,13 @@ public: private: void LogStartupSummary() const; + /** + * Diagnostic (lot L5) : ecrit dans le journal le contenu des variables de l'instance de + * jeu (GI) nommees sur la ligne de commande, par exemple -LPDumpVars=MeshSexRace,LegacyPercentage. + * Un tableau est ecrit element par element. Sans l'option, ne fait rien. + */ + void DumpRequestedVariables(const TCHAR* When) const; + TSharedPtr Counter; double StartTime = 0.0; };