Exemplo n.º 1
0
        private async Task <bool> LoadOrAskTypeData(AssetsFileInstance fileInst)
        {
            string uVer = fileInst.file.typeTree.unityVersion;

            if (am.LoadClassDatabaseFromPackage(uVer) == null)
            {
                VersionWindow version = new VersionWindow(uVer, am.classPackage);
                var           newFile = await version.ShowDialog <ClassDatabaseFile>(this);

                if (newFile == null)
                {
                    return(false);
                }

                am.classFile = newFile;
            }
            return(true);
        }
Exemplo n.º 2
0
        private static void RecurseTypeReplace(AssetsManager am, AssetsFileInstance inst, AssetTypeValueField field, List <ulong> ids, int depth, Dictionary <ulong, ulong> findAndReplace)
        {
            string p = new string(' ', depth);

            foreach (AssetTypeValueField child in field.pChildren)
            {
                if (!child.templateField.hasValue)
                {
                    if (child == null)
                    {
                        return;
                    }
                    string typeName = child.templateField.type;
                    if (typeName.StartsWith("PPtr<") && typeName.EndsWith(">") && child.childrenCount == 2)
                    {
                        int   fileId = child.Get("m_FileID").GetValue().AsInt();
                        ulong pathId = (ulong)child.Get("m_PathID").GetValue().AsInt64();
                        if (fileId == 0 && pathId != 0)
                        {
                            if (!ids.Contains(pathId))
                            {
                                ids.Add(pathId);
                                //AssetTypeValueField depBaseField = am.GetExtAsset(inst, child).instance.GetBaseField();
                                //RecurseTypeReplace(am, inst, depBaseField, ids, 0, find, replace);
                            }
                            //if (pathId == find)
                            //{
                            //    Debug.Log("matched, setting pathid to " + replace + " from " + child.Get("m_PathID").GetValue().AsInt64());
                            //    child.Get("m_PathID").value.Set((long)replace);
                            //}
                            foreach (KeyValuePair <ulong, ulong> far in findAndReplace)
                            {
                                //Debug.Log(pathId + " == " + far.Key);
                                if (pathId == far.Key)
                                {
                                    child.Get("m_PathID").value.Set((long)far.Value);
                                }
                            }
                        }
                    }
                    RecurseTypeReplace(am, inst, child, ids, depth + 1, findAndReplace);
                }
            }
        }
Exemplo n.º 3
0
        public void OpenAsset(long id)
        {
            ClassDatabaseFile  classFile  = helper.classFile;
            AssetsFileInstance correctAti = currentFile;
            AssetFileInfoEx    info       = correctAti.table.GetAssetInfo(id);
            //todo this won't work for assets with typetrees
            ClassDatabaseType classType = AssetHelper.FindAssetClassByID(classFile, info.curFileType);
            string            typeName  = classType.name.GetString(classFile);
            bool hasGameobjectField     = classType.fields.Any(f => f.fieldName.GetString(classFile) == "m_GameObject");
            bool parentPointerNull      = false;

            if (typeName != "GameObject" && hasGameobjectField)
            {
                //get gameobject parent
                AssetTypeValueField componentBaseField = helper.GetATI(correctAti.file, info).GetBaseField();
                AssetFileInfoEx     newInfo            = helper.GetExtAsset(correctAti, componentBaseField["m_GameObject"], true).info;
                if (newInfo != null && newInfo.index != 0)
                {
                    info = newInfo;
                }
                else
                {
                    parentPointerNull = true;
                }
            }
            if ((typeName == "GameObject" || hasGameobjectField) && !parentPointerNull)
            {
                AssetTypeValueField baseField = helper.GetATI(correctAti.file, info).GetBaseField();

                AssetTypeValueField transformPtr = baseField["m_Component"]["Array"][0]["component"];
                AssetTypeValueField transform    = helper.GetExtAsset(correctAti, transformPtr).instance.GetBaseField();
                baseField = GetRootTransform(helper, currentFile, transform);
                AssetTypeValueField gameObjectPtr = baseField["m_GameObject"];
                AssetTypeValueField gameObject    = helper.GetExtAsset(correctAti, gameObjectPtr).instance.GetBaseField();
                GameObjectViewer    view          = new GameObjectViewer(helper, correctAti, gameObject, info.index, id);
                view.Show();
            }
            else
            {
                AssetTypeValueField baseField = helper.GetATI(correctAti.file, info).GetBaseField();
                GameObjectViewer    view      = new GameObjectViewer(helper, correctAti, baseField, info);
                view.Show();
            }
        }
