Decompiled source of ItsJustWood v1.1.0

ItsJustWood.dll

Decompiled 6 months 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 Common;
using HarmonyLib;
using JetBrains.Annotations;
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("ItsJustWood")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("Randy Knapp Mods")]
[assembly: AssemblyProduct("ItsJustWood")]
[assembly: AssemblyCopyright("Copyright © RandyKnapp 2023")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("bb4dfa8b-72b0-4a9b-b9a0-5af5595aa309")]
[assembly: AssemblyFileVersion("1.1.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]
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_0008: Unknown result type (might be due to invalid IL or missing references)
			//IL_0012: Expected O, but got Unknown
			_rt = (RectTransform)((Component)this).transform;
			EnsureCorrectPosition();
		}

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

		public virtual void EnsureCorrectPosition()
		{
			//IL_0012: Unknown result type (might be due to invalid IL or missing references)
			//IL_001d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0056: Unknown result type (might be due to invalid IL or missing references)
			//IL_005b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0061: Unknown result type (might be due to invalid IL or missing references)
			//IL_0066: Unknown result type (might be due to invalid IL or missing references)
			//IL_0067: Unknown result type (might be due to invalid IL or missing references)
			//IL_0068: Unknown result type (might be due to invalid IL or missing references)
			//IL_0069: Unknown result type (might be due to invalid IL or missing references)
			//IL_0093: Expected I4, but got Unknown
			//IL_002a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0035: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bb: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c3: 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)
			//IL_00c6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cd: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fc: Unknown result type (might be due to invalid IL or missing references)
			//IL_0104: Unknown result type (might be due to invalid IL or missing references)
			//IL_0106: Unknown result type (might be due to invalid IL or missing references)
			//IL_0107: Unknown result type (might be due to invalid IL or missing references)
			//IL_010e: Unknown result type (might be due to invalid IL or missing references)
			//IL_013d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0145: Unknown result type (might be due to invalid IL or missing references)
			//IL_0147: Unknown result type (might be due to invalid IL or missing references)
			//IL_0148: Unknown result type (might be due to invalid IL or missing references)
			//IL_014f: Unknown result type (might be due to invalid IL or missing references)
			//IL_017e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0186: Unknown result type (might be due to invalid IL or missing references)
			//IL_0188: Unknown result type (might be due to invalid IL or missing references)
			//IL_0189: Unknown result type (might be due to invalid IL or missing references)
			//IL_0190: Unknown result type (might be due to invalid IL or missing references)
			//IL_01bf: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c7: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c9: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ca: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d1: Unknown result type (might be due to invalid IL or missing references)
			//IL_0200: Unknown result type (might be due to invalid IL or missing references)
			//IL_0208: Unknown result type (might be due to invalid IL or missing references)
			//IL_020a: Unknown result type (might be due to invalid IL or missing references)
			//IL_020b: 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_0241: Unknown result type (might be due to invalid IL or missing references)
			//IL_0249: Unknown result type (might be due to invalid IL or missing references)
			//IL_024b: 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_0253: Unknown result type (might be due to invalid IL or missing references)
			//IL_027f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0287: Unknown result type (might be due to invalid IL or missing references)
			//IL_0289: Unknown result type (might be due to invalid IL or missing references)
			//IL_028a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0291: Unknown result type (might be due to invalid IL or missing references)
			//IL_02bd: Unknown result type (might be due to invalid IL or missing references)
			//IL_02c5: Unknown result type (might be due to invalid IL or missing references)
			//IL_02c7: Unknown result type (might be due to invalid IL or missing references)
			//IL_02c8: Unknown result type (might be due to invalid IL or missing references)
			//IL_02cf: Unknown result type (might be due to invalid IL or missing references)
			//IL_02e4: 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;
				TextAnchor val = currentAnchor;
				Vector2 val2 = default(Vector2);
				switch ((int)val)
				{
				case 0:
				{
					RectTransform rt25 = _rt;
					RectTransform rt26 = _rt;
					RectTransform rt27 = _rt;
					((Vector2)(ref val2))..ctor(0f, 1f);
					rt27.anchorMax = val2;
					Vector2 pivot = (rt26.anchorMin = val2);
					rt25.pivot = pivot;
					break;
				}
				case 1:
				{
					RectTransform rt22 = _rt;
					RectTransform rt23 = _rt;
					RectTransform rt24 = _rt;
					((Vector2)(ref val2))..ctor(0.5f, 1f);
					rt24.anchorMax = val2;
					Vector2 pivot = (rt23.anchorMin = val2);
					rt22.pivot = pivot;
					break;
				}
				case 2:
				{
					RectTransform rt19 = _rt;
					RectTransform rt20 = _rt;
					RectTransform rt21 = _rt;
					((Vector2)(ref val2))..ctor(1f, 1f);
					rt21.anchorMax = val2;
					Vector2 pivot = (rt20.anchorMin = val2);
					rt19.pivot = pivot;
					break;
				}
				case 3:
				{
					RectTransform rt16 = _rt;
					RectTransform rt17 = _rt;
					RectTransform rt18 = _rt;
					((Vector2)(ref val2))..ctor(0f, 0.5f);
					rt18.anchorMax = val2;
					Vector2 pivot = (rt17.anchorMin = val2);
					rt16.pivot = pivot;
					break;
				}
				case 4:
				{
					RectTransform rt13 = _rt;
					RectTransform rt14 = _rt;
					RectTransform rt15 = _rt;
					((Vector2)(ref val2))..ctor(0.5f, 0.5f);
					rt15.anchorMax = val2;
					Vector2 pivot = (rt14.anchorMin = val2);
					rt13.pivot = pivot;
					break;
				}
				case 5:
				{
					RectTransform rt10 = _rt;
					RectTransform rt11 = _rt;
					RectTransform rt12 = _rt;
					((Vector2)(ref val2))..ctor(1f, 0.5f);
					rt12.anchorMax = val2;
					Vector2 pivot = (rt11.anchorMin = val2);
					rt10.pivot = pivot;
					break;
				}
				case 6:
				{
					RectTransform rt7 = _rt;
					RectTransform rt8 = _rt;
					RectTransform rt9 = _rt;
					((Vector2)(ref val2))..ctor(0f, 0f);
					rt9.anchorMax = val2;
					Vector2 pivot = (rt8.anchorMin = val2);
					rt7.pivot = pivot;
					break;
				}
				case 7:
				{
					RectTransform rt4 = _rt;
					RectTransform rt5 = _rt;
					RectTransform rt6 = _rt;
					((Vector2)(ref val2))..ctor(0.5f, 0f);
					rt6.anchorMax = val2;
					Vector2 pivot = (rt5.anchorMin = val2);
					rt4.pivot = pivot;
					break;
				}
				case 8:
				{
					RectTransform rt = _rt;
					RectTransform rt2 = _rt;
					RectTransform rt3 = _rt;
					((Vector2)(ref val2))..ctor(1f, 0f);
					rt3.anchorMax = val2;
					Vector2 pivot = (rt2.anchorMin = val2);
					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>();
			return ((Object)(object)component == (Object)null) ? go.AddComponent<T>() : component;
		}
	}
	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_024b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0250: Unknown result type (might be due to invalid IL or missing references)
			//IL_025d: Unknown result type (might be due to invalid IL or missing references)
			//IL_026f: 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 = "";
			Type type = obj.GetType();
			IEnumerable<FieldInfo> enumerable = from f in type.GetFields()
				where f.IsPublic
				select f;
			foreach (FieldInfo item in enumerable)
			{
				object value = item.GetValue(obj);
				string text2 = ((value == null) ? "null" : value.ToString());
				text = text + "\n" + indent + item.Name + ": " + text2;
			}
			return text;
		}

		public static Sprite LoadSpriteFromFile(string spritePath)
		{
			//IL_0024: Unknown result type (might be due to invalid IL or missing references)
			//IL_002a: Expected O, but got Unknown
			//IL_004f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0056: Unknown result type (might be due to invalid IL or missing references)
			//IL_005c: Unknown result type (might be due to invalid IL or missing references)
			spritePath = Path.Combine(Paths.PluginPath, spritePath);
			if (File.Exists(spritePath))
			{
				byte[] array = File.ReadAllBytes(spritePath);
				Texture2D val = new Texture2D(20, 20);
				if (ImageConversion.LoadImage(val, array))
				{
					return Sprite.Create(val, new Rect(0f, 0f, (float)((Texture)val).width, (float)((Texture)val).height), default(Vector2), 100f);
				}
			}
			return null;
		}

		public static Sprite LoadSpriteFromFile(string modFolder, string iconName)
		{
			string spritePath = Path.Combine(modFolder, iconName);
			return LoadSpriteFromFile(spritePath);
		}

		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 fieldInfo in fields)
			{
				object value = fieldInfo.GetValue(originalObject);
				fieldInfo.SetValue(cloneObject, value);
			}
		}

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

		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;
		}
	}
	public class WeightedRandomCollection<T>
	{
		private readonly Random _random;

		private List<T> _list;

		private Func<T, float> _weightSelector;

		private bool _removeOnSelect;

		public float TotalWeight { get; private set; }

		public WeightedRandomCollection(Random random)
		{
			_random = random;
		}

		public WeightedRandomCollection(Random random, IEnumerable<T> collection, Func<T, float> weightSelector, bool removeOnSelect = false)
		{
			_random = random ?? new Random();
			Setup(collection, weightSelector, removeOnSelect);
		}

		public void Setup(IEnumerable<T> collection, Func<T, float> weightSelector, bool removeOnSelect = false)
		{
			_list = collection.ToList();
			_weightSelector = weightSelector;
			_removeOnSelect = removeOnSelect;
			TotalWeight = _list.Sum(_weightSelector);
		}

		public T Roll()
		{
			if (_list == null)
			{
				return default(T);
			}
			float num = (float)_random.NextDouble() * TotalWeight;
			float num2 = 0f;
			T val = default(T);
			foreach (var item in _list.Select((T weightedItem) => new
			{
				Value = weightedItem,
				Weight = _weightSelector(weightedItem)
			}))
			{
				num2 += item.Weight;
				if (num2 >= num)
				{
					val = item.Value;
					break;
				}
			}
			if (_removeOnSelect)
			{
				_list.Remove(val);
				TotalWeight = _list.Sum(_weightSelector);
			}
			return val;
		}

		public List<T> Roll(int numberOfRolls)
		{
			if (_list == null)
			{
				return null;
			}
			List<T> list = new List<T>();
			for (int i = 0; i < numberOfRolls; i++)
			{
				T x = Roll();
				if (!EqualityComparer<T>.Default.Equals(x, default(T)))
				{
					list.Add(Roll());
				}
			}
			return list;
		}

		public void Reset()
		{
			_list = null;
			_weightSelector = null;
			_removeOnSelect = false;
			TotalWeight = 0f;
		}
	}
}
namespace ItsJustWood
{
	[HarmonyPatch(typeof(CookingStation), "OnAddFuelSwitch")]
	public static class CookingStation_OnAddFuelSwitch_Patch
	{
		[HarmonyPriority(0)]
		private static void Prefix(CookingStation __instance, Humanoid user, ItemData item, ref ItemDrop __state)
		{
			if (ItsJustWood.modEnabled.Value && (item == null || !(item.m_shared.m_name == __instance.m_fuelItem.m_itemData.m_shared.m_name)))
			{
				ItemDrop replacementFuelItem = ItsJustWood.GetReplacementFuelItem(user.GetInventory(), __instance.m_fuelItem);
				if (!((Object)(object)replacementFuelItem == (Object)null))
				{
					__state = __instance.m_fuelItem;
					__instance.m_fuelItem = replacementFuelItem;
				}
			}
		}

