Jam/Jam.dll

Decompiled a month ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
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 JetBrains.Annotations;
using Jotunn.Configs;
using Jotunn.Entities;
using Jotunn.Managers;
using Jotunn.Utils;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: AssemblyTitle("Jam")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("Randy Knapp Mods")]
[assembly: AssemblyProduct("Jam")]
[assembly: AssemblyCopyright("Copyright © RandyKnapp 2023")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("6c679b7e-9f39-4df2-9f8a-717e68fbf0e3")]
[assembly: AssemblyFileVersion("1.1.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.1.0.0")]
[module: UnverifiableCode]
public static class PlayerExtensions
{
	public static ZDO GetZDO(this Player player)
	{
		return ((Character)player).m_nview.GetZDO();
	}
}
namespace Common
{
	public class ConfigPositionedElement : MonoBehaviour
	{
		public ConfigEntry<TextAnchor> AnchorConfig;

		public ConfigEntry<Vector2> PositionConfig;

		protected RectTransform _rt;

		protected TextAnchor _currentAnchor;

		public virtual void Awake()
		{
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			//IL_0011: Expected O, but got Unknown
			_rt = (RectTransform)((Component)this).transform;
			EnsureCorrectPosition();
		}

		public virtual void Update()
		{
			EnsureCorrectPosition();
		}

		public virtual void EnsureCorrectPosition()
		{
			//IL_0011: Unknown result type (might be due to invalid IL or missing references)
			//IL_001c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0048: Unknown result type (might be due to invalid IL or missing references)
			//IL_004d: 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_0058: Unknown result type (might be due to invalid IL or missing references)
			//IL_0059: Unknown result type (might be due to invalid IL or missing references)
			//IL_0083: Expected I4, but got Unknown
			//IL_0029: Unknown result type (might be due to invalid IL or missing references)
			//IL_0034: 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_00b1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ed: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ee: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ef: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f5: 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_0129: Unknown result type (might be due to invalid IL or missing references)
			//IL_012a: Unknown result type (might be due to invalid IL or missing references)
			//IL_012b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0131: Unknown result type (might be due to invalid IL or missing references)
			//IL_015f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0165: Unknown result type (might be due to invalid IL or missing references)
			//IL_0166: Unknown result type (might be due to invalid IL or missing references)
			//IL_0167: Unknown result type (might be due to invalid IL or missing references)
			//IL_016d: Unknown result type (might be due to invalid IL or missing references)
			//IL_019b: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a1: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a2: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a3: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a9: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d7: Unknown result type (might be due to invalid IL or missing references)
			//IL_01dd: Unknown result type (might be due to invalid IL or missing references)
			//IL_01de: Unknown result type (might be due to invalid IL or missing references)
			//IL_01df: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e5: Unknown result type (might be due to invalid IL or missing references)
			//IL_0213: Unknown result type (might be due to invalid IL or missing references)
			//IL_0219: 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_021b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0221: Unknown result type (might be due to invalid IL or missing references)
			//IL_024c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0252: Unknown result type (might be due to invalid IL or missing references)
			//IL_0253: Unknown result type (might be due to invalid IL or missing references)
			//IL_0254: Unknown result type (might be due to invalid IL or missing references)
			//IL_025a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0285: Unknown result type (might be due to invalid IL or missing references)
			//IL_028b: Unknown result type (might be due to invalid IL or missing references)
			//IL_028c: Unknown result type (might be due to invalid IL or missing references)
			//IL_028d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0293: Unknown result type (might be due to invalid IL or missing references)
			//IL_02a5: Unknown result type (might be due to invalid IL or missing references)
			if (AnchorConfig != null && PositionConfig != null && (_currentAnchor != AnchorConfig.Value || !(_rt.anchoredPosition == PositionConfig.Value)))
			{
				_currentAnchor = AnchorConfig.Value;
				TextAnchor currentAnchor = _currentAnchor;
				Vector2 val = default(Vector2);
				switch ((int)currentAnchor)
				{
				case 0:
				{
					RectTransform rt25 = _rt;
					RectTransform rt26 = _rt;
					RectTransform rt27 = _rt;
					((Vector2)(ref val))..ctor(0f, 1f);
					rt27.anchorMax = val;
					Vector2 pivot = (rt26.anchorMin = val);
					rt25.pivot = pivot;
					break;
				}
				case 1:
				{
					RectTransform rt22 = _rt;
					RectTransform rt23 = _rt;
					RectTransform rt24 = _rt;
					((Vector2)(ref val))..ctor(0.5f, 1f);
					rt24.anchorMax = val;
					Vector2 pivot = (rt23.anchorMin = val);
					rt22.pivot = pivot;
					break;
				}
				case 2:
				{
					RectTransform rt19 = _rt;
					RectTransform rt20 = _rt;
					RectTransform rt21 = _rt;
					((Vector2)(ref val))..ctor(1f, 1f);
					rt21.anchorMax = val;
					Vector2 pivot = (rt20.anchorMin = val);
					rt19.pivot = pivot;
					break;
				}
				case 3:
				{
					RectTransform rt16 = _rt;
					RectTransform rt17 = _rt;
					RectTransform rt18 = _rt;
					((Vector2)(ref val))..ctor(0f, 0.5f);
					rt18.anchorMax = val;
					Vector2 pivot = (rt17.anchorMin = val);
					rt16.pivot = pivot;
					break;
				}
				case 4:
				{
					RectTransform rt13 = _rt;
					RectTransform rt14 = _rt;
					RectTransform rt15 = _rt;
					((Vector2)(ref val))..ctor(0.5f, 0.5f);
					rt15.anchorMax = val;
					Vector2 pivot = (rt14.anchorMin = val);
					rt13.pivot = pivot;
					break;
				}
				case 5:
				{
					RectTransform rt10 = _rt;
					RectTransform rt11 = _rt;
					RectTransform rt12 = _rt;
					((Vector2)(ref val))..ctor(1f, 0.5f);
					rt12.anchorMax = val;
					Vector2 pivot = (rt11.anchorMin = val);
					rt10.pivot = pivot;
					break;
				}
				case 6:
				{
					RectTransform rt7 = _rt;
					RectTransform rt8 = _rt;
					RectTransform rt9 = _rt;
					((Vector2)(ref val))..ctor(0f, 0f);
					rt9.anchorMax = val;
					Vector2 pivot = (rt8.anchorMin = val);
					rt7.pivot = pivot;
					break;
				}
				case 7:
				{
					RectTransform rt4 = _rt;
					RectTransform rt5 = _rt;
					RectTransform rt6 = _rt;
					((Vector2)(ref val))..ctor(0.5f, 0f);
					rt6.anchorMax = val;
					Vector2 pivot = (rt5.anchorMin = val);
					rt4.pivot = pivot;
					break;
				}
				case 8:
				{
					RectTransform rt = _rt;
					RectTransform rt2 = _rt;
					RectTransform rt3 = _rt;
					((Vector2)(ref val))..ctor(1f, 0f);
					rt3.anchorMax = val;
					Vector2 pivot = (rt2.anchorMin = val);
					rt.pivot = pivot;
					break;
				}
				}
				_rt.anchoredPosition = PositionConfig.Value;
			}
		}
	}
	[Serializable]
	public class RecipeRequirementConfig
	{
		public string item = "";

