Пример #1
0
        public dynamic LoadComponent(int pathID)
        {
            if (pathID == 0)
            {
                return(null);
            }

            int       index;
            Component subfile = FindComponent(pathID, out index);
            NotLoaded comp    = subfile as NotLoaded;

            if (comp == null)
            {
                return(subfile);
            }

            using (Stream stream = File.OpenRead(Parser.FilePath))
            {
                //stream.Position = comp.offset;
                //using (PartialStream ps = new PartialStream(stream, comp.size))
                {
                    Component asset = LoadComponent(/*ps*/ stream, index, comp);

                    /*if (!loadingReferencials &&
                     *      comp.offset + comp.size != stream.Position &&
                     *      (comp.classID1 != UnityClassID.SkinnedMeshRenderer ||
                     *              comp.offset + comp.size - 3 != stream.Position))
                     * {
                     *      Console.WriteLine(comp.classID1 + " ctr read bad length" + (stream.Position - comp.offset - comp.size));
                     * }*/
                    return(asset != null ? asset : subfile);
                }
            }
        }
Пример #2
0
        public Avatar Clone(AssetCabinet file)
        {
            Component avatar = file.Components.Find
                               (
                delegate(Component asset)
            {
                return(asset.classID1 == UnityClassID.Avatar &&
                       (asset is NotLoaded ? ((NotLoaded)asset).Name : ((Avatar)asset).m_Name) == m_Name);
            }
                               );

            if (avatar == null)
            {
                file.MergeTypeDefinition(this.file, UnityClassID.Avatar);

                Avatar dest = new Avatar(file);
                using (MemoryStream mem = new MemoryStream())
                {
                    this.WriteTo(mem);
                    mem.Position = 0;
                    dest.LoadFrom(mem);
                }
                return(dest);
            }
            else if (avatar is NotLoaded)
            {
                NotLoaded notLoaded = (NotLoaded)avatar;
                avatar = file.LoadComponent(file.SourceStream, notLoaded);
            }
            return((Avatar)avatar);
        }
Пример #3
0
        public Texture2D Clone(AssetCabinet file)
        {
            Component tex = file.Bundle != null
                                ? file.Bundle.FindComponent(m_Name, UnityClassID.Texture2D)
                                : file.Parser.GetTexture(m_Name);

            if (tex == null)
            {
                file.MergeTypeDefinition(this.file, UnityClassID.Texture2D);

                tex = new Texture2D(file);
                if (file.Bundle != null)
                {
                    file.Bundle.AddComponent(m_Name, tex);
                }
                CopyAttributesTo((Texture2D)tex);
                CopyImageTo((Texture2D)tex);
            }
            else if (tex is NotLoaded)
            {
                NotLoaded notLoaded = (NotLoaded)tex;
                if (notLoaded.replacement != null)
                {
                    tex = notLoaded.replacement;
                }
                else
                {
                    tex = file.LoadComponent(file.SourceStream, notLoaded);
                }
            }
            return((Texture2D)tex);
        }
Пример #4
0
        public MonoScript Clone(AssetCabinet file)
        {
            Component monoS = file.Bundle.FindComponent(m_Name, UnityClassID.MonoScript);

            if (monoS == null)
            {
                file.MergeTypeDefinition(this.file, UnityClassID.MonoScript);

                monoS = new MonoScript(file);
                file.Bundle.AddComponent(m_Name, monoS);
                using (MemoryStream mem = new MemoryStream())
                {
                    WriteTo(mem);
                    mem.Position = 0;
                    monoS.LoadFrom(mem);
                }
            }
            else if (monoS is NotLoaded)
            {
                NotLoaded notLoaded = (NotLoaded)monoS;
                if (notLoaded.replacement != null)
                {
                    monoS = notLoaded.replacement;
                }
                else
                {
                    monoS = file.LoadComponent(file.SourceStream, notLoaded);
                }
            }
            return((MonoScript)monoS);
        }
Пример #5
0
 public void ReplaceSubfile(int index, Component file, NotLoaded replaced)
 {
     if (index >= 0)
     {
         Components.RemoveAt(index);
         replaced.replacement = file;
         RemovedList.Add(replaced);
     }
     else
     {
         /*for (int i = Components.Count - 1; i >= 0; i--)
          * {
          *      if (Components[i].classID1 == file.classID1)
          *      {
          *              index = i + 1;
          *              break;
          *      }
          * }
          * if (index < 0)*/
         {
             index = Components.Count;
         }
     }
     Components.Insert(index, file);
 }
Пример #6
0
        public Animator Clone(AssetCabinet file)
        {
            Component gameObj = file.Bundle.FindComponent(m_GameObject.instance.m_Name, UnityClassID.GameObject);

            if (gameObj == null)
            {
                file.MergeTypeDefinition(this.file, UnityClassID.Animator);

                Animator dest = new Animator(file);
                AssetCabinet.IncompleteClones.Add(new Tuple <Component, Component>(this, dest));
                return(dest);
            }
            else if (gameObj is NotLoaded)
            {
                NotLoaded notLoaded = (NotLoaded)gameObj;
                if (notLoaded.replacement != null)
                {
                    gameObj = notLoaded.replacement;
                }
                else
                {
                    gameObj = file.LoadComponent(file.SourceStream, notLoaded);
                }
            }
            return(((GameObject)gameObj).FindLinkedComponent(UnityClassID.Animator));
        }
Пример #7
0
        public Material Clone(AssetCabinet file, bool cloneTextures)
        {
            Component mat = file.Bundle != null?file.Bundle.FindComponent(m_Name, UnityClassID.Material) : null;

            if (mat == null)
            {
                file.MergeTypeDefinition(this.file, UnityClassID.Material);

                mat = new Material(file);
                if (file.Bundle != null)
                {
                    file.Bundle.AddComponent(m_Name, mat);
                }
                CopyTo((Material)mat, cloneTextures);
            }
            else if (mat is NotLoaded)
            {
                NotLoaded notLoaded = (NotLoaded)mat;
                if (notLoaded.replacement != null)
                {
                    mat = notLoaded.replacement;
                }
                else
                {
                    mat = file.LoadComponent(file.SourceStream, notLoaded);
                }
            }
            return((Material)mat);
        }
Пример #8
0
        public Animator OpenAnimator(int componentIndex)
        {
            Component subfile = Parser.Cabinet.Components[componentIndex];

            if (subfile is Animator)
            {
                return((Animator)subfile);
            }
            NotLoaded animatorComp = (NotLoaded)subfile;
            bool      marked       = Marked.Remove(animatorComp);

            try
            {
                using (Stream stream = File.OpenRead(Parser.FilePath))
                {
                    return(Parser.Cabinet.LoadComponent(stream, componentIndex, animatorComp));
                }
            }
            finally
            {
                if (marked)
                {
                    Marked.Add(animatorComp.replacement);
                }
            }
        }
Пример #9
0
        public TextAsset Clone(AssetCabinet file)
        {
            Component text = file.Components.Find
                             (
                delegate(Component asset)
            {
                return(asset.classID1 == UnityClassID.TextAsset &&
                       (asset is NotLoaded ? ((NotLoaded)asset).Name : ((TextAsset)asset).m_Name) == m_Name);
            }
                             );

            if (text == null)
            {
                file.MergeTypeDefinition(this.file, UnityClassID.TextAsset);

                TextAsset dest = new TextAsset(file);
                file.Bundle.AddComponent(m_Name, dest);
                using (MemoryStream mem = new MemoryStream())
                {
                    this.WriteTo(mem);
                    mem.Position = 0;
                    dest.LoadFrom(mem);
                }
                return(dest);
            }
            else if (text is NotLoaded)
            {
                NotLoaded notLoaded = (NotLoaded)text;
                text = file.LoadComponent(file.SourceStream, notLoaded);
            }
            return((TextAsset)text);
        }
