Decompiled source of InvisiRay v2.1.3

MyFirstBoplMod_invisi_ray.dll

Decompiled 9 hours ago
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Logging;
using BoplFixedMath;
using HarmonyLib;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: AssemblyTitle("MyFirstBoplMod_invisi_ray")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("MyFirstBoplMod_invisi_ray")]
[assembly: AssemblyCopyright("Copyright ©  2026")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("dedaeefc-49bb-47e2-80fb-388d8acb9b9c")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")]
[assembly: AssemblyVersion("1.0.0.0")]
namespace MyFirstBoplMod_invisi_ray;

[BepInPlugin("com.YourUsername.InvisiRay", "Invisi-Ray Mod", "2.1.3")]
public class Plugin : BaseUnityPlugin
{
	internal static ManualLogSource Log;

	private void Awake()
	{
		//IL_0021: Unknown result type (might be due to invalid IL or missing references)
		Log = ((BaseUnityPlugin)this).Logger;
		Log.LogInfo((object)"Dedicated Invisi-Ray Mod loading...");
		new Harmony("com.YourUsername.InvisiRay").PatchAll();
		Log.LogInfo((object)"Invisi-Ray completely loaded!");
	}
}
[HarmonyPatch(typeof(AbilityGrid), "Awake")]
public class MenuInjectionPatch
{
	private static bool hasInjected;

	public static void Prefix(AbilityGrid __instance)
	{
		//IL_0044: Unknown result type (might be due to invalid IL or missing references)
		//IL_005f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0064: Unknown result type (might be due to invalid IL or missing references)
		//IL_0067: Unknown result type (might be due to invalid IL or missing references)
		//IL_0084: Unknown result type (might be due to invalid IL or missing references)
		//IL_0086: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b3: 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_00f6: 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_013f: 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_0179: Unknown result type (might be due to invalid IL or missing references)
		//IL_017d: 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_02eb: Unknown result type (might be due to invalid IL or missing references)
		//IL_01f0: Unknown result type (might be due to invalid IL or missing references)
		//IL_01f5: Unknown result type (might be due to invalid IL or missing references)
		//IL_01f9: 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_02a4: Unknown result type (might be due to invalid IL or missing references)
		//IL_02a9: Unknown result type (might be due to invalid IL or missing references)
		//IL_02ad: Unknown result type (might be due to invalid IL or missing references)
		//IL_02af: Unknown result type (might be due to invalid IL or missing references)
		//IL_0249: Unknown result type (might be due to invalid IL or missing references)
		//IL_024e: 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_0254: Unknown result type (might be due to invalid IL or missing references)
		if (hasInjected)
		{
			return;
		}
		NamedSpriteList value = Traverse.Create((object)__instance).Field("abilityIcons").GetValue<NamedSpriteList>();
		if (!((Object)(object)value != (Object)null) || value.sprites == null)
		{
			return;
		}
		NamedSprite val = default(NamedSprite);
		bool flag = false;
		foreach (NamedSprite sprite in value.sprites)
		{
			if (sprite.name.ToLower().Contains("grow"))
			{
				val = sprite;
				flag = true;
				break;
			}
		}
		if (!flag)
		{
			return;
		}
		GameObject val2 = Object.Instantiate<GameObject>(val.associatedGameObject);
		Object.DontDestroyOnLoad((Object)(object)val2);
		((Object)val2).name = "Invisi-Ray";
		Ability component = val2.GetComponent<Ability>();
		if ((Object)(object)component != (Object)null)
		{
			component.Cooldown = (Fix)4L;
		}
		Color val3 = default(Color);
		((Color)(ref val3))..ctor(0.15f, 0.15f, 0.15f, 1f);
		LineRenderer[] componentsInChildren = val2.GetComponentsInChildren<LineRenderer>(true);
		LineRenderer[] array = componentsInChildren;
		foreach (LineRenderer val4 in array)
		{
			val4.startColor = val3;
			val4.endColor = val3;
		}
		ParticleSystem[] componentsInChildren2 = val2.GetComponentsInChildren<ParticleSystem>(true);
		ParticleSystem[] array2 = componentsInChildren2;
		foreach (ParticleSystem val5 in array2)
		{
			MainModule main = val5.main;
			((MainModule)(ref main)).startColor = MinMaxGradient.op_Implicit(val3);
		}
		ShootScaleChange component2 = val2.GetComponent<ShootScaleChange>();
		if ((Object)(object)component2 != (Object)null)
		{
			if ((Object)(object)component2.RaycastParticlePrefab != (Object)null)
			{
				ParticleSystem val6 = Object.Instantiate<ParticleSystem>(component2.RaycastParticlePrefab);
				Object.DontDestroyOnLoad((Object)(object)((Component)val6).gameObject);
				val6.Stop();
				MainModule main2 = val6.main;
				((MainModule)(ref main2)).startColor = MinMaxGradient.op_Implicit(val3);
				if (((Component)val6).transform.childCount > 0)
				{
					ParticleSystem component3 = ((Component)((Component)val6).transform.GetChild(0)).GetComponent<ParticleSystem>();
					if ((Object)(object)component3 != (Object)null)
					{
						component3.Stop();
						MainModule main3 = component3.main;
						((MainModule)(ref main3)).startColor = MinMaxGradient.op_Implicit(val3);
					}
				}
				component2.RaycastParticlePrefab = val6;
			}
			if ((Object)(object)component2.RaycastParticleHitPrefab != (Object)null)
			{
				ParticleSystem val7 = Object.Instantiate<ParticleSystem>(component2.RaycastParticleHitPrefab);
				Object.DontDestroyOnLoad((Object)(object)((Component)val7).gameObject);
				val7.Stop();
				MainModule main4 = val7.main;
				((MainModule)(ref main4)).startColor = MinMaxGradient.op_Implicit(val3);
				component2.RaycastParticleHitPrefab = val7;
			}
		}
		val2.AddComponent<ShootInvisiRay>();
		Sprite val8 = LoadEmbeddedIcon();
		NamedSprite item = default(NamedSprite);
		((NamedSprite)(ref item))..ctor("Invisi-Ray", val8, val2, true);
		value.sprites.Add(item);
		hasInjected = true;
	}

	private static Sprite LoadEmbeddedIcon()
	{
		//IL_003d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0043: Expected O, but got Unknown
		//IL_0064: 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)
		Stream manifestResourceStream = Assembly.GetExecutingAssembly().GetManifestResourceStream("MyFirstBoplMod_invisi_ray.icon.png");
		if (manifestResourceStream != null)
		{
			byte[] array = new byte[manifestResourceStream.Length];
			manifestResourceStream.Read(array, 0, array.Length);
			Texture2D val = new Texture2D(256, 256);
			ImageConversion.LoadImage(val, array);
			return Sprite.Create(val, new Rect(0f, 0f, (float)((Texture)val).width, (float)((Texture)val).height), new Vector2(0.5f, 0.5f));
		}
		return null;
	}
}
[HarmonyPatch(typeof(ShootScaleChange), "ApplyScaleChange")]
public class InvisiRayHitPatch
{
	public static bool Prefix(ShootScaleChange __instance, RaycastInformation hit, Vec2 firepoint, Vec2 direction, ref bool hasFired, int playerId)
	{
		//IL_0025: 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_0049: Unknown result type (might be due to invalid IL or missing references)
		//IL_004e: 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_0054: Unknown result type (might be due to invalid IL or missing references)
		//IL_0055: Unknown result type (might be due to invalid IL or missing references)
		//IL_0068: Unknown result type (might be due to invalid IL or missing references)
		//IL_0069: Unknown result type (might be due to invalid IL or missing references)
		//IL_0090: 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_01ed: Unknown result type (might be due to invalid IL or missing references)
		//IL_01ff: Unknown result type (might be due to invalid IL or missing references)
		if (!((Object)((Component)__instance).gameObject).name.Contains("Invisi-Ray"))
		{
			return true;
		}
		if (hit.layer == LayerMask.NameToLayer("Water"))
		{
			hasFired = true;
			return true;
		}
		__instance.spawnRayCastEffect((Vector2)firepoint, (Vector2)direction, (float)hit.nearDist, true, false);
		FixTransform fixTrans = hit.pp.fixTrans;
		if ((Object)(object)fixTrans != (Object)null)
		{
			GameObject gameObject = ((Component)fixTrans).gameObject;
			int num = -1;
			if (hit.layer == LayerMask.NameToLayer("Player"))
			{
				IPlayerIdHolder component = ((Component)fixTrans).GetComponent<IPlayerIdHolder>();
				if (component != null)
				{
					num = component.GetPlayerId();
				}
				else
				{
					Ability component2 = ((Component)fixTrans).GetComponent<Ability>();
					if ((Object)(object)component2 != (Object)null)
					{
						num = component2.GetPlayerId();
					}
					else
					{
						SlimeController component3 = ((Component)fixTrans).GetComponent<SlimeController>();
						if ((Object)(object)component3 != (Object)null)
						{
							num = component3.GetPlayerId();
						}
					}
				}
			}
			Player val = null;
			if (num != -1)
			{
				val = PlayerHandler.Get().GetPlayer(num);
			}
			GameObject val2 = gameObject;
			if (val != null)
			{
				SlimeController componentInParent = gameObject.GetComponentInParent<SlimeController>();
				val2 = ((!((Object)(object)componentInParent != (Object)null)) ? ((Component)gameObject.transform.root).gameObject : ((Component)componentInParent).gameObject);
			}
			InvisibilityCloak invisibilityCloak = val2.GetComponent<InvisibilityCloak>();
			if ((Object)(object)invisibilityCloak == (Object)null)
			{
				invisibilityCloak = val2.AddComponent<InvisibilityCloak>();
			}
			invisibilityCloak.timer = 0f;
			invisibilityCloak.targetPlayer = val;
			if (val != null)
			{
				invisibilityCloak.duration = 4f;
				invisibilityCloak.fadeTime = 0.1f;
			}
			else if (hit.layer == LayerMask.NameToLayer("wall") || hit.layer == LayerMask.NameToLayer("NonLethalTerrain") || hit.layer == LayerMask.NameToLayer("LethalTerrain"))
			{
				invisibilityCloak.duration = 5f;
				invisibilityCloak.fadeTime = 0.7f;
			}
			else
			{
				invisibilityCloak.duration = 10f;
				invisibilityCloak.fadeTime = 0.1f;
			}
		}
		hasFired = true;
		return false;
	}
}
public class ShootInvisiRay : Ability
{
	public override void Init()
	{
	}

	public override void UpdateSim(Fix dt)
	{
	}
}
public class InvisibilityCloak : MonoBehaviour
{
	public float timer = 0f;

	public float duration = 5f;

	public Player targetPlayer;

	public float fadeTime = 0.7f;

	private Dictionary<SpriteRenderer, Color> originalColors = new Dictionary<SpriteRenderer, Color>();

	private void LateUpdate()
	{
		//IL_0043: Unknown result type (might be due to invalid IL or missing references)
		//IL_013e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0143: Unknown result type (might be due to invalid IL or missing references)
		//IL_0147: Unknown result type (might be due to invalid IL or missing references)
		//IL_014e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0155: Unknown result type (might be due to invalid IL or missing references)
		//IL_015d: 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_01bc: Unknown result type (might be due to invalid IL or missing references)
		timer += Time.deltaTime;
		bool flag = timer < duration;
		if (targetPlayer != null)
		{
			targetPlayer.isInvisible = flag;
			targetPlayer.timeSpentInvisible = Fix.Zero;
		}
		float num = 1f;
		if (timer < fadeTime)
		{
			num = Mathf.Lerp(1f, 0f, timer / fadeTime);
		}
		else if (timer > duration - fadeTime)
		{
			float num2 = timer - (duration - fadeTime);
			num = Mathf.Lerp(0f, 1f, num2 / fadeTime);
		}
		else
		{
			num = 0f;
		}
		SpriteRenderer[] componentsInChildren = ((Component)this).GetComponentsInChildren<SpriteRenderer>(true);
		SpriteRenderer[] array = componentsInChildren;
		foreach (SpriteRenderer val in array)
		{
			if (!((Object)(object)val == (Object)null))
			{
				if (!originalColors.ContainsKey(val))
				{
					originalColors[val] = val.color;
				}
				Color val2 = originalColors[val];
				val.color = new Color(val2.r, val2.g, val2.b, num);
			}
		}
		if (flag)
		{
			return;
		}
		foreach (KeyValuePair<SpriteRenderer, Color> originalColor in originalColors)
		{
			if ((Object)(object)originalColor.Key != (Object)null)
			{
				originalColor.Key.color = originalColor.Value;
			}
		}
		Object.Destroy((Object)(object)this);
	}
}