diff --git a/AquaMai/AquaMai.csproj b/AquaMai/AquaMai.csproj index 2890dfb4..b9bc0103 100644 --- a/AquaMai/AquaMai.csproj +++ b/AquaMai/AquaMai.csproj @@ -278,6 +278,7 @@ + diff --git a/AquaMai/AquaMai.toml b/AquaMai/AquaMai.toml index 96c21b33..36cdbaec 100644 --- a/AquaMai/AquaMai.toml +++ b/AquaMai/AquaMai.toml @@ -26,6 +26,9 @@ LoadAssetBundleWithoutManifest=true SkipEventInfo=true # Random BGM, put Mai2Cue.{acb,awb} of old version of the game in `LocalAssets\Mai2Cue` and rename them RandomBgm=false +# Execute some command on game idle or on game start +ExecOnIdle="" +ExecOnEntry="" [Performance] # Disable some useless delays to speed up the game boot process diff --git a/AquaMai/Config.cs b/AquaMai/Config.cs index c4348be0..3290300e 100644 --- a/AquaMai/Config.cs +++ b/AquaMai/Config.cs @@ -24,6 +24,8 @@ namespace AquaMai public bool QuickSkip { get; set; } public bool RandomBgm { get; set; } public string CustomVersionString { get; set; } + public string ExecOnIdle { get; set; } + public string ExecOnEntry { get; set; } } public class PerformanceConfig diff --git a/AquaMai/Main.cs b/AquaMai/Main.cs index 59094e2d..eaead5bb 100644 --- a/AquaMai/Main.cs +++ b/AquaMai/Main.cs @@ -80,6 +80,7 @@ namespace AquaMai Patch(typeof(FixCharaCrash)); Patch(typeof(CustomVersionString)); Patch(typeof(DisableReboot)); + Patch(typeof(RunCommandOnEvents)); MelonLogger.Msg("Loaded!"); } diff --git a/AquaMai/UX/RunCommandOnEvents.cs b/AquaMai/UX/RunCommandOnEvents.cs new file mode 100644 index 00000000..4d3462cd --- /dev/null +++ b/AquaMai/UX/RunCommandOnEvents.cs @@ -0,0 +1,43 @@ +using System; +using System.Diagnostics; +using HarmonyLib; +using MelonLoader; +using Process; + +namespace AquaMai.UX +{ + public class RunCommandOnEvents + { + [HarmonyPrefix] + [HarmonyPatch(typeof(AdvertiseProcess), "OnStart")] + public static void AdvertiseProcessPreStart() + { + if (!string.IsNullOrWhiteSpace(AquaMai.AppConfig.UX.ExecOnIdle)) + { + Exec(AquaMai.AppConfig.UX.ExecOnIdle); + } + } + + [HarmonyPrefix] + [HarmonyPatch(typeof(EntryProcess), "OnStart")] + public static void EntryProcessPreStart() + { + if (!string.IsNullOrWhiteSpace(AquaMai.AppConfig.UX.ExecOnEntry)) + { + Exec(AquaMai.AppConfig.UX.ExecOnEntry); + } + } + + private static void Exec(string command) + { + var process = new System.Diagnostics.Process(); + process.StartInfo.FileName = "cmd.exe"; + process.StartInfo.Arguments = "/c " + command; + process.StartInfo.UseShellExecute = true; + process.StartInfo.WindowStyle = ProcessWindowStyle.Hidden; + process.StartInfo.WorkingDirectory = Environment.CurrentDirectory; + + process.Start(); + } + } +} \ No newline at end of file