Decompiled source of No Items Challenge v1.1.0

tony4twentys-No Items Challenge.dll

Decompiled a week 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 Peak;
using Photon.Pun;
using Photon.Realtime;
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: IgnoresAccessChecksTo("Assembly-CSharp")]
[assembly: AssemblyTitle("No Items Challenge")]
[assembly: AssemblyDescription("Host-only PEAK challenge: no world loot, luggage destroyed, kiln flare kept.")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("No Items Challenge")]
[assembly: AssemblyCopyright("Copyright ©  2026")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("307f1ab3-ab27-4471-b7f5-ee05e6413a31")]
[assembly: AssemblyFileVersion("1.1.0.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.1.0.0")]
[module: UnverifiableCode]
namespace System.Runtime.CompilerServices
{
	[AttributeUsage(AttributeTargets.Assembly, AllowMultiple = true)]
	internal sealed class IgnoresAccessChecksToAttribute : Attribute
	{
		public IgnoresAccessChecksToAttribute(string assemblyName)
		{
		}
	}
}
namespace NoItemsChallenge
{
	[BepInPlugin("tony4twentys.No_Items_Challenge", "No Items Challenge", "1.1.0")]
	[BepInProcess("PEAK.exe")]
	public class NoItemsChallengePlugin : BaseUnityPlugin
	{
		private sealed class HostHooks : MonoBehaviourPunCallbacks
		{
			public override void OnJoinedRoom()
			{
				OnBecameHost();
				((MonoBehaviour)this).StartCoroutine(LogAfterInitialSpawn());
			}

			public override void OnMasterClientSwitched(Player newMasterClient)
			{
				OnBecameHost();
			}

			private static IEnumerator LogAfterInitialSpawn()
			{
				yield return (object)new WaitForSeconds(4f);
				LogSpawnSummary("after beach spawn");
			}
		}

		public const string PluginGuid = "tony4twentys.No_Items_Challenge";

		public const string PluginName = "No Items Challenge";

		public const string PluginVersion = "1.1.0";

		internal static ConfigEntry<bool> RespawnEnabled;

		internal static ConfigEntry<bool> BlockNatureItems;

		internal static ConfigEntry<bool> BlockSingleItemSpawners;

		internal static ConfigEntry<bool> DestroyLuggage;

		internal static ConfigEntry<bool> AllowKilnFlares;

		internal static ConfigEntry<bool> AllowCampfireMarshmallows;

		internal static ConfigEntry<bool> VerboseLogging;

		internal static int NatureBlocked;

		internal static int SinglesBlocked;

		internal static int LuggageDestroyed;

		private Harmony _harmony;

		private static bool _loggedDestroyError;

		private static bool _loggedReviveError;

		internal static NoItemsChallengePlugin Instance { get; private set; }

		internal static ManualLogSource Log { get; private set; }

		internal static bool IsSpawnHost
		{
			get
			{
				try
				{
					return PhotonNetwork.InRoom && PhotonNetwork.IsMasterClient;
				}
				catch
				{
					return false;
				}
			}
		}

		private void Awake()
		{
			//IL_00fa: Unknown result type (might be due to invalid IL or missing references)
			//IL_0104: Expected O, but got Unknown
			//IL_0115: Unknown result type (might be due to invalid IL or missing references)
			//IL_011b: Expected O, but got Unknown
			Instance = this;
			Log = ((BaseUnityPlugin)this).Logger;
			RespawnEnabled = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "RespawnOnCampfire", true, "Host only. Lighting a campfire revives dead / fully passed-out players there.");
			BlockNatureItems = ((BaseUnityPlugin)this).Config.Bind<bool>("Spawning", "BlockNatureItems", true, "Host only. Block world spawners (berries, mushrooms, trees, vines, nests, and so on).");
			BlockSingleItemSpawners = ((BaseUnityPlugin)this).Config.Bind<bool>("Spawning", "BlockSingleItemSpawners", true, "Host only. Block placed single-item spawners (shelf shrooms, bingbong, scrolls, bugle, backpacks, and so on).");
			DestroyLuggage = ((BaseUnityPlugin)this).Config.Bind<bool>("Spawning", "DestroyLuggage", true, "Host only. Photon-destroy luggage so clients without the mod lose the chests too.");
			AllowKilnFlares = ((BaseUnityPlugin)this).Config.Bind<bool>("Spawning", "AllowKilnFlares", true, "Still spawn the endgame flare (Peak.EndgameFlareSpawner / Kiln flare prefabs) so the helicopter can be called.");
			AllowCampfireMarshmallows = ((BaseUnityPlugin)this).Config.Bind<bool>("Spawning", "AllowCampfireMarshmallows", true, "Still spawn campfire marshmallows (BerryBush with SpawnPool.Campfire).");
			VerboseLogging = ((BaseUnityPlugin)this).Config.Bind<bool>("Debug", "VerboseLogging", false, "Log every blocked spawner and destroyed luggage piece. Leave off; biome loads spam otherwise.");
			_harmony = new Harmony("tony4twentys.No_Items_Challenge");
			_harmony.PatchAll();
			GameObject val = new GameObject("NoItemsChallenge_HostHooks");
			Object.DontDestroyOnLoad((Object)(object)val);
			((Object)val).hideFlags = (HideFlags)61;
			val.AddComponent<HostHooks>();
			Log.LogInfo((object)("No Items Challenge v1.1.0 loaded. Host-only: clients do not need this mod. Nature=" + (BlockNatureItems.Value ? "BLOCK" : "allow") + ", singles=" + (BlockSingleItemSpawners.Value ? "BLOCK" : "allow") + ", luggage=" + (DestroyLuggage.Value ? "DESTROY" : "keep") + ", kiln flares=" + (AllowKilnFlares.Value ? "allow" : "BLOCK") + ", campfire mallows=" + (AllowCampfireMarshmallows.Value ? "allow" : "BLOCK")));
		}

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

