示例#1
0
        private void LoadGeneric(AssetsFileInstance mainFile, bool isLevel)
        {
            List <AssetDetails> assets = new List <AssetDetails>();

            foreach (AssetFileInfoEx info in mainFile.table.assetFileInfo)
            {
                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 = AssetHelper.GetAssetNameFast(mainFile.file, helper.classFile, info);
                if (name == "")
                {
                    name = "[Unnamed]";
                }
                assets.Add(new AssetDetails(new AssetPPtr(0, info.index), GetIconForName(typeName), name, typeName, (int)info.curFileSize));
            }
            rootDir = new FSDirectory();
            rootDir.Create(assets);
            ChangeDirectory("");
        }
示例#2
0
        private void LoadResources(AssetsFileInstance ggm)
        {
            foreach (AssetFileInfoEx info in ggm.table.assetFileInfo)
            {
                ClassDatabaseType type = AssetHelper.FindAssetClassByID(helper.classFile, info.curFileType);
                if (type.name.GetString(helper.classFile) == "ResourceManager")
                {
                    AssetTypeInstance   inst        = helper.GetTypeInstance(ggm.file, info);
                    AssetTypeValueField baseField   = inst.GetBaseField();
                    AssetTypeValueField m_Container = baseField.Get("m_Container").Get("Array");
                    List <AssetDetails> assets      = new List <AssetDetails>();
                    for (int i = 0; i < m_Container.GetValue().AsArray().size; i++)
                    {
                        AssetTypeValueField item = m_Container[i];
                        string path = item.Get("first").GetValue().AsString();
                        AssetTypeValueField pointerField = item.Get("second");
                        //paths[path] = new AssetDetails(new AssetPPtr(fileID, pathID));

                        AssetExternal   assetExt  = helper.GetExtAsset(ggm, pointerField, true);
                        AssetFileInfoEx assetInfo = assetExt.info;
                        if (assetInfo == null)
                        {
                            continue;
                        }
                        ClassDatabaseType assetType = AssetHelper.FindAssetClassByID(helper.classFile, assetInfo.curFileType);
                        if (assetType == null)
                        {
                            continue;
                        }
                        string assetTypeName = assetType.name.GetString(helper.classFile);
                        string assetName     = AssetHelper.GetAssetNameFast(assetExt.file.file, helper.classFile, assetInfo);
                        if (path.Contains("/"))
                        {
                            if (path.Substring(path.LastIndexOf('/') + 1) == assetName.ToLower())
                            {
                                path = path.Substring(0, path.LastIndexOf('/') + 1) + assetName;
                            }
                        }
                        else
                        {
                            if (path == assetName.ToLower())
                            {
                                path = path.Substring(0, path.LastIndexOf('/') + 1) + assetName;
                            }
                        }

                        assets.Add(new AssetDetails(new AssetPPtr(0, assetInfo.index), GetIconForName(assetTypeName), path, assetTypeName, (int)assetInfo.curFileSize));
                    }
                    rootDir = new FSDirectory();
                    //rootDir.Create(paths);
                    rootDir.Create(assets);
                    ChangeDirectory("");
                    helper.UpdateDependencies();
                    CheckResourcesInfo();
                    return;
                }
            }
        }
示例#3
0
 private static AssetFileInfoEx FindGameObject(AssetsManager am, AssetsFileInstance inst, string name)
 {
     foreach (AssetFileInfoEx info in inst.table.pAssetFileInfo)
     {
         if (info.curFileType == 0x01)
         {
             ClassDatabaseType type     = AssetHelper.FindAssetClassByID(am.classFile, info.curFileType);
             string            infoName = AssetHelper.GetAssetNameFast(inst.file, am.classFile, info);
             if (infoName == name)
             {
                 return(info);
             }
         }
     }
     return(null);
 }
