Beispiel #1
0
        // All dependencies are stored in the root resource.assets file.  The order they
        // are listed corresponds to the fileId order.  We store this value, so we can
        // fetch the fileId of different assets to build AssetIdentifiers.
        private static void CalculateDependencyFileIds(string basePath, string fileName)
        {
            string path = Path.Combine(basePath, fileName);

            using (FileStream resStream = new FileStream(path, FileMode.Open, FileAccess.Read))
                using (AssetsFileReader reader = new AssetsFileReader(resStream))
                {
                    AssetsFile      file = new AssetsFile(reader);
                    AssetsFileTable resourcesFileTable = new AssetsFileTable(file);

                    int fileId = 1;

                    foreach (AssetsFileDependency dependency in file.dependencies.dependencies)
                    {
                        fileIdByResourcePath.Add(dependency.assetPath, fileId);
                        fileId++;
                    }
                }
        }
Beispiel #2
0
        private static void ParseAssetManifest(string basePath, string fileName, int fileId, ResourceAssets resourceAssets)
        {
            fileName = fileName.Replace("resources/", "Resources/");

            if (parsedManifests.Contains(fileName))
            {
                return;
            }

            parsedManifests.Add(fileName);

            string path = Path.Combine(basePath, fileName);

            using (FileStream resStream = new FileStream(path, FileMode.Open, FileAccess.Read))
                using (AssetsFileReader reader = new AssetsFileReader(resStream))
                {
                    AssetsFile      file = new AssetsFile(reader);
                    AssetsFileTable resourcesFileTable = new AssetsFileTable(file);

                    foreach (AssetsFileDependency dependency in file.dependencies.dependencies)
                    {
                        int dependencyFileId = fileIdByResourcePath[dependency.assetPath];
                        ParseAssetManifest(basePath, dependency.assetPath, dependencyFileId, resourceAssets);
                    }

                    foreach (AssetFileInfoEx assetFileInfo in resourcesFileTable.assetFileInfo)
                    {
                        reader.Position = assetFileInfo.absoluteFilePos;

                        AssetIdentifier identifier = new AssetIdentifier(fileId, assetFileInfo.index);

                        AssetParser assetParser;

                        if (assetParsersByClassId.TryGetValue(assetFileInfo.curFileType, out assetParser))
                        {
                            assetParser.Parse(identifier, reader, resourceAssets);
                        }

                        assetIdentifierToClassId.Add(identifier, assetFileInfo.curFileType);
                    }
                }
        }
Beispiel #3
0
        public uint   _fmt;      //not stored here in the .assets file, the variable is just to remember the .assets file version

        public ulong Read(ulong absFilePos, AssetsFileReader reader, uint version, bool bigEndian)
        {
            unityVersion  = reader.ReadNullTerminated();
            this.version  = reader.ReadUInt32();
            hasTypeTree   = reader.ReadBoolean();
            fieldCount    = reader.ReadUInt32();
            pTypes_Unity5 = new Type_0D[fieldCount];
            for (int i = 0; i < fieldCount; i++)
            {
                Type_0D type0d = new Type_0D();
                type0d.Read(hasTypeTree, reader.Position, reader, version, version, bigEndian);
                pTypes_Unity5[i] = type0d;
            }
            if (version < 0x0E)
            {
                dwUnknown = reader.ReadUInt24();
            }
            _fmt = version; //-todo: figure out what the heck this is for. if ver = -1 on write does it set it to default or something?
            return(reader.Position);
        }//Minimum AssetsFile format : 6
Beispiel #4
0
 public ulong Read(ulong absFilePos, AssetsFileReader reader, uint version, bool bigEndian)
 {
     unityVersion  = reader.ReadNullTerminated();
     this.version  = reader.ReadUInt32();
     hasTypeTree   = reader.ReadBoolean();
     fieldCount    = reader.ReadUInt32();
     pTypes_Unity5 = new Type_0D[fieldCount];
     for (int i = 0; i < fieldCount; i++)
     {
         Type_0D type0d = new Type_0D();
         type0d.Read(hasTypeTree, reader.Position, reader, version, version, bigEndian);
         pTypes_Unity5[i] = type0d;
     }
     if (version < 0x0E)
     {
         dwUnknown = reader.ReadUInt32();
     }
     _fmt = version;
     return(reader.Position);
 }
