Decompiled source of EnemyPositionDisplay v1.0.0

EnemyPositionDisplay.dll

Decompiled 2 years ago
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using BepInEx;
using HarmonyLib;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: AssemblyTitle("EnemyPositionDisplay")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("EnemyPositionDisplay")]
[assembly: AssemblyCopyright("Copyright ©  2025")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("F99D0088-701D-44FD-A0F3-1185A94BEA19")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")]
[assembly: AssemblyVersion("1.0.0.0")]
namespace EnemyPositionDisplay;

[BepInPlugin("EnemyPositionDisplay", "EnemyPositionDisplay", "1.0.0")]
public class EnemyPositionDisplay : BaseUnityPlugin
{
	[HarmonyPatch(typeof(EnemyParent), "SpawnRPC")]
	public static class SpawnRPCHookPatch
	{
		private static void Postfix(EnemyParent __instance)
		{
			//IL_005b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0060: Unknown result type (might be due to invalid IL or missing references)
			//IL_0061: Unknown result type (might be due to invalid IL or missing references)
			//IL_0073: Expected I4, but got Unknown
			//IL_0081: 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_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_00af: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b4: 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_00cb: Unknown result type (might be due to invalid IL or missing references)
			object? value = typeof(EnemyParent).GetField("Enemy", BindingFlags.Instance | BindingFlags.NonPublic).GetValue(__instance);
			Debug.Log((object)("Enemy difficulty: " + ((object)(Difficulty)(ref __instance.difficulty)).ToString()));
			Enemy val = (Enemy)((value is Enemy) ? value : null);
			if ((Object)(object)val != (Object)null)
			{
				MapCustom val2 = ((Component)val).gameObject.AddComponent<MapCustom>();
				Difficulty difficulty = __instance.difficulty;
				switch ((int)difficulty)
				{
				case 0:
					val2.sprite = enemySpriteSquare;
					val2.color = Color.red;
					break;
				case 1:
					val2.sprite = enemySpriteCircle;
					val2.color = Color.red;
					break;
				case 2:
					val2.sprite = enemySpriteTriangle;
					val2.color = Color.red;
					break;
				default:
					val2.sprite = enemySpriteSquare;
					val2.color = Color.red;
					break;
				}
			}
		}
	}

	private static Sprite enemySpriteSquare;

	private static Sprite enemySpriteCircle;

	private static Sprite enemySpriteTriangle;

	private void Awake()
	{
		//IL_0005: Unknown result type (might be due to invalid IL or missing references)
		new Harmony("EnemyPositionDisplay").PatchAll(Assembly.GetExecutingAssembly());
		CreateEnemySprites();
	}

	private static void CreateEnemySprites()
	{
		if (!((Object)(object)enemySpriteSquare != (Object)null) || !((Object)(object)enemySpriteCircle != (Object)null) || !((Object)(object)enemySpriteTriangle != (Object)null))
		{
			enemySpriteSquare = CreateSquareSprite();
			enemySpriteCircle = CreateCircleSprite();
			enemySpriteTriangle = CreateTriangleSprite();
		}
	}

	private static Sprite CreateSquareSprite()
	{
		//IL_0006: Unknown result type (might be due to invalid IL or missing references)
		//IL_000c: Expected O, but got Unknown
		//IL_001b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0020: 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_005a: Unknown result type (might be due to invalid IL or missing references)
		int num = 5;
		Texture2D val = new Texture2D(num, num, (TextureFormat)5, false);
		Color[] array = (Color[])(object)new Color[num * num];
		for (int i = 0; i < array.Length; i++)
		{
			array[i] = Color.white;
		}
		val.SetPixels(array);
		val.Apply();
		return Sprite.Create(val, new Rect(0f, 0f, (float)num, (float)num), new Vector2(0.5f, 0.5f));
	}

	private static Sprite CreateCircleSprite()
	{
		//IL_0006: Unknown result type (might be due to invalid IL or missing references)
		//IL_000c: Expected O, but got Unknown
		//IL_00aa: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b9: Unknown result type (might be due to invalid IL or missing references)
		//IL_006e: 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)
		//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)
		int num = 5;
		Texture2D val = new Texture2D(num, num, (TextureFormat)5, false);
		Color[] array = (Color[])(object)new Color[num * num];
		float num2 = (float)num / 2f;
		float num3 = (float)num / 2f - 1f;
		for (int i = 0; i < num; i++)
		{
			for (int j = 0; j < num; j++)
			{
				int num4 = i * num + j;
				float num5 = (float)j - num2;
				float num6 = (float)i - num2;
				if (num5 * num5 + num6 * num6 <= num3 * num3)
				{
					array[num4] = Color.white;
				}
				else
				{
					array[num4] = Color.clear;
				}
			}
		}
		val.SetPixels(array);
		val.Apply();
		return Sprite.Create(val, new Rect(0f, 0f, (float)num, (float)num), new Vector2(0.5f, 0.5f));
	}

	private static Sprite CreateTriangleSprite()
	{
		//IL_0007: Unknown result type (might be due to invalid IL or missing references)
		//IL_000d: Expected O, but got Unknown
		//IL_00c2: 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_005a: 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_006b: 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_008b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0077: Unknown result type (might be due to invalid IL or missing references)
		//IL_007c: Unknown result type (might be due to invalid IL or missing references)
		int num = 10;
		Texture2D val = new Texture2D(num, num, (TextureFormat)5, false);
		Color[] array = (Color[])(object)new Color[num * num];
		Vector2 a = default(Vector2);
		((Vector2)(ref a))..ctor((float)num / 2f, (float)(num - 1));
		Vector2 b = default(Vector2);
		((Vector2)(ref b))..ctor(1f, 1f);
		Vector2 c = default(Vector2);
		((Vector2)(ref c))..ctor((float)(num - 2), 1f);
		for (int i = 0; i < num; i++)
		{
			for (int j = 0; j < num; j++)
			{
				Vector2 p = new Vector2((float)j, (float)i);
				int num2 = i * num + j;
				if (IsPointInTriangle(p, a, b, c))
				{
					array[num2] = Color.white;
				}
				else
				{
					array[num2] = Color.clear;
				}
			}
		}
		val.SetPixels(array);
		val.Apply();
		return Sprite.Create(val, new Rect(0f, 0f, (float)num, (float)num), new Vector2(0.5f, 0.5f));
	}

	private static bool IsPointInTriangle(Vector2 p, Vector2 a, Vector2 b, Vector2 c)
	{
		//IL_0000: 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)
		//IL_000d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0013: Unknown result type (might be due to invalid IL or missing references)
		//IL_001b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0021: Unknown result type (might be due to invalid IL or missing references)
		//IL_0028: 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)
		//IL_0037: Unknown result type (might be due to invalid IL or missing references)
		//IL_003d: 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_004a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0052: 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_005f: 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)
		//IL_006f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0075: Unknown result type (might be due to invalid IL or missing references)
		//IL_007c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0082: Unknown result type (might be due to invalid IL or missing references)
		//IL_008a: 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_0097: 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)
		float num = (p.x - b.x) * (a.y - b.y) - (a.x - b.x) * (p.y - b.y);
		float num2 = (p.x - c.x) * (b.y - c.y) - (b.x - c.x) * (p.y - c.y);
		float num3 = (p.x - a.x) * (c.y - a.y) - (c.x - a.x) * (p.y - a.y);
		bool flag = num < 0f || num2 < 0f || num3 < 0f;
		bool flag2 = num > 0f || num2 > 0f || num3 > 0f;
		return !(flag && flag2);
	}
}