From 4be85d4ce2df2202f7bc1e234002c676addac731 Mon Sep 17 00:00:00 2001 From: Miepee Date: Thu, 8 Dec 2022 14:35:02 +0100 Subject: [PATCH] Add Mac support --- AM2RModPacker/ModPacker.Designer.cs | 9 +++++ AM2RModPacker/ModPacker.cs | 61 +++++++++++++++++++++++++++-- AM2RModPackerLib/Core.cs | 28 ++++++++++++- 3 files changed, 92 insertions(+), 6 deletions(-) diff --git a/AM2RModPacker/ModPacker.Designer.cs b/AM2RModPacker/ModPacker.Designer.cs index 035008e..af18089 100644 --- a/AM2RModPacker/ModPacker.Designer.cs +++ b/AM2RModPacker/ModPacker.Designer.cs @@ -49,6 +49,8 @@ public partial class ModPacker : Form miscOptionsPanel.AddRow(apkButton, apkLabel); miscOptionsPanel.AddRow(linuxCheckBox); miscOptionsPanel.AddRow(linuxButton, linuxLabel); + miscOptionsPanel.AddRow(macCheckBox); + miscOptionsPanel.AddRow(macButton, macLabel); var loadZipsPanel = new DynamicLayout() { Spacing = new Size(5, 5) }; loadZipsPanel.AddRow(originalZipButton, null, modZipButton); @@ -86,7 +88,10 @@ public partial class ModPacker : Form customSaveCheckBox.CheckedChanged += CustomSaveCheckBoxChecked_Changed; linuxCheckBox.CheckedChanged += LinuxCheckBox_CheckedChanged; linuxButton.Click += LinuxButton_Click; + macCheckBox.CheckedChanged += macCheckBox_CheckedChanged; + macButton.Click += macButton_Click; customSaveButton.Click += CustomSaveDataButton_Click; + yycCheckBox.CheckedChanged += YYCCheckBox_CheckedChanged; } #region Design Elements @@ -113,6 +118,10 @@ public partial class ModPacker : Form private CheckBox linuxCheckBox = new CheckBox() { Text = "Supports Linux" }; private Button linuxButton = new Button() { Text = "Load modded Linux .zip", Enabled = false }; private Label linuxLabel = new Label() { Text = "Modded Linux game loaded!", Visible = false }; + + private CheckBox macCheckBox = new CheckBox() { Text = "Supports Mac" }; + private Button macButton = new Button() { Text = "Load modded Mac .zip", Enabled = false }; + private Label macLabel = new Label() { Text = "Modded Mac game loaded!", Visible = false }; private Button originalZipButton = new Button() { Text = "Load 1.1" }; private Label originalZipLabel = new Label() { Text = "1.1 loaded!", Visible = false}; diff --git a/AM2RModPacker/ModPacker.cs b/AM2RModPacker/ModPacker.cs index 97db378..205ab39 100644 --- a/AM2RModPacker/ModPacker.cs +++ b/AM2RModPacker/ModPacker.cs @@ -13,8 +13,8 @@ namespace AM2RModPacker; public partial class ModPacker : Form { private static readonly string version = Core.Version; - private bool isOriginalLoaded, isModLoaded, isApkLoaded, isLinuxLoaded; - private string originalPath, modPath, apkPath, linuxPath; + private bool isOriginalLoaded, isModLoaded, isApkLoaded, isLinuxLoaded, isMacLoaded; + private string originalPath, modPath, apkPath, linuxPath, macPath; private string saveFilePath; private readonly ModProfileXML profile; @@ -72,6 +72,17 @@ public partial class ModPacker : Form } customSaveTextBox.Text = saveFilePath; } + + private void YYCCheckBox_CheckedChanged(object sender, EventArgs e) + { + // Don't do anything if it's been disabled + if (!yycCheckBox.Checked.Value) + return; + macCheckBox.Checked = false; + macLabel.Visible = false; + macButton.Enabled = false; + macPath = ""; + } private void ApkCheckBoxCheckedChanged(object sender, EventArgs e) { @@ -100,6 +111,28 @@ public partial class ModPacker : Form linuxLabel.Visible = isLinuxLoaded; UpdateCreateButton(); } + + private void macCheckBox_CheckedChanged(object sender, EventArgs e) + { + if (!yycCheckBox.Checked.Value) + { + macButton.Enabled = macCheckBox.Checked.Value; + UpdateCreateButton(); + } + else if (macCheckBox.Checked.Value) + { + MessageBox.Show("YoYoCompiler isn't supported with Mac!", "Warning", MessageBoxButtons.OK, MessageBoxType.Warning); + macCheckBox.Checked = false; + } + } + + private void macButton_Click(object sender, EventArgs e) + { + // Open window to select modded Mac .zip + (isMacLoaded, macPath) = SelectFile("Please select your custom Mac AM2R .zip", zipFileFilter); + macLabel.Visible = isMacLoaded; + UpdateCreateButton(); + } private void OriginalZipButton_Click(object sender, EventArgs e) { @@ -177,7 +210,20 @@ public partial class ModPacker : Form } } //TODO: mac - + if (macCheckBox.Checked.Value) + { + using (SaveFileDialog saveFile = new SaveFileDialog { Title = "Save Mac mod profile", Filters = { zipFileFilter } }) + { + if (saveFile.ShowDialog(this) == DialogResult.Ok) + output = saveFile.FileName; + else + { + createLabel.Text = "Mod packaging aborted!"; + return; + } + } + Core.CreateModPack(profile, macPath, originalPath, apkPath, output); + } createLabel.Text = "Mod package(s) created!"; } #endregion @@ -198,7 +244,13 @@ public partial class ModPacker : Form profile.SaveLocation = "%localappdata%/AM2R"; if (operatingSystem == ProfileOperatingSystems.Linux) profile.SaveLocation = profile.SaveLocation.Replace("%localappdata%", "~/.config"); - //todo: mac + else if (operatingSystem == ProfileOperatingSystems.Mac) + { + if (profile.SaveLocation.Contains("%localappdata%/AM2R")) + profile.SaveLocation = profile.SaveLocation.Replace("%localappdata%/AM2R", "~/Library/Application Support/com.yoyogames.am2r"); + else + profile.SaveLocation = "~/Library/Application Support/com.yoyogames." + new DirectoryInfo(profile.SaveLocation).Name.ToLower(); + } } private void AbortPatch() @@ -232,6 +284,7 @@ public partial class ModPacker : Form isModLoaded && // Modded zip must be provided (!apkCheckBox.Checked.Value || isApkLoaded) && // either APK is disabled OR APK is provided (!linuxCheckBox.Checked.Value || isLinuxLoaded) && // either Linux is disabled OR linux is provided + (!macCheckBox.Checked.Value || isMacLoaded) && // either Mac is disabled OR mac is provided (!customSaveCheckBox.Checked.Value || customSaveTextBox.Text != "")) // either custom saves are disabled OR custom save is provided createButton.Enabled = true; else diff --git a/AM2RModPackerLib/Core.cs b/AM2RModPackerLib/Core.cs index 1bc15bf..a6cb583 100644 --- a/AM2RModPackerLib/Core.cs +++ b/AM2RModPackerLib/Core.cs @@ -17,7 +17,7 @@ public static class Core { public static readonly string Version = "2.0.3"; private const string originalMD5 = "f2b84fe5ba64cb64e284be1066ca08ee"; - private static readonly string[] DATAFILES_BLACKLIST = { "data.win", "AM2R.exe", "D3DX9_43.dll", "game.unx" }; + private static readonly string[] DATAFILES_BLACKLIST = { "data.win", "AM2R.exe", "D3DX9_43.dll", "game.unx", "game.ios" }; // todo: dont do this, cwd is unreliable private static readonly string localPath = Directory.GetCurrentDirectory(); @@ -135,7 +135,29 @@ public static class Core CreatePatch(tempOriginalPath + "/AM2R.exe", tempModPath + "/" + runnerName, tempProfilePath + "/AM2R.xdelta"); } // todo: mac + else if (profile.OperatingSystem == "Mac") + { + if (!File.Exists(tempModPath + "/AM2R.app/Contents/MacOS/Mac_Runner")) + { + /*var result = MessageBox.Show("Modded Mac game not found, make sure it's not placed in any subfolders.\nCreated profile will likely not be installable, are you sure you want to continue?", "WARNING", MessageBoxButtons.YesNo, MessageBoxIcon.Warning); + if (result != DialogResult.Yes) + AbortPatch();*/ + } + if (File.Exists(tempModPath + "profile.xml")) + { + /*var result = MessageBox.Show("profile.xml found. This file is used by the AM2RLauncher to determine profile stats and its inclusion may make the profile uninstallable. Are you sure you want to continue?", "WARNING", MessageBoxButtons.YesNo, MessageBoxIcon.Warning); + if (result != DialogResult.Yes) + AbortPatch();*/ + } + + CreatePatch(tempOriginalPath + "/data.win", tempModPath + "/AM2R.app/Contents/Resources/game.ios", tempProfilePath + "/game.xdelta"); + CreatePatch(tempOriginalPath + "/AM2R.exe", tempModPath + "/AM2R.app/Contents/MacOS/Mac_Runner", tempProfilePath + "/AM2R.xdelta"); + + // Copy plist over for custom title name + File.Copy(tempModPath + "/AM2R.app/Contents/Info.plist", tempProfilePath + "/Info.plist"); + } + // Create game.droid patch and wrapper if Android is supported if (profile.Android) { @@ -225,6 +247,8 @@ public static class Core var dirInfo = new DirectoryInfo(tempModPath); if (profile.OperatingSystem == "Linux") dirInfo = new DirectoryInfo(tempModPath + "/assets"); + else if (profile.OperatingSystem == "Mac") + dirInfo = new DirectoryInfo(tempModPath + "/AM2R.app/Contents/Resources"); Directory.CreateDirectory(tempProfilePath + "/files_to_copy"); @@ -238,7 +262,7 @@ public static class Core // Get list of 1.1's music files string[] musFiles = Directory.GetFiles(tempOriginalPath, "*.ogg").Select(file => Path.GetFileName(file)).ToArray(); - if (profile.OperatingSystem == "Linux") + if (profile.OperatingSystem == "Linux" || profile.OperatingSystem == "Mac") musFiles = Directory.GetFiles(tempOriginalPath, "*.ogg").Select(file => Path.GetFileName(file).ToLower()).ToArray();