using System;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using GameNetcodeStuff;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using UnityEngine;
[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("TermSpeak")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyDescription("Automatically speak on talkie-walkies in your inventory while you're in the terminal")]
[assembly: AssemblyFileVersion("1.1.0.0")]
[assembly: AssemblyInformationalVersion("1.1.0")]
[assembly: AssemblyProduct("TermSpeak")]
[assembly: AssemblyTitle("TermSpeak")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.1.0.0")]
[module: UnverifiableCode]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
[CompilerGenerated]
[Microsoft.CodeAnalysis.Embedded]
internal sealed class EmbeddedAttribute : Attribute
{
}
}
namespace System.Runtime.CompilerServices
{
[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 TermMacros
{
[BepInPlugin("me.kdcf.termspeak", "TermSpeak", "1.1.0")]
[BepInProcess("Lethal Company.exe")]
[HarmonyPatch(typeof(Terminal))]
public class TermSpeak : BaseUnityPlugin
{
private static ConfigEntry<bool> needWalkieInHand;
private Harmony _harmony = new Harmony("me.kdcf.termspeak");
private static ManualLogSource _log = Logger.CreateLogSource("TermSpeak");
private void Awake()
{
needWalkieInHand = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "needWalkieInHand", false, "If set to 'true', you must have the walkie in your hand to activate it. If set to 'false', it only needs to be in your inventory.");
((BaseUnityPlugin)this).Logger.LogInfo((object)"Plugin me.kdcf.termspeak is loaded!");
_harmony.PatchAll(typeof(TermSpeak));
}
[HarmonyPatch("BeginUsingTerminal")]
[HarmonyPostfix]
public static void OpenTerminal(Terminal __instance)
{
SetWalkieMode(enabled: true);
}
[HarmonyPatch("QuitTerminal")]
[HarmonyPostfix]
public static void CloseTerminal(Terminal __instance)
{
SetWalkieMode(enabled: false);
}
public static void SetWalkieMode(bool enabled)
{
_log.LogInfo((object)"Terminal opened! Trying to find walkie talkie...");
PlayerControllerB localPlayerController = GameNetworkManager.Instance.localPlayerController;
_log.LogInfo((object)$"There are {localPlayerController.ItemSlots.Length} item slots to check.");
GrabbableObject val = null;
if (!needWalkieInHand.Value)
{
for (int i = 0; i < localPlayerController.ItemSlots.Length; i++)
{
if (localPlayerController.ItemSlots[i] is WalkieTalkie && (!enabled || localPlayerController.ItemSlots[i].isBeingUsed))
{
val = localPlayerController.ItemSlots[i];
break;
}
}
}
else
{
_log.LogInfo((object)"Terminal opened! Checking for walkie talkie...");
if (localPlayerController.ItemSlots[localPlayerController.currentItemSlot] is WalkieTalkie && (!enabled || localPlayerController.ItemSlots[localPlayerController.currentItemSlot].isBeingUsed))
{
val = localPlayerController.ItemSlots[localPlayerController.currentItemSlot];
}
}
if ((Object)(object)val == (Object)null)
{
_log.LogInfo((object)"No walkie talkie found!");
return;
}
_log.LogInfo((object)"Found walkie talkie! Trying to set its mode...");
val.UseItemOnClient(enabled);
}
}
public static class PluginInfo
{
public const string PLUGIN_GUID = "TermSpeak";
public const string PLUGIN_NAME = "TermSpeak";
public const string PLUGIN_VERSION = "1.1.0";
}
}