Ejemplo n.º 1
0
        //no classdatabase but may not work
        public static string GetAssetNameFastNaive(AssetsFile file, AssetFileInfoEx info)
        {
            AssetsFileReader reader = file.reader;

            if (AssetsFileExtra.HasName(info.curFileType))
            {
                reader.Position = info.absoluteFilePos;
                return(reader.ReadCountStringInt32());
            }
            else if (info.curFileType == 0x01)
            {
                reader.Position = info.absoluteFilePos;
                int size          = reader.ReadInt32();
                int componentSize = file.header.format > 0x10 ? 0xC : 0x10;
                reader.Position += size * componentSize;
                reader.Position += 4;
                return(reader.ReadCountStringInt32());
            }
            else if (info.curFileType == 0x72)
            {
                reader.Position  = info.absoluteFilePos;
                reader.Position += 28;
                string name = reader.ReadCountStringInt32();
                if (name != "")
                {
                    return(name);
                }
            }
            return(string.Empty);
        }
Ejemplo n.º 2
0
        public static string GetAssetNameFast(AssetFileInfoEx afi, ClassDatabaseFile cldb, ClassDatabaseType type, AssetsFileInstance inst)
        {
            AssetsFileReader reader = inst.file.reader;

            if (type.fields.Count < 2)
            {
                return(type.name.GetString(cldb));
            }
            else if (type.fields[1].fieldName.GetString(cldb) == "m_Name")
            {
                reader.Position = afi.absoluteFilePos;
                return(reader.ReadCountStringInt32());
            }
            else if (type.name.GetString(cldb) == "GameObject")
            {
                reader.Position = afi.absoluteFilePos;
                int size = reader.ReadInt32();
                reader.Position += size * 12;
                reader.Position += 4;
                return(reader.ReadCountStringInt32());
            }
            else if (type.name.GetString(cldb) == "MonoBehaviour")
            {
                reader.Position  = afi.absoluteFilePos;
                reader.Position += 28;
                string name = reader.ReadCountStringInt32();
                if (name != "")
                {
                    return(name);
                }
            }
            return(type.name.GetString(cldb));
        }
Ejemplo n.º 3
0
 private string GetAssetNameFast(AssetFileInfoEx afi, ClassDatabaseFile cldb, ClassDatabaseType type, AssetsFileReader reader)
 {
     if (type.fields.Count <= 1)
     {
         return(type.name.GetString(cldb));
     }
     if (type.fields[1].fieldName.GetString(cldb) == "m_Name")
     {
         reader.Position = afi.absoluteFilePos;
         return(reader.ReadCountStringInt32());
     }
     else if (type.name.GetString(cldb) == "GameObject")
     {
         reader.Position = afi.absoluteFilePos;
         int size = reader.ReadInt32();
         reader.Position += (ulong)(size * 12);
         reader.Position += 4;
         return(reader.ReadCountStringInt32());
     }
     else if (type.name.GetString(cldb) == "MonoBehaviour")
     {
         reader.Position  = afi.absoluteFilePos;
         reader.Position += 28;
         string name = reader.ReadCountStringInt32();
         if (name != "")
         {
             return(name);
         }
     }
     return(type.name.GetString(cldb));
 }
Ejemplo n.º 4
0
        public static string GetAssetNameFast(AssetsFile file, ClassDatabaseFile cldb, AssetFileInfoEx info)
        {
            ClassDatabaseType type = FindAssetClassByID(cldb, info.curFileType);

            AssetsFileReader reader = file.reader;

            if (type.fields.Count == 0)
            {
                return(type.name.GetString(cldb));
            }
            if (type.fields[1].fieldName.GetString(cldb) == "m_Name")
            {
                reader.Position = info.absoluteFilePos;
                return(reader.ReadCountStringInt32());
            }
            else if (type.name.GetString(cldb) == "GameObject")
            {
                reader.Position = info.absoluteFilePos;
                int size = reader.ReadInt32();
                reader.Position += size * 12;
                reader.Position += 4;
                return(reader.ReadCountStringInt32());
            }
            else if (type.name.GetString(cldb) == "MonoBehaviour")
            {
                reader.Position  = info.absoluteFilePos;
                reader.Position += 28;
                string name = reader.ReadCountStringInt32();
                if (name != "")
                {
                    return(name);
                }
            }
            return(type.name.GetString(cldb));
        }
