Decompiled source of KushCraftingStations v1.0.1

plugins/KushCraftingStations.dll

Decompiled 6 months ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Configuration;
using HarmonyLib;
using Jotunn.Configs;
using Jotunn.Entities;
using Jotunn.Managers;
using UnityEngine;
using ValheimMod;
using wackydatabase;
using wackydatabase.Datas;
using wackydatabase.SetData;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: AssemblyTitle("Kush Crafting Stations")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("Kush Crafting Stations")]
[assembly: AssemblyCopyright("Copyright ©  2024")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("d361bbf1-e696-4de9-b806-2efc93357f42")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")]
[assembly: AssemblyVersion("1.0.0.0")]
namespace ValheimMod
{
	internal static class Util
	{
		public class MeteorProjectileParameters
		{
			public float aoe;

			public float MinPhysicalDamage { get; set; }

			public float MaxPhysicalDamage { get; set; }

			public float MinElementalDamage { get; set; }

			public float MaxElementalDamage { get; set; }
		}

		public static readonly string KilledBonemass = "defeated_bonemass";

		public static readonly string KilledElder = "defeated_gdking";

		public static readonly string KilledYagluth = "defeated_goblinking";

		public static readonly string KilledModer = "defeated_dragon";

		public static readonly string KilledEikthyr = "defeated_eikthyr";

		public static readonly string KilledTroll = "KilledTroll";

		public static readonly string KilledSurtling = "killed_surtling";

		public static readonly string CustomMinDamageId = "min_attack_damage";

		public static readonly string CustomMaxDamageId = "max_attack_damage";

		public static readonly string CustomMinElemDamageId = "min_attack_elem_damage";

		public static readonly string CustomMaxElemDamageId = "max_attack_elem_damage";

		public static void SpawnMeteor()
		{
			//IL_0016: Unknown result type (might be due to invalid IL or missing references)
			//IL_002a: 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_0034: 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_0045: Unknown result type (might be due to invalid IL or missing references)
			Player localPlayer = Player.m_localPlayer;
			Vector3 randomVector = GetRandomVector(new Vector3(-40f, 20f, -40f), new Vector3(40f, 40f, 40f));
			SpawnCustomMeteor("projectile_meteor", ((Component)localPlayer).transform.position, randomVector);
		}

		public static void SetupMeteorProjectile(Projectile projectile, Character attackOwner, MeteorProjectileParameters parameters)
		{
			//IL_0028: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)projectile != (Object)null && parameters != null)
			{
				projectile.m_aoe = parameters.aoe;
				ProcessDamageZDO(ZDOMan.instance.GetZDO(attackOwner.GetZDOID()), parameters.MinPhysicalDamage, parameters.MaxPhysicalDamage, parameters.MinElementalDamage, parameters.MaxElementalDamage, 100);
			}
		}

		public static void ProcessDamageZDO(ZDO zdo, float MinPhysicalDamage, float MaxPhysicalDamage, float MinElementalDamage, float MaxElementalDamage, int spawnDamageModifier)
		{
			if (zdo != null)
			{
				float num = (float)spawnDamageModifier / 100f;
				zdo.Set(CustomMinDamageId, MinPhysicalDamage * num);
				zdo.Set(CustomMaxDamageId, MaxPhysicalDamage * num);
				if (MinElementalDamage != 0f)
				{
					zdo.Set(CustomMinElemDamageId, MinElementalDamage * num);
					zdo.Set(CustomMaxElemDamageId, MaxElementalDamage * num);
				}
			}
		}

		public static Projectile SetupProjectilePhysics(Character owner, GameObject gameObject, Vector3 target, float velocity = 10f, float accuracy = 5f)
		{
			//IL_002e: 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_003a: Unknown result type (might be due to invalid IL or missing references)
			//IL_003f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0043: 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_0049: Unknown result type (might be due to invalid IL or missing references)
			//IL_004a: Unknown result type (might be due to invalid IL or missing references)
			//IL_004f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0054: Unknown result type (might be due to invalid IL or missing references)
			//IL_0064: Unknown result type (might be due to invalid IL or missing references)
			//IL_0065: Unknown result type (might be due to invalid IL or missing references)
			//IL_006a: Unknown result type (might be due to invalid IL or missing references)
			//IL_006b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0070: Unknown result type (might be due to invalid IL or missing references)
			//IL_0080: Unknown result type (might be due to invalid IL or missing references)
			//IL_0085: Unknown result type (might be due to invalid IL or missing references)
			//IL_008a: Unknown result type (might be due to invalid IL or missing references)
			//IL_008b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0090: Unknown result type (might be due to invalid IL or missing references)
			//IL_0093: Unknown result type (might be due to invalid IL or missing references)
			//IL_0095: Unknown result type (might be due to invalid IL or missing references)
			try
			{
				Projectile val = ((gameObject != null) ? gameObject.GetComponent<Projectile>() : null);
				if ((Object)(object)val == (Object)null)
				{
					Debug.Log((object)"SetupProjectile null error");
					return null;
				}
				Vector3 val2 = target - ((Component)val).transform.position;
				Vector3 normalized = ((Vector3)(ref val2)).normalized;
				Vector3 val3 = Vector3.Cross(normalized, Vector3.up);
				normalized = Quaternion.AngleAxis(Random.Range(0f - accuracy, accuracy), val3) * normalized;
				normalized = Quaternion.AngleAxis(Random.Range(0f - accuracy, accuracy), Vector3.up) * normalized;
				val.Setup(owner, normalized * velocity, -1f, (HitData)null, (ItemData)null, (ItemData)null);
				return val;
			}
			catch (Exception arg)
			{
				Debug.Log((object)$"SetupProjectile error: {arg}");
			}
			return null;
		}

		public static void SpawnCustomMeteor(string nameProjectile, Vector3 target, Vector3 offset, float velocity = 10f, float accuracy = 5f)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			//IL_0003: Unknown result type (might be due to invalid IL or missing references)
			//IL_0017: Unknown result type (might be due to invalid IL or missing references)
			GameObject gameObject = SpawnProjectile(target + offset, nameProjectile);
			Character localPlayer = (Character)(object)Player.m_localPlayer;
			SetupMeteorProjectile(SetupProjectilePhysics(localPlayer, gameObject, target, velocity, accuracy), localPlayer, new MeteorProjectileParameters
			{
				MinPhysicalDamage = 8f,
				MaxPhysicalDamage = 12f,
				MinElementalDamage = 8f,
				MaxElementalDamage = 12f,
				aoe = 5f
			});
		}

		public static Vector3 GetRandomVector(Vector3 randomRangeMin, Vector3 randomRangeMax)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			//IL_0013: Unknown result type (might be due to invalid IL or missing references)
			//IL_0019: Unknown result type (might be due to invalid IL or missing references)
			//IL_0025: Unknown result type (might be due to invalid IL or missing references)
			//IL_002b: Unknown result type (might be due to invalid IL or missing references)
			//IL_003a: Unknown result type (might be due to invalid IL or missing references)
			//IL_003f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0042: Unknown result type (might be due to invalid IL or missing references)
			float num = Random.Range(randomRangeMin.x, randomRangeMax.x);
			float num2 = Random.Range(randomRangeMin.y, randomRangeMax.y);
			float num3 = Random.Range(randomRangeMin.z, randomRangeMax.z);
			return new Vector3(num, num2, num3);
		}

		public static GameObject SpawnProjectile(Vector3 pos, string name)
		{
			//IL_004f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0050: Unknown result type (might be due to invalid IL or missing references)
			try
			{
				if ((Object)(object)ZNetScene.instance == (Object)null)
				{
					Debug.Log((object)"Znet is no more");
					return null;
				}
				GameObject prefab = ZNetScene.instance.GetPrefab(name);
				if ((Object)(object)prefab == (Object)null)
				{
					Debug.Log((object)("Failed to find prefab for  projectile " + name));
					return null;
				}
				return Object.Instantiate<GameObject>(prefab, pos, Quaternion.identity);
			}
			catch (Exception)
			{
				Debug.Log((object)"Failed to create projectile");
			}
			return null;
		}

		public static bool DefeatedEikthyr()
		{
			return ZoneSystem.instance.GetGlobalKey(KilledEikthyr);
		}

		public static bool DefeatedBonemass()
		{
			return ZoneSystem.instance.GetGlobalKey(KilledBonemass);
		}

		public static bool DefeatedYagluth()
		{
			return ZoneSystem.instance.GetGlobalKey(KilledYagluth);
		}

		public static bool DefeatedModer()
		{
			return ZoneSystem.instance.GetGlobalKey(KilledModer);
		}

		public static bool DefeatedElder()
		{
			return ZoneSystem.instance.GetGlobalKey(KilledElder);
		}

		public static bool DefeatedTroll()
		{
			return ZoneSystem.instance.GetGlobalKey(KilledTroll);
		}

		public static bool DefeatedSurling()
		{
			return ZoneSystem.instance.GetGlobalKey(KilledSurtling);
		}

		public static GameObject getPrefab(string name)
		{
			GameObject prefab = ZNetScene.instance.GetPrefab(name);
			if ((Object)(object)prefab == (Object)null)
			{
				Debug.Log((object)("Missing object " + name));
			}
			return prefab;
		}

		public static bool FindSpawnPoint(out Vector3 point, float spawnRadius, int tries = 10)
		{
			//IL_0013: Unknown result type (might be due to invalid IL or missing references)
			//IL_002e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0033: Unknown result type (might be due to invalid IL or missing references)
			//IL_0038: 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_0052: 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_00a5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00aa: Unknown result type (might be due to invalid IL or missing references)
			//IL_0067: Unknown result type (might be due to invalid IL or missing references)
			//IL_0087: Unknown result type (might be due to invalid IL or missing references)
			//IL_0088: Unknown result type (might be due to invalid IL or missing references)
			float num = default(float);
			for (int i = 0; i < tries; i++)
			{
				Vector3 val = ((Component)Player.m_localPlayer).transform.position + Quaternion.Euler(0f, (float)Random.Range(0, 360), 0f) * Vector3.forward * Random.Range(0f, spawnRadius);
				if (ZoneSystem.instance.FindFloor(val, ref num) && !ZoneSystem.instance.IsBlocked(val))
				{
					val.y = num + 0.1f;
					point = val;
					return true;
				}
			}
			point = Vector3.zero;
			return false;
		}

		public static T getField<T>(this Type obj, string field)
		{
			BindingFlags bindingAttr = BindingFlags.Instance | BindingFlags.NonPublic;
			try
			{
				return (T)obj.GetField(field, bindingAttr).GetValue(null);
			}
			catch (Exception ex)
			{
				Debug.Log((object)("Error17: " + ex));
			}
			return default(T);
		}

		public static T getFieldStatic<T>(this Type obj, string field)
		{
			BindingFlags bindingAttr = BindingFlags.Static | BindingFlags.NonPublic;
			try
			{
				return (T)obj.GetField(field, bindingAttr).GetValue(null);
			}
			catch (Exception ex)
			{
				Debug.Log((object)("Error16: " + ex));
			}
			return default(T);
		}

		public static void setField(this Type obj, string field, object value)
		{
			BindingFlags bindingAttr = BindingFlags.Instance | BindingFlags.NonPublic;
			try
			{
				obj.GetField(field, bindingAttr).SetValue(null, value);
			}
			catch (Exception ex)
			{
				Debug.Log((object)("Error15: " + ex));
			}
		}

		public static void setFieldStatic(this Type obj, string field, object value)
		{
			BindingFlags bindingAttr = BindingFlags.Static | BindingFlags.NonPublic;
			try
			{
				obj.GetField(field, bindingAttr).SetValue(null, value);
			}
			catch (Exception ex)
			{
				Debug.Log((object)("Error14: " + ex));
			}
		}

		public static T getField<T>(this object obj, string field, bool isStatic = false)
		{
			BindingFlags bindingAttr = ((!isStatic) ? (BindingFlags.Instance | BindingFlags.NonPublic) : (BindingFlags.Static | BindingFlags.NonPublic));
			try
			{
				return (T)obj.GetType().GetField(field, bindingAttr).GetValue(obj);
			}
			catch (Exception ex)
			{
				Debug.Log((object)("Error13: " + ex?.ToString() + " obj " + ((obj == null) ? "null" : obj.GetType().Name) + " method " + field));
			}
			return default(T);
		}

		public static object getField(this object obj, string field, bool isStatic = false)
		{
			BindingFlags bindingAttr = ((!isStatic) ? (BindingFlags.Instance | BindingFlags.NonPublic) : (BindingFlags.Static | BindingFlags.NonPublic));
			try
			{
				return obj.GetType().GetField(field, bindingAttr).GetValue(obj);
			}
			catch (Exception ex)
			{
				Debug.Log((object)("Error12: " + ex?.ToString() + " obj " + ((obj == null) ? "null" : obj.GetType().Name) + " method " + field));
			}
			return null;
		}

		public static T getFieldPublic<T>(this object obj, string field)
		{
			BindingFlags bindingAttr = BindingFlags.Instance | BindingFlags.Public;
			try
			{
				return (T)obj.GetType().GetField(field, bindingAttr).GetValue(obj);
			}
			catch (Exception ex)
			{
				Debug.Log((object)("Error2: " + ex?.ToString() + " obj " + ((obj == null) ? "null" : obj.GetType().Name) + " method " + field));
			}
			return default(T);
		}

		public static void setField(this object obj, string field, object value, bool isStatic = false)
		{
			BindingFlags bindingAttr = BindingFlags.Instance | BindingFlags.NonPublic;
			if (isStatic)
			{
				bindingAttr = BindingFlags.Static | BindingFlags.NonPublic;
			}
			try
			{
				obj.GetType().GetField(field, bindingAttr).SetValue(obj, value);
			}
			catch (Exception ex)
			{
				Debug.Log((object)("Error11: " + ex));
			}
		}

		public static object callMethod(this Type obj, string method, object[] pars)
		{
			BindingFlags bindingAttr = BindingFlags.Static | BindingFlags.NonPublic;
			try
			{
				return obj.GetMethod(method, bindingAttr).Invoke(null, pars);
			}
			catch (Exception ex)
			{
				Debug.Log((object)("Error: " + ex));
			}
			return null;
		}

		public static object callMethod(this object obj, string method, object[] pars = null)
		{
			BindingFlags bindingAttr = BindingFlags.Instance | BindingFlags.NonPublic;
			try
			{
				if (pars != null)
				{
					Type[] types = pars?.Select((object p) => p.GetType()).ToArray();
					return obj.GetType().GetMethod(method, bindingAttr, null, types, null)?.Invoke(obj, pars);
				}
				return obj.GetType().GetMethod(method, bindingAttr).Invoke(obj, pars);
			}
			catch (Exception ex)
			{
				try
				{
					if (pars != null)
					{
						Type[] types2 = pars?.Select((object p) => p.GetType()).ToArray();
						return obj.GetType().BaseType.GetMethod(method, bindingAttr, null, types2, null)?.Invoke(obj, pars);
					}
					return obj.GetType().BaseType.GetMethod(method, bindingAttr).Invoke(obj, pars);
				}
				catch (Exception)
				{
					try
					{
						if (pars != null)
						{
							Type[] types3 = pars?.Select((object p) => p.GetType()).ToArray();
							return obj.GetType().BaseType.BaseType.GetMethod(method, bindingAttr, null, types3, null)?.Invoke(obj, pars);
						}
						return obj.GetType().BaseType.BaseType.GetMethod(method, bindingAttr).Invoke(obj, pars);
					}
					catch (Exception)
					{
						Debug.Log((object)("Error4: " + ex?.ToString() + " obj " + ((obj == null) ? "null" : obj.GetType().Name) + " method " + method));
					}
				}
			}
			return null;
		}

		public static T callMethod<T>(this object obj, string method, object[] pars = null)
		{
			BindingFlags bindingAttr = BindingFlags.Instance | BindingFlags.NonPublic;
			try
			{
				return (T)(obj.GetType().GetMethod(method, bindingAttr)?.Invoke(obj, pars));
			}
			catch (Exception ex)
			{
				try
				{
					return (T)obj.GetType().BaseType.GetMethod(method, bindingAttr).Invoke(obj, pars);
				}
				catch (Exception)
				{
					try
					{
						return (T)obj.GetType().BaseType.BaseType.GetMethod(method, bindingAttr).Invoke(obj, pars);
					}
					catch (Exception)
					{
						Debug.Log((object)("Error5: " + ex?.ToString() + " obj " + ((obj == null) ? "null" : obj.GetType().Name) + " method " + method));
					}
				}
			}
			return default(T);
		}

		public static long GetMillis()
		{
			return DateTime.Now.Ticks / 10000;
		}

		public static T callMethodParams<T>(this object obj, string method, object[] pars)
		{
			BindingFlags bindingAttr = BindingFlags.Instance | BindingFlags.NonPublic;
			try
			{
				return (T)obj.GetType().GetMethod(method, bindingAttr).Invoke(obj, pars);
			}
			catch (Exception ex)
			{
				Debug.Log((object)("Error: " + ex));
			}
			return default(T);
		}

		public static void DoRay(Vector3 from, Vector3 to, float time = 10f, Color startColor = default(Color), Color endColor = default(Color))
		{
			//IL_0011: Unknown result type (might be due to invalid IL or missing references)
			//IL_0012: Unknown result type (might be due to invalid IL or missing references)
			//IL_002b: Unknown result type (might be due to invalid IL or missing references)
			//IL_002c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0045: Unknown result type (might be due to invalid IL or missing references)
			//IL_0046: Unknown result type (might be due to invalid IL or missing references)
			//IL_005f: 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_007b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0081: Expected O, but got Unknown
			//IL_0087: Unknown result type (might be due to invalid IL or missing references)
			//IL_0096: 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)
			//IL_00af: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b8: Unknown result type (might be due to invalid IL or missing references)
			string[] obj = new string[8] { "Doing ray from ", null, null, null, null, null, null, null };
			Vector3 val = from;
			obj[1] = ((object)(Vector3)(ref val)).ToString();
			obj[2] = " to ";
			val = to;
			obj[3] = ((object)(Vector3)(ref val)).ToString();
			obj[4] = " col ";
			Color val2 = startColor;
			obj[5] = ((object)(Color)(ref val2)).ToString();
			obj[6] = " end ";
			val2 = endColor;
			obj[7] = ((object)(Color)(ref val2)).ToString();
			Debug.Log((object)string.Concat(obj));
			GameObject val3 = new GameObject();
			val3.transform.position = from;
			LineRenderer val4 = val3.AddComponent<LineRenderer>();
			val4.startColor = startColor;
			val4.endColor = endColor;
			val4.SetPositions((Vector3[])(object)new Vector3[2] { from, to });
			val4.SetWidth(0.1f, 0.1f);
			Object.Destroy((Object)(object)val3, time);
		}

		public static GameObject GetPrefab(string prefabName)
		{
			foreach (GameObject prefab in ZNetScene.instance.m_prefabs)
			{
				if (((Object)prefab).name == prefabName)
				{
					return prefab;
				}
			}
			return null;
		}

		public static Vector3 RandomCircle(Vector3 center, float radius)
		{
			//IL_0010: Unknown result type (might be due to invalid IL or missing references)
			//IL_002c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0039: 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_0054: Unknown result type (might be due to invalid IL or missing references)
			//IL_0057: Unknown result type (might be due to invalid IL or missing references)
			float num = Random.Range(0, 360);
			Vector3 result = default(Vector3);
			result.x = center.x + radius * Mathf.Sin(num * ((float)Math.PI / 180f));
			result.y = center.y;
			result.z = center.z + radius * Mathf.Cos(num * ((float)Math.PI / 180f));
			return result;
		}

		public static Vector3 GetPlayerPos()
		{
			//IL_000b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0010: Unknown result type (might be due to invalid IL or missing references)
			//IL_0013: Unknown result type (might be due to invalid IL or missing references)
			return ((Component)Player.m_localPlayer).transform.position;
		}

		public static Vector3 GetRandomLocation()
		{
			//IL_0011: Unknown result type (might be due to invalid IL or missing references)
			//IL_0016: 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_004e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0052: Unknown result type (might be due to invalid IL or missing references)
			//IL_006e: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00eb: 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_00f2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fa: Unknown result type (might be due to invalid IL or missing references)
			//IL_0164: 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_0170: Unknown result type (might be due to invalid IL or missing references)
			//IL_0172: Unknown result type (might be due to invalid IL or missing references)
			//IL_0177: Unknown result type (might be due to invalid IL or missing references)
			//IL_0191: Unknown result type (might be due to invalid IL or missing references)
			//IL_0193: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a7: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ac: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b1: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b5: Unknown result type (might be due to invalid IL or missing references)
			//IL_012d: Unknown result type (might be due to invalid IL or missing references)
			Vector3 position = ((Component)Player.m_localPlayer).transform.position;
			Random r = new Random();
			List<Heightmap> list = new List<Heightmap>();
			List<string> list2 = new List<string>();
			foreach (LocationInstance value in ZoneSystem.instance.m_locationInstances.Values)
			{
				if (!list2.Contains(value.m_location.m_prefabName))
				{
					list2.Add(value.m_location.m_prefabName);
				}
			}
			list2.Remove("StartTemple");
			string text = list2.OrderBy((string k) => r.Next()).FirstOrDefault();
			List<LocationInstance> list3 = new List<LocationInstance>();
			foreach (LocationInstance value2 in ZoneSystem.instance.m_locationInstances.Values)
			{
				float num = Vector3.Distance(value2.m_position, position);
				if (value2.m_location.m_prefabName == text && num > 500f && num < 3500f)
				{
					list3.Add(value2);
				}
			}
			LocationInstance val = list3.OrderBy((LocationInstance k) => r.Next()).FirstOrDefault();
			Debug.Log((object)("Got random loc, dist " + Vector3.Distance(val.m_position, position)));
			return val.m_position + new Vector3(0f, 15f, 0f);
		}
	}
}
namespace Kush_Crafting_Stations
{
	[BepInPlugin("Kush.CraftingStations", "kushzei", "1.0.1")]
	public class KushCraftingStations : BaseUnityPlugin
	{
		[HarmonyPriority(301)]
		[HarmonyPatch(typeof(PieceManager), "RegisterInPieceTables")]
		public static class PieceManagerRegisterPiecfes
		{
			public static void Prefix()
			{
				Debug.Log((object)"RegisterInPieceTables JOTUNN");
			}
		}

