/// <summary> /// 反序列化可更新模式版本资源列表(版本 2)回调函数。 /// </summary> /// <param name="binaryReader">指定流。</param> /// <returns>反序列化的可更新模式版本资源列表(版本 2)。</returns> public static UpdatableVersionList UpdatableVersionListDeserializeCallback_V2(BinaryReader binaryReader) { byte[] encryptBytes = binaryReader.ReadBytes(CachedHashBytesLength); string applicableGameVersion = binaryReader.ReadEncryptedString(encryptBytes); string internalResourceVersion = binaryReader.ReadEncryptedString(encryptBytes); int assetCount = binaryReader.Read7BitEncodedInt32(); UpdatableVersionList.Asset[] assets = assetCount > 0 ? new UpdatableVersionList.Asset[assetCount] : null; for (int i = 0; i < assetCount; i++) { string name = binaryReader.ReadEncryptedString(encryptBytes); AssetCategory assetCategory = (AssetCategory)binaryReader.ReadByte(); int dependencyAssetCount = binaryReader.Read7BitEncodedInt32(); int[] dependencyAssetIndexes = dependencyAssetCount > 0 ? new int[dependencyAssetCount] : null; for (int j = 0; j < dependencyAssetCount; j++) { dependencyAssetIndexes[j] = binaryReader.Read7BitEncodedInt32(); } assets[i] = new UpdatableVersionList.Asset(name, dependencyAssetIndexes, assetCategory); } int resourceCount = binaryReader.Read7BitEncodedInt32(); UpdatableVersionList.Resource[] resources = resourceCount > 0 ? new UpdatableVersionList.Resource[resourceCount] : null; for (int i = 0; i < resourceCount; i++) { string name = binaryReader.ReadEncryptedString(encryptBytes); string variant = binaryReader.ReadEncryptedString(encryptBytes); string extension = binaryReader.ReadEncryptedString(encryptBytes) ?? DefaultExtension; byte loadType = binaryReader.ReadByte(); int length = binaryReader.Read7BitEncodedInt32(); int hashCode = binaryReader.ReadInt32(); int zipLength = binaryReader.Read7BitEncodedInt32(); int zipHashCode = binaryReader.ReadInt32(); AssetCategory assetCategory = (AssetCategory)binaryReader.ReadByte(); int assetIndexCount = binaryReader.Read7BitEncodedInt32(); int[] assetIndexes = assetIndexCount > 0 ? new int[assetIndexCount] : null; for (int j = 0; j < assetIndexCount; j++) { assetIndexes[j] = binaryReader.Read7BitEncodedInt32(); } resources[i] = new UpdatableVersionList.Resource(name, variant, extension, loadType, length, hashCode, zipLength, zipHashCode, assetIndexes, assetCategory); } int fileSystemCount = binaryReader.Read7BitEncodedInt32(); UpdatableVersionList.FileSystem[] fileSystems = fileSystemCount > 0 ? new UpdatableVersionList.FileSystem[fileSystemCount] : null; for (int i = 0; i < fileSystemCount; i++) { string name = binaryReader.ReadEncryptedString(encryptBytes); int resourceIndexCount = binaryReader.Read7BitEncodedInt32(); int[] resourceIndexes = resourceIndexCount > 0 ? new int[resourceIndexCount] : null; for (int j = 0; j < resourceIndexCount; j++) { resourceIndexes[j] = binaryReader.Read7BitEncodedInt32(); } fileSystems[i] = new UpdatableVersionList.FileSystem(name, resourceIndexes); } int resourceGroupCount = binaryReader.Read7BitEncodedInt32(); UpdatableVersionList.ResourceGroup[] resourceGroups = resourceGroupCount > 0 ? new UpdatableVersionList.ResourceGroup[resourceGroupCount] : null; for (int i = 0; i < resourceGroupCount; i++) { string name = binaryReader.ReadEncryptedString(encryptBytes); int resourceIndexCount = binaryReader.Read7BitEncodedInt32(); int[] resourceIndexes = resourceIndexCount > 0 ? new int[resourceIndexCount] : null; for (int j = 0; j < resourceIndexCount; j++) { resourceIndexes[j] = binaryReader.Read7BitEncodedInt32(); } resourceGroups[i] = new UpdatableVersionList.ResourceGroup(name, resourceIndexes); } return(new UpdatableVersionList(applicableGameVersion, internalResourceVersion, assets, resources, fileSystems, resourceGroups)); }
/// <summary> /// 反序列化可更新模式版本资源列表(版本 0)回调函数。 /// </summary> /// <param name="binaryReader">指定流。</param> /// <returns>反序列化的可更新模式版本资源列表(版本 0)。</returns> public static UpdatableVersionList UpdatableVersionListDeserializeCallback_V0(BinaryReader binaryReader) { byte[] encryptBytes = binaryReader.ReadBytes(CachedHashBytesLength); string applicableGameVersion = binaryReader.ReadEncryptedString(encryptBytes); string internalResourceVersion = binaryReader.ReadEncryptedString(encryptBytes); int assetCount = binaryReader.ReadInt32(); UpdatableVersionList.Asset[] assets = assetCount > 0 ? new UpdatableVersionList.Asset[assetCount] : null; int resourceCount = binaryReader.ReadInt32(); UpdatableVersionList.Resource[] resources = resourceCount > 0 ? new UpdatableVersionList.Resource[resourceCount] : null; string[][] resourceToAssetNames = new string[resourceCount][]; List <KeyValuePair <string, Dictionary <string, AssetCategory> > > assetNameToDependencyAssetNames = new List <KeyValuePair <string, Dictionary <string, AssetCategory> > >(assetCount); List <KeyValuePair <string, AssetCategory> > assetNameToDependencyAssetCategory = new List <KeyValuePair <string, AssetCategory> >(assetCount); for (int i = 0; i < resourceCount; i++) { string name = binaryReader.ReadEncryptedString(encryptBytes); string variant = binaryReader.ReadEncryptedString(encryptBytes); byte loadType = binaryReader.ReadByte(); int length = binaryReader.ReadInt32(); int hashCode = binaryReader.ReadInt32(); int zipLength = binaryReader.ReadInt32(); int zipHashCode = binaryReader.ReadInt32(); AssetCategory assetCategory = (AssetCategory)binaryReader.ReadByte(); Utility.Converter.GetBytes(hashCode, s_CachedHashBytes); int assetNameCount = binaryReader.ReadInt32(); string[] assetNames = assetNameCount > 0 ? new string[assetNameCount] : null; for (int j = 0; j < assetNameCount; j++) { assetNames[j] = binaryReader.ReadEncryptedString(s_CachedHashBytes); AssetCategory dependencyAssetCategory = (AssetCategory)binaryReader.ReadByte(); int dependencyAssetNameCount = binaryReader.ReadInt32(); Dictionary <string, AssetCategory> dependencyAssetNames = dependencyAssetNameCount > 0 ? new Dictionary <string, AssetCategory>(dependencyAssetNameCount) : null; for (int k = 0; k < dependencyAssetNameCount; k++) { string dependencyAssetName = binaryReader.ReadEncryptedString(s_CachedHashBytes); AssetCategory dependencyAssetCategory2 = (AssetCategory)binaryReader.ReadByte(); dependencyAssetNames[dependencyAssetName] = dependencyAssetCategory2; } assetNameToDependencyAssetNames.Add(new KeyValuePair <string, Dictionary <string, AssetCategory> >(assetNames[j], dependencyAssetNames)); assetNameToDependencyAssetCategory.Add(new KeyValuePair <string, AssetCategory>(assetNames[j], dependencyAssetCategory)); } resourceToAssetNames[i] = assetNames; resources[i] = new UpdatableVersionList.Resource(name, variant, null, loadType, length, hashCode, zipLength, zipHashCode, assetNameCount > 0 ? new int[assetNameCount] : null, assetCategory); } assetNameToDependencyAssetNames.Sort(AssetNameToDependencyAssetNamesComparer); assetNameToDependencyAssetCategory.Sort(AssetNameToDependencyAssetNamesComparer); Array.Clear(s_CachedHashBytes, 0, CachedHashBytesLength); int index = 0; int index2 = 0; foreach (KeyValuePair <string, Dictionary <string, AssetCategory> > i in assetNameToDependencyAssetNames) { if (i.Value != null) { int[] dependencyAssetIndexes = new int[i.Value.Count]; int dependencyAssetIndexe = 0; foreach (var item in i.Value) { dependencyAssetIndexes[dependencyAssetIndexe] = GetAssetNameIndex(assetNameToDependencyAssetNames, item.Key); dependencyAssetIndexe += 1; } assets[index++] = new UpdatableVersionList.Asset(i.Key, dependencyAssetIndexes, assetNameToDependencyAssetCategory[index2].Value); } else { assets[index++] = new UpdatableVersionList.Asset(i.Key, null, assetNameToDependencyAssetCategory[index2].Value); } index2 += 1; } for (int i = 0; i < resources.Length; i++) { int[] assetIndexes = resources[i].GetAssetIndexes(); for (int j = 0; j < assetIndexes.Length; j++) { assetIndexes[j] = GetAssetNameIndex(assetNameToDependencyAssetNames, resourceToAssetNames[i][j]); } } int resourceGroupCount = binaryReader.ReadInt32(); UpdatableVersionList.ResourceGroup[] resourceGroups = resourceGroupCount > 0 ? new UpdatableVersionList.ResourceGroup[resourceGroupCount] : null; for (int i = 0; i < resourceGroupCount; i++) { string name = binaryReader.ReadEncryptedString(encryptBytes); int resourceIndexCount = binaryReader.ReadInt32(); int[] resourceIndexes = resourceIndexCount > 0 ? new int[resourceIndexCount] : null; for (int j = 0; j < resourceIndexCount; j++) { resourceIndexes[j] = binaryReader.ReadUInt16(); } resourceGroups[i] = new UpdatableVersionList.ResourceGroup(name, resourceIndexes); } return(new UpdatableVersionList(applicableGameVersion, internalResourceVersion, assets, resources, null, resourceGroups)); }