Ejemplo n.º 5
0
 private string ReadFSMName(AssetFileInfoEx afi, AssetsFileReader reader)
 {
     reader.Position  = afi.absoluteFilePos;
     reader.Position += 28;
     reader.ReadCountStringInt32();
     reader.Position += 16;
     return(reader.ReadCountStringInt32());
 }
        private void BackgroundWork(object sender, DoWorkEventArgs e)
        {
            List <AssetID> assetIds = new List <AssetID>();

            foreach (string fileName in fileNames)
            {
                AssetsFileInstance inst = am.LoadAssetsFile(fileName, true);
                inst.table.GenerateQuickLookupTree();
                am.LoadClassDatabaseFromPackage(inst.file.typeTree.unityVersion);
                foreach (AssetFileInfoEx inf in inst.table.GetAssetsOfType(0x73))
                {
                    AssetsFileReader fr = new AssetsFileReader(inst.file.readerPar);
                    fr.bigEndian = false;
                    fr.Position  = inf.absoluteFilePos;
                    fr.ReadCountStringInt32(); fr.Align();
                    fr.Position += 20;
                    string     m_ClassName    = fr.ReadCountStringInt32(); fr.Align();
                    string     m_Namespace    = fr.ReadCountStringInt32(); fr.Align();
                    string     m_AssemblyName = fr.ReadCountStringInt32(); fr.Align();
                    AssetID    assetId        = new AssetID(Path.GetFileName(fileName), inf.index);
                    ScriptInfo scriptInfo     = new ScriptInfo(m_AssemblyName, m_Namespace, m_ClassName);
                    assetIds.Add(assetId);
                    monoScriptToInfo.Add(assetId, scriptInfo);
                    monoScriptRefs.Add(assetId, new List <AssetID>());
                    bw.ReportProgress(0, assetId);
                }
            }
            foreach (string fileName in fileNames)
            {
                //don't worry, this doesn't load them twice
                AssetsFileInstance inst = am.LoadAssetsFile(fileName, true);
                foreach (AssetFileInfoEx inf in inst.table.GetAssetsOfType(0x72))
                {
                    AssetsFileReader fr = new AssetsFileReader(inst.file.readerPar);
                    fr.bigEndian = false;
                    fr.Position  = inf.absoluteFilePos;
                    fr.Position += 16;
                    int    m_FileID    = fr.ReadInt32();
                    long   m_PathID    = fr.ReadInt64();
                    string refFileName = fileName;
                    if (m_FileID != 0)
                    {
                        refFileName = inst.file.dependencies.dependencies[m_FileID - 1].assetPath;
                    }

                    AssetID scriptId = new AssetID(Path.GetFileName(refFileName), m_PathID);
                    AssetID selfId   = new AssetID(Path.GetFileName(fileName), inf.index);
                    if (monoScriptRefs.ContainsKey(scriptId))
                    {
                        monoScriptRefs[scriptId].Add(selfId);
                    }
                }
            }
            bw.ReportProgress(0);
        }
Ejemplo n.º 7
0
        private static string GetAssetNameFast(int fileId, long pathId, AssetsFileInstance inst)
        {
            if (pathId == 0)
            {
                return("");
            }

            AssetsFile      file  = null;
            AssetsFileTable table = null;

            if (fileId == 0)
            {
                file  = inst.file;
                table = inst.table;
            }
            else
            {
                AssetsFileInstance dep = inst.dependencies[fileId - 1];
                file  = dep.file;
                table = dep.table;
            }

            AssetFileInfoEx  inf    = table.getAssetInfo((ulong)pathId);
            AssetsFileReader reader = file.reader;

            if (allowed.Contains(inf.curFileType))
            {
                reader.Position = inf.absoluteFilePos;
                return(reader.ReadCountStringInt32());
            }
            if (inf.curFileType == 0x1)
            {
                reader.Position = inf.absoluteFilePos;
                int size = reader.ReadInt32();
                reader.Position += (ulong)(size * 12);
                reader.Position += 4;
                return(reader.ReadCountStringInt32());
            }
            else if (inf.curFileType == 0x72)
            {
                reader.Position  = inf.absoluteFilePos;
                reader.Position += 28;
                string name = reader.ReadCountStringInt32();
                if (name != "")
                {
                    return(name);
                }
            }
            return("");
        }