Пример #10
0
        public new Cubemap Clone(AssetCabinet file)
        {
            Component cubemap = file.Bundle.FindComponent(m_Name, UnityClassID.Cubemap);

            if (cubemap == null)
            {
                file.MergeTypeDefinition(this.file, UnityClassID.Cubemap);

                Cubemap clone = new Cubemap(file);
                file.Bundle.AddComponent(m_Name, clone);
                CopyAttributesTo(clone);
                CopyImageTo(clone);
                foreach (PPtr <Texture2D> texPtr in m_SourceTextures)
                {
                    if (texPtr.asset != null)
                    {
                        clone.m_SourceTextures.Add(new PPtr <Texture2D>(texPtr.instance.Clone(file)));
                    }
                }
                return(clone);
            }
            else if (cubemap is NotLoaded)
            {
                NotLoaded notLoaded = (NotLoaded)cubemap;
                if (notLoaded.replacement != null)
                {
                    cubemap = notLoaded.replacement;
                }
                else
                {
                    cubemap = file.LoadComponent(file.SourceStream, notLoaded);
                }
            }
            return((Cubemap)cubemap);
        }
Пример #11
0
        public AnimationClip Clone(AssetCabinet file)
        {
            Component clip = file.Components.Find
                             (
                delegate(Component asset)
            {
                return(asset.classID() == UnityClassID.AnimationClip &&
                       (asset is NotLoaded ? ((NotLoaded)asset).Name : ((AnimationClip)asset).m_Name) == m_Name);
            }
                             );

            if (clip == null)
            {
                file.MergeTypeDefinition(this.file, UnityClassID.AnimationClip);

                clip = new AnimationClip(file);
            }
            else if (clip is NotLoaded)
            {
                NotLoaded notLoaded = (NotLoaded)clip;
                clip = file.LoadComponent(file.SourceStream, notLoaded);
            }
            using (MemoryStream mem = new MemoryStream())
            {
                WriteTo(mem);
                mem.Position = 0;
                clip.LoadFrom(mem);
            }
            return((AnimationClip)clip);
        }
Пример #12
0
        public void CopyTo(MeshRenderer dest)
        {
            dest.m_Enabled                     = m_Enabled;
            dest.m_CastShadows                 = m_CastShadows;
            dest.m_ReceiveShadows              = m_ReceiveShadows;
            dest.m_MotionVectors               = m_MotionVectors;
            dest.m_LightmapIndex               = m_LightmapIndex;
            dest.m_LightmapTilingOffset        = m_LightmapTilingOffset;
            dest.m_LightmapTilingOffsetDynamic = m_LightmapTilingOffsetDynamic;

            dest.m_Materials = new List <PPtr <Material> >(m_Materials.Count);
            for (int i = 0; i < m_Materials.Count; i++)
            {
                Component mat = m_Materials[i].instance;
                if (mat != null && dest.file != file)
                {
                    if (dest.file.Bundle != null)
                    {
                        mat = dest.file.Bundle.FindComponent(m_Materials[i].instance.m_Name, UnityClassID.Material);
                        if (mat == null)
                        {
                            mat = m_Materials[i].instance.Clone(dest.file);
                        }
                        else if (mat is NotLoaded)
                        {
                            NotLoaded notLoaded = (NotLoaded)mat;
                            if (notLoaded.replacement != null)
                            {
                                mat = notLoaded.replacement;
                            }
                            else
                            {
                                mat = dest.file.LoadComponent(dest.file.SourceStream, notLoaded);
                            }
                        }
                    }
                    else
                    {
                        Report.ReportLog("Material " + m_Materials[i].instance.m_Name + " not copied.");
                        mat = null;
                    }
                }
                dest.m_Materials.Add(new PPtr <Material>(mat));
            }

            if (file.VersionNumber < AssetCabinet.VERSION_5_5_0)
            {
                dest.m_SubsetIndices = (uint[])m_SubsetIndices.Clone();
            }
            else
            {
                dest.m_StaticBatchInfo = m_StaticBatchInfo;
            }
            dest.m_LightProbeUsage      = m_LightProbeUsage;
            dest.m_ReflectionProbeUsage = m_ReflectionProbeUsage;
            dest.m_SortingLayerID       = m_SortingLayerID;
            dest.m_SortingLayer         = m_SortingLayer;
            dest.m_SortingOrder         = m_SortingOrder;
        }
Пример #13
0
        public static Animator OpenAnimator([DefaultVar] UnityParser parser, string name)
        {
            foreach (Component subfile in parser.Cabinet.Components)
            {
                if (subfile.classID() == UnityClassID.Animator)
                {
                    if (subfile is Animator)
                    {
                        Animator a = (Animator)subfile;
                        if (a.m_GameObject.instance.m_Name == name)
                        {
                            return(a);
                        }
                        continue;
                    }
                    NotLoaded animatorComp = (NotLoaded)subfile;
                    Stream    stream       = parser.Uncompressed == null?File.OpenRead(parser.FilePath) : parser.Uncompressed;

                    try
                    {
                        stream.Position = animatorComp.offset;
                        PPtr <GameObject> gameObjPtr = Animator.LoadGameObject(stream, parser.Cabinet.VersionNumber);
                        for (int i = 0; i < parser.Cabinet.Components.Count; i++)
                        {
                            Component gameObjSubfile = parser.Cabinet.Components[i];
                            if (gameObjSubfile.pathID == gameObjPtr.m_PathID)
                            {
                                if (gameObjSubfile is GameObject)
                                {
                                    GameObject gameObj = (GameObject)gameObjSubfile;
                                    if (gameObj.m_Name == name)
                                    {
                                        return(parser.Cabinet.LoadComponent(stream, animatorComp));
                                    }
                                    break;
                                }
                                NotLoaded gameObjComp = (NotLoaded)gameObjSubfile;
                                stream.Position = gameObjComp.offset;
                                if (GameObject.LoadName(stream, parser.Cabinet.VersionNumber) == name)
                                {
                                    return(parser.Cabinet.LoadComponent(stream, animatorComp));
                                }
                                break;
                            }
                        }
                    }
                    finally
                    {
                        if (stream != parser.Uncompressed)
                        {
                            stream.Close();
                            stream.Dispose();
                        }
                    }
                }
            }
            return(null);
        }
Пример #14
0
        public MonoScript Clone(AssetCabinet file)
        {
            Component monoS;

            if (file.VersionNumber < AssetCabinet.VERSION_5_0_0)
            {
                monoS = file.Bundle.FindComponent(m_Name, UnityClassID.MonoScript);
            }
            else
            {
                string        searchName = " / " + m_Name;
                PPtr <Object> ms         = file.AssetRefs.Find
                                           (
                    delegate(PPtr <Object> objPtr)
                {
                    return(objPtr.asset != null &&
                           (
                               objPtr.asset is NotLoaded && ((NotLoaded)objPtr.asset).Name.EndsWith(searchName) ||
                               objPtr.asset is MonoScript && ((MonoScript)objPtr.asset).m_Name == m_Name
                           ));
                }
                                           );
                monoS = ms != null ? ms.asset : null;
            }
            if (monoS == null)
            {
                file.MergeTypeDefinition(this.file, UnityClassID.MonoScript);

                monoS = new MonoScript(file);
                if (file.VersionNumber < AssetCabinet.VERSION_5_0_0)
                {
                    file.Bundle.AddComponent(m_Name, monoS);
                }
                else
                {
                    file.AssetRefs.Add(new PPtr <Object>(monoS));
                }
                using (MemoryStream mem = new MemoryStream())
                {
                    WriteTo(mem);
                    mem.Position = 0;
                    monoS.LoadFrom(mem);
                }
            }
            else if (monoS is NotLoaded)
            {
                NotLoaded notLoaded = (NotLoaded)monoS;
                if (notLoaded.replacement != null)
                {
                    monoS = notLoaded.replacement;
                }
                else
                {
                    monoS = file.LoadComponent(file.SourceStream, notLoaded);
                }
            }
            return((MonoScript)monoS);
        }
