using System;
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 BepInEx.Logging;
using GameNetcodeStuff;
using HarmonyLib;
using InteractionControl.Patches;
using Microsoft.CodeAnalysis;
using Unity.Netcode;
using UnityEngine;
using UnityEngine.InputSystem;
using UnityEngine.UI;
[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: IgnoresAccessChecksTo("Assembly-CSharp")]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("InteractionControl")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0+89fb35a24dc9c694d25f2eb4edb6c51dc9d5da87")]
[assembly: AssemblyProduct("InteractionControl")]
[assembly: AssemblyTitle("InteractionControl")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
[module: UnverifiableCode]
namespace Microsoft.CodeAnalysis
{
[CompilerGenerated]
[Microsoft.CodeAnalysis.Embedded]
internal sealed class EmbeddedAttribute : Attribute
{
}
}
namespace System.Runtime.CompilerServices
{
[CompilerGenerated]
[Microsoft.CodeAnalysis.Embedded]
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Event | AttributeTargets.Parameter | AttributeTargets.ReturnValue | AttributeTargets.GenericParameter, AllowMultiple = false, Inherited = false)]
internal sealed class NullableAttribute : Attribute
{
public readonly byte[] NullableFlags;
public NullableAttribute(byte P_0)
{
NullableFlags = new byte[1] { P_0 };
}
public NullableAttribute(byte[] P_0)
{
NullableFlags = P_0;
}
}
[CompilerGenerated]
[Microsoft.CodeAnalysis.Embedded]
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Method | AttributeTargets.Interface | AttributeTargets.Delegate, AllowMultiple = false, Inherited = false)]
internal sealed class NullableContextAttribute : Attribute
{
public readonly byte Flag;
public NullableContextAttribute(byte P_0)
{
Flag = P_0;
}
}
}
[HarmonyPatch(typeof(NetworkManager))]
internal static class KickIfModNotInstalled
{
private static readonly string MOD_GUID = "com.jacobot5.InteractionControl";
[HarmonyPostfix]
[HarmonyPatch("SetSingleton")]
private static void RegisterPrefab()
{
//IL_000f: Unknown result type (might be due to invalid IL or missing references)
//IL_0015: Expected O, but got Unknown
//IL_0017: Unknown result type (might be due to invalid IL or missing references)
//IL_001e: Unknown result type (might be due to invalid IL or missing references)
GameObject val = new GameObject(MOD_GUID + " Prefab");
((Object)val).hideFlags = (HideFlags)(((Object)val).hideFlags | 0x3D);
Object.DontDestroyOnLoad((Object)(object)val);
NetworkObject obj = val.AddComponent<NetworkObject>();
typeof(NetworkObject).GetField("GlobalObjectIdHash", BindingFlags.Instance | BindingFlags.NonPublic).SetValue(obj, GetHash(MOD_GUID));
NetworkManager.Singleton.PrefabHandler.AddNetworkPrefab(val);
static uint GetHash(string value)
{
return value?.Aggregate(17u, (uint current, char c) => (current * 31) ^ c) ?? 0;
}
}
}
namespace InteractionControl
{
[BepInPlugin("com.jacobot5.InteractionControl", "InteractionControl", "1.2.0")]
public class InteractionControlMod : BaseUnityPlugin
{
public const string modGUID = "com.jacobot5.InteractionControl";
public const string modName = "InteractionControl";
public const string modVersion = "1.2.0";
private readonly Harmony harmony = new Harmony("com.jacobot5.InteractionControl");
private static InteractionControlMod Instance;
public static ConfigEntry<bool> configGrabWithJetpack;
public static ConfigEntry<bool> configTriggerWithJetpack;
public static ConfigEntry<bool> configSwitchSlotsWithJetpack;
public static ManualLogSource mls;
private void Awake()
{
if ((Object)(object)Instance == (Object)null)
{
Instance = this;
}
mls = Logger.CreateLogSource("com.jacobot5.InteractionControl");
mls.LogInfo((object)"InteractionControl has awoken.");
configGrabWithJetpack = ((BaseUnityPlugin)this).Config.Bind<bool>("Jetpack", "GrabWithJetpack", false, "Whether to enable grabbing objects while in jetpack control mode");
configSwitchSlotsWithJetpack = ((BaseUnityPlugin)this).Config.Bind<bool>("Jetpack", "SwitchSlotsWithJetpack", false, "Whether to enable switching item slots while in jetpack control mode (RECOMMENDED to enable if using GrabWithJetpack)");
configTriggerWithJetpack = ((BaseUnityPlugin)this).Config.Bind<bool>("Jetpack", "TriggerWithJetpack", false, "Whether to enable triggering things while in jetpack control mode (IGNORE unless you have issues)");
harmony.PatchAll(typeof(InteractionControlMod));
harmony.PatchAll(typeof(PlayerControllerBPatch));
harmony.PatchAll(typeof(KickIfModNotInstalled));
}
}
}
namespace InteractionControl.Patches
{
[HarmonyPatch(typeof(PlayerControllerB))]
internal class PlayerControllerBPatch
{
[HarmonyPatch("Interact_performed")]
[HarmonyPrefix]
private static bool GrabPatch(PlayerControllerB __instance, ref CallbackContext context)
{
if (((NetworkBehaviour)__instance).IsOwner && __instance.isPlayerDead && (!((NetworkBehaviour)__instance).IsServer || __instance.isHostPlayerObject))
{
if (!StartOfRound.Instance.overrideSpectateCamera && (Object)(object)__instance.spectatedPlayerScript != (Object)null && !__instance.spectatedPlayerScript.isPlayerDead)
{
__instance.SpectateNextPlayer(false);
}
}
else
{
if (((!((NetworkBehaviour)__instance).IsOwner || !__instance.isPlayerControlled || (((NetworkBehaviour)__instance).IsServer && !__instance.isHostPlayerObject)) && !__instance.isTestingPlayer) || !((CallbackContext)(ref context)).performed || __instance.timeSinceSwitchingSlots < 0.2f || __instance.inSpecialMenu)
{
return false;
}
ShipBuildModeManager.Instance.CancelBuildMode(true);
if (!__instance.isGrabbingObjectAnimation && !__instance.isTypingChat && !__instance.inTerminalMenu && !__instance.throwingObject && !__instance.IsInspectingItem && !((Object)(object)__instance.inAnimationWithEnemy != (Object)null) && (!__instance.jetpackControls || InteractionControlMod.configGrabWithJetpack.Value) && (!__instance.disablingJetpackControls || InteractionControlMod.configGrabWithJetpack.Value) && !StartOfRound.Instance.suckingPlayersOutOfShip)
{
InteractionControlMod.mls.LogInfo((object)"ALLOWED interaction");
if (!__instance.activatingItem && !__instance.waitingToDropItem)
{
__instance.BeginGrabObject();
}
if (!((Object)(object)__instance.hoveringOverTrigger == (Object)null) && !__instance.hoveringOverTrigger.holdInteraction && (!__instance.isHoldingObject || __instance.hoveringOverTrigger.oneHandedItemAllowed) && (!__instance.twoHanded || (__instance.hoveringOverTrigger.twoHandedItemAllowed && !__instance.hoveringOverTrigger.specialCharacterAnimation)) && __instance.InteractTriggerUseConditionsMet())
{
__instance.hoveringOverTrigger.Interact(__instance.thisPlayerBody);
}
}
}
return false;
}
[HarmonyPatch("InteractTriggerUseConditionsMet")]
[HarmonyPrefix]
private static bool TriggerPatch(PlayerControllerB __instance, ref bool __result)
{
if (__instance.sinkingValue > 0.73f)
{
__result = false;
return false;
}
if (__instance.jetpackControls && !InteractionControlMod.configTriggerWithJetpack.Value && (__instance.hoveringOverTrigger.specialCharacterAnimation || __instance.hoveringOverTrigger.isLadder))
{
InteractionControlMod.mls.LogInfo((object)"Blocked interaction while in jetpack mode.");
__result = false;
return false;
}
if (__instance.isClimbingLadder)
{
if (__instance.hoveringOverTrigger.isLadder)
{
if (!__instance.hoveringOverTrigger.usingLadder)
{
__result = false;
return false;
}
}
else if (__instance.hoveringOverTrigger.specialCharacterAnimation)
{
__result = false;
return false;
}
}
else if (__instance.inSpecialInteractAnimation && !__instance.hoveringOverTrigger.allowUseWhileInAnimation)
{
__result = false;
return false;
}
if (__instance.disableInteract)
{
__result = false;
return false;
}
if (__instance.hoveringOverTrigger.isPlayingSpecialAnimation)
{
__result = false;
return false;
}
__result = true;
return false;
}
[HarmonyPatch("ScrollMouse_performed")]
[HarmonyPrefix]
private static bool ScrollMousePatch(PlayerControllerB __instance, ref CallbackContext context)
{
if (__instance.inTerminalMenu)
{
float num = ((CallbackContext)(ref context)).ReadValue<float>();
Scrollbar terminalScrollVertical = __instance.terminalScrollVertical;
terminalScrollVertical.value += num / 3f;
}
else if (((((NetworkBehaviour)__instance).IsOwner && __instance.isPlayerControlled && (!((NetworkBehaviour)__instance).IsServer || __instance.isHostPlayerObject)) || __instance.isTestingPlayer) && !(__instance.timeSinceSwitchingSlots < 0.3f) && !__instance.isGrabbingObjectAnimation && !__instance.quickMenuManager.isMenuOpen && !__instance.inSpecialInteractAnimation && !__instance.throwingObject && !__instance.isTypingChat && !__instance.twoHanded && !__instance.activatingItem && (!__instance.jetpackControls || InteractionControlMod.configSwitchSlotsWithJetpack.Value) && (!__instance.disablingJetpackControls || InteractionControlMod.configSwitchSlotsWithJetpack.Value))
{
ShipBuildModeManager.Instance.CancelBuildMode(true);
__instance.playerBodyAnimator.SetBool("GrabValidated", false);
if (((CallbackContext)(ref context)).ReadValue<float>() > 0f)
{
__instance.SwitchToItemSlot(__instance.NextItemSlot(true), (GrabbableObject)null);
__instance.SwitchItemSlotsServerRpc(true);
}
else
{
__instance.SwitchToItemSlot(__instance.NextItemSlot(false), (GrabbableObject)null);
__instance.SwitchItemSlotsServerRpc(false);
}
if ((Object)(object)__instance.currentlyHeldObjectServer != (Object)null)
{
((Component)__instance.currentlyHeldObjectServer).gameObject.GetComponent<AudioSource>().PlayOneShot(__instance.currentlyHeldObjectServer.itemProperties.grabSFX, 0.6f);
}
__instance.timeSinceSwitchingSlots = 0f;
}
return false;
}
}
}
namespace System.Runtime.CompilerServices
{
[AttributeUsage(AttributeTargets.Assembly, AllowMultiple = true)]
internal sealed class IgnoresAccessChecksToAttribute : Attribute
{
public IgnoresAccessChecksToAttribute(string assemblyName)
{
}
}
}