using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Configuration;
using GameNetcodeStuff;
using HarmonyLib;
using Microsoft.CodeAnalysis;
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: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("LethalCompanyPlugin")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyDescription("My first plugin")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("LethalCompanyPlugin")]
[assembly: AssemblyTitle("LethalCompanyPlugin")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.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 LethalCompanyPlugin
{
public static class PluginInfo
{
public const string PLUGIN_GUID = "LethalCompanyPlugin";
public const string PLUGIN_NAME = "LethalCompanyPlugin";
public const string PLUGIN_VERSION = "1.0.0";
}
}
namespace GilbyMod
{
public enum ActionID
{
Flashlight,
Slot0,
Slot1,
Slot2,
Slot3,
Emote1,
Emote2,
Walkie
}
public sealed class BindableAction
{
public static Dictionary<string, BindableAction> ActionDictionary = new Dictionary<string, BindableAction>();
public static List<BindableAction> ActionList = new List<BindableAction>();
public ActionID Id { get; }
public Key Hotkey { get; }
public string Description { get; }
public ConfigEntry<Key> ConfigEntry { get; set; }
private BindableAction(ActionID id, Key hotkey, string description)
{
//IL_0010: Unknown result type (might be due to invalid IL or missing references)
//IL_0011: Unknown result type (might be due to invalid IL or missing references)
Id = id;
Hotkey = hotkey;
Description = description;
}
public static void Create(ActionID id, Key hotkey, string description)
{
//IL_0002: Unknown result type (might be due to invalid IL or missing references)
//IL_002e: Unknown result type (might be due to invalid IL or missing references)
//IL_0077: Unknown result type (might be due to invalid IL or missing references)
BindableAction bindableAction = new BindableAction(id, hotkey, description);
ConfigEntry<Key> configEntry = ((BaseUnityPlugin)Plugin.Instance).Config.Bind<Key>("Bindings", bindableAction.Id.ToString(), bindableAction.Hotkey, bindableAction.Description);
bindableAction.ConfigEntry = configEntry;
ActionDictionary.Add(id.ToString(), bindableAction);
ActionList.Add(bindableAction);
Debug.Log((object)$"{id} bound to {hotkey}");
}
}
[BepInPlugin("GilbyMod", "GilbyMod", "1.1.0")]
public class Plugin : BaseUnityPlugin
{
public static class PluginInfo
{
public const string PLUGIN_GUID = "GilbyMod";
public const string PLUGIN_NAME = "GilbyMod";
public const string PLUGIN_VERSION = "1.1.0";
}
public static Plugin Instance;
private static readonly Dictionary<string, MethodInfo> MethodCache = new Dictionary<string, MethodInfo>();
private static readonly Dictionary<string, FieldInfo> FieldCache = new Dictionary<string, FieldInfo>();
private static readonly object[] backwardsParam = new object[1] { false };
private static readonly object[] forwardsParam = new object[1] { true };
private void Awake()
{
//IL_008f: Unknown result type (might be due to invalid IL or missing references)
//IL_0095: Expected O, but got Unknown
if ((Object)(object)Instance == (Object)null)
{
Instance = this;
BindableAction.Create(ActionID.Slot0, (Key)41, "Your first item slot");
BindableAction.Create(ActionID.Slot1, (Key)42, "Your second item slot");
BindableAction.Create(ActionID.Slot2, (Key)43, "Your third item slot");
BindableAction.Create(ActionID.Slot3, (Key)44, "Your fourth item slot");
BindableAction.Create(ActionID.Flashlight, (Key)20, "Toggle your held flashlight on/off");
BindableAction.Create(ActionID.Emote1, (Key)94, "Dance");
BindableAction.Create(ActionID.Emote2, (Key)95, "Point");
BindableAction.Create(ActionID.Walkie, (Key)32, "Walkie");
Harmony val = new Harmony("GTweaking");
val.PatchAll(typeof(Plugin));
Debug.Log((object)"GilbyMod loaded");
return;
}
throw new Exception("Multiple versions of GilbyMod!!!");
}
[HarmonyPatch(typeof(PlayerControllerB), "Update")]
[HarmonyPostfix]
public static void ReadInput(PlayerControllerB __instance)
{
//IL_02a8: Unknown result type (might be due to invalid IL or missing references)
//IL_02b3: Expected O, but got Unknown
//IL_02e5: Unknown result type (might be due to invalid IL or missing references)
//IL_02f0: Expected O, but got Unknown
//IL_034a: Unknown result type (might be due to invalid IL or missing references)
//IL_0355: Expected O, but got Unknown
//IL_0384: Unknown result type (might be due to invalid IL or missing references)
//IL_038f: Expected O, but got Unknown
if ((!((NetworkBehaviour)__instance).IsOwner || !__instance.isPlayerControlled || (((NetworkBehaviour)__instance).IsServer && !__instance.isHostPlayerObject)) && !__instance.isTestingPlayer)
{
return;
}
List<BindableAction> list = BindableAction.ActionDictionary.Values.Where((BindableAction boundAction) => ((ButtonControl)Keyboard.current[boundAction.ConfigEntry.Value]).wasPressedThisFrame).ToList();
List<BindableAction> list2 = BindableAction.ActionDictionary.Values.Where((BindableAction boundAction) => ((ButtonControl)Keyboard.current[boundAction.ConfigEntry.Value]).wasReleasedThisFrame).ToList();
GrabbableObject val = null;
for (int i = 0; i < __instance.ItemSlots.Length; i++)
{
if (__instance.ItemSlots[i] is WalkieTalkie && __instance.ItemSlots[i].isBeingUsed)
{
val = __instance.ItemSlots[i];
}
}
foreach (BindableAction item in list)
{
switch (item.Id)
{
case ActionID.Flashlight:
if (__instance.currentlyHeldObjectServer is FlashlightItem && (Object)(object)__instance.currentlyHeldObjectServer != (Object)(object)__instance.pocketedFlashlight)
{
__instance.pocketedFlashlight = __instance.currentlyHeldObjectServer;
}
if (!(__instance.pocketedFlashlight is FlashlightItem) || !__instance.pocketedFlashlight.isHeld)
{
return;
}
__instance.pocketedFlashlight.UseItemOnClient(true);
if (!(__instance.currentlyHeldObjectServer is FlashlightItem))
{
GrabbableObject pocketedFlashlight = __instance.pocketedFlashlight;
FlashlightItem val2 = (FlashlightItem)(object)((pocketedFlashlight is FlashlightItem) ? pocketedFlashlight : null);
((Behaviour)val2.flashlightBulbGlow).enabled = false;
((Behaviour)val2.flashlightBulb).enabled = false;
if (((GrabbableObject)val2).isBeingUsed)
{
((Behaviour)__instance.helmetLight).enabled = true;
val2.usingPlayerHelmetLight = true;
val2.PocketFlashlightServerRpc(true);
}
else
{
((Behaviour)__instance.helmetLight).enabled = false;
val2.usingPlayerHelmetLight = false;
val2.PocketFlashlightServerRpc(false);
}
}
break;
case ActionID.Slot0:
StopEmotes(__instance);
SwitchToSlot(__instance, 0);
break;
case ActionID.Slot1:
StopEmotes(__instance);
SwitchToSlot(__instance, 1);
break;
case ActionID.Slot2:
StopEmotes(__instance);
SwitchToSlot(__instance, 2);
break;
case ActionID.Slot3:
StopEmotes(__instance);
SwitchToSlot(__instance, 3);
break;
case ActionID.Emote1:
PerformEmote(__instance, 1);
break;
case ActionID.Emote2:
PerformEmote(__instance, 2);
break;
case ActionID.Walkie:
if ((Object)val == (Object)null)
{
return;
}
if (__instance.currentlyHeldObjectServer is WalkieTalkie)
{
__instance.currentlyHeldObjectServer.UseItemOnClient(true);
}
else if ((Object)val != (Object)null)
{
val.UseItemOnClient(true);
}
break;
}
}
foreach (BindableAction item2 in list2)
{
ActionID id = item2.Id;
ActionID actionID = id;
if (actionID == ActionID.Walkie)
{
if ((Object)val == (Object)null)
{
break;
}
if (__instance.currentlyHeldObjectServer is WalkieTalkie)
{
__instance.currentlyHeldObjectServer.UseItemOnClient(false);
}
else if ((Object)val != (Object)null)
{
val.UseItemOnClient(false);
}
}
}
}
private static void SwitchToSlot(PlayerControllerB __instance, int requestedSlot)
{
if (!CanSwap(__instance) || __instance.currentItemSlot == requestedSlot)
{
return;
}
ShipBuildModeManager.Instance.CancelBuildMode(true);
__instance.playerBodyAnimator.SetBool("GrabValidated", false);
int num = __instance.currentItemSlot - requestedSlot;
if (num > 0)
{
if (num == 3)
{
GetPrivateMethod("SwitchItemSlotsServerRpc").Invoke(__instance, forwardsParam);
}
else
{
do
{
GetPrivateMethod("SwitchItemSlotsServerRpc").Invoke(__instance, backwardsParam);
num--;
}
while (num != 0);
}
}
else if (num == -3)
{
GetPrivateMethod("SwitchItemSlotsServerRpc").Invoke(__instance, backwardsParam);
}
else
{
do
{
GetPrivateMethod("SwitchItemSlotsServerRpc").Invoke(__instance, forwardsParam);
num++;
}
while (num != 0);
}
object[] parameters = new object[2]
{
requestedSlot,
__instance.ItemSlots[requestedSlot]
};
GetPrivateMethod("SwitchToItemSlot").Invoke(__instance, parameters);
if ((Object)(object)__instance.currentlyHeldObjectServer != (Object)null)
{
((Component)__instance.currentlyHeldObjectServer).gameObject.GetComponent<AudioSource>().PlayOneShot(__instance.currentlyHeldObjectServer.itemProperties.grabSFX, 0.6f);
}
GetPrivateField("timeSinceSwitchingSlots").SetValue(__instance, 0f);
}
private static void PerformEmote(PlayerControllerB __instance, int emoteId)
{
__instance.timeSinceStartingEmote = 0f;
__instance.performingEmote = true;
__instance.playerBodyAnimator.SetInteger("emoteNumber", emoteId);
__instance.StartPerformingEmoteServerRpc();
}
private static MethodInfo GetPrivateMethod(string name)
{
if (MethodCache.TryGetValue(name, out var value))
{
return value;
}
value = typeof(PlayerControllerB).GetMethod(name, BindingFlags.Instance | BindingFlags.NonPublic);
if (value == null)
{
NullReferenceException ex = new NullReferenceException("Method " + name + " could not be found!");
Debug.LogException((Exception)ex);
throw ex;
}
MethodCache[name] = value;
return value;
}
private static FieldInfo GetPrivateField(string name)
{
if (FieldCache.TryGetValue(name, out var value))
{
return value;
}
value = typeof(PlayerControllerB).GetField(name, BindingFlags.Instance | BindingFlags.NonPublic);
if (value == null)
{
NullReferenceException ex = new NullReferenceException("Field " + name + " could not be found!");
Debug.LogException((Exception)ex);
throw ex;
}
FieldCache[name] = value;
return value;
}
private static bool CanSwap(PlayerControllerB __instance)
{
float num = (float)GetPrivateField("timeSinceSwitchingSlots").GetValue(__instance);
bool flag = (bool)GetPrivateField("throwingObject").GetValue(__instance);
return !((double)num < 0.01 || __instance.inTerminalMenu || __instance.isGrabbingObjectAnimation || __instance.inSpecialInteractAnimation || flag) && !__instance.isTypingChat && !__instance.twoHanded && !__instance.activatingItem && !__instance.jetpackControls && !__instance.disablingJetpackControls;
}
private static void StopEmotes(PlayerControllerB __instance)
{
__instance.performingEmote = false;
__instance.StopPerformingEmoteServerRpc();
__instance.timeSinceStartingEmote = 0f;
}
}
}