示例#4
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));
                    }
                }
            }
        }
        public IList <AssetsToolsAsset> GetAssets()
        {
            var assets = new List <AssetsToolsAsset>();

            foreach (var info in assetsFile.table.assetFileInfo)
            {
                var type = AssetHelper.FindAssetClassByID(manager.classFile, info.curFileType);
                if (type == null)
                {
                    continue;
                }

                var typeName  = type.name.GetString(manager.classFile);
                var assetName = AssetHelper.GetAssetNameFast(assetsFile.file, manager.classFile, info);
                var baseField = manager.GetATI(assetsFile.file, info).GetBaseField();

                assets.Add(new AssetsToolsAsset(info, typeName, assetName, baseField));
            }

            return(assets);
        }
示例#6
0
        private void GetTk2dSprites(AssetsFileInstance inst)
        {
            collections    = new List <TkSpriteCollection>();
            animations     = new List <TkSpriteAnimation>();
            animationClips = new List <TkSpriteAnimationClip>();
            List <TkSpriteFrame> sprFrames = new List <TkSpriteFrame>();
            string managedPath             = Path.Combine(Path.GetDirectoryName(inst.path), "Managed");

            Dictionary <AssetID, TkSpriteCollection> collectionLookup = new Dictionary <AssetID, TkSpriteCollection>();
            int tk2dSCid = -1;
            int tk2dSAid = -1;

            foreach (AssetFileInfoEx mbInf in inst.table.GetAssetsOfType(0x72))
            {
                string scriptName  = null;
                ushort scriptIndex = AssetHelper.GetScriptIndex(inst.file, mbInf);
                if (tk2dSCid != -1 && scriptIndex == tk2dSCid)
                {
                    scriptName = "tk2dSpriteCollectionData";
                }
                else if (tk2dSAid != -1 && scriptIndex == tk2dSAid)
                {
                    scriptName = "tk2dSpriteAnimation";
                }

                if (tk2dSCid == -1 || tk2dSAid == -1) //still looking for script ids
                {
                    AssetTypeValueField mbBase = am.GetATI(inst.file, mbInf).GetBaseField();
                    AssetTypeValueField scBase = am.GetExtAsset(inst, mbBase.Get("m_Script")).instance.GetBaseField();
                    scriptName = scBase.Get("m_Name").GetValue().AsString();
                    if (scriptName == "tk2dSpriteCollectionData")
                    {
                        tk2dSCid = scriptIndex;
                    }
                    else if (scriptName == "tk2dSpriteAnimation")
                    {
                        tk2dSAid = scriptIndex;
                    }
                    else
                    {
                        continue; //nope, nobody cares
                    }
                }

                if (scriptName == null)
                {
                    continue;
                }

                AssetTypeValueField mbSerialBase = am.GetMonoBaseFieldCached(inst, mbInf, managedPath);
                if (scriptName == "tk2dSpriteCollectionData")
                {
                    AssetTypeValueField textures = mbSerialBase.Get("textures");

                    List <AssetExternal> textureExts    = new List <AssetExternal>();
                    List <int>           textureWidths  = new List <int>();
                    List <int>           textureHeights = new List <int>();
                    for (int i = 0; i < textures.childrenCount; i++)
                    {
                        AssetExternal textureExt = am.GetExtAsset(inst, mbSerialBase.Get("textures")[i], true);
                        if (textureExt.info.curFileSize > 100000)
                        {
                            //bad news, unity probably stored the entire image into an array which is gonna
                            //take up too much memory when we decode it, so we'll change the data to a byte array
                            ClassDatabaseType      textureType = AssetHelper.FindAssetClassByID(am.classFile, textureExt.info.curFileType);
                            AssetTypeTemplateField textureTemp = new AssetTypeTemplateField();
                            textureTemp.FromClassDatabase(am.classFile, textureType, 0);
                            AssetTypeTemplateField image_data = textureTemp.children[textureTemp.childrenCount - 1];
                            image_data.valueType = EnumValueTypes.ByteArray; //convert array to bytearray, much better
                            AssetTypeInstance   textureTypeInstance = new AssetTypeInstance(new[] { textureTemp }, inst.file.reader, textureExt.info.absoluteFilePos);
                            AssetTypeValueField textureBase         = textureTypeInstance.GetBaseField();
                            textureExt.instance = textureTypeInstance;
                            textureExts.Add(textureExt);
                            textureWidths.Add(textureBase.Get("m_Width").GetValue().AsInt());
                            textureHeights.Add(textureBase.Get("m_Height").GetValue().AsInt());
                        }
                        else
                        {
                            textureExt = am.GetExtAsset(inst, mbSerialBase.Get("textures")[i]);
                            AssetTypeValueField textureBase = textureExt.instance.GetBaseField();
                            textureExts.Add(textureExt);
                            textureWidths.Add(textureBase.Get("m_Width").GetValue().AsInt());
                            textureHeights.Add(textureBase.Get("m_Height").GetValue().AsInt());
                        }
                    }

                    TkSpriteCollection collection = new TkSpriteCollection()
                    {
                        name        = mbSerialBase.Get("spriteCollectionName").GetValue().AsString(),
                        version     = mbSerialBase.Get("version").GetValue().AsInt(),
                        baseTexture = null,                           //do later
                        textures    = new Dictionary <int, Bitmap>(), //same
                        textureExts = textureExts,
                        sprites     = new List <TkSpriteDefinition>()
                    };
                    collectionLookup[new AssetID(inst.name, mbInf.index)] = collection;
                    AssetTypeValueField spriteDefinitions = mbSerialBase.Get("spriteDefinitions");
                    foreach (AssetTypeValueField def in spriteDefinitions.children)
                    {
                        bool flipped       = def.Get("flipped").GetValue().AsInt() == 1;
                        int  materialId    = def.Get("materialId").GetValue().AsInt();
                        int  textureWidth  = textureWidths[materialId];
                        int  textureHeight = textureHeights[materialId];

                        double uxn = double.MaxValue;
                        double uxp = 0;
                        double uyn = double.MaxValue;
                        double uyp = 0;
                        double pxn = double.MaxValue;
                        double pyn = double.MaxValue;
                        AssetTypeValueField positions = def.Get("positions");
                        AssetTypeValueField uvs       = def.Get("uvs");
                        for (int i = 0; i < 4; i++)
                        {
                            AssetTypeValueField pos = positions[i];
                            AssetTypeValueField uv  = uvs[i];
                            double posX             = pos.Get("x").GetValue().AsFloat();
                            double posY             = pos.Get("y").GetValue().AsFloat();
                            double uvX = Math.Round(uv.Get("x").GetValue().AsFloat() * textureWidth);
                            double uvY = textureHeight - Math.Round(uv.Get("y").GetValue().AsFloat() * textureHeight);
                            if (posX < pxn)
                            {
                                pxn = posX;
                            }
                            if (posY < pyn)
                            {
                                pyn = posY;
                            }

                            if (uvX < uxn)
                            {
                                uxn = uvX;
                            }
                            if (uvX > uxp)
                            {
                                uxp = uvX;
                            }
                            if (uvY < uyn)
                            {
                                uyn = uvY;
                            }
                            if (uvY > uyp)
                            {
                                uyp = uvY;
                            }
                        }
                        int spriteX      = (int)uxn;
                        int spriteY      = (int)uyn;
                        int spriteWidth  = (int)(uxp - uxn);
                        int spriteHeight = (int)(uyp - uyn);

                        AssetTypeValueField boundsData          = def.Get("boundsData");
                        AssetTypeValueField untrimmedBoundsData = def.Get("untrimmedBoundsData");
                        AssetTypeValueField texelSize           = def.Get("texelSize");

                        float texelX = texelSize.Get("x").GetValue().AsFloat();
                        float texelY = texelSize.Get("y").GetValue().AsFloat();

                        float realX = ((float)pxn) / texelX;
                        float realY = -((flipped ? spriteWidth : spriteHeight) + ((float)pyn) / texelY);

                        TkSpriteDefinition sprite = new TkSpriteDefinition()
                        {
                            parent     = collection,
                            name       = def.Get("name").GetValue().AsString(),
                            x          = spriteX,
                            y          = spriteY,
                            width      = spriteWidth,
                            height     = spriteHeight,
                            xOff       = realX,
                            yOff       = realY,
                            materialId = materialId,
                            fullWidth  = untrimmedBoundsData[1].Get("x").GetValue().AsFloat() / texelX,
                            fullHeight = untrimmedBoundsData[1].Get("y").GetValue().AsFloat() / texelY,
                            flipped    = flipped
                        };
                        collection.sprites.Add(sprite);
                    }
                    collections.Add(collection);
                }
                else if (scriptName == "tk2dSpriteAnimation")
                {
                    AssetFileInfoEx   gameObjectInfo = inst.table.GetAssetInfo(mbSerialBase.Get("m_GameObject").Get("m_PathID").GetValue().AsInt64());
                    TkSpriteAnimation animation      = new TkSpriteAnimation()
                    {
                        parents        = new List <TkSpriteCollection>(), //do later
                        parentIds      = new List <AssetID>(),
                        gameObjectName = AssetHelper.GetAssetNameFast(inst.file, am.classFile, gameObjectInfo),
                        clips          = new List <TkSpriteAnimationClip>()
                    };

                    AssetTypeValueField clips = mbSerialBase.Get("clips");
                    foreach (AssetTypeValueField clip in clips.children)
                    {
                        TkSpriteAnimationClip aniClip = new TkSpriteAnimationClip()
                        {
                            parent    = animation,
                            name      = clip.Get("name").GetValue().AsString(),
                            fps       = clip.Get("fps").GetValue().AsFloat(),
                            loopStart = clip.Get("loopStart").GetValue().AsInt(),
                            wrapMode  = (WrapMode)clip.Get("wrapMode").GetValue().AsInt(),
                            frames    = new List <TkSpriteFrame>()
                        };
                        animation.clips.Add(aniClip);
                        animationClips.Add(aniClip);

                        AssetTypeValueField frames = clip.Get("frames");
                        foreach (AssetTypeValueField frame in frames.children)
                        {
                            AssetExternal collectionExt = am.GetExtAsset(inst, frame.Get("spriteCollection"));
                            AssetID       collectionId  = new AssetID(collectionExt.file.name, collectionExt.info.index);
                            if (!animation.parentIds.Contains(collectionId))
                            {
                                animation.parentIds.Add(collectionId);
                            }
                            TkSpriteFrame sprFrame = new TkSpriteFrame()
                            {
                                collection   = null, //do later
                                collectionId = collectionId,
                                spriteId     = frame.Get("spriteId").GetValue().AsInt()
                            };
                            sprFrames.Add(sprFrame);
                            aniClip.frames.Add(sprFrame);
                        }
                    }
                    animations.Add(animation);
                }
            }

            foreach (TkSpriteAnimation animation in animations)
            {
                foreach (AssetID parentId in animation.parentIds)
                {
                    if (collectionLookup.ContainsKey(parentId))
                    {
                        animation.parents.Add(collectionLookup[parentId]);
                    }
                }
            }
            foreach (TkSpriteFrame frame in sprFrames)
            {
                if (collectionLookup.ContainsKey(frame.collectionId))
                {
                    frame.collection = collectionLookup[frame.collectionId];
                }
            }
        }
