Decompiled source of MinimalStatusEffects v1.0.7

MinimalStatusEffects/MinimalStatusEffects.dll

Decompiled a year 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 BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using Common;
using HarmonyLib;
using TMPro;
using UnityEngine;
using UnityEngine.UI;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: AssemblyTitle("MinimalStatusEffects")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("Randy Knapp Mods")]
[assembly: AssemblyProduct("MinimalStatusEffects")]
[assembly: AssemblyCopyright("Copyright © Randy Knapp 2023")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("70b6ed26-2afe-4e7a-a40f-cf187f14fca0")]
[assembly: AssemblyFileVersion("1.0.7.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")]
[assembly: AssemblyVersion("1.0.7.0")]
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 MinimalStatusEffects
{
	[HarmonyPatch(typeof(Hud), "UpdateStatusEffects", new Type[] { typeof(List<StatusEffect>) })]
	public static class Hud_UpdateStatusEffects_Patch
	{
		public static Sprite _sprite;

		private static void Postfix(List<StatusEffect> statusEffects, List<RectTransform> ___m_statusEffects, RectTransform ___m_statusEffectListRoot)
		{
			//IL_003b: Unknown result type (might be due to invalid IL or missing references)
			//IL_002f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0040: Unknown result type (might be due to invalid IL or missing references)
			//IL_005e: 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_0086: Unknown result type (might be due to invalid IL or missing references)
			//IL_0075: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ba: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d0: 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_0127: 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_02d4: Unknown result type (might be due to invalid IL or missing references)
			//IL_02fb: Unknown result type (might be due to invalid IL or missing references)
			//IL_0325: Unknown result type (might be due to invalid IL or missing references)
			//IL_033c: Unknown result type (might be due to invalid IL or missing references)
			//IL_036f: Unknown result type (might be due to invalid IL or missing references)
			//IL_037c: Unknown result type (might be due to invalid IL or missing references)
			//IL_038c: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d3: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ea: Unknown result type (might be due to invalid IL or missing references)
			//IL_0203: Unknown result type (might be due to invalid IL or missing references)
			if (Game.m_noMap && !MinimalStatusEffectConfig.EnabledInNomap.Value)
			{
				return;
			}
			Vector2 anchoredPosition = (Game.m_noMap ? MinimalStatusEffectConfig.NomapScreenPosition.Value : MinimalStatusEffectConfig.ScreenPosition.Value);
			float num = (Game.m_noMap ? MinimalStatusEffectConfig.NomapListSize.Value.x : MinimalStatusEffectConfig.ListSize.Value.x);
			float num2 = (Game.m_noMap ? MinimalStatusEffectConfig.NomapListSize.Value.y : MinimalStatusEffectConfig.ListSize.Value.y);
			float num3 = (Game.m_noMap ? MinimalStatusEffectConfig.NomapIconSize.Value : MinimalStatusEffectConfig.IconSize.Value);
			___m_statusEffectListRoot.anchorMin = new Vector2(1f, 1f);
			___m_statusEffectListRoot.anchorMax = new Vector2(1f, 1f);
			___m_statusEffectListRoot.SetSizeWithCurrentAnchors((Axis)1, num2);
			___m_statusEffectListRoot.SetSizeWithCurrentAnchors((Axis)0, num);
			___m_statusEffectListRoot.anchoredPosition = anchoredPosition;
			float num4 = 0f;
			for (int i = 0; i < ___m_statusEffects.Count; i++)
			{
				StatusEffect val = statusEffects[i];
				RectTransform val2 = ___m_statusEffects[i];
				((Transform)val2).localPosition = new Vector3(0f, num4, 0f);
				num4 -= (Game.m_noMap ? MinimalStatusEffectConfig.NomapEntrySpacing.Value : MinimalStatusEffectConfig.EntrySpacing.Value);
				Transform obj = ((Transform)val2).Find("Name");
				RectTransform val3 = (RectTransform)(object)((obj is RectTransform) ? obj : null);
				if ((Object)(object)val3 != (Object)null)
				{
					TMP_Text component = ((Component)val3).GetComponent<TMP_Text>();
					component.richText = true;
					component.textWrappingMode = (TextWrappingModes)1;
					component.alignment = (TextAlignmentOptions)4097;
					component.fontSize = (Game.m_noMap ? MinimalStatusEffectConfig.NomapFontSize.Value : MinimalStatusEffectConfig.FontSize.Value);
					val3.anchorMin = new Vector2(0f, 0.5f);
					val3.anchorMax = new Vector2(1f, 0.5f);
					val3.anchoredPosition = new Vector2(120f + num3, 2f);
					val3.SetSizeWithCurrentAnchors((Axis)1, num3 + 20f);
					val3.SetSizeWithCurrentAnchors((Axis)0, num);
					string iconText = val.GetIconText();
					Transform val4 = ((Transform)val2).Find("TimeText");
					if (!string.IsNullOrEmpty(iconText))
					{
						if ((Object)(object)val4 != (Object)null)
						{
							((Component)val4).gameObject.SetActive(false);
						}
						string text = Localization.instance.Localize(val.m_name);
						component.text = text + " <color=#ffb75c>" + iconText + "</color>";
					}
				}
				Transform obj2 = ((Transform)val2).Find("Icon");
				RectTransform val5 = (RectTransform)(object)((obj2 is RectTransform) ? obj2 : null);
				val5.anchorMin = new Vector2(0.5f, 0.5f);
				val5.anchorMax = new Vector2(0.5f, 0.5f);
				val5.SetSizeWithCurrentAnchors((Axis)1, num3);
				val5.SetSizeWithCurrentAnchors((Axis)0, num3);
				val5.anchoredPosition = new Vector2(num3, 0f);
				Transform obj3 = ((Transform)val2).Find("Cooldown");
				RectTransform val6 = (RectTransform)(object)((obj3 is RectTransform) ? obj3 : null);
				val6.anchorMin = new Vector2(0.5f, 0.5f);
				val6.anchorMax = new Vector2(0.5f, 0.5f);
				val6.SetSizeWithCurrentAnchors((Axis)1, 16f);
				val6.SetSizeWithCurrentAnchors((Axis)0, 16f);
				val6.anchoredPosition = new Vector2(20f, -10f);
				((Transform)val6).Rotate(Vector3.forward * (-200f * Time.deltaTime));
				if ((Object)(object)_sprite == (Object)null)
				{
					_sprite = Utils.LoadSpriteFromFile("MinimalStatusEffects", "refresh_icon.png");
				}
				if ((Object)(object)_sprite != (Object)null)
				{
					Image component2 = ((Component)val6).GetComponent<Image>();
					component2.overrideSprite = _sprite;
				}
			}
		}
	}
	[HarmonyPatch(typeof(Hud), "UpdateShipHud")]
	public static class Hud_UpdateShipHud_Patch
	{
		public static void Postfix(Hud __instance)
		{
			//IL_005d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0081: Unknown result type (might be due to invalid IL or missing references)
			//IL_0075: Unknown result type (might be due to invalid IL or missing references)
			//IL_00aa: Unknown result type (might be due to invalid IL or missing references)
			//IL_009e: Unknown result type (might be due to invalid IL or missing references)
			if (!Game.m_noMap || MinimalStatusEffectConfig.EnabledInNomap.Value)
			{
				float num = (Game.m_noMap ? MinimalStatusEffectConfig.NomapSailingPowerIndicatorScale.Value : MinimalStatusEffectConfig.SailingPowerIndicatorScale.Value);
				Transform parent = __instance.m_rudder.transform.parent;
				RectTransform val = (RectTransform)(object)((parent is RectTransform) ? parent : null);
				((Transform)val).localScale = new Vector3(num, num, 1f);
				val.anchoredPosition = (Game.m_noMap ? MinimalStatusEffectConfig.NomapSailingPowerIndicatorPosition.Value : MinimalStatusEffectConfig.SailingPowerIndicatorPosition.Value);
				__instance.m_shipWindIndicatorRoot.anchoredPosition = (Game.m_noMap ? MinimalStatusEffectConfig.NomapSailingWindIndicatorPosition.Value : MinimalStatusEffectConfig.SailingWindIndicatorPosition.Value);
			}
		}
	}
	public static class MinimalStatusEffectConfig
	{
		public static ConfigEntry<Vector2> ScreenPosition;

		public static ConfigEntry<Vector2> ListSize;

		public static ConfigEntry<float> EntrySpacing;

		public static ConfigEntry<float> IconSize;

		public static ConfigEntry<int> FontSize;

		public static ConfigEntry<Vector2> SailingWindIndicatorPosition;

		public static ConfigEntry<Vector2> SailingPowerIndicatorPosition;

		public static ConfigEntry<float> SailingPowerIndicatorScale;

		public static ConfigEntry<bool> EnabledInNomap;

		public static ConfigEntry<Vector2> NomapScreenPosition;

		public static ConfigEntry<Vector2> NomapListSize;

		public static ConfigEntry<float> NomapEntrySpacing;

		public static ConfigEntry<float> NomapIconSize;

		public static ConfigEntry<int> NomapFontSize;

		public static ConfigEntry<Vector2> NomapSailingWindIndicatorPosition;

		public static ConfigEntry<Vector2> NomapSailingPowerIndicatorPosition;

		public static ConfigEntry<float> NomapSailingPowerIndicatorScale;
	}
	[BepInPlugin("randyknapp.mods.minimalstatuseffects", "Minimal Status Effects", "1.0.7")]
	[BepInIncompatibility("randyknapp.mods.auga")]
	public class MinimalStatusEffects : BaseUnityPlugin
	{
		public const string PluginId = "randyknapp.mods.minimalstatuseffects";

		public const string Version = "1.0.7";

		private Harmony _harmony;

		private void Awake()
		{
			//IL_001b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0049: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e0: 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_0180: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ae: Unknown result type (might be due to invalid IL or missing references)
			//IL_0245: Unknown result type (might be due to invalid IL or missing references)
			//IL_0273: Unknown result type (might be due to invalid IL or missing references)
			MinimalStatusEffectConfig.ScreenPosition = ((BaseUnityPlugin)this).Config.Bind<Vector2>("General", "ScreenPosition", new Vector2(-230f, -290f), "The position offset from the top right corner of the screen.");
			MinimalStatusEffectConfig.ListSize = ((BaseUnityPlugin)this).Config.Bind<Vector2>("General", "ListSize", new Vector2(200f, 400f), "The size of the list box.");
			MinimalStatusEffectConfig.EntrySpacing = ((BaseUnityPlugin)this).Config.Bind<float>("General", "EntrySpacing", 42f, "The number of units between the top of each entry in the status effects list.");
			MinimalStatusEffectConfig.IconSize = ((BaseUnityPlugin)this).Config.Bind<float>("General", "IconSize", 32f, "The size of the square icons.");
			MinimalStatusEffectConfig.FontSize = ((BaseUnityPlugin)this).Config.Bind<int>("General", "FontSize", 20, "The size of the text on the label.");
			MinimalStatusEffectConfig.SailingWindIndicatorPosition = ((BaseUnityPlugin)this).Config.Bind<Vector2>("SailingIndicator", "SailingWindIndicatorPosition", new Vector2(-350f, -140f), "Location of the sailing wind direction indicator on screen.");
			MinimalStatusEffectConfig.SailingPowerIndicatorPosition = ((BaseUnityPlugin)this).Config.Bind<Vector2>("SailingIndicator", "SailingPowerIndicatorPosition", new Vector2(-270f, -215f), "Location of the sailing power indicator on screen.");
			MinimalStatusEffectConfig.SailingPowerIndicatorScale = ((BaseUnityPlugin)this).Config.Bind<float>("SailingIndicator", "SailingPowerIndicatorScale", 0.65f, "Scale of the sailing power indicator.");
			MinimalStatusEffectConfig.EnabledInNomap = ((BaseUnityPlugin)this).Config.Bind<bool>("Nomap", "Enabled", true, "Enabled in nomap mode");
			MinimalStatusEffectConfig.NomapScreenPosition = ((BaseUnityPlugin)this).Config.Bind<Vector2>("Nomap", "ScreenPosition", new Vector2(-230f, -290f), "For nomap mode. The position offset from the top right corner of the screen.");
			MinimalStatusEffectConfig.NomapListSize = ((BaseUnityPlugin)this).Config.Bind<Vector2>("Nomap", "ListSize", new Vector2(200f, 400f), "For nomap mode. The size of the list box.");
			MinimalStatusEffectConfig.NomapEntrySpacing = ((BaseUnityPlugin)this).Config.Bind<float>("Nomap", "EntrySpacing", 42f, "For nomap mode. The number of units between the top of each entry in the status effects list.");
			MinimalStatusEffectConfig.NomapIconSize = ((BaseUnityPlugin)this).Config.Bind<float>("Nomap", "IconSize", 32f, "For nomap mode. The size of the square icons.");
			MinimalStatusEffectConfig.NomapFontSize = ((BaseUnityPlugin)this).Config.Bind<int>("Nomap", "FontSize", 20, "For nomap mode. The size of the text on the label.");
			MinimalStatusEffectConfig.NomapSailingWindIndicatorPosition = ((BaseUnityPlugin)this).Config.Bind<Vector2>("SailingIndicator Nomap", "SailingWindIndicatorPosition", new Vector2(-350f, -140f), "For nomap mode. Location of the sailing wind direction indicator on screen.");
			MinimalStatusEffectConfig.NomapSailingPowerIndicatorPosition = ((BaseUnityPlugin)this).Config.Bind<Vector2>("SailingIndicator Nomap", "SailingPowerIndicatorPosition", new Vector2(-270f, -215f), "For nomap mode. Location of the sailing power indicator on screen.");
			MinimalStatusEffectConfig.NomapSailingPowerIndicatorScale = ((BaseUnityPlugin)this).Config.Bind<float>("SailingIndicator Nomap", "SailingPowerIndicatorScale", 0.65f, "For nomap mode. Scale of the sailing power indicator.");
			_harmony = Harmony.CreateAndPatchAll(Assembly.GetExecutingAssembly(), "randyknapp.mods.minimalstatuseffects");
		}
	}
}