private void buttonLeft_Click(object sender, EventArgs e) { if (SelectedMod == null) { return; } if (SelectedMod.isActiveList) { return; } StageModXML xml = Globals.Utils.OpenStageKamiModFile(SelectedMod.modFolder); if (xml == null) { return; } int id = xml.IntendedStage; for (int i = 0; i < _SmashProjectManager.CurrentProject.ActiveStageMods.Count; ++i) { if (id == _SmashProjectManager.CurrentProject.ActiveStageMods[i].StageID) { MessageBox.Show(String.Format("Cannot activate mod. Stage mod '{0}' is already occupying that stage slot.", _SmashProjectManager.CurrentProject.ActiveStageMods[i].FolderName)); return; } } StageSlotMod newActiveMod = new StageSlotMod(); newActiveMod.FolderName = SelectedMod.modFolder; newActiveMod.StageID = id; _SmashProjectManager.CurrentProject.ActiveStageMods.Add(newActiveMod); RefreshModsLists(); _GridMods.SelectMod(newActiveMod.FolderName); }
private void ProcessStageModFiles(string[] files, string baseDirectory) { string[] xmlFiles = Utils.FindFilesByFilename(files, "kamimod.xml"); List <string> XmlModFiles = new List <string>(); List <StageModXML> XmlMods = new List <StageModXML>(); if (xmlFiles != null) { foreach (string xmlFile in xmlFiles) { if (Path.GetFileName(xmlFile) != "kamimod.xml") { continue; } StageModXML mod = Utils.DeserializeXML <StageModXML>(xmlFile); if (mod == null) { continue; } XmlMods.Add(mod); XmlModFiles.Add(xmlFile); } } if (XmlMods.Count > 0) { for (int i = 0; i < XmlMods.Count; ++i) { string oldBasePath = Path.GetDirectoryName(XmlModFiles[0]); string modFolderName = oldBasePath.Split(Path.DirectorySeparatorChar).Last(); if (modFolderName == "unzip") { modFolderName = XmlMods[i].DisplayName; } StageModXML xmlTest = Utils.OpenStageKamiModFile(modFolderName); if (xmlTest != null) { MessageBox.Show(String.Format("Mod already exists under the same folder name '{0}'. Skipping...", modFolderName)); return; } oldBasePath = oldBasePath + Path.DirectorySeparatorChar; string newBasePath = PathHelper.FolderStageMods + modFolderName + Path.DirectorySeparatorChar; Utils.CopyAllValidFilesBetweenDirectories(oldBasePath, newBasePath); LogHelper.Info(String.Format("KamiMod {0} imported successfully!", modFolderName)); RefreshRowData(); } } else { string baseDirectoryTopFolderExcluded = baseDirectory.Remove(baseDirectory.LastIndexOf(Path.DirectorySeparatorChar, baseDirectory.Length - 2)); string stageFolder = Utils.FindDirectoryInFiles(files, DB.StagesDB.StageNames, baseDirectoryTopFolderExcluded); //Check if all the folders are either empty, or don't exist if (stageFolder.Equals(String.Empty)) { MessageBox.Show("No valid mod files or directories found. Make sure that the mod files follow the Sm4shExplorer file tree, and have a root folder of 'melee' or 'end' that has a stage folder such as 'BattleField_f'"); LogHelper.Error("No valid mod files or directories found. Make sure that the mod files follow the Sm4shExplorer file tree, and have a root folder of 'melee' or 'end' that has a stage folder such as 'BattleField_f'"); return; } DB.Stage stage = null; string[] folderParts = stageFolder.Split(Path.DirectorySeparatorChar); string folder1 = folderParts[folderParts.Length - 2]; string folder2 = folderParts.Last(); if (folder1.Equals("melee")) { foreach (DB.Stage st in DB.StagesDB.Stages) { if (st.Type != DB.StageType.Melee) { continue; } if (!folder2.Equals(st.Label)) { continue; } stage = st; break; } } else if (folder1.Equals("end")) { foreach (DB.Stage st in DB.StagesDB.Stages) { if (st.Type != DB.StageType.End) { continue; } if (!folder2.Equals(st.Label)) { continue; } stage = st; break; } } if (stage == null) { MessageBox.Show("No 'end' or 'melee' folder found. Make sure that the mod files follow the Sm4shExplorer file tree, and have a root folder of 'melee' or 'end' that has a stage folder such as 'BattleField_f'"); LogHelper.Error("No 'end' or 'melee' folder found. Make sure that the mod files follow the Sm4shExplorer file tree, and have a root folder of 'melee' or 'end' that has a stage folder such as 'BattleField_f'"); return; } string name = baseDirectory.Split(Path.DirectorySeparatorChar).Last(); Forms.NewModNamePopup popup = new Forms.NewModNamePopup(); popup.nameText = name; bool nameValid = false; while (!nameValid) { popup.ShowDialog(); if (!popup.confirmPressed) { return; } popup.confirmPressed = false; name = popup.nameText; name = PathHelper.RemoveInvalidFilenameChars(name); if (name.Length < 1) { MessageBox.Show("Invalid mod name given. Please enter a new one."); continue; } StageModXML xmlTest = Utils.OpenStageKamiModFile(name); if (xmlTest != null) { MessageBox.Show("Mod already exists under the same folder name. Please enter a new one."); continue; } nameValid = true; } string newModDirectory = PathHelper.FolderStageMods + Path.DirectorySeparatorChar + name + Path.DirectorySeparatorChar; string[] Files_stage_10 = Utils.FindFilesByFilename(files, "stage_10"); string[] Files_stage_11 = Utils.FindFilesByFilename(files, "stage_11"); string[] Files_stage_12 = Utils.FindFilesByFilename(files, "stage_12"); string[] Files_stage_13 = Utils.FindFilesByFilename(files, "stage_13"); string[] Files_stage_30 = Utils.FindFilesByFilename(files, "stage_30"); string[] Files_stagen_10 = Utils.FindFilesByFilename(files, "stagen_10"); #region XML File Creation StageModXML xml = new StageModXML(); xml.DisplayName = name; xml.WifiSafe = true; //Assuming wifi-safe xml.IntendedStage = stage.ID; xml.stage_10 = Files_stage_10.Length > 0; xml.stage_11 = Files_stage_11.Length > 0; xml.stage_12 = Files_stage_12.Length > 0; xml.stage_13 = Files_stage_13.Length > 0; xml.stage_30 = Files_stage_30.Length > 0; xml.stagen_10 = Files_stagen_10.Length > 0; Utils.SerializeXMLToFile(xml, newModDirectory + "kamimod.xml"); #endregion Utils.CopyAllValidFilesBetweenDirectories(stageFolder, newModDirectory + "stage" + Path.DirectorySeparatorChar); if (xml.stage_10 || xml.stage_11 || xml.stage_12 || xml.stage_13 || xml.stage_30 || xml.stagen_10) { string baseChrPath = newModDirectory + "ui" + Path.DirectorySeparatorChar; Directory.CreateDirectory(baseChrPath); if (xml.stage_10) { File.Copy(Files_stage_10[0], baseChrPath + "stage_10_XX.nut"); } if (xml.stage_11) { File.Copy(Files_stage_11[0], baseChrPath + "stage_11_XX.nut"); } if (xml.stage_12) { File.Copy(Files_stage_12[0], baseChrPath + "stage_12_XX.nut"); } if (xml.stage_13) { File.Copy(Files_stage_13[0], baseChrPath + "stage_13_XX.nut"); } if (xml.stage_30) { File.Copy(Files_stage_30[0], baseChrPath + "stage_30_XX.nut"); } if (xml.stagen_10) { File.Copy(Files_stagen_10[0], baseChrPath + "stagen_10_XX.nut"); } } LogHelper.Info(String.Format("Mod {0} imported successfully!", name)); RefreshRowData(); } }
public void RefreshRowData() { _RowData = new List <RowData>(); _Project = _SmashProjectManager.CurrentProject; if (_IsActiveList) { if (_ModListType == ModListType.CharacterGeneral) { for (int j = 0; j < _Project.ActiveCharacterGeneralMods.Count; ++j) { if (_Project.ActiveCharacterGeneralMods[j].CharacterID != _CurrentFighter.id) { continue; } RowData row = new RowData(); row.modFolder = _Project.ActiveCharacterGeneralMods[j].FolderName; CharacterGeneralModXML data = Globals.Utils.OpenCharacterGeneralKamiModFile(_CurrentFighter.name, row.modFolder); if (data != null) { row.name = data.DisplayName; row.wifiSafe = data.WifiSafe; } else { row.name = String.Format("{0} (Mod is missing!)", row.modFolder); row.modMissing = true; row.propertiesEnabled = false; } _RowData.Add(row); } } else if (_ModListType == ModListType.Stage) { for (int j = 0; j < _Project.ActiveStageMods.Count; ++j) { RowData row = new RowData(); row.modFolder = _Project.ActiveStageMods[j].FolderName; StageModXML data = Globals.Utils.OpenStageKamiModFile(row.modFolder); if (data != null) { row.name = data.DisplayName; row.wifiSafe = data.WifiSafe; } else { row.name = String.Format("{0} (Mod is missing!)", row.modFolder); row.modMissing = true; row.propertiesEnabled = false; } _RowData.Add(row); } } else if (_ModListType == ModListType.General) { for (int j = 0; j < _Project.ActiveGeneralMods.Count; ++j) { RowData row = new RowData(); row.modFolder = _Project.ActiveGeneralMods[j]; GeneralModXML data = Globals.Utils.OpenGeneralKamiModFile(row.modFolder); if (data != null) { row.name = data.DisplayName; row.wifiSafe = data.WifiSafe; } else { row.name = String.Format("{0} (Mod is missing!)", row.modFolder); row.modMissing = true; row.propertiesEnabled = false; } _RowData.Add(row); } } } else { string baseDirectory = String.Empty; switch (_ModListType) { case (ModListType.CharacterSlots): baseDirectory = PathHelper.FolderCharSlotsMods + _CurrentFighter.name + Path.DirectorySeparatorChar; break; case (ModListType.CharacterGeneral): baseDirectory = PathHelper.FolderCharGeneralMods + _CurrentFighter.name + Path.DirectorySeparatorChar; break; case (ModListType.Stage): baseDirectory = PathHelper.FolderStageMods; break; case (ModListType.General): baseDirectory = PathHelper.FolderGeneralMods; break; } string[] kamiFiles = Directory.GetFiles(baseDirectory, "kamimod.xml", SearchOption.AllDirectories); for (int i = 0; i < kamiFiles.Count(); ++i) { string modFolderName = kamiFiles[i].Replace(baseDirectory, String.Empty).Split(Path.DirectorySeparatorChar).First(); //Check if the mod is already active. If it is, don't include it in this list. bool modIsActive = false; switch (_ModListType) { case (ModListType.CharacterSlots): for (int j = 0; j < _Project.ActiveCharacterSlotMods.Count; ++j) { if (_Project.ActiveCharacterSlotMods[j].CharacterID == _CurrentFighter.id) { if (_Project.ActiveCharacterSlotMods[j].FolderName.Equals(modFolderName)) { modIsActive = true; break; } } } break; case (ModListType.CharacterGeneral): for (int j = 0; j < _Project.ActiveCharacterGeneralMods.Count; ++j) { if (_Project.ActiveCharacterGeneralMods[j].FolderName.Equals(modFolderName)) { modIsActive = true; break; } } break; case (ModListType.Stage): for (int j = 0; j < _Project.ActiveStageMods.Count; ++j) { if (_Project.ActiveStageMods[j].FolderName.Equals(modFolderName)) { modIsActive = true; break; } } break; case (ModListType.General): for (int j = 0; j < _Project.ActiveGeneralMods.Count; ++j) { if (_Project.ActiveGeneralMods[j].Equals(modFolderName)) { modIsActive = true; break; } } break; } if (modIsActive) { continue; } RowData row = new RowData(); row.modFolder = modFolderName; switch (_ModListType) { case (ModListType.CharacterSlots): CharacterSlotModXML data = Utils.DeserializeXML <CharacterSlotModXML>(kamiFiles[i]); row.name = data.DisplayName; row.missingPortraits = (!data.chr_00 || !data.chr_11 || !data.chr_13 || !data.stock_90); if (data.UseCustomName && !row.missingPortraits) { if (!data.chrn_11 || data.BoxingRingText == null) { row.missingPortraits = true; } else if (data.BoxingRingText.Equals(string.Empty)) { row.missingPortraits = true; } } row.metal = data.MetalModel; row.hasAudio = data.Sound || data.Voice; row.hasCustomName = data.UseCustomName; row.wifiSafe = data.WifiSafe; break; case (ModListType.CharacterGeneral): CharacterGeneralModXML data2 = Utils.DeserializeXML <CharacterGeneralModXML>(kamiFiles[i]); row.name = data2.DisplayName; row.wifiSafe = data2.WifiSafe; break; case (ModListType.Stage): StageModXML data3 = Utils.DeserializeXML <StageModXML>(kamiFiles[i]); row.name = data3.DisplayName; row.wifiSafe = data3.WifiSafe; break; case (ModListType.General): GeneralModXML data4 = Utils.DeserializeXML <GeneralModXML>(kamiFiles[i]); row.name = data4.DisplayName; row.wifiSafe = data4.WifiSafe; break; } _RowData.Add(row); } } PopulateRows(); }
public static void SaveStageKamiModFile(string modName, StageModXML data) { SerializeXMLToFile(data, PathHelper.FolderStageMods + modName + Path.DirectorySeparatorChar + "kamimod.xml"); }
public static StageModXML OpenStageKamiModFile(string modName) { StageModXML data = DeserializeXML <StageModXML>(PathHelper.FolderStageMods + modName + Path.DirectorySeparatorChar + "kamimod.xml"); return(data); }
public ModProperties(string modPath, ModsList.ModListType modListType, string charName = "") { InitializeComponent(); ModPath = modPath; ModListType = modListType; CharName = charName; PathKami = ModPath + Path.DirectorySeparatorChar + "kamimod.xml"; switch (ModListType) { case ModsList.ModListType.CharacterGeneral: XMLDataCharGeneral = Utils.DeserializeXML <CharacterGeneralModXML>(PathKami); if (XMLDataCharGeneral == null) { return; } XMLDataCharGeneral.isDirty = false; textBoxDisplayName.Text = XMLDataCharGeneral.DisplayName; checkBoxWifiSafe.Checked = XMLDataCharGeneral.WifiSafe; if (XMLDataCharGeneral.Notes == null) { XMLDataCharGeneral.Notes = String.Empty; } textBoxNotes.Text = XMLDataCharGeneral.Notes.Replace("\n", "\r\n"); groupBoxPortaits.Visible = false; groupBoxStageData.Visible = false; this.Height -= groupBoxPortaits.Height + groupBoxStageData.Height; break; case ModsList.ModListType.Stage: XMLDataStage = Utils.DeserializeXML <StageModXML>(PathKami); if (XMLDataStage == null) { return; } XMLDataStage.isDirty = false; textBoxDisplayName.Text = XMLDataStage.DisplayName; checkBoxWifiSafe.Checked = XMLDataStage.WifiSafe; if (XMLDataStage.Notes == null) { XMLDataStage.Notes = String.Empty; } textBoxNotes.Text = XMLDataStage.Notes.Replace("\n", "\r\n"); for (int i = 0; i < DB.StagesDB.Stages.Count; ++i) { if (DB.StagesDB.Stages[i].ID == XMLDataStage.IntendedStage) { labelStageName.Text = DB.StagesDB.Stages[i].LabelHuman; } } PathStage10 = ModPath + Path.DirectorySeparatorChar + "ui" + Path.DirectorySeparatorChar + "stage_10_XX.nut"; PathStage11 = ModPath + Path.DirectorySeparatorChar + "ui" + Path.DirectorySeparatorChar + "stage_11_XX.nut"; PathStage12 = ModPath + Path.DirectorySeparatorChar + "ui" + Path.DirectorySeparatorChar + "stage_12_XX.nut"; PathStage13 = ModPath + Path.DirectorySeparatorChar + "ui" + Path.DirectorySeparatorChar + "stage_13_XX.nut"; PathStage30 = ModPath + Path.DirectorySeparatorChar + "ui" + Path.DirectorySeparatorChar + "stage_30_XX.nut"; PathStagen10 = ModPath + Path.DirectorySeparatorChar + "ui" + Path.DirectorySeparatorChar + "stagen_10_XX.nut"; XMLDataStage.stage_10 = File.Exists(PathStage10); XMLDataStage.stage_11 = File.Exists(PathStage11); XMLDataStage.stage_12 = File.Exists(PathStage12); XMLDataStage.stage_13 = File.Exists(PathStage13); XMLDataStage.stage_30 = File.Exists(PathStage30); XMLDataStage.stagen_10 = File.Exists(PathStagen10); buttonExport_stage10.Enabled = XMLDataStage.stage_10; buttonExport_stage11.Enabled = XMLDataStage.stage_11; buttonExport_stage12.Enabled = XMLDataStage.stage_12; buttonExport_stage13.Enabled = XMLDataStage.stage_13; buttonExport_stage30.Enabled = XMLDataStage.stage_30; buttonExport_stagen10.Enabled = XMLDataStage.stagen_10; if (XMLDataStage.stage_10) { pictureBox_stage10.BackgroundImage = FileTypes.NUT.BitmapFromPortraitNut(PathStage10); UpdatePictureBoxClickable(pictureBox_stage10); } if (XMLDataStage.stage_11) { pictureBox_stage11.BackgroundImage = FileTypes.NUT.BitmapFromPortraitNut(PathStage11); UpdatePictureBoxClickable(pictureBox_stage11); } if (XMLDataStage.stage_12) { pictureBox_stage12.BackgroundImage = FileTypes.NUT.BitmapFromPortraitNut(PathStage12); UpdatePictureBoxClickable(pictureBox_stage12); } if (XMLDataStage.stage_13) { pictureBox_stage13.BackgroundImage = FileTypes.NUT.BitmapFromPortraitNut(PathStage13); UpdatePictureBoxClickable(pictureBox_stage13); } if (XMLDataStage.stage_30) { pictureBox_stage30.BackgroundImage = FileTypes.NUT.BitmapFromPortraitNut(PathStage30); UpdatePictureBoxClickable(pictureBox_stage30); } if (XMLDataStage.stagen_10) { pictureBox_stagen10.BackgroundImage = FileTypes.NUT.BitmapFromPortraitNut(PathStagen10, true); UpdatePictureBoxClickable(pictureBox_stagen10); } break; case ModsList.ModListType.General: XMLDataGeneral = Utils.DeserializeXML <GeneralModXML>(PathKami); if (XMLDataGeneral == null) { return; } XMLDataGeneral.isDirty = false; textBoxDisplayName.Text = XMLDataGeneral.DisplayName; checkBoxWifiSafe.Checked = XMLDataGeneral.WifiSafe; if (XMLDataGeneral.Notes == null) { XMLDataGeneral.Notes = String.Empty; } textBoxNotes.Text = XMLDataGeneral.Notes.Replace("\n", "\r\n"); groupBoxPortaits.Visible = false; groupBoxStageData.Visible = false; this.Height -= groupBoxPortaits.Height + groupBoxStageData.Height; break; } IsInitialized = true; }