Ejemplo n.º 1
0
        private Object ReadAsset(AssetReader reader, AssetInfo assetInfo, long offset, int size)
        {
            Object asset = Collection.AssetFactory.CreateAsset(assetInfo);

            if (asset == null)
            {
                return(null);
            }

            reader.BaseStream.Position = offset;
            if (Config.IsGenerateGUIDByContent)
            {
                byte[] data = reader.ReadBytes(size);
#if !DEBUG
                try
#endif
                {
                    asset.Read(data);
                }
#if !DEBUG
                catch
                {
                    Logger.Instance.Log(LogType.Error, LogCategory.General, $"Version[{reader.Version}] '{Name}'");
                    throw;
                }
#endif

                using (MD5 md5 = MD5.Create())
                {
                    byte[] md5Hash = md5.ComputeHash(data);
                    assetInfo.GUID = new EngineGUID(md5Hash);
                }
            }
            else
            {
                using (AssetReader alignReader = new AssetReader(reader, offset))
                {
#if !DEBUG
                    try
#endif
                    {
                        asset.Read(alignReader);
                    }
#if !DEBUG
                    catch
                    {
                        Logger.Instance.Log(LogType.Error, LogCategory.General, $"Version[{reader.Version}] '{Name}'");
                        throw;
                    }
#endif
                }
                long read = reader.BaseStream.Position - offset;
                if (read != size)
                {
                    throw new Exception($"Read {read} but expected {size} for asset type {asset.ClassID}. Version[{reader.Version}] '{Name}'");
                }
            }
            return(asset);
        }
Ejemplo n.º 2
0
        public override void Read(AssetReader reader)
        {
            base.Read(reader);

            int fileCount = reader.ReadInt32();

            FilenameEntry[] files = new FilenameEntry[fileCount];
            for (int i = 0; i < fileCount; i++)
            {
                int    fileId = reader.ReadInt32();
                string file   = reader.ReadString();
                files[i] = new FilenameEntry(fileId, file);
            }

            int unknown = reader.ReadInt32();

            int hashCount = reader.ReadInt32();

            HashEntry[] hashes = new HashEntry[hashCount];
            try
            {
                for (int i = 0; i < hashCount; i++)
                {
                    int    fileId    = reader.ReadInt32();
                    byte[] hashBytes = reader.ReadBytes(16);

                    int trailer = reader.ReadInt32();
                    if (trailer != 0)
                    {
                        throw new InvalidDataException($"Expected trailer (0), got {trailer}");
                    }

                    hashes[i] = new HashEntry(fileId, hashBytes);
                }
            }
            catch (Exception ex)
            {
                Logger.Log(LogType.Info, LogCategory.Import, $"Failed to read hashes from asset bundle manifest, hash-table is incomplete: {ex.GetType().Name} -> {ex.Message}");
                byte[] buffer = new byte[4096];
                while (reader.Read(buffer, 0, buffer.Length) != 0)
                {
                    //yeet the remaining bytes into nowhere
                }

                for (int i = 0; i < hashes.Length; i++)
                {
                    if (hashes[i] == null)
                    {
                        hashes[i] = new HashEntry(-1, new byte[0]);
                    }
                }
            }

            FileEntries = files;
            HashEntries = hashes;
        }
Ejemplo n.º 3
0
        private Object ReadAsset(AssetReader reader, AssetInfo assetInfo, long offset, int size)
        {
            Object asset = Collection.AssetFactory.CreateAsset(assetInfo);

            if (asset == null)
            {
                return(null);
            }

            reader.BaseStream.Position = offset;
            if (Config.IsGenerateGUIDByContent)
            {
                byte[] data = reader.ReadBytes(size);
#if !DEBUG
                try
#endif
                {
                    asset.Read(data);
                }
#if !DEBUG
                catch (Exception ex)
                {
                    throw new SerializedFileException($"Error during reading asset type {asset.ClassID}", ex, Version, Name, FilePath);
                }
#endif

                using (MD5 md5 = MD5.Create())
                {
                    byte[] md5Hash = md5.ComputeHash(data);
                    assetInfo.GUID = new EngineGUID(md5Hash);
                }
            }
            else
            {
#if !DEBUG
                try
#endif
                {
                    asset.Read(reader);
                }
#if !DEBUG
                catch (Exception ex)
                {
                    throw new SerializedFileException($"Error during reading asset type {asset.ClassID}", ex, Version, Name, FilePath);
                }
#endif
                long read = reader.BaseStream.Position - offset;
                if (read != size)
                {
                    throw new SerializedFileException($"Read {read} but expected {size} for asset type {asset.ClassID}", Version, Name, FilePath);
                }
            }
            return(asset);
        }