Пример #15
0
        public Material Clone(AssetCabinet file, bool cloneTextures)
        {
            Component mat = file != this.file
                                ? file.Bundle != null && !file.Bundle.m_IsStreamedSceneAssetBundle
                                        ? file.Bundle.FindComponent(m_Name, UnityClassID.Material)
                                        : file.Components.Find
                            (
                delegate(Component asset)
            {
                return(asset.classID() == UnityClassID.Material &&
                       (asset is NotLoaded ? ((NotLoaded)asset).Name : ((Material)asset).m_Name) == m_Name);
            }
                            )
                                : null;

            if (mat == null)
            {
                file.MergeTypeDefinition(this.file, UnityClassID.Material);

                mat = new Material(file);
                if (file.Bundle != null && this.file.Bundle != null)
                {
                    List <Component> externals = new List <Component>();
                    AssetBundle.AddExternalAssetsFromPreloadTable(this, this.file.Bundle, externals);
                    for (int i = 0; i < externals.Count; i++)
                    {
                        ExternalAsset ext       = (ExternalAsset)externals[i];
                        string        assetPath = this.file.References[ext.FileID - 1].assetPath;
                        int           cabPos    = assetPath.LastIndexOf("/") + 1;
                        if (!AssetCabinet.LoadedCabinets.ContainsKey(assetPath.Substring(cabPos)))
                        {
                            ext.FileID = file.MergeReference(this.file, ext.FileID);
                        }
                        else
                        {
                            externals.RemoveAt(i--);
                        }
                    }
                    file.Bundle.AddComponent(m_Name, mat, externals);
                }
                CopyTo((Material)mat, cloneTextures);
            }
            else if (mat is NotLoaded)
            {
                NotLoaded notLoaded = (NotLoaded)mat;
                if (notLoaded.replacement != null)
                {
                    mat = notLoaded.replacement;
                }
                else
                {
                    mat = file.LoadComponent(file.SourceStream, notLoaded);
                }
            }
            return((Material)mat);
        }
Пример #16
0
 bool IsVirtualAnimator(NotLoaded gameObject)
 {
     foreach (Animator animator in VirtualAnimators)
     {
         if (animator.m_GameObject.asset == gameObject)
         {
             return(true);
         }
     }
     return(false);
 }
Пример #17
0
        public Texture2D GetTexture(string name)
        {
            if (name == null)
            {
                return(null);
            }
            Stream stream = null;

            try
            {
                foreach (Component asset in Textures)
                {
                    if (asset is Texture2D)
                    {
                        Texture2D tex = (Texture2D)asset;
                        if (name == tex.m_Name || Regex.IsMatch(name, tex.m_Name + "-[^-]+-[^-]+-[^-]+"))
                        {
                            return(tex);
                        }
                    }
                    else
                    {
                        NotLoaded comp = (NotLoaded)asset;
                        if (comp.Name == null)
                        {
                            if (stream == null)
                            {
                                stream = File.OpenRead(FilePath);
                            }
                            stream.Position = comp.offset;
                            comp.Name       = Texture2D.LoadName(stream);
                        }
                        if (name == comp.Name || Regex.IsMatch(name, comp.Name + "-[^-]+-[^-]+-[^-]+"))
                        {
                            if (stream == null)
                            {
                                stream = File.OpenRead(FilePath);
                            }
                            return(LoadTexture(stream, comp));
                        }
                    }
                }
                return(null);
            }
            finally
            {
                if (stream != null)
                {
                    stream.Close();
                    stream.Dispose();
                    stream = null;
                }
            }
        }
Пример #18
0
        public Texture2D LoadTexture(Stream stream, NotLoaded comp)
        {
            Texture2D tex = comp.replacement != null ? (Texture2D)comp.replacement : Cabinet.LoadComponent(stream, comp);

            if (tex != null)
            {
                int index = Textures.IndexOf(comp);
                Textures.RemoveAt(index);
                Textures.Insert(index, tex);
            }
            return(tex);
        }
Пример #19
0
        public void CopyTo(Animation dest)
        {
            dest.m_Enabled = m_Enabled;

            dest.m_Animations = new List <PPtr <AnimationClip> >(m_Animations.Count);
            for (int i = -1; i < m_Animations.Count; i++)
            {
                Component clip = i < 0 ? m_Animation.instance : m_Animations[i].instance;
                if (clip != null && dest.file != file)
                {
                    string name = ((AnimationClip)clip).m_Name;
                    if (dest.file.Bundle != null)
                    {
                        Component asset = dest.file.Bundle.FindComponent(name, UnityClassID.AnimationClip);
                        if (asset == null)
                        {
                            clip = ((AnimationClip)clip).Clone(dest.file);
                        }
                        else if (asset is NotLoaded)
                        {
                            NotLoaded notLoaded = (NotLoaded)asset;
                            if (notLoaded.replacement != null)
                            {
                                clip = notLoaded.replacement;
                            }
                            else
                            {
                                clip = dest.file.LoadComponent(dest.file.SourceStream, notLoaded);
                            }
                        }
                    }
                    else
                    {
                        Report.ReportLog("AnimationClip " + name + " not copied.");
                        clip = null;
                    }
                }
                if (i < 0)
                {
                    dest.m_Animation = new PPtr <AnimationClip>(clip);
                }
                else
                {
                    dest.m_Animations.Add(new PPtr <AnimationClip>(clip));
                }
            }

            dest.m_WrapMode          = m_WrapMode;
            dest.m_PlayAutomatically = m_PlayAutomatically;
            dest.m_AnimatePhysics    = m_AnimatePhysics;
            dest.m_CullingType       = m_CullingType;
        }
Пример #20
0
 public void UpdateOrLoad()
 {
     if (asset is NotLoaded)
     {
         NotLoaded notLoaded = (NotLoaded)asset;
         if (notLoaded.replacement != null)
         {
             asset = instance = (T)notLoaded.replacement;
         }
         else
         {
             asset = instance = asset.file.LoadComponent(asset.file.SourceStream, notLoaded);
         }
     }
 }
Пример #21
0
        public void Dump()
        {
            string msg = String.Empty;

            for (int i = 0; i < m_PreloadTable.Count; i++)
            {
                PPtr <Object> objPtr = m_PreloadTable[i];
                if (objPtr.m_FileID == 0)
                {
                    Component comp = file.FindComponent(objPtr.asset.pathID);
                    if (comp == null)
                    {
                        comp = new NotLoaded(file, objPtr.asset.pathID, 0, 0);
                    }
                    //if (comp.classID1 == UnityClassID.Material // comp.pathID != 0 && comp.classID1 != UnityClassID.GameObject && comp.classID1 != UnityClassID.Transform)
                    {
                        msg += i + " PathID=" + objPtr.asset.pathID + " " + comp.classID1 + " " + (!(comp is NotLoaded) ? AssetCabinet.ToString(comp) : ((NotLoaded)comp).Name) + "\r\n";
                    }
                }
                else
                {
                    msg += i + " external FileID=" + objPtr.m_FileID + " PathID=" + objPtr.m_PathID + "\r\n";
                }
            }
            Report.ReportLog(msg);

            msg = string.Empty;
            for (int i = 0; i < m_Container.Count; i++)
            {
                if (m_Container[i].Value.asset.asset.pathID != 0)
                {
                    Component asset = file.FindComponent(m_Container[i].Value.asset.asset.pathID);
                    msg += i + " " + m_Container[i].Key + " PathID=" + m_Container[i].Value.asset.asset.pathID + " i=" + m_Container[i].Value.preloadIndex + " s=" + m_Container[i].Value.preloadSize + " " + asset.classID1.ToString() + " " + (asset is NotLoaded ? ((NotLoaded)asset).Name : AssetCabinet.ToString(asset)) + "\r\n";
                }
                else
                {
                    msg += "NULL! " + i + " " + m_Container[i].Key + " PathID=" + m_Container[i].Value.asset.asset.pathID + " i=" + m_Container[i].Value.preloadIndex + " s=" + m_Container[i].Value.preloadSize + " NULL!\r\n";
                }
            }
            Report.ReportLog(msg);

            if (m_MainAsset.asset.asset != null)
            {
                Component asset = file.FindComponent(m_MainAsset.asset.asset.pathID);
                msg = "Main Asset i=" + m_MainAsset.preloadIndex + " s=" + m_MainAsset.preloadSize + " " + asset.classID1.ToString() + " " + (asset is NotLoaded ? ((NotLoaded)asset).Name : AssetCabinet.ToString(asset));
                Report.ReportLog(msg);
            }
        }
