using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using BepInEx;
using GameNetcodeStuff;
using HarmonyLib;
using TerminalApi;
using TerminalApi.Events;
using UnityEngine;
using UnityEngine.Events;
[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: AssemblyTitle("NexiumTech")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("NexiumTech")]
[assembly: AssemblyCopyright("Copyright © 2023")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("b0fe5129-1447-4aa0-9416-bbb736787bf1")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")]
[assembly: AssemblyVersion("1.0.0.0")]
namespace MoreTerminalCommands;
[BepInPlugin("net.navarrotech.MoreTerminalCommands", "MoreTerminalCommands", "1.0.1")]
[BepInDependency("atomic.terminalapi", "1.2.0")]
public class Plugin : BaseUnityPlugin
{
public const string ModGUID = "net.navarrotech.MoreTerminalCommands";
public const string ModName = "MoreTerminalCommands";
public const string ModVersion = "1.0.1";
private const string TeleportCommand = "teleport";
private const string TeleportCommandAlt = "tp";
private const string TeleportCommandAlt2 = "scotty";
private const string InverseTeleportCommand = "iteleport";
private const string InverseTeleportCommandAlt = "itp";
private const string LightsCommand = "lights";
private const string LightsCommandAlt = "light";
private const string ShipDoorCommand = "shipdoor";
private const string ShipDoorCommandAlt = "door";
private const string LockShipDoorCommand = "lockdoor";
private const string UnlockShipDoorCommand = "unlockdoor";
private const string GreatAssetCommand = "greatasset";
private const string RandomTeleportCommand = "randomtp";
private const string ExplodeCommand = "explode";
private const string TakeoffCommand = "takeoff";
internal bool lockDoor = false;
internal HangarShipDoor door = null;
public void Awake()
{
//IL_0025: Unknown result type (might be due to invalid IL or missing references)
//IL_002f: Expected O, but got Unknown
//IL_0037: Unknown result type (might be due to invalid IL or missing references)
//IL_0041: Expected O, but got Unknown
//IL_0049: Unknown result type (might be due to invalid IL or missing references)
//IL_0053: Expected O, but got Unknown
((BaseUnityPlugin)this).Logger.LogInfo((object)"Plugin net.navarrotech.MoreTerminalCommands is loaded!");
Harmony.CreateAndPatchAll(Assembly.GetExecutingAssembly(), (string)null);
Events.TerminalAwake += new TerminalEventHandler(TerminalIsAwake);
Events.TerminalParsedSentence += new TerminalParseSentenceEventHandler(TextSubmitted);
Events.TerminalBeginUsing += new TerminalEventHandler(OnBeginUsing);
}
[HarmonyPatch("Update")]
[HarmonyPostfix]
public void Update()
{
if (Object.op_Implicit((Object)(object)door) && lockDoor)
{
door.doorPower = 1f;
}
}
private void TerminalIsAwake(object sender, TerminalEventArgs e)
{
((BaseUnityPlugin)this).Logger.LogMessage((object)"Terminal is awake");
TerminalApi.AddCommand("teleport", "Attempting Teleport...\n\n", "tele1", true);
TerminalApi.AddCommand("tp", "Attempting Teleport...\n\n", "tele2", true);
TerminalApi.AddCommand("scotty", "Attempting Teleport...\n\n", "tele2", true);
TerminalApi.AddCommand("iteleport", "Attempting Inverse Teleport...\n\n", "intele", true);
TerminalApi.AddCommand("itp", "Attempting Inverse Teleport...\n\n", "intele", true);
TerminalApi.AddCommand("lights", "Toggling lights...\n\n", "lightswitch1", true);
TerminalApi.AddCommand("light", "Toggling lights...\n\n", "lightswitch2", true);
TerminalApi.AddCommand("shipdoor", "Toggling door...\n\n", "doorhydraulic", true);
TerminalApi.AddCommand("door", "Toggling door...\n\n", "doorhydraulic", true);
TerminalApi.AddCommand("lockdoor", "Locking door...\n\n", "doorhydraulic1", true);
TerminalApi.AddCommand("unlockdoor", "Unlocking ship door...\n\n", "doorhydraulic4", true);
TerminalApi.AddCommand("randomtp", "Attempting random teleport...", "randomteleport", true);
TerminalApi.AddCommand("greatasset", "Welcome...", "greatasset", true);
door = Object.FindObjectOfType<HangarShipDoor>();
}
private ShipTeleporter GetTeleporter(bool selectInverse = false)
{
ShipTeleporter[] array = Object.FindObjectsOfType<ShipTeleporter>();
for (int i = 0; i < array.Length; i++)
{
if (selectInverse == array[i].isInverseTeleporter)
{
return array[i];
}
}
return null;
}
private InteractTrigger GetTrigger(string name)
{
InteractTrigger[] array = Object.FindObjectsOfType<InteractTrigger>();
for (int i = 0; i < array.Length; i++)
{
if (((Object)array[i]).name == name)
{
return array[i];
}
}
return null;
}
private void ToggleShipDoor()
{
HangarShipDoor val = Object.FindObjectOfType<HangarShipDoor>();
if (!((Object)(object)val == (Object)null) && !val.overheated)
{
if (val.doorPower == 1f)
{
((UnityEvent<PlayerControllerB>)(object)val.triggerScript.onInteract).Invoke(GameNetworkManager.Instance.localPlayerController);
}
else
{
((UnityEvent<PlayerControllerB>)(object)val.triggerScript.onStopInteract).Invoke(GameNetworkManager.Instance.localPlayerController);
}
}
}
private Landmine GetLandmine(string tag)
{
Landmine[] array = Object.FindObjectsOfType<Landmine>();
for (int i = 0; i < array.Length; i++)
{
if (((Component)array[i]).tag == tag)
{
return array[i];
}
}
return null;
}
private void ExplodeLandmine(string tag)
{
Landmine landmine = GetLandmine(tag);
if (Object.op_Implicit((Object)(object)landmine) && ((Behaviour)landmine).enabled)
{
landmine.Detonate();
}
}
private void PlayGreatAssetIntro()
{
StartOfRound val = Object.FindObjectOfType<StartOfRound>();
Terminal val2 = Object.FindObjectOfType<Terminal>();
if (!((Object)(object)val == (Object)null) && !((Object)(object)val2 == (Object)null))
{
val2.terminalAudio.PlayOneShot(val.shipIntroSpeechSFX);
}
}
private void TextSubmitted(object sender, TerminalParseSentenceEventArgs e)
{
((BaseUnityPlugin)this).Logger.LogMessage((object)$"Text submitted: {e.SubmittedText} Node Returned: {e.ReturnedNode}");
string text = e.SubmittedText.ToLower();
if (text.StartsWith("explode"))
{
ExplodeLandmine(text.Substring(8));
return;
}
string text2 = text;
string text3 = text2;
if (text3 == null)
{
return;
}
ShipTeleporter teleporter;
ShipTeleporter teleporter2;
switch (text3.Length)
{
default:
return;
case 8:
switch (text3[0])
{
default:
return;
case 't':
break;
case 's':
goto IL_0127;
case 'l':
if (text3 == "lockdoor")
{
HangarShipDoorPatch.SetLocked(locked: true);
}
return;
case 'r':
if (text3 == "randomtp")
{
DoubleTp();
}
return;
}
if (!(text3 == "teleport"))
{
return;
}
goto IL_0245;
case 6:
{
char c = text3[0];
if (c != 'l')
{
if (c != 's' || !(text3 == "scotty"))
{
return;
}
goto IL_0245;
}
if (!(text3 == "lights"))
{
return;
}
break;
}
case 10:
switch (text3[0])
{
case 'u':
if (text3 == "unlockdoor")
{
HangarShipDoorPatch.SetLocked();
}
break;
case 'g':
if (text3 == "greatasset")
{
PlayGreatAssetIntro();
}
break;
}
return;
case 2:
if (!(text3 == "tp"))
{
return;
}
goto IL_0245;
case 9:
if (!(text3 == "iteleport"))
{
return;
}
goto IL_0290;
case 3:
if (!(text3 == "itp"))
{
return;
}
goto IL_0290;
case 7:
if (text3 == "takeoff")
{
InteractTrigger trigger = GetTrigger("StartGameLever");
if ((Object)(object)trigger != (Object)null)
{
((UnityEvent<PlayerControllerB>)(object)trigger.onInteract).Invoke(GameNetworkManager.Instance.localPlayerController);
}
}
return;
case 4:
if (!(text3 == "door"))
{
return;
}
goto IL_0316;
case 5:
{
if (!(text3 == "light"))
{
return;
}
break;
}
IL_0127:
if (!(text3 == "shipdoor"))
{
return;
}
goto IL_0316;
IL_0245:
teleporter = GetTeleporter();
if (Object.op_Implicit((Object)(object)teleporter) && teleporter.buttonTrigger.interactable)
{
((UnityEvent<PlayerControllerB>)(object)teleporter.buttonTrigger.onInteract).Invoke(GameNetworkManager.Instance.localPlayerController);
}
return;
IL_0290:
teleporter2 = GetTeleporter(selectInverse: true);
if (Object.op_Implicit((Object)(object)teleporter2) && teleporter2.buttonTrigger.interactable)
{
((UnityEvent<PlayerControllerB>)(object)teleporter2.buttonTrigger.onInteract).Invoke(GameNetworkManager.Instance.localPlayerController);
}
return;
IL_0316:
ToggleShipDoor();
return;
}
InteractTrigger trigger2 = GetTrigger("LightSwitch");
if (Object.op_Implicit((Object)(object)trigger2))
{
((UnityEvent<PlayerControllerB>)(object)trigger2.onInteract).Invoke(GameNetworkManager.Instance.localPlayerController);
}
}
private IEnumerator DoubleTp()
{
ShipTeleporter regular = GetTeleporter();
ShipTeleporter inverse = GetTeleporter(selectInverse: true);
if ((Object)(object)regular == (Object)null || (Object)(object)inverse == (Object)null)
{
((BaseUnityPlugin)this).Logger.LogDebug((object)"No regular and inverse teleporter owned");
yield return (object)new WaitForSeconds(0f);
}
((UnityEvent<PlayerControllerB>)(object)inverse.buttonTrigger.onInteract).Invoke(GameNetworkManager.Instance.localPlayerController);
yield return (object)new WaitForSeconds(2.5f);
((UnityEvent<PlayerControllerB>)(object)regular.buttonTrigger.onInteract).Invoke(GameNetworkManager.Instance.localPlayerController);
}
private void OnBeginUsing(object sender, TerminalEventArgs e)
{
((BaseUnityPlugin)this).Logger.LogMessage((object)"Player has just started using the terminal");
List<GrabbableObject> list = new List<GrabbableObject>();
GrabbableObject[] array = Object.FindObjectsOfType<GrabbableObject>();
int num = 0;
for (int i = 0; i < array.Length; i++)
{
if (array[i].itemProperties.isScrap && !array[i].scrapPersistedThroughRounds && !array[i].isInShipRoom)
{
list.Add(array[i]);
num += array[i].scrapValue;
}
}
string text = string.Join("\n", list.Select((GrabbableObject x) => x.itemProperties.itemName + " : " + x.scrapValue + " Value"));
string text2 = "Items not in ship: " + list.Count() + "\n\n" + text + "\n\nWith a total value of: " + num + "\n\n";
}
}
[HarmonyPatch(typeof(HangarShipDoor))]
internal class HangarShipDoorPatch
{
public static bool keepLocked;
[HarmonyPatch("Update")]
[HarmonyPostfix]
private static void DoorUpdate(ref float ___doorPower, ref bool ___overheated, ref float ___doorPowerDuration)
{
if (keepLocked)
{
___doorPower = 1f;
___overheated = false;
___doorPowerDuration = 0f;
}
else
{
___doorPowerDuration = 20f;
}
}
public static void SetLocked(bool locked = false)
{
keepLocked = locked;
}
}