Decompiled source of TurretsPhysicsPatch v0.2.0

TurretsPhysicsPatch.dll

Decompiled 5 months ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using BepInEx;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using UnityEngine;

[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("TurretsPhysicsPatch")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0+f7ae7fce1ac2b9765bf13639300cbfa549ce7538")]
[assembly: AssemblyProduct("TurretsPhysicsPatch")]
[assembly: AssemblyTitle("TurretsPhysicsPatch")]
[assembly: AssemblyVersion("1.0.0.0")]
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;
		}
	}
}
namespace TurretsPhysicsPatch
{
	[BepInPlugin("TheCampingTurret.Rounds.TCTPP.patch", "TurretsPhysicsPatch", "0.2.0")]
	[BepInProcess("Rounds.exe")]
	public class TurretsPhysicsPatch : BaseUnityPlugin
	{
		private const string ModId = "TheCampingTurret.Rounds.TCTPP.patch";

		private const string ModName = "TurretsPhysicsPatch";

		public const string Version = "0.2.0";

		private void Awake()
		{
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			new Harmony("TheCampingTurret.Rounds.TCTPP.patch").PatchAll(Assembly.GetExecutingAssembly());
		}
	}
	[HarmonyPatch(typeof(MoveTransform), "Update")]
	public class Patch_MoveTransform
	{
		[HarmonyPatch(typeof(MoveTransform), "Update")]
		private static bool Prefix(MoveTransform __instance)
		{
			//IL_0093: Unknown result type (might be due to invalid IL or missing references)
			//IL_0098: 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_00b0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ba: Unknown result type (might be due to invalid IL or missing references)
			//IL_0177: Unknown result type (might be due to invalid IL or missing references)
			//IL_017e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0185: Unknown result type (might be due to invalid IL or missing references)
			//IL_0192: Unknown result type (might be due to invalid IL or missing references)
			//IL_0197: Unknown result type (might be due to invalid IL or missing references)
			//IL_0199: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a0: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a7: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b6: Unknown result type (might be due to invalid IL or missing references)
			//IL_01bb: Unknown result type (might be due to invalid IL or missing references)
			//IL_01bf: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c6: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e4: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e6: Unknown result type (might be due to invalid IL or missing references)
			//IL_0204: Unknown result type (might be due to invalid IL or missing references)
			//IL_0206: Unknown result type (might be due to invalid IL or missing references)
			//IL_021d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0224: Unknown result type (might be due to invalid IL or missing references)
			//IL_022b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0230: 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_0257: Unknown result type (might be due to invalid IL or missing references)
			//IL_025c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0278: Unknown result type (might be due to invalid IL or missing references)
			//IL_027d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0282: Unknown result type (might be due to invalid IL or missing references)
			//IL_0290: Unknown result type (might be due to invalid IL or missing references)
			//IL_0295: Unknown result type (might be due to invalid IL or missing references)
			//IL_029a: Unknown result type (might be due to invalid IL or missing references)
			//IL_034d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0354: Unknown result type (might be due to invalid IL or missing references)
			//IL_035b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0365: Unknown result type (might be due to invalid IL or missing references)
			//IL_036a: Unknown result type (might be due to invalid IL or missing references)
			//IL_036c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0373: Unknown result type (might be due to invalid IL or missing references)
			//IL_037a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0384: Unknown result type (might be due to invalid IL or missing references)
			//IL_0389: Unknown result type (might be due to invalid IL or missing references)
			//IL_038d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0394: Unknown result type (might be due to invalid IL or missing references)
			//IL_03b7: Unknown result type (might be due to invalid IL or missing references)
			//IL_03b9: Unknown result type (might be due to invalid IL or missing references)
			//IL_03dc: Unknown result type (might be due to invalid IL or missing references)
			//IL_03de: Unknown result type (might be due to invalid IL or missing references)
			//IL_03fa: Unknown result type (might be due to invalid IL or missing references)
			//IL_0401: Unknown result type (might be due to invalid IL or missing references)
			//IL_0408: Unknown result type (might be due to invalid IL or missing references)
			//IL_040d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0439: Unknown result type (might be due to invalid IL or missing references)
			//IL_043e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0443: Unknown result type (might be due to invalid IL or missing references)
			//IL_0464: Unknown result type (might be due to invalid IL or missing references)
			//IL_0469: Unknown result type (might be due to invalid IL or missing references)
			//IL_046e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0481: Unknown result type (might be due to invalid IL or missing references)
			//IL_0486: Unknown result type (might be due to invalid IL or missing references)
			//IL_048b: Unknown result type (might be due to invalid IL or missing references)
			MoveTransform __instance2 = __instance;
			float num = (float)Traverse.Create((object)__instance2).Field("simulationSpeed").GetValue();
			float num2 = Time.deltaTime * num + __instance2.GetAdditionalData().msleft;
			float num3 = 1f / 70f;
			if (num2 > num3)
			{
				float num4 = num3 * num;
				float num5 = __instance2.GetAdditionalData().time_since_started;
				Vector2 val = Vector2.op_Implicit(__instance2.velocity);
				Vector2 val2 = Vector2.op_Implicit(((Component)__instance2).transform.position);
				int simulateGravity = __instance2.simulateGravity;
				float gravity = __instance2.gravity;
				float multiplier = __instance2.multiplier;
				float cd = __instance2.drag * 0.0075f;
				float ag;
				if (simulateGravity == 0)
				{
					ag = (0f - gravity) * multiplier;
				}
				else
				{
					ag = 0f;
				}
				if (cd < 1E-06f && !__instance2.GetAdditionalData().accelerationeffect)
				{
					Vector2 val5 = default(Vector2);
					while (num2 > num3)
					{
						Vector2 val3 = TurretsPhysicsExtensions.rungekutta4(new Vector2(val2.x, val.x), num5, num3, 0f);
						Vector2 val4 = TurretsPhysicsExtensions.rungekutta4(new Vector2(val2.y, val.y), num5, num3, ag);
						((Vector2)(ref val5))..ctor(val3.x, val4.x);
						MoveTransform obj = __instance2;
						obj.distanceTravelled += Vector2.Distance(val2, val5);
						((Component)__instance2).transform.position = Vector2.op_Implicit(val5);
						__instance2.velocity = new Vector3(val3.y, val4.y);
						((Component)__instance2).transform.rotation = Quaternion.LookRotation(__instance2.velocity, Vector3.forward);
						val2 = Vector2.op_Implicit(((Component)__instance2).transform.position);
						val = Vector2.op_Implicit(__instance2.velocity);
						num2 -= num3;
						num5 += num3;
					}
				}
				else
				{
					Func<float, float, float> drag = (float t, float v) => (0f - cd) * Math.Abs(v) * v;
					Func<float, float, float> func;
					Func<float, float, float> func2;
					if (__instance2.GetAdditionalData().accelerationeffect)
					{
						func = delegate(float t, float v)
						{
							float num7 = drag(t, v) + ag;
							foreach (Func<float, float, float> item in __instance2.GetAdditionalData().a_y)
							{
								num7 += item(t, v);
							}
							return num7;
						};
						func2 = delegate(float t, float v)
						{
							float num6 = drag(t, v);
							foreach (Func<float, float, float> item2 in __instance2.GetAdditionalData().a_x)
							{
								num6 += item2(t, v);
							}
							return num6;
						};
					}
					else
					{
						func = (float t, float v) => drag(t, v) + ag;
						func2 = (float t, float v) => drag(t, v);
					}
					Vector2 val8 = default(Vector2);
					while (num2 > num3)
					{
						Vector2 val6 = TurretsPhysicsExtensions.rungekutta4(new Vector2(val2.x, val.x), num5, num3, func2);
						Vector2 val7 = TurretsPhysicsExtensions.rungekutta4(new Vector2(val2.y, val.y), num5, num3, func);
						((Vector2)(ref val8))..ctor(val6.x, val7.x);
						MoveTransform obj2 = __instance2;
						obj2.distanceTravelled += Vector2.Distance(val2, val8);
						((Component)__instance2).transform.position = Vector2.op_Implicit(val8);
						__instance2.velocity = new Vector3(val6.y, val7.y);
						((Component)__instance2).transform.rotation = Quaternion.LookRotation(__instance2.velocity, Vector3.forward);
						val2 = Vector2.op_Implicit(((Component)__instance2).transform.position);
						val = Vector2.op_Implicit(__instance2.velocity);
						num2 -= num3;
						num5 += num3;
					}
				}
				__instance2.GetAdditionalData().time_since_started = num5;
			}
			__instance2.GetAdditionalData().msleft = num2;
			return false;
		}
	}
	[Serializable]
	public class MoveTransformAdditionalData
	{
		public float msleft;