Пример #22
0
        public bool SetAssetName(int componentIndex, string name)
        {
            Component asset = Parser.Cabinet.Components[componentIndex];

            if (asset is NotLoaded)
            {
                NotLoaded notLoaded = (NotLoaded)asset;
                asset = Parser.Cabinet.LoadComponent(asset.pathID);
                if (asset is NotLoaded)
                {
                    return(false);
                }
                if (asset.classID1 == UnityClassID.GameObject)
                {
                    foreach (Animator anim in VirtualAnimators)
                    {
                        if (anim.m_GameObject.asset == notLoaded)
                        {
                            anim.m_GameObject = new PPtr <GameObject>(asset);
                            break;
                        }
                    }
                }
            }
            if (Parser.Cabinet.Bundle != null)
            {
                Parser.Cabinet.Bundle.RegisterForUpdate(asset);
            }
            Type         t    = asset.GetType();
            PropertyInfo info = t.GetProperty("m_GameObject");

            if (info != null)
            {
                PPtr <GameObject> gameObjPtr = info.GetValue(asset, null) as PPtr <GameObject>;
                if (gameObjPtr != null && gameObjPtr.instance != null)
                {
                    gameObjPtr.instance.m_Name = name;
                    return(true);
                }
            }
            info = t.GetProperty("m_Name");
            if (info != null)
            {
                info.SetValue(asset, name, null);
                return(true);
            }
            return(false);
        }
Пример #23
0
        public Texture2D GetTexture(int index)
        {
            Texture2D tex = Textures[index] as Texture2D;

            if (tex != null)
            {
                return(tex);
            }

            NotLoaded comp = (NotLoaded)Textures[index];

            using (Stream stream = File.OpenRead(FilePath))
            {
                tex = LoadTexture(stream, comp);
            }
            return(tex);
        }
Пример #24
0
        public void ReplaceSubfile(Component replaced, Component file)
        {
            Components.Remove(file);
            int index = Components.IndexOf(replaced);

            Components.RemoveAt(index);
            for (int i = 0; i < RemovedList.Count; i++)
            {
                NotLoaded asset = RemovedList[i];
                if (asset.replacement == replaced)
                {
                    asset.replacement = file;
                    break;
                }
            }
            Components.Insert(index, file);
            file.pathID = replaced.pathID;
        }
Пример #25
0
        public Shader Clone(AssetCabinet file)
        {
            Component sha = file.Bundle != null?file.Bundle.FindComponent(m_Name, UnityClassID.Shader) : null;

            if (sha == null)
            {
                file.MergeTypeDefinition(this.file, UnityClassID.Shader);

                Shader dest = new Shader(file);
                if (file.Bundle != null)
                {
                    file.Bundle.AddComponent(m_Name, dest);
                }
                dest.m_Name     = m_Name;
                dest.m_Script   = m_Script;
                dest.m_PathName = m_PathName;
                foreach (PPtr <Shader> asset in m_Dependencies)
                {
                    sha = asset.asset;
                    if (sha != null)
                    {
                        Type       t    = sha.GetType();
                        MethodInfo info = t.GetMethod("Clone", new Type[] { typeof(AssetCabinet) });
                        sha = (Component)info.Invoke(sha, new object[] { file });
                    }
                    dest.m_Dependencies.Add(new PPtr <Shader>(sha));
                }
                dest.m_ShaderIsBaked = m_ShaderIsBaked;
                return(dest);
            }
            else if (sha is NotLoaded)
            {
                NotLoaded notLoaded = (NotLoaded)sha;
                if (notLoaded.replacement != null)
                {
                    sha = notLoaded.replacement;
                }
                else
                {
                    sha = file.LoadComponent(file.SourceStream, notLoaded);
                }
            }
            return((Shader)sha);
        }
Пример #26
0
        private string GetNameFromGameObject(bool filter, Stream stream)
        {
            long pos = stream.Position;
            PPtr <GameObject> gameObjPtr = Animator.LoadGameObject(stream);

            if (gameObjPtr.m_PathID == 0)
            {
                stream.Position = pos;
                return(null);
            }
            NotLoaded asset = Parser.Cabinet.FindComponent(gameObjPtr.m_PathID);

            if (filter && asset.Name == null)
            {
                stream.Position = asset.offset;
                asset.Name      = GameObject.LoadName(stream);
            }
            return(asset.Name);
        }
Пример #27
0
        public Sprite Clone(AssetCabinet file)
        {
            Component sprite = file.Bundle.FindComponent(m_Name, UnityClassID.Sprite);

            if (sprite == null)
            {
                if (m_RD.texture.instance == null)
                {
                    throw new Exception("Cant clone textureless Sprite");
                }

                file.MergeTypeDefinition(this.file, UnityClassID.Sprite);

                Sprite dest = new Sprite(file);
                dest.m_Name          = m_Name;
                dest.m_Rect          = m_Rect.Clone();
                dest.m_Offset        = m_Offset;
                dest.m_Border        = m_Border;
                dest.m_PixelsToUnits = m_PixelsToUnits;
                dest.m_Extrude       = m_Extrude;
                dest.m_IsPolygon     = m_IsPolygon;
                dest.m_RD            = m_RD.Clone(file);
                file.Bundle.UnregisterFromUpdate(dest.m_RD.texture.instance);
                file.Bundle.AppendComponent(m_RD.texture.instance.m_Name, UnityClassID.Texture2D, dest);
                file.Bundle.RegisterForUpdate(dest);
                return(dest);
            }
            else if (sprite is NotLoaded)
            {
                NotLoaded notLoaded = (NotLoaded)sprite;
                if (notLoaded.replacement != null)
                {
                    sprite = notLoaded.replacement;
                }
                else
                {
                    sprite = file.LoadComponent(file.SourceStream, notLoaded);
                }
            }
            return((Sprite)sprite);
        }
Пример #28
0
        public PhysicMaterial Clone(AssetCabinet file)
        {
            Component pMat = file != this.file
                                ? file.Components.Find
                             (
                delegate(Component asset)
            {
                return(asset.classID() == UnityClassID.PhysicMaterial &&
                       (asset is NotLoaded ? ((NotLoaded)asset).Name : ((PhysicMaterial)asset).m_Name) == m_Name);
            }
                             )
                                : null;

            if (pMat == null)
            {
                file.MergeTypeDefinition(this.file, UnityClassID.PhysicMaterial);

                PhysicMaterial clone = new PhysicMaterial(file);
                clone.m_Name          = m_Name;
                clone.dynamicFriction = dynamicFriction;
                clone.staticFriction  = staticFriction;
                clone.bounciness      = bounciness;
                clone.frictionCombine = frictionCombine;
                clone.bounceCombine   = bounceCombine;
                return(clone);
            }
            else if (pMat is NotLoaded)
            {
                NotLoaded notLoaded = (NotLoaded)pMat;
                if (notLoaded.replacement != null)
                {
                    pMat = notLoaded.replacement;
                }
                else
                {
                    pMat = file.LoadComponent(file.SourceStream, notLoaded);
                }
            }
            return((PhysicMaterial)pMat);
        }