Beispiel #5
0
        public static List <byte[]> LoadAllAssetsDataFromBundle(AssetBundleFile bundle)
        {
            List <byte[]>    files  = new List <byte[]>();
            AssetsFileReader reader = bundle.reader;

            AssetBundleDirectoryInfo06[] dirInf = bundle.bundleInf6.dirInf;
            for (int i = 0; i < dirInf.Length; i++)
            {
                AssetBundleDirectoryInfo06 info = dirInf[i];
                if (bundle.IsAssetsFile(reader, info))
                {
                    files.Add(LoadAssetDataFromBundle(bundle, i));
                }
                else
                {
                    files.Add(null);
                }
            }
            return(files);
        }
Beispiel #6
0
 public AssetsFileTable(AssetsFile pFile, bool readNames = true)
 {
     this.pFile                 = pFile;
     reader                     = new AssetsFileReader(pFile.readerPar); //todo, look back and see why I made a new reader here
     readerPar                  = pFile.readerPar;
     reader.bigEndian           = pFile.header.endianness == 1 ? true : false;
     reader.BaseStream.Position = pFile.AssetTablePos;
     assetFileInfoCount         = pFile.AssetCount;
     pAssetFileInfo             = new AssetFileInfoEx[assetFileInfoCount];
     for (int i = 0; i < assetFileInfoCount; i++)
     {
         AssetFileInfoEx assetFileInfoSet = new AssetFileInfoEx();
         if (pFile.header.format >= 0x0E)
         {
             assetFileInfoSet.index = reader.ReadUInt64();
         }
         else
         {
             assetFileInfoSet.index = reader.ReadUInt32();
         }
         assetFileInfoSet.offs_curFile       = reader.ReadUInt32();
         assetFileInfoSet.curFileSize        = reader.ReadUInt32();
         assetFileInfoSet.curFileTypeOrIndex = reader.ReadUInt32();
         if (pFile.header.format < 0x10)
         {
             assetFileInfoSet.inheritedUnityClass = reader.ReadUInt16();
         }
         if (pFile.header.format <= 0x10)
         {
             assetFileInfoSet.scriptIndex = reader.ReadUInt16();
         }
         if (0x0F <= pFile.header.format && pFile.header.format <= 0x10)
         {
             assetFileInfoSet.unknown1 = reader.ReadByte();
             reader.ReadBytes(3);
         }
         assetFileInfoSet.absoluteFilePos = pFile.header.offs_firstFile + assetFileInfoSet.offs_curFile;
         assetFileInfoSet.curFileType     = (uint)pFile.typeTree.pTypes_Unity5[assetFileInfoSet.curFileTypeOrIndex].classId; //todo: fix this variable (it can be from a different variable (index))
         pAssetFileInfo[i] = assetFileInfoSet;
     }
 }
Beispiel #7
0
        public static DetectedFileType DetectFileType(string filePath)
        {
            string possibleBundleHeader;
            int    possibleFormat;
            string emptyVersion;

            using (FileStream fs = File.OpenRead(filePath))
                using (AssetsFileReader r = new AssetsFileReader(fs))
                {
                    if (fs.Length < 0x20)
                    {
                        return(DetectedFileType.Unknown);
                    }
                    possibleBundleHeader = r.ReadStringLength(7);
                    r.Position           = 0x08;
                    possibleFormat       = r.ReadInt32();
                    r.Position           = 0x14;

                    string possibleVersion = "";
                    char   curChar;
                    while (r.Position < r.BaseStream.Length && (curChar = (char)r.ReadByte()) != 0x00)
                    {
                        possibleVersion += curChar;
                        if (possibleVersion.Length < 0xFF)
                        {
                            break;
                        }
                    }
                    emptyVersion = Regex.Replace(possibleVersion, "[a-zA-Z0-9\\.]", "");
                }
            if (possibleBundleHeader == "UnityFS")
            {
                return(DetectedFileType.BundleFile);
            }
            else if (possibleFormat < 0xFF && emptyVersion == "")
            {
                return(DetectedFileType.AssetsFile);
            }
            return(DetectedFileType.Unknown);
        }