		public float time_since_started;

		public bool accelerationeffect;

		public List<Func<float, float, float>> a_x;

		public List<Func<float, float, float>> a_y;

		public MoveTransformAdditionalData()
		{
			msleft = 0f;
			accelerationeffect = false;
			time_since_started = 0f;
			a_x = new List<Func<float, float, float>>();
			a_y = new List<Func<float, float, float>>();
		}
	}
	public static class MoveTransformExtension
	{
		private static readonly ConditionalWeakTable<MoveTransform, MoveTransformAdditionalData> data = new ConditionalWeakTable<MoveTransform, MoveTransformAdditionalData>();

		public static MoveTransformAdditionalData GetAdditionalData(this MoveTransform movetransform)
		{
			return data.GetOrCreateValue(movetransform);
		}

		public static void AddData(this MoveTransform movetransform, MoveTransformAdditionalData value)
		{
			try
			{
				data.Add(movetransform, value);
			}
			catch (Exception)
			{
			}
		}
	}
	public static class TurretsPhysicsExtensions
	{
		public static Vector2 rungekutta4(Vector2 dir, float t, float dtt, Func<float, float, float> func)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0022: Unknown result type (might be due to invalid IL or missing references)
			//IL_003c: 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_0072: Unknown result type (might be due to invalid IL or missing references)
			//IL_0088: Unknown result type (might be due to invalid IL or missing references)
			//IL_0096: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bc: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c7: 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_00d8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00dd: 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_00e4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e6: 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)
			float y = dir.y;
			Vector2 val = default(Vector2);
			((Vector2)(ref val))..ctor(y, func(t, y));
			Vector2 val2 = default(Vector2);
			((Vector2)(ref val2))..ctor(y + dtt / 2f * val.y, func(t + dtt / 2f, y + dtt / 2f * val.y));
			Vector2 val3 = default(Vector2);
			((Vector2)(ref val3))..ctor(y + dtt / 2f * val2.y, func(t + dtt / 2f, y + dtt / 2f * val2.y));
			Vector2 val4 = default(Vector2);
			((Vector2)(ref val4))..ctor(y + dtt * val3.y, func(t + dtt, y + dtt * val3.y));
			return dir + dtt / 6f * (val + 2f * val2 + 2f * val3 + val4);
		}