Пример #29
0
        public void CopyTo(MeshRenderer dest)
        {
            dest.m_Enabled              = m_Enabled;
            dest.m_CastShadows          = m_CastShadows;
            dest.m_ReceiveShadows       = m_ReceiveShadows;
            dest.m_LightmapIndex        = m_LightmapIndex;
            dest.m_LightmapTilingOffset = m_LightmapTilingOffset;

            dest.m_Materials = new List <PPtr <Material> >(m_Materials.Count);
            for (int i = 0; i < m_Materials.Count; i++)
            {
                Component mat = null;
                if (m_Materials[i].instance != null)
                {
                    mat = dest.file.Bundle.FindComponent(m_Materials[i].instance.m_Name, UnityClassID.Material);
                    if (mat == null)
                    {
                        mat = m_Materials[i].instance.Clone(dest.file);
                    }
                    else if (mat is NotLoaded)
                    {
                        NotLoaded notLoaded = (NotLoaded)mat;
                        if (notLoaded.replacement != null)
                        {
                            mat = notLoaded.replacement;
                        }
                        else
                        {
                            mat = dest.file.LoadComponent(dest.file.SourceStream, notLoaded);
                        }
                    }
                }
                dest.m_Materials.Add(new PPtr <Material>(mat));
            }

            dest.m_SubsetIndices  = (uint[])m_SubsetIndices.Clone();
            dest.m_UseLightProbes = m_UseLightProbes;
            dest.m_SortingLayerID = m_SortingLayerID;
            dest.m_SortingOrder   = m_SortingOrder;
        }
Пример #30
0
        void LoadCamera()
        {
            Camera camera = Editor.Parser;

            checkBoxCameraEnabled.Checked             = camera.m_Enabled > 0;
            comboBoxCameraClearFlags.SelectedIndex    = (int)camera.m_ClearFlags - 1;
            editTextBoxCameraBackgroundRed.Text       = camera.m_BackGroundColor.Red.ToFloatString();
            editTextBoxCameraBackgroundGreen.Text     = camera.m_BackGroundColor.Green.ToFloatString();
            editTextBoxCameraBackgroundBlue.Text      = camera.m_BackGroundColor.Blue.ToFloatString();
            editTextBoxCameraBackgroundAlpha.Text     = camera.m_BackGroundColor.Alpha.ToFloatString();
            editTextBoxCameraCullingMask.Text         = camera.m_CullingMask.m_Bits.ToString("X");
            checkBoxCameraOrthographic.Checked        = camera.orthographic;
            editTextBoxCameraOrthographicSize.Text    = camera.orthographic_size.ToFloatString();
            editTextBoxCameraFieldOfView.Text         = camera.field_of_view.ToFloatString();
            editTextBoxCameraNearClip.Text            = camera.near_clip_plane.ToFloatString();
            editTextBoxCameraFarClip.Text             = camera.far_clip_plane.ToFloatString();
            editTextBoxCameraViewportX.Text           = camera.m_NormalizedViewPortRect.x.ToFloatString();
            editTextBoxCameraViewportY.Text           = camera.m_NormalizedViewPortRect.y.ToFloatString();
            editTextBoxCameraViewportWidth.Text       = camera.m_NormalizedViewPortRect.width.ToFloatString();
            editTextBoxCameraViewportHeight.Text      = camera.m_NormalizedViewPortRect.height.ToFloatString();
            editTextBoxCameraDepth.Text               = camera.m_Depth.ToFloatString();
            comboBoxCameraRenderingPath.SelectedIndex = camera.m_RenderingPath + 1;
            int       renderTexIdx = 0;
            NotLoaded renderTex    = (NotLoaded)camera.m_TargetTexture.asset;

            if (renderTex != null)
            {
                string renderTexName = renderTex.Name + " " + renderTex.pathID + (renderTex.file != Editor.Parser.file ? " in " + renderTex.file.Parser.GetCabinetName(renderTex.file) : String.Empty);
                renderTexIdx = comboBoxCameraTargetTexture.FindStringExact(renderTexName);
            }
            comboBoxCameraTargetTexture.SelectedIndex = renderTexIdx;
            checkBoxCameraOcclusionCulling.Checked    = camera.m_OcclusionCulling;
            checkBoxCameraHDR.Checked               = camera.m_HDR;
            editTextBoxCameraTargetDisplay.Text     = camera.m_TargetDisplay.ToString();
            editTextBoxCameraTargetEye.Text         = camera.m_TargetEye.ToString();
            editTextBoxCameraStereoConvergence.Text = camera.m_StereoConvergence.ToFloatString();
            editTextBoxCameraStereoSeparation.Text  = camera.m_StereoSeparation.ToFloatString();
            checkBoxCameraStereoMirrorMode.Checked  = camera.m_StereoMirrorMode;
        }
Пример #31
0
 bool IsVirtualAnimator(NotLoaded gameObject)
 {
     foreach (Animator animator in VirtualAnimators)
     {
         if (animator.m_GameObject.asset == gameObject)
         {
             return true;
         }
     }
     return false;
 }
Пример #32
0
 public AssetInfo(AssetCabinet file, Stream stream)
 {
     this.file = file;
     BinaryReader reader = new BinaryReader(stream);
     preloadIndex = reader.ReadInt32();
     preloadSize = reader.ReadInt32();
     PPtr<Object> objPtr = new PPtr<Object>(stream);
     if (objPtr.m_FileID == 0 && objPtr.m_PathID != 0)
     {
         Component comp = file.FindComponent(objPtr.m_PathID, false);
         if (comp == null)
         {
             comp = new NotLoaded(file, objPtr.m_PathID, 0, 0);
         }
         asset = new PPtr<Object>(comp);
     }
     else
     {
         asset = objPtr;
     }
 }
Пример #33
0
        public void WriteTo(Stream stream)
        {
            BinaryWriter writer = new BinaryWriter(stream);
            long beginPos = stream.Position;

            stream.Position += 4 + 4 + 4 + 4;
            writer.WriteInt32BE(Unknown6);
            writer.WriteName0(Version);

            writer.Write(Unknown7);

            writer.Write(Types.Count);
            for (int i = 0; i < Types.Count; i++)
            {
                writer.Write(Types[i].typeId);
                WriteType(writer, Types[i].definitions);
            }

            writer.Write(Unknown8);

            writer.Write(Components.Count);
            long assetMetaPosition = stream.Position;
            stream.Position += Components.Count * 5 * sizeof(int);

            writer.Write(References.Length);
            for (int i = 0; i < References.Length; i++)
            {
                writer.Write(References[i].guid.ToByteArray());
                writer.Write(References[i].type);
                writer.WriteName0(References[i].filePath);
                writer.WriteName0(References[i].assetPath);
            }
            UsedLength = (int)stream.Position - (Parser.HeaderLength + Parser.Offset + 0x13);
            stream.Position = (stream.Position + 16) & ~(long)15;
            DataPosition = (int)stream.Position - (Parser.HeaderLength + Parser.Offset);

            uint[] offsets = new uint[Components.Count];
            uint[] sizes = new uint[Components.Count];
            byte[] align = new byte[3];
            Dictionary<AssetCabinet, Stream> foreignNotLoaded = new Dictionary<AssetCabinet, Stream>();
            try
            {
                for (int i = 0; i < Components.Count; i++)
                {
                    offsets[i] = (uint)stream.Position;
                    Component comp = Components[i];
                    if (comp is NeedsSourceStreamForWriting)
                    {
                        if (comp.file == this)
                        {
                            ((NeedsSourceStreamForWriting)comp).SourceStream = SourceStream;
                        }
                        else
                        {
                            Stream str;
                            if (!foreignNotLoaded.TryGetValue(comp.file, out str))
                            {
                                str = File.OpenRead(comp.file.Parser.FilePath);
                                foreignNotLoaded.Add(comp.file, str);
                            }
                            ((NotLoaded)comp).SourceStream = str;
                        }
                    }
                    comp.WriteTo(stream);
                    sizes[i] = (uint)stream.Position - offsets[i];
                    int rest = 4 - (int)(stream.Position & 3);
                    if (rest < 4 && i < Components.Count - 1)
                    {
                        writer.Write(align, 0, rest);
                    }
                    Parser.worker.ReportProgress(50 + i * 49 / Components.Count);
                }
            }
            finally
            {
                foreach (var foreign in foreignNotLoaded)
                {
                    foreign.Value.Close();
                    if (Parser.DeleteModFiles.Contains(foreign.Key))
                    {
                        File.Delete(foreign.Key.Parser.FilePath);
                    }
                }
            }
            Parser.ContentLength = ContentLengthCopy = (int)stream.Position - (Parser.HeaderLength + Parser.Offset);

            stream.Position = beginPos;
            writer.WriteInt32BE(UsedLength);
            writer.WriteInt32BE(ContentLengthCopy);
            writer.WriteInt32BE(Format);
            writer.WriteInt32BE(DataPosition);

            stream.Position = assetMetaPosition;
            NotLoaded newAssetBundle = null;
            for (int i = 0; i < Components.Count; i++)
            {
                Component comp = Components[i];
                writer.Write(comp.pathID);
                writer.Write(offsets[i] - (uint)DataPosition - (uint)(Parser.HeaderLength + Parser.Offset));
                writer.Write(sizes[i]);
                writer.Write((int)comp.classID1);
                writer.Write((int)comp.classID2);
                if (comp.file != this)
                {
                    NotLoaded notLoaded = new NotLoaded(this, comp.pathID, comp.classID1, comp.classID2);
                    notLoaded.size = sizes[i];
                    ReplaceSubfile(comp, notLoaded);
                    if (comp.classID1 == UnityClassID.AssetBundle)
                    {
                        newAssetBundle = notLoaded;
                    }
                    comp = notLoaded;
                }
                if (comp is NotLoaded)
                {
                    ((NotLoaded)comp).offset = offsets[i];
                }
            }
            if (newAssetBundle != null)
            {
                Bundle = LoadComponent(stream, newAssetBundle);
            }
        }
