Decompiled source of StickyNade v3.1.0

stickyNade.dll

Decompiled 4 months ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BoplFixedMath;
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(".NETFramework,Version=v4.6", FrameworkDisplayName = "")]
[assembly: AssemblyCompany("stickyNade")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyDescription("My first plugin")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("stickyNade")]
[assembly: AssemblyTitle("stickyNade")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.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.Module, AllowMultiple = false, Inherited = false)]
	internal sealed class RefSafetyRulesAttribute : Attribute
	{
		public readonly int Version;

		public RefSafetyRulesAttribute(int P_0)
		{
			Version = P_0;
		}
	}
}
namespace stickyNade
{
	[BepInPlugin("com.erwer.stickyNade", "stickyNade", "1.0.0")]
	[BepInIncompatibility("savaGe-NoOwnerExplosionDeaths-1.0.0")]
	public class Plugin : BaseUnityPlugin
	{
		public const string PLUGIN_GUID = "com.erwer.stickyNade";

		public const string PLUGIN_NAME = "stickyNade";

		public const string PLUGIN_VERSION = "1.0.0";

		private void Awake()
		{
			//IL_0017: Unknown result type (might be due to invalid IL or missing references)
			//IL_001d: Expected O, but got Unknown
			((BaseUnityPlugin)this).Logger.LogInfo((object)"Plugin com.erwer.stickyNade is loaded!");
			Harmony val = new Harmony("com.erwer.stickyNade");
			val.PatchAll(typeof(Patches));
		}
	}
	public class GrenadeAdapter : IPlatformAttachable
	{
		private readonly Grenade _grenade;

		public StickyRoundedRectangle stuckToGround;

		public bool hasLanded;

		public Fix SurfaceOffset { get; set; }

		public Fix LocalPlatformPosition { get; set; }

		public Vec2 HitNormal { get; set; } = Vec2.up;


		public GrenadeAdapter(Grenade grenade)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			_grenade = grenade;
		}

		public void RepositionOnParent()
		{
			//IL_0018: Unknown result type (might be due to invalid IL or missing references)
			//IL_001d: 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_0027: 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_0034: Unknown result type (might be due to invalid IL or missing references)
			if (Object.op_Implicit((Object)(object)stuckToGround))
			{
				Vec2 position = stuckToGround.PositionFromLocalPlayerPos(LocalPlatformPosition, Fix.Zero);
				((Component)_grenade).GetComponent<FixTransform>().position = position;
			}
		}

