Decompiled source of No Items Challenge v1.0.0

tony4twenty-No Items Challenge.dll

Decompiled 2 months ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using HarmonyLib;
using Photon.Pun;
using UnityEngine;
using Zorro.Core;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: AssemblyTitle("No Items Challenge")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("No Items Challenge")]
[assembly: AssemblyCopyright("Copyright ©  2025")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("307f1ab3-ab27-4471-b7f5-ee05e6413a31")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
[module: UnverifiableCode]
namespace NoItemsChallenge;

[BepInPlugin("tony4twentys.No_Items_Challenge", "No Items Challenge", "1.0.0")]
public class NoItemsChallengePlugin : BaseUnityPlugin
{
	[HarmonyPatch(typeof(Spawner), "TrySpawnItems")]
	private static class Spawner_TrySpawnItems_Patch
	{
		private static bool Prefix(Spawner __instance, ref List<PhotonView> __result)
		{
			//IL_0051: Unknown result type (might be due to invalid IL or missing references)
			try
			{
				if (!PhotonNetwork.IsMasterClient)
				{
					return true;
				}
				if (__instance is Luggage)
				{
					return true;
				}
				if (BlockNatureItems.Value)
				{
					logger.LogInfo((object)$"[No Items Challenge] Blocked {((object)__instance).GetType().Name} from spawning items at {((Component)__instance).transform.position}");
					__result = new List<PhotonView>();
					return false;
				}
				return true;
			}
			catch (Exception ex)
			{
				logger.LogError((object)("[No Items Challenge] Error in Spawner.TrySpawnItems patch: " + ex.Message));
				return true;
			}
		}
	}

	[HarmonyPatch(typeof(SingleItemSpawner), "TrySpawnItems")]
	private static class SingleItemSpawner_TrySpawnItems_Patch
	{
		private static bool Prefix(SingleItemSpawner __instance, ref List<PhotonView> __result)
		{
			//IL_015b: 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_0053: Unknown result type (might be due to invalid IL or missing references)
			//IL_0059: Invalid comparison between Unknown and I4
			//IL_00ee: Unknown result type (might be due to invalid IL or missing references)
			try
			{
				if (!PhotonNetwork.IsMasterClient)
				{
					return true;
				}
				if (BlockSingleItemSpawners.Value)
				{
					try
					{
						MapHandler instance = Singleton<MapHandler>.Instance;
						Segment? val = ((instance != null) ? new Segment?(instance.GetCurrentSegment()) : null);
						if (val.HasValue && (int)val.Value == 4)
						{
							GameObject prefab = __instance.prefab;
							string text = ((prefab == null) ? null : ((Object)prefab).name?.ToLower()) ?? "";
							if (text.Contains("flare") || text.Contains("signal") || text.Contains("rescue"))
							{
								ManualLogSource logger = NoItemsChallengePlugin.logger;
								GameObject prefab2 = __instance.prefab;
								logger.LogInfo((object)string.Format("[No Items Challenge] Allowing flare spawn in The Kiln: {0} at {1}", ((prefab2 != null) ? ((Object)prefab2).name : null) ?? "unknown", ((Component)__instance).transform.position));
								return true;
							}
						}
					}
					catch (Exception ex)
					{
						NoItemsChallengePlugin.logger.LogWarning((object)("[No Items Challenge] Could not check current segment for flare exception: " + ex.Message));
					}
					ManualLogSource logger2 = NoItemsChallengePlugin.logger;
					GameObject prefab3 = __instance.prefab;
					logger2.LogInfo((object)string.Format("[No Items Challenge] Blocked SingleItemSpawner from spawning {0} at {1}", ((prefab3 != null) ? ((Object)prefab3).name : null) ?? "unknown", ((Component)__instance).transform.position));
					__result = new List<PhotonView>();
					return false;
				}
				return true;
			}
			catch (Exception ex2)
			{
				NoItemsChallengePlugin.logger.LogError((object)("[No Items Challenge] Error in SingleItemSpawner.TrySpawnItems patch: " + ex2.Message));
				return true;
			}
		}
	}

	[HarmonyPatch(typeof(Luggage), "Awake")]
	private static class Luggage_Awake_Patch
	{
		[CompilerGenerated]
		private sealed class <DestroyLuggageAfterDelay>d__1 : IEnumerator<object>, IDisposable, IEnumerator
		{
			private int <>1__state;

			private object <>2__current;

			public Luggage luggage;

			public PhotonView pv;

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

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

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

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

			private bool MoveNext()
			{
				//IL_0026: Unknown result type (might be due to invalid IL or missing references)
				//IL_0030: Expected O, but got Unknown
				//IL_0087: Unknown result type (might be due to invalid IL or missing references)
				switch (<>1__state)
				{
				default:
					return false;
				case 0:
					<>1__state = -1;
					<>2__current = (object)new WaitForSeconds(0.5f);
					<>1__state = 1;
					return true;
				case 1:
					<>1__state = -1;
					if ((Object)(object)luggage != (Object)null && (Object)(object)pv != (Object)null)
					{
						logger.LogInfo((object)$"[No Items Challenge] Destroying newly spawned luggage: {((Object)((Component)luggage).gameObject).name} at {((Component)luggage).transform.position}");
						PhotonNetwork.Destroy(pv);
					}
					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();
			}
		}

		private static void Postfix(Luggage __instance)
		{
			try
			{
				if (!PhotonNetwork.IsMasterClient)
				{
					return;
				}
				PhotonView component = ((Component)__instance).GetComponent<PhotonView>();
				if ((Object)(object)component != (Object)null)
				{
					NoItemsChallengePlugin instance = Instance;
					if (instance != null)
					{
						((MonoBehaviour)instance).StartCoroutine(DestroyLuggageAfterDelay(__instance, component));
					}
				}
			}
			catch (Exception ex)
			{
				logger.LogError((object)("[No Items Challenge] Error in Luggage.Awake patch: " + ex.Message));
			}
		}

		[IteratorStateMachine(typeof(<DestroyLuggageAfterDelay>d__1))]
		private static IEnumerator DestroyLuggageAfterDelay(Luggage luggage, PhotonView pv)
		{
			//yield-return decompiler failed: Unexpected instruction in Iterator.Dispose()
			return new <DestroyLuggageAfterDelay>d__1(0)
			{
				luggage = luggage,
				pv = pv
			};
		}
	}

	[HarmonyPatch(typeof(Campfire), "Light_Rpc")]
	private static class Campfire_Light_Rpc_Patch
	{
		private static void Postfix(Campfire __instance)
		{
			//IL_0027: Unknown result type (might be due to invalid IL or missing references)
			//IL_0049: 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: Invalid comparison between Unknown and I4
			if (!PhotonNetwork.IsMasterClient)
			{
				return;
			}
			if (RespawnEnabled.Value)
			{
				RespawnAllDeadPlayers(((Component)__instance).transform.position);
			}
			try
			{
				MapHandler instance = Singleton<MapHandler>.Instance;
				Segment? val = ((instance != null) ? new Segment?(instance.GetCurrentSegment()) : null);
				if (val.HasValue && (int)val.Value == 4)
				{
					logger.LogInfo((object)"[No Items Challenge] Detected The Kiln segment - flares should now be available for helicopter rescue!");
				}
			}
			catch (Exception ex)
			{
				logger.LogWarning((object)("[No Items Challenge] Could not detect current segment: " + ex.Message));
			}
		}
	}

	[HarmonyPatch(typeof(MapHandler), "JumpToSegmentLogic", new Type[]
	{
		typeof(Segment),
		typeof(HashSet<int>),
		typeof(bool)
	})]
	private static class MapHandler_JumpToSegmentLogic_Patch
	{
		[CompilerGenerated]
		private sealed class <DestroyLuggageAfterSegmentLoad>d__1 : IEnumerator<object>, IDisposable, IEnumerator
		{
			private int <>1__state;

			private object <>2__current;

			public Segment segment;

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

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

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

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

			private bool MoveNext()
			{
				//IL_0031: Unknown result type (might be due to invalid IL or missing references)
				//IL_003b: Expected O, but got Unknown
				//IL_0056: 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_0081: Expected O, but got Unknown
				//IL_009c: Unknown result type (might be due to invalid IL or missing references)
				switch (<>1__state)
				{
				default:
					return false;
				case 0:
					<>1__state = -1;
					<>2__current = (object)new WaitForSeconds(2f);
					<>1__state = 1;
					return true;
				case 1:
					<>1__state = -1;
					logger.LogInfo((object)$"[No Items Challenge] Destroying all luggage in segment {segment}...");
					DestroyAllLuggageInScene();
					<>2__current = (object)new WaitForSeconds(2f);
					<>1__state = 2;
					return true;
				case 2:
					<>1__state = -1;
					logger.LogInfo((object)$"[No Items Challenge] Second pass for segment {segment}...");
					DestroyAllLuggageInScene();
					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();
			}
		}

		private static void Postfix(Segment segment)
		{
			//IL_002a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0040: Unknown result type (might be due to invalid IL or missing references)
			if (PhotonNetwork.IsMasterClient && !((Object)(object)Instance == (Object)null))
			{
				logger.LogInfo((object)$"[No Items Challenge] Segment {segment} loaded, destroying luggage after short delay...");
				((MonoBehaviour)Instance).StartCoroutine(DestroyLuggageAfterSegmentLoad(segment));
			}
		}

		[IteratorStateMachine(typeof(<DestroyLuggageAfterSegmentLoad>d__1))]
		private static IEnumerator DestroyLuggageAfterSegmentLoad(Segment segment)
		{
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			//IL_0008: Unknown result type (might be due to invalid IL or missing references)
			//yield-return decompiler failed: Unexpected instruction in Iterator.Dispose()
			return new <DestroyLuggageAfterSegmentLoad>d__1(0)
			{
				segment = segment
			};
		}
	}

	private Harmony _harmony;

	private static ManualLogSource logger;

	public static NoItemsChallengePlugin Instance;

	private static ConfigEntry<bool> RespawnEnabled;

	private static ConfigEntry<bool> BlockNatureItems;

	private static ConfigEntry<bool> BlockSingleItemSpawners;

	private void Awake()
	{
		//IL_0078: Unknown result type (might be due to invalid IL or missing references)
		//IL_0082: Expected O, but got Unknown
		Instance = this;
		logger = ((BaseUnityPlugin)this).Logger;
		RespawnEnabled = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "RespawnOnCampfire", true, "Whether lighting a campfire respawns all dead players");
		BlockNatureItems = ((BaseUnityPlugin)this).Config.Bind<bool>("Spawning", "BlockNatureItems", true, "Block nature items (berries, mushrooms, trees, etc.) from spawning");
		BlockSingleItemSpawners = ((BaseUnityPlugin)this).Config.Bind<bool>("Spawning", "BlockSingleItemSpawners", true, "Block individual item spawners (shelf shrooms, healing puffs, magic beans, bingbong, scrolls, bugle etc.)");
		_harmony = new Harmony("tony4twentys.No_Items_Challenge");
		_harmony.PatchAll();
		logger.LogInfo((object)("No Items Challenge v1.0.0 loaded - Nature items: " + (BlockNatureItems.Value ? "BLOCKED" : "ALLOWED") + ", Single item spawners: " + (BlockSingleItemSpawners.Value ? "BLOCKED" : "ALLOWED") + ", Luggage: DESTROYED"));
	}

	private void OnDestroy()
	{
		Harmony harmony = _harmony;
		if (harmony != null)
		{
			harmony.UnpatchSelf();
		}
	}

	public static void RespawnAllDeadPlayers(Vector3 position)
	{
		//IL_0070: Unknown result type (might be due to invalid IL or missing references)
		//IL_0071: Unknown result type (might be due to invalid IL or missing references)
		//IL_007b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0080: 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_008f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0094: Unknown result type (might be due to invalid IL or missing references)
		if (!PhotonNetwork.IsMasterClient)
		{
			return;
		}
		int num = 0;
		foreach (Character allCharacter in Character.AllCharacters)
		{
			if ((Object)(object)allCharacter != (Object)null && (allCharacter.data.dead || allCharacter.data.fullyPassedOut))
			{
				((MonoBehaviourPun)allCharacter).photonView.RPC("RPCA_ReviveAtPosition", (RpcTarget)0, new object[2]
				{
					position + Vector3.up * 1.5f + Random.insideUnitSphere * 2f,
					true
				});
				num++;
			}
		}
		if (num > 0)
		{
			logger.LogInfo((object)$"[No Items Challenge] Respawned {num} dead players at campfire");
		}
	}

	private static void DestroyAllLuggageInScene()
	{
		if (!PhotonNetwork.IsMasterClient)
		{
			return;
		}
		try
		{
			Luggage[] array = Object.FindObjectsByType<Luggage>((FindObjectsSortMode)0);
			int num = 0;
			Luggage[] array2 = array;
			foreach (Luggage val in array2)
			{
				if ((Object)(object)val != (Object)null && (Object)(object)((Component)val).gameObject != (Object)null)
				{
					PhotonView component = ((Component)val).GetComponent<PhotonView>();
					if ((Object)(object)component != (Object)null)
					{
						PhotonNetwork.Destroy(component);
						num++;
					}
				}
			}
			if (num > 0)
			{
				logger.LogInfo((object)$"[No Items Challenge] Destroyed {num} luggage pieces.");
			}
		}
		catch (Exception ex)
		{
			logger.LogWarning((object)("[No Items Challenge] Luggage destruction failed: " + ex.Message));
		}
	}
}