diff --git a/AM2RPortHelper.sln b/AM2RPortHelper.sln index fcd513f..0eb9db2 100644 --- a/AM2RPortHelper.sln +++ b/AM2RPortHelper.sln @@ -15,6 +15,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AM2RPortHelperGUI.Mac", "AM EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AM2RPortHelperGUI.Wpf", "AM2RPortHelperGUI\AM2RPortHelperGUI.Wpf\AM2RPortHelperGUI.Wpf.csproj", "{4C4043B0-38AB-479A-A4B3-D3F7F39092F0}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "UndertaleModLib", "UndertaleModTool\UndertaleModLib\UndertaleModLib.csproj", "{F402FD71-4FF4-4E2E-ADCD-A45FBDAFD713}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -49,6 +51,10 @@ Global {3907CAFD-896C-47F1-B284-C75BC5EA4B3B}.Debug|Any CPU.Build.0 = Debug|Any CPU {3907CAFD-896C-47F1-B284-C75BC5EA4B3B}.Release|Any CPU.ActiveCfg = Release|Any CPU {3907CAFD-896C-47F1-B284-C75BC5EA4B3B}.Release|Any CPU.Build.0 = Release|Any CPU + {F402FD71-4FF4-4E2E-ADCD-A45FBDAFD713}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {F402FD71-4FF4-4E2E-ADCD-A45FBDAFD713}.Debug|Any CPU.Build.0 = Debug|Any CPU + {F402FD71-4FF4-4E2E-ADCD-A45FBDAFD713}.Release|Any CPU.ActiveCfg = Release|Any CPU + {F402FD71-4FF4-4E2E-ADCD-A45FBDAFD713}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE @@ -56,4 +62,4 @@ Global GlobalSection(ExtensibilityGlobals) = postSolution SolutionGuid = {BDB99405-8678-4A39-A8A6-5CD38EC1EADA} EndGlobalSection -EndGlobal \ No newline at end of file +EndGlobal diff --git a/AM2RPortHelperLib/AM2RPortHelperLib.csproj b/AM2RPortHelperLib/AM2RPortHelperLib.csproj index 08de1e4..c2e52ac 100644 --- a/AM2RPortHelperLib/AM2RPortHelperLib.csproj +++ b/AM2RPortHelperLib/AM2RPortHelperLib.csproj @@ -1,7 +1,7 @@ - netstandard2.0 + netstandard2.1 enable 10 1.8.0 @@ -23,4 +23,8 @@ + + + + diff --git a/AM2RPortHelperLib/RawMods.cs b/AM2RPortHelperLib/RawMods.cs index f8031b3..15d0fa9 100644 --- a/AM2RPortHelperLib/RawMods.cs +++ b/AM2RPortHelperLib/RawMods.cs @@ -2,6 +2,7 @@ using System.Diagnostics; using System.IO.Compression; using System.Runtime.InteropServices; using System.Text.RegularExpressions; +using UndertaleModLib; using static AM2RPortHelperLib.Core; namespace AM2RPortHelperLib; @@ -11,6 +12,7 @@ public abstract class RawMods : IMods // For completionist sake, it should be possible to also port raw APKs to win/lin/mac // But until some person actually shows up that needs this feature, I'm too lazy to implement it + // TODO: documentation public static ModOS GetModOSOfRawZip(string inputRawZipPath) { @@ -95,8 +97,7 @@ public abstract class RawMods : IMods Directory.Delete(assetsDir, true); } - // TODO: try to figure out if its possible to extract the name from the data.win file and then just offer a "use custom save directory" option that decides whether to use it or not. - public static void PortToAndroid(string inputRawZipPath, string outputRawApkPath, string modName = null, bool usesInternet = false, OutputHandlerDelegate outputDelegate = null) + public static void PortToAndroid(string inputRawZipPath, string outputRawApkPath, bool useCustomSaveDirectory = false, bool usesInternet = false, OutputHandlerDelegate outputDelegate = null) { ModOS currentOS = GetModOSOfRawZip(inputRawZipPath); SendOutput("Zip Recognized as " + currentOS); @@ -185,17 +186,26 @@ public abstract class RawMods : IMods // TODO: Hermite probably best as image upscaler, but we'll see // On certain occasions, we need to modify the manifest file. - if (modName != null || usesInternet) + if (useCustomSaveDirectory || usesInternet) { string manifestFile = File.ReadAllText(apkDir + "/AndroidManifest.xml"); // If a custom name was given, replace it everywhere. - if (modName != null) + if (useCustomSaveDirectory) { + string modName; + FileInfo datafile = new FileInfo(extractDirectory + "/game.ios"); + using (FileStream fs = datafile.OpenRead()) + { + UndertaleData gmData = UndertaleIO.Read(fs, SendOutput, SendOutput); + modName = gmData.GeneralInfo.DisplayName.Content; + } + modName = modName.Replace(" ", "").Replace(":", ""); + // rules for name: A-Z, a-z, digits, underscore and needs to start with letters Regex nameReg = new Regex(@"^[a-zA-Z][a-zA-Z0-9_]*$"); if (!nameReg.Match(modName).Success) - throw new InvalidDataException("The display name " + modName + " is invalid! The name has to start with letters (a-z), and can only contain letters, digits and underscore!"); + throw new InvalidDataException("The display name " + modName + " is invalid! The name has to start with letters (a-z), and can only contain letters, digits, space, colon and underscore!"); // first in the manifest manifestFile = manifestFile.Replace("com.companyname.AM2RWrapper", $"com.companyname.{modName}"); @@ -268,8 +278,7 @@ public abstract class RawMods : IMods Directory.Delete(extractDirectory, true); } - //TODO: try to figure out if its possible to extract the name from the data.win file? They do have a displayname option last time I checked... - public static void PortToMac(string inputRawZipPath, string outputRawZipPath, string modName, OutputHandlerDelegate outputDelegate = null) + public static void PortToMac(string inputRawZipPath, string outputRawZipPath, OutputHandlerDelegate outputDelegate = null) { ModOS currentOS = GetModOSOfRawZip(inputRawZipPath); SendOutput("Zip Recognized as " + currentOS); @@ -334,6 +343,7 @@ public abstract class RawMods : IMods string bin; string args; + // TODO: replace this via built-in lib if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) { bin = "\"" + utilDir + "/UTMTCli/UndertaleModCli.exe\""; @@ -364,7 +374,15 @@ public abstract class RawMods : IMods HelperMethods.DirectoryCopy(extractDirectory, assetsDir); // Edit config and plist to change display name - //TODO: handle error on special characters + string modName; + FileInfo datafile = new FileInfo(extractDirectory + "/game.ios"); + using (FileStream fs = datafile.OpenRead()) + { + UndertaleData gmData = UndertaleIO.Read(fs, SendOutput, SendOutput); + modName = gmData.GeneralInfo.DisplayName.Content; + } + //TODO: handle error on special characters, but need to know which characters are invalid in the first place + //if (modName.Contains()) SendOutput("Editing Runner references to AM2R..."); string textFile = File.ReadAllText(assetsDir + "/yoyorunner.config"); textFile = textFile.Replace("YoYo Runner", modName); diff --git a/UndertaleModTool b/UndertaleModTool index ad5a84b..7970426 160000 --- a/UndertaleModTool +++ b/UndertaleModTool @@ -1 +1 @@ -Subproject commit ad5a84bdfbf3a58079c3e2a60ce487b3438a0bce +Subproject commit 79704260e15ab8c7ffdbc7effb3cbe366f480a00