예제 #1
0
        public LoadModPackageDialog(InstallerPackageFile emip, AssetsManager am) : this()
        {
            this.emip = emip;
            this.am   = am;

            BuildTreeAssets();
        }
예제 #2
0
        private async void MenuLoadPackageFile_Click(object?sender, RoutedEventArgs e)
        {
            OpenFileDialog ofd = new OpenFileDialog();

            ofd.Filters = new List <FileDialogFilter>()
            {
                new FileDialogFilter()
                {
                    Name = "UABE Mod Installer Package", Extensions = new List <string>()
                    {
                        "emip"
                    }
                }
            };

            string[] fileList = await ofd.ShowAsync(this);

            if (fileList.Length == 0)
            {
                return;
            }

            string emipPath = fileList[0];

            if (emipPath != null && emipPath != string.Empty)
            {
                AssetsFileReader     r    = new AssetsFileReader(File.OpenRead(emipPath)); //todo close this
                InstallerPackageFile emip = new InstallerPackageFile();
                emip.Read(r);

                LoadModPackageDialog dialog = new LoadModPackageDialog(emip, am);
                await dialog.ShowDialog(this);
            }
        }
예제 #3
0
        private void BuildEmip(string path)
        {
            InstallerPackageFile emip = new InstallerPackageFile
            {
                magic          = "EMIP",
                includesCldb   = false,
                modName        = boxModName.Text ?? "",
                modCreators    = boxCredits.Text ?? "",
                modDescription = boxDesc.Text ?? ""
            };

            emip.affectedFiles = new List <InstallerPackageAssetsDesc>();

            foreach (ModMakerTreeFileInfo file in affectedFiles.Items)
            {
                //hack pls fix thx
                string filePath = file.relPath;
                InstallerPackageAssetsDesc desc = new InstallerPackageAssetsDesc()
                {
                    isBundle = false,
                    path     = filePath
                };
                desc.replacers = new List <object>();
                foreach (ModMakerTreeReplacerInfo change in file.Replacers)
                {
                    desc.replacers.Add(change.assetsReplacer);
                }
                emip.affectedFiles.Add(desc);
            }

            using (FileStream fs = File.OpenWrite(path))
                using (AssetsFileWriter writer = new AssetsFileWriter(fs))
                {
                    emip.Write(writer);
                }
        }
예제 #4
0
        private static void ApplyEmip(string[] args)
        {
            HashSet <string> flags    = GetFlags(args);
            string           emipFile = args[1];
            string           rootDir  = args[2];

            if (!File.Exists(emipFile))
            {
                Console.WriteLine($"File {emipFile} does not exist!");
                return;
            }

            InstallerPackageFile instPkg = new InstallerPackageFile();
            FileStream           fs      = File.OpenRead(emipFile);
            AssetsFileReader     r       = new AssetsFileReader(fs);

            instPkg.Read(r, true);

            Console.WriteLine($"Installing emip...");
            Console.WriteLine($"{instPkg.modName} by {instPkg.modCreators}");
            Console.WriteLine(instPkg.modDescription);

            foreach (var affectedFile in instPkg.affectedFiles)
            {
                string affectedFileName = Path.GetFileName(affectedFile.path);
                string affectedFilePath = Path.Combine(rootDir, affectedFile.path);

                if (affectedFile.isBundle)
                {
                    string decompFile = $"{affectedFilePath}.decomp";
                    string modFile    = $"{affectedFilePath}.mod";
                    string bakFile    = GetNextBackup(affectedFilePath);

                    if (bakFile == null)
                    {
                        return;
                    }

                    if (flags.Contains("-md"))
                    {
                        decompFile = null;
                    }

                    Console.WriteLine($"Decompressing {affectedFileName} to {decompFile??"memory"}...");
                    AssetBundleFile       bun  = DecompressBundle(affectedFilePath, decompFile);
                    List <BundleReplacer> reps = new List <BundleReplacer>();

                    foreach (var rep in affectedFile.replacers)
                    {
                        var bunRep = (BundleReplacer)rep;
                        if (bunRep is BundleReplacerFromAssets)
                        {
                            //read in assets files from the bundle for replacers that need them
                            string assetName = bunRep.GetOriginalEntryName();
                            var    bunRepInf = BundleHelper.GetDirInfo(bun, assetName);
                            long   pos       = bun.bundleHeader6.GetFileDataOffset() + bunRepInf.offset;
                            bunRep.Init(bun.reader, pos, bunRepInf.decompressedSize);
                        }
                        reps.Add(bunRep);
                    }

                    Console.WriteLine($"Writing {modFile}...");
                    FileStream       mfs = File.OpenWrite(modFile);
                    AssetsFileWriter mw  = new AssetsFileWriter(mfs);
                    bun.Write(mw, reps, instPkg.addedTypes); //addedTypes does nothing atm

                    mfs.Close();
                    bun.Close();

                    Console.WriteLine($"Swapping mod file...");
                    File.Move(affectedFilePath, bakFile);
                    File.Move(modFile, affectedFilePath);

                    if (!flags.Contains("-kd") && !flags.Contains("-md") && File.Exists(decompFile))
                    {
                        File.Delete(decompFile);
                    }

                    Console.WriteLine($"Done.");
                }
                else //isAssetsFile
                {
                    string modFile = $"{affectedFilePath}.mod";
                    string bakFile = GetNextBackup(affectedFilePath);

                    if (bakFile == null)
                    {
                        return;
                    }

                    FileStream            afs    = File.OpenRead(affectedFilePath);
                    AssetsFileReader      ar     = new AssetsFileReader(afs);
                    AssetsFile            assets = new AssetsFile(ar);
                    List <AssetsReplacer> reps   = new List <AssetsReplacer>();

                    foreach (var rep in affectedFile.replacers)
                    {
                        var assetsReplacer = (AssetsReplacer)rep;
                        reps.Add(assetsReplacer);
                    }

                    Console.WriteLine($"Writing {modFile}...");
                    FileStream       mfs = File.OpenWrite(modFile);
                    AssetsFileWriter mw  = new AssetsFileWriter(mfs);
                    assets.Write(mw, 0, reps, 0, instPkg.addedTypes);

                    mfs.Close();
                    ar.Close();

                    Console.WriteLine($"Swapping mod file...");
                    File.Move(affectedFilePath, bakFile);
                    File.Move(modFile, affectedFilePath);

                    Console.WriteLine($"Done.");
                }
            }

            return;
        }
