Decompiled source of UnpopJesters v1.0.1

UnpopJesters.dll

Decompiled 2 hours ago
using System;
using System.Collections;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Configuration;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using TMPro;
using Unity.Netcode;
using UnityEngine;
using UnityEngine.InputSystem;
using UnityEngine.InputSystem.Controls;
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: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("UnpopJesters")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("UnpopJesters")]
[assembly: AssemblyTitle("UnpopJesters")]
[assembly: AssemblyVersion("1.0.0.0")]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[Embedded]
	[AttributeUsage(AttributeTargets.Class | AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Event | AttributeTargets.Parameter | AttributeTargets.ReturnValue | AttributeTargets.GenericParameter, AllowMultiple = false, Inherited = false)]
	internal sealed class NullableAttribute : Attribute
	{
		public readonly byte[] NullableFlags;

		public NullableAttribute(byte P_0)
		{
			NullableFlags = new byte[1] { P_0 };
		}

		public NullableAttribute(byte[] P_0)
		{
			NullableFlags = P_0;
		}
	}
	[CompilerGenerated]
	[Embedded]
	[AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Method | AttributeTargets.Interface | AttributeTargets.Delegate, AllowMultiple = false, Inherited = false)]
	internal sealed class NullableContextAttribute : Attribute
	{
		public readonly byte Flag;

		public NullableContextAttribute(byte P_0)
		{
			Flag = P_0;
		}
	}
}
namespace TriteethUnpopJesters
{
	[BepInPlugin("com.triteeth.unpopjesters", "UnpopJestersMod", "1.0.0")]
	public class UnpopJestersMod : BaseUnityPlugin
	{
		public static ConfigEntry<string> actKey;

		public static ConfigEntry<int> dedAmt;

		public static ConfigEntry<int> brkThresh;

		public static ConfigEntry<string> stdTxt;

		public static ConfigEntry<string> brkTxt;

		public static ConfigEntry<string> noJstTxt;

		public static ConfigEntry<int> fSize;

		public static ConfigEntry<float> visDur;

		public static ConfigEntry<float> fadeDur;

		public static ConfigEntry<float> offX;

		public static ConfigEntry<float> offY;

		private GameObject? cv;

		private TextMeshProUGUI? tx;

		private Coroutine? rt;

		private Key pKey = (Key)28;

		public static float lockTimer;

		private readonly Harmony hmy = new Harmony("com.triteeth.unpopjesters");

		private void Awake()
		{
			//IL_019c: Unknown result type (might be due to invalid IL or missing references)
			//IL_019d: Unknown result type (might be due to invalid IL or missing references)
			actKey = ((BaseUnityPlugin)this).Config.Bind<string>("Input", "Key", "N", "The keyboard key to press");
			dedAmt = ((BaseUnityPlugin)this).Config.Bind<int>("Settings", "DeductionAmount", 100, "Money removed on press");
			brkThresh = ((BaseUnityPlugin)this).Config.Bind<int>("Settings", "BrokeThreshold", 100, "Below this amount shows broke text");
			stdTxt = ((BaseUnityPlugin)this).Config.Bind<string>("Display Text", "StandardText", "(-100)", "Text when money is deducted");
			brkTxt = ((BaseUnityPlugin)this).Config.Bind<string>("Display Text", "BrokeText", "UR BROKE", "Text when below threshold");
			noJstTxt = ((BaseUnityPlugin)this).Config.Bind<string>("Display Text", "NoJestersText", "NO JESTERS POPPED", "Text when no jesters are active");
			fSize = ((BaseUnityPlugin)this).Config.Bind<int>("UI Styling", "FontSize", 72, "Size of the text font");
			visDur = ((BaseUnityPlugin)this).Config.Bind<float>("UI Styling", "VisibleDuration", 2f, "Time text stays completely visible");
			fadeDur = ((BaseUnityPlugin)this).Config.Bind<float>("UI Styling", "FadeDuration", 1f, "Time text takes to fade away");
			offX = ((BaseUnityPlugin)this).Config.Bind<float>("UI Positioning", "OffsetX", 0f, "Horizontal text position screen offset");
			offY = ((BaseUnityPlugin)this).Config.Bind<float>("UI Positioning", "OffsetY", 100f, "Vertical text position screen offset");
			if (Enum.TryParse<Key>(actKey.Value, ignoreCase: true, out Key result))
			{
				pKey = result;
			}
			hmy.PatchAll(typeof(UnpopJestersMod));
		}

