Decompiled source of InvisiRay v2.0.1

MyFirstBoplMod_invisi_ray.dll

Decompiled 3 hours ago
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.0.0")]
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_00b0: Unknown result type (might be due to invalid IL or missing references)
		//IL_011f: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ee: 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)
		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)
		{
			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)5L;
			}
			val2.AddComponent<ShootInvisiRay>();
			Sprite val3 = LoadEmbeddedIcon();
			NamedSprite item = default(NamedSprite);
			((NamedSprite)(ref item))..ctor("Invisi-Ray", val3, 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_0044: Unknown result type (might be due to invalid IL or missing references)
		//IL_0045: 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_004b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0050: Unknown result type (might be due to invalid IL or missing references)
		//IL_0051: 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_0065: 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"))
		{
			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;
			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 targetPlayer = null;
			if (num != -1)
			{
				targetPlayer = PlayerHandler.Get().GetPlayer(num);
				Plugin.Log.LogInfo((object)("Invisi-Ray successfully hit Player " + num));
			}
			InvisibilityCloak invisibilityCloak = gameObject.GetComponent<InvisibilityCloak>();
			if ((Object)(object)invisibilityCloak == (Object)null)
			{
				invisibilityCloak = gameObject.AddComponent<InvisibilityCloak>();
			}
			invisibilityCloak.timer = 0f;
			invisibilityCloak.targetPlayer = targetPlayer;
		}
		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 = 3f;

	public Player targetPlayer;

	private SpriteRenderer[] sprites;

	private void Awake()
	{
		sprites = ((Component)this).GetComponentsInChildren<SpriteRenderer>(true);
	}

	private void LateUpdate()
	{
		//IL_0043: 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;
		}
		else if (sprites != null)
		{
			SpriteRenderer[] array = sprites;
			foreach (SpriteRenderer val in array)
			{
				if ((Object)(object)val != (Object)null)
				{
					((Renderer)val).enabled = !flag;
				}
			}
		}
		if (!flag)
		{
			Object.Destroy((Object)(object)this);
		}
	}
}