Exemplo n.º 4
0
        internal static void ChangeDisableUnityAudio(string path, bool newValue, QModGame game)
        {
            if (game != QModGame.Subnautica && game != QModGame.BelowZero)
            {
                throw new ArgumentException("Neither Subnautica nor Below Zero detected!");
            }
            AssetsManager      am  = new AssetsManager();
            AssetsFileInstance afi = am.LoadAssetsFile(path, false);

            if (game == QModGame.Subnautica)
            {
                am.LoadClassDatabase("cldb.dat");
            }
            else
            {
                am.LoadClassDatabase("cldb2018.dat");
            }
            AssetFileInfoEx     audioInfo      = afi.table.getAssetInfo(4);
            AssetTypeInstance   audioAti       = am.GetATI(afi.file, audioInfo);
            AssetTypeValueField audioBaseField = audioAti.GetBaseField();

            audioBaseField.Get("m_DisableAudio").GetValue().Set(newValue);
            byte[] audioAsset;
            using (MemoryStream memStream = new MemoryStream())
                using (AssetsFileWriter writer = new AssetsFileWriter(memStream))
                {
                    writer.bigEndian = false;
                    audioBaseField.Write(writer);
                    audioAsset = memStream.ToArray();
                }
            List <AssetsReplacer> rep = new List <AssetsReplacer>()
            {
                new AssetsReplacerFromMemory(0, 4, 0x0B, 0xFFFF, audioAsset)
            };

            using (MemoryStream memStream = new MemoryStream())
                using (AssetsFileWriter writer = new AssetsFileWriter(memStream))
                {
                    afi.file.Write(writer, 0, rep.ToArray(), 0);
                    afi.stream.Close();
                    File.WriteAllBytes(path, memStream.ToArray());
                }
        }
Exemplo n.º 5
0
        private static string GetLevelName(AssetsManager am, int index)
        {
            AssetsFileInstance inst = am.files.FirstOrDefault(f => f.name == "globalgamemanagers");

            if (inst == null)
            {
                return(string.Empty);
            }
            AssetFileInfoEx bsInf = inst.table.GetAssetsOfType(0x8D).FirstOrDefault(); //BuildSettings

            if (bsInf == null)
            {
                return(string.Empty);
            }
            AssetTypeValueField bsBaseField = am.GetATI(inst.file, bsInf).GetBaseField();
            AssetTypeValueField scenes      = bsBaseField.Get("scenes").Get("Array");

            return(scenes[(uint)index].GetValue().AsString());
        }
Exemplo n.º 6
0
        public void LoadMainAssetsFile(AssetsFileInstance inst)
        {
            if (currentFile == null || Path.GetFullPath(currentFile.path) != Path.GetFullPath(inst.path))
            {
                inst.table.GenerateQuickLookupTree();
                helper.UpdateDependencies();
                helper.LoadClassDatabaseFromPackage(inst.file.typeTree.unityVersion);
                if (helper.classFile == null)
                {
                    //may still not work but better than nothing I guess
                    //in the future we should probably do a selector
                    //like uabe does
                    List <ClassDatabaseFile> files = helper.classPackage.files;
                    helper.classFile = files[files.Count - 1];
                }
                UpdateFileList();
                currentFile = inst;

                string ggmPath = Path.Combine(Path.GetDirectoryName(inst.path), "globalgamemanagers");
                if (inst.name == "resources.assets" && File.Exists(ggmPath))
                {
                    if (MessageBox.Show("Load resources.assets in directory mode? (Significantly faster)", "Assets View",
                                        MessageBoxButtons.YesNo) == DialogResult.Yes)
                    {
                        AssetsFileInstance ggmInst = helper.LoadAssetsFile(ggmPath, true);
                        helper.UpdateDependencies();
                        LoadResources(ggmInst);
                    }
                    else
                    {
                        LoadGeneric(inst, false);
                    }
                }
                else
                {
                    LoadGeneric(inst, false);
                }

                string[] vers   = helper.classFile.header.unityVersions;
                string   corVer = vers.FirstOrDefault(v => !v.Contains("*"));
                Text = "AssetsView .NET - ver " + inst.file.typeTree.unityVersion + " / db " + corVer;
            }
        }