		[HarmonyPriority(301)]
		[HarmonyPatch(typeof(ObjectDB), "Awake")]
		public static class Object_Awake_Path
		{
			private static bool IsObjectDBValid()
			{
				return (Object)(object)ObjectDB.instance != (Object)null && ObjectDB.instance.m_items.Count != 0 && ObjectDB.instance.m_recipes.Count != 0;
			}

			public static void Postfix()
			{
				if (IsObjectDBValid())
				{
					inst.CreateCraftingStations(Get().PrefabsToMakeIntoCraftingStation.Value);
				}
			}
		}

		[HarmonyPatch(typeof(SetData), "SetPieceRecipeData")]
		public static class SetDatarecipedata
		{
			public static void Postfix(PieceData data, ObjectDB Instant, GameObject[] AllObjects, bool cloneonly, SetData __instance)
			{
				GameObject prefab = Util.getPrefab(data.name);
				if (data.craftingStationData != null)
				{
				}
				if (data.cSExtensionData == null && (Object)(object)prefab != (Object)null && (Object)(object)prefab.GetComponent<StationExtension>() != (Object)null)
				{
					Object.Destroy((Object)(object)prefab.GetComponent<StationExtension>());
				}
				if (Object.op_Implicit((Object)(object)prefab) && (Object)(object)prefab.GetComponent<CraftingStation>() != (Object)null)
				{
					WMRecipeCust.NewCraftingStations.Add(prefab.GetComponent<CraftingStation>());
				}
			}
		}