		public int amount = 1;
	}
	[Serializable]
	public class RecipeConfig
	{
		public string name = "";

		public string item = "";

		public int amount = 1;

		public string craftingStation = "";

		public int minStationLevel = 1;

		public bool enabled = true;

		public string repairStation = "";

		public List<RecipeRequirementConfig> resources = new List<RecipeRequirementConfig>();
	}
	[Serializable]
	public class RecipesConfig
	{
		public List<RecipeConfig> recipes = new List<RecipeConfig>();
	}
	public static class GameObjectExtensions
	{
		public static RectTransform RectTransform(this GameObject go)
		{
			Transform transform = go.transform;
			return (RectTransform)(object)((transform is RectTransform) ? transform : null);
		}

		public static T RequireComponent<T>(this GameObject go) where T : Component
		{
			T component = go.GetComponent<T>();
			if (!((Object)(object)component == (Object)null))
			{
				return component;
			}
			return go.AddComponent<T>();
		}
	}
	public class GotDestroyed : MonoBehaviour
	{
		public void OnDisable()
		{
			Debug.LogError((object)("I got destroyed! (" + ((Object)((Component)this).gameObject).name + ")"));
			Debug.Log((object)Environment.StackTrace);
		}
	}
	public class MultiValueDictionary<TKey, TValue> : Dictionary<TKey, List<TValue>>
	{
		public void Add(TKey key, TValue value)
		{
			if (!TryGetValue(key, out var value2))
			{
				value2 = new List<TValue>();
				Add(key, value2);
			}
			value2.Add(value);
		}

		public bool ContainsValue(TKey key, TValue value)
		{
			if (TryGetValue(key, out var value2))
			{
				return value2.Contains(value);
			}
			return false;
		}

		public void Remove(TKey key, TValue value)
		{
			if (TryGetValue(key, out var value2))
			{
				value2.Remove(value);
				if (value2.Count <= 0)
				{
					Remove(key);
				}
			}
		}

		public void Merge(MultiValueDictionary<TKey, TValue> toMergeWith)
		{
			if (toMergeWith == null)
			{
				return;
			}
			foreach (KeyValuePair<TKey, List<TValue>> item in toMergeWith)
			{
				foreach (TValue item2 in item.Value)
				{
					Add(item.Key, item2);
				}
			}
		}

		public List<TValue> GetValues(TKey key, bool returnEmptySet = false)
		{
			if (!TryGetValue(key, out var value) && returnEmptySet)
			{
				return new List<TValue>();
			}
			return value;
		}
	}
	public static class PrefabCreator
	{
		public static ManualLogSource Logger;

		public static Dictionary<string, CraftingStation> CraftingStations;

		public static T RequireComponent<T>(GameObject go) where T : Component
		{
			T val = go.GetComponent<T>();
			if ((Object)(object)val == (Object)null)
			{
				val = go.AddComponent<T>();
			}
			return val;
		}

		public static void Reset()
		{
			CraftingStations = null;
		}

		private static void InitCraftingStations()
		{
			if (CraftingStations != null)
			{
				return;
			}
			CraftingStations = new Dictionary<string, CraftingStation>();
			foreach (Recipe recipe in ObjectDB.instance.m_recipes)
			{
				if ((Object)(object)recipe.m_craftingStation != (Object)null && !CraftingStations.ContainsKey(((Object)recipe.m_craftingStation).name))
				{
					CraftingStations.Add(((Object)recipe.m_craftingStation).name, recipe.m_craftingStation);
				}
			}
		}

		public static Recipe CreateRecipe(string name, string itemId, RecipeConfig recipeConfig)
		{
			//IL_0200: Unknown result type (might be due to invalid IL or missing references)
			//IL_0205: Unknown result type (might be due to invalid IL or missing references)
			//IL_0212: Unknown result type (might be due to invalid IL or missing references)
			//IL_0224: Expected O, but got Unknown
			InitCraftingStations();
			GameObject itemPrefab = ObjectDB.instance.GetItemPrefab(itemId);
			if ((Object)(object)itemPrefab == (Object)null)
			{
				ManualLogSource logger = Logger;
				if (logger != null)
				{
					logger.LogWarning((object)("[PrefabCreator] Could not find item prefab (" + itemId + ")"));
				}
				return null;
			}
			Recipe val = ScriptableObject.CreateInstance<Recipe>();
			((Object)val).name = name;
			val.m_amount = recipeConfig.amount;
			val.m_minStationLevel = recipeConfig.minStationLevel;
			val.m_item = itemPrefab.GetComponent<ItemDrop>();
			val.m_enabled = recipeConfig.enabled;
			if (!string.IsNullOrEmpty(recipeConfig.craftingStation))
			{
				if (!CraftingStations.ContainsKey(recipeConfig.craftingStation))
				{
					ManualLogSource logger2 = Logger;
					if (logger2 != null)
					{
						logger2.LogWarning((object)("[PrefabCreator] Could not find crafting station (" + itemId + "): " + recipeConfig.craftingStation));
					}
					string text = string.Join(", ", CraftingStations.Keys);
					ManualLogSource logger3 = Logger;
					if (logger3 != null)
					{
						logger3.LogInfo((object)("[PrefabCreator] Available Stations: " + text));
					}
				}
				else
				{
					val.m_craftingStation = CraftingStations[recipeConfig.craftingStation];
				}
			}
			if (!string.IsNullOrEmpty(recipeConfig.repairStation))
			{
				if (!CraftingStations.ContainsKey(recipeConfig.repairStation))
				{
					ManualLogSource logger4 = Logger;
					if (logger4 != null)
					{
						logger4.LogWarning((object)("[PrefabCreator] Could not find repair station (" + itemId + "): " + recipeConfig.repairStation));
					}
					string text2 = string.Join(", ", CraftingStations.Keys);
					ManualLogSource logger5 = Logger;
					if (logger5 != null)
					{
						logger5.LogInfo((object)("[PrefabCreator] Available Stations: " + text2));
					}
				}
				else
				{
					val.m_repairStation = CraftingStations[recipeConfig.repairStation];
				}
			}
			List<Requirement> list = new List<Requirement>();
			foreach (RecipeRequirementConfig resource in recipeConfig.resources)
			{
				GameObject itemPrefab2 = ObjectDB.instance.GetItemPrefab(resource.item);
				if ((Object)(object)itemPrefab2 == (Object)null)
				{
					ManualLogSource logger6 = Logger;
					if (logger6 != null)
					{
						logger6.LogError((object)("[PrefabCreator] Could not find requirement item (" + itemId + "): " + resource.item));
					}
				}
				else
				{
					list.Add(new Requirement
					{
						m_amount = resource.amount,
						m_resItem = itemPrefab2.GetComponent<ItemDrop>()
					});
				}
			}
			val.m_resources = list.ToArray();
			return val;
		}

		public static Recipe AddNewRecipe(string name, string itemId, RecipeConfig recipeConfig)
		{
			Recipe val = CreateRecipe(name, itemId, recipeConfig);
			if ((Object)(object)val == (Object)null)
			{
				ManualLogSource logger = Logger;
				if (logger != null)
				{
					logger.LogError((object)("[PrefabCreator] Failed to create recipe (" + name + ")"));
				}
				return null;
			}
			return AddNewRecipe(val);
		}