Exemplo n.º 7
0
        private void XRefsDialog_Load(object sender, EventArgs e)
        {
            List <AssetID> xrefs = map.GetXRefs(id);

            if (xrefs == null)
            {
                xrefList.Items.Add("[no xrefs]");
            }
            else
            {
                foreach (AssetID id in xrefs)
                {
                    int instIndex = am.files.FindIndex(f => Path.GetFileName(f.path).ToLower() == Path.GetFileName(id.fileName).ToLower());
                    if (instIndex != -1)
                    {
                        AssetsFileInstance xrefInst = am.files[instIndex];
                        AssetsFile         xrefFile = xrefInst.file;
                        AssetFileInfoEx    xrefInf  = xrefInst.table.GetAssetInfo(id.pathID);
                        uint fixedId     = AssetHelper.FixAudioID(xrefInf.curFileType);
                        bool hasTypeTree = xrefFile.typeTree.hasTypeTree;

                        string assetName = AssetHelper.GetAssetNameFast(xrefFile, am.classFile, xrefInf);
                        string typeName;
                        if (hasTypeTree)
                        {
                            Type_0D xrefType = AssetHelper.FindTypeTreeTypeByID(xrefFile.typeTree, fixedId);
                            typeName = xrefType.typeFieldsEx[0].GetTypeString(xrefType.stringTable);
                        }
                        else
                        {
                            ClassDatabaseType xrefType = AssetHelper.FindAssetClassByID(am.classFile, fixedId);
                            typeName = xrefType.name.GetString(am.classFile);
                        }
                        xrefList.Items.Add(new ListBoxInfo($"{id.fileName} {id.pathID} ({typeName} {assetName})", id));
                    }
                    else
                    {
                        xrefList.Items.Add(new ListBoxInfo($"{id.fileName} {id.pathID}", id));
                    }
                }
            }
        }
Exemplo n.º 8
0
        private static bool TryParseTypeTree(AssetsFileInstance fileInst, ref string type, bool createBlankAsset, out AssetTypeTemplateField templateField, out int typeId)
        {
            templateField = null;

            var     tt = fileInst.file.typeTree;
            Type_0D ttType;
            bool    needsTypeId;

            if (int.TryParse(type, out typeId))
            {
                ttType      = AssetHelper.FindTypeTreeTypeByID(tt, (uint)typeId);
                needsTypeId = false;
            }
            else
            {
                ttType      = AssetHelper.FindTypeTreeTypeByName(tt, type);
                needsTypeId = true;
            }

            if (ttType == null)
            {
                return(false);
            }

            if (needsTypeId)
            {
                typeId = ttType.classId;
            }

            if (createBlankAsset)
            {
                templateField = new AssetTypeTemplateField();
                if (ttType.typeFieldsExCount == 0)
                {
                    typeId = 0x01;
                    ttType = AssetHelper.FindTypeTreeTypeByID(tt, 0x01);
                }
                type = ttType.typeFieldsEx[0].GetTypeString(ttType.stringTable);
                templateField.From0D(ttType, 0);
            }
            return(true);
        }
Exemplo n.º 9
0
 public static bool AllDependenciesLoaded(AssetsManager am, AssetsFileInstance afi)
 {
     foreach (AssetsFileDependency dep in afi.file.dependencies.dependencies)
     {
         string absAssetPath = dep.assetPath;
         if (absAssetPath.StartsWith("archive:/"))
         {
             return(false); //todo
         }
         if (!Path.IsPathRooted(absAssetPath))
         {
             absAssetPath = Path.Combine(Path.GetDirectoryName(afi.path), dep.assetPath);
         }
         if (!am.files.Any(d => d != null && Path.GetFileName(d.path).ToLower() == Path.GetFileName(absAssetPath).ToLower()))
         {
             return(false);
         }
     }
     return(true);
 }
Exemplo n.º 10
0
        public List <AssetInfo> LoadAllFSMsFromFile(string path)
        {
            curFile = am.LoadAssetsFile(path, true);
            am.UpdateDependencies();

            am.LoadClassDatabaseFromPackage(curFile.file.typeTree.unityVersion);

            AssetsFile      file  = curFile.file;
            AssetsFileTable table = curFile.table;

            //we read manually with binaryreader to speed up reading, but sometimes the dataVersion field won't exist
            //so here we read the template manually to see whether it exists and back up a bit if it doesn't
            string           assemblyPath = Path.Combine(Path.GetDirectoryName(curFile.path), "Managed", "PlayMaker.dll");
            MonoDeserializer deserializer = new MonoDeserializer();

            deserializer.Read("PlayMakerFSM", MonoDeserializer.GetAssemblyWithDependencies(assemblyPath), file.header.format);
            bool hasDataField = deserializer.children[0].children[0].name == "dataVersion";

            return(GetFSMInfos(file, table, hasDataField));
        }
