Decompiled source of CampfireItems v1.0.0

BepInEx/plugins/CampfireItems.dll

Decompiled 3 weeks ago
using System;
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 UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: AssemblyTitle("Rougelike Perks")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("Rougelike Perks")]
[assembly: AssemblyCopyright("Copyright ©  2025")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("aff4c14e-4e53-4a16-90c4-afb5cb247cde")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")]
[assembly: AssemblyVersion("1.0.0.0")]
[BepInPlugin("com.Pope0.campfireitems", "campfireitems", "1.1.0")]
public class CampfireSpawner : BaseUnityPlugin
{
	[HarmonyPatch(typeof(Campfire), "Light_Rpc")]
	private class Campfire_Light_Rpc_Patch
	{
		private static void Postfix(Campfire __instance)
		{
			if (PhotonNetwork.IsMasterClient)
			{
				SpawnLinkedItems(__instance, spawnCount.Value);
			}
		}
	}

	[HarmonyPatch(typeof(Item), "Interact")]
	private class Item_Interact_Patch
	{
		private static void Postfix(Item __instance, Character interactor)
		{
			if (!spawnedItemGroups.ContainsKey(((Object)__instance).GetInstanceID()))
			{
				return;
			}
			List<Item> list = spawnedItemGroups[((Object)__instance).GetInstanceID()];
			foreach (Item item in list)
			{
				if ((Object)(object)item != (Object)null && (Object)(object)item != (Object)(object)__instance && (Object)(object)((Component)item).gameObject != (Object)null && PhotonNetwork.IsMasterClient)
				{
					PhotonNetwork.Destroy(((Component)item).gameObject);
				}
			}
			spawnedItemGroups.Remove(((Object)__instance).GetInstanceID());
		}
	}

	private readonly Harmony harmony = new Harmony("com.Pope0.campfireitems");

	private static ManualLogSource logger;

	private static Dictionary<int, List<Item>> spawnedItemGroups = new Dictionary<int, List<Item>>();

	private static ConfigEntry<int> spawnCount;

	private static ConfigEntry<string> disabledSpawnPools;

	private static ConfigEntry<float> spawnHeight;

	private static ConfigEntry<float> itemSpacing;

	private static HashSet<SpawnPool> disabledPools = new HashSet<SpawnPool>();

	private void Awake()
	{
		logger = ((BaseUnityPlugin)this).Logger;
		SetupConfig();
		harmony.PatchAll();
		((BaseUnityPlugin)this).Logger.LogInfo((object)"Campfire Item Spawner mod loaded!");
		((BaseUnityPlugin)this).Logger.LogInfo((object)$"Spawn count: {spawnCount.Value}");
		((BaseUnityPlugin)this).Logger.LogInfo((object)("Disabled pools: " + disabledSpawnPools.Value));
	}

	private void SetupConfig()
	{
		//IL_008e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0098: Expected O, but got Unknown
		spawnCount = ((BaseUnityPlugin)this).Config.Bind<int>("General", "SpawnCount", 3, "Number of items to spawn above the campfire (1-10)");
		if (spawnCount.Value < 1)
		{
			spawnCount.Value = 1;
		}
		if (spawnCount.Value > 10)
		{
			spawnCount.Value = 10;
		}
		disabledSpawnPools = ((BaseUnityPlugin)this).Config.Bind<string>("SpawnPools", "DisabledPools", "GuidebookPageBeach,GuidebookPageTropics,GuidebookPageAlpine,None,Unused1,Unused2,MushroomCluster,BerryBushBeach,BerryBushJungle,SpikyVine,CoconutTree,WillowTreeJungle,JungleVine,WinterberryTree,", new ConfigDescription("Comma-separated list of spawn pools to disable. Available pools: None, Unused1, Unused2, MushroomCluster, BerryBushBeach, BerryBushJungle, SpikyVine, CoconutTree, WillowTreeJungle, JungleVine, WinterberryTree, LuggageBeach, LuggageJungle, LuggageTundra, LuggageCaldera, LuggageClimber, LuggageAncient, LuggageCursed, RespawnCoffin, Nest, GuidebookPageBeach, GuidebookPageTropics, GuidebookPageAlpine", (AcceptableValueBase)null, new object[1]
		{
			new ConfigurationManagerAttributes
			{
				Order = 1
			}
		}));
		spawnHeight = ((BaseUnityPlugin)this).Config.Bind<float>("Positioning", "SpawnHeight", 1.5f, "Height above the campfire to spawn items (0.5-5.0)");
		itemSpacing = ((BaseUnityPlugin)this).Config.Bind<float>("Positioning", "ItemSpacing", 0.8f, "Spacing between spawned items (0.3-2.0)");
		if (spawnHeight.Value < 0.5f)
		{
			spawnHeight.Value = 0.5f;
		}
		if (spawnHeight.Value > 5f)
		{
			spawnHeight.Value = 5f;
		}
		if (itemSpacing.Value < 0.3f)
		{
			itemSpacing.Value = 0.3f;
		}
		if (itemSpacing.Value > 2f)
		{
			itemSpacing.Value = 2f;
		}
		ParseDisabledPools();
		disabledSpawnPools.SettingChanged += delegate
		{
			ParseDisabledPools();
		};
	}

	private void ParseDisabledPools()
	{
		//IL_006b: Unknown result type (might be due to invalid IL or missing references)
		//IL_007d: Unknown result type (might be due to invalid IL or missing references)
		disabledPools.Clear();
		if (string.IsNullOrWhiteSpace(disabledSpawnPools.Value))
		{
			return;
		}
		string[] array = disabledSpawnPools.Value.Split(new char[1] { ',' });
		string[] array2 = array;
		foreach (string text in array2)
		{
			string text2 = text.Trim();
			if (Enum.TryParse<SpawnPool>(text2, ignoreCase: true, out SpawnPool result))
			{
				disabledPools.Add(result);
				logger.LogInfo((object)$"Disabled spawn pool: {result}");
			}
			else
			{
				logger.LogWarning((object)("Invalid spawn pool name: " + text2));
			}
		}
	}

	private static void SpawnLinkedItems(Campfire campfire, int count)
	{
		//IL_0031: Unknown result type (might be due to invalid IL or missing references)
		//IL_0036: Unknown result type (might be due to invalid IL or missing references)
		//IL_003c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0041: Unknown result type (might be due to invalid IL or missing references)
		//IL_0046: 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_005a: Expected O, but got Unknown
		//IL_0071: Unknown result type (might be due to invalid IL or missing references)
		//IL_0079: 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_0097: Unknown result type (might be due to invalid IL or missing references)
		//IL_018e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0195: Expected O, but got Unknown
		//IL_01a1: Unknown result type (might be due to invalid IL or missing references)
		//IL_01b5: Unknown result type (might be due to invalid IL or missing references)
		//IL_01ba: Unknown result type (might be due to invalid IL or missing references)
		//IL_01be: Unknown result type (might be due to invalid IL or missing references)
		//IL_01c0: Unknown result type (might be due to invalid IL or missing references)
		List<Transform> list = new List<Transform>();
		List<Item> list2 = new List<Item>();
		float value = spawnHeight.Value;
		float value2 = itemSpacing.Value;
		float num = (float)(count - 1) * value2;
		Vector3 val = ((Component)campfire).transform.position + Vector3.up * value;
		for (int i = 0; i < count; i++)
		{
			GameObject val2 = new GameObject("TempSpawnPoint");
			float num2 = (float)i * value2 - num / 2f;
			val2.transform.position = val + ((Component)campfire).transform.right * num2;
			val2.transform.rotation = Quaternion.identity;
			list.Add(val2.transform);
		}
		List<SpawnPool> source = Enum.GetValues(typeof(SpawnPool)).Cast<SpawnPool>().ToList();
		List<SpawnPool> list3 = source.Where((SpawnPool pool) => !disabledPools.Contains(pool) && (int)pool != 0 && (int)pool != 1 && (int)pool != 2).ToList();
		if (list3.Count == 0)
		{
			logger.LogWarning((object)"All spawn pools are disabled! Cannot spawn items.");
			{
				foreach (Transform item2 in list)
				{
					Object.Destroy((Object)(object)((Component)item2).gameObject);
				}
				return;
			}
		}
		List<PhotonView> list4 = new List<PhotonView>();
		foreach (Transform item3 in list)
		{
			GameObject val3 = new GameObject("TempSpawner");
			Spawner val4 = val3.AddComponent<Spawner>();
			val4.spawnMode = (SpawnMode)1;
			SpawnPool spawnPool = list3[Random.Range(0, list3.Count)];
			val4.spawnPool = spawnPool;
			val4.canRepeatSpawns = true;
			List<PhotonView> collection = val4.SpawnItems(new List<Transform> { item3 });
			list4.AddRange(collection);
			Object.Destroy((Object)(object)val3);
		}
		Item item = default(Item);
		foreach (PhotonView item4 in list4)
		{
			if ((Object)(object)item4 != (Object)null && ((Component)item4).TryGetComponent<Item>(ref item))
			{
				list2.Add(item);
			}
		}
		foreach (Item item5 in list2)
		{
			if ((Object)(object)item5 != (Object)null)
			{
				spawnedItemGroups[((Object)item5).GetInstanceID()] = new List<Item>(list2);
			}
		}
		foreach (Transform item6 in list)
		{
			Object.Destroy((Object)(object)((Component)item6).gameObject);
		}
		logger.LogInfo((object)$"Spawned {list2.Count} linked items above campfire using {list3.Count} available pools!");
	}
}
public class ConfigurationManagerAttributes
{
	public int Order { get; set; }
}
namespace Rougelike_Perks;

internal class Class2
{
}