		public static Recipe AddNewRecipe(Recipe recipe)
		{
			int num = ObjectDB.instance.m_recipes.RemoveAll((Recipe x) => ((Object)x).name == ((Object)recipe).name);
			if (num > 0)
			{
				ManualLogSource logger = Logger;
				if (logger != null)
				{
					logger.LogInfo((object)$"[PrefabCreator] Removed recipe ({((Object)recipe).name}): {num}");
				}
			}
			ObjectDB.instance.m_recipes.Add(recipe);
			ManualLogSource logger2 = Logger;
			if (logger2 != null)
			{
				logger2.LogInfo((object)("[PrefabCreator] Added recipe: " + ((Object)recipe).name));
			}
			return recipe;
		}
	}
	[Serializable]
	public struct SerializableVector3
	{
		public float x;

		public float y;

		public float z;

		public SerializableVector3(float x, float y, float z)
		{
			this.x = x;
			this.y = y;
			this.z = z;
		}

		public void ToPackage(ZPackage pkg)
		{
			pkg.Write(x);
			pkg.Write(y);
			pkg.Write(z);
		}

		public static SerializableVector3 FromPackage(ZPackage pkg)
		{
			SerializableVector3 result = default(SerializableVector3);
			result.x = pkg.ReadSingle();
			result.y = pkg.ReadSingle();
			result.z = pkg.ReadSingle();
			return result;
		}

		public override string ToString()
		{
			return $"[{x}, {y}, {z}]";
		}

		public static implicit operator Vector3(SerializableVector3 s)
		{
			//IL_0012: Unknown result type (might be due to invalid IL or missing references)
			return new Vector3(s.x, s.y, s.z);
		}

		public static implicit operator SerializableVector3(Vector3 v)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_000c: Unknown result type (might be due to invalid IL or missing references)
			return new SerializableVector3(v.x, v.y, v.z);
		}

		public static SerializableVector3 operator +(SerializableVector3 a, SerializableVector3 b)
		{
			return new SerializableVector3(a.x + b.x, a.y + b.y, a.z + b.z);
		}

		public static SerializableVector3 operator -(SerializableVector3 a, SerializableVector3 b)
		{
			return new SerializableVector3(a.x - b.x, a.y - b.y, a.z - b.z);
		}

		public static SerializableVector3 operator -(SerializableVector3 a)
		{
			return new SerializableVector3(0f - a.x, 0f - a.y, 0f - a.z);
		}

		public static SerializableVector3 operator *(SerializableVector3 a, float m)
		{
			return new SerializableVector3(a.x * m, a.y * m, a.z * m);
		}

		public static SerializableVector3 operator *(float m, SerializableVector3 a)
		{
			return new SerializableVector3(a.x * m, a.y * m, a.z * m);
		}

		public static SerializableVector3 operator /(SerializableVector3 a, float d)
		{
			return new SerializableVector3(a.x / d, a.y / d, a.z / d);
		}
	}
	public static class Utils
	{
		public static void PrintObject(object o)
		{
			if (o == null)
			{
				Debug.Log((object)"null");
			}
			else
			{
				Debug.Log((object)(o?.ToString() + ":\n" + GetObjectString(o, "  ")));
			}
		}

		public static string GetObjectString(object obj, string indent)
		{
			string text = "";
			foreach (FieldInfo item in from f in obj.GetType().GetFields()
				where f.IsPublic
				select f)
			{
				object value = item.GetValue(obj);
				string text2 = ((value == null) ? "null" : value.ToString());
				text = text + "\n" + indent + item.Name + ": " + text2;
			}
			return text;
		}

		public static string RemoveBetween(string s, string from, string to)
		{
			int num = 0;
			while (num >= 0)
			{
				num = s.IndexOf(from, StringComparison.InvariantCulture);
				if (num < 0)
				{
					break;
				}
				int num2 = s.IndexOf(to, num, StringComparison.InvariantCulture);
				if (num2 < 0)
				{
					break;
				}
				s = s.Remove(num, num2 - num + to.Length);
			}
			return s;
		}

		public static void CopyFields(object originalObject, object cloneObject, Type typeToReflect, BindingFlags bindingFlags = BindingFlags.Instance | BindingFlags.Public)
		{
			FieldInfo[] fields = typeToReflect.GetFields(bindingFlags);
			foreach (FieldInfo obj in fields)
			{
				object value = obj.GetValue(originalObject);
				obj.SetValue(cloneObject, value);
			}
		}

		public static bool IsServer()
		{
			//IL_0018: Unknown result type (might be due to invalid IL or missing references)
			//IL_001e: Invalid comparison between Unknown and I4
			if (!ZNet.instance.IsServer() && !ZNet.instance.IsDedicated())
			{
				return (int)SystemInfo.graphicsDeviceType == 4;
			}
			return true;
		}
	}
	public static class ArrayUtils
	{
		public static bool IsNullOrEmpty<T>(T[] a)
		{
			if (a != null)
			{
				return a.Length == 0;
			}
			return true;
		}

		public static T[] Copy<T>(T[] other)
		{
			return other?.ToArray();
		}
	}
	public static class ListExtensions
	{
		public static bool TryFind<T>(this List<T> list, Predicate<T> predicate, out T result)
		{
			int num = list.FindIndex(predicate);
			if (num != -1)
			{
				result = list[num];
				return true;
			}
			result = default(T);
			return false;
		}
	}
}
namespace Jam
{
	public static class RecipesHelper
	{
		public static List<RequirementConfig> MakeRecipeFromConfig(string itemName, string configString)
		{
			//IL_0094: 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_00a1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b5: Expected O, but got Unknown
			List<RequirementConfig> list = new List<RequirementConfig>();
			string[] array = configString.Replace(" ", "").Split(new char[1] { ',' }, StringSplitOptions.RemoveEmptyEntries);
			for (int i = 0; i < array.Length; i++)
			{
				string[] array2 = array[i].Split(new char[1] { ':' }, StringSplitOptions.RemoveEmptyEntries);
				if (array2.Length != 2)
				{
					Jam.JamLogger.LogError((object)("Incorrectly formatted recipe for " + itemName + "! Should be 'ITEM:QUANITY,ITEM2:QUANTITY' etc."));
					continue;
				}
				string item = array2[0];
				if (!int.TryParse(array2[1], out var result))
				{
					Jam.JamLogger.LogError((object)("Incorrectly formatted recipe for " + itemName + "! Should be 'ITEM:QUANITY,ITEM2:QUANTITY' etc."));
					continue;
				}
				list.Add(new RequirementConfig
				{
					Item = item,
					Amount = result,
					Recover = true
				});
			}
			return list;
		}

