Decompiled source of CoinJumper v1.0.1

CoinJumper.dll

Decompiled a day ago
using System;
using System.Diagnostics;
using System.IO;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Bootstrap;
using CoinJumper.Patches;
using CoinJumper.Scripts;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using PluginConfig.API;
using PluginConfig.API.Fields;
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("CoinJumper")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.0.1.0")]
[assembly: AssemblyInformationalVersion("1.0.1+227459edcb8670af3619bd5450d507b689202047")]
[assembly: AssemblyProduct("CoinJumper")]
[assembly: AssemblyTitle("CoinJumper")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.1.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 CoinJumper
{
	[BepInPlugin("CoinJumper", "CoinJumper", "1.0.1")]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	public class Plugin : BaseUnityPlugin
	{
		public static float BounceMultiplierValue = 1f;

		public static bool SoundOnValue = true;

		public static int MaxBouncesValue = 0;

		private static readonly Harmony Harmony = new Harmony("CoinJumper");

		private void Awake()
		{
			Harmony.PatchAll(typeof(CoinPatch));
			if (Chainloader.PluginInfos.ContainsKey("com.eternalUnion.pluginConfigurator"))
			{
				ConfigSetup.Init();
			}
		}
	}
	internal static class ConfigSetup
	{
		[Serializable]
		[CompilerGenerated]
		private sealed class <>c
		{
			public static readonly <>c <>9 = new <>c();

			public static OnValueChangeEventDelegate <>9__0_0;

			public static BoolValueChangeEventDelegate <>9__0_1;

			public static IntValueChangeEventDelegate <>9__0_2;

			internal void <Init>b__0_0(FloatSliderValueChangeEvent e)
			{
				Plugin.BounceMultiplierValue = e.newValue;
			}

			internal void <Init>b__0_1(BoolValueChangeEvent e)
			{
				Plugin.SoundOnValue = e.value;
			}

			internal void <Init>b__0_2(IntValueChangeEvent e)
			{
				Plugin.MaxBouncesValue = e.value;
			}
		}

		internal static void Init()
		{
			//IL_0075: Unknown result type (might be due to invalid IL or missing references)
			//IL_007b: Expected O, but got Unknown
			//IL_008c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0092: Expected O, but got Unknown
			//IL_00a3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00aa: Expected O, but got Unknown
			//IL_00bf: 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_00ca: Expected O, but got Unknown
			//IL_00e5: 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_00f0: Expected O, but got Unknown
			//IL_010c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0111: Unknown result type (might be due to invalid IL or missing references)
			//IL_0117: Expected O, but got Unknown
			PluginConfigurator val = PluginConfigurator.Create("CoinJumper", "CoinJumper");
			string text = Path.Combine(Path.GetDirectoryName(typeof(Plugin).Assembly.Location) ?? string.Empty, "icon.png");
			val.SetIconWithURL("file://" + text);
			FloatSliderField val2 = new FloatSliderField(val.rootPanel, "Bouncy", "bouncy", new Tuple<float, float>(0f, 2f), 1f, 1);
			BoolField val3 = new BoolField(val.rootPanel, "Sound", "sound_on", true);
			IntField val4 = new IntField(val.rootPanel, "Max Bounces (0 = unlimited)", "max_bounces", 0);
			object obj = <>c.<>9__0_0;
			if (obj == null)
			{
				OnValueChangeEventDelegate val5 = delegate(FloatSliderValueChangeEvent e)
				{
					Plugin.BounceMultiplierValue = e.newValue;
				};
				<>c.<>9__0_0 = val5;
				obj = (object)val5;
			}
			val2.onValueChange += (OnValueChangeEventDelegate)obj;
			object obj2 = <>c.<>9__0_1;
			if (obj2 == null)
			{
				BoolValueChangeEventDelegate val6 = delegate(BoolValueChangeEvent e)
				{
					Plugin.SoundOnValue = e.value;
				};
				<>c.<>9__0_1 = val6;
				obj2 = (object)val6;
			}
			val3.onValueChange += (BoolValueChangeEventDelegate)obj2;
			object obj3 = <>c.<>9__0_2;
			if (obj3 == null)
			{
				IntValueChangeEventDelegate val7 = delegate(IntValueChangeEvent e)
				{
					Plugin.MaxBouncesValue = e.value;
				};
				<>c.<>9__0_2 = val7;
				obj3 = (object)val7;
			}
			val4.onValueChange += (IntValueChangeEventDelegate)obj3;
			Plugin.BounceMultiplierValue = val2.value;
			Plugin.SoundOnValue = val3.value;
			Plugin.MaxBouncesValue = val4.value;
		}
	}
	public static class MyPluginInfo
	{
		public const string PLUGIN_GUID = "CoinJumper";

		public const string PLUGIN_NAME = "CoinJumper";

		public const string PLUGIN_VERSION = "1.0.1";
	}
}
namespace CoinJumper.Scripts
{
	public class Bouncy : MonoBehaviour
	{
		private const float MinSpeed = 0f;

		private const float MaxSpeed = 800f;

		public GameObject audioObjectPrefab;

		private readonly LayerMask _collisionMask = LayerMask.op_Implicit(-1);

		private int _bounceCount = 0;

		private Rigidbody _rb;

		private const float SkinWidth = 0.01f;

		public Action<int> OnBounce;

		private void Awake()
		{
			_rb = ((Component)this).GetComponent<Rigidbody>();
			_rb.sleepThreshold = 0f;
			_rb.interpolation = (RigidbodyInterpolation)1;
			_rb.collisionDetectionMode = (CollisionDetectionMode)3;
		}

		private void FixedUpdate()
		{
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			//IL_000c: 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_0074: Unknown result type (might be due to invalid IL or missing references)
			//IL_0079: 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_004a: Unknown result type (might be due to invalid IL or missing references)
			//IL_004f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0053: Unknown result type (might be due to invalid IL or missing references)
			//IL_0059: 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_0119: Unknown result type (might be due to invalid IL or missing references)
			//IL_0152: Unknown result type (might be due to invalid IL or missing references)
			//IL_0157: Unknown result type (might be due to invalid IL or missing references)
			//IL_015a: Unknown result type (might be due to invalid IL or missing references)
			//IL_015f: Unknown result type (might be due to invalid IL or missing references)
			//IL_016c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0171: Unknown result type (might be due to invalid IL or missing references)
			//IL_0173: Unknown result type (might be due to invalid IL or missing references)
			//IL_0174: Unknown result type (might be due to invalid IL or missing references)
			//IL_0176: Unknown result type (might be due to invalid IL or missing references)
			//IL_017b: Unknown result type (might be due to invalid IL or missing references)
			//IL_017f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0184: 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_01ac: Unknown result type (might be due to invalid IL or missing references)
			//IL_01db: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e0: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e2: 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)
			//IL_0215: Unknown result type (might be due to invalid IL or missing references)
			//IL_0219: Unknown result type (might be due to invalid IL or missing references)
			//IL_021e: Unknown result type (might be due to invalid IL or missing references)
			Vector3 val = _rb.velocity;
			float num = ((Vector3)(ref val)).magnitude;
			if (num < 0.01f)
			{
				return;
			}
			if (num > 800f)
			{
				num = 800f;
				Rigidbody rb = _rb;
				val = _rb.velocity;
				rb.velocity = ((Vector3)(ref val)).normalized * num;
			}
			val = _rb.velocity;
			Vector3 normalized = ((Vector3)(ref val)).normalized;
			float num2 = num * Time.fixedDeltaTime;
			RaycastHit[] array = _rb.SweepTestAll(normalized, num2, (QueryTriggerInteraction)1);
			if (array == null || array.Length == 0)
			{
				return;
			}
			Array.Sort(array, (RaycastHit x, RaycastHit y) => ((RaycastHit)(ref x)).distance.CompareTo(((RaycastHit)(ref y)).distance));
			RaycastHit[] array2 = array;
			for (int i = 0; i < array2.Length; i++)
			{
				RaycastHit val2 = array2[i];
				if (!((Object)(object)((RaycastHit)(ref val2)).transform == (Object)(object)((Component)this).transform) && ((1 << ((Component)((RaycastHit)(ref val2)).collider).gameObject.layer) & LayerMask.op_Implicit(_collisionMask)) != 0)
				{
					float num3 = Mathf.Max(0f, ((RaycastHit)(ref val2)).distance - 0.01f);
					Rigidbody rb2 = _rb;
					rb2.position += normalized * num3;
					Vector3 normal = ((RaycastHit)(ref val2)).normal;
					val = Vector3.Reflect(normalized, normal);
					Vector3 normalized2 = ((Vector3)(ref val)).normalized;
					float num4 = num * Plugin.BounceMultiplierValue;
					float num5 = Mathf.Clamp(num4, 0f, 800f);
					_rb.velocity = normalized2 * num5;
					if (Object.op_Implicit((Object)(object)audioObjectPrefab) && Plugin.SoundOnValue)
					{
						Object.Instantiate<GameObject>(audioObjectPrefab, ((RaycastHit)(ref val2)).point, Quaternion.LookRotation(normal));
					}
					float num6 = num2 - ((RaycastHit)(ref val2)).distance;
					if (num6 > 0f)
					{
						Rigidbody rb3 = _rb;
						rb3.position += normalized2 * num6;
					}
					_bounceCount++;
					OnBounce(_bounceCount);
					break;
				}
			}
		}
	}
}
namespace CoinJumper.Patches
{
	[HarmonyPatch]
	public static class CoinPatch
	{
		[HarmonyPrefix]
		[HarmonyPatch(typeof(Coin), "GetDeleted")]
		public static void patch_GetDeleted(Coin __instance)
		{
			Bouncy component = ((Component)__instance).GetComponent<Bouncy>();
			if (Object.op_Implicit((Object)(object)component))
			{
				Object.Destroy((Object)(object)component);
			}
		}

		[HarmonyPostfix]
		[HarmonyPatch(typeof(Coin), "Start")]
		private static void patch_Start(Coin __instance)
		{
			Bouncy orAddComponent = ComponentExtensions.GetOrAddComponent<Bouncy>((Component)(object)__instance);
			orAddComponent.audioObjectPrefab = __instance.coinHitSound;
			orAddComponent.OnBounce = (Action<int>)Delegate.Combine(orAddComponent.OnBounce, (Action<int>)delegate(int bounceCount)
			{
				if (Plugin.MaxBouncesValue > 0 && bounceCount > Plugin.MaxBouncesValue)
				{
					__instance.GetDeleted();
				}
				else
				{
					((MonoBehaviour)__instance).CancelInvoke("GetDeleted");
					((MonoBehaviour)__instance).Invoke("GetDeleted", 5f);
				}
			});
		}

		[HarmonyPrefix]
		[HarmonyPatch(typeof(Coin), "OnCollisionEnter")]
		private static bool patch_OnCollisionEnter(Coin __instance, Collision collision)
		{
			return false;
		}
	}
}