		internal static void NoteNatureBlocked()
		{
			NatureBlocked++;
		}

		internal static void NoteSingleBlocked()
		{
			SinglesBlocked++;
		}

		internal static void LogSpawnSummary(string reason)
		{
			if (NatureBlocked != 0 || SinglesBlocked != 0 || LuggageDestroyed != 0)
			{
				Log.LogInfo((object)("[No Items Challenge] " + reason + ": blocked nature=" + NatureBlocked + ", singles=" + SinglesBlocked + ", luggage destroyed=" + LuggageDestroyed));
			}
		}

		internal static void RespawnAllDeadPlayers(Vector3 position)
		{
			//IL_0098: Unknown result type (might be due to invalid IL or missing references)
			//IL_0099: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a3: Unknown result type (might be due to invalid IL or missing references)
			//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_00b7: 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)
			//IL_00c1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d8: Unknown result type (might be due to invalid IL or missing references)
			if (!IsSpawnHost || !RespawnEnabled.Value)
			{
				return;
			}
			try
			{
				int num = 0;
				List<Character> allCharacters = Character.AllCharacters;
				if (allCharacters == null)
				{
					return;
				}
				for (int i = 0; i < allCharacters.Count; i++)
				{
					Character val = allCharacters[i];
					if (!((Object)(object)val == (Object)null) && !((Object)(object)val.data == (Object)null) && (val.data.dead || val.data.fullyPassedOut))
					{
						Vector3 val2 = position + Vector3.up * 1.5f + Random.insideUnitSphere * 2f;
						((MonoBehaviourPun)val).photonView.RPC("RPCA_ReviveAtPosition", (RpcTarget)0, new object[3] { val2, true, -1 });
						num++;
					}
				}
				if (num > 0)
				{
					Log.LogInfo((object)("[No Items Challenge] Respawned " + num + " dead players at campfire"));
				}
			}
			catch (Exception ex)
			{
				if (!_loggedReviveError)
				{
					_loggedReviveError = true;
					Log.LogError((object)("[No Items Challenge] Campfire revive failed: " + ex));
				}
			}
		}

		internal static void QueueLuggageDestroy(Luggage luggage)
		{
			if (IsSpawnHost && DestroyLuggage.Value && !((Object)(object)luggage == (Object)null) && !((Object)(object)Instance == (Object)null))
			{
				((MonoBehaviour)Instance).StartCoroutine(DestroyLuggageNextFrame(luggage));
			}
		}

		private static IEnumerator DestroyLuggageNextFrame(Luggage luggage)
		{
			yield return null;
			TryDestroyLuggage(luggage);
		}

		internal static IEnumerator SweepLuggageAfterDelay(string reason, float delaySeconds)
		{
			yield return (object)new WaitForSeconds(delaySeconds);
			int before = LuggageDestroyed;
			DestroyAllLuggageInScene();
			int added = LuggageDestroyed - before;
			if (added > 0 || VerboseLogging.Value)
			{
				Log.LogInfo((object)("[No Items Challenge] Luggage sweep (" + reason + "): +" + added + " (total " + LuggageDestroyed + ")"));
			}
		}