		[HarmonyPriority(800)]
		private static void Postfix(CookingStation __instance, ItemDrop __state)
		{
			if (ItsJustWood.modEnabled.Value && !((Object)(object)__state == (Object)null))
			{
				__instance.m_fuelItem = __state;
			}
		}
	}
	[HarmonyPatch(typeof(Fireplace), "Interact")]
	public static class Fireplace_Interact_Patch
	{
		[HarmonyPriority(0)]
		private static void Prefix(Fireplace __instance, Humanoid user, ref ItemDrop __state)
		{
			if (!ItsJustWood.modEnabled.Value || (Object)(object)__instance.m_fuelItem != (Object)(object)ItsJustWood.wood)
			{
				return;
			}
			Inventory inventory = user.GetInventory();
			if (!inventory.HaveItem(__instance.m_fuelItem.m_itemData.m_shared.m_name, true))
			{
				ItemDrop replacementFuelItem = ItsJustWood.GetReplacementFuelItem(inventory, __instance.m_fuelItem);
				if (!((Object)(object)replacementFuelItem == (Object)null))
				{
					__state = __instance.m_fuelItem;
					__instance.m_fuelItem = replacementFuelItem;
				}
			}
		}

		[HarmonyPriority(800)]
		private static void Postfix(Fireplace __instance, ItemDrop __state)
		{
			if (ItsJustWood.modEnabled.Value && !((Object)(object)__state == (Object)null))
			{
				__instance.m_fuelItem = __state;
			}
		}
	}
	[BepInPlugin("randyknapp.mods.itsjustwood", "It's Just Wood", "1.1.0")]
	public class ItsJustWood : BaseUnityPlugin
	{
		private const string pluginID = "randyknapp.mods.itsjustwood";

