Skip to content

Commit

Permalink
Ue5.0.3 (hxhb#58)
Browse files Browse the repository at this point in the history
* fix 4.26+ run error

* fix crash issue

* 适配ue5.0.3

Co-authored-by: hxhb <[email protected]>
Co-authored-by: wujun1 <[email protected]>
  • Loading branch information
3 people authored Sep 6, 2022
1 parent 20322b0 commit 215c1e6
Show file tree
Hide file tree
Showing 13 changed files with 157 additions and 76 deletions.
2 changes: 1 addition & 1 deletion HotPatcher/Source/CookerWriterForUE5/CookerWriterForUE5.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#pragma once

#if ENGINE_MAJOR_VERSION > 4 && ENGINE_MINOR_VERSION > 0
#if ENGINE_MAJOR_VERSION > 4 /*&& ENGINE_MINOR_VERSION > 0*/
#include "ZenStoreWriter.h"
#include "PackageNameCache.h"
#include "LooseCookedPackageWriter.h"
Expand Down
128 changes: 76 additions & 52 deletions HotPatcher/Source/CookerWriterForUE5/LooseCookedPackageWriter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -80,25 +80,28 @@ TFuture<FMD5Hash> FLooseCookedPackageWriter::AsyncSave(FRecord& Record, const FC
return AsyncSaveOutputFiles(Record, Context);
}

void FLooseCookedPackageWriter::CompleteExportsArchiveForDiff(FName PackageName, FLargeMemoryWriter& ExportsArchive)
void FLooseCookedPackageWriter::CompleteExportsArchiveForDiff(const FPackageInfo& Info, FLargeMemoryWriter& ExportsArchive)
{
FPackageWriterRecords::FPackage& BaseRecord = Records.FindRecordChecked(PackageName);
FPackageWriterRecords::FPackage& BaseRecord = Records.FindRecordChecked(Info.InputPackageName);
FRecord& Record = static_cast<FRecord&>(BaseRecord);
Record.bCompletedExportsArchiveForDiff = true;

// Add on all the attachments which are usually added on during Commit. The order must match AsyncSave.
for (FBulkDataRecord& BulkRecord : Record.BulkDatas)
{
if (BulkRecord.Info.BulkDataType == FBulkDataInfo::AppendToExports)
if (BulkRecord.Info.BulkDataType == FBulkDataInfo::AppendToExports && BulkRecord.Info.MultiOutputIndex == Info.MultiOutputIndex)
{
ExportsArchive.Serialize(const_cast<void*>(BulkRecord.Buffer.GetData()),
BulkRecord.Buffer.GetSize());
}
}
for (FLinkerAdditionalDataRecord& AdditionalRecord : Record.LinkerAdditionalDatas)
{
ExportsArchive.Serialize(const_cast<void*>(AdditionalRecord.Buffer.GetData()),
AdditionalRecord.Buffer.GetSize());
if (AdditionalRecord.Info.MultiOutputIndex == Info.MultiOutputIndex)
{
ExportsArchive.Serialize(const_cast<void*>(AdditionalRecord.Buffer.GetData()),
AdditionalRecord.Buffer.GetSize());
}
}

uint32 FooterData = PACKAGE_FILE_TAG;
Expand All @@ -108,7 +111,11 @@ void FLooseCookedPackageWriter::CompleteExportsArchiveForDiff(FName PackageName,

void FLooseCookedPackageWriter::CollectForSavePackageData(FRecord& Record, FCommitContext& Context)
{
Context.ExportsBuffers.Add(FExportBuffer{ Record.Package->Buffer, MoveTemp(Record.Package->Regions) });
Context.ExportsBuffers.AddDefaulted(Record.Packages.Num());
for (FPackageWriterRecords::FWritePackage& Package : Record.Packages)
{
Context.ExportsBuffers[Package.Info.MultiOutputIndex].Add(FExportBuffer{ Package.Buffer, MoveTemp(Package.Regions) });
}
}

void FLooseCookedPackageWriter::CollectForSaveBulkData(FRecord& Record, FCommitContext& Context)
Expand All @@ -122,7 +129,7 @@ void FLooseCookedPackageWriter::CollectForSaveBulkData(FRecord& Record, FCommitC
// Already Added in CompleteExportsArchiveForDiff
continue;
}
Context.ExportsBuffers.Add(FExportBuffer{ BulkRecord.Buffer, MoveTemp(BulkRecord.Regions) });
Context.ExportsBuffers[BulkRecord.Info.MultiOutputIndex].Add(FExportBuffer{ BulkRecord.Buffer, MoveTemp(BulkRecord.Regions) });
}
else
{
Expand All @@ -132,6 +139,7 @@ void FLooseCookedPackageWriter::CollectForSaveBulkData(FRecord& Record, FCommitC
OutputFile.Buffer = FCompositeBuffer(BulkRecord.Buffer);
OutputFile.Regions = MoveTemp(BulkRecord.Regions);
OutputFile.bIsSidecar = true;
OutputFile.bContributeToHash = BulkRecord.Info.MultiOutputIndex == 0; // Only caculate the main package output hash
}
}
}
Expand All @@ -145,7 +153,7 @@ void FLooseCookedPackageWriter::CollectForSaveLinkerAdditionalDataRecords(FRecor

for (FLinkerAdditionalDataRecord& AdditionalRecord : Record.LinkerAdditionalDatas)
{
Context.ExportsBuffers.Add(FExportBuffer{ AdditionalRecord.Buffer, MoveTemp(AdditionalRecord.Regions) });
Context.ExportsBuffers[AdditionalRecord.Info.MultiOutputIndex].Add(FExportBuffer{ AdditionalRecord.Buffer, MoveTemp(AdditionalRecord.Regions) });
}
}

Expand All @@ -157,6 +165,7 @@ void FLooseCookedPackageWriter::CollectForSaveAdditionalFileRecords(FRecord& Rec
OutputFile.Filename = AdditionalRecord.Info.Filename;
OutputFile.Buffer = FCompositeBuffer(AdditionalRecord.Buffer);
OutputFile.bIsSidecar = true;
OutputFile.bContributeToHash = AdditionalRecord.Info.MultiOutputIndex == 0; // Only calculate the main package output hash
}
}