Exemplo n.º 11
0
        private void OpenFile(string fileName)
        {
            ResetUI();
            Text = TITLE_DEF + " [loading assets...]";

            activeFile = am.LoadAssetsFile(fileName, true);
            am.LoadClassDatabaseFromPackage(activeFile.file.typeTree.unityVersion);
            am.UpdateDependencies();

            bitmapCache = new Dictionary <AssetID, Bitmap>();

            GetTk2dSprites(activeFile);

            spriteCollectionsList.Items.Add("==================================");
            spriteCollectionsList.Items.Add(Path.GetFileName(fileName));
            spriteCollectionsList.Items.Add("==================================");
            spriteCollectionsList.Items.AddRange(collections.ToArray());

            Text = TITLE_DEF;
        }
Exemplo n.º 12
0
        private static AssetTypeValueField GetEDMono(AssetsManager am, AssetsFileInstance fileInst, AssetTypeValueField goBaseField)
        {
            AssetTypeValueField m_Components = goBaseField.Get("m_Components").Get("Array");

            for (int i = 0; i < m_Components.GetValue().AsArray().size; i++)
            {
                AssetTypeValueField component = m_Components[i];
                AssetExternal       ext       = am.GetExtAsset(fileInst, component, true);
                if (ext.info.curFileType == 0x72)
                {
                    //todo, check if this is the right monob
                    //as there's only one this is fine for now
                    //but I still hate this
                    ext = am.GetExtAsset(fileInst, component, false);
                    AssetTypeValueField monoBaseField = ext.instance.GetBaseField();
                    return(monoBaseField);
                }
            }
            return(null);
        }
Exemplo n.º 13
0
        public static ulong RecurseShaderDependencies(AssetsManager am, AssetsFileInstance baseInst, ulong pathId, AssetTypeValueField shaderPPtr, List <AssetsReplacer> assets, Dictionary <AssetID, ulong> assetMap, out ulong outPathId)
        {
            //UnityEngine.Debug.Log("RSD Running");
            AssetsFileInstance shaderInst;
            int shaderFileId = shaderPPtr.Get("m_FileID").GetValue().AsInt();

            if (shaderFileId == 0)
            {
                shaderInst = baseInst;
            }
            else
            {
                shaderInst = baseInst.dependencies[shaderFileId - 1];
            }

            AssetID shaderId = new AssetID(Path.GetFileName(shaderInst.path), shaderPPtr.Get("m_PathID").GetValue().AsInt64());

            if (assetMap.ContainsKey(shaderId))
            {
                outPathId = pathId;
                return(assetMap[shaderId]);
            }
            AssetTypeValueField shaderBaseField = am.GetExtAsset(baseInst, shaderPPtr).instance.GetBaseField();

            List <ulong>        dependencies   = new List <ulong>();
            AssetTypeValueField m_Dependencies = shaderBaseField.Get("m_Dependencies").Get("Array");

            foreach (AssetTypeValueField m_Dependency in m_Dependencies.pChildren)
            {
                //UnityEngine.Debug.Log("from file " + Path.GetFileName(baseInst.path) + shaderPPtr.Get("m_FileID").GetValue().AsInt() + ":" + shaderPPtr.Get("m_PathID").GetValue().AsInt() + " getting pptr " + m_Dependency.Get("m_FileID").GetValue().AsInt() + ":" + m_Dependency.Get("m_PathID").GetValue().AsInt64());
                dependencies.Add(RecurseShaderDependencies(am, shaderInst, pathId, m_Dependency, assets, assetMap, out pathId));
            }

            ulong shaderPathid = pathId;

            assetMap.Add(shaderId, pathId);
            assets.Add(ShaderConverter.ConvertShader(shaderBaseField, pathId++, dependencies));

            outPathId = pathId;
            return(shaderPathid);
        }
Exemplo n.º 14
0
    public static void OpenSceneByName()
    {
        AssetsManager am = new AssetsManager();

        am.LoadClassPackage(Path.Combine(Application.dataPath, "cldb.dat"));

        string gameDataPath = GetGamePath();

        AssetsFileInstance inst          = am.LoadAssetsFile(Path.Combine(gameDataPath, "globalgamemanagers"), false);
        AssetFileInfoEx    buildSettings = inst.table.getAssetInfo(11);

        List <string>       scenes     = new List <string>();
        AssetTypeValueField baseField  = am.GetATI(inst.file, buildSettings).GetBaseField();
        AssetTypeValueField sceneArray = baseField.Get("scenes").Get("Array");

        for (uint i = 0; i < sceneArray.GetValue().AsArray().size; i++)
        {
            scenes.Add(sceneArray[i].GetValue().AsString() + "[" + i + "]");
        }
        SceneSelector sel = SceneSelector.ShowDialog(am, scenes, gameDataPath);
    }