		private const string pluginName = "It's Just Wood";

		private const string pluginVersion = "1.1.0";

		public static ConfigEntry<bool> modEnabled;

		public static ConfigEntry<Vector2> FineWoodToWoodCount;

		public static ConfigEntry<Vector2> CoreWoodToWoodCount;

		public static ConfigEntry<Vector2> AncientBarkToWoodCount;

		public static ConfigEntry<Vector2> YggdrasilWoodToWoodCount;

		public static ConfigEntry<bool> AllowFineWoodForFuel;

		public static ConfigEntry<bool> AllowCoreWoodForFuel;

		public static ConfigEntry<bool> AllowAncientBarkForFuel;

		public static ConfigEntry<bool> AllowYggdrasilWoodForFuel;

		public static ConfigEntry<bool> AllowAncientBarkForCoal;

		public static ConfigEntry<bool> AllowYggdrasilWoodForCoal;

		private Harmony _harmony;

		public static ItemDrop wood;

		[UsedImplicitly]
		private void Awake()
		{
			//IL_003b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0069: 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_00c5: Unknown result type (might be due to invalid IL or missing references)
			modEnabled = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "Enabled", true, "Enable the mod.");
			FineWoodToWoodCount = ((BaseUnityPlugin)this).Config.Bind<Vector2>("Recipes", "FineWoodToWoodCount", new Vector2(8f, 8f), "The Fine Wood -> Wood recipe counts. X = amount of fine wood used, Y = amount of wood created");
			CoreWoodToWoodCount = ((BaseUnityPlugin)this).Config.Bind<Vector2>("Recipes", "CoreWoodToWoodCount", new Vector2(8f, 8f), "The Core Wood -> Wood recipe counts. X = amount of core wood used, Y = amount of wood created");
			AncientBarkToWoodCount = ((BaseUnityPlugin)this).Config.Bind<Vector2>("Recipes", "AncientBarkToWoodCount", new Vector2(8f, 8f), "The Ancient Bark -> Wood recipe counts. X = amount of ancient bark used, Y = amount of wood created");
			YggdrasilWoodToWoodCount = ((BaseUnityPlugin)this).Config.Bind<Vector2>("Recipes", "YggdrasilWoodToWoodCount", new Vector2(8f, 8f), "The Yggdrasil wood -> Wood recipe counts. X = amount of Yggdrasil wood used, Y = amount of wood created");
			AllowFineWoodForFuel = ((BaseUnityPlugin)this).Config.Bind<bool>("Fuel", "AllowFineWoodForFuel", true, "Allow fine wood to be used as fuel for fires");
			AllowCoreWoodForFuel = ((BaseUnityPlugin)this).Config.Bind<bool>("Fuel", "AllowCoreWoodForFuel", true, "Allow core wood to be used as fuel for fires");
			AllowAncientBarkForFuel = ((BaseUnityPlugin)this).Config.Bind<bool>("Fuel", "AllowAncientBarkForFuel", true, "Allow ancient bark to be used as fuel for fires");
			AllowYggdrasilWoodForFuel = ((BaseUnityPlugin)this).Config.Bind<bool>("Fuel", "AllowYggdrasilWoodForFuel", true, "Allow Yggdrasil wood to be used as fuel for fires");
			AllowAncientBarkForCoal = ((BaseUnityPlugin)this).Config.Bind<bool>("Fuel", "AllowAncientBarkForCoal", true, "Allow ancient bark to be used to create coal in a charcoal kiln");
			AllowYggdrasilWoodForCoal = ((BaseUnityPlugin)this).Config.Bind<bool>("Fuel", "AllowYggdrasilWoodForCoal", true, "Allow Yggdrasil wood to be used to create coal in a charcoal kiln");
			_harmony = Harmony.CreateAndPatchAll(Assembly.GetExecutingAssembly(), "randyknapp.mods.itsjustwood");
		}

