-
Notifications
You must be signed in to change notification settings - Fork 0
/
Main.cs
56 lines (48 loc) · 1.67 KB
/
Main.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
using Il2CppAssets.Scripts.Database;
using MelonLoader;
using UnityEngine;
namespace QuickRestart
{
public class Main : MelonMod
{
private MelonPreferences_Category _category;
private MelonPreferences_Entry _restartKeybind;
private MelonPreferences_Entry _exitKeybind;
private bool _isBattleScene;
/// <summary>
/// Initialize the MelonLoader preferences for keybinds.
/// </summary>
public override void OnInitializeMelon()
{
_category = MelonPreferences.CreateCategory("QuickRestart");
_restartKeybind = _category.CreateEntry("Restart Key", KeyCode.Backspace);
_exitKeybind = _category.CreateEntry("Exit Song Key", KeyCode.Delete);
MelonPreferences.Save();
base.OnInitializeMelon();
}
/// <summary>
/// Check for keybinds being pressed.
/// </summary>
public override void OnUpdate()
{
if (!_isBattleScene) return;
if (Input.GetKeyDown((KeyCode)_restartKeybind.BoxedValue))
{
BattleHelper.GameRestart();
}
else if (Input.GetKeyDown((KeyCode)_exitKeybind.BoxedValue))
{
BattleHelper.GameFinish();
}
base.OnUpdate();
}
/// <summary>
/// Ensure the battle scene is the active one, otherwise do not allow restarting.
/// </summary>
public override void OnSceneWasLoaded(int buildIndex, string sceneName)
{
_isBattleScene = sceneName == "GameMain";
base.OnSceneWasLoaded(buildIndex, sceneName);
}
}
}