		private void Update()
		{
			//IL_0052: Unknown result type (might be due to invalid IL or missing references)
			if (Object.op_Implicit((Object)(object)NetworkManager.Singleton) && NetworkManager.Singleton.IsServer)
			{
				if (lockTimer > 0f)
				{
					lockTimer -= Time.deltaTime;
				}
				if (Keyboard.current != null && ((ButtonControl)Keyboard.current[pKey]).wasPressedThisFrame)
				{
					Run();
				}
			}
		}

		private void Run()
		{
			Terminal val = Object.FindFirstObjectByType<Terminal>();
			if ((Object)(object)val == (Object)null)
			{
				return;
			}
			JesterAI[] array = Object.FindObjectsOfType<JesterAI>();
			bool flag = false;
			JesterAI[] array2 = array;
			foreach (JesterAI val2 in array2)
			{
				if ((Object)(object)val2 != (Object)null && ((EnemyAI)val2).currentBehaviourStateIndex == 2)
				{
					flag = true;
					break;
				}
			}
			string text = "";
			if (!flag && lockTimer <= 0f)
			{
				text = noJstTxt.Value;
			}
			else if (val.groupCredits < brkThresh.Value)
			{
				text = brkTxt.Value;
			}
			else
			{
				val.groupCredits -= dedAmt.Value;
				if (val.groupCredits < 0)
				{
					val.groupCredits = 0;
				}
				val.SyncGroupCreditsServerRpc(val.groupCredits, val.numberOfItemsInDropship);
				text = stdTxt.Value;
				lockTimer = 240f;
				JesterAI[] array3 = array;
				foreach (JesterAI val3 in array3)
				{
					if ((Object)(object)val3 != (Object)null)
					{
						((EnemyAI)val3).SwitchToBehaviourClientRpc(0);
					}
				}
			}
			if (rt != null)
			{
				((MonoBehaviour)this).StopCoroutine(rt);
			}
			rt = ((MonoBehaviour)this).StartCoroutine(Fx(text));
		}

		[HarmonyPatch(typeof(JesterAI), "Update")]
		[HarmonyPrefix]
		public static void ForceJesterStayBoxed(JesterAI __instance)
		{
			if (Object.op_Implicit((Object)(object)NetworkManager.Singleton) && NetworkManager.Singleton.IsServer && lockTimer > 0f)
			{
				__instance.popUpTimer = -240f;
				((EnemyAI)__instance).creatureAnimator.SetBool("isWindingUp", false);
				if (((EnemyAI)__instance).currentBehaviourStateIndex != 0)
				{
					((EnemyAI)__instance).SwitchToBehaviourClientRpc(0);
				}
			}
		}

		private IEnumerator Fx(string s)
		{
			Init();
			if (!((Object)(object)tx == (Object)null))
			{
				((TMP_Text)tx).text = s;
				((Graphic)tx).color = Color.red;
				yield return (object)new WaitForSeconds(visDur.Value);
				float e = 0f;
				while (e < fadeDur.Value)
				{
					e += Time.deltaTime;
					float a = Mathf.Lerp(1f, 0f, e / fadeDur.Value);
					((Graphic)tx).color = new Color(1f, 0f, 0f, a);
					yield return null;
				}
				((Graphic)tx).color = new Color(1f, 0f, 0f, 0f);
			}
		}

		private void Init()
		{
			//IL_001e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0028: Expected O, but got Unknown
			//IL_0059: Unknown result type (might be due to invalid IL or missing references)
			//IL_005f: Expected O, but got Unknown
			//IL_0119: Unknown result type (might be due to invalid IL or missing references)
			if (!((Object)(object)cv != (Object)null))
			{
				cv = new GameObject("QCanvas");
				Canvas val = cv.AddComponent<Canvas>();
				val.renderMode = (RenderMode)0;
				cv.AddComponent<CanvasScaler>();
				cv.AddComponent<GraphicRaycaster>();
				GameObject val2 = new GameObject("QText");
				val2.transform.SetParent(cv.transform, false);
				tx = val2.AddComponent<TextMeshProUGUI>();
				((TMP_Text)tx).fontSize = fSize.Value;
				((TMP_Text)tx).alignment = (TextAlignmentOptions)514;
				TextMeshProUGUI val3 = Object.FindFirstObjectByType<TextMeshProUGUI>();
				if ((Object)(object)val3 != (Object)null && (Object)(object)((TMP_Text)val3).font != (Object)null)
				{
					((TMP_Text)tx).font = ((TMP_Text)val3).font;
				}
				RectTransform component = val2.GetComponent<RectTransform>();
				component.SetSizeWithCurrentAnchors((Axis)0, 800f);
				component.SetSizeWithCurrentAnchors((Axis)1, 200f);
				component.anchoredPosition = new Vector2(offX.Value, offY.Value);
			}
		}
	}
}