Exemplo n.º 1
0
        private static FileType CheckFileType(EndianBinaryReader reader)
        {
            var signature = reader.ReadStringToNull(20);

            reader.Position = 0;
            switch (signature)
            {
            case "UnityWeb":
            case "UnityRaw":
            case "UnityArchive":
            case "UnityFS":
                return(FileType.BundleFile);

            case "UnityWebData1.0":
                return(FileType.WebFile);

            case "MXENGINEMXR":
            case "DIGILOCAPLY":
                return(FileType.MxrFile);

            default:
            {
                var magic = reader.ReadBytes(2);
                reader.Position = 0;
                if (WebFile.gzipMagic.SequenceEqual(magic))
                {
                    return(FileType.WebFile);
                }
                reader.Position = 0x20;
                magic           = reader.ReadBytes(6);
                reader.Position = 0;
                if (WebFile.brotliMagic.SequenceEqual(magic))
                {
                    return(FileType.WebFile);
                }
                if (SerializedFile.IsSerializedFile(reader))
                {
                    return(FileType.AssetsFile);
                }
                else
                {
                    return(FileType.ResourceFile);
                }
            }
            }
        }
Exemplo n.º 2
0
        private void LoadBundleFile(string fullName, EndianBinaryReader reader, string parentPath = null)
        {
            var fileName = Path.GetFileName(fullName);

            Logger.Info("Loading " + fileName);
            try
            {
                var bundleFile = new BundleFile(reader, fullName);
                foreach (var file in bundleFile.fileList)
                {
                    var subReader = new EndianBinaryReader(file.stream);
                    if (SerializedFile.IsSerializedFile(subReader))
                    {
                        var dummyPath = Path.GetDirectoryName(fullName) + Path.DirectorySeparatorChar + file.fileName;
                        if (bundleFile.fileList.Length == 1)
                        {
                            dummyPath = fullName;
                        }
                        LoadAssetsFromMemory(dummyPath, subReader, parentPath ?? fullName, bundleFile.m_Header.unityRevision, (bundleFile.fileList.Length == 1));
                    }
                    else
                    {
                        resourceFileReaders.Add(file.fileName, subReader);
                    }
                }
            }
            catch
            {
                /*var str = $"Unable to load bundle file {fileName}";
                 * if (parentPath != null)
                 * {
                 *  str += $" from {Path.GetFileName(parentPath)}";
                 * }
                 * Logger.Error(str);*/
            }
            finally
            {
                reader.Dispose();
            }
        }
Exemplo n.º 3
0
        private void LoadBundleFile(string fullName, EndianBinaryReader reader, string parentPath = null)
        {
            var fileName = Path.GetFileName(fullName);

            Logger.Info("Loading " + fileName);
            try
            {
                var bundleFile = new BundleFile(reader, fullName);
                foreach (var file in bundleFile.fileList)
                {
                    var subReader = new EndianBinaryReader(file.stream);
                    if (SerializedFile.IsSerializedFile(subReader))
                    {
                        var dummyPath = Path.GetDirectoryName(fullName) + Path.DirectorySeparatorChar + file.fileName;
                        LoadAssetsFromMemory(dummyPath, subReader, parentPath ?? fullName, bundleFile.m_Header.unityRevision);
                    }
                    else
                    {
                        resourceFileReaders[file.fileName] = subReader; //TODO
                    }
                }
            }
            catch (Exception e)
            {
                var str = $"Error while reading bundle file {fileName}";
                if (parentPath != null)
                {
                    str += $" from {Path.GetFileName(parentPath)}";
                }
                Logger.Error(str, e);
            }
            finally
            {
                reader.Dispose();
            }
        }