Expand All @@ -170,57 +179,68 @@ void FLooseCookedPackageWriter::CollectForSaveExportsFooter(FRecord& Record, FCo

uint32 FooterData = PACKAGE_FILE_TAG;
FSharedBuffer Buffer = FSharedBuffer::Clone(&FooterData, sizeof(FooterData));
Context.ExportsBuffers.Add(FExportBuffer{ Buffer, TArray<FFileRegion>() });
for (FPackageWriterRecords::FWritePackage& Package : Record.Packages)
{
Context.ExportsBuffers[Package.Info.MultiOutputIndex].Add(FExportBuffer{ Buffer, TArray<FFileRegion>() });
}
}

void FLooseCookedPackageWriter::AddToExportsSize(int32& ExportsSize)
void FLooseCookedPackageWriter::AddToExportsSize(int64& ExportsSize)
{
ExportsSize += sizeof(uint32); // Footer size
}

void FLooseCookedPackageWriter::CollectForSaveExportsBuffers(FRecord& Record, FCommitContext& Context)
{
// Split the ExportsBuffer into (1) Header and (2) Exports + AllAppendedData
int64 HeaderSize = Record.Package->Info.HeaderSize;
check(Context.ExportsBuffers.Num() > 0);
FExportBuffer& HeaderAndExportsBuffer = Context.ExportsBuffers[0];
FSharedBuffer& HeaderAndExportsData = HeaderAndExportsBuffer.Buffer;

// Header (.uasset/.umap)
check(Context.ExportsBuffers.Num() == Record.Packages.Num());
for (FPackageWriterRecords::FWritePackage& Package : Record.Packages)
{
FWriteFileData& OutputFile = Context.OutputFiles.Emplace_GetRef();
OutputFile.Filename = Record.Begin.LooseFilePath;
OutputFile.Buffer = FCompositeBuffer(
FSharedBuffer::MakeView(HeaderAndExportsData.GetData(), HeaderSize, HeaderAndExportsData));
OutputFile.bIsSidecar = false;
}
TArray<FExportBuffer>& ExportsBuffers = Context.ExportsBuffers[Package.Info.MultiOutputIndex];
check(ExportsBuffers.Num() > 0);

// Exports + AllAppendedData (.uexp)
{
FWriteFileData& OutputFile = Context.OutputFiles.Emplace_GetRef();
OutputFile.Filename = FPaths::ChangeExtension(Record.Begin.LooseFilePath, LexToString(EPackageExtension::Exports));
OutputFile.bIsSidecar = false;
// Split the ExportsBuffer into (1) Header and (2) Exports + AllAppendedData
int64 HeaderSize = Package.Info.HeaderSize;
FExportBuffer& HeaderAndExportsBuffer = ExportsBuffers[0];
FSharedBuffer& HeaderAndExportsData = HeaderAndExportsBuffer.Buffer;

int32 NumBuffers = Context.ExportsBuffers.Num();
TArray<FSharedBuffer> BuffersForComposition;
BuffersForComposition.Reserve(NumBuffers);

const uint8* ExportsStart = static_cast<const uint8*>(HeaderAndExportsData.GetData()) + HeaderSize;
BuffersForComposition.Add(FSharedBuffer::MakeView(ExportsStart, HeaderAndExportsData.GetSize() - HeaderSize,
HeaderAndExportsData));
OutputFile.Regions.Append(MoveTemp(HeaderAndExportsBuffer.Regions));

for (FExportBuffer& ExportsBuffer : TArrayView<FExportBuffer>(Context.ExportsBuffers).Slice(1, NumBuffers - 1))
// Header (.uasset/.umap)
{
BuffersForComposition.Add(ExportsBuffer.Buffer);
OutputFile.Regions.Append(MoveTemp(ExportsBuffer.Regions));
FWriteFileData& OutputFile = Context.OutputFiles.Emplace_GetRef();
OutputFile.Filename = Package.Info.LooseFilePath;
OutputFile.Buffer = FCompositeBuffer(
FSharedBuffer::MakeView(HeaderAndExportsData.GetData(), HeaderSize, HeaderAndExportsData));
OutputFile.bIsSidecar = false;
OutputFile.bContributeToHash = Package.Info.MultiOutputIndex == 0; // Only calculate the main package output hash
}
OutputFile.Buffer = FCompositeBuffer(BuffersForComposition);

// Adjust regions so they are relative to the start of the uexp file
for (FFileRegion& Region : OutputFile.Regions)
// Exports + AllAppendedData (.uexp)
{
Region.Offset -= HeaderSize;
FWriteFileData& OutputFile = Context.OutputFiles.Emplace_GetRef();
OutputFile.Filename = FPaths::ChangeExtension(Package.Info.LooseFilePath, LexToString(EPackageExtension::Exports));
OutputFile.bIsSidecar = false;
OutputFile.bContributeToHash = Package.Info.MultiOutputIndex == 0; // Only caculate the main package output hash

int32 NumBuffers = ExportsBuffers.Num();
TArray<FSharedBuffer> BuffersForComposition;
BuffersForComposition.Reserve(NumBuffers);

const uint8* ExportsStart = static_cast<const uint8*>(HeaderAndExportsData.GetData()) + HeaderSize;
BuffersForComposition.Add(FSharedBuffer::MakeView(ExportsStart, HeaderAndExportsData.GetSize() - HeaderSize,
HeaderAndExportsData));
OutputFile.Regions.Append(MoveTemp(HeaderAndExportsBuffer.Regions));

for (FExportBuffer& ExportsBuffer : TArrayView<FExportBuffer>(ExportsBuffers).Slice(1, NumBuffers - 1))
{
BuffersForComposition.Add(ExportsBuffer.Buffer);
OutputFile.Regions.Append(MoveTemp(ExportsBuffer.Regions));
}
OutputFile.Buffer = FCompositeBuffer(BuffersForComposition);

// Adjust regions so they are relative to the start of the uexp file
for (FFileRegion& Region : OutputFile.Regions)
{
Region.Offset -= HeaderSize;
}
}
}
}
Expand Down Expand Up @@ -286,7 +306,8 @@ static void WriteToFile(const FString& Filename, const FCompositeBuffer& Buffer)

