Decompiled source of GambitChecker v1.0.0

BepInEx/plugins/GambitChecker/GambitChecker.dll

Decompiled 19 hours ago
using System;
using System.Collections;
using System.Diagnostics;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Logging;
using HarmonyLib;
using TMPro;
using UnityEngine;
using UnityEngine.UI;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: AssemblyTitle("GambitChecker")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("GambitChecker")]
[assembly: AssemblyCopyright("Copyright ©  2026")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("8090df7f-7d3b-427e-bbe3-c69ec3e2acd4")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")]
[assembly: AssemblyVersion("1.0.0.0")]
namespace GambitCheckerMod;

[BepInPlugin("com.nuke_land.gambitchecker", "Gambit Level Checker", "1.0.0")]
public class GambitChecker : BaseUnityPlugin
{
	public static ManualLogSource logger;

	public static float WheelSize { get; set; } = 250f;

	public static float PositionX { get; set; } = 780f;

	public static float PositionY { get; set; } = -350f;

	private void Awake()
	{
		logger = ((BaseUnityPlugin)this).Logger;
		Harmony.CreateAndPatchAll(typeof(GambitChecker), (string)null);
		((BaseUnityPlugin)this).Logger.LogInfo((object)"GambitChecker mod loaded!");
	}

	[HarmonyPatch(typeof(LevelGenerator), "GenerateDone")]
	[HarmonyPostfix]
	private static void OnLevelGenerated(LevelGenerator __instance)
	{
		//IL_0069: Unknown result type (might be due to invalid IL or missing references)
		if (!((Object)(object)__instance == (Object)null) && !((Object)__instance.Level).name.Contains("Lobby") && !((Object)__instance.Level).name.Contains("Shop") && !((Object)__instance.Level).name.Contains("Level - Arena Fight") && !SemiFunc.MenuLevel() && !((Object)(object)PlayerController.instance == (Object)null))
		{
			new GameObject("GambitTemp").AddComponent<GambitTempChecker>().StartCheck();
		}
	}
}
public class GambitTempChecker : MonoBehaviour
{
	private GameObject uiRoot;

	private TextMeshProUGUI titleLabel;

	private TextMeshProUGUI countLabel;

	public void StartCheck()
	{
		((MonoBehaviour)this).StartCoroutine(DoCheck());
	}

	private IEnumerator DoCheck()
	{
		yield return (object)new WaitForSeconds(2.8f);
		int count = (from go in Object.FindObjectsOfType<GameObject>(true)
			where (Object)(object)go != (Object)null && go.activeInHierarchy && ((Object)go).name.Contains("Spinny")
			select go).ToList().Count;
		CreateGambitWheelUI(count);
		yield return (object)new WaitForSeconds(3.5f);
		yield return ((MonoBehaviour)this).StartCoroutine(ShowTextWithFade());
		yield return (object)new WaitForSeconds(3f);
		yield return ((MonoBehaviour)this).StartCoroutine(FadeOut());
		Object.Destroy((Object)(object)((Component)this).gameObject);
	}

	private void CreateGambitWheelUI(int gambitCount)
	{
		//IL_0005: Unknown result type (might be due to invalid IL or missing references)
		//IL_000b: Expected O, but got Unknown
		//IL_0039: Unknown result type (might be due to invalid IL or missing references)
		//IL_006d: 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_00a5: Unknown result type (might be due to invalid IL or missing references)
		//IL_00be: 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_0118: Unknown result type (might be due to invalid IL or missing references)
		//IL_011e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0137: Unknown result type (might be due to invalid IL or missing references)
		//IL_0156: Unknown result type (might be due to invalid IL or missing references)
		//IL_015c: Expected O, but got Unknown
		//IL_018b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0192: Unknown result type (might be due to invalid IL or missing references)
		//IL_01a5: Unknown result type (might be due to invalid IL or missing references)
		//IL_01b3: Unknown result type (might be due to invalid IL or missing references)
		//IL_01bf: Unknown result type (might be due to invalid IL or missing references)
		//IL_01c0: Unknown result type (might be due to invalid IL or missing references)
		//IL_01de: Unknown result type (might be due to invalid IL or missing references)
		GameObject val = new GameObject("GambitWheelCanvas");
		Canvas obj = val.AddComponent<Canvas>();
		obj.renderMode = (RenderMode)0;
		obj.sortingOrder = 9999;
		CanvasScaler obj2 = val.AddComponent<CanvasScaler>();
		obj2.uiScaleMode = (ScaleMode)1;
		obj2.referenceResolution = new Vector2(1920f, 1080f);
		uiRoot = val;
		Vector2 val2 = default(Vector2);
		((Vector2)(ref val2))..ctor(GambitChecker.PositionX, GambitChecker.PositionY);
		float wheelSize = GambitChecker.WheelSize;
		titleLabel = CreateText("Gambit count:", 28f, Color.white);
		((TMP_Text)titleLabel).transform.SetParent(val.transform, false);
		((TMP_Text)titleLabel).transform.localPosition = new Vector3(val2.x, val2.y + wheelSize / 2f + 60f, 0f);
		((TMP_Text)titleLabel).alpha = 0f;
		countLabel = CreateText(gambitCount.ToString(), 48f, Color.white, bold: true);
		((TMP_Text)countLabel).transform.SetParent(val.transform, false);
		((TMP_Text)countLabel).transform.localPosition = new Vector3(val2.x, val2.y + wheelSize / 2f + 25f, 0f);
		((TMP_Text)countLabel).alpha = 0f;
		GameObject val3 = new GameObject("WheelContainer");
		val3.transform.SetParent(val.transform, false);
		RectTransform val4 = val3.AddComponent<RectTransform>();
		Vector2 val5 = default(Vector2);
		((Vector2)(ref val5))..ctor(0.5f, 0.5f);
		val4.anchorMax = val5;
		val4.anchorMin = val5;
		val4.pivot = new Vector2(0.5f, 0.5f);
		val4.sizeDelta = new Vector2(wheelSize, wheelSize);
		((Transform)val4).localPosition = Vector2.op_Implicit(val2);
		CreateWheel(val3.transform, wheelSize);
		CreateArrow(val.transform, val2, wheelSize);
		((MonoBehaviour)this).StartCoroutine(SpinWheel(val4, gambitCount, wheelSize));
	}

	private TextMeshProUGUI CreateText(string text, float fontSize, Color color, bool bold = false)
	{
		//IL_000b: 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_004d: 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_0077: Unknown result type (might be due to invalid IL or missing references)
		//IL_007d: Unknown result type (might be due to invalid IL or missing references)
		//IL_008e: Unknown result type (might be due to invalid IL or missing references)
		//IL_00a2: Unknown result type (might be due to invalid IL or missing references)
		TextMeshProUGUI obj = new GameObject("Text_" + text).AddComponent<TextMeshProUGUI>();
		((TMP_Text)obj).text = text;
		((TMP_Text)obj).fontSize = fontSize;
		((TMP_Text)obj).alignment = (TextAlignmentOptions)514;
		((TMP_Text)obj).fontStyle = (FontStyles)(bold ? 1 : 0);
		((TMP_Text)obj).outlineWidth = 0.15f;
		((TMP_Text)obj).outlineColor = Color32.op_Implicit(Color.black);
		((Graphic)obj).color = color;
		RectTransform component = ((Component)obj).GetComponent<RectTransform>();
		Vector2 val = default(Vector2);
		((Vector2)(ref val))..ctor(0.5f, 0.5f);
		component.anchorMax = val;
		component.anchorMin = val;
		component.pivot = new Vector2(0.5f, 0.5f);
		component.sizeDelta = new Vector2(400f, 80f);
		return obj;
	}

	private void CreateArrow(Transform parent, Vector2 position, float wheelSize)
	{
		//IL_0005: Unknown result type (might be due to invalid IL or missing references)
		//IL_000a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0017: Unknown result type (might be due to invalid IL or missing references)
		//IL_0030: 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_0047: Unknown result type (might be due to invalid IL or missing references)
		//IL_005c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0066: Unknown result type (might be due to invalid IL or missing references)
		//IL_006c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0085: Unknown result type (might be due to invalid IL or missing references)
		//IL_0095: 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_00ce: Unknown result type (might be due to invalid IL or missing references)
		GameObject val = new GameObject("Arrow");
		val.transform.SetParent(parent, false);
		RectTransform obj = val.AddComponent<RectTransform>();
		Vector2 val2 = default(Vector2);
		((Vector2)(ref val2))..ctor(0.5f, 0.5f);
		obj.anchorMax = val2;
		obj.anchorMin = val2;
		obj.pivot = new Vector2(0.5f, 1f);
		obj.sizeDelta = new Vector2(40f, 50f);
		((Transform)obj).localPosition = new Vector3(position.x, position.y + wheelSize / 2f - 10f, 0f);
		Image obj2 = val.AddComponent<Image>();
		((Graphic)obj2).color = Color.black;
		Texture2D val3 = CreateTriangleTexture();
		Sprite sprite = Sprite.Create(val3, new Rect(0f, 0f, (float)((Texture)val3).width, (float)((Texture)val3).height), new Vector2(0.5f, 0f));
		obj2.sprite = sprite;
	}

	private Texture2D CreateTriangleTexture()
	{
		//IL_0007: Unknown result type (might be due to invalid IL or missing references)
		//IL_000d: Expected O, but got Unknown
		//IL_009b: Unknown result type (might be due to invalid IL or missing references)
		//IL_00a0: 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_008d: 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_007a: Unknown result type (might be due to invalid IL or missing references)
		int num = 64;
		Texture2D val = new Texture2D(num, num, (TextureFormat)4, false);
		Color[] pixels = val.GetPixels();
		for (int i = 0; i < num; i++)
		{
			for (int j = 0; j < num; j++)
			{
				float num2 = 5f;
				float num3 = num - 5;
				float num4 = (float)num / 2f;
				if ((float)i >= num2 && (float)i <= num3)
				{
					float num5 = ((float)i - num2) / (num3 - num2);
					float num6 = num4 * num5;
					if ((float)j >= num4 - num6 && (float)j <= num4 + num6)
					{
						pixels[i * num + j] = Color.black;
					}
					else
					{
						pixels[i * num + j] = Color.clear;
					}
				}
				else
				{
					pixels[i * num + j] = Color.clear;
				}
			}
		}
		val.SetPixels(pixels);
		val.Apply();
		return val;
	}

	private void CreateWheel(Transform parent, float size)
	{
		//IL_000d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0012: Unknown result type (might be due to invalid IL or missing references)
		//IL_001f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0038: Unknown result type (might be due to invalid IL or missing references)
		//IL_003e: 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_005b: 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_009a: Unknown result type (might be due to invalid IL or missing references)
		float radius = size / 2f;
		GameObject val = new GameObject("Wheel");
		val.transform.SetParent(parent, false);
		RectTransform obj = val.AddComponent<RectTransform>();
		Vector2 val2 = default(Vector2);
		((Vector2)(ref val2))..ctor(0.5f, 0.5f);
		obj.anchorMax = val2;
		obj.anchorMin = val2;
		obj.pivot = new Vector2(0.5f, 0.5f);
		obj.sizeDelta = new Vector2(size, size);
		Image obj2 = val.AddComponent<Image>();
		Texture2D val3 = CreateWheelTexture(radius);
		Sprite sprite = Sprite.Create(val3, new Rect(0f, 0f, (float)((Texture)val3).width, (float)((Texture)val3).height), new Vector2(0.5f, 0.5f));
		obj2.sprite = sprite;
	}

	private Texture2D CreateWheelTexture(float radius)
	{
		//IL_0010: Unknown result type (might be due to invalid IL or missing references)
		//IL_0016: Expected O, but got Unknown
		//IL_00a8: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ad: Unknown result type (might be due to invalid IL or missing references)
		//IL_00c7: Unknown result type (might be due to invalid IL or missing references)
		//IL_00cc: Unknown result type (might be due to invalid IL or missing references)
		//IL_012c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0131: Unknown result type (might be due to invalid IL or missing references)
		//IL_0191: Unknown result type (might be due to invalid IL or missing references)
		//IL_0196: 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_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)
		int num = (int)(radius * 2f) + 20;
		Texture2D val = new Texture2D(num, num, (TextureFormat)4, false);
		Color[] pixels = val.GetPixels();
		float num2 = (float)num / 2f;
		float num3 = (float)num / 2f;
		float num4 = 8f;
		float num5 = 4f;
		float[] array = new float[6];
		for (int i = 0; i < 6; i++)
		{
			array[i] = (float)i * 60f * ((float)Math.PI / 180f);
		}
		for (int j = 0; j < num; j++)
		{
			for (int k = 0; k < num; k++)
			{
				float num6 = (float)k - num2;
				float num7 = (float)j - num3;
				float num8 = Mathf.Sqrt(num6 * num6 + num7 * num7);
				if (num8 > radius)
				{
					pixels[j * num + k] = Color.clear;
					continue;
				}
				if (num8 > radius - num4)
				{
					pixels[j * num + k] = Color.black;
					continue;
				}
				bool flag = false;
				float[] array2 = array;
				foreach (float num9 in array2)
				{
					if (Mathf.Abs(num6 * Mathf.Sin(num9) - num7 * Mathf.Cos(num9)) < num5 / 2f)
					{
						flag = true;
						break;
					}
				}
				if (flag)
				{
					pixels[j * num + k] = Color.black;
					continue;
				}
				float num10 = Mathf.Atan2(num7, num6) * 57.29578f;
				if (num10 < 0f)
				{
					num10 += 360f;
				}
				if (num10 < 60f || (num10 >= 180f && num10 < 240f))
				{
					pixels[j * num + k] = new Color(1f, 0.3f, 0.3f);
				}
				else if ((num10 >= 60f && num10 < 120f) || (num10 >= 240f && num10 < 300f))
				{
					pixels[j * num + k] = new Color(1f, 1f, 0.3f);
				}
				else if ((num10 >= 120f && num10 < 180f) || num10 >= 300f)
				{
					pixels[j * num + k] = new Color(0.3f, 1f, 0.3f);
				}
			}
		}
		val.SetPixels(pixels);
		val.Apply();
		return val;
	}

	private IEnumerator SpinWheel(RectTransform wheel, int gambitCount, float size)
	{
		float randomAngleForSector = GetRandomAngleForSector(gambitCount);
		float num = 1800f + randomAngleForSector;
		float duration = 3f;
		float elapsed = 0f;
		Vector3 startRotation = ((Transform)wheel).localEulerAngles;
		Vector3 endRotation = new Vector3(0f, 0f, num);
		while (elapsed < duration)
		{
			elapsed += Time.deltaTime;
			float num2 = elapsed / duration;
			num2 = 1f - Mathf.Pow(1f - num2, 3f);
			((Transform)wheel).localEulerAngles = Vector3.Lerp(startRotation, endRotation, num2);
			yield return null;
		}
		((Transform)wheel).localEulerAngles = endRotation;
	}

	private float GetRandomAngleForSector(int gambitCount)
	{
		Random random = new Random();
		return gambitCount switch
		{
			0 => (new float[2] { 60f, 240f })[random.Next(2)] + (float)(random.NextDouble() * 40.0 - 20.0), 
			1 => (new float[2] { 120f, 300f })[random.Next(2)] + (float)(random.NextDouble() * 40.0 - 20.0), 
			_ => (new float[2] { 0f, 180f })[random.Next(2)] + (float)(random.NextDouble() * 40.0 - 20.0), 
		};
	}

	private IEnumerator ShowTextWithFade()
	{
		float fadeDuration = 0.5f;
		float elapsed = 0f;
		while (elapsed < fadeDuration)
		{
			elapsed += Time.deltaTime;
			float alpha = Mathf.Lerp(0f, 1f, elapsed / fadeDuration);
			((TMP_Text)titleLabel).alpha = alpha;
			((TMP_Text)countLabel).alpha = alpha;
			yield return null;
		}
		((TMP_Text)titleLabel).alpha = 1f;
		((TMP_Text)countLabel).alpha = 1f;
	}

	private IEnumerator FadeOut()
	{
		if (!((Object)(object)uiRoot == (Object)null))
		{
			CanvasGroup canvasGroup = uiRoot.AddComponent<CanvasGroup>();
			float duration = 1f;
			float elapsed = 0f;
			while (elapsed < duration)
			{
				elapsed += Time.deltaTime;
				canvasGroup.alpha = Mathf.Lerp(1f, 0f, elapsed / duration);
				yield return null;
			}
			Object.Destroy((Object)(object)uiRoot);
		}
	}
}