示例#7
0
        private ObservableCollection <AssetInfoDataGridItem> MakeDataGridItems()
        {
            dataGridItems = new ObservableCollection <AssetInfoDataGridItem>();

            bool usingTypeTree = assetsFile.file.typeTree.hasTypeTree;

            foreach (AssetFileInfoEx info in assetsFile.table.assetFileInfo)
            {
                string name;
                string container;
                string type;
                int    fileId;
                long   pathId;
                int    size;
                string modified;

                ClassDatabaseType cldbType = AssetHelper.FindAssetClassByID(am.classFile, info.curFileType);
                name      = AssetHelper.GetAssetNameFast(assetsFile.file, am.classFile, info); //handles both cldb and typetree
                container = string.Empty;
                fileId    = 0;
                pathId    = info.index;
                size      = (int)info.curFileSize;
                modified  = "";

                if (usingTypeTree)
                {
                    Type_0D ttType = assetsFile.file.typeTree.unity5Types[info.curFileTypeOrIndex];
                    if (ttType.typeFieldsEx.Length != 0)
                    {
                        type = ttType.typeFieldsEx[0].GetTypeString(ttType.stringTable);
                    }
                    else
                    {
                        if (cldbType != null)
                        {
                            type = cldbType.name.GetString(am.classFile);
                        }
                        else
                        {
                            type = $"0x{info.curFileType:X8}";
                        }
                    }
                }
                else
                {
                    if (cldbType != null)
                    {
                        type = cldbType.name.GetString(am.classFile);
                    }
                    else
                    {
                        type = $"0x{info.curFileType:X8}";
                    }
                }

                if (info.curFileType == 0x01)
                {
                    name = $"GameObject {name}";
                }
                if (name == string.Empty)
                {
                    name = "Unnamed asset";
                }

                var item = new AssetInfoDataGridItem()
                {
                    Name      = name,
                    Container = container,
                    Type      = type,
                    TypeID    = info.curFileType,
                    FileID    = fileId,
                    PathID    = pathId,
                    Size      = size,
                    Modified  = modified
                };

                dataGridItems.Add(item);
            }
            return(dataGridItems);
        }
