// Copyright Epic Games, Inc. All Rights Reserved. #include "LyraCosmeticCheats.h" #include "Engine/World.h" #include "GameFramework/GameStateBase.h" #include "LyraControllerComponent_CharacterParts.h" #include "System/LyraDevelopmentStatics.h" ////////////////////////////////////////////////////////////////////// // ULyraCosmeticCheats ULyraCosmeticCheats::ULyraCosmeticCheats() { #if UE_WITH_CHEAT_MANAGER if (HasAnyFlags(RF_ClassDefaultObject)) { UCheatManager::RegisterForOnCheatManagerCreated(FOnCheatManagerCreated::FDelegate::CreateLambda( [](UCheatManager* CheatManager) { CheatManager->AddCheatManagerExtension(NewObject(CheatManager)); })); } #endif } void ULyraCosmeticCheats::AddCharacterPart(const FString& AssetName, bool bSuppressNaturalParts) { #if UE_WITH_CHEAT_MANAGER if (ULyraControllerComponent_CharacterParts* CosmeticComponent = GetCosmeticComponent()) { TSubclassOf PartClass = ULyraDevelopmentStatics::FindClassByShortName(AssetName); if (PartClass != nullptr) { FLyraCharacterPart Part; Part.PartClass = PartClass; CosmeticComponent->AddCheatPart(Part, bSuppressNaturalParts); } } #endif } void ULyraCosmeticCheats::ReplaceCharacterPart(const FString& AssetName, bool bSuppressNaturalParts) { ClearCharacterPartOverrides(); AddCharacterPart(AssetName, bSuppressNaturalParts); } void ULyraCosmeticCheats::ClearCharacterPartOverrides() { #if UE_WITH_CHEAT_MANAGER if (ULyraControllerComponent_CharacterParts* CosmeticComponent = GetCosmeticComponent()) { CosmeticComponent->ClearCheatParts(); } #endif } ULyraControllerComponent_CharacterParts* ULyraCosmeticCheats::GetCosmeticComponent() const { if (APlayerController* PC = GetPlayerController()) { return PC->FindComponentByClass(); } return nullptr; }