		public static List<Requirement> MakeRequirementFromConfig(string itemName, string configString)
		{
			List<RequirementConfig> list = MakeRecipeFromConfig(itemName, configString);
			List<Requirement> list2 = new List<Requirement>();
			foreach (RequirementConfig item in list)
			{
				Requirement requirement = item.GetRequirement();
				GameObject prefab = PrefabManager.Instance.GetPrefab(item.Item);
				if ((Object)(object)prefab == (Object)null)
				{
					Jam.JamLogger.LogError((object)("Could not add requirement " + item.Item + ", for " + itemName + ". Prefab not found."));
					continue;
				}
				ItemDrop component = prefab.GetComponent<ItemDrop>();
				if ((Object)(object)component != (Object)null)
				{
					requirement.m_resItem = component;
					list2.Add(requirement);
					continue;
				}
				Jam.JamLogger.LogError((object)("Could not add requirement " + item.Item + ", for " + itemName + "."));
			}
			return list2;
		}
	}
	public class UpdateJams
	{
		public static void UpdateJamConfigruations()
		{
			string[] jams = Jam.Jams;
			foreach (string text in jams)
			{
				string empty = string.Empty;
				bool flag = true;
				float num = 0f;
				float num2 = 0f;
				float num3 = 0f;
				float num4 = 0f;
				float num5 = 0f;
				switch (text)
				{
				case "RaspberryJam":
					flag = Jam.RaspberryJamEnabled.Value;
					empty = Jam.RaspberryJamRecipe.Value;
					num5 = Jam.RaspberryJamDuration.Value;
					num = Jam.RaspberryJamHealth.Value;
					num2 = Jam.RaspberryJamStamina.Value;
					num3 = Jam.RaspberryJamEtir.Value;
					num4 = Jam.RaspberryJamRegen.Value;
					break;
				case "HoneyRaspberryJam":
					flag = Jam.HoneyRaspberryJamEnabled.Value;
					empty = Jam.HoneyRaspberryJamRecipe.Value;
					num5 = Jam.HoneyRaspberryJamDuration.Value;
					num = Jam.HoneyRaspberryJamHealth.Value;
					num2 = Jam.HoneyRaspberryJamStamina.Value;
					num3 = Jam.HoneyRaspberryJamEtir.Value;
					num4 = Jam.HoneyRaspberryJamRegen.Value;
					break;
				case "BlueberryJam":
					flag = Jam.BlueberryJamEnabled.Value;
					empty = Jam.BlueberryJamRecipe.Value;
					num5 = Jam.BlueberryJamDuration.Value;
					num = Jam.BlueberryJamHealth.Value;
					num2 = Jam.BlueberryJamStamina.Value;
					num3 = Jam.BlueberryJamEtir.Value;
					num4 = Jam.BlueberryJamRegen.Value;
					break;
				case "HoneyBlueberryJam":
					flag = Jam.HoneyBlueberryJamEnabled.Value;
					empty = Jam.HoneyBlueberryJamRecipe.Value;
					num5 = Jam.HoneyBlueberryJamDuration.Value;
					num = Jam.HoneyBlueberryJamHealth.Value;
					num2 = Jam.HoneyBlueberryJamStamina.Value;
					num3 = Jam.HoneyBlueberryJamEtir.Value;
					num4 = Jam.HoneyBlueberryJamRegen.Value;
					break;
				case "CloudberryJam":
					flag = Jam.CloudberryJamEnabled.Value;
					empty = Jam.CloudberryJamRecipe.Value;
					num5 = Jam.CloudberryJamDuration.Value;
					num = Jam.CloudberryJamHealth.Value;
					num2 = Jam.CloudberryJamStamina.Value;
					num3 = Jam.CloudberryJamEtir.Value;
					num4 = Jam.CloudberryJamRegen.Value;
					break;
				case "HoneyCloudberryJam":
					flag = Jam.HoneyCloudberryJamEnabled.Value;
					empty = Jam.HoneyCloudberryJamRecipe.Value;
					num5 = Jam.HoneyCloudberryJamDuration.Value;
					num = Jam.HoneyCloudberryJamHealth.Value;
					num2 = Jam.HoneyCloudberryJamStamina.Value;
					num3 = Jam.HoneyCloudberryJamEtir.Value;
					num4 = Jam.HoneyCloudberryJamRegen.Value;
					break;
				case "KingsJam":
					flag = Jam.KingsJamEnabled.Value;
					empty = Jam.KingsJamRecipe.Value;
					num5 = Jam.KingsJamDuration.Value;
					num = Jam.KingsJamHealth.Value;
					num2 = Jam.KingsJamStamina.Value;
					num3 = Jam.KingsJamEtir.Value;
					num4 = Jam.KingsJamRegen.Value;
					break;
				case "NordicJam":
					flag = Jam.NordicJamEnabled.Value;
					empty = Jam.NordicJamRecipe.Value;
					num5 = Jam.NordicJamDuration.Value;
					num = Jam.NordicJamHealth.Value;
					num2 = Jam.NordicJamStamina.Value;
					num3 = Jam.NordicJamEtir.Value;
					num4 = Jam.NordicJamRegen.Value;
					break;
				case "MushroomJam":
					flag = Jam.MushroomJamEnabled.Value;
					empty = Jam.MushroomJamRecipe.Value;
					num5 = Jam.MushroomJamDuration.Value;
					num = Jam.MushroomJamHealth.Value;
					num2 = Jam.MushroomJamStamina.Value;
					num3 = Jam.MushroomJamEtir.Value;
					num4 = Jam.MushroomJamRegen.Value;
					break;
				case "AshlandsJam":
					flag = Jam.AshlandsJamEnabled.Value;
					empty = Jam.AshlandsJamRecipe.Value;
					num5 = Jam.AshlandsJamDuration.Value;
					num = Jam.AshlandsJamHealth.Value;
					num2 = Jam.AshlandsJamStamina.Value;
					num3 = Jam.AshlandsJamEtir.Value;
					num4 = Jam.AshlandsJamRegen.Value;
					break;
				default:
					Jam.JamLogger.LogError((object)("Could not update " + text + " configurations. Not a configurable jam."));
					continue;
				}
				UpdateJamConfigruation(text, flag, empty, num5, num, num2, num3, num4);
			}
		}

		public static void UpdateJamConfigruation(string name, bool enabled, string recipe, float duration, float health, float stamina, float etir, float regen)
		{
			Requirement[] resources = RecipesHelper.MakeRequirementFromConfig(name, recipe).ToArray();
			Recipe val = ((IEnumerable<Recipe>)ObjectDB.instance.m_recipes).FirstOrDefault((Func<Recipe, bool>)((Recipe x) => (Object)(object)x.m_item != (Object)null && (Object)(object)x.m_item.m_itemData.m_dropPrefab != (Object)null && ((Object)x.m_item.m_itemData.m_dropPrefab).name == name));
			if ((Object)(object)val == (Object)null)
			{
				Jam.JamLogger.LogError((object)("Could not find recipe for item " + name));
			}
			else
			{
				val.m_enabled = enabled;
				val.m_resources = resources;
			}
			GameObject item = PrefabManager.Instance.GetPrefab(name);
			if ((Object)(object)item == (Object)null)
			{
				Jam.JamLogger.LogError((object)("Could not find prefab for item " + name));
				return;
			}
			ItemDrop component = item.GetComponent<ItemDrop>();
			if ((Object)(object)component == (Object)null)
			{
				Jam.JamLogger.LogError((object)("Could not find itemDrop for item " + name));
				return;
			}
			component.m_itemData.m_shared.m_foodBurnTime = duration;
			component.m_itemData.m_shared.m_food = health;
			component.m_itemData.m_shared.m_foodStamina = stamina;
			component.m_itemData.m_shared.m_foodEitr = etir;
			component.m_itemData.m_shared.m_foodRegen = regen;
			PieceTable val2 = null;
			GameObject prefab = PrefabManager.Instance.GetPrefab("Feaster");
			ItemDrop val3 = default(ItemDrop);
			if ((Object)(object)prefab == (Object)null || !prefab.TryGetComponent<ItemDrop>(ref val3))
			{
				Jam.JamLogger.LogWarning((object)"Serving Tray not found, will not add build piece.");
				return;
			}
			val2 = val3.m_itemData.m_shared.m_buildPieces;
			GameObject val4 = val2.m_pieces.Find((GameObject x) => ((Object)x).name == Utils.GetPrefabName(((Object)item).name));
			if (!enabled && (Object)(object)val4 != (Object)null)
			{
				val2.m_pieces.Remove(val4);
			}
			else if (enabled && (Object)(object)val4 == (Object)null)
			{
				val2.m_pieces.Add(item);
			}
		}
	}
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	[NetworkCompatibility(/*Could not decode attribute arguments.*/)]
	[BepInPlugin("randyknapp.mods.jam", "Jam", "1.1.0")]
	public class Jam : BaseUnityPlugin
	{
		public const string PluginId = "randyknapp.mods.jam";

