using System;
using System.Collections;
using System.Diagnostics;
using System.IO;
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.0", FrameworkDisplayName = ".NET Standard 2.0")]
[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.0")]
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_0089: 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;
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_00c0: 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_00d9: Unknown result type (might be due to invalid IL or missing references)
//IL_00e5: Unknown result type (might be due to invalid IL or missing references)
//IL_00f2: Unknown result type (might be due to invalid IL or missing references)
//IL_00fe: Unknown result type (might be due to invalid IL or missing references)
//IL_0111: Unknown result type (might be due to invalid IL or missing references)
//IL_011b: Expected O, but got Unknown
//IL_0123: Unknown result type (might be due to invalid IL or missing references)
//IL_012d: Expected O, but got Unknown
//IL_0135: Unknown result type (might be due to invalid IL or missing references)
//IL_013f: Expected O, but got Unknown
Log.Init(((BaseUnityPlugin)this).Logger);
SetupConfig();
AssetBundle val;
using (Stream stream = Assembly.GetExecutingAssembly().GetManifestResourceStream("QuickRestart.booth_assets"))
{
val = AssetBundle.LoadFromStream(stream);
}
Texture2D val2 = val.LoadAsset<Texture2D>("Assets/Texture2D/Booth_texUICleanButton.png");
Texture2D val3 = val.LoadAsset<Texture2D>("Assets/Texture2D/Booth_texUIOutlineOnly.png");
Texture2D val4 = val.LoadAsset<Texture2D>("Assets/Texture2D/Booth_texUIHighlightBoxOutlineThick.png");
Rect val5 = default(Rect);
((Rect)(ref val5))..ctor(0f, 0f, (float)((Texture)val2).width, (float)((Texture)val2).height);
Rect val6 = default(Rect);
((Rect)(ref val6))..ctor(0f, 0f, (float)((Texture)val3).width, (float)((Texture)val3).height);
Rect val7 = default(Rect);
((Rect)(ref val7))..ctor(0f, 0f, (float)((Texture)val4).width, (float)((Texture)val4).height);
Sprite val8 = Sprite.Create(val2, val5, new Vector2(0f, 0f));
Sprite val9 = Sprite.Create(val3, val6, new Vector2(0f, 0f));
Sprite val10 = Sprite.Create(val4, val7, new Vector2(0f, 0f));
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_00c6: Unknown result type (might be due to invalid IL or missing references)
//IL_00d0: Expected O, but got Unknown
//IL_01e4: Unknown result type (might be due to invalid IL or missing references)
//IL_01ee: Expected O, but got Unknown
//IL_036c: Unknown result type (might be due to invalid IL or missing references)
//IL_0376: 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(0);
Transform val11 = Object.Instantiate<Transform>(child, ((Transform)self.mainPanel).GetChild(0));
TextMeshProUGUI componentInChildren = (TextMeshProUGUI)(object)((Component)val11).GetComponentInChildren<HGTextMeshProUGUI>();
((TMP_Text)componentInChildren).text = "Restart";
Transform parent = ((TMP_Text)componentInChildren).transform.parent;
TextMeshProUGUI val12 = Object.Instantiate<TextMeshProUGUI>(componentInChildren, parent);
Object.Destroy((Object)(object)componentInChildren);
((UnityEventBase)((Button)((Component)val11).GetComponentInChildren<HGButton>()).onClick).RemoveAllListeners();
((UnityEvent)((Button)((Component)val11).GetComponentInChildren<HGButton>()).onClick).AddListener((UnityAction)delegate
{
BoothUtil.ResetGame(self, ConfigConfirmationDialog.Value, this, startNewGame: true);
});
if ("top".Equals(ConfigRestartButtonPosition.Value, StringComparison.InvariantCultureIgnoreCase))
{
((Component)val11).transform.SetAsFirstSibling();
}
else if ("bottom".Equals(ConfigRestartButtonPosition.Value, StringComparison.InvariantCultureIgnoreCase))
{
((Component)val11).transform.SetAsLastSibling();
}
else
{
try
{
int num = Convert.ToInt32(ConfigRestartButtonPosition.Value);
if (num < 0)
{
num = 0;
}
else if (num >= ((Component)val11).transform.parent.childCount)
{
num = ((Component)val11).transform.parent.childCount - 1;
}
((Component)val11).transform.SetSiblingIndex(num);
}
catch (FormatException)
{
((Component)val11).transform.SetAsLastSibling();
}
}
if (PlayerCharacterMasterController.instances.Count > 1 && !BoothUtil.IsMultiplayerHost())
{
((Component)val11).gameObject.SetActive(false);
}
((UnityEvent)((Button)((Component)val11).GetComponent<HGButton>()).onClick).AddListener((UnityAction)delegate
{
BoothUtil.ResetGame(self, ConfigConfirmationDialog.Value, this, startNewGame: true);
});
Transform val13 = Object.Instantiate<Transform>(child, ((Transform)self.mainPanel).GetChild(0));
TextMeshProUGUI componentInChildren2 = (TextMeshProUGUI)(object)((Component)val13).GetComponentInChildren<HGTextMeshProUGUI>();
((TMP_Text)componentInChildren2).text = "Character Select";
Transform parent2 = ((TMP_Text)componentInChildren2).transform.parent;
TextMeshProUGUI val14 = Object.Instantiate<TextMeshProUGUI>(componentInChildren2, parent2);
Object.Destroy((Object)(object)componentInChildren2);
if ("top".Equals(ConfigCharacterButtonPosition.Value, StringComparison.InvariantCultureIgnoreCase))
{
((Component)val13).transform.SetAsFirstSibling();
}
else if ("bottom".Equals(ConfigCharacterButtonPosition.Value, StringComparison.InvariantCultureIgnoreCase))
{
((Component)val13).transform.SetAsLastSibling();
}
else
{
try
{
int num2 = Convert.ToInt32(ConfigCharacterButtonPosition.Value);
if (num2 < 0)
{
num2 = 0;
}
else if (num2 >= ((Component)val13).transform.parent.childCount)
{
num2 = ((Component)val13).transform.parent.childCount - 1;
}
((Component)val13).transform.SetSiblingIndex(num2);
}
catch (FormatException)
{
((Component)val13).transform.SetAsLastSibling();
}
}
if (PlayerCharacterMasterController.instances.Count > 1 && !BoothUtil.IsMultiplayerHost())
{
((Component)val13).gameObject.SetActive(false);
}
((UnityEventBase)((Button)((Component)val13).GetComponentInChildren<HGButton>()).onClick).RemoveAllListeners();
((UnityEvent)((Button)((Component)val13).GetComponent<HGButton>()).onClick).AddListener((UnityAction)delegate
{
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)
{
Reflection.InvokeMethod((object)pauseScreen, "OnDisable");
Object.Destroy((Object)(object)((Component)pauseScreen).gameObject);
}
if (IsMultiplayerHost())
{
NetworkSession.instance.EndRun();
if (startNewGame)
{
((MonoBehaviour)parent).StartCoroutine(StartNewGameMultiplayer());
}
return;
}
if (Run.instance != null && ((Component)Run.instance).gameObject != null)
{
Object.Destroy((Object)(object)((Component)Run.instance).gameObject);
}
if (startNewGame)
{
((MonoBehaviour)parent).StartCoroutine(StartNewGameSingleplayer());
}
}
private static IEnumerator StartNewGameSingleplayer()
{
while (!Object.op_Implicit((Object)(object)PreGameController.instance))
{
yield return (object)new WaitForSeconds(0.1f);
}
Reflection.InvokeMethod((object)PreGameController.instance, "StartRun");
}
private static IEnumerator StartNewGameMultiplayer()
{
while (!Object.op_Implicit((Object)(object)PreGameController.instance))
{
yield return (object)new WaitForSeconds(0.1f);
}
PreGameController.instance.StartLaunch();
}
}
}