Beispiel #1
0
        private void buttonMetaLoad_Click(object sender, EventArgs e)
        {
            OpenFileDialog LoadMeta = new OpenFileDialog();
            LoadMeta.Filter = "Metadata XML|*.xml";
            DialogResult LoadResult = LoadMeta.ShowDialog();
            if (LoadResult != DialogResult.OK) return;

            ModEntry modMetaData = new ModEntry();
            modMetaData.ReadFromFile(LoadMeta.FileName);

            textModName.Text = modMetaData.Name;
            textModVersion.Text = modMetaData.Version;
            textModAuthor.Text = modMetaData.Author;
            textModWebsite.Text = modMetaData.Website;
            textModDescription.Text = modMetaData.Description.Replace("\n", "\r\n");
            foreach(string li in comboForVersion.Items)
            {
                if(modMetaData.MGSVersion == li)
                {
                    comboForVersion.SelectedIndex = comboForVersion.Items.IndexOf(li);
                    break;
                }
            }
        }
Beispiel #2
0
        public static bool InstallMod(string ModFile)
        {
            if (!ModManager.ValidInstallPath) return false; // no valid install specified

            if (!File.Exists(GameArchivePath)) return false;

            // extract existing DAT file
            ExtractGameArchive();

            // import existing DAT xml
            QarFile qarXml = new QarFile();
            qarXml.LoadFromFile(GameArchiveXmlPath);

            // extract mod files to temp folder
            if (Directory.Exists("_temp")) Directory.Delete("_temp", true);
            FastZip unzipper = new FastZip();
            unzipper.ExtractZip(ModFile, "_temp", "(.*?)");

            // load mod metadata
            ModEntry modMetadata = new ModEntry();
            modMetadata.ReadFromFile("_temp\\metadata.xml");
            File.Delete("_temp\\metadata.xml");

            // check for fpk merges
            List<ModFpkEntry> installedFpkFiles = new List<ModFpkEntry>();
            foreach (QarEntry gzsQar in qarXml.QarEntries)
            {
                string qarExt = gzsQar.FilePath.Substring(gzsQar.FilePath.LastIndexOf(".") + 1).ToLower();
                if (qarExt == "fpk" || qarExt == "fpkd")
                {
                    // extract FPK and add files to list
                    string fpkFile = GameArchiveDir + "\\" + gzsQar.FilePath;
                    string fpkDir = fpkFile.Replace(".", "_");
                    GzsTool.GzsTool.Run(fpkFile);

                    List<string> fpkFiles = Directory.GetFiles(fpkDir, "*.*", SearchOption.AllDirectories).ToList();
                    foreach (string file in fpkFiles)
                    {
                        string fpkFilePath = fpkFile.Substring(GameArchiveDir.Length);
                        fpkFilePath = fpkFilePath.Replace("\\", "/");

                        string fpkPath = file.Substring(file.LastIndexOf("Assets\\"));
                        fpkPath = "/" + fpkPath.Replace("\\", "/");

                        installedFpkFiles.Add(new ModFpkEntry() { FilePath = fpkFilePath, FpkFile = fpkPath });
                    }
                }
            }

            // compare lists and build merge fpk list
            List<string> mergeFpks = new List<string>();
            foreach (ModFpkEntry installedFpk in installedFpkFiles)
            {
                foreach (ModEntry mod in GetInstalledMods())
                {
                    if (mod.ModFpkEntries.Find(entry => entry.FpkFile == installedFpk.FpkFile) != null) // if the mod has an fpk that should be merged with an installed fpk
                    {
                        if (!mergeFpks.Contains(installedFpk.FpkFile))
                        {
                            mergeFpks.Add(installedFpk.FpkFile);
                        }
                    }
                }
            }

            if (mergeFpks.Count > 0)
            {
                // merge fpks
                foreach (string fpkFile in mergeFpks)
                {
                    string fpkPath = Tools.ToQarPath(fpkFile);
                    string gameFpkPath = GameArchiveDir + fpkPath;
                    string gameFpkDir = GameArchiveDir + "\\master\\0\\01\\" + fpkPath.Replace(".", "_");
                    string modFpkPath = "_temp\\" + fpkPath;
                    string modFpkDir = "_temp\\" + fpkPath.Replace(".", "_");

                    GzsTool.GzsTool.Run(gameFpkPath);
                    GzsTool.GzsTool.Run(modFpkPath);

                    // load existing xml data
                    FpkFile fpkXml = new FpkFile();
                    fpkXml.LoadFromFile(gameFpkPath + ".xml");

                    // generate list of files to move and add to xml
                    List<string> filesToMove = new List<string>();
                    foreach (ModFpkEntry file in modMetadata.ModFpkEntries.FindAll(entry => entry.FpkFile == fpkFile))
                    {
                        filesToMove.Add(file.FilePath.Replace("/", "\\"));
                        if (fpkXml.FpkEntries.Count(entry => entry.FilePath == file.FilePath) == 0)
                        {
                            // insert new fpk entries as required
                            fpkXml.FpkEntries.Add(new FpkEntry() { FilePath = fpkFile });
                        }
                    }

                    // create directories and move files
                    foreach (string file in filesToMove)
                    {
                        string fileDir = (gameFpkDir + file).Substring(0, (gameFpkDir + file).LastIndexOf("\\"));
                        if (!Directory.Exists(fileDir))
                        {
                            Directory.CreateDirectory(fileDir);
                        }
                        File.Copy(modFpkDir + file, gameFpkDir + file, true);
                    }

                    fpkXml.WriteToFile(gameFpkPath + ".xml");
                    GzsTool.GzsTool.Run(gameFpkPath + ".xml");
                }
            }

            // copy files for new DAT
            foreach (ModQarEntry modQarFile in modMetadata.ModQarEntries)
            {
                string fileName = "/" + modQarFile.FilePath.Replace("\\", "/");
                string fileDir = (GameArchiveDir + modQarFile.FilePath.Replace("/", "\\")).Substring(0, (GameArchiveDir + modQarFile.FilePath).LastIndexOf("/"));

                // if file is not already in QAR, add it
                if (qarXml.QarEntries.Count(entry => entry.FilePath == modQarFile.FilePath) == 0)
                {
                    qarXml.QarEntries.Add(new QarEntry() { FilePath = modQarFile.FilePath, Compressed = modQarFile.Compressed, Hash = modQarFile.Hash });
                }

                // copy all files that weren't merged FPKS
                if (!mergeFpks.Contains(fileName))
                {
                    if (!Directory.Exists(fileDir))
                    {
                        Directory.CreateDirectory(fileDir);
                    }
                    File.Copy("_temp\\" + modQarFile.FilePath.Replace("/", "\\"), ModManager.GameArchiveDir + modQarFile.FilePath.Replace("/", "\\"), true);
                }
            }

            // build XML for new DAT
            qarXml.WriteToFile(GameArchiveXmlPath);

            // build new DAT
            GzsTool.GzsTool.Run(GameArchiveXmlPath);

            // remove temp files
            Directory.Delete("_temp", true);
            Directory.Delete(GameArchiveDir, true);
            File.Delete(GameArchiveXmlPath);

            UpdateDatHash();

            return true;
        }