		public const string creator = "kushzei";

		public const string version = "1.0.1";

		public const string guid = "Kush.CraftingStations";

		private Harmony _hi = null;

		private static KushCraftingStations inst;

		public ConfigEntry<string> PrefabsToMakeIntoCraftingStation { get; set; }

		public static KushCraftingStations Get()
		{
			return inst;
		}

		private KushCraftingStations()
		{
			//IL_0015: Unknown result type (might be due to invalid IL or missing references)
			//IL_001a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0023: Expected O, but got Unknown
			//IL_0049: Unknown result type (might be due to invalid IL or missing references)
			//IL_0053: Expected O, but got Unknown
			inst = this;
			ConfigurationManagerAttributes val = new ConfigurationManagerAttributes
			{
				IsAdminOnly = true
			};
			PrefabsToMakeIntoCraftingStation = ((BaseUnityPlugin)this).Config.Bind<string>("Server config", "PrefabsToMakeIntoCraftingStation", "cauldron_ext3_butchertable,cauldron_ext5_mortarandpestle,piece_workbench_ext2,piece_workbench_ext3,forge_ext2,forge_ext3,forge_ext4", new ConfigDescription("List of prefabs that will become new crafting benches", (AcceptableValueBase)null, new object[1] { val }));
			SynchronizationManager.OnConfigurationSynchronized += delegate
			{
				if ((Object)(object)ObjectDB.instance != (Object)null)
				{
					inst.CreateCraftingStations(Get().PrefabsToMakeIntoCraftingStation.Value);
				}
			};
		}