		public const string DisplayName = "Jam";

		public const string Version = "1.1.0";

		private static string ConfigFileName = "randyknapp.mods.jam.cfg";

		private static string ConfigFileFullPath;

		public static readonly ManualLogSource JamLogger;

		public static CustomLocalization Localization;

		public static readonly string[] Jams;

		public static ConfigEntry<bool> RaspberryJamEnabled;

		public static string RaspberryJamRecipeDefault;

		public static ConfigEntry<string> RaspberryJamRecipe;

		public static ConfigEntry<float> RaspberryJamDuration;

		public static ConfigEntry<float> RaspberryJamHealth;

		public static ConfigEntry<float> RaspberryJamStamina;

		public static ConfigEntry<float> RaspberryJamEtir;

		public static ConfigEntry<float> RaspberryJamRegen;

		public static ConfigEntry<bool> HoneyRaspberryJamEnabled;

		public static string HoneyRaspberryJamRecipeDefault;

		public static ConfigEntry<string> HoneyRaspberryJamRecipe;

		public static ConfigEntry<float> HoneyRaspberryJamDuration;

		public static ConfigEntry<float> HoneyRaspberryJamHealth;

		public static ConfigEntry<float> HoneyRaspberryJamStamina;

		public static ConfigEntry<float> HoneyRaspberryJamEtir;

		public static ConfigEntry<float> HoneyRaspberryJamRegen;

		public static ConfigEntry<bool> BlueberryJamEnabled;

		public static string BlueberryJamRecipeDefault;

		public static ConfigEntry<string> BlueberryJamRecipe;

		public static ConfigEntry<float> BlueberryJamDuration;

		public static ConfigEntry<float> BlueberryJamHealth;

		public static ConfigEntry<float> BlueberryJamStamina;

		public static ConfigEntry<float> BlueberryJamEtir;

		public static ConfigEntry<float> BlueberryJamRegen;

		public static ConfigEntry<bool> HoneyBlueberryJamEnabled;

		public static string HoneyBlueberryJamRecipeDefault;

		public static ConfigEntry<string> HoneyBlueberryJamRecipe;

		public static ConfigEntry<float> HoneyBlueberryJamDuration;

		public static ConfigEntry<float> HoneyBlueberryJamHealth;

		public static ConfigEntry<float> HoneyBlueberryJamStamina;

		public static ConfigEntry<float> HoneyBlueberryJamEtir;

		public static ConfigEntry<float> HoneyBlueberryJamRegen;

		public static ConfigEntry<bool> CloudberryJamEnabled;

		public static string CloudberryJamRecipeDefault;

		public static ConfigEntry<string> CloudberryJamRecipe;

		public static ConfigEntry<float> CloudberryJamDuration;

		public static ConfigEntry<float> CloudberryJamHealth;

		public static ConfigEntry<float> CloudberryJamStamina;

		public static ConfigEntry<float> CloudberryJamEtir;

		public static ConfigEntry<float> CloudberryJamRegen;

		public static ConfigEntry<bool> HoneyCloudberryJamEnabled;

		public static string HoneyCloudberryJamRecipeDefault;

		public static ConfigEntry<string> HoneyCloudberryJamRecipe;

		public static ConfigEntry<float> HoneyCloudberryJamDuration;

		public static ConfigEntry<float> HoneyCloudberryJamHealth;

		public static ConfigEntry<float> HoneyCloudberryJamStamina;

		public static ConfigEntry<float> HoneyCloudberryJamEtir;

		public static ConfigEntry<float> HoneyCloudberryJamRegen;

		public static ConfigEntry<bool> KingsJamEnabled;

		public static string KingsJamRecipeDefault;

		public static ConfigEntry<string> KingsJamRecipe;

		public static ConfigEntry<float> KingsJamDuration;

		public static ConfigEntry<float> KingsJamHealth;

		public static ConfigEntry<float> KingsJamStamina;

		public static ConfigEntry<float> KingsJamEtir;

		public static ConfigEntry<float> KingsJamRegen;

		public static ConfigEntry<bool> NordicJamEnabled;

		public static string NordicJamRecipeDefault;

		public static ConfigEntry<string> NordicJamRecipe;

		public static ConfigEntry<float> NordicJamDuration;

		public static ConfigEntry<float> NordicJamHealth;

		public static ConfigEntry<float> NordicJamStamina;

		public static ConfigEntry<float> NordicJamEtir;

		public static ConfigEntry<float> NordicJamRegen;

		public static ConfigEntry<bool> MushroomJamEnabled;

		public static string MushroomJamRecipeDefault;

		public static ConfigEntry<string> MushroomJamRecipe;

		public static ConfigEntry<float> MushroomJamDuration;

		public static ConfigEntry<float> MushroomJamHealth;

		public static ConfigEntry<float> MushroomJamStamina;

		public static ConfigEntry<float> MushroomJamEtir;

		public static ConfigEntry<float> MushroomJamRegen;

		public static ConfigEntry<bool> AshlandsJamEnabled;

		public static string AshlandsJamRecipeDefault;

		public static ConfigEntry<string> AshlandsJamRecipe;

		public static ConfigEntry<float> AshlandsJamDuration;

		public static ConfigEntry<float> AshlandsJamHealth;

		public static ConfigEntry<float> AshlandsJamStamina;

		public static ConfigEntry<float> AshlandsJamEtir;

		public static ConfigEntry<float> AshlandsJamRegen;

		private static Jam _instance;

		private Harmony _harmony;

		private DateTime _lastReloadTime;

		private const long RELOAD_DELAY = 10000000L;

		private readonly ConfigurationManagerAttributes AdminConfig = new ConfigurationManagerAttributes
		{
			IsAdminOnly = true
		};

		private readonly ConfigurationManagerAttributes ClientConfig = new ConfigurationManagerAttributes
		{
			IsAdminOnly = false
		};