Ejemplo n.º 8
0
        public override void Parse(AssetIdentifier identifier, AssetsFileReader reader, ResourceAssets resourceAssets, Dictionary <int, string> relativeFileIdToPath)
        {
            MonobehaviourAsset monobehaviour = new MonobehaviourAsset();
            int fileId = reader.ReadInt32();

            monobehaviour.GameObjectIdentifier = new AssetIdentifier(relativeFileIdToPath[fileId], reader.ReadInt64());
            monobehaviour.Enabled = reader.ReadBoolean();
            reader.Align();
            monobehaviour.MonoscriptIdentifier = new AssetIdentifier(relativeFileIdToPath[reader.ReadInt32()], reader.ReadInt64());
            monobehaviour.Name = reader.ReadCountStringInt32();

            // Hack - If we have not yet loaded monoscripts then we are currently processing unit monobehaviours
            // that we do not care about.  Monoscripts should be fully loaded before we actually parse anything
            // we do care about in resource.assets.  If this becomes a problem later, we can do two passes and
            // load monobeahviours in the second pass.
            if (!MonoscriptAssetParser.MonoscriptsByAssetId.ContainsKey(monobehaviour.MonoscriptIdentifier))
            {
                return;
            }

            MonoscriptAsset monoscript = MonoscriptAssetParser.MonoscriptsByAssetId[monobehaviour.MonoscriptIdentifier];

            monobehaviour.MonoscriptName = monoscript.Name;


            if (monobehaviourParsersByMonoscriptName.TryGetValue(monoscript.Name, out MonobehaviourParser monoResourceParser))
            {
                monoResourceParser.Parse(identifier, monobehaviour.GameObjectIdentifier, reader, resourceAssets, relativeFileIdToPath);
            }

            MonobehavioursByAssetId.Add(identifier, monobehaviour);
        }
Ejemplo n.º 9
0
        public override void Parse(AssetIdentifier identifier, AssetsFileReader reader, ResourceAssets resourceAssets, Dictionary <int, string> relativeFileIdToPath)
        {
            string assetName = reader.ReadCountStringInt32();

            if (assetName == "RandomStart")
            {
                reader.Position += 9;
                int width     = reader.ReadInt32();
                int height    = reader.ReadInt32();
                int imageSize = reader.ReadInt32();
                reader.Position += 52;

                byte[] data        = reader.ReadBytes(imageSize);
                byte[] decodedData = AssetsTools.NET.Extra.DXTDecoders.ReadDXT1(data, width, height);
                using (MemoryStream stream = new MemoryStream(decodedData))
                {
                    Bitmap bmp = new Bitmap(width, height, PixelFormat.Format32bppArgb);

                    Rectangle  dimension = new Rectangle(0, 0, bmp.Width, bmp.Height);
                    BitmapData picData   = bmp.LockBits(dimension, ImageLockMode.ReadWrite, bmp.PixelFormat);
                    picData.Stride = width * 4;
                    IntPtr pixelStartAddress = picData.Scan0;

                    Marshal.Copy(decodedData, 0, pixelStartAddress, decodedData.Length);

                    bmp.UnlockBits(picData);

                    resourceAssets.NitroxRandom = new RandomStartGenerator(bmp);
                }
            }
        }
