Exemple #1
0
 public ulong Read(AssetsFileReader reader, ulong filePos)
 {
     reader.bigEndian = false;
     header           = reader.ReadStringLength(4);
     if (header != "cldb")
     {
         return(reader.Position);
     }
     fileVersion = reader.ReadByte();
     if (fileVersion != 3)
     {
         return(reader.Position);
     }
     compressionType = reader.ReadByte();
     if (compressionType != 0)
     {
         return(reader.Position);
     }
     compressedSize    = reader.ReadUInt32();
     uncompressedSize  = reader.ReadUInt32();
     unityVersionCount = reader.ReadByte();
     pUnityVersions    = new string[unityVersionCount];
     for (int i = 0; i < unityVersionCount; i++)
     {
         pUnityVersions[i] = reader.ReadCountString();
     }
     stringTableLen = reader.ReadUInt32();
     stringTablePos = reader.ReadUInt32();
     return(reader.Position);
 }
Exemple #2
0
        public bool Read(AssetsFileReader reader, bool prefReplacersInMemory = false)
        {
            reader.bigEndian = false;

            magic = reader.ReadStringLength(4);
            if (magic != "EMIP")
            {
                return(false);
            }

            includesCldb = reader.ReadByte() != 0;

            modName        = reader.ReadCountStringInt16();
            modCreators    = reader.ReadCountStringInt16();
            modDescription = reader.ReadCountStringInt16();

            if (includesCldb)
            {
                addedTypes = new ClassDatabaseFile();
                addedTypes.Read(reader);
                //get past the string table since the reader goes back to the beginning
                reader.Position = addedTypes.header.stringTablePos + addedTypes.header.stringTableLen;
            }
            else
            {
                addedTypes = null;
            }

            int affectedFilesCount = reader.ReadInt32();

            affectedFiles = new List <InstallerPackageAssetsDesc>();
            for (int i = 0; i < affectedFilesCount; i++)
            {
                List <object> replacers         = new List <object>();
                InstallerPackageAssetsDesc desc = new InstallerPackageAssetsDesc()
                {
                    isBundle = reader.ReadByte() != 0,
                    path     = reader.ReadCountStringInt16()
                };
                int replacerCount = reader.ReadInt32();
                for (int j = 0; j < replacerCount; j++)
                {
                    object repObj = ParseReplacer(reader, prefReplacersInMemory);
                    if (repObj is AssetsReplacer repAsset)
                    {
                        replacers.Add(repAsset);
                    }
                    else if (repObj is BundleReplacer repBundle)
                    {
                        replacers.Add(repBundle);
                    }
                }
                desc.replacers = replacers;
                affectedFiles.Add(desc);
            }

            return(true);
        }
        private void addFileToolStripMenuItem_Click(object sender, EventArgs e)
        {
            OpenFileDialog ofd = new OpenFileDialog();

            ofd.DefaultExt = "";
            if (ofd.ShowDialog() == DialogResult.OK)
            {
                string possibleBundleHeader;
                int    possibleFormat;
                string emptyVersion;
                using (FileStream fs = File.OpenRead(ofd.FileName))
                    using (AssetsFileReader reader = new AssetsFileReader(fs))
                    {
                        if (fs.Length < 0x20)
                        {
                            MessageBox.Show("File too small. Are you sure this is a unity file?", "Assets View");
                            return;
                        }
                        possibleBundleHeader = reader.ReadStringLength(7);
                        reader.Position      = 0x08;
                        possibleFormat       = reader.ReadInt32();
                        reader.Position      = 0x14;

                        string possibleVersion = "";
                        char   curChar;
                        while (reader.Position < reader.BaseStream.Length && (curChar = (char)reader.ReadByte()) != 0x00)
                        {
                            possibleVersion += curChar;
                            if (possibleVersion.Length < 0xFF)
                            {
                                break;
                            }
                        }
                        emptyVersion = Regex.Replace(possibleVersion, "[a-zA-Z0-9\\.]", "");
                    }
                if (possibleBundleHeader == "UnityFS")
                {
                    LoadBundleFile(ofd.FileName);
                    IEManager.Init(helper, currentFile, ofd.FileName, true);
                }
                else if (possibleFormat < 0xFF && emptyVersion == "")
                {
                    LoadAssetsFile(ofd.FileName);
                    IEManager.Init(helper, currentFile, ofd.FileName, false);
                }
                else
                {
                    MessageBox.Show("Couldn't detect file type. Are you sure this is a unity file?", "Assets View");
                }
            }
        }
Exemple #4
0
        public static DetectedFileType DetectFileType(string filePath)
        {
            string possibleBundleHeader;
            int    possibleFormat;
            string emptyVersion;

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

                    if (possibleFormat >= 0x16)
                    {
                        reader.Position += 0x1c;
                    }

                    var  possibleVersion = "";
                    char curChar;
                    while (reader.Position < reader.BaseStream.Length && (curChar = (char)reader.ReadByte()) != 0x00)
                    {
                        possibleVersion += curChar;
                        if (possibleVersion.Length > 0xFF)
                        {
                            break;
                        }
                    }

                    emptyVersion = Regex.Replace(possibleVersion, "[a-zA-Z0-9\\.]", "");
                }

            if (possibleBundleHeader == "UnityFS")
            {
                return(DetectedFileType.BundleFile);
            }
            if (possibleFormat < 0xFF && emptyVersion == "")
            {
                return(DetectedFileType.AssetsFile);
            }
            return(DetectedFileType.Unknown);
        }
Exemple #5
0
        private void openToolStripMenuItem_Click(object sender, EventArgs e)
        {
            OpenFileDialog ofd = new OpenFileDialog();

            ofd.Filter = "Unity content (*.unity3d;*.assets)|*.unity3d;*.assets|Bundle file (*.unity3d)|*.unity3d|Assets file (*.assets)|*.assets|All types (*.*)|*.*";
            if (ofd.ShowDialog() == DialogResult.OK)
            {
                //try
                //{
                //todo, use using
                FileStream       stream     = new FileStream(ofd.FileName, FileMode.Open, FileAccess.ReadWrite);
                AssetsFileReader tempReader = new AssetsFileReader(stream);     //todo .assets sanity check
                if (tempReader.ReadStringLength(7) != "UnityFS")
                {
                    tempReader.Position = 0;
                    AssetViewer av = new AssetViewer(stream, Path.GetDirectoryName(stream.Name), Path.GetFileName(stream.Name));
                    av.ShowDialog();
                }
                else
                {
                    tempReader.Position = 0;
                    BundleLoader bl = new BundleLoader(stream);
                    bl.ShowDialog();
                    if (bl.loaded)
                    {
                        bundleContents.Enabled = true;
                        exportButton.Enabled   = true;
                        importButton.Enabled   = true;
                        infoButton.Enabled     = true;
                        foreach (AssetsBundleDirectoryInfo06 di in bl.bundle.bundleInf6.dirInf)
                        {
                            bundleContents.Items.Add(di.name);
                        }
                        bundleContents.SelectedIndex = 0;
                        bundlePath    = bl.bundleFilename;
                        fileName.Text = Path.GetFileName(bundlePath);
                        bundle        = bl.bundle;
                    }
                }
                tempReader = null;
                //} catch (Exception ex)
                //{
                //    MessageBox.Show("Unable to open the file!\n" + ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                //}
            }
        }
        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);
        }
Exemple #7
0
        public static string ReadCountStringInt16(this AssetsFileReader _this)
        {
            short length = _this.ReadInt16();

            return(_this.ReadStringLength(length));
        }