Decompiled source of remote mod v1.0.8

plugins/remote_mod.dll

Decompiled 5 days ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;
using System.Reflection.Emit;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Configuration;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using UnityEngine;
using UnityEngine.InputSystem;
using Zorro.Core;

[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("remote_mod")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyDescription("remote_mod by 91Kitty")]
[assembly: AssemblyFileVersion("1.0.7.0")]
[assembly: AssemblyInformationalVersion("1.0.7")]
[assembly: AssemblyProduct("remote_mod")]
[assembly: AssemblyTitle("remote_mod")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.7.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;
		}
	}
}
[BepInPlugin("com.Kitty.remote", "remote", "1.0.7")]
public class remote : BaseUnityPlugin
{
	[HarmonyPatch(typeof(MainCameraMovement), "LateUpdate")]
	private class CameraMovementPatch
	{
		private static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstruction> instructions)
		{
			//IL_00ae: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b4: Expected O, but got Unknown
			//IL_00bc: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c2: Expected O, but got Unknown
			List<CodeInstruction> list = new List<CodeInstruction>(instructions);
			FieldInfo fieldInfo = AccessTools.Field(typeof(Character), "localCharacter");
			FieldInfo fieldInfo2 = AccessTools.Field(typeof(Character), "data");
			FieldInfo fieldInfo3 = AccessTools.Field(typeof(CharacterData), "fullyPassedOut");
			MethodInfo methodInfo = AccessTools.Method(typeof(remote), "IsRemoteModeActive", (Type[])null, (Type[])null);
			for (int i = 0; i < list.Count - 4; i++)
			{
				if (CodeInstructionExtensions.LoadsField(list[i], fieldInfo, false) && CodeInstructionExtensions.LoadsField(list[i + 1], fieldInfo2, false) && CodeInstructionExtensions.LoadsField(list[i + 2], fieldInfo3, false))
				{
					list.InsertRange(i + 3, (IEnumerable<CodeInstruction>)(object)new CodeInstruction[2]
					{
						new CodeInstruction(OpCodes.Call, (object)methodInfo),
						new CodeInstruction(OpCodes.Or, (object)null)
					});
					break;
				}
			}
			return list;
		}
	}

	[HarmonyPatch(typeof(CharacterInput), "Sample")]
	private class InputHandlerPatch
	{
		private static void Prefix(ref bool playerMovementActive)
		{
			if (IsRemoteModeActive())
			{
				playerMovementActive = true;
			}
		}

		private static void Postfix(CharacterInput __instance)
		{
			//IL_0028: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a3: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a8: Unknown result type (might be due to invalid IL or missing references)
			//IL_0196: Unknown result type (might be due to invalid IL or missing references)
			//IL_019b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0210: Unknown result type (might be due to invalid IL or missing references)
			if (!IsRemoteModeActive())
			{
				return;
			}
			FieldInfo fieldInfo = AccessTools.Field(typeof(CharacterInput), "moveInput");
			if (fieldInfo != null)
			{
				fieldInfo.SetValue(__instance, Vector2.zero);
			}
			__instance.jumpWasPressed = false;
			__instance.sprintWasPressed = false;
			__instance.crouchWasPressed = false;
			FieldInfo fieldInfo2 = AccessTools.Field(typeof(CharacterInput), "proneWasPressed");
			if (fieldInfo2 != null && fieldInfo2.FieldType == typeof(bool))
			{
				fieldInfo2.SetValue(__instance, false);
			}
			FieldInfo[] fields = typeof(CharacterInput).GetFields(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
			foreach (FieldInfo fieldInfo3 in fields)
			{
				if (fieldInfo3.Name.Contains("move") || fieldInfo3.Name.Contains("Jump") || fieldInfo3.Name.Contains("Sprint") || fieldInfo3.Name.Contains("Crouch") || fieldInfo3.Name.Contains("Prone"))
				{
					if (fieldInfo3.FieldType == typeof(bool))
					{
						fieldInfo3.SetValue(__instance, false);
					}
					else if (fieldInfo3.FieldType == typeof(Vector2) || fieldInfo3.FieldType == typeof(Vector3))
					{
						fieldInfo3.SetValue(__instance, Activator.CreateInstance(fieldInfo3.FieldType));
					}
				}
			}
			if (CharacterInput.action_look != null)
			{
				__instance.lookInput = CharacterInput.action_look.ReadValue<Vector2>();
			}
			else
			{
				__instance.lookInput = Vector2.zero;
			}
			if (enableMouseButtonMapping)
			{
				__instance.spectateLeftWasPressed = Input.GetMouseButtonDown(0);
				__instance.spectateRightWasPressed = Input.GetMouseButtonDown(1);
			}
			else
			{
				__instance.spectateLeftWasPressed = false;
				__instance.spectateRightWasPressed = false;
			}
			InputAction action_spectateLeft = CharacterInput.action_spectateLeft;
			if (action_spectateLeft != null && action_spectateLeft.WasPressedThisFrame())
			{
				__instance.spectateLeftWasPressed = true;
			}
			InputAction action_spectateRight = CharacterInput.action_spectateRight;
			if (action_spectateRight != null && action_spectateRight.WasPressedThisFrame())
			{
				__instance.spectateRightWasPressed = true;
			}
			float num = Input.mouseScrollDelta.y;
			if (Input.GetKey((KeyCode)334))
			{
				num -= 0.1f;
			}
			if (Input.GetKey((KeyCode)335))
			{
				num += 0.1f;
			}
			__instance.scrollInput = num;
		}
	}

	[HarmonyPatch]
	public static class InteractionPatches
	{
		private static float originalDistance;

		[HarmonyPatch(typeof(Interaction), "DoInteractableRaycasts")]
		[HarmonyPrefix]
		private static bool Prefix_DoInteractableRaycasts(Interaction __instance)
		{
			if (!IsRemoteModeActive())
			{
				return true;
			}
			originalDistance = __instance.distance;
			__instance.distance = float.MaxValue;
			return true;
		}

		[HarmonyPatch(typeof(Interaction), "DoInteractableRaycasts")]
		[HarmonyPostfix]
		private static void Postfix_DoInteractableRaycasts(Interaction __instance)
		{
			if (IsRemoteModeActive())
			{
				__instance.distance = originalDistance;
			}
		}

		[HarmonyPatch(typeof(CharacterInteractible), "IsSecondaryInteractible")]
		[HarmonyPrefix]
		private static bool Prefix_IsSecondaryInteractible(ref bool __result, CharacterInteractible __instance)
		{
			if (!IsRemoteModeActive())
			{
				return true;
			}
			if (__instance.character.data.dead || (Object)(object)__instance.character == (Object)(object)Character.localCharacter || !Object.op_Implicit((Object)(object)Character.localCharacter.data.currentItem) || !Character.localCharacter.data.currentItem.canUseOnFriend)
			{
				__result = false;
				return false;
			}
			_ = __instance.character.data.fullyPassedOut;
			__result = true;
			return false;
		}

		[HarmonyPatch(typeof(BackpackWheel), "Update")]
		[HarmonyPrefix]
		private static bool DisableDistanceCheck(BackpackWheel __instance)
		{
			//IL_00ed: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f2: Unknown result type (might be due to invalid IL or missing references)
			//IL_0102: Unknown result type (might be due to invalid IL or missing references)
			//IL_0042: Unknown result type (might be due to invalid IL or missing references)
			//IL_005d: Unknown result type (might be due to invalid IL or missing references)
			//IL_008c: Unknown result type (might be due to invalid IL or missing references)
			//IL_009d: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bb: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cb: Unknown result type (might be due to invalid IL or missing references)
			if (!IsRemoteModeActive())
			{
				return true;
			}
			if (!Character.localCharacter.input.interactIsPressed)
			{
				__instance.Choose();
				GUIManager.instance.CloseBackpackWheel();
				return false;
			}
			if (__instance.chosenSlice.IsSome && !__instance.chosenSlice.Value.isBackpackWear && !((Behaviour)__instance.slices[__instance.chosenSlice.Value.slotID + 1].image).enabled)
			{
				((Component)__instance.currentlyHeldItem).transform.position = Vector3.Lerp(((Component)__instance.currentlyHeldItem).transform.position, ((Component)__instance.slices[__instance.chosenSlice.Value.slotID + 1]).transform.GetChild(0).GetChild(0).position, Time.deltaTime * 20f);
			}
			else
			{
				((Component)__instance.currentlyHeldItem).transform.localPosition = Vector3.Lerp(((Component)__instance.currentlyHeldItem).transform.localPosition, Vector3.zero, Time.deltaTime * 20f);
			}
			return false;
		}
	}

	private static bool isRemoteModeActive;

	private MainCameraMovement cameraMovement;

	private ConfigEntry<KeyboardShortcut> keyboardToggleKey;

	private ConfigEntry<KeyboardShortcut> gamepadButton1;

	private ConfigEntry<KeyboardShortcut> gamepadButton2;

	private static bool enableMouseButtonMapping;

	private static MethodInfo resetInputMethod;

	private void Awake()
	{
		//IL_0018: Unknown result type (might be due to invalid IL or missing references)
		//IL_0047: Unknown result type (might be due to invalid IL or missing references)
		//IL_0076: Unknown result type (might be due to invalid IL or missing references)
		//IL_008f: Unknown result type (might be due to invalid IL or missing references)
		keyboardToggleKey = ((BaseUnityPlugin)this).Config.Bind<KeyboardShortcut>("Binds", "KeyboardToggle", new KeyboardShortcut((KeyCode)103, Array.Empty<KeyCode>()), "Keyboard toggle key / 键盘切换键");
		gamepadButton1 = ((BaseUnityPlugin)this).Config.Bind<KeyboardShortcut>("Binds", "GamepadButton1", new KeyboardShortcut((KeyCode)334, Array.Empty<KeyCode>()), "Gamepad button 1 / 手柄按键1");
		gamepadButton2 = ((BaseUnityPlugin)this).Config.Bind<KeyboardShortcut>("Binds", "GamepadButton2", new KeyboardShortcut((KeyCode)335, Array.Empty<KeyCode>()), "Gamepad button 2 / 手柄按键2");
		new Harmony("com.Kitty.remote").PatchAll(Assembly.GetExecutingAssembly());
		resetInputMethod = typeof(CharacterInput).GetMethod("ResetInput", BindingFlags.Instance | BindingFlags.NonPublic);
	}

	private void Update()
	{
		if (CheckToggleInput() && !((Object)(object)Character.localCharacter == (Object)null) && !((Object)(object)Character.localCharacter.data == (Object)null) && !Character.localCharacter.data.fullyPassedOut)
		{
			if ((Object)(object)cameraMovement == (Object)null)
			{
				cameraMovement = Singleton<MainCameraMovement>.Instance;
			}
			if (!((Object)(object)cameraMovement == (Object)null))
			{
				isRemoteModeActive = !isRemoteModeActive;
			}
		}
	}

	private bool CheckToggleInput()
	{
		//IL_0006: Unknown result type (might be due to invalid IL or missing references)
		//IL_000b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0019: 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)
		//IL_0043: Unknown result type (might be due to invalid IL or missing references)
		//IL_0048: 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_0033: Unknown result type (might be due to invalid IL or missing references)
		//IL_0058: Unknown result type (might be due to invalid IL or missing references)
		//IL_005d: Unknown result type (might be due to invalid IL or missing references)
		KeyboardShortcut value = keyboardToggleKey.Value;
		bool num = ((KeyboardShortcut)(ref value)).IsDown();
		value = gamepadButton1.Value;
		int num2;
		if (((KeyboardShortcut)(ref value)).IsDown())
		{
			value = gamepadButton2.Value;
			if (((KeyboardShortcut)(ref value)).IsPressed())
			{
				num2 = 1;
				goto IL_006b;
			}
		}
		value = gamepadButton2.Value;
		if (((KeyboardShortcut)(ref value)).IsDown())
		{
			value = gamepadButton1.Value;
			num2 = (((KeyboardShortcut)(ref value)).IsPressed() ? 1 : 0);
		}
		else
		{
			num2 = 0;
		}
		goto IL_006b;
		IL_006b:
		bool flag = (byte)num2 != 0;
		return num || flag;
	}

	public static bool IsRemoteModeActive()
	{
		return isRemoteModeActive;
	}
}