Пример #34
0
        public void LoadFrom(Stream stream)
        {
            BinaryReader reader = new BinaryReader(stream);
            m_Name = reader.ReadNameA4();

            int numObjects = reader.ReadInt32();
            m_PreloadTable = new List<PPtr<Object>>(numObjects);
            for (int i = 0; i < numObjects; i++)
            {
                PPtr<Object> objPtr = new PPtr<Object>(stream);
                if (objPtr.m_FileID == 0)
                {
                    Component comp = file.FindComponent(objPtr.m_PathID, false);
                    if (comp == null)
                    {
                        comp = new NotLoaded(file, objPtr.m_PathID, 0, 0);
                    }
                    objPtr = new PPtr<Object>(comp);
                }
                m_PreloadTable.Add(objPtr);
            }

            int numContainerEntries = reader.ReadInt32();
            m_Container = new List<KeyValuePair<string, AssetInfo>>(numContainerEntries);
            for (int i = 0; i < numContainerEntries; i++)
            {
                m_Container.Add
                (
                    new KeyValuePair<string, AssetInfo>
                    (
                        reader.ReadNameA4(), new AssetInfo(file, stream)
                    )
                );
            }

            m_MainAsset = new AssetInfo(file, stream);

            int numScriptComps = reader.ReadInt32();
            m_ScriptCompatibility = new AssetBundleScriptInfo[numScriptComps];
            for (int i = 0; i < numScriptComps; i++)
            {
                m_ScriptCompatibility[i] = new AssetBundleScriptInfo(stream);
            }

            int numClassComps = reader.ReadInt32();
            m_ClassCompatibility = new KeyValuePair<int, uint>[numClassComps];
            for (int i = 0; i < numClassComps; i++)
            {
                m_ClassCompatibility[i] = new KeyValuePair<int, uint>
                (
                    reader.ReadInt32(), reader.ReadUInt32()
                );
            }

            m_RuntimeCompatibility = reader.ReadUInt32();
        }
Пример #35
0
 public void ReplaceSubfile(int index, Component file, NotLoaded replaced)
 {
     if (index >= 0)
     {
         Components.RemoveAt(index);
         replaced.replacement = file;
         RemovedList.Add(replaced);
     }
     else
     {
         /*for (int i = Components.Count - 1; i >= 0; i--)
         {
             if (Components[i].classID1 == file.classID1)
             {
                 index = i + 1;
                 break;
             }
         }
         if (index < 0)*/
         {
             index = Components.Count;
         }
     }
     Components.Insert(index, file);
 }