Ejemplo n.º 10
0
        private static byte[] FixTexture2DFast(AssetsFileInstance inst, AssetFileInfoEx inf)
        {
            AssetsFileReader r = inst.file.reader;

            r.Position  = inf.absoluteFilePos;
            r.Position += (ulong)r.ReadInt32() + 4;
            r.Align();
            r.Position += 0x48;
            r.Position += (ulong)r.ReadInt32() + 4;
            r.Align();
            r.Position += 0x8;
            ulong  filePathPos        = r.Position;
            int    assetLengthMinusFP = (int)(filePathPos - inf.absoluteFilePos);
            string filePath           = r.ReadCountStringInt32();
            string directory          = Path.GetDirectoryName(inst.path);
            string fixedPath          = Path.Combine(directory, filePath);

            byte[] newData = new byte[assetLengthMinusFP + 4 + fixedPath.Length];
            r.Position = inf.absoluteFilePos;
            //imo easier to write it with binary writer than manually copy the bytes
            using (MemoryStream ms = new MemoryStream())
                using (AssetsFileWriter w = new AssetsFileWriter(ms))
                {
                    w.bigEndian = false;
                    w.Write(r.ReadBytes(assetLengthMinusFP));
                    w.WriteCountStringInt32(fixedPath);
                    var ret = ms.ToArray();
                    if (ret == null)
                    {
                        return(null);
                    }
                    return(ret);
                }
        }
        public override void Parse(AssetIdentifier identifier, AssetIdentifier gameObjectIdentifier, AssetsFileReader reader, ResourceAssets resourceAssets, Dictionary <int, string> relativeFileIdToPath)
        {
            string classId = reader.ReadCountStringInt32();

            ClassIdByGameObjectId.Add(gameObjectIdentifier, classId);
            GameObjectIdByClassId.Add(classId, gameObjectIdentifier);
        }
Ejemplo n.º 12
0
        public override void Parse(AssetIdentifier identifier, AssetsFileReader reader, ResourceAssets resourceAssets)
        {
            MonobehaviourAsset monobehaviour = new MonobehaviourAsset();

            monobehaviour.GameObjectIdentifier = new AssetIdentifier((uint)reader.ReadInt32(), (ulong)reader.ReadInt64());
            monobehaviour.Enabled = reader.ReadInt32(); // unknown but assume this is what it is
            monobehaviour.MonoscriptIdentifier = new AssetIdentifier((uint)reader.ReadInt32(), (ulong)reader.ReadInt64());
            monobehaviour.Name = reader.ReadCountStringInt32();

            // Hack - If we have not yet loaded monoscripts then we are currently processing unit monobehaviours
            // that we do not care about.  Monoscripts should be fully loaded before we actually parse anything
            // we do care about in resource.assets.  If this becomes a problem later, we can do two passes and
            // load monobeahviours in the second pass.
            if (!MonoscriptAssetParser.MonoscriptsByAssetId.ContainsKey(monobehaviour.MonoscriptIdentifier))
            {
                return;
            }

            MonoscriptAsset monoscript = MonoscriptAssetParser.MonoscriptsByAssetId[monobehaviour.MonoscriptIdentifier];

            monobehaviour.MonoscriptName = monoscript.Name;

            MonobehaviourParser monoResourceParser;

            if (monobehaviourParsersByMonoscriptName.TryGetValue(monoscript.Name, out monoResourceParser))
            {
                monoResourceParser.Parse(identifier, monobehaviour.GameObjectIdentifier, reader, resourceAssets);
            }

            MonobehavioursByAssetId.Add(identifier, monobehaviour);
        }
Ejemplo n.º 13
0
        public override void Parse(AssetIdentifier identifier, AssetIdentifier gameObjectIdentifier, AssetsFileReader reader, ResourceAssets resourceAssets)
        {
            string classId = reader.ReadCountStringInt32();

            ClassIdByGameObjectId.Add(gameObjectIdentifier, classId);
            GameObjectIdByClassId.Add(classId, gameObjectIdentifier);
        }
Ejemplo n.º 14
0
        public override void Parse(AssetIdentifier identifier, AssetsFileReader reader, ResourceAssets resourceAssets, Dictionary <int, string> relativeFileIdToPath)
        {
            MonoscriptAsset monoscriptAsset = new MonoscriptAsset();

            monoscriptAsset.Name = reader.ReadCountStringInt32();

            MonoscriptsByAssetId.Add(identifier, monoscriptAsset);
        }
Ejemplo n.º 15
0
        public override void Parse(AssetIdentifier identifier, AssetsFileReader reader, ResourceAssets resourceAssets)
        {
            MonoscriptAsset monoscriptAsset = new MonoscriptAsset();

            monoscriptAsset.Name = reader.ReadCountStringInt32();

            MonoscriptsByAssetId.Add(identifier, monoscriptAsset);
        }
