Ejemplo n.º 1
0
        /// <summary>
        /// 导入一整个目录的资源文件
        /// </summary>
        /// <param name="directoryPath"></param>
        /// <param name="targetFileName"></param>
        public static void ImportAssets(string directoryPath, string targetFileName)
        {
            if (Directory.Exists(directoryPath))
            {
                var files    = Directory.GetFiles(directoryPath);
                var replList = new List <AssetsReplacer>();

                //清空LOG文件
                logPath = Path.GetFileNameWithoutExtension(targetFileName) + ".txt";
                File.WriteAllText(logPath, "", Encoding.UTF8);

                for (int i = 0; i < files.Length; i++)
                {
                    //锁定范围(920,1000]
                    //if (i >= 920 && i <= 960) continue;
                    //if (i >= 1000 && i <= 1500) continue;
                    //if (i >= int.Parse(arr[0]) && i <= int.Parse(arr[1])) continue;

                    var    splitArr = Path.GetFileNameWithoutExtension(files[i]).Split(new string[] { "--" }, StringSplitOptions.None);
                    string name;

                    if (splitArr.Length == 2)
                    {
                        name = splitArr[1];
                    }
                    else
                    {
                        name = splitArr[3];
                    }

                    var temp = GenReplacerFromMemory(long.Parse(name), files[i], splitArr);
                    //var temp = GenReplacerFromMemoryByJson(long.Parse(name), files[i]);

                    if (temp != null)
                    {
                        replList.Add(temp);
                    }
                }

                var inst   = IEManager.AssetsFileInstance;
                var writer = new AssetsFileWriter(File.OpenWrite(targetFileName));
                //Bundle和普通的分离操作
                if (IEManager.IsBundle)
                {
                    AssetBundleFile          abFile   = inst.parentBundle.file;
                    var                      index    = FindAssetsIDInBundle(inst, abFile);
                    BundleReplacerFromAssets brfa     = new BundleReplacerFromAssets(Path.GetFileName(inst.path), null, inst.file, replList, index);
                    List <BundleReplacer>    bRepList = new List <BundleReplacer>();
                    bRepList.Add(brfa);
                    abFile.Write(writer, bRepList);
                }
                else
                {
                    inst.file.Write(writer, 0, replList, 0);
                }

                writer.Close();
            }
        }
Ejemplo n.º 2
0
        private void button1_Click(object sender, EventArgs e)
        {
            OpenFileDialog ofd = new OpenFileDialog();

            if (ofd.ShowDialog() != DialogResult.OK)
            {
                return;
            }

            string mainFile = ofd.FileName;
            string outFile  = Path.Combine(Path.GetDirectoryName(ofd.FileName), "out.assets");
            //string classFile = "U5.6.0f3_AT.NET.dat";

            FileStream       mffs            = new FileStream(mainFile, FileMode.Open);
            FileStream       offs            = new FileStream(outFile, FileMode.Create);
            AssetsFile       assetsFile      = new AssetsFile(new AssetsFileReader(mffs));
            AssetsFileWriter writer          = new AssetsFileWriter(offs);
            AssetsReplacer   assetsReplacer1 = new AssetsReplacerFromFile(0, 100, 0x1, 0xFFFF, new FileStream("testasset.dat", FileMode.Open), 0, 0x0E);

            assetsFile.Write(writer, 0, new AssetsReplacer[] { assetsReplacer1 }, 0);
            writer.Close();
            writer.Dispose();
            //AssetsFileTable assetsFileTable = new AssetsFileTable(assetsFile);
            //AssetFileInfoEx assetsFileInfo = assetsFileTable.getAssetInfo(289578);

            //FileStream cffs = new FileStream(classFile, FileMode.Open);
            //AssetTypeTemplateField pBaseField = new AssetTypeTemplateField();
            //ClassDatabaseFile classDatabaseFile = new ClassDatabaseFile();
            //classDatabaseFile.Read(new AssetsFileReader(cffs));

            //ClassDatabaseType classDatabaseType = AssetHelper.FindAssetClassByName(classDatabaseFile, "MonoBehaviour");

            //pBaseField.FromClassDatabase(classDatabaseFile, classDatabaseType, 0);

            //AssetTypeInstance ati = new AssetTypeInstance(1, new[] { pBaseField }, new AssetsFileReader(mffs), false, assetsFileInfo.absoluteFilePos);

            //MonoClass mc = new MonoClass();
            //mc.Read("Peeper", "E:\\Steam\\steamapps\\common\\Subnautica\\Subnautica_Data\\Managed\\Assembly-CSharp.dll");
            //AssetTypeTemplateField[] templateField = pBaseField.children.Concat(mc.children).ToArray();
            //pBaseField.children = templateField;
            //pBaseField.childrenCount = (uint)pBaseField.children.Length;

            //AssetTypeInstance ati2 = new AssetTypeInstance(1, new[] { pBaseField }, new AssetsFileReader(mffs), false, assetsFileInfo.absoluteFilePos);

            //MessageBox.Show("" + ati.GetBaseField().childrenCount);
            //MessageBox.Show("" + ati.GetBaseField().childrenCount);
            //MessageBox.Show("" + ati.GetBaseField().Get("m_Component").Get("Array").Get(0).Get("component").Get("m_PathID").GetValue().AsInt64());
            //MessageBox.Show("" + ati2.GetBaseField().Get("rechargeInterval").GetValue().AsFloat());
            //Console.WriteLine(ati.GetBaseField().Get(2).GetValue().asString);
            //Console.ReadLine();
        }