예제 #1
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));
                    }
                }
            }
        }
예제 #2
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);
        }
예제 #3
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);
        }
예제 #4
0
파일: Extensions.cs 프로젝트: nesrak1/UABEA
        //codeflow needs work but should be fine for now
        public static void GetUABENameFast(AssetsFile file, ClassDatabaseFile cldb, AssetsFileReader reader, long filePosition, uint classId, ushort monoId,
                                           out string assetName, out string typeName)
        {
            ClassDatabaseType type = AssetHelper.FindAssetClassByID(cldb, classId);

            if (file.typeTree.hasTypeTree)
            {
                Type_0D ttType;
                if (classId == 0x72)
                {
                    ttType = AssetHelper.FindTypeTreeTypeByScriptIndex(file.typeTree, monoId);
                }
                else
                {
                    ttType = AssetHelper.FindTypeTreeTypeByID(file.typeTree, classId);
                }

                if (ttType != null && ttType.typeFieldsEx.Length != 0)
                {
                    typeName = ttType.typeFieldsEx[0].GetTypeString(ttType.stringTable);
                    if (ttType.typeFieldsEx.Length > 1 && ttType.typeFieldsEx[1].GetNameString(ttType.stringTable) == "m_Name")
                    {
                        reader.Position = filePosition;
                        assetName       = reader.ReadCountStringInt32();
                        if (assetName == "")
                        {
                            assetName = "Unnamed asset";
                        }
                        return;
                    }
                    else if (typeName == "GameObject")
                    {
                        reader.Position = filePosition;
                        int size          = reader.ReadInt32();
                        int componentSize = file.header.format > 0x10 ? 0x0c : 0x10;
                        reader.Position += size * componentSize;
                        reader.Position += 0x04;
                        assetName        = reader.ReadCountStringInt32();
                        assetName        = $"GameObject {assetName}";
                        return;
                    }
                    else if (typeName == "MonoBehaviour")
                    {
                        reader.Position  = filePosition;
                        reader.Position += 0x1c;
                        assetName        = reader.ReadCountStringInt32();
                        if (assetName == "")
                        {
                            assetName = "Unnamed asset";
                        }
                        return;
                    }
                    assetName = "Unnamed asset";
                    return;
                }
            }

            if (type == null)
            {
                typeName  = $"0x{classId:X8}";
                assetName = "Unnamed asset";
                return;
            }

            typeName = type.name.GetString(cldb);

            if (type.fields.Count == 0)
            {
                assetName = "Unnamed asset";
                return;
            }

            if (type.fields.Count > 1 && type.fields[1].fieldName.GetString(cldb) == "m_Name")
            {
                reader.Position = filePosition;
                assetName       = reader.ReadCountStringInt32();
                if (assetName == "")
                {
                    assetName = "Unnamed asset";
                }
                return;
            }
            else if (typeName == "GameObject")
            {
                reader.Position = filePosition;
                int size          = reader.ReadInt32();
                int componentSize = file.header.format > 0x10 ? 0x0c : 0x10;
                reader.Position += size * componentSize;
                reader.Position += 0x04;
                assetName        = reader.ReadCountStringInt32();
                assetName        = $"GameObject {assetName}";
                return;
            }
            else if (typeName == "MonoBehaviour")
            {
                reader.Position  = filePosition;
                reader.Position += 0x1c;
                assetName        = reader.ReadCountStringInt32();
                if (assetName == "")
                {
                    assetName = "Unnamed asset";
                }
                return;
            }
            assetName = "Unnamed asset";
            return;
        }
예제 #5
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));
        }
예제 #6
0
파일: Extensions.cs 프로젝트: Igor55x/UAAE
        public static void GetUAAENameFast(AssetsWorkspace workspace, AssetItem item, out string type, out string name)
        {
            var file     = workspace.LoadedFiles[item.FileID].file;
            var cldb     = workspace.Am.classFile;
            var classId  = item.TypeID;
            var cldbType = AssetHelper.FindAssetClassByID(cldb, classId);
            var reader   = file.reader;

            if (file.typeTree.hasTypeTree)
            {
                var ttType = classId == 0x72 ?
                             AssetHelper.FindTypeTreeTypeByScriptIndex(file.typeTree, item.MonoID) :
                             AssetHelper.FindTypeTreeTypeByID(file.typeTree, classId);


                type = ttType.typeFieldsEx[0].GetTypeString(ttType.stringTable);
                switch (ttType.typeFieldsEx.Length)
                {
                case > 1 when ttType.typeFieldsEx[1].GetNameString(ttType.stringTable) == "m_Name":
                {
                    reader.Position = item.Position;
                    name            = reader.ReadCountStringInt32();
                    if (name != "")
                    {
                        return;
                    }
                    break;
                }

                default:
                    switch (type)
                    {
                    case "GameObject":
                    {
                        reader.Position = item.Position;
                        var size          = reader.ReadInt32();
                        var componentSize = file.header.format > 0x10 ? 0x0c : 0x10;
                        reader.Position += size * componentSize;
                        reader.Position += 0x04;
                        name             = reader.ReadCountStringInt32();
                        name             = name == "" ? "Unnamed asset" : $"{type} {name}";
                        return;
                    }

                    case "MonoBehaviour":
                        reader.Position  = item.Position;
                        reader.Position += 0x1c;
                        name             = reader.ReadCountStringInt32();
                        name             = name == "" ? "Unnamed asset" : $"{type} {name}";
                        return;
                    }
                    break;
                }
                name = "Unnamed asset";
                return;
            }

            if (cldbType == null)
            {
                type = $"0x{classId:X8}";
                name = "Unnamed asset";
                return;
            }

            type = cldbType.name.GetString(cldb);
            switch (cldbType.fields.Count)
            {
            case 0:
                name = "Unnamed asset";
                return;

            case > 1 when cldbType.fields[1].fieldName.GetString(cldb) == "m_Name":
            {
                reader.Position = item.Position;
                name            = reader.ReadCountStringInt32();
                if (name != "")
                {
                    return;
                }
                break;
            }

            default:
                switch (type)
                {
                case "GameObject":
                {
                    reader.Position = item.Position;
                    var size          = reader.ReadInt32();
                    var componentSize = file.header.format > 0x10 ? 0x0c : 0x10;
                    reader.Position += size * componentSize;
                    reader.Position += 0x04;
                    name             = reader.ReadCountStringInt32();
                    name             = name == "" ? "Unnamed asset" : $"{type} {name}";
                    return;
                }

                case "MonoBehaviour":
                {
                    reader.Position  = item.Position;
                    reader.Position += 0x1c;
                    name             = reader.ReadCountStringInt32();
                    name             = name == "" ? "Unnamed asset" : $"{type} {name}";
                    return;
                }
                }
                break;
            }
            name = "Unnamed asset";
        }