Beispiel #8
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;
        }
        public ulong Read(AssetsFileReader reader, ulong filePos, int version)
        {
            typeName = new ClassDatabaseFileString();
            typeName.Read(reader, reader.Position);
            fieldName = new ClassDatabaseFileString();
            fieldName.Read(reader, reader.Position);
            depth   = reader.ReadByte();
            isArray = reader.ReadByte();
            size    = reader.ReadUInt32();
            switch (version)
            {
            case 1:
                flags2 = reader.ReadUInt32();
                break;

            case 3:
                this.version = reader.ReadUInt16();
                flags2       = reader.ReadUInt32();
                break;
            }
            return(reader.Position);
        }
        public override void Parse(AssetIdentifier identifier, AssetsFileReader reader, ResourceAssets resourceAssets, Dictionary <int, string> relativeFileIdToPath)
        {
            GameObjectAsset gameObjectAsset = new GameObjectAsset();

            gameObjectAsset.Identifier = identifier;

            uint componentCount = reader.ReadUInt32();

            for (int i = 0; i < componentCount; i++)
            {
                AssetIdentifier component = new AssetIdentifier(relativeFileIdToPath[reader.ReadInt32()], reader.ReadInt64());
                gameObjectAsset.Components.Add(component);
            }

            reader.ReadUInt32(); // Layer (not used)

            int length = reader.ReadInt32();

            gameObjectAsset.Name = reader.ReadStringLength(length);

            GameObjectsByAssetId.Add(identifier, gameObjectAsset);
        }
Beispiel #11
0
        private static byte[] GetBundleData(string bunPath, int index)
        {
            AssetsFileReader r   = new AssetsFileReader(File.Open(bunPath, FileMode.Open, FileAccess.Read, FileShare.Read));
            AssetsBundleFile bun = new AssetsBundleFile();

            bun.Read(r, true);

            //if the bundle doesn't have this section return empty
            if (index >= bun.bundleInf6.dirInf.Length)
            {
                return(new byte[0]);
            }

            AssetsBundleDirectoryInfo06 dirInf = bun.bundleInf6.dirInf[index];
            int start  = (int)(bun.bundleHeader6.GetFileDataOffset() + dirInf.offset);
            int length = (int)dirInf.decompressedSize;

            byte[] data;
            r.BaseStream.Position = start;
            data = r.ReadBytes(length);
            return(data);
        }
Beispiel #12
0
 public ulong Read(bool hasTypeTree, ulong absFilePos, AssetsFileReader reader, uint version, uint typeVersion, bool bigEndian)
 {
     classId = reader.ReadInt32();
     if (version >= 0x10)
     {
         unknown16_1 = reader.ReadByte();
     }
     if (version >= 0x11)
     {
         scriptIndex = reader.ReadUInt16();
     }
     if ((version < 0x11 && classId < 0) || (version >= 0x11 && scriptIndex != 0xFFFF))
     {
         unknown1 = reader.ReadUInt32();
         unknown2 = reader.ReadUInt32();
         unknown3 = reader.ReadUInt32();
         unknown4 = reader.ReadUInt32();
     }
     unknown5 = reader.ReadUInt32();
     unknown6 = reader.ReadUInt32();
     unknown7 = reader.ReadUInt32();
     unknown8 = reader.ReadUInt32();
     if (hasTypeTree)
     {
         typeFieldsExCount = reader.ReadUInt32();
         stringTableLen    = reader.ReadUInt32();
         pTypeFieldsEx     = new TypeField_0D[typeFieldsExCount];
         for (int i = 0; i < typeFieldsExCount; i++)
         {
             TypeField_0D typefield0d = new TypeField_0D();
             typefield0d.Read(reader.Position, reader, bigEndian);
             pTypeFieldsEx[i] = typefield0d;
         }
         string rawStringTable = Encoding.UTF8.GetString(reader.ReadBytes((int)stringTableLen));
         pStringTable = rawStringTable.Split('\0');
         Array.Resize(ref pStringTable, pStringTable.Length - 1);
     }
     return(reader.Position);
 }
        public void Read(AssetsFileReader reader, int version)
        {
            typeName = new ClassDatabaseFileString();
            typeName.Read(reader);
            fieldName = new ClassDatabaseFileString();
            fieldName.Read(reader);
            depth   = reader.ReadByte();
            isArray = reader.ReadByte();
            size    = reader.ReadInt32();
            switch (version)
            {
            case 1:
                flags2 = reader.ReadUInt32();
                break;

            case 3:
            case 4:
                this.version = reader.ReadUInt16();
                flags2       = reader.ReadUInt32();
                break;
            }
        }
