Example #1
0
        public AssetTypeValueField GetMonoBaseFieldCached(AssetsFileInstance inst, AssetFileInfoEx info, string managedPath)
        {
            AssetsFile file        = inst.file;
            ushort     scriptIndex = file.typeTree.pTypes_Unity5[info.curFileTypeOrIndex].scriptIndex;

            if (scriptIndex != 0xFFFF && inst.templateFieldCache.ContainsKey(scriptIndex))
            {
                AssetTypeTemplateField baseTemplateField = inst.templateFieldCache[scriptIndex];
                AssetTypeInstance      baseAti           = new AssetTypeInstance(baseTemplateField, file.reader, false, info.absoluteFilePos);
                return(baseAti.GetBaseField());
            }
            else
            {
                AssetTypeValueField baseValueField = MonoClass.GetMonoBaseField(this, inst, info, managedPath);
                inst.templateFieldCache[scriptIndex] = baseValueField.templateField;
                return(baseValueField);
            }
        }
Example #2
0
        public void LoadBundleDependencies(AssetsFileInstance ofFile, BundleFileInstance ofBundle, string path)
        {
            for (int i = 0; i < ofFile.dependencies.Count; i++)
            {
                string depPath = ofFile.file.dependencies.dependencies[i].assetPath;
                if (files.FindIndex(f => Path.GetFileName(f.path).ToLower() == Path.GetFileName(depPath).ToLower()) == -1)
                {
                    string bunPath  = Path.GetFileName(depPath);
                    int    bunIndex = Array.FindIndex(ofBundle.file.bundleInf6.dirInf, d => Path.GetFileName(d.name) == bunPath);

                    //by default, the directory of an assets file is the bundle's file path (somepath\bundle.unity3d\file.assets)
                    //we back out again to get the directory the bundle is in
                    string noBunPath      = Path.Combine(path, "..");
                    string nbAbsPath      = Path.Combine(noBunPath, depPath);
                    string nbLocalAbsPath = Path.Combine(noBunPath, Path.GetFileName(depPath));

                    //if the user chose to set the path to the directory the bundle is in,
                    //we need to check for that as well
                    string absPath      = Path.Combine(path, depPath);
                    string localAbsPath = Path.Combine(path, Path.GetFileName(depPath));

                    if (bunIndex != -1)
                    {
                        LoadAssetsFileFromBundle(ofBundle, bunIndex, true);
                    }
                    else if (File.Exists(absPath))
                    {
                        LoadAssetsFile(File.OpenRead(absPath), true);
                    }
                    else if (File.Exists(localAbsPath))
                    {
                        LoadAssetsFile(File.OpenRead(localAbsPath), true);
                    }
                    else if (File.Exists(nbAbsPath))
                    {
                        LoadAssetsFile(File.OpenRead(nbAbsPath), true);
                    }
                    else if (File.Exists(nbLocalAbsPath))
                    {
                        LoadAssetsFile(File.OpenRead(nbLocalAbsPath), true);
                    }
                }
            }
        }
        public void UpdateDependencies()
        {
            for (int x = 0; x < files.Count; x++)
            {
                AssetsFileInstance ofFile = files[x];

                for (int i = 0; i < files.Count; i++)
                {
                    AssetsFileInstance file = files[i];
                    for (int j = 0; j < file.file.dependencies.dependencyCount; j++)
                    {
                        AssetsFileDependency dep = file.file.dependencies.dependencies[j];
                        if (Path.GetFileName(dep.assetPath.ToLower()) == Path.GetFileName(ofFile.path.ToLower()))
                        {
                            file.dependencies[j] = ofFile;
                        }
                    }
                }
            }
        }
