Decompiled source of GoldenVisualIndicator v0.3.4

mods/GoldenVisualIndicator.dll

Decompiled 2 weeks ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Reflection;
using System.Resources;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using Beetle_Utils;
using GoldenVisualIndicator;
using HarmonyLib;
using Il2Cpp;
using Il2CppInterop.Runtime.InteropTypes.Arrays;
using MelonLoader;
using Microsoft.CodeAnalysis;
using UnityEngine;
using UnityEngine.UI;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: MelonInfo(typeof(Core), "GoldenVisualIndicator", "0.1", "pablops", null)]
[assembly: MelonGame("Bugfight Studio", "Beetleball")]
[assembly: MelonAdditionalDependencies(new string[] { "BeetleUtils" })]
[assembly: MelonAdditionalCredits("Spike")]
[assembly: TargetFramework(".NETCoreApp,Version=v6.0", FrameworkDisplayName = ".NET 6.0")]
[assembly: AssemblyCompany("GoldenVisualIndicator")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("GoldenVisualIndicator")]
[assembly: AssemblyTitle("GoldenVisualIndicator")]
[assembly: NeutralResourcesLanguage("en-US")]
[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 GoldenVisualIndicator
{
	[HarmonyPatch(typeof(DungBall), "OnNetworkSpawn")]
	public static class DungBall_OnNetworkSpawn_Patch
	{
		private static void Postfix(DungBall __instance)
		{
			if (Core.Instance != null)
			{
				Core.Instance.OnDungBallSpawned(__instance);
			}
		}
	}
	public class Core : MelonMod
	{
		[CompilerGenerated]
		private sealed class <DestroyGoldenWarn>d__12 : IEnumerator<object>, IEnumerator, IDisposable
		{
			private int <>1__state;

			private object <>2__current;

			public float seconds;

			public GameObject go;

			public Core <>4__this;

			object IEnumerator<object>.Current
			{
				[DebuggerHidden]
				get
				{
					return <>2__current;
				}
			}

			object IEnumerator.Current
			{
				[DebuggerHidden]
				get
				{
					return <>2__current;
				}
			}

			[DebuggerHidden]
			public <DestroyGoldenWarn>d__12(int <>1__state)
			{
				this.<>1__state = <>1__state;
			}

			[DebuggerHidden]
			void IDisposable.Dispose()
			{
				<>1__state = -2;
			}

			private bool MoveNext()
			{
				//IL_0027: Unknown result type (might be due to invalid IL or missing references)
				//IL_0031: Expected O, but got Unknown
				switch (<>1__state)
				{
				default:
					return false;
				case 0:
					<>1__state = -1;
					<>2__current = (object)new WaitForSeconds(seconds);
					<>1__state = 1;
					return true;
				case 1:
					<>1__state = -1;
					if ((Object)(object)go != (Object)null)
					{
						<>4__this.activeWarnings = Mathf.Max(0, <>4__this.activeWarnings - 1);
						Object.Destroy((Object)(object)go);
					}
					return false;
				}
			}

			bool IEnumerator.MoveNext()
			{
				//ILSpy generated this explicit interface implementation from .override directive in MoveNext
				return this.MoveNext();
			}

			[DebuggerHidden]
			void IEnumerator.Reset()
			{
				throw new NotSupportedException();
			}
		}

		public static Core Instance;

		public List<DungBall> trackedDungBalls = new List<DungBall>();

		private HashSet<DungBall> goldenWarned = new HashSet<DungBall>();

		public bool onMainMenu = true;

		private RawImage goldenImage;

		private GameObject goldenGO = null;

		private int activeWarnings = 0;

		public Transform hudRoot = null;

		public override void OnInitializeMelon()
		{
			//IL_000c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0012: Expected O, but got Unknown
			Instance = this;
			Harmony val = new Harmony("golden.visual.indicator");
			val.PatchAll();
			((MelonBase)this).LoggerInstance.Msg("My quest for cheese concludes in a tragedy");
			((MelonBase)this).LoggerInstance.Msg("GoldenVisualIndicator Mod Initialized.");
		}

		public override void OnUpdate()
		{
			if (onMainMenu)
			{
				return;
			}
			foreach (DungBall trackedDungBall in trackedDungBalls)
			{
				if (trackedDungBall.Size >= 5 && !goldenWarned.Contains(trackedDungBall))
				{
					goldenWarned.Add(trackedDungBall);
					CreateGoldenWarningInHud();
				}
			}
		}

		public override void OnSceneWasLoaded(int buildIndex, string sceneName)
		{
			if (0 <= buildIndex && buildIndex <= 4)
			{
				onMainMenu = true;
				trackedDungBalls.Clear();
				goldenWarned.Clear();
				activeWarnings = 0;
			}
			else
			{
				onMainMenu = false;
			}
		}

		public void OnDungBallSpawned(DungBall db)
		{
			if (!onMainMenu && (Object)(object)db != (Object)null && !trackedDungBalls.Contains(db))
			{
				trackedDungBalls.Add(db);
			}
		}

		private void CreateGoldenWarningInHud()
		{
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_000c: Expected O, but got Unknown
			//IL_006b: 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_0086: Unknown result type (might be due to invalid IL or missing references)
			//IL_009c: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bc: Unknown result type (might be due to invalid IL or missing references)
			GameObject val = new GameObject("GoldenWarn");
			if ((Object)(object)hudRoot == (Object)null)
			{
				FindHudRoot();
			}
			val.transform.SetParent(hudRoot, false);
			RawImage val2 = val.AddComponent<RawImage>();
			val2.texture = (Texture)(object)LoadTexture("golden.png");
			RectTransform rectTransform = ((Graphic)val2).rectTransform;
			Vector2 val3 = default(Vector2);
			((Vector2)(ref val3))..ctor(0f, 1f);
			rectTransform.anchorMax = val3;
			rectTransform.anchorMin = val3;
			rectTransform.pivot = new Vector2(0.5f, 0f);
			rectTransform.sizeDelta = new Vector2(100f, 100f);
			float num = 80 + activeWarnings * 50;
			rectTransform.anchoredPosition = new Vector2(num, -500f);
			IconBouncer iconBouncer = val.AddComponent<IconBouncer>();
			activeWarnings++;
			MelonCoroutines.Start(DestroyGoldenWarn(4f, val));
		}

		[IteratorStateMachine(typeof(<DestroyGoldenWarn>d__12))]
		private IEnumerator DestroyGoldenWarn(float seconds, GameObject go)
		{
			//yield-return decompiler failed: Unexpected instruction in Iterator.Dispose()
			return new <DestroyGoldenWarn>d__12(0)
			{
				<>4__this = this,
				seconds = seconds,
				go = go
			};
		}

		private void FindHudRoot()
		{
			Il2CppArrayBase<Canvas> val = Object.FindObjectsOfType<Canvas>();
			foreach (Canvas item in val)
			{
				if (!(((Object)item).name == "Canvas") && !(((Object)item).name == "Canvas_CustomLobby"))
				{
					continue;
				}
				Transform val2 = ((Component)item).transform.Find("PlayerHUD");
				if ((Object)(object)val2 != (Object)null)
				{
					hudRoot = val2.Find("Root");
					if ((Object)(object)hudRoot != (Object)null)
					{
						break;
					}
				}
			}
		}

		private Texture2D LoadTexture(string fileName)
		{
			//IL_004c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0052: Expected O, but got Unknown
			string path = BeetleUtils.ModFolder();
			path = Path.Combine(path, "Assets");
			string text = Path.Combine(path, fileName);
			if (!File.Exists(text))
			{
				MelonLogger.Error("Texture not found: " + text);
				return null;
			}
			byte[] array = File.ReadAllBytes(text);
			Texture2D val = new Texture2D(2, 2, (TextureFormat)4, false);
			ImageConversion.LoadImage(val, Il2CppStructArray<byte>.op_Implicit(array));
			return val;
		}
	}
	[RegisterTypeInIl2Cpp]
	public class IconBouncer : MonoBehaviour
	{
		public float speed = 3f;

		public float height = 45f;

		public float squashAmount = 0.15f;

		public Vector3 originalPos;

		private Vector3 originalScale = Vector3.one;

		private void Start()
		{
			//IL_0008: 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)
			originalPos = ((Component)this).transform.localPosition;
		}

		private void Update()
		{
			UpdateBounce();
		}

		public void UpdateBounce()
		{
			//IL_0021: 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_003d: 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)
			float num = Mathf.Sin(Time.time * speed);
			float num2 = Mathf.Abs(num);
			((Component)this).transform.localPosition = originalPos + new Vector3(0f, num2 * height, 0f);
			float num3 = Mathf.Lerp(squashAmount, 0f - squashAmount, num2);
			float num4 = originalScale.x + num3;
			float num5 = originalScale.y - num3;
			((Component)this).transform.localScale = new Vector3(num4, num5, originalScale.z);
		}
	}
}