Beispiel #14
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));
        }
        private void ReadBundle(FileStream stream)
        {
            reader         = new AssetsFileReader(stream);
            bundle         = new AssetBundleFile();
            bundleFilename = stream.Name;
            bundle.Read(reader, true);
            reader.Position = 0;
            switch (bundle.bundleHeader6.flags & 0x3F)
            {
            case 0:
                compressionMethod.Text = "Compression Method: None";
                break;

            case 1:
                compressionMethod.Text = "Compression Method: LZMA";
                break;

            case 2:
            case 3:
                compressionMethod.Text = "Compression Method: LZ4";
                break;

            default:
                compressionMethod.Text = "Compression Method: Unknown";
                break;
            }
            if ((bundle.bundleHeader6.flags & 0x3F) == 0)
            {
                note.Text = "Bundle is not compressed. You can load it or compress it.";
                compressButton.Enabled = true;
                loadButton.Enabled     = true;
            }
            else
            {
                note.Text = "Bundle is compressed. You must decompress the bundle to load.";
                decompressButton.Enabled = true;
            }
        }
Beispiel #16
0
        private bool GetResSTexture(TextureFile texFile, AssetContainer cont)
        {
            TextureFile.StreamingInfo streamInfo = texFile.m_StreamData;
            if (streamInfo.path != null && streamInfo.path != "" && cont.FileInstance.parentBundle != null)
            {
                //some versions apparently don't use archive:/
                string searchPath = streamInfo.path;
                if (searchPath.StartsWith("archive:/"))
                {
                    searchPath = searchPath.Substring(9);
                }

                searchPath = Path.GetFileName(searchPath);

                AssetBundleFile bundle = cont.FileInstance.parentBundle.file;

                AssetsFileReader             reader = bundle.reader;
                AssetBundleDirectoryInfo06[] dirInf = bundle.bundleInf6.dirInf;
                for (int i = 0; i < dirInf.Length; i++)
                {
                    AssetBundleDirectoryInfo06 info = dirInf[i];
                    if (info.name == searchPath)
                    {
                        reader.Position             = bundle.bundleHeader6.GetFileDataOffset() + info.offset + streamInfo.offset;
                        texFile.pictureData         = reader.ReadBytes((int)streamInfo.size);
                        texFile.m_StreamData.offset = 0;
                        texFile.m_StreamData.size   = 0;
                        texFile.m_StreamData.path   = "";
                        return(true);
                    }
                }
                return(false);
            }
            else
            {
                return(true);
            }
        }
Beispiel #17
0
 ///void Free();
 public void Read(long filePos, AssetsFileReader reader)
 {
     reader.Position = filePos;
     checksumLow     = reader.ReadUInt64();
     checksumHigh    = reader.ReadUInt64();
     blockCount      = reader.ReadUInt32();
     blockInf        = new AssetBundleBlockInfo06[blockCount];
     for (int i = 0; i < blockCount; i++)
     {
         blockInf[i].decompressedSize = reader.ReadUInt32();
         blockInf[i].compressedSize   = reader.ReadUInt32();
         blockInf[i].flags            = reader.ReadUInt16();
     }
     directoryCount = reader.ReadUInt32();
     dirInf         = new AssetBundleDirectoryInfo06[directoryCount];
     for (int i = 0; i < directoryCount; i++)
     {
         dirInf[i].offset           = reader.ReadInt64();
         dirInf[i].decompressedSize = reader.ReadInt64();
         dirInf[i].flags            = reader.ReadUInt32();
         dirInf[i].name             = reader.ReadNullTerminated();
     }
 }