		[UsedImplicitly]
		public void Awake()
		{
			_instance = this;
			AddConfig("Jam 1 - RaspberryJam", "Jam Enabled", "Enable the Jam to be crafted", synced: true, value: true, ref RaspberryJamEnabled);
			AddConfig("Jam 1 - RaspberryJam", "Jam Recipe", "The items needed to craft the Jam. A comma separated list of ITEM:QUANTITY pairs separated by a colon.", synced: true, RaspberryJamRecipeDefault, ref RaspberryJamRecipe);
			AddConfig("Jam 1 - RaspberryJam", "Jam Duration", "Duration the Jam last in seconds.", synced: true, 1200f, ref RaspberryJamDuration);
			AddConfig("Jam 1 - RaspberryJam", "Jam Health", "Health value the Jam grants.", synced: true, 14f, ref RaspberryJamHealth);
			AddConfig("Jam 1 - RaspberryJam", "Jam Stamina", "Stamina value the Jam grants.", synced: true, 30f, ref RaspberryJamStamina);
			AddConfig("Jam 1 - RaspberryJam", "Jam Etir", "Etir value the Jam grants.", synced: true, 0f, ref RaspberryJamEtir);
			AddConfig("Jam 1 - RaspberryJam", "Jam Health Regen", "Health Regen value the Jam grants.", synced: true, 1f, ref RaspberryJamRegen);
			AddConfig("Jam 2 - HoneyRaspberryJam", "Jam Enabled", "Enable the Jam to be crafted", synced: true, value: true, ref HoneyRaspberryJamEnabled);
			AddConfig("Jam 2 - HoneyRaspberryJam", "Jam Recipe", "The items needed to craft the Jam. A comma separated list of ITEM:QUANTITY pairs separated by a colon.", synced: true, HoneyRaspberryJamRecipeDefault, ref HoneyRaspberryJamRecipe);
			AddConfig("Jam 2 - HoneyRaspberryJam", "Jam Duration", "Duration the Jam last in seconds.", synced: true, 1200f, ref HoneyRaspberryJamDuration);
			AddConfig("Jam 2 - HoneyRaspberryJam", "Jam Health", "Health value the Jam grants.", synced: true, 18f, ref HoneyRaspberryJamHealth);
			AddConfig("Jam 2 - HoneyRaspberryJam", "Jam Stamina", "Stamina value the Jam grants.", synced: true, 35f, ref HoneyRaspberryJamStamina);
			AddConfig("Jam 2 - HoneyRaspberryJam", "Jam Etir", "Etir value the Jam grants.", synced: true, 0f, ref HoneyRaspberryJamEtir);
			AddConfig("Jam 2 - HoneyRaspberryJam", "Jam Health Regen", "Health Regen value the Jam grants.", synced: true, 2f, ref HoneyRaspberryJamRegen);
			AddConfig("Jam 3 - BlueberryJam", "Jam Enabled", "Enable the Jam to be crafted", synced: true, value: true, ref BlueberryJamEnabled);
			AddConfig("Jam 3 - BlueberryJam", "Jam Recipe", "The items needed to craft the Jam. A comma separated list of ITEM:QUANTITY pairs separated by a colon.", synced: true, BlueberryJamRecipeDefault, ref BlueberryJamRecipe);
			AddConfig("Jam 3 - BlueberryJam", "Jam Duration", "Duration the Jam last in seconds.", synced: true, 1200f, ref BlueberryJamDuration);
			AddConfig("Jam 3 - BlueberryJam", "Jam Health", "Health value the Jam grants.", synced: true, 14f, ref BlueberryJamHealth);
			AddConfig("Jam 3 - BlueberryJam", "Jam Stamina", "Stamina value the Jam grants.", synced: true, 35f, ref BlueberryJamStamina);
			AddConfig("Jam 3 - BlueberryJam", "Jam Etir", "Etir value the Jam grants.", synced: true, 0f, ref BlueberryJamEtir);
			AddConfig("Jam 3 - BlueberryJam", "Jam Health Regen", "Health Regen value the Jam grants.", synced: true, 1f, ref BlueberryJamRegen);
			AddConfig("Jam 4 - HoneyBlueberryJam", "Jam Enabled", "Enable the Jam to be crafted", synced: true, value: true, ref HoneyBlueberryJamEnabled);
			AddConfig("Jam 4 - HoneyBlueberryJam", "Jam Recipe", "The items needed to craft the Jam. A comma separated list of ITEM:QUANTITY pairs separated by a colon.", synced: true, HoneyBlueberryJamRecipeDefault, ref HoneyBlueberryJamRecipe);
			AddConfig("Jam 4 - HoneyBlueberryJam", "Jam Duration", "Duration the Jam last in seconds.", synced: true, 1200f, ref HoneyBlueberryJamDuration);
			AddConfig("Jam 4 - HoneyBlueberryJam", "Jam Health", "Health value the Jam grants.", synced: true, 18f, ref HoneyBlueberryJamHealth);
			AddConfig("Jam 4 - HoneyBlueberryJam", "Jam Stamina", "Stamina value the Jam grants.", synced: true, 40f, ref HoneyBlueberryJamStamina);
			AddConfig("Jam 4 - HoneyBlueberryJam", "Jam Etir", "Etir value the Jam grants.", synced: true, 0f, ref HoneyBlueberryJamEtir);
			AddConfig("Jam 4 - HoneyBlueberryJam", "Jam Health Regen", "Health Regen value the Jam grants.", synced: true, 2f, ref HoneyBlueberryJamRegen);
			AddConfig("Jam 5 - CloudberryJam", "Jam Enabled", "Enable the Jam to be crafted", synced: true, value: true, ref CloudberryJamEnabled);
			AddConfig("Jam 5 - CloudberryJam", "Jam Recipe", "The items needed to craft the Jam. A comma separated list of ITEM:QUANTITY pairs separated by a colon.", synced: true, CloudberryJamRecipeDefault, ref CloudberryJamRecipe);
			AddConfig("Jam 5 - CloudberryJam", "Jam Duration", "Duration the Jam last in seconds.", synced: true, 1200f, ref CloudberryJamDuration);
			AddConfig("Jam 5 - CloudberryJam", "Jam Health", "Health value the Jam grants.", synced: true, 26f, ref CloudberryJamHealth);
			AddConfig("Jam 5 - CloudberryJam", "Jam Stamina", "Stamina value the Jam grants.", synced: true, 45f, ref CloudberryJamStamina);
			AddConfig("Jam 5 - CloudberryJam", "Jam Etir", "Etir value the Jam grants.", synced: true, 0f, ref CloudberryJamEtir);
			AddConfig("Jam 5 - CloudberryJam", "Jam Health Regen", "Health Regen value the Jam grants.", synced: true, 1f, ref CloudberryJamRegen);
			AddConfig("Jam 6 - HoneyCloudberryJam", "Jam Enabled", "Enable the Jam to be crafted", synced: true, value: true, ref HoneyCloudberryJamEnabled);
			AddConfig("Jam 6 - HoneyCloudberryJam", "Jam Recipe", "The items needed to craft the Jam. A comma separated list of ITEM:QUANTITY pairs separated by a colon.", synced: true, HoneyCloudberryJamRecipeDefault, ref HoneyCloudberryJamRecipe);
			AddConfig("Jam 6 - HoneyCloudberryJam", "Jam Duration", "Duration the Jam last in seconds.", synced: true, 1200f, ref HoneyCloudberryJamDuration);
			AddConfig("Jam 6 - HoneyCloudberryJam", "Jam Health", "Health value the Jam grants.", synced: true, 30f, ref HoneyCloudberryJamHealth);
			AddConfig("Jam 6 - HoneyCloudberryJam", "Jam Stamina", "Stamina value the Jam grants.", synced: true, 50f, ref HoneyCloudberryJamStamina);
			AddConfig("Jam 6 - HoneyCloudberryJam", "Jam Etir", "Etir value the Jam grants.", synced: true, 0f, ref HoneyCloudberryJamEtir);
			AddConfig("Jam 6 - HoneyCloudberryJam", "Jam Health Regen", "Health Regen value the Jam grants.", synced: true, 2f, ref HoneyCloudberryJamRegen);
			AddConfig("Jam 7 - KingsJam", "Jam Enabled", "Enable the Jam to be crafted", synced: true, value: true, ref KingsJamEnabled);
			AddConfig("Jam 7 - KingsJam", "Jam Recipe", "The items needed to craft the Jam. A comma separated list of ITEM:QUANTITY pairs separated by a colon.", synced: true, KingsJamRecipeDefault, ref KingsJamRecipe);
			AddConfig("Jam 7 - KingsJam", "Jam Duration", "Duration the Jam last in seconds.", synced: true, 1200f, ref KingsJamDuration);
			AddConfig("Jam 7 - KingsJam", "Jam Health", "Health value the Jam grants.", synced: true, 26f, ref KingsJamHealth);
			AddConfig("Jam 7 - KingsJam", "Jam Stamina", "Stamina value the Jam grants.", synced: true, 50f, ref KingsJamStamina);
			AddConfig("Jam 7 - KingsJam", "Jam Etir", "Etir value the Jam grants.", synced: true, 0f, ref KingsJamEtir);
			AddConfig("Jam 7 - KingsJam", "Jam Health Regen", "Health Regen value the Jam grants.", synced: true, 2f, ref KingsJamRegen);
			AddConfig("Jam 8 - NordicJam", "Jam Enabled", "Enable the Jam to be crafted", synced: true, value: true, ref NordicJamEnabled);
			AddConfig("Jam 8 - NordicJam", "Jam Recipe", "The items needed to craft the Jam. A comma separated list of ITEM:QUANTITY pairs separated by a colon.", synced: true, NordicJamRecipeDefault, ref NordicJamRecipe);
			AddConfig("Jam 8 - NordicJam", "Jam Duration", "Duration the Jam last in seconds.", synced: true, 1200f, ref NordicJamDuration);
			AddConfig("Jam 8 - NordicJam", "Jam Health", "Health value the Jam grants.", synced: true, 26f, ref NordicJamHealth);
			AddConfig("Jam 8 - NordicJam", "Jam Stamina", "Stamina value the Jam grants.", synced: true, 55f, ref NordicJamStamina);
			AddConfig("Jam 8 - NordicJam", "Jam Etir", "Etir value the Jam grants.", synced: true, 0f, ref NordicJamEtir);
			AddConfig("Jam 8 - NordicJam", "Jam Health Regen", "Health Regen value the Jam grants.", synced: true, 2f, ref NordicJamRegen);
			AddConfig("Jam 9 - MushroomJam", "Jam Enabled", "Enable the Jam to be crafted", synced: true, value: true, ref MushroomJamEnabled);
			AddConfig("Jam 9 - MushroomJam", "Jam Recipe", "The items needed to craft the Jam. A comma separated list of ITEM:QUANTITY pairs separated by a colon.", synced: true, MushroomJamRecipeDefault, ref MushroomJamRecipe);
			AddConfig("Jam 9 - MushroomJam", "Jam Duration", "Duration the Jam last in seconds.", synced: true, 1500f, ref MushroomJamDuration);
			AddConfig("Jam 9 - MushroomJam", "Jam Health", "Health value the Jam grants.", synced: true, 35f, ref MushroomJamHealth);
			AddConfig("Jam 9 - MushroomJam", "Jam Stamina", "Stamina value the Jam grants.", synced: true, 55f, ref MushroomJamStamina);
			AddConfig("Jam 9 - MushroomJam", "Jam Etir", "Etir value the Jam grants.", synced: true, 30f, ref MushroomJamEtir);
			AddConfig("Jam 9 - MushroomJam", "Jam Health Regen", "Health Regen value the Jam grants.", synced: true, 3f, ref MushroomJamRegen);
			AddConfig("Jam 10 - AshlandsJam", "Jam Enabled", "Enable the Jam to be crafted", synced: true, value: true, ref AshlandsJamEnabled);
			AddConfig("Jam 10 - AshlandsJam", "Jam Recipe", "The items needed to craft the Jam. A comma separated list of ITEM:QUANTITY pairs separated by a colon.", synced: true, AshlandsJamRecipeDefault, ref AshlandsJamRecipe);
			AddConfig("Jam 10 - AshlandsJam", "Jam Duration", "Duration the Jam last in seconds.", synced: true, 1500f, ref AshlandsJamDuration);
			AddConfig("Jam 10 - AshlandsJam", "Jam Health", "Health value the Jam grants.", synced: true, 40f, ref AshlandsJamHealth);
			AddConfig("Jam 10 - AshlandsJam", "Jam Stamina", "Stamina value the Jam grants.", synced: true, 60f, ref AshlandsJamStamina);
			AddConfig("Jam 10 - AshlandsJam", "Jam Etir", "Etir value the Jam grants.", synced: true, 35f, ref AshlandsJamEtir);
			AddConfig("Jam 10 - AshlandsJam", "Jam Health Regen", "Health Regen value the Jam grants.", synced: true, 4f, ref AshlandsJamRegen);
			AssetBundle val = LoadAssetBundle("jamassets");
			if ((Object)(object)val != (Object)null)
			{
				val.LoadAllAssets<GameObject>();
				LoadItem(val, "RaspberryJam", RaspberryJamRecipe.Value, 1);
				LoadItem(val, "HoneyRaspberryJam", HoneyRaspberryJamRecipe.Value, 1);
				LoadItem(val, "BlueberryJam", BlueberryJamRecipe.Value, 1);
				LoadItem(val, "HoneyBlueberryJam", HoneyBlueberryJamRecipe.Value, 1);
				LoadItem(val, "CloudberryJam", CloudberryJamRecipe.Value, 3);
				LoadItem(val, "HoneyCloudberryJam", HoneyCloudberryJamRecipe.Value, 3);
				LoadItem(val, "NordicJam", NordicJamRecipe.Value, 3);
				LoadItem(val, "KingsJam", KingsJamRecipe.Value, 3);
				LoadItem(val, "MushroomJam", MushroomJamRecipe.Value, 4);
				LoadItem(val, "AshlandsJam", AshlandsJamRecipe.Value, 5);
				string text = AssetUtils.LoadTextFromResources("Localization.English.json", Assembly.GetExecutingAssembly());
				Localization.AddJsonFile("English", text);
				SetupWatcher();
				_harmony = Harmony.CreateAndPatchAll(Assembly.GetExecutingAssembly(), "randyknapp.mods.jam");
				ItemManager.OnItemsRegistered += UpdateItemsOnGameStart;
			}
			else
			{
				JamLogger.LogError((object)"Could not load Jam assets! This mod will not load items!");
			}
		}