Пример #36
0
 public dynamic LoadComponent(Stream stream, int index, NotLoaded comp)
 {
     stream.Position = comp.offset;
     try
     {
         switch (comp.classID1)
         {
         case UnityClassID.AnimationClip:
             {
                 AnimationClip animationClip = new AnimationClip(this, comp.pathID, comp.classID1, comp.classID2);
                 ReplaceSubfile(index, animationClip, comp);
                 animationClip.LoadFrom(stream);
                 return animationClip;
             }
         case UnityClassID.Animator:
             {
                 Animator animator = new Animator(this, comp.pathID, comp.classID1, comp.classID2);
                 ReplaceSubfile(index, animator, comp);
                 animator.LoadFrom(stream);
                 return animator;
             }
         case UnityClassID.AnimatorController:
             {
                 AnimatorController animatorController = new AnimatorController(this, comp.pathID, comp.classID1, comp.classID2);
                 ReplaceSubfile(index, animatorController, comp);
                 animatorController.LoadFrom(stream);
                 return animatorController;
             }
         case UnityClassID.AssetBundle:
             {
                 AssetBundle assetBundle = new AssetBundle(this, comp.pathID, comp.classID1, comp.classID2);
                 ReplaceSubfile(index, assetBundle, comp);
                 assetBundle.LoadFrom(stream);
                 return assetBundle;
             }
         case UnityClassID.AudioClip:
             {
                 if (loadingReferencials)
                 {
                     return comp;
                 }
                 AudioClip ac = new AudioClip(this, comp.pathID, comp.classID1, comp.classID2);
                 ReplaceSubfile(index, ac, comp);
                 ac.LoadFrom(stream);
                 return ac;
             }
         case UnityClassID.AudioListener:
             {
                 AudioListener audioListener = new AudioListener(this, comp.pathID, comp.classID1, comp.classID2);
                 ReplaceSubfile(index, audioListener, comp);
                 audioListener.LoadFrom(stream);
                 return audioListener;
             }
         case UnityClassID.AudioSource:
             {
                 AudioSource audioSrc = new AudioSource(this, comp.pathID, comp.classID1, comp.classID2);
                 ReplaceSubfile(index, audioSrc, comp);
                 audioSrc.LoadFrom(stream);
                 return audioSrc;
             }
         case UnityClassID.Avatar:
             {
                 if (loadingReferencials)
                 {
                     return comp;
                 }
                 Avatar avatar = new Avatar(this, comp.pathID, comp.classID1, comp.classID2);
                 ReplaceSubfile(index, avatar, comp);
                 avatar.LoadFrom(stream);
                 return avatar;
             }
         case UnityClassID.BoxCollider:
             {
                 BoxCollider boxCol = new BoxCollider(this, comp.pathID, comp.classID1, comp.classID2);
                 ReplaceSubfile(index, boxCol, comp);
                 boxCol.LoadFrom(stream);
                 return boxCol;
             }
         case UnityClassID.Camera:
             {
                 Camera camera = new Camera(this, comp.pathID, comp.classID1, comp.classID2);
                 ReplaceSubfile(index, camera, comp);
                 camera.LoadFrom(stream);
                 return camera;
             }
         case UnityClassID.CapsuleCollider:
             {
                 CapsuleCollider capsuleCol = new CapsuleCollider(this, comp.pathID, comp.classID1, comp.classID2);
                 ReplaceSubfile(index, capsuleCol, comp);
                 capsuleCol.LoadFrom(stream);
                 return capsuleCol;
             }
         case UnityClassID.Cubemap:
             {
                 Cubemap cubemap = new Cubemap(this, comp.pathID, comp.classID1, comp.classID2);
                 ReplaceSubfile(index, cubemap, comp);
                 cubemap.LoadFrom(stream);
                 Parser.Textures.Add(cubemap);
                 return cubemap;
             }
         case UnityClassID.EllipsoidParticleEmitter:
             {
                 EllipsoidParticleEmitter ellipsoid = new EllipsoidParticleEmitter(this, comp.pathID, comp.classID1, comp.classID2);
                 ReplaceSubfile(index, ellipsoid, comp);
                 ellipsoid.LoadFrom(stream);
                 return ellipsoid;
             }
         case UnityClassID.FlareLayer:
             {
                 FlareLayer flareLayer = new FlareLayer(this, comp.pathID, comp.classID1, comp.classID2);
                 ReplaceSubfile(index, flareLayer, comp);
                 flareLayer.LoadFrom(stream);
                 return flareLayer;
             }
         case UnityClassID.Light:
             {
                 Light light = new Light(this, comp.pathID, comp.classID1, comp.classID2);
                 ReplaceSubfile(index, light, comp);
                 light.LoadFrom(stream);
                 return light;
             }
         case UnityClassID.LinkToGameObject:
             {
                 LinkToGameObject link = new LinkToGameObject(this, comp.pathID, comp.classID1, comp.classID2);
                 ReplaceSubfile(index, link, comp);
                 link.LoadFrom(stream);
                 return link;
             }
         case UnityClassID.LinkToGameObject223:
             {
                 LinkToGameObject223 link = new LinkToGameObject223(this, comp.pathID, comp.classID1, comp.classID2);
                 ReplaceSubfile(index, link, comp);
                 link.LoadFrom(stream);
                 return link;
             }
         case UnityClassID.LinkToGameObject225:
             {
                 LinkToGameObject225 link = new LinkToGameObject225(this, comp.pathID, comp.classID1, comp.classID2);
                 ReplaceSubfile(index, link, comp);
                 link.LoadFrom(stream);
                 return link;
             }
         case UnityClassID.GameObject:
             {
                 GameObject gameObj = new GameObject(this, comp.pathID, comp.classID1, comp.classID2);
                 ReplaceSubfile(index, gameObj, comp);
                 gameObj.LoadFrom(stream);
                 return gameObj;
             }
         case UnityClassID.Material:
             {
                 Material mat = new Material(this, comp.pathID, comp.classID1, comp.classID2);
                 ReplaceSubfile(index, mat, comp);
                 mat.LoadFrom(stream);
                 return mat;
             }
         case UnityClassID.Mesh:
             {
                 if (loadingReferencials)
                 {
                     return comp;
                 }
                 Mesh mesh = new Mesh(this, comp.pathID, comp.classID1, comp.classID2);
                 ReplaceSubfile(index, mesh, comp);
                 mesh.LoadFrom(stream);
                 return mesh;
             }
         case UnityClassID.MeshCollider:
             {
                 MeshCollider meshCol = new MeshCollider(this, comp.pathID, comp.classID1, comp.classID2);
                 ReplaceSubfile(index, meshCol, comp);
                 meshCol.LoadFrom(stream);
                 return meshCol;
             }
         case UnityClassID.MeshFilter:
             {
                 MeshFilter meshFilter = new MeshFilter(this, comp.pathID, comp.classID1, comp.classID2);
                 ReplaceSubfile(index, meshFilter, comp);
                 meshFilter.LoadFrom(stream);
                 return meshFilter;
             }
         case UnityClassID.MeshRenderer:
             {
                 MeshRenderer meshRenderer = new MeshRenderer(this, comp.pathID, comp.classID1, comp.classID2);
                 ReplaceSubfile(index, meshRenderer, comp);
                 meshRenderer.LoadFrom(stream);
                 return meshRenderer;
             }
         default:
             if (comp.classID2 == UnityClassID.MonoBehaviour)
             {
                 if (Types.Count > 0)
                 {
                     MonoBehaviour monoBehaviour = new MonoBehaviour(this, comp.pathID, comp.classID1, comp.classID2);
                     ReplaceSubfile(index, monoBehaviour, comp);
                     monoBehaviour.LoadFrom(stream);
                     return monoBehaviour;
                 }
                 else
                 {
                     string message = comp.classID2 + " unhandled because of absence of Types in Cabinet (*.assets)";
                     if (!reported.Contains(message))
                     {
                         Report.ReportLog(message);
                         reported.Add(message);
                     }
                     return comp;
                 }
             }
             else
             {
                 string message = "Unhandled class: " + comp.classID1 + "/" + comp.classID2;
                 if (!reported.Contains(message))
                 {
                     Report.ReportLog(message);
                     reported.Add(message);
                 }
             }
             break;
         case UnityClassID.MonoScript:
             {
                 if (loadingReferencials)
                 {
                     return comp;
                 }
                 MonoScript monoScript = new MonoScript(this, comp.pathID, comp.classID1, comp.classID2);
                 ReplaceSubfile(index, monoScript, comp);
                 monoScript.LoadFrom(stream);
                 return monoScript;
             }
         case UnityClassID.MultiLink:
             {
                 MultiLink multi = new MultiLink(this, comp.pathID, comp.classID1, comp.classID2);
                 ReplaceSubfile(index, multi, comp);
                 multi.LoadFrom(stream);
                 return multi;
             }
         case UnityClassID.ParticleAnimator:
             {
                 ParticleAnimator particleAnimator = new ParticleAnimator(this, comp.pathID, comp.classID1, comp.classID2);
                 ReplaceSubfile(index, particleAnimator, comp);
                 particleAnimator.LoadFrom(stream);
                 return particleAnimator;
             }
         case UnityClassID.ParticleRenderer:
             {
                 ParticleRenderer particleRenderer = new ParticleRenderer(this, comp.pathID, comp.classID1, comp.classID2);
                 ReplaceSubfile(index, particleRenderer, comp);
                 particleRenderer.LoadFrom(stream);
                 return particleRenderer;
             }
         case UnityClassID.ParticleSystem:
             {
                 ParticleSystem particleSystem = new ParticleSystem(this, comp.pathID, comp.classID1, comp.classID2);
                 ReplaceSubfile(index, particleSystem, comp);
                 particleSystem.LoadFrom(stream);
                 return particleSystem;
             }
         case UnityClassID.ParticleSystemRenderer:
             {
                 ParticleSystemRenderer particleSystemRenderer = new ParticleSystemRenderer(this, comp.pathID, comp.classID1, comp.classID2);
                 ReplaceSubfile(index, particleSystemRenderer, comp);
                 particleSystemRenderer.LoadFrom(stream);
                 return particleSystemRenderer;
             }
         case UnityClassID.Projector:
             {
                 Projector projector = new Projector(this, comp.pathID, comp.classID1, comp.classID2);
                 ReplaceSubfile(index, projector, comp);
                 projector.LoadFrom(stream);
                 return projector;
             }
         case UnityClassID.Rigidbody:
             {
                 RigidBody rigidBody = new RigidBody(this, comp.pathID, comp.classID1, comp.classID2);
                 ReplaceSubfile(index, rigidBody, comp);
                 rigidBody.LoadFrom(stream);
                 return rigidBody;
             }
         case UnityClassID.Shader:
             {
                 Shader shader = new Shader(this, comp.pathID, comp.classID1, comp.classID2);
                 ReplaceSubfile(index, shader, comp);
                 shader.LoadFrom(stream);
                 return shader;
             }
         case UnityClassID.SkinnedMeshRenderer:
             {
                 SkinnedMeshRenderer sMesh = new SkinnedMeshRenderer(this, comp.pathID, comp.classID1, comp.classID2);
                 ReplaceSubfile(index, sMesh, comp);
                 sMesh.LoadFrom(stream);
                 return sMesh;
             }
         case UnityClassID.SphereCollider:
             {
                 SphereCollider sphereCol = new SphereCollider(this, comp.pathID, comp.classID1, comp.classID2);
                 ReplaceSubfile(index, sphereCol, comp);
                 sphereCol.LoadFrom(stream);
                 return sphereCol;
             }
         case UnityClassID.Sprite:
             {
                 Sprite sprite = new Sprite(this, comp.pathID, comp.classID1, comp.classID2);
                 ReplaceSubfile(index, sprite, comp);
                 sprite.LoadFrom(stream);
                 return sprite;
             }
         case UnityClassID.SpriteRenderer:
             {
                 SpriteRenderer spriteRenderer = new SpriteRenderer(this, comp.pathID, comp.classID1, comp.classID2);
                 ReplaceSubfile(index, spriteRenderer, comp);
                 spriteRenderer.LoadFrom(stream);
                 return spriteRenderer;
             }
         case UnityClassID.TextAsset:
             {
                 if (loadingReferencials)
                 {
                     return comp;
                 }
                 TextAsset ta = new TextAsset(this, comp.pathID, comp.classID1, comp.classID2);
                 ReplaceSubfile(index, ta, comp);
                 ta.LoadFrom(stream);
                 return ta;
             }
         case UnityClassID.Texture2D:
             {
                 if (loadingReferencials)
                 {
                     return comp;
                 }
                 Texture2D tex = new Texture2D(this, comp.pathID, comp.classID1, comp.classID2);
                 ReplaceSubfile(index, tex, comp);
                 tex.LoadFrom(stream);
                 Parser.Textures.Add(tex);
                 return tex;
             }
         case UnityClassID.Transform:
             {
                 Transform trans = new Transform(this, comp.pathID, comp.classID1, comp.classID2);
                 ReplaceSubfile(index, trans, comp);
                 trans.LoadFrom(stream);
                 return trans;
             }
         }
     }
     catch
     {
         Report.ReportLog("Failed to load " + comp.classID1 + "/" + comp.classID2 + " PathID=" + comp.pathID);
         foreach (NotLoaded notLoaded in RemovedList)
         {
             if (notLoaded == comp)
             {
                 RemovedList.Remove(notLoaded);
                 Components.RemoveAt(index);
                 notLoaded.replacement = null;
                 Components.Insert(index, notLoaded);
                 break;
             }
         }
     }
     return null;
 }