Beispiel #3
0
        private void formMain_Load(object sender, EventArgs e)
        {
            comboForVersion.SelectedIndex = comboForVersion.Items.Count - 1;
            string modPath = Properties.Settings.Default.LastModDir;
            if (Directory.Exists(modPath))
            {
                if(File.Exists(modPath + "\\metadata.xml"))
                {
                    ModEntry modMetaData = new ModEntry();
                    modMetaData.ReadFromFile(modPath + "\\metadata.xml");

                    textModName.Text = modMetaData.Name;
                    textModVersion.Text = modMetaData.Version;
                    textModAuthor.Text = modMetaData.Author;
                    textModWebsite.Text = modMetaData.Website;
                    textModDescription.Text = modMetaData.Description.Replace("\n", "\r\n");
                }
                textModPath.Text = modPath;
                foreach (string modFile in Directory.GetFiles(modPath, "*.*", SearchOption.AllDirectories))
                {
                    string filePath = modFile.Substring(modPath.Length).Replace("\\", "/");
                    if (Hashing.ValidFileExtension(filePath) && filePath != "/metadata.xml") listModFiles.Items.Add(filePath);
                }
            } else
            {
                Properties.Settings.Default.LastModDir = String.Empty;
                Properties.Settings.Default.Save();
            }
        }