		public static bool IsObjectDBReady()
		{
			return (Object)(object)ObjectDB.instance != (Object)null && ObjectDB.instance.m_items.Count != 0 && (Object)(object)ObjectDB.instance.GetItemPrefab("Amber") != (Object)null;
		}

		public static void TryRegisterRecipes()
		{
			//IL_0045: Unknown result type (might be due to invalid IL or missing references)
			//IL_005a: Unknown result type (might be due to invalid IL or missing references)
			//IL_006f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0084: Unknown result type (might be due to invalid IL or missing references)
			if (modEnabled.Value && IsObjectDBReady())
			{
				wood = ObjectDB.instance.GetItemPrefab("Wood").GetComponent<ItemDrop>();
				AddWoodConversionRecipe("RoundLog", CoreWoodToWoodCount.Value);
				AddWoodConversionRecipe("FineWood", FineWoodToWoodCount.Value);
				AddWoodConversionRecipe("ElderBark", AncientBarkToWoodCount.Value);
				AddWoodConversionRecipe("YggdrasilWood", YggdrasilWoodToWoodCount.Value);
			}
		}

		public static void AddWoodConversionRecipe(string prefabName, Vector2 conversion)
		{
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			//IL_0032: Unknown result type (might be due to invalid IL or missing references)
			RecipeConfig recipeConfig = new RecipeConfig
			{
				amount = Mathf.CeilToInt(conversion.y),
				enabled = true,
				resources = new List<RecipeRequirementConfig>
				{
					new RecipeRequirementConfig
					{
						item = prefabName,
						amount = Mathf.CeilToInt(conversion.x)
					}
				}
			};
			if (recipeConfig.amount > 0 && recipeConfig.resources[0].amount > 0)
			{
				PrefabCreator.AddNewRecipe("Recipe_" + prefabName + "ToWood", "Wood", recipeConfig);
			}
		}

