BuiltinVersionListSerializer.ResourcePackVersionListDeserializeCallback.cs 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. //------------------------------------------------------------
  2. // Game Framework
  3. // Copyright © 2013-2021 loyalsoft. All rights reserved.
  4. // Homepage: http://www.game7000.com/
  5. // Feedback: http://www.game7000.com/
  6. //------------------------------------------------------------
  7. using GameFramework.Resource;
  8. using System.IO;
  9. using System.Text;
  10. namespace UnityGameFramework.Runtime
  11. {
  12. /// <summary>
  13. /// 内置版本资源列表序列化器。
  14. /// </summary>
  15. public static partial class BuiltinVersionListSerializer
  16. {
  17. /// <summary>
  18. /// 反序列化资源包版本资源列表(版本 0)回调函数。
  19. /// </summary>
  20. /// <param name="stream">指定流。</param>
  21. /// <returns>反序列化的资源包版本资源列表(版本 0)。</returns>
  22. public static ResourcePackVersionList ResourcePackVersionListDeserializeCallback_V0(Stream stream)
  23. {
  24. using (BinaryReader binaryReader = new BinaryReader(stream, Encoding.UTF8))
  25. {
  26. byte[] encryptBytes = binaryReader.ReadBytes(CachedHashBytesLength);
  27. int dataOffset = binaryReader.ReadInt32();
  28. long dataLength = binaryReader.ReadInt64();
  29. int dataHashCode = binaryReader.ReadInt32();
  30. int resourceCount = binaryReader.Read7BitEncodedInt32();
  31. ResourcePackVersionList.Resource[] resources = resourceCount > 0 ? new ResourcePackVersionList.Resource[resourceCount] : null;
  32. for (int i = 0; i < resourceCount; i++)
  33. {
  34. string name = binaryReader.ReadEncryptedString(encryptBytes);
  35. string variant = binaryReader.ReadEncryptedString(encryptBytes);
  36. string extension = binaryReader.ReadEncryptedString(encryptBytes) ?? DefaultExtension;
  37. byte loadType = binaryReader.ReadByte();
  38. long offset = binaryReader.Read7BitEncodedInt64();
  39. int length = binaryReader.Read7BitEncodedInt32();
  40. int hashCode = binaryReader.ReadInt32();
  41. int compressedLength = binaryReader.Read7BitEncodedInt32();
  42. int compressedHashCode = binaryReader.ReadInt32();
  43. resources[i] = new ResourcePackVersionList.Resource(name, variant, extension, loadType, offset, length, hashCode, compressedLength, compressedHashCode);
  44. }
  45. return new ResourcePackVersionList(dataOffset, dataLength, dataHashCode, resources);
  46. }
  47. }
  48. }
  49. }