Beispiel #4
0
        private void PopulateBoxes(string DataPath)
        {
            // unpack existing fpks
            foreach (string fpkFile in Directory.GetFiles(DataPath, "*.fpk*", SearchOption.AllDirectories))
            {
                string fpkDir = Path.Combine(Path.GetDirectoryName(fpkFile), Path.GetFileName(fpkFile).Replace(".", "_"));
                if (!Directory.Exists(fpkDir))
                {
                    //extract fpk
                    GzsLib.ExtractArchive<FpkFile>(fpkFile, fpkDir);
                }
            }

            foreach (string modFile in Directory.GetFiles(DataPath, "*.*", SearchOption.AllDirectories))
            {
                string filePath = modFile.Substring(DataPath.Length).Replace("\\", "/");
                if (Tools.IsValidFile(filePath) && filePath != "/metadata.xml") listModFiles.Items.Add(filePath);
            }

            if (File.Exists(Path.Combine(DataPath, "metadata.xml")))
            {
                ModEntry modMetaData = new ModEntry();
                modMetaData.ReadFromFile(Path.Combine(DataPath, "metadata.xml"));

                textModName.Text = modMetaData.Name;
                textModVersion.Text = modMetaData.Version;
                textModAuthor.Text = modMetaData.Author;
                textModWebsite.Text = modMetaData.Website;
                textModDescription.Text = modMetaData.Description.Replace("\n", "\r\n");
                foreach (string li in comboForVersion.Items)
                {
                    if (modMetaData.MGSVersion.AsString() == li)
                    {
                        comboForVersion.SelectedIndex = comboForVersion.Items.IndexOf(li);
                        break;
                    }
                }
            }

            if (File.Exists(DataPath + "\\readme.txt"))
            {
                StreamReader s = new StreamReader(DataPath + "\\readme.txt");
                string readme = s.ReadToEnd();
                textModDescription.Text = readme;
            }
        }
        private void buttonMetaLoad_Click(object sender, EventArgs e)
        {
            OpenFileDialog LoadMeta = new OpenFileDialog();
            LoadMeta.Filter = "Metadata XML|*.xml";
            DialogResult LoadResult = LoadMeta.ShowDialog();
            if (LoadResult != DialogResult.OK) return;

            ModEntry modMetaData = new ModEntry();
            modMetaData.ReadFromFile(LoadMeta.FileName);

            textModName.Text = modMetaData.Name;
            textModVersion.Text = modMetaData.Version;
            textModAuthor.Text = modMetaData.Author;
            textModWebsite.Text = modMetaData.Website;
            textModDescription.Text = modMetaData.Description.Replace("\n", "\r\n");
        }