Example #4
0
 public void LoadDependencies(AssetsFileInstance ofFile, string path)
 {
     for (int i = 0; i < ofFile.dependencies.Count; i++)
     {
         string depPath = ofFile.file.dependencies.dependencies[i].assetPath;
         if (files.FindIndex(f => Path.GetFileName(f.path).ToLower() == Path.GetFileName(depPath).ToLower()) == -1)
         {
             string absPath      = Path.Combine(path, depPath);
             string localAbsPath = Path.Combine(path, Path.GetFileName(depPath));
             if (File.Exists(absPath))
             {
                 LoadAssetsFile(File.OpenRead(absPath), true);
             }
             else if (File.Exists(localAbsPath))
             {
                 LoadAssetsFile(File.OpenRead(localAbsPath), true);
             }
         }
     }
 }
Example #5
0
        public AssetExternal GetExtAsset(AssetsFileInstance relativeTo, AssetTypeValueField atvf, bool onlyGetInfo = false)
        {
            AssetExternal ext    = new AssetExternal();
            uint          fileId = (uint)atvf.Get("m_FileID").GetValue().AsInt();
            ulong         pathId = (ulong)atvf.Get("m_PathID").GetValue().AsInt64();

            if (fileId == 0 && pathId == 0)
            {
                ext.info     = null;
                ext.instance = null;
                ext.file     = null;
            }
            else if (atvf.Get("m_FileID").GetValue().AsInt() != 0)
            {
                AssetsFileInstance dep = relativeTo.dependencies[(int)fileId - 1];
                ext.info = dep.table.getAssetInfo(pathId);
                if (!onlyGetInfo)
                {
                    ext.instance = GetATI(dep.file, ext.info);
                }
                else
                {
                    ext.instance = null;
                }
                ext.file = dep;
            }
            else
            {
                ext.info = relativeTo.table.getAssetInfo(pathId);
                if (!onlyGetInfo)
                {
                    ext.instance = GetATI(relativeTo.file, ext.info);
                }
                else
                {
                    ext.instance = null;
                }
                ext.file = relativeTo;
            }
            return(ext);
        }
        public AssetExternal GetExtAsset(AssetsFileInstance relativeTo, int fileId, long pathId, bool onlyGetInfo = false, bool forceFromCldb = false)
        {
            AssetExternal ext = new AssetExternal();

            if (fileId == 0 && pathId == 0)
            {
                ext.info     = null;
                ext.instance = null;
                ext.file     = null;
            }
            else if (fileId != 0)
            {
                AssetsFileInstance dep = relativeTo.dependencies[fileId - 1];
                ext.info = dep.table.GetAssetInfo(pathId);
                if (!onlyGetInfo)
                {
                    ext.instance = GetATI(dep.file, ext.info, forceFromCldb);
                }
                else
                {
                    ext.instance = null;
                }
                ext.file = dep;
            }
            else
            {
                ext.info = relativeTo.table.GetAssetInfo(pathId);
                if (!onlyGetInfo)
                {
                    ext.instance = GetATI(relativeTo.file, ext.info, forceFromCldb);
                }
                else
                {
                    ext.instance = null;
                }
                ext.file = relativeTo;
            }
            return(ext);
        }
 //todo, set stream options
 private void LoadDeps(AssetsFileInstance ofFile, string path)
 {
     for (int i = 0; i < ofFile.dependencies.Count; i++)
     {
         string depPath = ofFile.file.dependencies.dependencies[i].assetPath;
         if (files.FindIndex(f => Path.GetFileName(f.path).ToLower() == Path.GetFileName(depPath).ToLower()) == -1)
         {
             string absPath      = Path.Combine(path, depPath);
             string localAbsPath = Path.Combine(path, Path.GetFileName(depPath));
             if (File.Exists(absPath))
             {
                 LoadAssetsFile(
                     new FileStream(absPath, FileMode.Open, FileAccess.Read, FileShare.Read), true);
             }
             else if (File.Exists(localAbsPath))
             {
                 LoadAssetsFile(
                     new FileStream(localAbsPath, FileMode.Open, FileAccess.Read, FileShare.Read), true);
             }
         }
     }
 }