Beispiel #18
0
 ///void Free();
 public bool Read(ulong filePos, AssetsFileReader reader /*, AssetsFileVerifyLogger errorLogger = NULL*/)
 {
     reader.Position = filePos;
     checksumLow     = reader.ReadUInt64();
     checksumHigh    = reader.ReadUInt64();
     blockCount      = reader.ReadUInt32();
     blockInf        = new AssetsBundleBlockInfo06[blockCount];
     for (int i = 0; i < blockCount; i++)
     {
         blockInf[i].decompressedSize = reader.ReadUInt32();
         blockInf[i].compressedSize   = reader.ReadUInt32();
         blockInf[i].flags            = reader.ReadUInt16();
     }
     directoryCount = reader.ReadUInt32();
     dirInf         = new AssetsBundleDirectoryInfo06[directoryCount];
     for (int i = 0; i < directoryCount; i++)
     {
         dirInf[i].offset           = reader.ReadUInt64();
         dirInf[i].decompressedSize = reader.ReadUInt64();
         dirInf[i].flags            = reader.ReadUInt32();
         dirInf[i].name             = reader.ReadNullTerminated();
     }
     return(true);
 }
Beispiel #19
0
        public static string GetAssetNameFast(AssetsFile file, ClassDatabaseFile cldb, AssetFileInfoEx info)
        {
            ulong             pos  = info.absoluteFilePos;
            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 += (ulong)(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));
        }
Beispiel #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}");
        }
Beispiel #21
0
        public override void Parse(AssetIdentifier identifier, AssetsFileReader reader, ResourceAssets resourceAssets)
        {
            TransformAsset transformAsset = new TransformAsset();

            transformAsset.Identifier = identifier;

            reader.Position += 12;

            transformAsset.LocalRotation = new NitroxQuaternion(
                reader.ReadSingle(),  // Quaternion X
                reader.ReadSingle(),  // Quaternion Y
                reader.ReadSingle(),  // Quaternion Z
                reader.ReadSingle()); // Quaternion W

            transformAsset.LocalPosition = new NitroxVector3(
                reader.ReadSingle(),  // Position X
                reader.ReadSingle(),  // Position Y
                reader.ReadSingle()); // Position Z

            transformAsset.LocalScale = new NitroxVector3(
                reader.ReadSingle(),  // Scale X
                reader.ReadSingle(),  // Scale Y
                reader.ReadSingle()); // Scale Z

            int childrenCount = reader.ReadInt32();

            for (int i = 0; i < childrenCount; i++)
            {
                AssetIdentifier child = new AssetIdentifier(reader.ReadInt32(), reader.ReadInt64());
                ChildrenIdToParentId.Add(child, identifier);
            }

            transformAsset.ParentIdentifier = new AssetIdentifier(reader.ReadInt32(), reader.ReadInt64());

            TransformsByAssetId.Add(identifier, transformAsset);
        }
Beispiel #22
0
 public ulong Read(ulong absFilePos, AssetsFileReader reader)
 {
     mostSignificant  = reader.ReadInt64();
     leastSignificant = reader.ReadInt64();
     return(reader.Position);
 }
Beispiel #23
0
 public abstract void Parse(AssetIdentifier identifier, AssetsFileReader reader, ResourceAssets resourceAssets, Dictionary <int, string> relativeFileIdToPath);
Beispiel #24
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;
        }
