[+] Execute some command on game idle or on game start

pull/40/head
Clansty 2024-05-20 22:31:27 +08:00
parent 86164ba518
commit 21309cddf0
5 changed files with 50 additions and 0 deletions

View File

@ -278,6 +278,7 @@
<Compile Include="UX\LoadAssetBundleWithoutManifest.cs" />
<Compile Include="UX\QuickSkip.cs" />
<Compile Include="UX\RandomBgm.cs" />
<Compile Include="UX\RunCommandOnEvents.cs" />
<Compile Include="UX\SinglePlayer.cs" />
<Compile Include="UX\SkipEventInfo.cs" />
<Compile Include="UX\SkipWarningScreen.cs" />

View File

@ -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

View File

@ -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

View File

@ -80,6 +80,7 @@ namespace AquaMai
Patch(typeof(FixCharaCrash));
Patch(typeof(CustomVersionString));
Patch(typeof(DisableReboot));
Patch(typeof(RunCommandOnEvents));
MelonLogger.Msg("Loaded!");
}

View File

@ -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();
}
}
}