Decompiled source of REPONoItemsLeft v1.1.0

plugins/REPONoItemsLeft/REPONoItemsLeft.dll

Decompiled 5 hours ago
using System;
using System.Collections;
using System.Collections.Generic;
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.Configuration;
using BepInEx.Logging;
using HarmonyLib;
using Photon.Pun;
using REPONoItemsLeft.Patches;
using TMPro;
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: AssemblyTitle("REPONoItemsLeft")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("REPONoItemsLeft")]
[assembly: AssemblyCopyright("Copyright ©  2025")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("2ad62837-eb44-4bdd-9102-c6d3ae425ed5")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")]
[assembly: AssemblyVersion("1.0.0.0")]
public class KillManager : MonoBehaviourPun
{
	[CompilerGenerated]
	private sealed class <KillThemAll>d__10 : IEnumerator<object>, IDisposable, IEnumerator
	{
		private int <>1__state;

		private object <>2__current;

		public KillManager <>4__this;

		private TextMeshProUGUI <killOrDieText>5__1;

		private TextMeshProUGUI <counterText>5__2;

		private TextMeshProUGUI <dieText>5__3;

		private float <timer>5__4;

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

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

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

		[DebuggerHidden]
		void IDisposable.Dispose()
		{
			<killOrDieText>5__1 = null;
			<counterText>5__2 = null;
			<dieText>5__3 = null;
			<>1__state = -2;
		}

		private bool MoveNext()
		{
			//IL_009c: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00da: Expected O, but got Unknown
			//IL_0101: Unknown result type (might be due to invalid IL or missing references)
			//IL_0123: Unknown result type (might be due to invalid IL or missing references)
			//IL_012d: Expected O, but got Unknown
			//IL_0154: Unknown result type (might be due to invalid IL or missing references)
			//IL_0176: Unknown result type (might be due to invalid IL or missing references)
			//IL_0180: Expected O, but got Unknown
			//IL_01a7: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c9: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d3: Expected O, but got Unknown
			//IL_020c: Unknown result type (might be due to invalid IL or missing references)
			//IL_02e9: Unknown result type (might be due to invalid IL or missing references)
			//IL_031d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0327: Expected O, but got Unknown
			switch (<>1__state)
			{
			default:
				return false;
			case 0:
				<>1__state = -1;
				<killOrDieText>5__1 = killOrDieObj.GetComponent<TextMeshProUGUI>();
				<counterText>5__2 = counterObj.GetComponent<TextMeshProUGUI>();
				<dieText>5__3 = dieObj.GetComponent<TextMeshProUGUI>();
				((TMP_Text)<killOrDieText>5__1).text = "not enough valuables in the map";
				((Graphic)<killOrDieText>5__1).color = Color.white;
				((TMP_Text)<killOrDieText>5__1).fontSize = 32f;
				((Component)<killOrDieText>5__1).gameObject.SetActive(true);
				<>2__current = (object)new WaitForSeconds(3f);
				<>1__state = 1;
				return true;
			case 1:
				<>1__state = -1;
				((TMP_Text)<killOrDieText>5__1).text = "Kill a <color=red>Monster</color> to get <color=green>Money</color>";
				((Graphic)<killOrDieText>5__1).color = Color.white;
				((TMP_Text)<killOrDieText>5__1).fontSize = 32f;
				<>2__current = (object)new WaitForSeconds(3f);
				<>1__state = 2;
				return true;
			case 2:
				<>1__state = -1;
				((TMP_Text)<killOrDieText>5__1).text = "or";
				((Graphic)<killOrDieText>5__1).color = Color.white;
				((TMP_Text)<killOrDieText>5__1).fontSize = 32f;
				<>2__current = (object)new WaitForSeconds(1f);
				<>1__state = 3;
				return true;
			case 3:
				<>1__state = -1;
				((TMP_Text)<killOrDieText>5__1).text = "DIE";
				((Graphic)<killOrDieText>5__1).color = Color.red;
				((TMP_Text)<killOrDieText>5__1).fontSize = 100f;
				<>2__current = (object)new WaitForSeconds(3f);
				<>1__state = 4;
				return true;
			case 4:
				<>1__state = -1;
				((Component)<killOrDieText>5__1).gameObject.SetActive(false);
				((TMP_Text)<counterText>5__2).text = "Counter not initialized";
				((Graphic)<counterText>5__2).color = Color.red;
				((TMP_Text)<counterText>5__2).fontSize = 18f;
				((Component)<counterText>5__2).gameObject.SetActive(true);
				<timer>5__4 = countTime;
				goto IL_0294;
			case 5:
				<>1__state = -1;
				<timer>5__4 -= Time.deltaTime;
				goto IL_0294;
			case 6:
				{
					<>1__state = -1;
					if (GameManager.instance.gameMode == 0)
					{
						PlayerAvatar.instance.PlayerDeathRPC(0);
					}
					else
					{
						PlayerAvatar.instance.photonView.RPC("PlayerDeathRPC", (RpcTarget)0, new object[1] { 0 });
					}
					((Component)<dieText>5__3).gameObject.SetActive(false);
					break;
				}
				IL_0294:
				if (<timer>5__4 > 0f && !hasCompletedTasks)
				{
					((TMP_Text)<counterText>5__2).text = $"Time left: {(int)<timer>5__4}s";
					<>2__current = null;
					<>1__state = 5;
					return true;
				}
				if (!hasCompletedTasks)
				{
					((Component)<counterText>5__2).gameObject.SetActive(false);
					((TMP_Text)<dieText>5__3).text = "Better luck next time <color=red>;)</color>";
					((Graphic)<dieText>5__3).color = Color.white;
					((TMP_Text)<dieText>5__3).fontSize = 32f;
					((Component)<dieText>5__3).gameObject.SetActive(true);
					<>2__current = (object)new WaitForSeconds(3f);
					<>1__state = 6;
					return true;
				}
				break;
			}
			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 KillManager Instance;

	public static float countTime;

	public static GameObject killOrDieObj;

	public static GameObject counterObj;

	public static GameObject dieObj;

	public static bool hasCompletedTasks;

	private void Awake()
	{
		Instance = this;
	}

	[PunRPC]
	public void SetCounterTimer(float timer)
	{
		ModPatch.DebugRepo($"Setting counter timer to {timer}");
		countTime = timer;
	}

	[PunRPC]
	public void CompletedAllTasks()
	{
		hasCompletedTasks = true;
		counterObj.SetActive(false);
		((MonoBehaviour)this).StopCoroutine(KillThemAll());
	}

	[PunRPC]
	public void CallKillThemAll()
	{
		hasCompletedTasks = false;
		((MonoBehaviour)this).StartCoroutine(KillThemAll());
	}

	[IteratorStateMachine(typeof(<KillThemAll>d__10))]
	private IEnumerator KillThemAll()
	{
		//yield-return decompiler failed: Unexpected instruction in Iterator.Dispose()
		return new <KillThemAll>d__10(0)
		{
			<>4__this = this
		};
	}
}
namespace REPONoItemsLeft
{
	[BepInPlugin("FNKTLabs.REPONoItemsLeft", "No Items Left", "1.1.0")]
	public class ModBase : BaseUnityPlugin
	{
		private const string modGUID = "FNKTLabs.REPONoItemsLeft";

		private const string modName = "No Items Left";

		private const string modVersion = "1.1.0";

		private Harmony _harmony = new Harmony("FNKTLabs.REPONoItemsLeft");

		internal ManualLogSource _logSource;

		public static ConfigEntry<float> config_Timer;

		public void Awake()
		{
			_logSource = Logger.CreateLogSource("FNKTLabs.REPONoItemsLeft");
			_logSource.LogInfo((object)"REPO No Items Left loaded!");
			ConfigFile();
			_harmony.PatchAll(typeof(ModBase));
			_harmony.PatchAll(typeof(ModPatch));
		}

		public void ConfigFile()
		{
			//IL_002f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0039: Expected O, but got Unknown
			config_Timer = ((BaseUnityPlugin)this).Config.Bind<float>("Countdown Timer", "Time", 300f, new ConfigDescription("Sets the time the players have to kill a monster and get money and if there's not enough items the objectives still pending.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(10f, 600f), Array.Empty<object>()));
			ModPatch.counterTime = config_Timer.Value;
		}
	}
}
namespace REPONoItemsLeft.Patches
{
	public class CoroutineHelper : MonoBehaviour
	{
		private static CoroutineHelper instance;

		public static CoroutineHelper Instance
		{
			get
			{
				//IL_0016: Unknown result type (might be due to invalid IL or missing references)
				//IL_001c: Expected O, but got Unknown
				if ((Object)(object)instance == (Object)null)
				{
					GameObject val = new GameObject("CoroutineHelper");
					instance = val.AddComponent<CoroutineHelper>();
					Object.DontDestroyOnLoad((Object)(object)val);
				}
				return instance;
			}
		}
	}
	internal class ModPatch
	{
		public static float counterTime;

		private static int valuablesCount = 0;

		private static float currentValuablesValue = 0f;

		private static int currentExtractionHaulGoal = 0;

		private static bool killAllPlayers = true;

		private static bool onCountdown = false;

		private static ExtractionPoint currentExtractionPoint;

		private static State _currentExtractionPointState;

		private static TextMeshProUGUI killOrDieText;

		private static TextMeshProUGUI counterText;

		private static TextMeshProUGUI dieText;

		[HarmonyPatch(typeof(LevelGenerator), "GenerateDone")]
		[HarmonyPostfix]
		public static void GenerateDonePostfix(LevelGenerator __instance)
		{
			if (SemiFunc.RunIsLevel())
			{
				GameObject val = GameObject.Find("Run Manager PUN");
				if ((Object)(object)val != (Object)null)
				{
					val.AddComponent<KillManager>();
				}
				PrepareVariables();
				CreateHUDElements();
			}
		}

		private static void PrepareVariables()
		{
			killAllPlayers = true;
			onCountdown = false;
			KillManager.hasCompletedTasks = false;
			currentValuablesValue = 0f;
		}

		private static void CheckForItems(ValuableObject ignoreThis = null)
		{
			valuablesCount = 0;
			currentValuablesValue = 0f;
			List<ValuableObject> list = Object.FindObjectsOfType<ValuableObject>().ToList();
			if ((Object)(object)ignoreThis != (Object)null)
			{
				list.Remove(ignoreThis);
			}
			for (int i = 0; i < list.Count; i++)
			{
				currentValuablesValue += list[i].dollarValueCurrent;
				valuablesCount++;
			}
			UpdateHaulGoal();
		}

		private static void UpdateHaulGoal()
		{
			//IL_005b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0061: Invalid comparison between Unknown and I4
			//IL_0065: Unknown result type (might be due to invalid IL or missing references)
			//IL_006b: Invalid comparison between Unknown and I4
			//IL_008a: Unknown result type (might be due to invalid IL or missing references)
			//IL_008f: Unknown result type (might be due to invalid IL or missing references)
			FieldInfo fieldInfo = AccessTools.Field(typeof(RoundDirector), "extractionPointList");
			List<GameObject> list = fieldInfo.GetValue(RoundDirector.instance) as List<GameObject>;
			for (int i = 0; i < list.Count; i++)
			{
				ExtractionPoint component = list[i].GetComponent<ExtractionPoint>();
				FieldInfo fieldInfo2 = AccessTools.Field(typeof(ExtractionPoint), "currentState");
				object value = fieldInfo2.GetValue(component);
				if ((int)(State)value == 2 || (int)(State)value == 6)
				{
					currentExtractionHaulGoal = component.haulGoal;
					currentExtractionPoint = component;
					_currentExtractionPointState = (State)value;
				}
			}
		}

		[HarmonyPatch(typeof(PhysGrabObject), "DestroyPhysGrabObject")]
		[HarmonyPostfix]
		public static void DestroyPhysGrabObjectPostfix(PhysGrabObject __instance)
		{
			//IL_0036: Unknown result type (might be due to invalid IL or missing references)
			//IL_003c: Invalid comparison between Unknown and I4
			FieldInfo fieldInfo = AccessTools.Field(typeof(RoundDirector), "allExtractionPointsCompleted");
			bool flag = (bool)fieldInfo.GetValue(RoundDirector.instance);
			CheckForItems(((Component)__instance).GetComponent<ValuableObject>());
			if (flag || (int)_currentExtractionPointState == 6 || !(currentValuablesValue < (float)currentExtractionHaulGoal) || !killAllPlayers || onCountdown)
			{
				return;
			}
			onCountdown = true;
			if (GameManager.instance.gameMode == 0)
			{
				KillManager.Instance.CallKillThemAll();
			}
			else if ((Object)(object)KillManager.Instance != (Object)null)
			{
				PhotonView component = ((Component)KillManager.Instance).GetComponent<PhotonView>();
				if ((Object)(object)component != (Object)null)
				{
					component.RPC("CallKillThemAll", (RpcTarget)0, Array.Empty<object>());
				}
				else
				{
					DebugRepo("PhotonView not found on KillManager.");
				}
			}
			else
			{
				DebugRepo("KillManager instance is null!");
			}
		}

		[HarmonyPatch(typeof(ExtractionPoint), "HaulGoalSetRPC")]
		[HarmonyPostfix]
		public static void HaulGoalSetRPC(ExtractionPoint __instance)
		{
			CheckForItems();
		}

		[HarmonyPatch(typeof(RoundDirector), "ExtractionCompletedAllRPC")]
		[HarmonyPostfix]
		public static void ExtractionCompletedAllRPCPostfix(RoundDirector __instance)
		{
			killAllPlayers = false;
			if (GameManager.instance.gameMode == 0)
			{
				KillManager.Instance.CompletedAllTasks();
			}
			else if ((Object)(object)KillManager.Instance != (Object)null)
			{
				PhotonView component = ((Component)KillManager.Instance).GetComponent<PhotonView>();
				if ((Object)(object)component != (Object)null)
				{
					if (PhotonNetwork.IsMasterClient)
					{
						component.RPC("CompletedAllTasks", (RpcTarget)0, Array.Empty<object>());
					}
				}
				else
				{
					DebugRepo("PhotonView not found on KillManager.");
				}
			}
			else
			{
				DebugRepo("KillManager instance is null!");
			}
		}

		private static void CreateHUDElements()
		{
			//IL_003e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0045: Expected O, but got Unknown
			//IL_00dc: 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)
			//IL_010a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0121: 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_0133: Expected O, but got Unknown
			//IL_01ca: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e1: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f8: Unknown result type (might be due to invalid IL or missing references)
			//IL_020f: Unknown result type (might be due to invalid IL or missing references)
			//IL_021a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0221: Expected O, but got Unknown
			//IL_02b8: Unknown result type (might be due to invalid IL or missing references)
			//IL_02cf: Unknown result type (might be due to invalid IL or missing references)
			//IL_02e6: Unknown result type (might be due to invalid IL or missing references)
			//IL_02fd: Unknown result type (might be due to invalid IL or missing references)
			GameObject val = GameObject.Find("Game Hud");
			GameObject val2 = GameObject.Find("HealthMax");
			if (!((Object)(object)val != (Object)null) || !((Object)(object)val2 != (Object)null))
			{
				return;
			}
			TMP_FontAsset font = val2.GetComponent<TMP_Text>().font;
			GameObject val3 = new GameObject();
			val3.SetActive(false);
			((Object)val3).name = "Kill Or Die Hud";
			val3.AddComponent<TextMeshProUGUI>();
			killOrDieText = val3.GetComponent<TextMeshProUGUI>();
			((TMP_Text)killOrDieText).font = font;
			((TMP_Text)killOrDieText).enableWordWrapping = false;
			((TMP_Text)killOrDieText).alignment = (TextAlignmentOptions)514;
			((TMP_Text)killOrDieText).horizontalAlignment = (HorizontalAlignmentOptions)2;
			((TMP_Text)killOrDieText).verticalAlignment = (VerticalAlignmentOptions)512;
			val3.transform.SetParent(val.transform, false);
			RectTransform component = val3.GetComponent<RectTransform>();
			component.anchorMin = new Vector2(0.5f, 0.5f);
			component.anchorMax = new Vector2(0.5f, 0.5f);
			component.pivot = new Vector2(0.5f, 0.5f);
			component.anchoredPosition = new Vector2(0f, 0f);
			GameObject val4 = new GameObject();
			val4.SetActive(false);
			((Object)val4).name = "Final Countdown Hud";
			val4.AddComponent<TextMeshProUGUI>();
			counterText = val4.GetComponent<TextMeshProUGUI>();
			((TMP_Text)counterText).font = font;
			((TMP_Text)counterText).enableWordWrapping = false;
			((TMP_Text)counterText).alignment = (TextAlignmentOptions)514;
			((TMP_Text)counterText).horizontalAlignment = (HorizontalAlignmentOptions)2;
			((TMP_Text)counterText).verticalAlignment = (VerticalAlignmentOptions)512;
			val4.transform.SetParent(val.transform, false);
			RectTransform component2 = val4.GetComponent<RectTransform>();
			component2.anchorMin = new Vector2(0.5f, 1f);
			component2.anchorMax = new Vector2(0.5f, 1f);
			component2.pivot = new Vector2(0.5f, 1f);
			component2.anchoredPosition = new Vector2(0f, 0f);
			GameObject val5 = new GameObject();
			val5.SetActive(false);
			((Object)val5).name = "Die Hud";
			val5.AddComponent<TextMeshProUGUI>();
			dieText = val5.GetComponent<TextMeshProUGUI>();
			((TMP_Text)dieText).font = font;
			((TMP_Text)dieText).enableWordWrapping = false;
			((TMP_Text)dieText).alignment = (TextAlignmentOptions)514;
			((TMP_Text)dieText).horizontalAlignment = (HorizontalAlignmentOptions)2;
			((TMP_Text)dieText).verticalAlignment = (VerticalAlignmentOptions)512;
			val5.transform.SetParent(val.transform, false);
			RectTransform component3 = val5.GetComponent<RectTransform>();
			component3.anchorMin = new Vector2(0.5f, 0.5f);
			component3.anchorMax = new Vector2(0.5f, 0.5f);
			component3.pivot = new Vector2(0.5f, 0.5f);
			component3.anchoredPosition = new Vector2(0f, 0f);
			KillManager.killOrDieObj = val3;
			KillManager.dieObj = val5;
			KillManager.counterObj = val4;
			if (GameManager.instance.gameMode == 0)
			{
				KillManager.Instance.SetCounterTimer(counterTime);
			}
			else if (PhotonNetwork.IsMasterClient)
			{
				PhotonView component4 = ((Component)KillManager.Instance).GetComponent<PhotonView>();
				if ((Object)(object)component4 != (Object)null)
				{
					component4.RPC("SetCounterTimer", (RpcTarget)0, new object[1] { counterTime });
				}
				else
				{
					DebugRepo("PhotonView not found on KillManager.");
				}
			}
		}

		private static void DebugHierarchy(Transform obj, int depth)
		{
			//IL_0085: Unknown result type (might be due to invalid IL or missing references)
			//IL_008c: Expected O, but got Unknown
			string text = new string('-', depth * 2);
			MonoBehaviour[] components = ((Component)obj).GetComponents<MonoBehaviour>();
			string text2 = string.Join(", ", components.Select((MonoBehaviour m) => ((object)m).GetType().Name));
			Debug.Log((object)(text + " " + ((Object)obj).name + ", scripts: " + text2));
			foreach (Transform item in obj)
			{
				Transform obj2 = item;
				DebugHierarchy(obj2, depth + 1);
			}
		}

		public static void DebugRepo(string message)
		{
			Debug.Log((object)("REPONoItemsLeft >>>> " + message));
		}
	}
}