using System;
using System.Collections;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using Booth;
using On.RoR2.UI;
using QuickRestart;
using R2API.Utils;
using RoR2;
using RoR2.UI;
using TMPro;
using UnityEngine;
using UnityEngine.Events;
using UnityEngine.Networking;
using UnityEngine.UI;
[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("QuickRestart")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("QuickRestart")]
[assembly: AssemblyTitle("QuickRestart")]
[assembly: AssemblyVersion("1.0.0.0")]
namespace Booth
{
internal static class Log
{
private static ManualLogSource _logSource;
internal static void Init(ManualLogSource logSource)
{
_logSource = logSource;
}
internal static void Debug(object data)
{
_logSource.LogDebug(data);
}
internal static void Error(object data)
{
_logSource.LogError(data);
}
internal static void Fatal(object data)
{
_logSource.LogFatal(data);
}
internal static void Info(object data)
{
_logSource.LogInfo(data);
}
internal static void Message(object data)
{
_logSource.LogMessage(data);
}
internal static void Warning(object data)
{
_logSource.LogWarning(data);
}
}
[NetworkCompatibility(/*Could not decode attribute arguments.*/)]
[BepInDependency(/*Could not decode attribute arguments.*/)]
[BepInPlugin("com.IkalaGaming.QuickRestart", "QuickRestart", "1.5.3")]
public class QuickRestart : BaseUnityPlugin
{
private static KeyCode ResetKeyCode = (KeyCode)116;
private float TimeSpentHoldingKey = 0f;
private float ResetKeyThreshold = 1f;
private bool ResetAlready = false;
private bool IsInChatBox = false;
public static ConfigEntry<string> ConfigRestartButtonPosition { get; set; }
public static ConfigEntry<string> ConfigCharacterButtonPosition { get; set; }
public static ConfigEntry<bool> ConfigResetKeyEnabled { get; set; }
public static ConfigEntry<string> ConfigResetKeyBind { get; set; }
public static ConfigEntry<float> ConfigResetKeyHoldTime { get; set; }
public static ConfigEntry<bool> ConfigConfirmationDialog { get; set; }
public void SetupConfig()
{
//IL_00dd: Unknown result type (might be due to invalid IL or missing references)
//IL_00cc: Unknown result type (might be due to invalid IL or missing references)
//IL_00d1: Unknown result type (might be due to invalid IL or missing references)
ConfigRestartButtonPosition = ((BaseUnityPlugin)this).Config.Bind<string>("Graphics", "RestartPosition", "bottom", "The position of the restart button in the pause menu. Options are 'top', 'bottom', or the number of positions away from the top, so '1' would be 1 below the top item and thus second in the list. Falls back to default if you give weird values.");
ConfigCharacterButtonPosition = ((BaseUnityPlugin)this).Config.Bind<string>("Graphics", "CharacterPosition", "bottom", "The position of the character select button in the pause menu. Options are 'top', 'bottom', or the number of positions away from the top, so '1' would be 1 below the top item and thus second in the list. Falls back to default if you give weird values. Evaluated after the restart button is placed.");
ConfigConfirmationDialog = ((BaseUnityPlugin)this).Config.Bind<bool>("Graphics", "ConfirmationDialogEnabled", false, "Enables a confirmation dialog when trying to reset so it is not done accidentally");
ConfigResetKeyEnabled = ((BaseUnityPlugin)this).Config.Bind<bool>("Keybind", "ResetKeyEnabled", false, "Allows a key press to be used to reset runs in addition to the menu");
ConfigResetKeyBind = ((BaseUnityPlugin)this).Config.Bind<string>("Keybind", "ResetKeyBind", "T", "The key that has to be pressed to reset. Falls back to default if you give weird values.");
try
{
ResetKeyCode = (KeyCode)Enum.Parse(typeof(KeyCode), ConfigResetKeyBind.Value);
}
catch (Exception)
{
ResetKeyCode = (KeyCode)116;
}
ConfigResetKeyHoldTime = ((BaseUnityPlugin)this).Config.Bind<float>("Keybind", "ResetKeyHoldTime", 1f, "The number of seconds that the reset key has to be held in order to reset. Falls back to default if you give weird values.");
if (ConfigResetKeyHoldTime.Value >= 0f)
{
ResetKeyThreshold = ConfigResetKeyHoldTime.Value;
}
}
private void HandleResetKey()
{
//IL_0001: Unknown result type (might be due to invalid IL or missing references)
//IL_0097: Unknown result type (might be due to invalid IL or missing references)
if (Input.GetKey(ResetKeyCode))
{
TimeSpentHoldingKey += Time.deltaTime;
if (TimeSpentHoldingKey > ResetKeyThreshold && !ResetAlready)
{
PauseScreenController pauseScreen = null;
if (PauseScreenController.instancesList.Count > 0)
{
pauseScreen = PauseScreenController.instancesList[0];
}
TimeSpentHoldingKey = 0f;
ResetAlready = true;
Log.Debug("Restarting from keybind");
BoothUtil.ResetGame(pauseScreen, ConfigConfirmationDialog.Value, this, startNewGame: true);
}
}
if (Input.GetKeyUp(ResetKeyCode))
{
TimeSpentHoldingKey = 0f;
ResetAlready = false;
}
}
private void Update()
{
if (ConfigResetKeyEnabled.Value)
{
bool flag = Run.instance != null;
bool flag2 = PlayerCharacterMasterController.instances.Count > 1 && !BoothUtil.IsMultiplayerHost();
if (flag && !flag2 && !IsInChatBox)
{
HandleResetKey();
}
}
}
public void Awake()
{
//IL_001b: Unknown result type (might be due to invalid IL or missing references)
//IL_0025: Expected O, but got Unknown
//IL_002d: Unknown result type (might be due to invalid IL or missing references)
//IL_0037: Expected O, but got Unknown
//IL_003f: Unknown result type (might be due to invalid IL or missing references)
//IL_0049: Expected O, but got Unknown
Log.Init(((BaseUnityPlugin)this).Logger);
SetupConfig();
ChatBox.FocusInputField += (hook_FocusInputField)delegate(orig_FocusInputField orig, ChatBox self)
{
orig.Invoke(self);
IsInChatBox = true;
};
ChatBox.UnfocusInputField += (hook_UnfocusInputField)delegate(orig_UnfocusInputField orig, ChatBox self)
{
orig.Invoke(self);
IsInChatBox = false;
};
PauseScreenController.Awake += (hook_Awake)delegate(orig_Awake orig, PauseScreenController self)
{
//IL_00ad: Unknown result type (might be due to invalid IL or missing references)
//IL_00b7: Expected O, but got Unknown
//IL_00c6: Unknown result type (might be due to invalid IL or missing references)
//IL_00d0: Expected O, but got Unknown
//IL_0335: Unknown result type (might be due to invalid IL or missing references)
//IL_033f: Expected O, but got Unknown
//IL_034e: Unknown result type (might be due to invalid IL or missing references)
//IL_0358: Expected O, but got Unknown
orig.Invoke(self);
if (Run.instance != null && !Object.op_Implicit((Object)(object)PreGameController.instance))
{
Transform child = ((Transform)self.mainPanel).GetChild(0).GetChild(1);
Transform val = Object.Instantiate<Transform>(child, ((Transform)self.mainPanel).GetChild(0));
TextMeshProUGUI componentInChildren = (TextMeshProUGUI)(object)((Component)val).GetComponentInChildren<HGTextMeshProUGUI>();
((TMP_Text)componentInChildren).text = "Restart";
Transform parent = ((TMP_Text)componentInChildren).transform.parent;
TextMeshProUGUI val2 = Object.Instantiate<TextMeshProUGUI>(componentInChildren, parent);
Object.Destroy((Object)(object)componentInChildren);
HGButton component = ((Component)val).GetComponent<HGButton>();
((Button)component).onClick = new ButtonClickedEvent();
((UnityEvent)((Button)component).onClick).AddListener((UnityAction)delegate
{
Log.Debug("Restarting from button");
BoothUtil.ResetGame(self, ConfigConfirmationDialog.Value, this, startNewGame: true);
});
if ("top".Equals(ConfigRestartButtonPosition.Value, StringComparison.InvariantCultureIgnoreCase))
{
((Component)val).transform.SetAsFirstSibling();
}
else if ("bottom".Equals(ConfigRestartButtonPosition.Value, StringComparison.InvariantCultureIgnoreCase))
{
((Component)val).transform.SetAsLastSibling();
}
else
{
try
{
int num = Convert.ToInt32(ConfigRestartButtonPosition.Value);
if (num < 0)
{
num = 0;
}
else if (num >= ((Component)val).transform.parent.childCount)
{
num = ((Component)val).transform.parent.childCount - 1;
}
((Component)val).transform.SetSiblingIndex(num);
}
catch (FormatException)
{
((Component)val).transform.SetAsLastSibling();
}
}
if (PlayerCharacterMasterController.instances.Count > 1 && !BoothUtil.IsMultiplayerHost())
{
((Component)val).gameObject.SetActive(false);
}
Transform val3 = Object.Instantiate<Transform>(child, ((Transform)self.mainPanel).GetChild(0));
TextMeshProUGUI componentInChildren2 = (TextMeshProUGUI)(object)((Component)val3).GetComponentInChildren<HGTextMeshProUGUI>();
((TMP_Text)componentInChildren2).text = "Character Select";
Transform parent2 = ((TMP_Text)componentInChildren2).transform.parent;
TextMeshProUGUI val4 = Object.Instantiate<TextMeshProUGUI>(componentInChildren2, parent2);
Object.Destroy((Object)(object)componentInChildren2);
if ("top".Equals(ConfigCharacterButtonPosition.Value, StringComparison.InvariantCultureIgnoreCase))
{
((Component)val3).transform.SetAsFirstSibling();
}
else if ("bottom".Equals(ConfigCharacterButtonPosition.Value, StringComparison.InvariantCultureIgnoreCase))
{
((Component)val3).transform.SetAsLastSibling();
}
else
{
try
{
int num2 = Convert.ToInt32(ConfigCharacterButtonPosition.Value);
if (num2 < 0)
{
num2 = 0;
}
else if (num2 >= ((Component)val3).transform.parent.childCount)
{
num2 = ((Component)val3).transform.parent.childCount - 1;
}
((Component)val3).transform.SetSiblingIndex(num2);
}
catch (FormatException)
{
((Component)val3).transform.SetAsLastSibling();
}
}
if (PlayerCharacterMasterController.instances.Count > 1 && !BoothUtil.IsMultiplayerHost())
{
((Component)val3).gameObject.SetActive(false);
}
HGButton component2 = ((Component)val3).GetComponent<HGButton>();
((Button)component2).onClick = new ButtonClickedEvent();
((UnityEvent)((Button)component2).onClick).AddListener((UnityAction)delegate
{
Log.Debug("Returning to Character Select from button");
BoothUtil.ResetGame(self, ConfigConfirmationDialog.Value, this, startNewGame: false);
});
}
};
}
}
}
namespace QuickRestart
{
internal class BoothUtil
{
public static void ResetGame(PauseScreenController pauseScreen, bool AskConfirmation, Booth.QuickRestart parent, bool startNewGame)
{
//IL_0050: Unknown result type (might be due to invalid IL or missing references)
//IL_0085: Unknown result type (might be due to invalid IL or missing references)
//IL_0098: Unknown result type (might be due to invalid IL or missing references)
//IL_00ad: Expected O, but got Unknown
if (AskConfirmation)
{
if (SimpleDialogBox.instancesList.Count <= 0)
{
SimpleDialogBox val = SimpleDialogBox.Create((MPEventSystem)null);
val.headerToken = new TokenParamsPair("Are you sure?", Array.Empty<object>());
string text = "Are you sure you want to reset this run?";
if (pauseScreen == null)
{
text += " Use info screen button (usually tab/select) to move cursor.";
}
val.descriptionToken = new TokenParamsPair(text, Array.Empty<object>());
val.AddActionButton((UnityAction)delegate
{
ActuallyResetGame(pauseScreen, parent, startNewGame);
}, "Yes", true, Array.Empty<object>());
val.AddCancelButton("Cancel", Array.Empty<object>());
}
}
else
{
ActuallyResetGame(pauseScreen, parent, startNewGame);
}
}
public static bool IsMultiplayerHost()
{
return Object.op_Implicit((Object)(object)NetworkSession.instance) && NetworkServer.active;
}
private static void ActuallyResetGame(PauseScreenController pauseScreen, Booth.QuickRestart parent, bool startNewGame)
{
if (pauseScreen != null)
{
pauseScreen.DestroyPauseScreen(true);
}
if (Run.instance != null && ((Component)Run.instance).gameObject != null)
{
Object.Destroy((Object)(object)((Component)Run.instance).gameObject);
Object.Destroy((Object)(object)Run.instance);
}
if (startNewGame)
{
((MonoBehaviour)parent).StartCoroutine(StartNewGame());
}
}
private static IEnumerator StartNewGame()
{
while (!Object.op_Implicit((Object)(object)PreGameController.instance))
{
yield return (object)new WaitForSeconds(0.1f);
}
Reflection.InvokeMethod((object)PreGameController.instance, "StartRun");
}
}
}