Beispiel #6
0
        private void ProcessInstallMod(string ModFile, bool ignoreConflicts = false)
        {
            // extract metadata and load
            FastZip unzipper = new FastZip();
            unzipper.ExtractZip(ModFile, ".", "metadata.xml");

            ModEntry modMetadata = new ModEntry();
            modMetadata.ReadFromFile("metadata.xml");
            File.Delete("metadata.xml"); // delete temp metadata

            if (!checkConflicts.Checked && !ignoreConflicts)
            {
                // check version conflicts
                int SBVersion = ModManager.GetSBVersion();
                int MGSVersion = ModManager.GetMGSVersion();

                int modSBVersion = Convert.ToInt32(modMetadata.SBVersion);
                int modMGSVersion = Convert.ToInt32(modMetadata.MGSVersion);

                // Check if mod requires SB update
                if (modSBVersion > SBVersion)
                {
                    MessageBox.Show(String.Format("{0} requires a newer version of SnakeBite. Please follow the link on the Settings page to get the latest version.", modMetadata.Name), "Update required", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return;
                }

                // Check MGS version compatibility
                if (MGSVersion != modMGSVersion && modMGSVersion != 0)
                {
                    if (MGSVersion > modMGSVersion) MessageBox.Show(String.Format("{0} requires MGSV version {1}, but your installation is version {2}. Please update {0} and try again.", modMetadata.Name, modMGSVersion, MGSVersion), "Update required", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    if (MGSVersion < modMGSVersion) MessageBox.Show(String.Format("{0} requires MGSV version {1}, but your installation is version {2}. Please update MGSV and try again.", modMetadata.Name, modMGSVersion, MGSVersion), "Update required", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return;
                }

                // search installed mods for conflicts
                List<string> conflictingMods = new List<string>();

                foreach (ModEntry modEntry in objSettings.ModEntries) // iterate through installed mods
                {
                    foreach (ModQarEntry qarEntry in modMetadata.ModQarEntries) // iterate qar files from new mod
                    {
                        ModQarEntry conflicts = modEntry.ModQarEntries.FirstOrDefault(entry => entry.FilePath == qarEntry.FilePath);
                        if (conflicts != null)
                        {
                            conflictingMods.Add(modEntry.Name);
                            break;
                        }
                    }

                    foreach (ModFpkEntry fpkEntry in modMetadata.ModFpkEntries) // iterate fpk files from new mod
                    {
                        ModFpkEntry conflicts = modEntry.ModFpkEntries.FirstOrDefault(entry => entry.FpkFile == fpkEntry.FpkFile && entry.FilePath == fpkEntry.FilePath);
                        if (conflicts != null)
                        {
                            if (!conflictingMods.Contains(modEntry.Name))
                            {
                                conflictingMods.Add(modEntry.Name);
                                break;
                            }
                        }
                    }
                }

                // if the mod conflicts, display message
                if (conflictingMods.Count > 0)
                {
                    string msgboxtext = "The selected mod conflicts with these mods:\n";
                    foreach (string Conflict in conflictingMods)
                    {
                        msgboxtext += Conflict + "\n";
                    }
                    msgboxtext += "\nPlease uninstall the mods above and try again.";
                    MessageBox.Show(msgboxtext, "Installation Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return;
                }

                bool sysConflict = false;
                // check for system file conflicts
                foreach (ModQarEntry gameQarFile in objSettings.GameData.GameQarEntries)
                {
                    if (modMetadata.ModQarEntries.Count(entry => entry.FilePath == gameQarFile.FilePath) > 0) sysConflict = true;
                }

                foreach (ModFpkEntry gameFpkFile in objSettings.GameData.GameFpkEntries)
                {
                    if (modMetadata.ModFpkEntries.Count(entry => entry.FilePath == gameFpkFile.FilePath && entry.FpkFile == gameFpkFile.FpkFile) > 0) sysConflict = true;
                }
                if (sysConflict)
                {
                    MessageBox.Show("The selected mod conflicts with existing MGSV system files.", "SnakeBite", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return;
                }
            }

            DialogResult confirmInstall = MessageBox.Show(String.Format("You are about to install {0}, continue?", modMetadata.Name), "SnakeBite", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
            if (confirmInstall == DialogResult.No) return;

            showProgressWindow(String.Format("Installing {0}, please wait...", modMetadata.Name));

            // Install mod to game database
            objSettings.ModEntries.Add(modMetadata);
            objSettings.SaveSettings();

            // Install mod to 01.dat
            ModManager.InstallMod(ModFile);

            RefreshInstalledMods();
            listInstalledMods.SelectedIndex = listInstalledMods.Items.Count - 1;

            hideProgressWindow();
        }
        private void buttonInstallMod_Click(object sender, EventArgs e)
        {
            // Show open file dialog for mod file
            OpenFileDialog openModFile = new OpenFileDialog();
            openModFile.Filter = "MGSV Mod Files|*.mgsv|All Files|*.*";
            DialogResult ofdResult = openModFile.ShowDialog();
            if (ofdResult != DialogResult.OK) return;

            // extract metadata and load
            FastZip unzipper = new FastZip();
            unzipper.ExtractZip(openModFile.FileName, ".", "metadata.xml");

            ModEntry modMetadata = new ModEntry();
            modMetadata.ReadFromFile("metadata.xml");
            File.Delete("metadata.xml"); // delete temp metadata

            if(!checkConflicts.Checked)
            {
                // search installed mods for conflicts
                List<string> conflictingMods = new List<string>();

                foreach (ModEntry modEntry in objSettings.ModEntries) // iterate through installed mods
                {
                    foreach (ModQarEntry qarEntry in modMetadata.ModQarEntries) // iterate qar files from new mod
                    {
                        ModQarEntry conflicts = modEntry.ModQarEntries.FirstOrDefault(entry => entry.FilePath == qarEntry.FilePath);
                        if (conflicts != null)
                        {
                            conflictingMods.Add(modEntry.Name);
                            break;
                        }
                    }

                    foreach (ModFpkEntry fpkEntry in modMetadata.ModFpkEntries) // iterate fpk files from new mod
                    {
                        ModFpkEntry conflicts = modEntry.ModFpkEntries.FirstOrDefault(entry => entry.FpkFile == fpkEntry.FpkFile && entry.FilePath == fpkEntry.FilePath);
                        if (conflicts != null)
                        {
                            if (!conflictingMods.Contains(modEntry.Name))
                            {
                                conflictingMods.Add(modEntry.Name);
                                break;
                            }
                        }
                    }
                }

                // if the mod conflicts, display message
                if (conflictingMods.Count > 0)
                {
                    string msgboxtext = "The selected mod conflicts with these mods:\n";
                    foreach (string Conflict in conflictingMods)
                    {
                        msgboxtext += Conflict + "\n";
                    }
                    msgboxtext += "\nPlease uninstall the mods above and try again.";
                    MessageBox.Show(msgboxtext, "Installation Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return;
                }

                bool sysConflict = false;
                // check for system file conflicts
                foreach (ModQarEntry gameQarFile in objSettings.GameData.GameQarEntries)
                {
                    if (modMetadata.ModQarEntries.Count(entry => entry.FilePath == gameQarFile.FilePath) > 0) sysConflict = true;
                }

                foreach (ModFpkEntry gameFpkFile in objSettings.GameData.GameFpkEntries)
                {
                    if (modMetadata.ModFpkEntries.Count(entry => entry.FilePath == gameFpkFile.FilePath && entry.FpkFile == gameFpkFile.FpkFile) > 0) sysConflict = true;
                }
                if (sysConflict)
                {
                    MessageBox.Show("The selected mod conflicts with existing MGSV system files.", "SnakeBite", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return;
                }
            }

            DialogResult confirmInstall = MessageBox.Show(String.Format("You are about to install {0}, continue?", modMetadata.Name), "SnakeBite", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
            if (confirmInstall == DialogResult.No) return;

            showProgressWindow(String.Format("Installing {0}, please wait...", modMetadata.Name));

            // Install mod to game database
            objSettings.ModEntries.Add(modMetadata);
            objSettings.SaveSettings();

            // Install mod to 01.dat
            ModManager.InstallMod(openModFile.FileName);

            LoadInstalledMods();
            listInstalledMods.SelectedIndex = listInstalledMods.Items.Count - 1;

            hideProgressWindow();
        }