void UpdateProjectFile(SAModel.SAEditorCommon.UI.ProgressDialog progress) { bool needsUpdate = false; if (splitEntries.Count > 0 || splitMDLEntries.Count > 0) { Templates.ProjectTemplate projFile = ProjectFunctions.openProjectFileString(Path.GetFullPath(SAToolsHub.projXML)); Templates.ProjectInfo projInfo = projFile.GameInfo; List <Templates.SplitEntry> projEntries = projFile.SplitEntries; List <Templates.SplitEntryMDL> projMdlEntries = projFile.SplitMDLEntries; foreach (Templates.SplitEntry entry in splitEntries) { if (!projEntries.Exists(x => x.IniFile == entry.IniFile)) { projEntries.Add(entry); needsUpdate = true; } } if (projMdlEntries.Count > 0) { foreach (Templates.SplitEntryMDL entry in splitMDLEntries) { if (!projMdlEntries.Exists(x => x.ModelFile == entry.ModelFile)) { projMdlEntries.Add(entry); needsUpdate = true; } } } if (needsUpdate) { XmlSerializer serializer = new XmlSerializer(typeof(Templates.ProjectTemplate)); XmlWriter writer = XmlWriter.Create(SAToolsHub.projXML, new XmlWriterSettings() { Indent = true }); Templates.ProjectTemplate updProjFile = new Templates.ProjectTemplate(); updProjFile.GameInfo = projInfo; updProjFile.SplitEntries = projEntries; if (splitMDLEntries.Count > 0) { updProjFile.SplitMDLEntries = projMdlEntries; } serializer.Serialize(writer, updProjFile); writer.Close(); } } }
private void openProject(Templates.ProjectTemplate projFile) { string rootFolder; setGame = projFile.GameInfo.GameName; projectDirectory = (projFile.GameInfo.ModSystemFolder); gameDirectory = (projFile.GameInfo.GameSystemFolder); switch (setGame) { case "SADXPC": gameDir = gameDirectory + "\\system\\"; rootFolder = "SADX Game Files"; break; case "SA2PC": gameDir = gameDirectory + "\\resource\\gd_PC\\"; rootFolder = "SA2PC Game Files"; break; default: gameDir = gameDirectory; rootFolder = setGame + " Game Directory"; break; } PopulateTreeView(projectDirectory); PopulateTreeView(gameDir); treeView1.Nodes[1].Text = rootFolder; this.treeView1.NodeMouseClick += new TreeNodeMouseClickEventHandler(this.treeView1_NodeMouseClick); projSplitEntries = projFile.SplitEntries; if (setGame.Contains("SA2")) { projSplitMDLEntries = projFile.SplitMDLEntries; } toggleButtons(setGame); closeProjectToolStripMenuItem.Enabled = true; if (projFile.GameInfo.CanBuild) { buildToolStripMenuItem.Enabled = true; editProjectInfoToolStripMenuItem.Enabled = true; tsBuild.Enabled = true; tsGameRun.Enabled = true; tsEditProj.Enabled = true; } editToolStripMenuItem.Enabled = true; }
private void LoadINI(string filename) { CloseChildWindows(); Templates.ProjectTemplate projtmp = ProjectFunctions.openProjectFileString(filename); if (projtmp.GameInfo.GameName != "SADXPC") { MessageBox.Show(this, "Unsupported project type.", "SADXTweaker2", MessageBoxButtons.OK, MessageBoxIcon.Stop); return; } Program.project = projtmp; Program.IniData = projtmp.SplitEntries.Where(a => a.SourceFile == "sonic.exe").Select(b => IniSerializer.Deserialize <IniData>(Path.Combine(projtmp.GameInfo.ProjectFolder, b.IniFile + "_data.ini"))).ToArray(); windowToolStripMenuItem.Enabled = true; if (Settings.MRUList.Contains(filename)) { recentProjectsToolStripMenuItem.DropDownItems.RemoveAt(Settings.MRUList.IndexOf(filename)); Settings.MRUList.Remove(filename); } Settings.MRUList.Insert(0, filename); recentProjectsToolStripMenuItem.DropDownItems.Insert(0, new ToolStripMenuItem(filename)); }
private void btnSave_Click(object sender, EventArgs e) { Stream projFileStream; Templates.ProjectTemplate projectFile = new Templates.ProjectTemplate(); SaveFileDialog saveFileDialog1 = new SaveFileDialog(); saveFileDialog1.Filter = "Project File (*.sap)|*.sap"; saveFileDialog1.RestoreDirectory = true; if (saveFileDialog1.ShowDialog() == DialogResult.OK) { if ((projFileStream = saveFileDialog1.OpenFile()) != null) { gamePath = GetSystemPath(); XmlSerializer serializer = new XmlSerializer(typeof(Templates.ProjectTemplate)); TextWriter writer = new StreamWriter(projFileStream); Templates.ProjectInfo projInfo = new Templates.ProjectInfo(); switch (game) { case "sadx": projInfo.GameName = "SADXPC"; projInfo.CanBuild = true; projInfo.GameSystemFolder = gamePath; projInfo.ModSystemFolder = projPath; List <Templates.SplitEntry> dxsplitEntries = new List <Templates.SplitEntry>() { new Templates.SplitEntry { SourceFile = (sonic + ".exe"), IniFile = (sonic + "_data.ini"), CmnName = "Executable Data" }, new Templates.SplitEntry { SourceFile = (chrmodels + "_orig.dll"), IniFile = (chrmodels + "_orig_data.ini"), CmnName = "Chrmodels Data" }, new Templates.SplitEntry { SourceFile = (adv00models + ".dll"), IniFile = (adv00models + "_data.ini"), CmnName = "Station Square Data" }, new Templates.SplitEntry { SourceFile = (adv01models + ".dll"), IniFile = (adv01models + "_data.ini"), CmnName = "Egg Carrier (Exterior) Data" }, new Templates.SplitEntry { SourceFile = (adv01cmodels + ".dll"), IniFile = (adv01cmodels + "_data.ini"), CmnName = "Egg Carrier (Interior) Data" }, new Templates.SplitEntry { SourceFile = (adv02models + ".dll"), IniFile = (adv02models + "_data.ini"), CmnName = "Mystic Ruins Data" }, new Templates.SplitEntry { SourceFile = (adv03models + ".dll"), IniFile = (adv03models + "_data.ini"), CmnName = "The Past Data" }, new Templates.SplitEntry { SourceFile = (bosschaos0models + ".dll"), IniFile = (bosschaos0models + "_data.ini"), CmnName = "Boss Chaos 0 Data" }, new Templates.SplitEntry { SourceFile = (chaostggarden02mr_daytime + ".dll"), IniFile = (chaostggarden02mr_daytime + "_data.ini"), CmnName = "MR Garden (Daytime) Data" }, new Templates.SplitEntry { SourceFile = (chaostggarden02mr_evening + ".dll"), IniFile = (chaostggarden02mr_evening + "_data.ini"), CmnName = "MR Garden (Evening) Data" }, new Templates.SplitEntry { SourceFile = (chaostggarden02mr_night + ".dll"), IniFile = (chaostggarden02mr_night + "_data.ini"), CmnName = "MR Garden (Night) Data" }, }; projectFile.GameInfo = projInfo; projectFile.SplitEntries = dxsplitEntries; break; case "sa2": projInfo.GameName = "SA2PC"; projInfo.CanBuild = true; projInfo.GameSystemFolder = gamePath; projInfo.ModSystemFolder = projPath; List <Templates.SplitEntry> sa2splitEntries = new List <Templates.SplitEntry>() { new Templates.SplitEntry { SourceFile = (sonic2app + ".exe"), IniFile = (sonic2app + "_data.ini"), CmnName = "Executable Data" }, new Templates.SplitEntry { SourceFile = (data_dll + "_orig.dll"), IniFile = (data_dll + "_orig_data.ini"), CmnName = "Data DLL Data" }, }; projectFile.GameInfo = projInfo; projectFile.SplitEntries = sa2splitEntries; projectFile.SplitMDLEntries = splitMdlEntries; break; } serializer.Serialize(writer, projectFile); projFileStream.Close(); } } DialogResult xmlCreated = MessageBox.Show(("Project XML Successfully Created!"), "Project XML Created", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); if (xmlCreated == DialogResult.OK) { this.Close(); } }
private void btnCreate_Click(object sender, EventArgs e) { SaveFileDialog saveFileDialog1 = new SaveFileDialog(); saveFileDialog1.Filter = "Project File (*.sap)|*.sap"; saveFileDialog1.RestoreDirectory = true; if (checkBox1.Checked && (txtProjFolder.Text != null)) { saveFileDialog1.InitialDirectory = txtProjFolder.Text; } if (saveFileDialog1.ShowDialog() == DialogResult.OK) { if ((projFileStream = saveFileDialog1.OpenFile()) != null) { XmlSerializer serializer = new XmlSerializer(typeof(Templates.ProjectTemplate)); TextWriter writer = new StreamWriter(projFileStream); if (checkBox1.Checked && (txtProjFolder.Text != null)) { projFolder = txtProjFolder.Text; } else { projFolder = Path.Combine((Path.GetDirectoryName(saveFileDialog1.FileName)), Path.GetFileNameWithoutExtension(saveFileDialog1.FileName)); if (!Directory.Exists(projFolder)) { Directory.CreateDirectory(projFolder); } } projName = saveFileDialog1.FileName; projectFile = new Templates.ProjectTemplate(); Templates.ProjectInfo projInfo = new Templates.ProjectInfo(); projInfo.GameName = gameName; if (gameName == "SADXPC" || gameName == "SA2PC") { projInfo.CanBuild = true; } else { projInfo.CanBuild = false; } projInfo.GameSystemFolder = gamePath; projInfo.ModSystemFolder = projFolder; projectFile.GameInfo = projInfo; projectFile.SplitEntries = splitEntries; if (gameName == "SA2" || gameName == "SA2GC" || gameName == "SA2PC") { projectFile.SplitMDLEntries = splitMdlEntries; } serializer.Serialize(writer, projectFile); projFileStream.Close(); #if !DEBUG backgroundWorker1.RunWorkerAsync(); #endif #if DEBUG backgroundWorker1_DoWork(null, null); BackgroundWorker1_RunWorkerCompleted(null, null); #endif } } }
void openFile(string projFileString) { if (projFileString != null) { Templates.ProjectTemplate projFile = ProjectFunctions.openProjectFileString(projFileString); if (projFile.GameInfo.GameName == "SA2PC") { string projFolder = projFile.GameInfo.ProjectFolder; string gameFolder = ""; if (projFile.GameInfo.GameDataFolder != null) { gameFolder = Path.Combine(ProjectFunctions.GetGamePath(projFile.GameInfo.GameName), projFile.GameInfo.GameDataFolder); } else { gameFolder = Path.Combine(ProjectFunctions.GetGamePath(projFile.GameInfo.GameName), "resource", "gd_PC"); } if (File.Exists(Path.Combine(projFolder, "ADVERTISE_data.ini"))) { IniData ini = IniSerializer.Deserialize <IniData>(Path.Combine(projFolder, "ADVERTISE_data.ini")); filename = Path.Combine(projFolder, ini.Files.First((item) => item.Value.Type == "stageselectlist").Value.Filename); levels = new List <StageSelectLevel>(StageSelectLevelList.Load(filename)); string socFilePath = ""; string prsFilePath = ""; if (projFile.GameInfo.GameName == "SA2PC") { if (File.Exists(Path.Combine(projFolder, "gd_PC", "SOC", "stageMapBG.pak"))) { socFilePath = Path.Combine(projFolder, "gd_PC", "SOC", "stageMapBG.pak"); } else { socFilePath = Path.Combine(gameFolder, "SOC", "stageMapBG.pak"); } if (File.Exists(Path.Combine(projFolder, "gd_PC", "PRS", "stageMap.pak"))) { prsFilePath = Path.Combine(projFolder, "gd_PC", "PRS", "stageMap.pak"); } else { prsFilePath = Path.Combine(gameFolder, "PRS", "stageMap.pak"); } } else { socFilePath = Path.Combine(gameFolder, "stageMapBG.prs"); prsFilePath = Path.Combine(gameFolder, "stageMap.prs"); } PAKFile socpak = new PAKFile(socFilePath); using (MemoryStream str = new MemoryStream(socpak.Entries.Find((a) => a.Name.Equals("stagemap.dds")).Data)) bgtex = LoadDDS(str); if (File.Exists(prsFilePath)) { PAKFile pakf = new PAKFile(prsFilePath); byte[] inf = pakf.Entries.Find((a) => a.Name.Equals("stagemap.inf")).Data; uitexs = new Bitmap[inf.Length / 0x3C]; for (int i = 0; i < uitexs.Length; i++) { using (MemoryStream str = new MemoryStream(pakf.Entries.Find( (a) => a.Name.Equals(Encoding.ASCII.GetString(inf, i * 0x3C, 0x1c).TrimEnd('\0') + ".dds")).Data)) uitexs[i] = LoadDDS(str); } } else { uitexs = TextureArchive.GetTextures(prsFilePath, out bool hasNames).Select((tex) => tex.Image).ToArray(); } saveToolStripMenuItem.Enabled = panel1.Enabled = panel2.Enabled = true; selected = 0; level.SelectedIndex = (int)levels[selected].Level; character.SelectedIndex = (int)levels[selected].Character; column.Value = levels[selected].Column; row.Value = levels[selected].Row; DrawLevel(); } } else { MessageBox.Show("The opened project file is not ", "Incorrect File", MessageBoxButtons.OK); } } Program.sapFile = ""; }
private void btnCreate_Click(object sender, EventArgs e) { if (backgroundWorker1.IsBusy) { return; } SaveFileDialog saveFileDialog1 = new SaveFileDialog(); saveFileDialog1.Filter = "Project File (*.sap)|*.sap"; saveFileDialog1.RestoreDirectory = true; if (checkBoxSaveDifferentFolder.Checked && textBoxProjFolder.Text != "") { saveFileDialog1.InitialDirectory = textBoxProjFolder.Text; } if (saveFileDialog1.ShowDialog() == DialogResult.OK) { if ((projFileStream = saveFileDialog1.OpenFile()) != null) { XmlSerializer serializer = new(typeof(Templates.ProjectTemplate)); XmlWriter xmlWriter = XmlWriter.Create(projFileStream, new XmlWriterSettings() { Indent = true }); if (checkBoxSaveDifferentFolder.Checked && (textBoxProjFolder.Text != null)) { projFolder = textBoxProjFolder.Text; } else { projFolder = Path.Combine((Path.GetDirectoryName(saveFileDialog1.FileName)), Path.GetFileNameWithoutExtension(saveFileDialog1.FileName)); if (!Directory.Exists(projFolder)) { Directory.CreateDirectory(projFolder); } } projName = saveFileDialog1.FileName; projectFile = new Templates.ProjectTemplate(); Templates.ProjectInfo projInfo = new Templates.ProjectInfo(); projInfo.GameName = gameName; projInfo.CheckFile = checkFile; projInfo.GameDataFolder = gameDataFolder; projInfo.ProjectFolder = (checkBoxSaveDifferentFolder.Checked && textBoxProjFolder.Text != "") ? projFolder : Path.GetFileNameWithoutExtension(saveFileDialog1.FileName); projInfo.CanBuild = (gameName == "SADXPC" || gameName == "SA2PC"); projectFile.GameInfo = projInfo; projectFile.SplitEntries = splitEntries; if (splitMdlEntries != null) { projectFile.SplitMDLEntries = splitMdlEntries; } serializer.Serialize(xmlWriter, projectFile); projFileStream.Close(); #if !DEBUG backgroundWorker1.RunWorkerAsync(); #endif #if DEBUG backgroundWorker1_DoWork(null, null); BackgroundWorker1_RunWorkerCompleted(null, null); #endif } } }