		public static Vector2 rungekutta4(Vector2 dir, float t, float dtt, float func)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0008: Unknown result type (might be due to invalid IL or missing references)
			//IL_001c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0026: Unknown result type (might be due to invalid IL or missing references)
			//IL_002b: 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)
			return new Vector2(dir.x + dtt * dir.y + dtt * dtt * func / 2f, dir.y + dtt * func);
		}

		public static void add_constant_acceleration(this MoveTransform movetransform, Vector3 accelerations, float starttime)
		{
			//IL_000e: Unknown result type (might be due to invalid IL or missing references)
			//IL_000f: Unknown result type (might be due to invalid IL or missing references)
			movetransform.GetAdditionalData().a_x.Add((float t, float v) => (t > starttime) ? accelerations.x : 0f);
			movetransform.GetAdditionalData().a_y.Add((float t, float v) => (t > starttime) ? accelerations.y : 0f);
			movetransform.GetAdditionalData().accelerationeffect = true;
		}

		public static void add_variate_acceleration(this MoveTransform movetransform, List<Func<float, float, float>> List_of_equations, float starttime)
		{
			List<Func<float, float, float>> List_of_equations2 = List_of_equations;
			movetransform.GetAdditionalData().a_x.Add((float t, float v) => (t > starttime) ? List_of_equations2[0](t, v) : 0f);
			movetransform.GetAdditionalData().a_y.Add((float t, float v) => (t > starttime) ? List_of_equations2[1](t, v) : 0f);
			movetransform.GetAdditionalData().accelerationeffect = true;
		}

		public static void add_variate_acceleration(this MoveTransform movetransform, Func<float, float, float> equation, char direction, float starttime)
		{
			Func<float, float, float> equation2 = equation;
			switch (direction)
			{
			case 'x':
				movetransform.GetAdditionalData().a_x.Add((float t, float v) => (t > starttime) ? equation2(t, v) : 0f);
				movetransform.GetAdditionalData().accelerationeffect = true;
				break;
			case 'y':
				movetransform.GetAdditionalData().a_y.Add((float t, float v) => (t > starttime) ? equation2(t, v) : 0f);
				movetransform.GetAdditionalData().accelerationeffect = true;
				break;
			default:
				throw new Exception("Incorrect direction set");
			}
		}
	}
}