예제 #5
0
        private async void BtnImport_Click(object?sender, Avalonia.Interactivity.RoutedEventArgs e)
        {
            OpenFileDialog ofd = new OpenFileDialog();

            ofd.Filters = new List <FileDialogFilter>()
            {
                new FileDialogFilter()
                {
                    Name = "UABE Mod Installer Package", Extensions = new List <string>()
                    {
                        "emip"
                    }
                }
            };

            string[] fileList = await ofd.ShowAsync(this);

            if (fileList.Length == 0)
            {
                return;
            }

            string emipPath = fileList[0];

            if (emipPath != null && emipPath != string.Empty)
            {
                OpenFolderDialog ofdBase = new OpenFolderDialog();
                ofdBase.Title = "Select base folder";

                string rootPath = await ofdBase.ShowAsync(this);

                if (rootPath != null && rootPath != string.Empty)
                {
                    InstallerPackageFile impEmip = new InstallerPackageFile();

                    if (importedEmipStream != null && importedEmipStream.CanRead)
                    {
                        importedEmipStream.Close();
                    }

                    importedEmipStream = File.OpenRead(emipPath);
                    AssetsFileReader r = new AssetsFileReader(importedEmipStream);
                    impEmip.Read(r);

                    boxModName.Text = impEmip.modName;
                    boxCredits.Text = impEmip.modCreators;
                    boxDesc.Text    = impEmip.modDescription;

                    foreach (InstallerPackageAssetsDesc affectedFile in impEmip.affectedFiles)
                    {
                        if (!affectedFile.isBundle)
                        {
                            string file = Path.GetFullPath(affectedFile.path, rootPath);
                            if (!fileToTvi.ContainsKey(file))
                            {
                                ModMakerTreeFileInfo newFileItem = new ModMakerTreeFileInfo(file, rootPath);
                                filesItems.Add(newFileItem);
                                fileToTvi.Add(file, newFileItem);
                            }

                            ModMakerTreeFileInfo fileItem = fileToTvi[file];

                            foreach (AssetsReplacer replacer in affectedFile.replacers)
                            {
                                AssetID assetId = new AssetID(file, replacer.GetPathID());

                                var obsItems = fileItem.Replacers;
                                obsItems.Add(new ModMakerTreeReplacerInfo(assetId, replacer));
                            }
                        }
                    }
                }
            }
        }