bool FPackageReader::ReadAssetRegistryDataIfCookedPackage(TArray<FAssetData*>& AssetDataList, TArray<FString>& CookedPackageNamesWithoutAssetData) { if (!!(GetPackageFlags() & PKG_FilterEditorOnly)) { const FString PackageName = FPackageName::FilenameToLongPackageName(PackageFilename); bool bFoundAtLeastOneAsset = false; // If the packaged is saved with the right version we have the information // which of the objects in the export map as the asset. // Otherwise we need to store a temp minimal data and then force load the asset // to re-generate its registry data if (UE4Ver() >= VER_UE4_COOKED_ASSETS_IN_EDITOR_SUPPORT) { const FString PackagePath = FPackageName::GetLongPackagePath(PackageName); TArray<FObjectImport> ImportMap; TArray<FObjectExport> ExportMap; SerializeNameMap(); SerializeImportMap(ImportMap); SerializeExportMap(ExportMap); for (FObjectExport& Export : ExportMap) { if (Export.bIsAsset) { FString GroupNames; // Not used for anything TMap<FName, FString> Tags; // Not used for anything TArray<int32> ChunkIDs; // Not used for anything // We need to get the class name from the import/export maps FName ObjectClassName; if (Export.ClassIndex.IsNull()) { ObjectClassName = UClass::StaticClass()->GetFName(); } else if (Export.ClassIndex.IsExport()) { const FObjectExport& ClassExport = ExportMap[Export.ClassIndex.ToExport()]; ObjectClassName = ClassExport.ObjectName; } else if (Export.ClassIndex.IsImport()) { const FObjectImport& ClassImport = ImportMap[Export.ClassIndex.ToImport()]; ObjectClassName = ClassImport.ObjectName; } AssetDataList.Add(new FAssetData(FName(*PackageName), FName(*PackagePath), FName(*GroupNames), Export.ObjectName, ObjectClassName, Tags, ChunkIDs, GetPackageFlags())); bFoundAtLeastOneAsset = true; } } } if (!bFoundAtLeastOneAsset) { CookedPackageNamesWithoutAssetData.Add(PackageName); } return true; } return false; }
void FPackageReader::SerializeStringAssetReferencesMap(TArray<FString>& OutStringAssetReferencesMap) { if (UE4Ver() >= VER_UE4_ADD_STRING_ASSET_REFERENCES_MAP && PackageFileSummary.StringAssetReferencesCount > 0) { Seek(PackageFileSummary.StringAssetReferencesOffset); if (UE4Ver() < VER_UE4_KEEP_ONLY_PACKAGE_NAMES_IN_STRING_ASSET_REFERENCES_MAP) { for (int32 ReferenceIdx = 0; ReferenceIdx < PackageFileSummary.StringAssetReferencesCount; ++ReferenceIdx) { FString Buf; *this << Buf; if (GetIniFilenameFromObjectsReference(Buf) != nullptr) { OutStringAssetReferencesMap.AddUnique(MoveTemp(Buf)); } else { FString NormalizedPath = FPackageName::GetNormalizedObjectPath(MoveTemp(Buf)); if (!NormalizedPath.IsEmpty()) { OutStringAssetReferencesMap.AddUnique( FPackageName::ObjectPathToPackageName( NormalizedPath ) ); } } } } else { for (int32 ReferenceIdx = 0; ReferenceIdx < PackageFileSummary.StringAssetReferencesCount; ++ReferenceIdx) { FString Buf; *this << Buf; OutStringAssetReferencesMap.Add(MoveTemp(Buf)); } } } }
FArchive& FArchiveUObject::operator<<(struct FStringAssetReference& Value) { FString Path = Value.ToString(); *this << Path; if (IsLoading()) { if (UE4Ver() < VER_UE4_KEEP_ONLY_PACKAGE_NAMES_IN_STRING_ASSET_REFERENCES_MAP) { FString NormalizedPath = FPackageName::GetNormalizedObjectPath(Path); if (Value.ToString() != NormalizedPath) { Value.SetPath(NormalizedPath); } } else { Value.SetPath(MoveTemp(Path)); } } return *this; }