		public static ItemDrop GetReplacementFuelItem(Inventory inventory, ItemDrop builtIn)
		{
			if ((Object)(object)builtIn != (Object)(object)wood)
			{
				return null;
			}
			if (inventory.HaveItem(builtIn.m_itemData.m_shared.m_name, true))
			{
				return null;
			}
			ItemDrop component = ObjectDB.instance.GetItemPrefab("FineWood").GetComponent<ItemDrop>();
			ItemDrop component2 = ObjectDB.instance.GetItemPrefab("RoundLog").GetComponent<ItemDrop>();
			ItemDrop component3 = ObjectDB.instance.GetItemPrefab("ElderBark").GetComponent<ItemDrop>();
			ItemDrop component4 = ObjectDB.instance.GetItemPrefab("YggdrasilWood").GetComponent<ItemDrop>();
			if (AllowAncientBarkForFuel.Value && inventory.HaveItem(component3.m_itemData.m_shared.m_name, true))
			{
				return component3;
			}
			if (AllowCoreWoodForFuel.Value && inventory.HaveItem(component2.m_itemData.m_shared.m_name, true))
			{
				return component2;
			}
			if (AllowFineWoodForFuel.Value && inventory.HaveItem(component.m_itemData.m_shared.m_name, true))
			{
				return component;
			}
			if (AllowYggdrasilWoodForFuel.Value && inventory.HaveItem(component4.m_itemData.m_shared.m_name, true))
			{
				return component4;
			}
			return null;
		}
	}
	[HarmonyPatch(typeof(ObjectDB), "CopyOtherDB")]
	public static class ObjectDB_CopyOtherDB_Patch
	{
		public static void Postfix()
		{
			ItsJustWood.TryRegisterRecipes();
		}
	}
	[HarmonyPatch(typeof(ObjectDB), "Awake")]
	public static class ObjectDB_Awake_Patch
	{
		public static void Postfix()
		{
			ItsJustWood.TryRegisterRecipes();
		}
	}
	[HarmonyPatch(typeof(Smelter), "Awake")]
	public static class Smelter_Awake_Patch
	{
		public static void Postfix(Smelter __instance)
		{
			//IL_00ba: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bf: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cb: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d5: Expected O, but got Unknown
			//IL_0157: Unknown result type (might be due to invalid IL or missing references)
			//IL_015c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0169: Unknown result type (might be due to invalid IL or missing references)
			//IL_0173: Expected O, but got Unknown
			if (!ItsJustWood.modEnabled.Value || __instance.m_conversion.Find((ItemConversion x) => (Object)(object)x.m_from == (Object)(object)ItsJustWood.wood) == null)
			{
				return;
			}
			if (ItsJustWood.AllowAncientBarkForCoal.Value)
			{
				ItemDrop ancientWood = ObjectDB.instance.GetItemPrefab("ElderBark").GetComponent<ItemDrop>();
				ItemConversion val = __instance.m_conversion.Find((ItemConversion x) => (Object)(object)x.m_from == (Object)(object)ancientWood);
				if (val == null)
				{
					ItemDrop component = ObjectDB.instance.GetItemPrefab("Coal").GetComponent<ItemDrop>();
					val = new ItemConversion
					{
						m_from = ancientWood,
						m_to = component
					};
					__instance.m_conversion.Add(val);
				}
			}
			if (ItsJustWood.AllowYggdrasilWoodForCoal.Value)
			{
				ItemDrop yggdrasilWood = ObjectDB.instance.GetItemPrefab("YggdrasilWood").GetComponent<ItemDrop>();
				ItemConversion val2 = __instance.m_conversion.Find((ItemConversion x) => (Object)(object)x.m_from == (Object)(object)yggdrasilWood);
				if (val2 == null)
				{
					ItemDrop component2 = ObjectDB.instance.GetItemPrefab("Coal").GetComponent<ItemDrop>();
					val2 = new ItemConversion
					{
						m_from = yggdrasilWood,
						m_to = component2
					};
					__instance.m_conversion.Add(val2);
				}
			}
		}
	}
	[HarmonyPatch(typeof(Smelter), "OnAddFuel")]
	public static class Smelter_OnAddFuel_Patch
	{
		[HarmonyPriority(0)]
		private static void Prefix(Smelter __instance, Humanoid user, ItemData item, ref ItemDrop __state)
		{
			if (ItsJustWood.modEnabled.Value && (item == null || !(item.m_shared.m_name == __instance.m_fuelItem.m_itemData.m_shared.m_name)))
			{
				ItemDrop replacementFuelItem = ItsJustWood.GetReplacementFuelItem(user.GetInventory(), __instance.m_fuelItem);
				if (!((Object)(object)replacementFuelItem == (Object)null))
				{
					__state = __instance.m_fuelItem;
					__instance.m_fuelItem = replacementFuelItem;
				}
			}
		}

		[HarmonyPriority(800)]
		private static void Postfix(Smelter __instance, ItemDrop __state)
		{
			if (ItsJustWood.modEnabled.Value && !((Object)(object)__state == (Object)null))
			{
				__instance.m_fuelItem = __state;
			}
		}
	}
}