// Portage UE 5.5 - voir LPModSettingsLibrary.h #include "LPModSettingsLibrary.h" #include "GameFramework/SaveGame.h" #include "Kismet/GameplayStatics.h" #include "LifePlay.h" #include "UObject/UnrealType.h" bool ULPModSettingsLibrary::SaveModSelection(UObject* GameInstance) { static const TCHAR* Slot = TEXT("GameSettings"); static const FName SettingsModEnabledsName(TEXT("ModEnableds")); if (!GameInstance) { return false; } if (!UGameplayStatics::DoesSaveGameExist(Slot, 0)) { UE_LOG(LogLifePlay, Display, TEXT("Modules : pas encore de %s.sav, choix enregistre a la premiere sauvegarde"), Slot); return false; } USaveGame* Settings = UGameplayStatics::LoadGameFromSlot(Slot, 0); const FArrayProperty* From = CastField(GameInstance->GetClass()->FindPropertyByName(SettingsModEnabledsName)); const FArrayProperty* To = Settings ? CastField(Settings->GetClass()->FindPropertyByName(SettingsModEnabledsName)) : nullptr; if (!From || !To || !From->SameType(To)) { UE_LOG(LogLifePlay, Warning, TEXT("Modules : %s.sav illisible ou sans ModEnableds compatible, choix non enregistre"), Slot); return false; } To->CopyCompleteValue(To->ContainerPtrToValuePtr(Settings), From->ContainerPtrToValuePtr(GameInstance)); const bool bSaved = UGameplayStatics::SaveGameToSlot(Settings, Slot, 0); FScriptArrayHelper Helper(To, To->ContainerPtrToValuePtr(Settings)); UE_LOG(LogLifePlay, Display, TEXT("Modules : choix (%d module(s)) %s dans %s.sav"), Helper.Num(), bSaved ? TEXT("enregistre") : TEXT("NON enregistre"), Slot); return bSaved; }