Example #8
0
        public AssetsFileInstance LoadAssetsFileFromBundle(BundleFileInstance bunInst, int index, bool loadDeps = false)
        {
            string assetMemPath = Path.Combine(bunInst.path, bunInst.file.GetFileName(index));

            int listIndex = files.FindIndex(f => f.path.ToLower() == Path.GetFullPath(assetMemPath).ToLower());

            if (listIndex == -1)
            {
                if (bunInst.file.IsAssetsFile(index))
                {
                    bunInst.file.GetFileRange(index, out long offset, out long length);
                    SegmentStream      stream     = new SegmentStream(bunInst.stream, offset, length);
                    AssetsFileInstance assetsInst = LoadAssetsFile(stream, assetMemPath, loadDeps, bunInst: bunInst);
                    bunInst.loadedAssetsFiles.Add(assetsInst);
                    return(assetsInst);
                }
            }
            else
            {
                return(files[listIndex]);
            }
            return(null);
        }
Example #9
0
        public AssetsFileInstance LoadAssetsFileFromBundle(BundleFileInstance bunInst, int index, bool loadDeps = false)
        {
            var    dirInf       = bunInst.file.bundleInf6.dirInf[index];
            string assetMemPath = Path.Combine(bunInst.path, dirInf.name);

            int listIndex = files.FindIndex(f => f.path.ToLower() == Path.GetFullPath(assetMemPath).ToLower());

            if (listIndex == -1)
            {
                if (bunInst.file.IsAssetsFile(bunInst.file.reader, dirInf))
                {
                    byte[]             assetData  = BundleHelper.LoadAssetDataFromBundle(bunInst.file, index);
                    MemoryStream       ms         = new MemoryStream(assetData);
                    AssetsFileInstance assetsInst = LoadAssetsFile(ms, assetMemPath, loadDeps, bunInst: bunInst);
                    bunInst.assetsFiles.Add(assetsInst);
                    return(assetsInst);
                }
            }
            else
            {
                return(files[listIndex]);
            }
            return(null);
        }
 public LambdaAssetReplacer(AssetsManager manager, AssetsFileInstance assetsFile, AssetFileInfoEx asset, Action <AssetTypeValueField> modify)
     : this(manager, assetsFile.file, asset, modify)
 {
 }
Example #11
0
 public AssetTypeInstance GetTypeInstance(AssetsFileInstance inst, AssetFileInfoEx info, bool forceFromCldb = false)
 {
     return(GetTypeInstance(inst.file, info, forceFromCldb));
 }
 protected SerializingAssetReplacer(AssetsManager manager, AssetsFileInstance assetsFile, AssetFileInfoEx asset)
     : this(manager, assetsFile.file, asset)
 {
 }
Example #13
0
        public AssetExternal GetExtAsset(AssetsFileInstance relativeTo, int fileId, long pathId, bool onlyGetInfo = false, bool forceFromCldb = false)
        {
            AssetExternal ext = new AssetExternal
            {
                info     = null,
                instance = null,
                file     = null
            };

            if (fileId == 0 && pathId == 0)
            {
                return(ext);
            }
            else if (fileId != 0)
            {
                AssetsFileInstance dep = relativeTo.GetDependency(this, fileId - 1);

                if (dep == null)
                {
                    return(ext);
                }

                ext.file = dep;
                ext.info = dep.table.GetAssetInfo(pathId);

                if (ext.info == null)
                {
                    return(ext);
                }

                if (!onlyGetInfo)
                {
                    ext.instance = GetTypeInstance(dep.file, ext.info, forceFromCldb);
                }
                else
                {
                    ext.instance = null;
                }

                return(ext);
            }
            else
            {
                ext.file = relativeTo;
                ext.info = relativeTo.table.GetAssetInfo(pathId);

                if (ext.info == null)
                {
                    return(ext);
                }

                if (!onlyGetInfo)
                {
                    ext.instance = GetTypeInstance(relativeTo.file, ext.info, forceFromCldb);
                }
                else
                {
                    ext.instance = null;
                }

                return(ext);
            }
        }