Exemplo n.º 15
0
        private void addFileToolStripMenuItem_Click(object sender, EventArgs e)
        {
            OpenFileDialog ofd = new OpenFileDialog();

            ofd.DefaultExt = "";
            if (ofd.ShowDialog() == DialogResult.OK)
            {
                OpenAssetsDialog openFile = new OpenAssetsDialog(ofd.FileName);
                openFile.ShowDialog();
                if (openFile.selection > -1)
                {
                    AssetsFileInstance inst = helper.LoadAssetsFile(ofd.FileName, (openFile.selection == 0) ? false : true);
                    inst.table.GenerateQuickLookupTree();
                    helper.UpdateDependencies();
                    UpdateFileList();
                    string fileName = Path.GetFileName(ofd.FileName);
                    currentFile = inst;
                    LoadGeneric(inst, false);
                }
            }
        }
Exemplo n.º 16
0
        private void LoadGeneric(AssetsFileInstance mainFile, bool isLevel)
        {
            //Dictionary<string, AssetDetails> paths = new Dictionary<string, AssetDetails>();
            List <AssetDetails> assets = new List <AssetDetails>();

            foreach (AssetFileInfoEx info in mainFile.table.pAssetFileInfo)
            {
                ClassDatabaseType type = AssetHelper.FindAssetClassByID(helper.classFile, info.curFileType);
                if (type == null)
                {
                    continue;
                }
                string typeName = type.name.GetString(helper.classFile);
                if (typeName != "GameObject" && isLevel)
                {
                    continue;
                }
                string name = AssetInfo.GetAssetNameFast(info, helper.classFile, type, mainFile);
                if (name == "")
                {
                    name = "[Unnamed]";
                }
                //int count = 0;
                //string newName = name;
                //while (paths.Keys.Contains(newName)/* && count < 20*/)
                //{
                //    count++;
                //    newName = $"{name} ({count})";
                //}
                //if (count < 20)
                //{
                //paths[newName] = new AssetDetails(new AssetPPtr(0, info.index), name, typeName, (int)info.curFileSize);
                assets.Add(new AssetDetails(new AssetPPtr(0, info.index), GetIconForName(typeName), name, typeName, (int)info.curFileSize));
                //}
            }
            rootDir = new FSDirectory();
            //rootDir.Create(paths);
            rootDir.Create(assets);
            ChangeDirectory("");
        }
Exemplo n.º 17
0
        public static AssetExternal GetExtAssetNewData(this AssetsManager _this, AssetsFileInstance relativeTo, int fileId, long pathId,
                                                       Stream data, 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.GetDependency(_this, fileId - 1);
                ext.info = dep.table.GetAssetInfo(pathId);
                if (!onlyGetInfo)
                {
                    ext.instance = _this.GetTypeInstanceNewData(dep.file, ext.info, data, forceFromCldb);
                }
                else
                {
                    ext.instance = null;
                }
                ext.file = dep;
            }
            else
            {
                ext.info = relativeTo.table.GetAssetInfo(pathId);
                if (!onlyGetInfo)
                {
                    ext.instance = _this.GetTypeInstanceNewData(relativeTo.file, ext.info, data, forceFromCldb);
                }
                else
                {
                    ext.instance = null;
                }
                ext.file = relativeTo;
            }
            return(ext);
        }
Exemplo n.º 18
0
        public void AddReplacer(AssetsFileInstance forFile, AssetsReplacer replacer, Stream? previewStream = null)
        {
            AssetsFile assetsFile = forFile.file;
            AssetID assetId = new AssetID(forFile.path, replacer.GetPathID());

            if (NewAssets.ContainsKey(assetId))
                RemoveReplacer(forFile, NewAssets[assetId], true);

            NewAssets[assetId] = replacer;

            //make stream to use as a replacement to the one from file
            if (previewStream == null)
            {
                MemoryStream newStream = new MemoryStream();
                AssetsFileWriter newWriter = new AssetsFileWriter(newStream);
                replacer.Write(newWriter);
                newStream.Position = 0;
                previewStream = newStream;
            }
            NewAssetDatas[assetId] = previewStream;

            if (!(replacer is AssetsRemover))
            {
                AssetsFileReader reader = new AssetsFileReader(previewStream);
                AssetContainer cont = new AssetContainer(
                    reader, 0, replacer.GetPathID(), (uint)replacer.GetClassID(),
                    replacer.GetMonoScriptID(), (uint)previewStream.Length, forFile);

                LoadedAssets[assetId] = cont;
            }
            else
            {
                LoadedAssets.Remove(assetId);
            }

            if (ItemUpdated != null)
                ItemUpdated(forFile, assetId);

            Modified = true;
        }
