using System;
using System.CodeDom.Compiler;
using System.Collections;
using System.ComponentModel;
using System.Diagnostics;
using System.Globalization;
using System.Linq;
using System.Reflection;
using System.Resources;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using HarmonyLib;
using IQuit.Behaviors;
using IQuit.NetcodePatcher;
using Microsoft.CodeAnalysis;
using Unity.Netcode;
using UnityEngine;
using UnityEngine.UI;
[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("Sehelitar")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyCopyright("Sehelitar @ https://sehelitar.tv")]
[assembly: AssemblyDescription("The Company can't fire you if you quit first!")]
[assembly: AssemblyFileVersion("1.1.0")]
[assembly: AssemblyInformationalVersion("1.1.0+ae0798a42a98941074bdad04a3d4378352e3d8f9")]
[assembly: AssemblyProduct("IQuit")]
[assembly: AssemblyTitle("IQuit")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.1.0.0")]
[module: UnverifiableCode]
[module: RefSafetyRules(11)]
[module: NetcodePatchedAssembly]
internal class <Module>
{
static <Module>()
{
NetworkVariableSerializationTypes.InitializeSerializer_UnmanagedByMemcpy<bool>();
NetworkVariableSerializationTypes.InitializeEqualityChecker_UnmanagedIEquatable<bool>();
}
}
namespace Microsoft.CodeAnalysis
{
[CompilerGenerated]
[Microsoft.CodeAnalysis.Embedded]
internal sealed class EmbeddedAttribute : Attribute
{
}
}
namespace System.Runtime.CompilerServices
{
[CompilerGenerated]
[Microsoft.CodeAnalysis.Embedded]
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Event | AttributeTargets.Parameter | AttributeTargets.ReturnValue | AttributeTargets.GenericParameter, AllowMultiple = false, Inherited = false)]
internal sealed class NullableAttribute : Attribute
{
public readonly byte[] NullableFlags;
public NullableAttribute(byte P_0)
{
NullableFlags = new byte[1] { P_0 };
}
public NullableAttribute(byte[] P_0)
{
NullableFlags = P_0;
}
}
[CompilerGenerated]
[Microsoft.CodeAnalysis.Embedded]
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Method | AttributeTargets.Interface | AttributeTargets.Delegate, AllowMultiple = false, Inherited = false)]
internal sealed class NullableContextAttribute : Attribute
{
public readonly byte Flag;
public NullableContextAttribute(byte P_0)
{
Flag = P_0;
}
}
[CompilerGenerated]
[Microsoft.CodeAnalysis.Embedded]
[AttributeUsage(AttributeTargets.Module, AllowMultiple = false, Inherited = false)]
internal sealed class RefSafetyRulesAttribute : Attribute
{
public readonly int Version;
public RefSafetyRulesAttribute(int P_0)
{
Version = P_0;
}
}
}
namespace IQuit
{
[GeneratedCode("System.Resources.Tools.StronglyTypedResourceBuilder", "4.0.0.0")]
[DebuggerNonUserCode]
[CompilerGenerated]
internal class Locale
{
private static ResourceManager resourceMan;
private static CultureInfo resourceCulture;
[EditorBrowsable(EditorBrowsableState.Advanced)]
internal static ResourceManager ResourceManager
{
get
{
if (resourceMan == null)
{
resourceMan = new ResourceManager("IQuit.Locale", typeof(Locale).Assembly);
}
return resourceMan;
}
}
[EditorBrowsable(EditorBrowsableState.Advanced)]
internal static CultureInfo Culture
{
get
{
return resourceCulture;
}
set
{
resourceCulture = value;
}
}
internal static string CommandDesc => ResourceManager.GetString("CommandDesc", resourceCulture);
internal static string HostOnly => ResourceManager.GetString("HostOnly", resourceCulture);
internal static string RequestDenied => ResourceManager.GetString("RequestDenied", resourceCulture);
internal static string RequestGranted => ResourceManager.GetString("RequestGranted", resourceCulture);
internal static string ReturnEquipment => ResourceManager.GetString("ReturnEquipment", resourceCulture);
internal static string SendingResignation => ResourceManager.GetString("SendingResignation", resourceCulture);
internal Locale()
{
}
}
[BepInPlugin("IQuit", "IQuit", "1.1.0")]
[BepInProcess("Lethal Company.exe")]
public class Plugin : BaseUnityPlugin
{
private static Harmony _globalHarmony;
internal static ManualLogSource Log { get; private set; }
internal static PluginConfigStruct GameConfig { get; private set; }
private void Awake()
{
//IL_0025: Unknown result type (might be due to invalid IL or missing references)
//IL_002f: Expected O, but got Unknown
Log = ((BaseUnityPlugin)this).Logger;
((BaseUnityPlugin)this).Logger.LogInfo((object)"Plugin IQuit is loaded!");
PatchNetwork();
_globalHarmony = new Harmony("IQuit");
_globalHarmony.PatchAll();
PluginConfigStruct gameConfig = default(PluginConfigStruct);
gameConfig.AllowOthers = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "AllowOthers", false, "Allow non-host players to quit.");
gameConfig.FastReset = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "FastReset", true, "Instantly reset your game and bypass the eject sequence.");
GameConfig = gameConfig;
}
private static void PatchNetwork()
{
try
{
Type[] types = Assembly.GetExecutingAssembly().GetTypes();
foreach (Type type in types)
{
MethodInfo[] methods = type.GetMethods(BindingFlags.Instance | BindingFlags.Static | BindingFlags.NonPublic);
foreach (MethodInfo methodInfo in methods)
{
if (methodInfo.GetCustomAttributes(typeof(RuntimeInitializeOnLoadMethodAttribute), inherit: false).Length != 0)
{
Log.LogInfo((object)("Initialize network patch for " + type.FullName));
methodInfo.Invoke(null, null);
}
}
}
}
catch (Exception)
{
}
}
}
internal struct PluginConfigStruct
{
public ConfigEntry<bool> AllowOthers;
public ConfigEntry<bool> FastReset;
}
public static class PluginInfo
{
public const string PLUGIN_GUID = "IQuit";
public const string PLUGIN_NAME = "IQuit";
public const string PLUGIN_VERSION = "1.1.0";
}
}
namespace IQuit.Patches
{
[HarmonyPatch(typeof(Terminal))]
internal class TerminalPatch
{
private static ResignationHandler? _resignationHandler;
[HarmonyPatch("Awake")]
[HarmonyPrefix]
[HarmonyPriority(800)]
private static void Awake(ref Terminal __instance)
{
TerminalNode val = ScriptableObject.CreateInstance<TerminalNode>();
val.clearPreviousText = true;
val.terminalEvent = "iquit_goodbye";
val.displayText = Locale.SendingResignation + "\n\n";
TerminalKeyword val2 = ScriptableObject.CreateInstance<TerminalKeyword>();
val2.isVerb = false;
val2.word = "iquit";
val2.specialKeywordResult = val;
__instance.terminalNodes.allKeywords = CollectionExtensions.AddToArray<TerminalKeyword>(__instance.terminalNodes.allKeywords, val2);
_resignationHandler = ((Component)__instance).gameObject.AddComponent<ResignationHandler>();
TerminalNode val3 = (from x in __instance.terminalNodes.specialNodes
where ((Object)x).name == "HelpCommands"
select (x)).FirstOrDefault();
if (!((Object)(object)val3 == (Object)null))
{
string displayText = val3.displayText;
val3.displayText = displayText.Substring(0, displayText.Length - 23) + ">IQUIT\r\n" + Locale.CommandDesc + "\r\n\r\n[numberOfItemsOnRoute]\r\n";
}
}
[HarmonyPatch("RunTerminalEvents")]
[HarmonyPostfix]
private static void RunTerminalEvents(ref Terminal __instance, ref TerminalNode node)
{
if (node.terminalEvent == "iquit_goodbye")
{
_resignationHandler?.HandleResignation();
}
}
}
}
namespace IQuit.Behaviors
{
public class ResignationHandler : NetworkBehaviour
{
private bool _fromSelf;
private readonly NetworkVariable<bool> _allowOther = new NetworkVariable<bool>(Plugin.GameConfig.AllowOthers.Value, (NetworkVariableReadPermission)0, (NetworkVariableWritePermission)0);
private readonly NetworkVariable<bool> _fastReset = new NetworkVariable<bool>(Plugin.GameConfig.FastReset.Value, (NetworkVariableReadPermission)0, (NetworkVariableWritePermission)0);
private bool _isRunning;
public void HandleResignation()
{
_fromSelf = true;
PlayerQuitedServerRpc();
}
[ServerRpc(RequireOwnership = false)]
private void PlayerQuitedServerRpc()
{
//IL_0024: Unknown result type (might be due to invalid IL or missing references)
//IL_002e: Invalid comparison between Unknown and I4
//IL_008c: Unknown result type (might be due to invalid IL or missing references)
//IL_0096: Invalid comparison between Unknown and I4
//IL_005f: Unknown result type (might be due to invalid IL or missing references)
//IL_0068: Unknown result type (might be due to invalid IL or missing references)
//IL_006d: Unknown result type (might be due to invalid IL or missing references)
//IL_007c: Unknown result type (might be due to invalid IL or missing references)
NetworkManager networkManager = ((NetworkBehaviour)this).NetworkManager;
if (networkManager != null && networkManager.IsListening)
{
if ((int)base.__rpc_exec_stage != 1 && (networkManager.IsClient || networkManager.IsHost))
{
ServerRpcParams val = default(ServerRpcParams);
FastBufferWriter val2 = ((NetworkBehaviour)this).__beginSendServerRpc(2700636679u, val, (RpcDelivery)0);
((NetworkBehaviour)this).__endSendServerRpc(ref val2, 2700636679u, val, (RpcDelivery)0);
}
if ((int)base.__rpc_exec_stage == 1 && (networkManager.IsServer || networkManager.IsHost) && !_isRunning)
{
Plugin.Log.LogDebug((object)"[Event] PlayerQuitedServerRPC");
ResetClientRpc(!StartOfRound.Instance.firingPlayersCutsceneRunning && (_allowOther.Value || _fromSelf));
_fromSelf = false;
}
}
}
[ClientRpc]
private void ResetClientRpc(bool granted)
{
//IL_0024: Unknown result type (might be due to invalid IL or missing references)
//IL_002e: Invalid comparison between Unknown and I4
//IL_00a7: Unknown result type (might be due to invalid IL or missing references)
//IL_00b1: Invalid comparison between Unknown and I4
//IL_005f: Unknown result type (might be due to invalid IL or missing references)
//IL_0068: Unknown result type (might be due to invalid IL or missing references)
//IL_006d: Unknown result type (might be due to invalid IL or missing references)
//IL_007d: Unknown result type (might be due to invalid IL or missing references)
//IL_0083: 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)
NetworkManager networkManager = ((NetworkBehaviour)this).NetworkManager;
if (networkManager != null && networkManager.IsListening)
{
if ((int)base.__rpc_exec_stage != 2 && (networkManager.IsServer || networkManager.IsHost))
{
ClientRpcParams val = default(ClientRpcParams);
FastBufferWriter val2 = ((NetworkBehaviour)this).__beginSendClientRpc(4081331157u, val, (RpcDelivery)0);
((FastBufferWriter)(ref val2)).WriteValueSafe<bool>(ref granted, default(ForPrimitives));
((NetworkBehaviour)this).__endSendClientRpc(ref val2, 4081331157u, val, (RpcDelivery)0);
}
if ((int)base.__rpc_exec_stage == 2 && (networkManager.IsClient || networkManager.IsHost))
{
((MonoBehaviour)this).StartCoroutine(ResetCoroutine(granted));
}
}
}
private IEnumerator ResetCoroutine(bool granted)
{
if (_isRunning)
{
yield break;
}
_isRunning = true;
Terminal terminal = Object.FindObjectOfType<Terminal>();
if (!_fastReset.Value || !StartOfRound.Instance.inShipPhase)
{
if (!_fastReset.Value)
{
terminal.screenText.ReleaseSelection();
terminal.screenText.DeactivateInputField(false);
yield return (object)new WaitForSeconds(2f);
terminal.screenText.ActivateInputField();
((Selectable)terminal.screenText).Select();
}
if (terminal.terminalInUse)
{
TerminalNode val = ScriptableObject.CreateInstance<TerminalNode>();
val.clearPreviousText = true;
val.displayText = "// <size=20><color=" + (granted ? "#0000ff" : "#ff0000") + ">" + (granted ? Locale.RequestGranted : Locale.RequestDenied) + "</color></size> //\r\n" + (granted ? Locale.ReturnEquipment : Locale.HostOnly) + "\r\n\r\n";
terminal.LoadNewNode(val);
}
if (!granted)
{
yield break;
}
if (!_fastReset.Value)
{
yield return (object)new WaitForSeconds((float)((!_fastReset.Value) ? 5 : 0));
}
}
if (!StartOfRound.Instance.inShipPhase)
{
StartOfRound.Instance.firingPlayersCutsceneRunning = true;
StartOfRound.Instance.ShipLeaveAutomatically(false);
yield return (object)new WaitUntil((Func<bool>)(() => StartOfRound.Instance.inShipPhase));
StartOfRound.Instance.firingPlayersCutsceneRunning = false;
}
if (!_fastReset.Value)
{
if (((NetworkBehaviour)this).IsServer)
{
StartOfRound.Instance.ManuallyEjectPlayersServerRpc();
}
yield return (object)new WaitForSeconds(10f);
_isRunning = false;
yield break;
}
terminal.ClearBoughtItems();
terminal.SetItemSales();
GameNetworkManager.Instance.localPlayerController.inSpecialInteractAnimation = true;
GameNetworkManager.Instance.localPlayerController.DropAllHeldItems(true, false);
SoundManager.Instance.SetDiageticMixerSnapshot(3, 2f);
StartOfRound.Instance.shipDoorAudioSource.Stop();
StartOfRound.Instance.speakerAudioSource.Stop();
if (((NetworkBehaviour)this).IsServer)
{
GameNetworkManager.Instance.ResetSavedGameValues();
}
StartOfRound.Instance.ResetShip();
yield return (object)new WaitForSeconds(0.1f);
GameNetworkManager.Instance.localPlayerController.TeleportPlayer(StartOfRound.Instance.playerSpawnPositions[GameNetworkManager.Instance.localPlayerController.playerClientId].position, false, 0f, false, true);
StartOfRound.Instance.currentPlanetPrefab.transform.position = ((Component)StartOfRound.Instance.planetContainer).transform.position;
yield return (object)new WaitForSeconds(0.1f);
if (((NetworkBehaviour)this).IsServer)
{
StartOfRound instance = StartOfRound.Instance;
instance.playersRevived++;
yield return (object)new WaitUntil((Func<bool>)(() => StartOfRound.Instance.playersRevived >= GameNetworkManager.Instance.connectedPlayers));
StartOfRound.Instance.playersRevived = 0;
StartOfRound.Instance.EndPlayersFiredSequenceClientRpc();
}
else
{
StartOfRound.Instance.PlayerHasRevivedServerRpc();
}
_isRunning = false;
}
protected override void __initializeVariables()
{
if (_allowOther == null)
{
throw new Exception("ResignationHandler._allowOther cannot be null. All NetworkVariableBase instances must be initialized.");
}
((NetworkVariableBase)_allowOther).Initialize((NetworkBehaviour)(object)this);
((NetworkBehaviour)this).__nameNetworkVariable((NetworkVariableBase)(object)_allowOther, "_allowOther");
base.NetworkVariableFields.Add((NetworkVariableBase)(object)_allowOther);
if (_fastReset == null)
{
throw new Exception("ResignationHandler._fastReset cannot be null. All NetworkVariableBase instances must be initialized.");
}
((NetworkVariableBase)_fastReset).Initialize((NetworkBehaviour)(object)this);
((NetworkBehaviour)this).__nameNetworkVariable((NetworkVariableBase)(object)_fastReset, "_fastReset");
base.NetworkVariableFields.Add((NetworkVariableBase)(object)_fastReset);
((NetworkBehaviour)this).__initializeVariables();
}
[RuntimeInitializeOnLoadMethod]
internal static void InitializeRPCS_ResignationHandler()
{
//IL_0011: Unknown result type (might be due to invalid IL or missing references)
//IL_001b: Expected O, but got Unknown
//IL_002c: Unknown result type (might be due to invalid IL or missing references)
//IL_0036: Expected O, but got Unknown
NetworkManager.__rpc_func_table.Add(2700636679u, new RpcReceiveHandler(__rpc_handler_2700636679));
NetworkManager.__rpc_func_table.Add(4081331157u, new RpcReceiveHandler(__rpc_handler_4081331157));
}
private static void __rpc_handler_2700636679(NetworkBehaviour target, FastBufferReader reader, __RpcParams rpcParams)
{
//IL_0029: Unknown result type (might be due to invalid IL or missing references)
//IL_003f: Unknown result type (might be due to invalid IL or missing references)
NetworkManager networkManager = target.NetworkManager;
if (networkManager != null && networkManager.IsListening)
{
target.__rpc_exec_stage = (__RpcExecStage)1;
((ResignationHandler)(object)target).PlayerQuitedServerRpc();
target.__rpc_exec_stage = (__RpcExecStage)0;
}
}
private static void __rpc_handler_4081331157(NetworkBehaviour target, FastBufferReader reader, __RpcParams rpcParams)
{
//IL_002f: Unknown result type (might be due to invalid IL or missing references)
//IL_0035: Unknown result type (might be due to invalid IL or missing references)
//IL_0044: Unknown result type (might be due to invalid IL or missing references)
//IL_005e: Unknown result type (might be due to invalid IL or missing references)
NetworkManager networkManager = target.NetworkManager;
if (networkManager != null && networkManager.IsListening)
{
bool granted = default(bool);
((FastBufferReader)(ref reader)).ReadValueSafe<bool>(ref granted, default(ForPrimitives));
target.__rpc_exec_stage = (__RpcExecStage)2;
((ResignationHandler)(object)target).ResetClientRpc(granted);
target.__rpc_exec_stage = (__RpcExecStage)0;
}
}
protected internal override string __getTypeName()
{
return "ResignationHandler";
}
}
}
namespace IQuit.NetcodePatcher
{
[AttributeUsage(AttributeTargets.Module)]
internal class NetcodePatchedAssemblyAttribute : Attribute
{
}
}