		public void doLand()
		{
			//IL_0017: 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_0031: Unknown result type (might be due to invalid IL or missing references)
			//IL_0036: 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_00c5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d9: 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_00fc: 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_0136: Unknown result type (might be due to invalid IL or missing references)
			//IL_0165: 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_01a6: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ab: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b0: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b7: Unknown result type (might be due to invalid IL or missing references)
			//IL_01cf: Unknown result type (might be due to invalid IL or missing references)
			//IL_023e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0243: Unknown result type (might be due to invalid IL or missing references)
			//IL_0248: Unknown result type (might be due to invalid IL or missing references)
			//IL_024d: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f6: 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_021e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0223: Unknown result type (might be due to invalid IL or missing references)
			//IL_0228: Unknown result type (might be due to invalid IL or missing references)
			FixTransform fixTrans = _grenade.body.fixTrans;
			Fix val = (Fix)1f;
			PhysicsParent[] array = (PhysicsParent[])(object)new PhysicsParent[50];
			HashSet<int> hashSet = new HashSet<int>();
			int num = DetPhysics.Get().circleCastRoundedRect(fixTrans.position, val, ref array);
			Debug.Log((object)$"Hit count: {num}");
			Vec2 val2 = default(Vec2);
			for (int i = 0; i < num; i++)
			{
				StickyRoundedRectangle component = ((Component)array[i].fixTrans).GetComponent<StickyRoundedRectangle>();
				if ((Object)(object)component != (Object)null)
				{
					Debug.Log((object)("Found sticky component on " + ((Object)((Component)array[i].fixTrans).gameObject).name));
					stuckToGround = component;
					Vec2 position = ((Component)_grenade).GetComponent<FixTransform>().position;
					Vec2 position2 = array[i].fixTrans.position;
					double num2 = mathhs.differ_angel(((Component)_grenade).transform.position.x, ((Component)_grenade).transform.position.y, (float)array[i].fixTrans.position.x, (float)array[i].fixTrans.position.y);
					((Vec2)(ref val2))..ctor((Fix)Math.Cos(num2 * Math.PI / 180.0), (Fix)Math.Sin(num2 * Math.PI / 180.0));
					List<RaycastInformation> list = new List<RaycastInformation>();
					DetPhysics.Get().RaycastAll((Vec2)((Component)_grenade).transform.position, val2, (Fix)250f, LayerMask.op_Implicit(LayerMask.GetMask(new string[1] { "wall" })), list, 0);
					if (list.Count > 0)
					{
						Debug.Log((object)$"Raycast hit at {list[0].nearPos}");
						((Component)_grenade).transform.position = (Vector3)list[0].nearPos;
					}
					LocalPlatformPosition = stuckToGround.LocalPlayerPosFromPos(list[0].nearPos, Fix.Zero);
					hasLanded = true;
					AudioManager.Get().Play("arrowHit");
					((Component)_grenade).transform.SetParent(((Component)array[i].fixTrans).gameObject.transform);
					Updater.DestroyFix((MonoBehaviour)(object)((Component)_grenade).GetComponent<FixTransform>());
					for (int j = 0; j < ((Component)_grenade).transform.childCount; j++)
					{
						Object.Destroy((Object)(object)((Component)((Component)_grenade).transform.GetChild(j)).gameObject);
					}
					break;
				}
				Debug.Log((object)("No sticky component found on " + ((Object)((Component)array[i].fixTrans).gameObject).name));
			}
		}
	}
	public class Patches
	{
		public static Dictionary<Grenade, GrenadeAdapter> GrenadeAdapters = new Dictionary<Grenade, GrenadeAdapter>();

		[HarmonyPatch(typeof(Grenade), "Awake")]
		[HarmonyPostfix]
		public static void PatchGrenade(Grenade __instance)
		{
			//IL_000c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0011: Unknown result type (might be due to invalid IL or missing references)
			__instance.body.bounciness = (Fix)0f;
			GrenadeAdapter value = new GrenadeAdapter(__instance);
			GrenadeAdapters[__instance] = value;
		}

		[HarmonyPatch(typeof(Grenade), "UpdateSim")]
		[HarmonyPrefix]
		public static bool GrenadePatch2(Grenade __instance, ref Fix simDeltaTime)
		{
			//IL_009a: Unknown result type (might be due to invalid IL or missing references)
			//IL_009f: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bf: Unknown result type (might be due to invalid IL or missing references)
			//IL_0115: 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_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_00e7: 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_00f1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f7: Unknown result type (might be due to invalid IL or missing references)
			//IL_012a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0130: Unknown result type (might be due to invalid IL or missing references)
			//IL_0135: Unknown result type (might be due to invalid IL or missing references)
			//IL_013a: Unknown result type (might be due to invalid IL or missing references)
			//IL_013f: 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_014a: Unknown result type (might be due to invalid IL or missing references)
			bool flag = false;
			GrenadeAdapter grenadeAdapter = GrenadeAdapters[__instance];
			if (grenadeAdapter != null && __instance.hasBeenThrown && __instance.DetonatesOnOwner)
			{
				if (!grenadeAdapter.hasLanded)
				{
					grenadeAdapter.doLand();
					flag = true;
				}
				else
				{
					grenadeAdapter.RepositionOnParent();
					flag = false;
				}
			}
			if (!flag)
			{
				if (!__instance.hasBeenThrown && ((Object)(object)__instance.thrower == (Object)null || !((Component)__instance.thrower).gameObject.activeSelf))
				{
					__instance.hasBeenThrown = true;
					__instance.hurtOwnerDelay = -Fix.One;
					((Component)__instance).GetComponent<DPhysicsCircle>().ManualInit();
				}
				if (__instance.hasBeenThrown && __instance.hurtOwnerDelay > 0L)
				{
					__instance.hurtOwnerDelay -= simDeltaTime * GameTime.PlayerTimeScale;
					if (__instance.hurtOwnerDelay <= 0L)
					{
						__instance.DetonatesOnOwner = true;
					}
				}
				if (__instance.selfDestructDelay > 0L)
				{
					__instance.selfDestructDelay -= simDeltaTime * GameTime.PlayerTimeScale;
					if (__instance.selfDestructDelay <= 0L)
					{
						__instance.Detonate();
					}
				}
			}
			return flag;
		}
	}
	public class mathhs
	{
		public static double differ_angel(float x1, float y1, float x2, float y2)
		{
			float num = x2 - x1;
			float num2 = y2 - y1;
			return Math.Atan2(num2, num) * 180.0 / Math.PI;
		}
	}
	public static class PluginInfo
	{
		public const string PLUGIN_GUID = "stickyNade";

		public const string PLUGIN_NAME = "stickyNade";

		public const string PLUGIN_VERSION = "1.0.0";
	}
}