Skip to content

Commit

Permalink
Merge pull request #12 from ManlyMarco/master
Browse files Browse the repository at this point in the history
  • Loading branch information
Keelhauled committed Sep 14, 2020
2 parents f0c7f97 + 001bd03 commit 8eedb30
Show file tree
Hide file tree
Showing 6 changed files with 95 additions and 109 deletions.
3 changes: 2 additions & 1 deletion src/TitleShortcuts.AISyoujyo/TitleShortcuts.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,12 @@ public class TitleShortcuts : TitleShortcutsCore

private bool checkInput = false;
private bool cancelAuto = false;
private bool firstLaunch = true;
private TitleScene titleScene;

protected override string[] PossibleArguments => new[] { "-femalemaker", "-malemaker" };

private void Awake()
protected override void Awake()
{
AutoStart = Config.Bind(SECTION_GENERAL, "Automatic start mode", AutoStartOption.Disabled, new ConfigDescription(DESCRIPTION_AUTOSTART));
StartFemaleMaker = Config.Bind(SECTION_HOTKEYS, "Open female maker", new KeyboardShortcut(KeyCode.F));
Expand Down
18 changes: 13 additions & 5 deletions src/TitleShortcuts.Core/TitleShortcutsCore.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using BepInEx;
using BepInEx.Logging;
using System;
using System.Linq;

Expand All @@ -18,20 +19,27 @@ public abstract class TitleShortcutsCore : BaseUnityPlugin

protected virtual string[] PossibleArguments { get; }

protected bool firstLaunch = true;
protected static TitleShortcutsCore Plugin;
protected static new ManualLogSource Logger;

private string startupArgument;
protected string StartupArgument
protected virtual void Awake()
{
Plugin = this;
Logger = base.Logger;
}

private static string startupArgument;
protected static string StartupArgument
{
get
{
if(startupArgument == null)
{
if(PossibleArguments != null)
if(Plugin.PossibleArguments != null)
{
var args = Environment.GetCommandLineArgs();
if(args != null && args.Length > 0)
startupArgument = args.Select(x => x.Trim().ToLower()).FirstOrDefault(x => PossibleArguments.Contains(x));
startupArgument = args.Select(x => x.Trim().ToLower()).FirstOrDefault(x => Plugin.PossibleArguments.Contains(x));
}

if(startupArgument == null)
Expand Down
3 changes: 2 additions & 1 deletion src/TitleShortcuts.HoneySelect/TitleShortcuts.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,12 @@ public class TitleShortcuts : TitleShortcutsCore

private bool checkInput = false;
private bool cancelAuto = false;
private bool firstLaunch = true;
private TitleScene titleScene;

protected override string[] PossibleArguments => new[] { "-femalemaker", "-malemaker" };

private void Awake()
protected override void Awake()
{
AutoStart = Config.Bind(SECTION_GENERAL, "Automatic start mode", AutoStartOption.Disabled, new ConfigDescription(DESCRIPTION_AUTOSTART));
StartFemaleMaker = Config.Bind(SECTION_HOTKEYS, "Female maker", new KeyboardShortcut(KeyCode.F));
Expand Down
8 changes: 8 additions & 0 deletions src/TitleShortcuts.Koikatu/TitleShortcuts.Koikatu.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@
</PropertyGroup>
<Import Project="..\BuildSettings.Koikatu.props" />
<ItemGroup>
<Reference Include="0Harmony, Version=2.0.0.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\..\packages\IllusionLibs.BepInEx.Harmony.2.0.6\lib\net35\0Harmony.dll</HintPath>
<Private>False</Private>
</Reference>
<Reference Include="Assembly-CSharp, Version=0.0.0.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\..\packages\IllusionLibs.Koikatu.Assembly-CSharp.2019.4.27\lib\net35\Assembly-CSharp.dll</HintPath>
<Private>False</Private>
Expand All @@ -23,6 +27,10 @@
<HintPath>..\..\packages\IllusionLibs.BepInEx.5.0.1.1\lib\net35\BepInEx.dll</HintPath>
<Private>False</Private>
</Reference>
<Reference Include="BepInEx.Harmony, Version=2.0.0.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\..\packages\IllusionLibs.BepInEx.Harmony.2.0.6\lib\net35\BepInEx.Harmony.dll</HintPath>
<Private>False</Private>
</Reference>
<Reference Include="System" />
<Reference Include="UnityEngine, Version=0.0.0.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\..\packages\IllusionLibs.Koikatu.UnityEngine.5.6.2\lib\net35\UnityEngine.dll</HintPath>
Expand Down
171 changes: 69 additions & 102 deletions src/TitleShortcuts.Koikatu/TitleShortcuts.cs
Original file line number Diff line number Diff line change
@@ -1,157 +1,124 @@
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using HarmonyLib;
using System.Collections;
using System.ComponentModel;
using UnityEngine;
using UnityEngine.Events;
using UnityEngine.SceneManagement;

namespace KeelPlugins
{
[BepInProcess(KoikatuConstants.MainGameProcessName)]
[BepInProcess(KoikatuConstants.MainGameProcessNameSteam)]
[BepInProcess(KoikatuConstants.VRProcessName)]
[BepInProcess(KoikatuConstants.VRProcessNameSteam)]
[BepInPlugin(GUID, PluginName, Version)]
public class TitleShortcuts : TitleShortcutsCore
{
private ConfigEntry<AutoStartOption> AutoStart { get; set; }
private ConfigEntry<KeyboardShortcut> StartFemaleMaker { get; set; }
private ConfigEntry<KeyboardShortcut> StartMaleMaker { get; set; }
private ConfigEntry<KeyboardShortcut> StartUploader { get; set; }
private ConfigEntry<KeyboardShortcut> StartDownloader { get; set; }
private ConfigEntry<KeyboardShortcut> StartFreeH { get; set; }
private ConfigEntry<KeyboardShortcut> StartLiveShow { get; set; }
private static ConfigEntry<KeyboardShortcut> StartFemaleMaker { get; set; }
private static ConfigEntry<KeyboardShortcut> StartMaleMaker { get; set; }
private static ConfigEntry<KeyboardShortcut> StartUploader { get; set; }
private static ConfigEntry<KeyboardShortcut> StartDownloader { get; set; }
private static ConfigEntry<KeyboardShortcut> StartFreeH { get; set; }
private static ConfigEntry<KeyboardShortcut> StartLiveShow { get; set; }

private bool checkInput = false;
private bool cancelAuto = false;
private TitleScene titleScene;
private const string ArgumentFemaleMaker = "-femalemaker";
private const string ArgumentMaleMaker = "-malemaker";
private const string ArgumentFreeH= "-freeh";
private const string ArgumentLive = "-live";

protected override string[] PossibleArguments => new[] { "-femalemaker", "-malemaker", "-freeh", "-live" };
private static bool autostartFinished = false;
private static TitleScene titleScene;

private void Awake()
protected override string[] PossibleArguments => new[] { ArgumentFemaleMaker, ArgumentMaleMaker, ArgumentFreeH, ArgumentLive };

protected override void Awake()
{
AutoStart = Config.Bind(SECTION_GENERAL, "Automatic start mode", AutoStartOption.Disabled, new ConfigDescription(DESCRIPTION_AUTOSTART));
base.Awake();

StartFemaleMaker = Config.Bind(SECTION_HOTKEYS, "Open female maker", new KeyboardShortcut(KeyCode.F));
StartMaleMaker = Config.Bind(SECTION_HOTKEYS, "Open male maker", new KeyboardShortcut(KeyCode.M));
StartUploader = Config.Bind(SECTION_HOTKEYS, "Open uploader", new KeyboardShortcut(KeyCode.U));
StartDownloader = Config.Bind(SECTION_HOTKEYS, "Open downloader", new KeyboardShortcut(KeyCode.D));
StartFreeH = Config.Bind(SECTION_HOTKEYS, "Start free H", new KeyboardShortcut(KeyCode.H));
StartLiveShow = Config.Bind(SECTION_HOTKEYS, "Start live show", new KeyboardShortcut(KeyCode.L));

SceneManager.sceneLoaded += StartInput;
Harmony.CreateAndPatchAll(GetType());
}

private void StartInput(Scene scene, LoadSceneMode mode)
[HarmonyPrefix]
[HarmonyPatch(typeof(TitleScene), "Start")]
private static void TitleSceneStart(TitleScene __instance)
{
var title = FindObjectOfType<TitleScene>();
titleScene = __instance;
Plugin.StartCoroutine(TitleSceneInput());
}

if(title)
[HarmonyPrefix]
[HarmonyPatch(typeof(Manager.Scene.Data), nameof(Manager.Scene.Data.isFade), MethodType.Setter)]
private static bool DisableFadeout()
{
return autostartFinished;
}

[HarmonyPrefix]
[HarmonyPatch(typeof(LogoScene), "Start")]
private static bool DisableIntro(ref IEnumerator __result)
{
IEnumerator LoadTitle()
{
if(!checkInput)
Singleton<Manager.Scene>.Instance.LoadReserve(new Manager.Scene.Data
{
titleScene = title;
checkInput = true;
StartCoroutine(InputCheck());
}
}
else
{
checkInput = false;
levelName = "Title",
isFade = false
}, false);
yield break;
}
__result = LoadTitle();
return false;
}

private IEnumerator InputCheck()
private static IEnumerator TitleSceneInput()
{
while(checkInput)
while(titleScene != null)
{
if(!cancelAuto && AutoStart.Value != AutoStartOption.Disabled && (Input.GetKey(KeyCode.Escape) || Input.GetKey(KeyCode.F1)))
if(StartFemaleMaker.Value.IsDown() || !autostartFinished && StartupArgument == ArgumentFemaleMaker)
{
Logger.Log(LogLevel.Message, "Automatic start cancelled");
cancelAuto = true;
StartMode(titleScene.OnCustomFemale, "Starting female maker");
}

if(!Manager.Scene.Instance.IsNowLoadingFade)
else if(StartMaleMaker.Value.IsDown() || !autostartFinished && StartupArgument == ArgumentMaleMaker)
{
if(StartFemaleMaker.Value.IsPressed() || firstLaunch && StartupArgument == "-femalemaker")
{
StartMode(titleScene.OnCustomFemale, "Starting female maker");
}
else if(StartMaleMaker.Value.IsPressed() || firstLaunch && StartupArgument == "-malemaker")
{
StartMode(titleScene.OnCustomMale, "Starting male maker");
}

else if(StartUploader.Value.IsPressed())
{
StartMode(titleScene.OnUploader, "Starting uploader");
}
else if(StartDownloader.Value.IsPressed())
{
StartMode(titleScene.OnDownloader, "Starting downloader");
}

else if(StartFreeH.Value.IsPressed() || firstLaunch && StartupArgument == "-freeh")
{
StartMode(titleScene.OnOtherFreeH, "Starting free H");
}
else if(StartLiveShow.Value.IsPressed() || firstLaunch && StartupArgument == "-live")
{
StartMode(titleScene.OnOtherIdolLive, "Starting live show");
}

else if(!cancelAuto && AutoStart.Value != AutoStartOption.Disabled)
{
switch(AutoStart.Value)
{
case AutoStartOption.FemaleMaker:
StartMode(titleScene.OnCustomFemale, "Automatically starting female maker");
break;

case AutoStartOption.MaleMaker:
StartMode(titleScene.OnCustomMale, "Automatically starting male maker");
break;

case AutoStartOption.FreeH:
StartMode(titleScene.OnOtherFreeH, "Automatically starting free H");
break;
StartMode(titleScene.OnCustomMale, "Starting male maker");
}

case AutoStartOption.LiveStage:
StartMode(titleScene.OnOtherIdolLive, "Automatically starting live show");
break;
}
}
else if(StartUploader.Value.IsDown())
{
StartMode(titleScene.OnUploader, "Starting uploader");
}
else if(StartDownloader.Value.IsDown())
{
StartMode(titleScene.OnDownloader, "Starting downloader");
}

cancelAuto = true;
else if(StartFreeH.Value.IsDown() || !autostartFinished && StartupArgument == ArgumentFreeH)
{
StartMode(titleScene.OnOtherFreeH, "Starting free H");
}
else if(StartLiveShow.Value.IsDown() || !autostartFinished && StartupArgument == ArgumentLive)
{
StartMode(titleScene.OnOtherIdolLive, "Starting live show");
}

yield return null;
}
}

private void StartMode(UnityAction action, string msg)
private static void StartMode(UnityAction action, string msg)
{
firstLaunch = false;
if(!FindObjectOfType<ConfigScene>())
{
Logger.LogMessage(msg);
checkInput = false;
titleScene = null;
action();
autostartFinished = true;
}
}

private enum AutoStartOption
{
Disabled,
[Description("Female maker")]
FemaleMaker,
[Description("Male maker")]
MaleMaker,
[Description("Free H")]
FreeH,
[Description("Live stage")]
LiveStage
}
}
}
1 change: 1 addition & 0 deletions src/TitleShortcuts.Koikatu/packages.config
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="IllusionLibs.BepInEx" version="5.0.1.1" targetFramework="net35" developmentDependency="true" />
<package id="IllusionLibs.BepInEx.Harmony" version="2.0.6" targetFramework="net35" developmentDependency="true" />
<package id="IllusionLibs.Koikatu.Assembly-CSharp" version="2019.4.27" targetFramework="net35" developmentDependency="true" />
<package id="IllusionLibs.Koikatu.UnityEngine" version="5.6.2" targetFramework="net35" developmentDependency="true" />
<package id="IllusionLibs.Koikatu.UnityEngine.UI" version="5.6.2" targetFramework="net35" developmentDependency="true" />
Expand Down

0 comments on commit 8eedb30

Please sign in to comment.