Ejemplo n.º 16
0
        public override void Parse(AssetIdentifier identifier, AssetIdentifier gameObjectIdentifier, AssetsFileReader reader, ResourceAssets resourceAssets, Dictionary <int, string> relativeFileIdToPath)
        {
            PrefabPlaceholderAsset prefabPlaceholderAsset = new PrefabPlaceholderAsset();

            prefabPlaceholderAsset.Identifier           = identifier;
            prefabPlaceholderAsset.GameObjectIdentifier = gameObjectIdentifier;
            prefabPlaceholderAsset.ClassId = reader.ReadCountStringInt32();

            PrefabPlaceholderIdToPlaceholderAsset.Add(identifier, prefabPlaceholderAsset);
        }
Ejemplo n.º 17
0
        public override void Parse(AssetIdentifier identifier, AssetsFileReader reader, ResourceAssets resourceAssets, Dictionary <int, string> relativeFileIdToPath)
        {
            string assetName = reader.ReadCountStringInt32();


            if (textParsersByAssetName.TryGetValue(assetName, out AssetParser textResourceParser))
            {
                textResourceParser.Parse(identifier, reader, resourceAssets, relativeFileIdToPath);
            }
        }
Ejemplo n.º 18
0
        public override void Parse(AssetIdentifier identifier, AssetsFileReader reader, ResourceAssets resourceAssets)
        {
            string assetName = reader.ReadCountStringInt32();

            AssetParser textResourceParser;

            if (textParsersByAssetName.TryGetValue(assetName, out textResourceParser))
            {
                textResourceParser.Parse(identifier, reader, resourceAssets);
            }
        }
Ejemplo n.º 19
0
        public static string GetAssetNameFast(AssetFileInfoEx afi, ClassDatabaseFile cldb, ClassDatabaseType type, AssetsFileInstance inst)
        {
            AssetsFileReader reader = inst.file.reader;

            if (type.fields.Count == 0)
            {
                return(type.name.GetString(cldb));
            }
            else if (type.fields.Count == 1)
            {
                // the dreamers lay sleeping to protect the vessel
                return(type.name.GetString(cldb));
            }
            else if (type.fields[1].fieldName.GetString(cldb) == "m_Name")
            {
                reader.Position = afi.absoluteFilePos;
                return(reader.ReadCountStringInt32());
            }
            else if (type.name.GetString(cldb) == "GameObject")
            {
                reader.Position = afi.absoluteFilePos;
                int size = reader.ReadInt32();
                reader.Position += (ulong)size * 12;
                reader.Position += 4UL;
                return(reader.ReadCountStringInt32());
            }
            else if (type.name.GetString(cldb) == "MonoBehaviour")
            {
                reader.Position  = afi.absoluteFilePos;
                reader.Position += 28UL;
                string name = reader.ReadCountStringInt32();
                if (name != "")
                {
                    return(name);
                }
            }
            return(type.name.GetString(cldb));
        }
Ejemplo n.º 20
0
        private string GetAssetNameFastModded(AssetsFile file, ClassDatabaseFile cldb, AssetFileInfoEx info)
        {
            ClassDatabaseType type = AssetHelper.FindAssetClassByID(cldb, info.curFileType);

            AssetsFileReader reader = file.reader;

            if (type.fields.Count == 0)
            {
                return(type.name.GetString(cldb));
            }
            if (type.fields.Count > 1 && type.fields[1].fieldName.GetString(cldb) == "m_Name")
            {
                reader.Position = info.absoluteFilePos;
                return(reader.ReadCountStringInt32());
            }
            else if (type.name.GetString(cldb) == "GameObject")
            {
                reader.Position = info.absoluteFilePos;
                int size          = reader.ReadInt32();
                int componentSize = file.header.format > 0x10 ? 0xC : 0x10;
                reader.Position += size * componentSize;
                reader.Position += 4;
                return(reader.ReadCountStringInt32());
            }
            else if (type.name.GetString(cldb) == "MonoBehaviour")
            {
                reader.Position  = info.absoluteFilePos;
                reader.Position += 28;
                string name = reader.ReadCountStringInt32();
                if (name != "")
                {
                    return(name);
                }
            }
            return($"pathId_{info.index}");
        }