示例#8
0
        private void AddAssetItem(AssetsFileInstance fileInst, AssetFileInfoEx info, int fileId = 0)
        {
            var          thisFile  = fileInst.file;
            var          cldb      = Am.classFile;
            var          cldbType  = AssetHelper.FindAssetClassByID(cldb, info.curFileType);
            var          name      = AssetHelper.GetAssetNameFast(thisFile, cldb, info); //handles both cldb and typetree
            const string container = "";
            string       type;
            var          typeId   = info.curFileType;
            var          pathId   = info.index;
            var          size     = (int)info.curFileSize;
            const string modified = "";
            ushort       monoId   = 0xFFFF;

            var hasTypeTree = thisFile.typeTree.hasTypeTree;

            if (hasTypeTree)
            {
                var ttType = AssetHelper.FindTypeTreeTypeByID(thisFile.typeTree, typeId);
                if (ttType == null)
                {
                    type = $"0x{typeId:X8}";
                }
                else if (ttType.typeFieldsEx.Length != 0)
                {
                    type = ttType.typeFieldsEx[0].GetTypeString(ttType.stringTable);
                }
                else
                {
                    type = cldbType != null?
                           cldbType.name.GetString(cldb) : $"0x{typeId:X8}";
                }
            }
            else
            {
                type = cldbType != null?
                       cldbType.name.GetString(cldb) : $"0x{typeId:X8}";
            }

            if (typeId == 0x72)
            {
                monoId = (ushort)(0xFFFFFFFF - info.curFileTypeOrIndex);
            }

            var item = new AssetItem
            {
                Name      = name,
                Container = container,
                Type      = type,
                TypeID    = typeId,
                FileID    = fileId,
                PathID    = pathId,
                Size      = size,
                Modified  = modified,
                Position  = info.absoluteFilePos,
                MonoID    = monoId
            };

            if (string.IsNullOrEmpty(name) || !HasName(cldb, cldbType))
            {
                name = "Unnamed asset";
            }

            if (typeId is 0x01 or 0x72)
            {
                name = type != name ? $"{type} {name}" : type;
            }

            Workspace.LoadedAssets.Add(item);
            var assetId = new AssetID(fileInst.path, item.PathID);

            Workspace.LoadedContainers[assetId] = Workspace.MakeAssetContainer(item);
            var data = item.ToArray();

            data[0] = name;
            assetList.Items.Add(new ListViewItem(data));
        }