Exemplo n.º 19
0
        private void FixAsset(AssetsFileInstance inst, AssetTypeValueField field, AssetFileInfoEx inf)
        {
            if (inf.curFileType == 0x01) //fix gameobject
            {
                AssetTypeValueField Array = field.Get("m_Component").Get("Array");
                //remove all null pointers
                List <AssetTypeValueField> newFields = Array.pChildren.Where(f =>
                                                                             f.pChildren[0].pChildren[1].GetValue().AsInt64() != 0
                                                                             ).ToList();

                //add editdiffer monobehaviour
                newFields.Add(CreatePPtrField(0, sceneId)); //this will be pathId that the below will go into
                AssetID aid = ConvertToAssetID(inst, 0, (long)inf.index);
                AddReplacer(CreateEditDifferMonoBehaviour(references[aid].pathId, Array, aid, rand), 0x72, 0x0000, false);

                uint newSize = (uint)newFields.Count;
                Array.SetChildrenList(newFields.ToArray(), newSize);
                Array.GetValue().Set(new AssetTypeArray()
                {
                    size = newSize
                });
            }
            else if (inf.curFileType == 0x1c) //fix texture2d
            {
                AssetTypeValueField path = field.Get("m_StreamData").Get("path");
                string pathString        = path.GetValue().AsString();
                string directory         = Path.GetDirectoryName(inst.path);
                string fixedPath         = Path.Combine(directory, pathString);
                path.GetValue().Set(fixedPath);
            }
            else if (inf.curFileType == 0x53) //fix audioclip
            {
                AssetTypeValueField path = field.Get("m_Resource").Get("m_Source");
                string pathString        = path.GetValue().AsString();
                string directory         = Path.GetDirectoryName(inst.path);
                string fixedPath         = Path.Combine(directory, pathString);
                path.GetValue().Set(fixedPath);
            }
        }
Exemplo n.º 20
0
        public static AssetExternal GetExtAsset(this AssetsManager am, AssetsFileInstance relativeTo, int fileId, long pathId, bool onlyGetInfo = 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 = am.GetATI(dep.file, ext.info);
                }
                else
                {
                    ext.instance = null;
                }
                ext.file = dep;
            }
            else
            {
                ext.info = relativeTo.table.GetAssetInfo(pathId);
                if (!onlyGetInfo)
                {
                    ext.instance = am.GetATI(relativeTo.file, ext.info);
                }
                else
                {
                    ext.instance = null;
                }
                ext.file = relativeTo;
            }
            return(ext);
        }
Exemplo n.º 21
0
        private void OpenScene_Click(object sender, RoutedEventArgs e)
        {
            if (am == null)
            {
                CreateAssetManager();
            }

            string gameDataPath = GetGamePath();

            if (string.IsNullOrEmpty(gameDataPath))
            {
                return;
            }

            AssetsFileInstance inst          = am.LoadAssetsFile(Path.Combine(gameDataPath, "globalgamemanagers"), false);
            AssetFileInfoEx    buildSettings = inst.table.GetAssetInfo(11);

            List <string>       scenes     = new List <string>();
            AssetTypeValueField baseField  = am.GetATI(inst.file, buildSettings).GetBaseField();
            AssetTypeValueField sceneArray = baseField.Get("scenes").Get("Array");

            for (int i = 0; i < sceneArray.GetValue().AsArray().size; i++)
            {
                scenes.Add(sceneArray[i].GetValue().AsString());
            }
            SceneSelector sel = new SceneSelector(scenes);

            sel.ShowDialog();
            if (sel.selectedFile != "")
            {
                int    levelId  = scenes.IndexOf(sel.selectedFile);
                string filePath = Path.Combine(gameDataPath, "level" + levelId);
                lastFilename       = filePath;
                openLast.IsEnabled = true;
                closeTab.IsEnabled = true;
                LoadFSMs(filePath);
            }
        }
