Decompiled source of ChainMod v0.1.0

plugins/com.github.Jagdoggo.ChainMod.dll

Decompiled 2 months ago
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 BepInEx.Logging;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using UnityEngine;
using UnityEngine.InputSystem;
using UnityEngine.InputSystem.Controls;

[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("com.github.Jagdoggo.ChainMod")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("0.1.0.0")]
[assembly: AssemblyInformationalVersion("0.1.0")]
[assembly: AssemblyProduct("com.github.Jagdoggo.ChainMod")]
[assembly: AssemblyTitle("ChainMod")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("0.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.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;
		}
	}
	[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 BepInEx
{
	[AttributeUsage(AttributeTargets.Class, Inherited = false, AllowMultiple = false)]
	[Conditional("CodeGeneration")]
	internal sealed class BepInAutoPluginAttribute : Attribute
	{
		public BepInAutoPluginAttribute(string? id = null, string? name = null, string? version = null)
		{
		}
	}
}
namespace BepInEx.Preloader.Core.Patching
{
	[AttributeUsage(AttributeTargets.Class, Inherited = false, AllowMultiple = false)]
	[Conditional("CodeGeneration")]
	internal sealed class PatcherAutoPluginAttribute : Attribute
	{
		public PatcherAutoPluginAttribute(string? id = null, string? name = null, string? version = null)
		{
		}
	}
}
namespace ChainMod
{
	[BepInPlugin("com.github.Jagdoggo.ChainMod", "ChainMod", "0.1.0")]
	public class Plugin : BaseUnityPlugin
	{
		private readonly Harmony _harmony = new Harmony("com.github.Jagdoggo.ChainMod");

		private ConfigEntry<float> chainForceCon;

		private ConfigEntry<float> maxForceCon;

		private ConfigEntry<float> minDistanceCon;

		private ConfigEntry<Key> connectChainKeyCon;

		private float chainForce;

		private float maxForce;

		private float minDistance;

		private Key connectChainKey;

		private bool chainActive;

		private LineRenderer chainLine;

		private Character chainedTarget;

		public const string Id = "com.github.Jagdoggo.ChainMod";

		internal static ManualLogSource Log { get; private set; }

		public static string Name => "ChainMod";

		public static string Version => "0.1.0";

		private void Awake()
		{
			//IL_0104: Unknown result type (might be due to invalid IL or missing references)
			//IL_0109: Unknown result type (might be due to invalid IL or missing references)
			Log = ((BaseUnityPlugin)this).Logger;
			Log.LogInfo((object)("Plugin " + Name + " is loaded!"));
			_harmony.PatchAll(Assembly.GetExecutingAssembly());
			chainForceCon = ((BaseUnityPlugin)this).Config.Bind<float>("Chain Settings", "Chain Force", 20f, "How strong the pull of the chain is");
			maxForceCon = ((BaseUnityPlugin)this).Config.Bind<float>("Chain Settings", "Chain Maximum Force", 40f, "How strong the pull of the chain can be");
			minDistanceCon = ((BaseUnityPlugin)this).Config.Bind<float>("Chain Settings", "Chain Distance", 4f, "How far apart players have to be before applying force");
			connectChainKeyCon = ((BaseUnityPlugin)this).Config.Bind<Key>("Chain Settings", "Connect Chain Key", (Key)24, "The key to connect chain");
			chainForce = chainForceCon.Value;
			maxForce = maxForceCon.Value;
			minDistance = minDistanceCon.Value;
			connectChainKey = connectChainKeyCon.Value;
		}

		private void Update()
		{
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_0060: Unknown result type (might be due to invalid IL or missing references)
			//IL_0066: Unknown result type (might be due to invalid IL or missing references)
			//IL_006b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0070: Unknown result type (might be due to invalid IL or missing references)
			//IL_01fb: Unknown result type (might be due to invalid IL or missing references)
			//IL_0202: Unknown result type (might be due to invalid IL or missing references)
			//IL_0207: Unknown result type (might be due to invalid IL or missing references)
			//IL_0211: Unknown result type (might be due to invalid IL or missing references)
			//IL_0216: Unknown result type (might be due to invalid IL or missing references)
			//IL_0231: Unknown result type (might be due to invalid IL or missing references)
			//IL_0242: Unknown result type (might be due to invalid IL or missing references)
			//IL_0252: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ac: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b3: Expected O, but got Unknown
			//IL_00fc: Unknown result type (might be due to invalid IL or missing references)
			//IL_0106: Expected O, but got Unknown
			//IL_0120: Unknown result type (might be due to invalid IL or missing references)
			//IL_0144: Unknown result type (might be due to invalid IL or missing references)
			if (((ButtonControl)Keyboard.current[connectChainKey]).wasPressedThisFrame)
			{
				Character localCharacter = Character.localCharacter;
				if ((Object)(object)localCharacter == (Object)null)
				{
					return;
				}
				Character val = FindClosestPlayer(localCharacter);
				if ((Object)(object)val == (Object)null)
				{
					return;
				}
				Transform hip = GetHip(localCharacter);
				Transform hip2 = GetHip(val);
				if ((Object)(object)hip == (Object)null || (Object)(object)hip2 == (Object)null)
				{
					return;
				}
				Vector3 val2 = hip2.position - hip.position;
				float magnitude = ((Vector3)(ref val2)).magnitude;
				if (magnitude >= minDistance)
				{
					return;
				}
				chainActive = !chainActive;
				if (chainActive)
				{
					chainedTarget = val;
					GameObject val3 = new GameObject("ChainLine");
					chainLine = val3.AddComponent<LineRenderer>();
					chainLine.positionCount = 3;
					chainLine.startWidth = 0.05f;
					chainLine.endWidth = 0.05f;
					((Renderer)chainLine).material = new Material(Shader.Find("Sprites/Default"));
					chainLine.startColor = new Color(0.5547f, 0.3477f, 0.2344f, 1f);
					chainLine.endColor = new Color(0.5547f, 0.3477f, 0.2344f, 1f);
				}
				else
				{
					if ((Object)(object)chainLine != (Object)null)
					{
						Object.Destroy((Object)(object)((Component)chainLine).gameObject);
					}
					chainedTarget = null;
				}
				Log.LogInfo((object)("Chain toggled " + (chainActive ? "ON" : "OFF")));
			}
			if (chainActive && (Object)(object)chainLine != (Object)null && (Object)(object)chainedTarget != (Object)null)
			{
				Transform hip3 = GetHip(Character.localCharacter);
				Transform hip4 = GetHip(chainedTarget);
				if ((Object)(object)hip3 != (Object)null && (Object)(object)hip4 != (Object)null)
				{
					Vector3 val4 = (hip3.position + hip4.position) / 2f;
					val4.y -= 0.5f;
					chainLine.SetPosition(0, hip3.position);
					chainLine.SetPosition(1, val4);
					chainLine.SetPosition(2, hip4.position);
				}
			}
		}

		private void FixedUpdate()
		{
			//IL_006d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0073: Unknown result type (might be due to invalid IL or missing references)
			//IL_0078: Unknown result type (might be due to invalid IL or missing references)
			//IL_007d: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cc: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00dc: Unknown result type (might be due to invalid IL or missing references)
			//IL_00de: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ea: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ec: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f8: Unknown result type (might be due to invalid IL or missing references)
			//IL_013b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0144: Unknown result type (might be due to invalid IL or missing references)
			//IL_0113: Unknown result type (might be due to invalid IL or missing references)
			//IL_0118: Unknown result type (might be due to invalid IL or missing references)
			//IL_0123: Unknown result type (might be due to invalid IL or missing references)
			//IL_0128: Unknown result type (might be due to invalid IL or missing references)
			//IL_012b: Unknown result type (might be due to invalid IL or missing references)
			//IL_012d: Unknown result type (might be due to invalid IL or missing references)
			//IL_012f: Unknown result type (might be due to invalid IL or missing references)
			Character localCharacter = Character.localCharacter;
			if (!chainActive || (Object)(object)localCharacter == (Object)null || (Object)(object)chainedTarget == (Object)null)
			{
				return;
			}
			Transform hip = GetHip(localCharacter);
			Transform hip2 = GetHip(chainedTarget);
			if ((Object)(object)hip == (Object)null || (Object)(object)hip2 == (Object)null)
			{
				return;
			}
			Transform hip3 = GetHip(localCharacter);
			Rigidbody val = ((hip3 != null) ? ((Component)hip3).GetComponent<Rigidbody>() : null);
			if ((Object)(object)val == (Object)null)
			{
				return;
			}
			Vector3 val2 = hip2.position - hip.position;
			float magnitude = ((Vector3)(ref val2)).magnitude;
			if (!(magnitude <= minDistance))
			{
				((Vector3)(ref val2)).Normalize();
				float num = magnitude - minDistance;
				float num2 = Mathf.Clamp(num * chainForce, 0f, maxForce);
				Vector3 val3 = val2 * num2;
				Vector3 linearVelocity = val.linearVelocity;
				Vector3 val4 = Vector3.Project(linearVelocity, val2);
				Vector3 val5 = linearVelocity - val4;
				val.linearVelocity = val4 + val5 * 0.8f;
				if (!Character.localCharacter.data.isGrounded)
				{
					Vector3 val6 = -Physics.gravity * val.mass;
					val.AddForce(val3 + val6, (ForceMode)0);
				}
				val.AddForce(val3, (ForceMode)2);
				val.angularVelocity = Vector3.zero;
			}
		}

		private Character[] GetActivePlayers()
		{
			return (from p in Object.FindObjectsByType<Character>((FindObjectsSortMode)0)
				where (Object)(object)p != (Object)null && !Object.op_Implicit((Object)(object)p.Ghost) && !p.isBot && ((Behaviour)p).isActiveAndEnabled
				select p).ToArray();
		}

		private Transform GetHip(Character c)
		{
			return ((IEnumerable<Transform>)((Component)c).GetComponentsInChildren<Transform>()).FirstOrDefault((Func<Transform, bool>)((Transform t) => ((Object)t).name == "Hip"));
		}

		private Character FindClosestPlayer(Character local)
		{
			//IL_0050: Unknown result type (might be due to invalid IL or missing references)
			//IL_0057: Unknown result type (might be due to invalid IL or missing references)
			Character[] activePlayers = GetActivePlayers();
			Transform hip = GetHip(local);
			if ((Object)(object)hip == (Object)null)
			{
				return null;
			}
			Character result = null;
			float num = float.MaxValue;
			Character[] array = activePlayers;
			foreach (Character val in array)
			{
				if ((Object)(object)val == (Object)(object)local)
				{
					continue;
				}
				Transform hip2 = GetHip(val);
				if (!((Object)(object)hip2 == (Object)null))
				{
					float num2 = Vector3.Distance(hip.position, hip2.position);
					if (num2 < num)
					{
						num = num2;
						result = val;
					}
				}
			}
			return result;
		}
	}
}
namespace System.Runtime.CompilerServices
{
	[AttributeUsage(AttributeTargets.Assembly, AllowMultiple = true)]
	internal sealed class IgnoresAccessChecksToAttribute : Attribute
	{
		public IgnoresAccessChecksToAttribute(string assemblyName)
		{
		}
	}
}