void FLooseCookedPackageWriter::FWriteFileData::Write(FMD5& AccumulatedHash, EWriteOptions WriteOptions) const
{
if (EnumHasAnyFlags(WriteOptions, EWriteOptions::ComputeHash))
//@todo: FH: Should we calculate the hash of both output, currently only the main package output hash is calculated
if (EnumHasAnyFlags(WriteOptions, EWriteOptions::ComputeHash) && bContributeToHash)
{
for (const FSharedBuffer& Segment : Buffer.GetSegments())
{
Expand Down Expand Up @@ -321,17 +342,20 @@ void FLooseCookedPackageWriter::FWriteFileData::Write(FMD5& AccumulatedHash, EWr

void FLooseCookedPackageWriter::UpdateManifest(FRecord& Record)
{
FName PackageName = Record.Begin.PackageName;
FIoChunkId ChunkId = CreateIoChunkId(FPackageId::FromName(PackageName).Value(), 0, EIoChunkType::ExportBundleData);
PackageStoreManifest.AddPackageData(PackageName, Record.Begin.LooseFilePath, ChunkId);
for (const FPackageWriterRecords::FWritePackage& Package : Record.Packages)
{
PackageStoreManifest.AddPackageData(Package.Info.InputPackageName, Package.Info.OutputPackageName, Package.Info.LooseFilePath, Package.Info.ChunkId);
}
for (const FPackageWriterRecords::FBulkData& BulkData : Record.BulkDatas)
{
PackageStoreManifest.AddBulkData(BulkData.Info.InputPackageName, BulkData.Info.OutputPackageName, BulkData.Info.LooseFilePath, BulkData.Info.ChunkId);
}
}

bool FLooseCookedPackageWriter::GetPreviousCookedBytes(FName PackageName, FPreviousCookedBytesData& OutData)
bool FLooseCookedPackageWriter::GetPreviousCookedBytes(const FPackageInfo& Info, FPreviousCookedBytesData& OutData)
{
FPackageWriterRecords::FPackage& BaseRecord = Records.FindRecordChecked(PackageName);
FRecord& Record = static_cast<FRecord&>(BaseRecord);
FArchiveStackTrace::FPackageData ExistingPackageData;
FArchiveStackTrace::LoadPackageIntoMemory(*Record.Begin.LooseFilePath, ExistingPackageData, OutData.Data);
FArchiveStackTrace::LoadPackageIntoMemory(*Info.LooseFilePath, ExistingPackageData, OutData.Data);
OutData.Size = ExistingPackageData.Size;
OutData.HeaderSize = ExistingPackageData.HeaderSize;
OutData.StartOffset = ExistingPackageData.StartOffset;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ class FLooseCookedPackageWriter : public TPackageWriterToSharedBuffer<ICookedPac
}

virtual void BeginPackage(const FBeginPackageInfo& Info) override;
virtual void AddToExportsSize(int32& ExportsSize) override;
virtual void AddToExportsSize(int64& ExportsSize) override;

virtual FDateTime GetPreviousCookTime() const override;
virtual void Initialize(const FCookInfo& Info) override;
Expand All @@ -46,8 +46,8 @@ class FLooseCookedPackageWriter : public TPackageWriterToSharedBuffer<ICookedPac
virtual void RemoveCookedPackages(TArrayView<const FName> PackageNamesToRemove) override;
virtual void RemoveCookedPackages() override;
virtual void MarkPackagesUpToDate(TArrayView<const FName> UpToDatePackages) override;
virtual bool GetPreviousCookedBytes(FName PackageName, FPreviousCookedBytesData& OutData) override;
virtual void CompleteExportsArchiveForDiff(FName PackageName, FLargeMemoryWriter& ExportsArchive) override;
virtual bool GetPreviousCookedBytes(const FPackageInfo& Info, FPreviousCookedBytesData& OutData) override;
virtual void CompleteExportsArchiveForDiff(const FPackageInfo& Info, FLargeMemoryWriter& ExportsArchive) override;
virtual TFuture<FMD5Hash> CommitPackageInternal(FPackageWriterRecords::FPackage&& BaseRecord,
const FCommitPackageInfo& Info) override;
virtual FPackageWriterRecords::FPackage* ConstructRecord() override;
Expand Down Expand Up @@ -78,6 +78,7 @@ class FLooseCookedPackageWriter : public TPackageWriterToSharedBuffer<ICookedPac
FCompositeBuffer Buffer;
TArray<FFileRegion> Regions;
bool bIsSidecar;
bool bContributeToHash = true;

void Write(FMD5& AccumulatedHash, EWriteOptions WriteOptions) const;
};
Expand All @@ -86,7 +87,7 @@ class FLooseCookedPackageWriter : public TPackageWriterToSharedBuffer<ICookedPac
struct FCommitContext
{
const FCommitPackageInfo& Info;
TArray<FExportBuffer> ExportsBuffers;
TArray<TArray<FExportBuffer>> ExportsBuffers;
TArray<FWriteFileData> OutputFiles;
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ class FPackageWriterRecords
/** Always valid during CommitPackageInternal */
IPackageWriter::FBeginPackageInfo Begin;
/** Always valid during CommitPackageInternal if Info.bSucceeded */
TOptional<FWritePackage> Package;
TArray<FWritePackage> Packages;
TArray<FBulkData> BulkDatas;
TArray<FAdditionalFile> AdditionalFiles;
TArray<FLinkerAdditionalData> LinkerAdditionalDatas;
Expand Down
4 changes: 2 additions & 2 deletions HotPatcher/Source/HotPatcherCore/HotPatcherCore.Build.cs
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ public HotPatcherCore(ReadOnlyTargetRules Target) : base(Target)

bool bEnablePackageContext = true;
AddPublicDefinitions("WITH_PACKAGE_CONTEXT", (Version.MajorVersion > 4 || Version.MinorVersion > 23) && bEnablePackageContext);
if (Version.MajorVersion > 4 || Version.MajorVersion > 26)
if (Version.MajorVersion > 4 || Version.MinorVersion > 26)
{
PublicDependencyModuleNames.AddRange(new string[]
{
Expand All @@ -176,7 +176,7 @@ public HotPatcherCore(ReadOnlyTargetRules Target) : base(Target)
});
}

if (Version.MajorVersion > 4 && Version.MinorVersion > 0)
if (Version.MajorVersion > 4 /*&& Version.MinorVersion > 0*/)
{
PublicIncludePaths.AddRange(new List<string>()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,11 @@ void USingleCookerProxy::CleanClusterCachedPlatformData(const FCookCluster& Cook
}
ExportObj->ClearAllCachedCookedPlatformData();
}
#if ENGINE_MAJOR_VERSION > 4
Package->MarkAsGarbage();
#else
Package->MarkPendingKill();
#endif
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,8 +101,10 @@ namespace ReleaseWorker
{
AllConfigPlatformSet.Add(PlatformsPakListFile.TargetPlatform);
}

AddProjectDirToTarget = AllConfigPlatformSet.Num() > 1 ? ETargetPlatform::AllPlatforms : AllConfigPlatformSet.Array()[0];
if(AllConfigPlatformSet.Num())
{
AddProjectDirToTarget = AllConfigPlatformSet.Num() > 1 ? ETargetPlatform::AllPlatforms : AllConfigPlatformSet.Array()[0];
}

UFlibHotPatcherCoreHelper::ImportProjectNotAssetDir(Context.GetSettingObject()->GetAddExternAssetsToPlatform(),AddProjectDirToTarget);
}
Expand Down
Loading

0 comments on commit 215c1e6

Please sign in to comment.