		public void Start()
		{
		}

		private void Awake()
		{
			Debug.Log((object)"Loading mod Kush.CraftingStations");
			_hi = Harmony.CreateAndPatchAll(Assembly.GetExecutingAssembly(), (string)null);
		}

		private void OnDestroy()
		{
			if (_hi != null)
			{
				_hi.UnpatchSelf();
			}
		}

		public void CreateCraftingStations(string prefabNames)
		{
			//IL_01a6: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ab: Unknown result type (might be due to invalid IL or missing references)
			//IL_01bd: Unknown result type (might be due to invalid IL or missing references)
			//IL_01cf: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e1: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ed: Unknown result type (might be due to invalid IL or missing references)
			//IL_020f: Expected O, but got Unknown
			//IL_020a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0211: Expected O, but got Unknown
			Debug.Log((object)("CreateCraftingStations " + prefabNames));
			List<string> list = (from prefab in prefabNames.Split(new char[1] { ',' })
				select prefab.Trim()).ToList();
			foreach (string item in list)
			{
				if ((Object)(object)Util.getPrefab(item + "_crafting") != (Object)null)
				{
					continue;
				}
				GameObject prefab2 = Util.GetPrefab(item);
				if ((Object)(object)prefab2 == (Object)null || (Object)(object)prefab2.GetComponent<Piece>() == (Object)null)
				{
					Debug.LogError((object)("Invalid prefab " + item + ". Cannot make it into crafting station!"));
					continue;
				}
				GameObject val = PrefabManager.Instance.CreateClonedPrefab(item + "_crafting", item);
				if ((Object)(object)val.GetComponent<CraftingStation>() == (Object)null)
				{
					CraftingStation val2 = val.AddComponent<CraftingStation>();
					val2.m_craftRequireFire = false;
					val2.m_craftRequireRoof = false;
					val2.m_showBasicRecipies = true;
					val2.m_name = item + "_crafting";
					Debug.Log((object)$"Added Craftingstation to {val}");
				}
				Piece component = val.GetComponent<Piece>();
				component.m_isUpgrade = false;
				component.m_noClipping = true;
				component.m_description = "$piece_craftingstation";
				if ((Object)(object)val.GetComponent<StationExtension>() != (Object)null)
				{
					Object.Destroy((Object)(object)val.GetComponent<StationExtension>());
					Debug.Log((object)("Removed StationExtension from " + ((Object)component).name));
				}
				PrefabManager.Instance.RegisterToZNetScene(val);
				CustomPiece val3 = new CustomPiece(val, true, new PieceConfig
				{
					Name = item + "_crafting",
					Description = prefab2.GetComponent<Piece>().m_description,
					Icon = prefab2.GetComponent<Piece>().m_icon,
					PieceTable = "Hammer",
					Category = ((object)(PieceCategory)(ref prefab2.GetComponent<Piece>().m_category)).ToString()
				});
				if (!PieceManager.Instance.AddPiece(val3))
				{
					Debug.LogError((object)("Failed to add piece " + item + "_crafting to list."));
				}
				PieceManager.Instance.callMethod("RegisterCustomPiece", new object[1] { val3 });
			}
		}

		public void OnGUI()
		{
		}
	}
}