		[UsedImplicitly]
		private void OnDestroy()
		{
			((BaseUnityPlugin)this).Config.Save();
		}

		private void SetupWatcher()
		{
			FileSystemWatcher fileSystemWatcher = new FileSystemWatcher(Paths.ConfigPath, ConfigFileName);
			fileSystemWatcher.Changed += ReadConfigValues;
			fileSystemWatcher.Created += ReadConfigValues;
			fileSystemWatcher.Renamed += ReadConfigValues;
			fileSystemWatcher.IncludeSubdirectories = true;
			fileSystemWatcher.SynchronizingObject = ThreadingHelper.SynchronizingObject;
			fileSystemWatcher.EnableRaisingEvents = true;
		}

		private void ReadConfigValues(object sender, FileSystemEventArgs e)
		{
			DateTime now = DateTime.Now;
			long num = now.Ticks - _lastReloadTime.Ticks;
			if (File.Exists(ConfigFileFullPath) && num >= 10000000)
			{
				try
				{
					JamLogger.LogInfo((object)"Attempting to reload configuration...");
					((BaseUnityPlugin)this).Config.Reload();
				}
				catch
				{
					JamLogger.LogWarning((object)("There was an issue loading " + ConfigFileName));
					return;
				}
				if ((Object)(object)ZNet.instance != (Object)null && !ZNet.instance.IsDedicated())
				{
					UpdateJams.UpdateJamConfigruations();
				}
				_lastReloadTime = now;
			}
		}

