using System;
using System.CodeDom.Compiler;
using System.ComponentModel;
using System.Diagnostics;
using System.Globalization;
using System.Reflection;
using System.Resources;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using System.Threading.Tasks;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using GameNetcodeStuff;
using HarmonyLib;
using LastResort.Patches;
using Unity.Netcode;
using UnityEngine;
using UnityEngine.InputSystem;
using UnityEngine.InputSystem.Controls;
[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: AssemblyTitle("LastResort")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("LastResort")]
[assembly: AssemblyCopyright("Copyright © 2024")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("f41c8e83-99af-4400-967c-eb1dd5e9a23c")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")]
[assembly: AssemblyVersion("1.0.0.0")]
internal class <Module>
{
static <Module>()
{
}
}
namespace LastResort
{
[BepInPlugin("LastResort", "LastResort", "1.0.1")]
public class LastResortMod : BaseUnityPlugin
{
private const string modGUID = "LastResort";
private const string modName = "LastResort";
private const string modVersion = "1.0.1";
private readonly Harmony harmony = new Harmony("LastResort");
private static LastResortMod Instance;
public static ManualLogSource Log;
public static ConfigEntry<Key> explodeKey;
public static Key defaultKey = (Key)104;
private void Awake()
{
//IL_0037: Unknown result type (might be due to invalid IL or missing references)
//IL_005a: Unknown result type (might be due to invalid IL or missing references)
//IL_005f: Unknown result type (might be due to invalid IL or missing references)
if ((Object)(object)Instance == (Object)null)
{
Instance = this;
}
Log = Logger.CreateLogSource("LastResort");
explodeKey = ((BaseUnityPlugin)this).Config.Bind<Key>("Binds", "Explode", defaultKey, "");
ManualLogSource log = Log;
Key value = explodeKey.Value;
log.LogInfo((object)("Binded " + ((object)(Key)(ref value)).ToString() + " key to explode. You can bind this to a different key by changing the settings in the mod's configuration file."));
harmony.PatchAll(typeof(LastResortMod));
harmony.PatchAll(typeof(PlayerControllerBPatch));
harmony.PatchAll(typeof(GameNetworkManagerPatch));
harmony.PatchAll(typeof(StartOfRoundPatch));
Log.LogInfo((object)"Ready to Explode!");
Type[] types = Assembly.GetExecutingAssembly().GetTypes();
Type[] array = types;
foreach (Type type in array)
{
MethodInfo[] methods = type.GetMethods(BindingFlags.Instance | BindingFlags.Static | BindingFlags.NonPublic);
MethodInfo[] array2 = methods;
foreach (MethodInfo methodInfo in array2)
{
object[] customAttributes = methodInfo.GetCustomAttributes(typeof(RuntimeInitializeOnLoadMethodAttribute), inherit: false);
if (customAttributes.Length != 0)
{
methodInfo.Invoke(null, null);
}
}
}
}
}
}
namespace LastResort.Properties
{
[GeneratedCode("System.Resources.Tools.StronglyTypedResourceBuilder", "17.0.0.0")]
[DebuggerNonUserCode]
[CompilerGenerated]
internal class Resources
{
private static ResourceManager resourceMan;
private static CultureInfo resourceCulture;
[EditorBrowsable(EditorBrowsableState.Advanced)]
internal static ResourceManager ResourceManager
{
get
{
if (resourceMan == null)
{
ResourceManager resourceManager = new ResourceManager("LastResort.Properties.Resources", typeof(Resources).Assembly);
resourceMan = resourceManager;
}
return resourceMan;
}
}
[EditorBrowsable(EditorBrowsableState.Advanced)]
internal static CultureInfo Culture
{
get
{
return resourceCulture;
}
set
{
resourceCulture = value;
}
}
internal static byte[] lastresortasset
{
get
{
object @object = ResourceManager.GetObject("lastresortasset", resourceCulture);
return (byte[])@object;
}
}
internal Resources()
{
}
}
}
namespace LastResort.Patches
{
[HarmonyPatch(typeof(PlayerControllerB))]
internal class PlayerControllerBPatch
{
public static ManualLogSource lastResortLog = LastResortMod.Log;
public static PlayerControllerB player;
public static bool explodeTipShown = false;
public static bool playerExploded = false;
public static bool isPlayerReady = false;
[HarmonyPatch("ConnectClientToPlayerObject")]
[HarmonyPostfix]
public static void initializeClientToPlayerObject()
{
lastResortLog.LogInfo((object)"Connected Client to Player Object");
player = GameNetworkManager.Instance.localPlayerController;
LastResortHandler.Instance.LastResortAudioSource = player.itemAudio;
LastResortHandler.Instance.LastResortAudioClip = Resources.FindObjectsOfTypeAll<Landmine>()[0].mineTrigger;
isPlayerReady = true;
}
[HarmonyPatch("Update")]
[HarmonyPostfix]
public static async void PlayerControllerB_Update(PlayerControllerB __instance)
{
if (isPlayerReady && !player.isPlayerDead && (Object)(object)player == (Object)(object)__instance)
{
bool keyPressed = ((ButtonControl)Keyboard.current[LastResortMod.explodeKey.Value]).wasPressedThisFrame;
if (StartOfRound.Instance.shipHasLanded && !explodeTipShown)
{
lastResortLog.LogInfo((object)"Explode tip has been shown");
HUDManager instance = HUDManager.Instance;
Key value = LastResortMod.explodeKey.Value;
instance.DisplayTip("Last Resort Mod", "You can now explode yourself by pressing the " + ((object)(Key)(ref value)).ToString() + " key.", false, false, "LC_Tip1");
explodeTipShown = true;
}
else if (!StartOfRound.Instance.shipHasLanded && explodeTipShown)
{
lastResortLog.LogInfo((object)"Explode tip has been set to false");
explodeTipShown = false;
playerExploded = false;
}
if (keyPressed && !playerExploded && explodeTipShown && !player.isPlayerDead)
{
playerExploded = true;
LastResortHandler.Instance.PlayExplosionSoundServerRpc(player.playerUsername, ((Component)player).transform.position);
await Task.Delay(500);
LastResortHandler.Instance.ExplodePositionServerRpc(((Component)player).transform.position);
}
}
}
}
public class LastResortHandler : NetworkBehaviour
{
public static LastResortHandler Instance;
public AudioSource LastResortAudioSource;
public AudioClip LastResortAudioClip;
private void Awake()
{
Instance = this;
}
[ServerRpc(RequireOwnership = false)]
public void ExplodePositionServerRpc(Vector3 position)
{
//IL_0024: Unknown result type (might be due to invalid IL or missing references)
//IL_002e: Invalid comparison between Unknown and I4
//IL_0099: Unknown result type (might be due to invalid IL or missing references)
//IL_00a3: 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_0089: Unknown result type (might be due to invalid IL or missing references)
//IL_00ca: 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(3317637825u, val, (RpcDelivery)0);
((FastBufferWriter)(ref val2)).WriteValueSafe(ref position);
((NetworkBehaviour)this).__endSendServerRpc(ref val2, 3317637825u, val, (RpcDelivery)0);
}
if ((int)base.__rpc_exec_stage == 1 && (networkManager.IsServer || networkManager.IsHost))
{
ExplodePositionClientRpc(position);
}
}
}
[ClientRpc]
public void ExplodePositionClientRpc(Vector3 position)
{
//IL_0024: Unknown result type (might be due to invalid IL or missing references)
//IL_002e: Invalid comparison between Unknown and I4
//IL_0099: Unknown result type (might be due to invalid IL or missing references)
//IL_00a3: 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_0089: Unknown result type (might be due to invalid IL or missing references)
//IL_00c9: 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(3529891776u, val, (RpcDelivery)0);
((FastBufferWriter)(ref val2)).WriteValueSafe(ref position);
((NetworkBehaviour)this).__endSendClientRpc(ref val2, 3529891776u, val, (RpcDelivery)0);
}
if ((int)base.__rpc_exec_stage == 2 && (networkManager.IsClient || networkManager.IsHost))
{
Landmine.SpawnExplosion(position, true, 5.7f, 5.7f);
}
}
}
[ServerRpc(RequireOwnership = false)]
public void PlayExplosionSoundServerRpc(string username, Vector3 position)
{
//IL_0024: Unknown result type (might be due to invalid IL or missing references)
//IL_002e: Invalid comparison between Unknown and I4
//IL_00d7: Unknown result type (might be due to invalid IL or missing references)
//IL_00e1: 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_0088: Unknown result type (might be due to invalid IL or missing references)
//IL_008e: Unknown result type (might be due to invalid IL or missing references)
//IL_0109: Unknown result type (might be due to invalid IL or missing references)
//IL_00c7: Unknown result type (might be due to invalid IL or missing references)
NetworkManager networkManager = ((NetworkBehaviour)this).NetworkManager;
if (networkManager == null || !networkManager.IsListening)
{
return;
}
if ((int)base.__rpc_exec_stage != 1 && (networkManager.IsClient || networkManager.IsHost))
{
ServerRpcParams val = default(ServerRpcParams);
FastBufferWriter val2 = ((NetworkBehaviour)this).__beginSendServerRpc(874432910u, val, (RpcDelivery)0);
bool flag = username != null;
((FastBufferWriter)(ref val2)).WriteValueSafe<bool>(ref flag, default(ForPrimitives));
if (flag)
{
((FastBufferWriter)(ref val2)).WriteValueSafe(username, false);
}
((FastBufferWriter)(ref val2)).WriteValueSafe(ref position);
((NetworkBehaviour)this).__endSendServerRpc(ref val2, 874432910u, val, (RpcDelivery)0);
}
if ((int)base.__rpc_exec_stage == 1 && (networkManager.IsServer || networkManager.IsHost))
{
PlayExplosionSoundClientRpc(username, position);
}
}
[ClientRpc]
public void PlayExplosionSoundClientRpc(string username, Vector3 position)
{
//IL_0024: Unknown result type (might be due to invalid IL or missing references)
//IL_002e: Invalid comparison between Unknown and I4
//IL_00d7: Unknown result type (might be due to invalid IL or missing references)
//IL_00e1: 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_0088: Unknown result type (might be due to invalid IL or missing references)
//IL_008e: Unknown result type (might be due to invalid IL or missing references)
//IL_0128: Unknown result type (might be due to invalid IL or missing references)
//IL_00c7: Unknown result type (might be due to invalid IL or missing references)
NetworkManager networkManager = ((NetworkBehaviour)this).NetworkManager;
if (networkManager == null || !networkManager.IsListening)
{
return;
}
if ((int)base.__rpc_exec_stage != 2 && (networkManager.IsServer || networkManager.IsHost))
{
ClientRpcParams val = default(ClientRpcParams);
FastBufferWriter val2 = ((NetworkBehaviour)this).__beginSendClientRpc(2257449764u, val, (RpcDelivery)0);
bool flag = username != null;
((FastBufferWriter)(ref val2)).WriteValueSafe<bool>(ref flag, default(ForPrimitives));
if (flag)
{
((FastBufferWriter)(ref val2)).WriteValueSafe(username, false);
}
((FastBufferWriter)(ref val2)).WriteValueSafe(ref position);
((NetworkBehaviour)this).__endSendClientRpc(ref val2, 2257449764u, val, (RpcDelivery)0);
}
if ((int)base.__rpc_exec_stage == 2 && (networkManager.IsClient || networkManager.IsHost))
{
LastResortMod.Log.LogInfo((object)(username + " exploded!"));
((Component)LastResortAudioSource).transform.position = position;
LastResortAudioSource.PlayOneShot(LastResortAudioClip);
}
}
protected override void __initializeVariables()
{
((NetworkBehaviour)this).__initializeVariables();
}
[RuntimeInitializeOnLoadMethod]
internal static void InitializeRPCS_LastResortHandler()
{
//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
//IL_0047: Unknown result type (might be due to invalid IL or missing references)
//IL_0051: Expected O, but got Unknown
//IL_0062: Unknown result type (might be due to invalid IL or missing references)
//IL_006c: Expected O, but got Unknown
NetworkManager.__rpc_func_table.Add(3317637825u, new RpcReceiveHandler(__rpc_handler_3317637825));
NetworkManager.__rpc_func_table.Add(3529891776u, new RpcReceiveHandler(__rpc_handler_3529891776));
NetworkManager.__rpc_func_table.Add(874432910u, new RpcReceiveHandler(__rpc_handler_874432910));
NetworkManager.__rpc_func_table.Add(2257449764u, new RpcReceiveHandler(__rpc_handler_2257449764));
}
private static void __rpc_handler_3317637825(NetworkBehaviour target, FastBufferReader reader, __RpcParams rpcParams)
{
//IL_0036: Unknown result type (might be due to invalid IL or missing references)
//IL_0041: Unknown result type (might be due to invalid IL or missing references)
//IL_0050: Unknown result type (might be due to invalid IL or missing references)
NetworkManager networkManager = target.NetworkManager;
if (networkManager != null && networkManager.IsListening)
{
Vector3 position = default(Vector3);
((FastBufferReader)(ref reader)).ReadValueSafe(ref position);
target.__rpc_exec_stage = (__RpcExecStage)1;
((LastResortHandler)(object)target).ExplodePositionServerRpc(position);
target.__rpc_exec_stage = (__RpcExecStage)0;
}
}
private static void __rpc_handler_3529891776(NetworkBehaviour target, FastBufferReader reader, __RpcParams rpcParams)
{
//IL_0036: Unknown result type (might be due to invalid IL or missing references)
//IL_0041: Unknown result type (might be due to invalid IL or missing references)
//IL_0050: Unknown result type (might be due to invalid IL or missing references)
NetworkManager networkManager = target.NetworkManager;
if (networkManager != null && networkManager.IsListening)
{
Vector3 position = default(Vector3);
((FastBufferReader)(ref reader)).ReadValueSafe(ref position);
target.__rpc_exec_stage = (__RpcExecStage)2;
((LastResortHandler)(object)target).ExplodePositionClientRpc(position);
target.__rpc_exec_stage = (__RpcExecStage)0;
}
}
private static void __rpc_handler_874432910(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_006e: 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_008c: Unknown result type (might be due to invalid IL or missing references)
NetworkManager networkManager = target.NetworkManager;
if (networkManager != null && networkManager.IsListening)
{
bool flag = default(bool);
((FastBufferReader)(ref reader)).ReadValueSafe<bool>(ref flag, default(ForPrimitives));
string username = null;
if (flag)
{
((FastBufferReader)(ref reader)).ReadValueSafe(ref username, false);
}
Vector3 position = default(Vector3);
((FastBufferReader)(ref reader)).ReadValueSafe(ref position);
target.__rpc_exec_stage = (__RpcExecStage)1;
((LastResortHandler)(object)target).PlayExplosionSoundServerRpc(username, position);
target.__rpc_exec_stage = (__RpcExecStage)0;
}
}
private static void __rpc_handler_2257449764(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_006e: 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_008c: Unknown result type (might be due to invalid IL or missing references)
NetworkManager networkManager = target.NetworkManager;
if (networkManager != null && networkManager.IsListening)
{
bool flag = default(bool);
((FastBufferReader)(ref reader)).ReadValueSafe<bool>(ref flag, default(ForPrimitives));
string username = null;
if (flag)
{
((FastBufferReader)(ref reader)).ReadValueSafe(ref username, false);
}
Vector3 position = default(Vector3);
((FastBufferReader)(ref reader)).ReadValueSafe(ref position);
target.__rpc_exec_stage = (__RpcExecStage)2;
((LastResortHandler)(object)target).PlayExplosionSoundClientRpc(username, position);
target.__rpc_exec_stage = (__RpcExecStage)0;
}
}
protected internal override string __getTypeName()
{
return "LastResortHandler";
}
}
[HarmonyPatch(typeof(GameNetworkManager))]
internal class GameNetworkManagerPatch
{
public static AssetBundle LastResortAssetBundle;
public static GameObject LastResortNetworkPrefab;
[HarmonyPatch("Start")]
[HarmonyPostfix]
public static void Init()
{
LastResortMod.Log.LogInfo((object)"GameNetworkManager Start");
LastResortAssetBundle = AssetBundle.LoadFromStream(Assembly.GetExecutingAssembly().GetManifestResourceStream("LastResort.lastresortasset"));
LastResortNetworkPrefab = LastResortAssetBundle.LoadAsset<GameObject>("assets/lastresort/lastresortnetwork.prefab");
LastResortNetworkPrefab.AddComponent<LastResortHandler>();
NetworkManager.Singleton.AddNetworkPrefab(LastResortNetworkPrefab);
}
}
[HarmonyPatch(typeof(StartOfRound))]
internal class StartOfRoundPatch
{
[HarmonyPatch("Start")]
[HarmonyPostfix]
public static void SpawnNetworkHandler()
{
//IL_0034: Unknown result type (might be due to invalid IL or missing references)
//IL_0039: Unknown result type (might be due to invalid IL or missing references)
LastResortMod.Log.LogInfo((object)"StartOfRound Start");
if (NetworkManager.Singleton.IsHost || NetworkManager.Singleton.IsServer)
{
GameObject val = Object.Instantiate<GameObject>(GameNetworkManagerPatch.LastResortNetworkPrefab, Vector3.zero, Quaternion.identity);
val.GetComponent<NetworkObject>().Spawn(false);
}
}
}
}