Beispiel #25
0
 public AssetTypeInstance(AssetTypeTemplateField baseField, AssetsFileReader reader, long filePos)
     : this(new[] { baseField }, reader, filePos)
 {
 }
        private void AddAssetItem(AssetsFile af, AssetFileInfoEx afi, AssetsFileReader worker, uint fileId)
        {
            uint   classId;
            ushort monoId;

            if (af.header.format <= 0x10)
            {
                classId = afi.inheritedUnityClass;
                if (classId == 0x72)
                {
                    monoId = (ushort)(0xFFFFFFFF - afi.curFileTypeOrIndex);
                }
                else
                {
                    monoId = 0xFFFF;
                }
            }
            else
            {
                classId = (uint)af.typeTree.pTypes_Unity5[afi.curFileTypeOrIndex].classId;
                monoId  = af.typeTree.pTypes_Unity5[afi.curFileTypeOrIndex].scriptIndex;
            }
            ClassDatabaseType type = AssetHelper.FindAssetClassByID(assetsManager.initialClassFile, classId);

            if (type == null)
            {
                string   tfileID   = fileId.ToString();
                string   tpathID   = unchecked ((long)afi.index).ToString();
                string   tsize     = afi.curFileSize.ToString();
                string   tmodified = "";
                string[] titems    = new string[] { "Unknown", "??? Custom ???", tfileID, tpathID, tsize, tmodified };
                assetDetails.Add(
                    new AssetDetails(
                        "Unknown",
                        "??? Custom ???",
                        afi.index,
                        fileId,
                        classId,
                        afi.absoluteFilePos,
                        monoId
                        )
                    );
                System.Diagnostics.Debug.WriteLine("unknown id " + tpathID + " classid " + afi.curFileType);
                assetList.Items.Add(new ListViewItem(titems));
                return;
            }
            string assetName;

            if (classId == 0x72)
            {
                assetName = "";
            }
            else
            {
                assetName = GetAssetNameFast(afi, assetsManager.initialClassFile, type, worker);
            }

            string assetType = type.name.GetString(assetsManager.initialClassFile);
            string fileID    = fileId.ToString();
            string pathID    = unchecked ((long)afi.index).ToString();
            string size      = afi.curFileSize.ToString();
            string modified  = "";

            if (assetName.Trim() == "")
            {
                assetName = assetType;                         //todo, seems redundant now, check on this later
            }
            string[] items = new string[] { assetName, assetType, fileID, pathID, size, modified };

            assetDetails.Add(
                new AssetDetails(
                    assetName,
                    assetType,
                    afi.index,
                    fileId,
                    classId,
                    afi.absoluteFilePos,
                    monoId
                    )
                );
            assetList.Items.Add(new ListViewItem(items));
        }
        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);
        }
 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));
 }
        private void GetAssetList()
        {
            /*classStream = new FileStream(Path.Combine(Application.StartupPath, "cldb.dat"), FileMode.Open);
             *
             * af = new AssetsFile(new AssetsFileReader(assetStream));
             * AssetsFileTable aft = new AssetsFileTable(af);
             *
             * cldb = new ClassDatabaseFile();
             * cldb.Read(new AssetsFileReader(classStream));
             *
             * AssetsFileReader worker = new AssetsFileReader(assetStream);
             * worker.bigEndian = false;
             *
             * foreach (AssetFileInfoEx afi in aft.pAssetFileInfo)
             * {
             *  ClassDatabaseType type = AssetHelper.FindAssetClassByID(cldb, afi.curFileType);
             *  string assetName = GetAssetNameFast(afi, cldb, type, worker);
             *  string assetType = type.name.GetString(cldb);
             *  string fileID = file.ToString();
             *  string pathID = unchecked((long)afi.index).ToString();
             *  string size = afi.curFileSize.ToString();
             *  string modified = "";
             *  if (assetName.Trim() == "") assetName = assetType; //todo, seems redundant now, check on this later
             *  string[] items = new string[] { assetName, assetType, fileID, pathID, size, modified };
             *  assetDetails.Add(
             *      new AssetDetails(
             *          assetName,
             *          assetType,
             *          afi.index,
             *          (uint)file,
             *          afi.curFileType,
             *          afi.absoluteFilePos,
             *          af.typeTree.pTypes_Unity5[afi.curFileTypeOrIndex].scriptIndex
             *      )
             *  );
             *  assetList.Items.Add(new ListViewItem(items));
             * }
             * assetList.Items.RemoveAt(0); //remove blank item that's here for some reason*/
            assetsManager = new AssetsManagerLegacy();
            assetsManager.LoadAssets(assetStream, assetRootDir);
            assetsManager.LoadClassFile(Path.Combine(Application.StartupPath, "cldb.dat"));
            AssetsFileReader worker = new AssetsFileReader(assetStream);

            worker.bigEndian = false;
            foreach (AssetFileInfoEx afi in assetsManager.initialTable.pAssetFileInfo)
            {
                AddAssetItem(assetsManager.initialFile, afi, worker, 0);
            }
            assetList.Items.RemoveAt(0);
            uint id = 1;

            foreach (AssetsManagerLegacy.Dependency dep in assetsManager.dependencies)
            {
                worker           = new AssetsFileReader(dep.file);
                worker.bigEndian = false;
                foreach (AssetFileInfoEx afi in dep.aft.pAssetFileInfo)
                {
                    AddAssetItem(dep.af, afi, worker, id);
                }
                id++;
            }
        }