		internal static void DestroyAllLuggageInScene()
		{
			if (!IsSpawnHost || !DestroyLuggage.Value)
			{
				return;
			}
			try
			{
				List<Luggage> aLL_LUGGAGE = Luggage.ALL_LUGGAGE;
				if (aLL_LUGGAGE != null && aLL_LUGGAGE.Count != 0)
				{
					Luggage[] array = aLL_LUGGAGE.ToArray();
					for (int i = 0; i < array.Length; i++)
					{
						TryDestroyLuggage(array[i]);
					}
				}
			}
			catch (Exception ex)
			{
				if (!_loggedDestroyError)
				{
					_loggedDestroyError = true;
					Log.LogWarning((object)("[No Items Challenge] Luggage sweep failed: " + ex.Message));
				}
			}
		}

		internal static void OnBecameHost()
		{
			if (IsSpawnHost)
			{
				DestroyAllLuggageInScene();
				if ((Object)(object)Instance != (Object)null)
				{
					((MonoBehaviour)Instance).StartCoroutine(SweepLuggageAfterDelay("became host", 1f));
				}
			}
		}

		private static void TryDestroyLuggage(Luggage luggage)
		{
			//IL_007d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0082: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)luggage == (Object)null || (Object)(object)((Component)luggage).gameObject == (Object)null)
			{
				return;
			}
			try
			{
				PhotonView val = luggage.photonView;
				if ((Object)(object)val == (Object)null)
				{
					val = ((Component)luggage).GetComponent<PhotonView>();
				}
				if (!((Object)(object)val == (Object)null))
				{
					if (VerboseLogging.Value)
					{
						Log.LogInfo((object)("[No Items Challenge] Destroying luggage " + ((Object)((Component)luggage).gameObject).name + " at " + ((object)((Component)luggage).transform.position/*cast due to .constrained prefix*/).ToString()));
					}
					PhotonNetwork.Destroy(val);
					LuggageDestroyed++;
				}
			}
			catch (Exception ex)
			{
				if (!_loggedDestroyError)
				{
					_loggedDestroyError = true;
					Log.LogWarning((object)("[No Items Challenge] Luggage destroy failed: " + ex.Message));
				}
			}
		}
	}
	[HarmonyPatch(typeof(Spawner), "TrySpawnItems")]
	internal static class SpawnerTrySpawnItemsPatch
	{
		private static bool _loggedError;

		private static bool Prefix(Spawner __instance, ref List<PhotonView> __result)
		{
			//IL_006c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0076: Invalid comparison between Unknown and I4
			//IL_00c0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c5: Unknown result type (might be due to invalid IL or missing references)
			try
			{
				if (!NoItemsChallengePlugin.IsSpawnHost)
				{
					return true;
				}
				if ((Object)(object)__instance == (Object)null || __instance is Luggage)
				{
					return true;
				}
				if (!NoItemsChallengePlugin.BlockNatureItems.Value)
				{
					return true;
				}
				BerryBush val = (BerryBush)(object)((__instance is BerryBush) ? __instance : null);
				if ((Object)(object)val != (Object)null && NoItemsChallengePlugin.AllowCampfireMarshmallows.Value && (int)((Spawner)val).spawnPool == 33554432)
				{
					return true;
				}
				NoItemsChallengePlugin.NoteNatureBlocked();
				if (NoItemsChallengePlugin.VerboseLogging.Value)
				{
					NoItemsChallengePlugin.Log.LogInfo((object)("[No Items Challenge] Blocked " + ((object)__instance).GetType().Name + " at " + ((object)((Component)__instance).transform.position/*cast due to .constrained prefix*/).ToString()));
				}
				__result = new List<PhotonView>();
				return false;
			}
			catch (Exception ex)
			{
				if (!_loggedError)
				{
					_loggedError = true;
					NoItemsChallengePlugin.Log.LogError((object)("[No Items Challenge] Spawner.TrySpawnItems patch: " + ex));
				}
				return true;
			}
		}
	}
	[HarmonyPatch(typeof(SingleItemSpawner), "TrySpawnItems")]
	internal static class SingleItemSpawnerTrySpawnItemsPatch
	{
		private static bool _loggedError;

		private static bool Prefix(SingleItemSpawner __instance, ref List<PhotonView> __result)
		{
			//IL_009a: 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)
			try
			{
				if (!NoItemsChallengePlugin.IsSpawnHost)
				{
					return true;
				}
				if ((Object)(object)__instance == (Object)null || !NoItemsChallengePlugin.BlockSingleItemSpawners.Value)
				{
					return true;
				}
				if (ShouldAllowFlare(__instance))
				{
					return true;
				}
				NoItemsChallengePlugin.NoteSingleBlocked();
				if (NoItemsChallengePlugin.VerboseLogging.Value)
				{
					string text = (((Object)(object)__instance.prefab != (Object)null) ? ((Object)__instance.prefab).name : "unknown");
					NoItemsChallengePlugin.Log.LogInfo((object)("[No Items Challenge] Blocked SingleItemSpawner " + text + " at " + ((object)((Component)__instance).transform.position/*cast due to .constrained prefix*/).ToString()));
				}
				__result = new List<PhotonView>();
				return false;
			}
			catch (Exception ex)
			{
				if (!_loggedError)
				{
					_loggedError = true;
					NoItemsChallengePlugin.Log.LogError((object)("[No Items Challenge] SingleItemSpawner.TrySpawnItems patch: " + ex));
				}
				return true;
			}
		}

		private static bool ShouldAllowFlare(SingleItemSpawner spawner)
		{
			//IL_00a5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00aa: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ab: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ad: Invalid comparison between Unknown and I4
			//IL_00af: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b1: Invalid comparison between Unknown and I4
			if (!NoItemsChallengePlugin.AllowKilnFlares.Value)
			{
				return false;
			}
			if (spawner is EndgameFlareSpawner)
			{
				return true;
			}
			string text = (((Object)(object)spawner.prefab != (Object)null) ? ((Object)spawner.prefab).name : null);
			if (string.IsNullOrEmpty(text))
			{
				return false;
			}
			if (text.IndexOf("flare", StringComparison.OrdinalIgnoreCase) < 0 && text.IndexOf("signal", StringComparison.OrdinalIgnoreCase) < 0)
			{
				return false;
			}
			MapHandler instance = Singleton<MapHandler>.Instance;
			if ((Object)(object)instance == (Object)null)
			{
				return false;
			}
			Segment currentSegment = instance.GetCurrentSegment();
			return (int)currentSegment == 4 || (int)currentSegment == 5;
		}
	}
	[HarmonyPatch(typeof(Luggage), "Awake")]
	internal static class LuggageAwakePatch
	{
		private static bool _loggedError;

		private static void Postfix(Luggage __instance)
		{
			try
			{
				NoItemsChallengePlugin.QueueLuggageDestroy(__instance);
			}
			catch (Exception ex)
			{
				if (!_loggedError)
				{
					_loggedError = true;
					NoItemsChallengePlugin.Log.LogError((object)("[No Items Challenge] Luggage.Awake patch: " + ex));
				}
			}
		}
	}
	[HarmonyPatch(typeof(Luggage), "OpenLuggageRPC")]
	internal static class LuggageOpenPatch
	{
		private static bool _loggedError;

		private static void Prefix(ref bool spawnItems)
		{
			try
			{
				if (NoItemsChallengePlugin.IsSpawnHost && NoItemsChallengePlugin.DestroyLuggage.Value)
				{
					spawnItems = false;
				}
			}
			catch (Exception ex)
			{
				if (!_loggedError)
				{
					_loggedError = true;
					NoItemsChallengePlugin.Log.LogError((object)("[No Items Challenge] Luggage.OpenLuggageRPC patch: " + ex));
				}
			}
		}
	}
	[HarmonyPatch(typeof(Campfire), "Light_Rpc")]
	internal static class CampfireLightPatch
	{
		private static bool _loggedError;

		private static void Postfix(Campfire __instance)
		{
			//IL_0015: Unknown result type (might be due to invalid IL or missing references)
			try
			{
				if (!((Object)(object)__instance == (Object)null))
				{
					NoItemsChallengePlugin.RespawnAllDeadPlayers(((Component)__instance).transform.position);
				}
			}
			catch (Exception ex)
			{
				if (!_loggedError)
				{
					_loggedError = true;
					NoItemsChallengePlugin.Log.LogError((object)("[No Items Challenge] Campfire.Light_Rpc patch: " + ex));
				}
			}
		}
	}
	[HarmonyPatch(typeof(MapHandler), "JumpToSegmentLogic")]
	internal static class MapHandlerJumpPatch
	{
		private static bool _loggedError;

		private unsafe static void Postfix(Segment newSegment)
		{
			try
			{
				if (NoItemsChallengePlugin.IsSpawnHost && !((Object)(object)NoItemsChallengePlugin.Instance == (Object)null))
				{
					NoItemsChallengePlugin.LogSpawnSummary("segment " + ((object)(*(Segment*)(&newSegment))/*cast due to .constrained prefix*/).ToString());
					((MonoBehaviour)NoItemsChallengePlugin.Instance).StartCoroutine(NoItemsChallengePlugin.SweepLuggageAfterDelay("segment " + ((object)(*(Segment*)(&newSegment))/*cast due to .constrained prefix*/).ToString(), 1f));
				}
			}
			catch (Exception ex)
			{
				if (!_loggedError)
				{
					_loggedError = true;
					NoItemsChallengePlugin.Log.LogError((object)("[No Items Challenge] JumpToSegmentLogic patch: " + ex));
				}
			}
		}
	}
}