Exemplo n.º 22
0
        public static string[] ActionValues(AssetTypeValueField actionData, AssetsFileInstance inst, int version)
        {
            AssetTypeValueField paramDataType = actionData.Get("paramDataType");
            int paramCount = paramDataType.GetValue().AsArray().size;

            byte[]       byteData = GetByteData(actionData.Get("byteData"));
            MemoryStream stream   = new MemoryStream(byteData);
            BinaryReader reader   = new BinaryReader(stream);

            string[] actionValues = new string[paramCount];
            for (int i = 0; i < paramCount; i++)
            {
                ParamDataType type              = (ParamDataType)paramDataType.Get(i).GetValue().AsInt();
                int           paramDataPos      = actionData.Get("paramDataPos").Get(i).GetValue().AsInt();
                int           paramByteDataSize = actionData.Get("paramByteDataSize").Get(i).GetValue().AsInt();
                reader.BaseStream.Position = paramDataPos;
                string displayValue = GetDisplayValue(actionData, inst, version, type, paramDataPos, paramByteDataSize, reader);
                actionValues[i] = displayValue;
            }
            reader.Close();
            stream.Close();
            return(actionValues);
        }
Exemplo n.º 23
0
        /////////////////////////////////////////////////////////

        private static void CreateEditDifferTypeTree(ClassDatabaseFile cldb, AssetsFileInstance inst)
        {
            Type_0D type = C2T5.Cldb2TypeTree(cldb, 0x72);

            type.scriptIndex = 0x0000;
            type.unknown1    = Constants.editDifferScriptNEHash[0];
            type.unknown2    = Constants.editDifferScriptNEHash[1];
            type.unknown3    = Constants.editDifferScriptNEHash[2];
            type.unknown4    = Constants.editDifferScriptNEHash[3];

            TypeTreeEditor editor    = new TypeTreeEditor(type);
            TypeField_0D   baseField = type.pTypeFieldsEx[0];

            editor.AddField(baseField, editor.CreateTypeField("unsigned int", "fileId", 1, 4, 0, false));
            editor.AddField(baseField, editor.CreateTypeField("UInt64", "pathId", 1, 8, 0, false));
            editor.AddField(baseField, editor.CreateTypeField("UInt64", "origPathId", 1, 8, 0, false));
            editor.AddField(baseField, editor.CreateTypeField("UInt8", "newAsset", 1, 1, 0, true));
            editor.AddField(baseField, editor.CreateTypeField("int", "instanceId", 1, 4, 0, false));
            type = editor.SaveType();

            inst.file.typeTree.pTypes_Unity5 = inst.file.typeTree.pTypes_Unity5.Concat(new Type_0D[] { type }).ToArray();
            inst.file.typeTree.fieldCount++;
        }
Exemplo n.º 24
0
        public void RemoveReplacer(AssetsFileInstance forFile, AssetsReplacer replacer, bool closePreviewStream = true)
        {
            AssetID assetId = new AssetID(forFile.path, replacer.GetPathID());

            if (NewAssets.ContainsKey(assetId))
            {
                NewAssets.Remove(assetId);
            }
            if (NewAssetDatas.ContainsKey(assetId))
            {
                if (closePreviewStream)
                    NewAssetDatas[assetId].Close();
                NewAssetDatas.Remove(assetId);
            }
            if (replacer is AssetsRemover && RemovedAssets.Contains(assetId))
                RemovedAssets.Remove(assetId);

            if (ItemUpdated != null)
                ItemUpdated(forFile, assetId);

            if (NewAssets.Count == 0)
                Modified = false;
        }
Exemplo n.º 25
0
        public AssetContainer GetAssetContainer(AssetsFileInstance fileInst, int fileId, long pathId, bool onlyInfo = true)
        {
            if (fileId != 0)
            {
                fileInst = fileInst.GetDependency(am, fileId - 1);
            }

            if (fileInst != null)
            {
                AssetID assetId = new AssetID(fileInst.path, pathId);
                if (LoadedAssets.TryGetValue(assetId, out AssetContainer? cont))
                {
                    if (!onlyInfo && !cont.HasInstance)
                    {
                        AssetTypeTemplateField tempField = GetTemplateField(cont.FileInstance.file, cont.ClassId, cont.MonoId);
                        AssetTypeInstance typeInst = new AssetTypeInstance(tempField, cont.FileReader, cont.FilePosition);
                        cont = new AssetContainer(cont, typeInst);
                    }
                    return cont;
                }
            }
            return null;
        }
Exemplo n.º 26
0
        public bool Load(FileStream bundleStream)
        {
            bundle = manager.LoadBundleFile(bundleStream);

            // The LO bundles don't indicate they are packed when checking the header flags.  We check the reported
            // asset sizes and unpack if needed.
            if (IsPacked(bundle))
            {
                bundle = Unpack(manager, bundle, unpackFile);
            }

            var files = BundleHelper.LoadAllAssetsDataFromBundle(bundle.file);

            assetsFileStream = new MemoryStream(files[0]);

            assetsFile = manager.LoadAssetsFile(assetsFileStream, bundle.file.bundleInf6.dirInf[0].name, true);

            assetsFile.table.GenerateQuickLookupTree();
            manager.UpdateDependencies();
            manager.LoadClassDatabaseFromPackage(assetsFile.file.typeTree.unityVersion);

            return(true);
        }