Ejemplo n.º 21
0
        public override void Parse(AssetIdentifier identifier, AssetIdentifier gameObjectIdentifier, AssetsFileReader reader, ResourceAssets resourceAssets, Dictionary <int, string> relativeFileIdToPath)
        {
            reader.Align();
            uint            size = reader.ReadUInt32();
            WorldEntityInfo wei;

            for (int i = 0; i < size; i++)
            {
                wei           = new WorldEntityInfo();
                wei.classId   = reader.ReadCountStringInt32();
                wei.techType  = (TechType)reader.ReadInt32();
                wei.slotType  = (EntitySlot.Type)reader.ReadInt32();
                wei.prefabZUp = reader.ReadBoolean();

                reader.Align();

                wei.cellLevel  = (LargeWorldEntity.CellLevel)reader.ReadInt32();
                wei.localScale = new UnityEngine.Vector3(reader.ReadSingle(), reader.ReadSingle(), reader.ReadSingle());
                resourceAssets.WorldEntitiesByClassId.Add(wei.classId, wei);
            }
        }
Ejemplo n.º 22
0
        //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;
        }
 public override void Parse(AssetIdentifier identifier, AssetsFileReader reader, ResourceAssets resourceAssets, Dictionary <int, string> relativeFileIdToPath)
 {
     reader.Align();
     resourceAssets.LootDistributionsJson = reader.ReadCountStringInt32().Replace("\\n", "");
 }
Ejemplo n.º 24
0
        public AssetTypeValueField ReadType(AssetsFileReader reader, ulong filePos, AssetTypeValueField valueField, bool bigEndian)
        {
            if (valueField.templateField.isArray)
            {
                if (valueField.templateField.childrenCount == 2)
                {
                    EnumValueTypes sizeType = valueField.templateField.children[0].valueType;
                    if (sizeType == EnumValueTypes.ValueType_Int32 ||
                        sizeType == EnumValueTypes.ValueType_UInt32)
                    {
                        valueField.childrenCount = reader.ReadUInt32();
                        valueField.pChildren     = new AssetTypeValueField[valueField.childrenCount];
                        for (int i = 0; i < valueField.childrenCount; i++)
                        {
                            valueField.pChildren[i] = new AssetTypeValueField();
                            valueField.pChildren[i].templateField = valueField.templateField.children[1];
                            valueField.pChildren[i] = ReadType(reader, reader.Position, valueField.pChildren[i], bigEndian);
                        }
                        if (valueField.templateField.align)
                        {
                            reader.Align();
                        }
                        AssetTypeArray ata = new AssetTypeArray();
                        ata.size         = valueField.childrenCount;
                        valueField.value = new AssetTypeValue(EnumValueTypes.ValueType_Array, 0);
                        valueField.value.Set(ata);
                    }
                    else
                    {
                        Debug.WriteLine("Invalid array value type! Found an unexpected " + sizeType.ToString() + " type instead!");
                    }
                }
                else
                {
                    Debug.WriteLine("Invalid array!");
                }
            }
            else
            {
                EnumValueTypes type = valueField.templateField.valueType;
                if (type != 0)
                {
                    valueField.value = new AssetTypeValue(type, 0);
                }
                if (type == EnumValueTypes.ValueType_String)
                {
                    valueField.value.Set(reader.ReadCountStringInt32());
                    reader.Align();
                }
                else
                {
                    valueField.childrenCount = valueField.templateField.childrenCount;
                    if (valueField.childrenCount == 0)
                    {
                        valueField.pChildren = new AssetTypeValueField[0];
                        switch (valueField.templateField.valueType)
                        {
                        case EnumValueTypes.ValueType_Int8:
                            valueField.value.Set(reader.ReadSByte());
                            if (valueField.templateField.align)
                            {
                                reader.Align();
                            }
                            break;

                        case EnumValueTypes.ValueType_UInt8:
                        case EnumValueTypes.ValueType_Bool:
                            valueField.value.Set(reader.ReadByte());
                            if (valueField.templateField.align)
                            {
                                reader.Align();
                            }
                            break;

                        case EnumValueTypes.ValueType_Int16:
                            valueField.value.Set(reader.ReadInt16());
                            if (valueField.templateField.align)
                            {
                                reader.Align();
                            }
                            break;

                        case EnumValueTypes.ValueType_UInt16:
                            valueField.value.Set(reader.ReadUInt16());
                            if (valueField.templateField.align)
                            {
                                reader.Align();
                            }
                            break;

                        case EnumValueTypes.ValueType_Int32:
                            valueField.value.Set(reader.ReadInt32());
                            break;

                        case EnumValueTypes.ValueType_UInt32:
                            valueField.value.Set(reader.ReadUInt32());
                            break;

                        case EnumValueTypes.ValueType_Int64:
                            valueField.value.Set(reader.ReadInt64());
                            break;

                        case EnumValueTypes.ValueType_UInt64:
                            valueField.value.Set(reader.ReadUInt64());
                            break;

                        case EnumValueTypes.ValueType_Float:
                            valueField.value.Set(reader.ReadSingle());
                            break;

                        case EnumValueTypes.ValueType_Double:
                            valueField.value.Set(reader.ReadDouble());
                            break;
                        }
                    }
                    else
                    {
                        valueField.pChildren = new AssetTypeValueField[valueField.childrenCount];
                        for (int i = 0; i < valueField.childrenCount; i++)
                        {
                            valueField.pChildren[i] = new AssetTypeValueField();
                            valueField.pChildren[i].templateField = valueField.templateField.children[i];
                            valueField.pChildren[i] = ReadType(reader, reader.Position, valueField.pChildren[i], bigEndian);
                        }
                    }
                }
            }
            return(valueField);
        }
