using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Logging;
using HPAModSuite.Patches;
using HarmonyLib;
using UnityEngine;
using UnityEngine.InputSystem;
[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: AssemblyTitle("HPAModSuite")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("HPAModSuite")]
[assembly: AssemblyCopyright("Copyright © 2023")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("93345dd0-198c-4a88-a52e-d3ecd8bb70df")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")]
[assembly: AssemblyVersion("1.0.0.0")]
namespace HPAModSuite
{
[BepInPlugin("danbean.HPAModSuite", "HPA Mod Suite", "0.0.0.1")]
public class HpaModSuiteBase : BaseUnityPlugin
{
private const string modGUID = "danbean.HPAModSuite";
private const string modName = "HPA Mod Suite";
private const string modVersion = "0.0.0.1";
private readonly Harmony harmony = new Harmony("danbean.HPAModSuite");
public static HpaModSuiteBase BaseInstance;
public ManualLogSource logger;
private void Awake()
{
if ((Object)(object)BaseInstance == (Object)null)
{
BaseInstance = this;
}
harmony.PatchAll(typeof(HpaModSuiteBase));
harmony.PatchAll(typeof(HPATerminal));
logger = Logger.CreateLogSource("danbean.HPAModSuite");
logger.LogMessage((object)"HPA Mod Suite up and running!");
}
public static void LogError(string error)
{
BaseInstance.logger.LogError((object)error);
}
public static void LogInfo(string info)
{
BaseInstance.logger.LogInfo((object)info);
}
public static void LogDebugInfo(string debugInfo)
{
}
}
}
namespace HPAModSuite.Patches
{
[HarmonyPatch(typeof(Terminal))]
internal class HPATerminal
{
private static readonly string[] players = new string[8] { "1", "2", "3", "4", "5", "6", "7", "8" };
private static List<string> history = new List<string>();
private static int historyOffset;
private static InputAction prevCommand;
private static InputAction nextCommand;
[HarmonyPatch("Start")]
[HarmonyPostfix]
private static void AssignInputActions()
{
//IL_000e: Unknown result type (might be due to invalid IL or missing references)
//IL_0018: Expected O, but got Unknown
//IL_0026: Unknown result type (might be due to invalid IL or missing references)
//IL_0030: Expected O, but got Unknown
prevCommand = new InputAction("previousCommand", (InputActionType)1, "<Keyboard>/upArrow", (string)null, (string)null, (string)null);
nextCommand = new InputAction("nextCommand", (InputActionType)1, "<Keyboard>/downArrow", (string)null, (string)null, (string)null);
prevCommand.Enable();
nextCommand.Enable();
}
[HarmonyPatch("OnSubmit")]
[HarmonyPrefix]
private static bool SubmitPrefix(ref string ___currentText, ref int ___textAdded, Terminal __instance)
{
string text = ___currentText.Substring(___currentText.Length - ___textAdded);
if (___textAdded == 1)
{
for (int i = 0; i < players.Length; i++)
{
ManualCameraRenderer mapScreen = StartOfRound.Instance.mapScreen;
if (text == players[i])
{
HpaModSuiteBase.LogDebugInfo("Received input: " + text);
mapScreen.SwitchRadarTargetAndSync(i);
if (mapScreen.radarTargets.Count > i)
{
HpaModSuiteBase.LogDebugInfo("Switching mapScreen to player " + mapScreen.radarTargets[i]?.name);
}
}
}
}
else
{
HpaModSuiteBase.LogDebugInfo(text + " added to history");
history.Add(text);
historyOffset = 0;
}
return true;
}
[HarmonyPatch("Update")]
[HarmonyPostfix]
private static void DetectUpAndDown(Terminal __instance)
{
if (!__instance.terminalInUse)
{
return;
}
if (prevCommand.triggered)
{
historyOffset = Math.Min(history.Count, historyOffset + 1);
string text = history[history.Count - historyOffset];
__instance.currentText = __instance.currentText.Substring(0, __instance.currentText.Length - __instance.textAdded) + text;
__instance.textAdded = text.Length;
__instance.screenText.text = __instance.currentText;
}
else if (nextCommand.triggered)
{
historyOffset = Math.Max(0, historyOffset - 1);
string text2 = history[history.Count - historyOffset];
__instance.currentText = __instance.currentText.Substring(0, __instance.currentText.Length - __instance.textAdded);
if (historyOffset != 0)
{
__instance.currentText += text2;
__instance.textAdded = text2.Length;
}
else
{
__instance.textAdded = 0;
}
__instance.screenText.text = __instance.currentText;
}
}
}
}