Exemplo n.º 27
0
Arquivo: Menu.cs Projeto: Igor55x/UAAE
        private bool LoadOrAskCldb(AssetsFileInstance fileInst)
        {
            var unityVersion = fileInst.file.typeTree.unityVersion;

            if (Am.LoadClassDatabaseFromPackage(unityVersion) == null)
            {
                var version = new VersionDialog(unityVersion, Am.classPackage);
                if (version.ShowDialog() != DialogResult.OK)
                {
                    return(false);
                }

                if (version.SelectedCldb != null)
                {
                    Am.classFile = version.SelectedCldb;
                }
                else
                {
                    return(false);
                }
            }
            return(true);
        }
Exemplo n.º 28
0
        private void BackgroundWork(object sender, DoWorkEventArgs e)
        {
            int i = 0;

            foreach (string fileName in fileNames)
            {
                bw.ReportProgress(0, (float)i / fileNames.Count);
                bw.ReportProgress(1, fileName);
                AssetsFileInstance inst = am.LoadAssetsFile(fileName, true);
                am.LoadClassDatabaseFromPackage(inst.file.typeTree.unityVersion);
                int j = 0;
                foreach (AssetFileInfoEx inf in inst.table.assetFileInfo)
                {
                    if (j % 500 == 0)
                    {
                        bw.ReportProgress(2, (float)j / inst.table.assetFileInfoCount);
                    }

                    AssetID             id = new AssetID(Path.GetFileName(inst.name), inf.index);
                    AssetTypeValueField baseField;
                    if (inf.curFileType == 0x72)
                    {
                        baseField = am.GetMonoBaseFieldCached(inst, inf, Path.Combine(dirName, "Managed"));
                    }
                    else
                    {
                        baseField = am.GetTypeInstance(inst.file, inf).GetBaseField();
                    }

                    RecurseReferences(inst, id, baseField);

                    j++;
                }
                i++;
            }
            bw.ReportProgress(3);
        }
Exemplo n.º 29
0
        private void SetPPtrEvents(TreeViewItem item, AssetsFileInstance fromFile, AssetContainer cont)
        {
            item.Tag = false;
            var expandObs = item.GetObservable(TreeViewItem.IsExpandedProperty);

            expandObs.Subscribe(isExpanded =>
            {
                if (isExpanded && !(bool)item.Tag)
                {
                    item.Tag = true; //don't load this again

                    if (cont != null)
                    {
                        AssetTypeValueField baseField = workspace.GetBaseField(cont);
                        TreeViewItem baseItem         = CreateTreeItem($"{baseField.GetFieldType()} {baseField.GetName()}");

                        TreeViewItem arrayIndexTreeItem = CreateTreeItem("Loading...");
                        baseItem.Items = new List <TreeViewItem>()
                        {
                            arrayIndexTreeItem
                        };
                        item.Items = new List <TreeViewItem>()
                        {
                            baseItem
                        };
                        SetTreeItemEvents(baseItem, cont.FileInstance, baseField);
                    }
                    else
                    {
                        item.Items = new List <TreeViewItem>()
                        {
                            CreateTreeItem("[null asset]")
                        };
                    }
                }
            });
        }
Exemplo n.º 30
0
        private bool TryParseTypeTree(AssetsFileInstance file, string typeIdText, bool createBlankAsset, out AssetTypeTemplateField tempField, out int typeId)
        {
            tempField = null;

            TypeTree tt = file.file.typeTree;
            Type_0D  ttType;
            bool     needsTypeId;

            if (int.TryParse(typeIdText, out typeId))
            {
                ttType      = AssetHelper.FindTypeTreeTypeByID(tt, (uint)typeId);
                needsTypeId = false;
            }
            else
            {
                ttType      = AssetHelper.FindTypeTreeTypeByName(tt, typeIdText);
                needsTypeId = true;
            }

            if (ttType == null)
            {
                return(false);
            }

            if (needsTypeId)
            {
                typeId = ttType.classId;
            }

            if (createBlankAsset)
            {
                tempField = new AssetTypeTemplateField();
                tempField.From0D(ttType, 0);
            }
            return(true);
        }