Пример #37
0
 public dynamic LoadComponent(Stream stream, NotLoaded comp)
 {
     return LoadComponent(stream, Components.IndexOf(comp), comp);
 }
Пример #38
0
        public AssetCabinet(Stream stream, UnityParser parser)
        {
            Parser = parser;
            BinaryReader reader = new BinaryReader(stream);

            UsedLength = reader.ReadInt32BE();
            ContentLengthCopy = reader.ReadInt32BE();
            Format = reader.ReadInt32BE();
            DataPosition = reader.ReadInt32BE();
            Unknown6 = reader.ReadInt32BE();
            Version = reader.ReadName0();

            Unknown7 = reader.ReadInt32();

            int numTypes = reader.ReadInt32();
            Types = new List<TypeDefinition>(numTypes);
            for (int i = 0; i < numTypes; i++)
            {
                TypeDefinition t = new TypeDefinition();
                t.typeId = reader.ReadInt32();
                t.definitions = new TypeDefinitionString();
                ReadType(reader, t.definitions);
                Types.Add(t);
            }

            Unknown8 = reader.ReadInt32();

            int numComponents = reader.ReadInt32();
            Components = new List<Component>(numComponents);
            for (int i = 0; i < numComponents; i++)
            {
                int pathID = reader.ReadInt32();
                uint offset = (uint)(parser.HeaderLength + parser.Offset) + (uint)DataPosition + reader.ReadUInt32();
                uint size = reader.ReadUInt32();
                NotLoaded comp = new NotLoaded(this, pathID, (UnityClassID)reader.ReadInt32(), (UnityClassID)reader.ReadInt32());
                comp.offset = offset;
                comp.size = size;
                Components.Add(comp);
            }

            int numRefs = reader.ReadInt32();
            References = new Reference[numRefs];
            for (int i = 0; i < numRefs; i++)
            {
                References[i] = new Reference();
                References[i].guid = new Guid(reader.ReadBytes(16));
                References[i].type = reader.ReadInt32();
                References[i].filePath = reader.ReadName0();
                References[i].assetPath = reader.ReadName0();
            }
            if (stream.Position != UsedLength + (parser.HeaderLength + parser.Offset) + 0x13)
            {
                Report.ReportLog("Unexpected Length Pos=" + stream.Position.ToString("X") + " UsedLength=" + UsedLength.ToString("X"));
            }
            long padding = (stream.Position + 16) & ~(long)15;
            if (padding != parser.HeaderLength + parser.Offset + DataPosition)
            {
                Report.ReportLog("Unexpected DataPosition");
            }

            RemovedList = new List<NotLoaded>();
            loadingReferencials = false;
            reported = new HashSet<string>();

            for (int i = 0; i < Components.Count; i++)
            {
                Component asset = Components[i];
                if (asset.classID1 == UnityClassID.AssetBundle)
                {
                    Bundle = LoadComponent(stream, i, (NotLoaded)asset);
                    break;
                }
            }
        }
Пример #39
0
        public void Dump()
        {
            string msg = String.Empty;
            for (int i = 0; i < m_PreloadTable.Count; i++)
            {
                PPtr<Object> objPtr = m_PreloadTable[i];
                if (objPtr.m_FileID == 0)
                {
                    Component comp = file.FindComponent(objPtr.asset.pathID);
                    if (comp == null)
                    {
                        comp = new NotLoaded(file, objPtr.asset.pathID, 0, 0);
                    }
                    //if (comp.classID1 == UnityClassID.Material // comp.pathID != 0 && comp.classID1 != UnityClassID.GameObject && comp.classID1 != UnityClassID.Transform)
                    {
                        msg += i + " PathID=" + objPtr.asset.pathID + " " + comp.classID1 + " " + (!(comp is NotLoaded) ? AssetCabinet.ToString(comp) : ((NotLoaded)comp).Name) + "\r\n";
                    }
                }
                else
                {
                    msg += i + " external FileID=" + objPtr.m_FileID + " PathID=" + objPtr.m_PathID + "\r\n";
                }
            }
            Report.ReportLog(msg);

            msg = string.Empty;
            for (int i = 0; i < m_Container.Count; i++)
            {
                if (m_Container[i].Value.asset.asset.pathID != 0)
                {
                    Component asset = file.FindComponent(m_Container[i].Value.asset.asset.pathID);
                    msg += i + " " + m_Container[i].Key + " PathID=" + m_Container[i].Value.asset.asset.pathID + " i=" + m_Container[i].Value.preloadIndex + " s=" + m_Container[i].Value.preloadSize + " " + asset.classID1.ToString() + " " + (asset is NotLoaded ? ((NotLoaded)asset).Name : AssetCabinet.ToString(asset)) + "\r\n";
                }
                else
                {
                    msg += "NULL! " + i + " " + m_Container[i].Key + " PathID=" + m_Container[i].Value.asset.asset.pathID + " i=" + m_Container[i].Value.preloadIndex + " s=" + m_Container[i].Value.preloadSize + " NULL!\r\n";
                }
            }
            Report.ReportLog(msg);

            if (m_MainAsset.asset.asset != null)
            {
                Component asset = file.FindComponent(m_MainAsset.asset.asset.pathID);
                msg = "Main Asset i=" + m_MainAsset.preloadIndex + " s=" + m_MainAsset.preloadSize + " " + asset.classID1.ToString() + " " + (asset is NotLoaded ? ((NotLoaded)asset).Name : AssetCabinet.ToString(asset));
                Report.ReportLog(msg);
            }
        }