		private void AddConfig<T>(string section, string key, string description, bool synced, T value, ref ConfigEntry<T> configEntry)
		{
			//IL_0033: Unknown result type (might be due to invalid IL or missing references)
			//IL_003d: Expected O, but got Unknown
			string extendedDescription = GetExtendedDescription(description, synced);
			configEntry = ((BaseUnityPlugin)this).Config.Bind<T>(section, key, value, new ConfigDescription(extendedDescription, (AcceptableValueBase)null, new object[1] { synced ? AdminConfig : ClientConfig }));
		}

		public string GetExtendedDescription(string description, bool synchronizedSetting)
		{
			return description + (synchronizedSetting ? " [Synced with Server]" : " [Not Synced with Server]");
		}

		public static AssetBundle LoadAssetBundle(string filename)
		{
			Assembly callingAssembly = Assembly.GetCallingAssembly();
			return AssetBundle.LoadFromStream(callingAssembly.GetManifestResourceStream(callingAssembly.GetName().Name + "." + filename));
		}

		private static void LoadItem(AssetBundle assetBundle, string assetName, string recipe, int stationLevel)
		{
			//IL_000f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0014: Unknown result type (might be due to invalid IL or missing references)
			//IL_001b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0026: Unknown result type (might be due to invalid IL or missing references)
			//IL_002d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0044: Expected O, but got Unknown
			//IL_003f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0049: Expected O, but got Unknown
			GameObject val = assetBundle.LoadAsset<GameObject>(assetName);
			ItemManager.Instance.AddItem(new CustomItem(val, true, new ItemConfig
			{
				Amount = 4,
				CraftingStation = CraftingStations.Cauldron,
				MinStationLevel = stationLevel,
				Requirements = RecipesHelper.MakeRecipeFromConfig(assetName, recipe).ToArray()
			}));
		}

		private static void UpdateItemsOnGameStart()
		{
			UpdateJams.UpdateJamConfigruations();
		}

		static Jam()
		{
			string configPath = Paths.ConfigPath;
			char directorySeparatorChar = Path.DirectorySeparatorChar;
			ConfigFileFullPath = configPath + directorySeparatorChar + ConfigFileName;
			JamLogger = Logger.CreateLogSource("Jam");
			Localization = LocalizationManager.Instance.GetLocalization();
			Jams = new string[10] { "RaspberryJam", "HoneyRaspberryJam", "BlueberryJam", "HoneyBlueberryJam", "CloudberryJam", "HoneyCloudberryJam", "KingsJam", "NordicJam", "MushroomJam", "AshlandsJam" };
			RaspberryJamRecipeDefault = "Raspberry:14";
			RaspberryJamRecipe = null;
			RaspberryJamDuration = null;
			RaspberryJamHealth = null;
			RaspberryJamStamina = null;
			RaspberryJamEtir = null;
			RaspberryJamRegen = null;
			HoneyRaspberryJamRecipeDefault = "Raspberry:8,Honey:4";
			HoneyRaspberryJamRecipe = null;
			HoneyRaspberryJamDuration = null;
			HoneyRaspberryJamHealth = null;
			HoneyRaspberryJamStamina = null;
			HoneyRaspberryJamEtir = null;
			HoneyRaspberryJamRegen = null;
			BlueberryJamRecipeDefault = "Blueberries:14";
			BlueberryJamRecipe = null;
			BlueberryJamDuration = null;
			BlueberryJamHealth = null;
			BlueberryJamStamina = null;
			BlueberryJamEtir = null;
			BlueberryJamRegen = null;
			HoneyBlueberryJamRecipeDefault = "Blueberries:8,Honey:4";
			HoneyBlueberryJamRecipe = null;
			HoneyBlueberryJamDuration = null;
			HoneyBlueberryJamHealth = null;
			HoneyBlueberryJamStamina = null;
			HoneyBlueberryJamEtir = null;
			HoneyBlueberryJamRegen = null;
			CloudberryJamRecipeDefault = "Cloudberry:14";
			CloudberryJamRecipe = null;
			CloudberryJamDuration = null;
			CloudberryJamHealth = null;
			CloudberryJamStamina = null;
			CloudberryJamEtir = null;
			CloudberryJamRegen = null;
			HoneyCloudberryJamRecipeDefault = "Cloudberry:8,Honey:4";
			HoneyCloudberryJamRecipe = null;
			HoneyCloudberryJamDuration = null;
			HoneyCloudberryJamHealth = null;
			HoneyCloudberryJamStamina = null;
			HoneyCloudberryJamEtir = null;
			HoneyCloudberryJamRegen = null;
			KingsJamRecipeDefault = "Raspberry:8,Cloudberry:6";
			KingsJamRecipe = null;
			KingsJamDuration = null;
			KingsJamHealth = null;
			KingsJamStamina = null;
			KingsJamEtir = null;
			KingsJamRegen = null;
			NordicJamRecipeDefault = "Blueberries:8,Cloudberry:6";
			NordicJamRecipe = null;
			NordicJamDuration = null;
			NordicJamHealth = null;
			NordicJamStamina = null;
			NordicJamEtir = null;
			NordicJamRegen = null;
			MushroomJamRecipeDefault = "MushroomMagecap:4,MushroomJotunPuffs:4,Onion:2,Honey:2";
			MushroomJamRecipe = null;
			MushroomJamDuration = null;
			MushroomJamHealth = null;
			MushroomJamStamina = null;
			MushroomJamEtir = null;
			MushroomJamRegen = null;
			AshlandsJamRecipeDefault = "Vineberry:4,MushroomSmokePuff:4,Onion:2,Honey:2";
			AshlandsJamRecipe = null;
			AshlandsJamDuration = null;
			AshlandsJamHealth = null;
			AshlandsJamStamina = null;
			AshlandsJamEtir = null;
			AshlandsJamRegen = null;
		}
	}
}