File size: 6,417 Bytes
7fd553e | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 | // Copyright Epic Games, Inc. All Rights Reserved.
#include "LyraHotfixManager.h"
#include "UObject/UObjectIterator.h"
#include "Engine/NetDriver.h"
#include "DeviceProfiles/DeviceProfileManager.h"
#include "DeviceProfiles/DeviceProfile.h"
#include "Settings/LyraSettingsLocal.h"
#include "HAL/MemoryMisc.h"
#include UE_INLINE_GENERATED_CPP_BY_NAME(LyraHotfixManager)
int32 ULyraHotfixManager::GameHotfixCounter = 0;
ULyraHotfixManager::ULyraHotfixManager()
{
#if !UE_BUILD_SHIPPING
OnScreenMessageHandle = FCoreDelegates::OnGetOnScreenMessages.AddUObject(this, &ULyraHotfixManager::GetOnScreenMessages);
#endif // !UE_BUILD_SHIPPING
HotfixCompleteDelegateHandle = AddOnHotfixCompleteDelegate_Handle(FOnHotfixCompleteDelegate::CreateUObject(this, &ThisClass::OnHotfixCompleted));
}
void ULyraHotfixManager::Init()
{
Super::Init();
}
void ULyraHotfixManager::OnHotfixCompleted(EHotfixResult HotfixResult)
{
// Reload DDoS detection config for all live Net Drivers (mirrors RepGraph code)
for (TObjectIterator<UNetDriver> It; It; ++It)
{
if (It->IsServer())
{
UE_LOG(LogHotfixManager, Log, TEXT("Reloading DDoS detection settings for NetDriver: %s"), *It->GetName());
It->DDoS.InitConfig();
}
}
if (bHasPendingDeviceProfileHotfix)
{
UE_LOG(LogHotfixManager, Log, TEXT("Re-applying Hotfixed DeviceProfile"));
bHasPendingDeviceProfileHotfix = false;
UDeviceProfileManager::Get().ReapplyDeviceProfile();
ULyraSettingsLocal* GameSettings = ULyraSettingsLocal::Get();
GameSettings->OnHotfixDeviceProfileApplied();
}
#if ENABLE_SHARED_MEMORY_TRACKER
FSharedMemoryTracker::PrintMemoryDiff(TEXT("Hotfix Complete"));
#endif
}
ULyraHotfixManager::~ULyraHotfixManager()
{
ClearOnHotfixCompleteDelegate_Handle(HotfixCompleteDelegateHandle);
#if !UE_BUILD_SHIPPING
FCoreDelegates::OnGetOnScreenMessages.Remove(OnScreenMessageHandle);
#endif // !UE_BUILD_SHIPPING
}
bool ULyraHotfixManager::WantsHotfixProcessing(const FCloudFileHeader& FileHeader)
{
bool bWantsProcessing = Super::WantsHotfixProcessing(FileHeader);
if (!bWantsProcessing)
{
FString SupportedFiles[] = {
TEXT("AssetMigrations.ini")
};
for (FString SupportedFile : SupportedFiles)
{
#if !UE_BUILD_SHIPPING
if (!DebugPrefix.IsEmpty())
{
SupportedFile = DebugPrefix + SupportedFile;
}
#endif
if (SupportedFile == FileHeader.FileName)
{
bWantsProcessing = true;
break;
}
}
}
return bWantsProcessing;
}
bool ULyraHotfixManager::HotfixIniFile(const FString& FileName, const FString& IniData)
{
if (!bHasPendingDeviceProfileHotfix && FileName.EndsWith(TEXT("DEVICEPROFILES.INI"), ESearchCase::IgnoreCase))
{
FConfigFile DeviceProfileHotfixConfig;
DeviceProfileHotfixConfig.CombineFromBuffer(IniData, FileName);
TSet<FString> Keys;
for (const auto& DPSection : AsConst(DeviceProfileHotfixConfig))
{
FString DeviceProfileName, DeviceProfileClass;
if (DPSection.Key.Split(TEXT(" "), &DeviceProfileName, &DeviceProfileClass) && DeviceProfileClass == *UDeviceProfile::StaticClass()->GetName())
{
Keys.Add(DeviceProfileName);
}
}
// Check if any of the hotfixed device profiles are referenced by the currently active profile(s):
bHasPendingDeviceProfileHotfix = UDeviceProfileManager::Get().DoActiveProfilesReference(Keys);
UE_LOG(LogHotfixManager, Log, TEXT("Active device profile was referenced by hotfix = %d"), (uint32)bHasPendingDeviceProfileHotfix);
}
return Super::HotfixIniFile(FileName, IniData);
}
bool ULyraHotfixManager::ApplyHotfixProcessing(const FCloudFileHeader& FileHeader)
{
// This allows json files to be downloaded automatically
const FString Extension = FPaths::GetExtension(FileHeader.FileName);
if (Extension == TEXT("json"))
{
return true;
}
const bool bResult = Super::ApplyHotfixProcessing(FileHeader);
if (bResult && FileHeader.FileName.EndsWith(TEXT("GAME.INI"), ESearchCase::IgnoreCase))
{
GameHotfixCounter++;
if (bHasPendingGameHotfix)
{
bHasPendingGameHotfix = false;
OnPendingGameHotfixChanged.Broadcast(bHasPendingGameHotfix);
}
}
return bResult;
}
bool ULyraHotfixManager::ShouldWarnAboutMissingWhenPatchingFromIni(const FString& AssetPath) const
{
return AssetPath.StartsWith(TEXT("/Engine/")) || AssetPath.StartsWith(TEXT("/Game/"));
}
void ULyraHotfixManager::PatchAssetsFromIniFiles()
{
#if ENABLE_SHARED_MEMORY_TRACKER
FSharedMemoryTracker::PrintMemoryDiff(TEXT("Start - PatchAssetsFromIniFiles"));
#endif
Super::PatchAssetsFromIniFiles();
#if ENABLE_SHARED_MEMORY_TRACKER
FSharedMemoryTracker::PrintMemoryDiff(TEXT("End - PatchAssetsFromIniFiles"));
#endif
}
void ULyraHotfixManager::OnHotfixAvailablityCheck(const TArray<FCloudFileHeader>& PendingChangedFiles, const TArray<FCloudFileHeader>& PendingRemoveFiles)
{
bool bNewPendingGameHotfix = false;
for (int32 Idx = 0; Idx < PendingChangedFiles.Num(); Idx++)
{
if (PendingChangedFiles[Idx].FileName.EndsWith(TEXT("GAME.INI"), ESearchCase::IgnoreCase))
{
bNewPendingGameHotfix = true;
break;
}
}
if (bNewPendingGameHotfix && !bHasPendingGameHotfix)
{
bHasPendingGameHotfix = true;
OnPendingGameHotfixChanged.Broadcast(bHasPendingGameHotfix);
}
}
#if !UE_BUILD_SHIPPING
void ULyraHotfixManager::GetOnScreenMessages(TMultiMap<FCoreDelegates::EOnScreenMessageSeverity, FText>& OutMessages)
{
// TODO Any messages/errors.
}
#endif // !UE_BUILD_SHIPPING
void ULyraHotfixManager::RequestPatchAssetsFromIniFiles()
{
if (!RequestPatchAssetsHandle.IsValid())
{
RequestPatchAssetsHandle = FTSTicker::GetCoreTicker().AddTicker(FTickerDelegate::CreateWeakLambda(this, [this](float DeltaTime) {
RequestPatchAssetsHandle.Reset();
UE_LOG(LogHotfixManager, Display, TEXT("Hotfix manager re-calling PatchAssetsFromIniFiles due to new plugins"));
PatchAssetsFromIniFiles();
return false;
}));
}
}
void ULyraHotfixManager::StartHotfixProcess()
{
if (GIsEditor)
{
UE_LOG(LogHotfixManager, Display, TEXT("Hotfixing skipped in development mode."));
TriggerHotfixComplete(EHotfixResult::SuccessNoChange);
return;
}
#if ENABLE_SHARED_MEMORY_TRACKER
FSharedMemoryTracker::PrintMemoryDiff(TEXT("StartHotfixProcess"));
#endif
Super::StartHotfixProcess();
}
|