Ejemplo n.º 25
0
 public override void Parse(AssetIdentifier identifier, AssetsFileReader reader, ResourceAssets resourceAssets)
 {
     reader.Align();
     resourceAssets.LootDistributionsJson = reader.ReadCountStringInt32().Replace("\\n", "");
 }
Ejemplo n.º 26
0
        public static string GetAssetNameFast(AssetsFile file, ClassDatabaseFile cldb, AssetFileInfoEx info)
        {
            ClassDatabaseType type   = FindAssetClassByID(cldb, info.curFileType);
            AssetsFileReader  reader = file.reader;

            if (file.typeTree.hasTypeTree)
            {
                Type_0D ttType     = file.typeTree.unity5Types[info.curFileTypeOrIndex];
                string  ttTypeName = ttType.typeFieldsEx[0].GetTypeString(ttType.stringTable);
                if (ttType.typeFieldsEx.Length == 0)
                {
                    return(type.name.GetString(cldb));                                 //fallback to cldb
                }
                if (ttType.typeFieldsEx.Length > 1 && ttType.typeFieldsEx[1].GetNameString(ttType.stringTable) == "m_Name")
                {
                    reader.Position = info.absoluteFilePos;
                    return(reader.ReadCountStringInt32());
                }
                //todo, use the typetree since we have it already, there could be extra fields
                else if (ttTypeName == "GameObject")
                {
                    reader.Position = info.absoluteFilePos;
                    int size          = reader.ReadInt32();
                    int componentSize = file.header.format > 0x10 ? 0x0c : 0x10;
                    reader.Position += size * componentSize;
                    reader.Position += 0x04;
                    return(reader.ReadCountStringInt32());
                }
                else if (ttTypeName == "MonoBehaviour")
                {
                    reader.Position  = info.absoluteFilePos;
                    reader.Position += 0x1c;
                    string name = reader.ReadCountStringInt32();
                    if (name != "")
                    {
                        return(name);
                    }
                }
                return(ttTypeName);
            }

            string typeName = type.name.GetString(cldb);

            if (type.fields.Count == 0)
            {
                return(type.name.GetString(cldb));
            }
            if (type.fields.Count > 1 && type.fields[1].fieldName.GetString(cldb) == "m_Name")
            {
                reader.Position = info.absoluteFilePos;
                return(reader.ReadCountStringInt32());
            }
            else if (typeName == "GameObject")
            {
                reader.Position = info.absoluteFilePos;
                int size          = reader.ReadInt32();
                int componentSize = file.header.format > 0x10 ? 0x0c : 0x10;
                reader.Position += size * componentSize;
                reader.Position += 0x04;
                return(reader.ReadCountStringInt32());
            }
            else if (typeName == "MonoBehaviour")
            {
                reader.Position  = info.absoluteFilePos;
                reader.Position += 0x1c;
                string name = reader.ReadCountStringInt32();
                if (name != "")
                {
                    return(name);
                }
            }
            return(typeName);
        }