Beispiel #30
0
        public TextureViewer(AssetsFileInstance inst, AssetTypeValueField baseField)
        {
            InitializeComponent();

            loaded = false;
            TextureFile tf = TextureFile.ReadTextureFile(baseField);

            //bundle resS
            TextureFile.StreamingInfo streamInfo = tf.m_StreamData;
            if (streamInfo.path != null && inst.parentBundle != null)
            {
                string searchPath = streamInfo.path;

                if (streamInfo.path.StartsWith("archive:/"))
                {
                    searchPath = searchPath.Substring(9);
                }

                searchPath = Path.GetFileName(searchPath);

                AssetBundleFile bundle = inst.parentBundle.file;

                AssetsFileReader             reader = bundle.reader;
                AssetBundleDirectoryInfo06[] dirInf = bundle.bundleInf6.dirInf;
                bool foundFile = false;
                for (int i = 0; i < dirInf.Length; i++)
                {
                    AssetBundleDirectoryInfo06 info = dirInf[i];
                    if (info.name == searchPath)
                    {
                        reader.Position        = bundle.bundleHeader6.GetFileDataOffset() + info.offset + (long)streamInfo.offset;
                        tf.pictureData         = reader.ReadBytes((int)streamInfo.size);
                        tf.m_StreamData.offset = 0;
                        tf.m_StreamData.size   = 0;
                        tf.m_StreamData.path   = "";
                        foundFile = true;
                        break;
                    }
                }
                if (!foundFile)
                {
                    MessageBox.Show("resS was detected but no file was found in bundle");
                }
            }

            byte[] texDat = tf.GetTextureData(inst);
            if (texDat != null && texDat.Length > 0)
            {
                string fmtName = ((TextureFormat)tf.m_TextureFormat).ToString().Replace("_", " ");
                Text           = $"Texture Viewer [{fmtName}]";
                loadedFileName = tf.m_Name;

                image = new Bitmap(tf.m_Width, tf.m_Height, PixelFormat.Format32bppArgb);

                Rectangle  rect    = new Rectangle(0, 0, image.Width, image.Height);
                BitmapData picData = image.LockBits(rect, ImageLockMode.ReadWrite, image.PixelFormat);
                picData.Stride = tf.m_Width * 4;
                IntPtr startAddr = picData.Scan0;
                Marshal.Copy(texDat, 0, startAddr, texDat.Length);

                image.UnlockBits(picData);
                image.RotateFlip(RotateFlipType.RotateNoneFlipY);

                x         = 0;
                y         = 0;
                width     = image.Width;
                height    = image.Height;
                sc        = 1f;
                mouseDown = false;

                DoubleBuffered = true;

                Rectangle workingArea   = Screen.PrimaryScreen.WorkingArea;
                int       waWidth       = workingArea.Width;
                int       waHeight      = workingArea.Height;
                int       cliDiffWidth  = Size.Width - ClientSize.Width;
                int       cliDiffHeight = Size.Height - ClientSize.Height;
                ClientSize = new Size(Math.Min(width, waWidth - cliDiffWidth), Math.Min(height, waHeight - cliDiffHeight));

                loaded = true;
            }
        }