Decompiled source of JotunnModStub v0.0.1

plugins\MistFinders.dll

Decompiled 3 months ago
using System;
using System.CodeDom.Compiler;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Diagnostics;
using System.Globalization;
using System.Reflection;
using System.Resources;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Configuration;
using Jotunn;
using Jotunn.Configs;
using Jotunn.Entities;
using Jotunn.Managers;
using Splatform;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: AssemblyTitle("MistFinders")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("MistFinders")]
[assembly: AssemblyCopyright("Copyright ©  2021")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("e3243d22-4307-4008-ba36-9f326008cde5")]
[assembly: AssemblyFileVersion("1.0.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
namespace MistFinders
{
	[BepInPlugin("sephalon.MistFinders", "MistFinders", "1.0.0")]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	internal class MistFinders : BaseUnityPlugin
	{
		internal class LocationQueryRPC : RPC
		{
			internal enum LocationType
			{
				Unknown,
				Mine,
				Skull
			}

			public void RequestLocations(string id1, string id2, Vector3 center)
			{
				//IL_000a: Unknown result type (might be due to invalid IL or missing references)
				//IL_0010: Expected O, but got Unknown
				//IL_001f: Unknown result type (might be due to invalid IL or missing references)
				Logger.LogInfo((object)"RequestLocations");
				ZPackage val = new ZPackage();
				val.Write(id1);
				val.Write(id2);
				val.Write(center);
				SendQuery(val);
			}

			public LocationType GetLocationTypeFromID(string id)
			{
				if (id.Equals("Mistlands_DvergrTownEntrance1"))
				{
					return LocationType.Mine;
				}
				if (id.Equals("Mistlands_DvergrTownEntrance2"))
				{
					return LocationType.Mine;
				}
				if (id.Equals("Mistlands_Excavation1"))
				{
					return LocationType.Skull;
				}
				if (id.Equals("Mistlands_Giant1"))
				{
					return LocationType.Skull;
				}
				return LocationType.Unknown;
			}

			public string GetMapStringForLocationType(LocationType locationType)
			{
				return locationType switch
				{
					LocationType.Mine => "Mine", 
					LocationType.Skull => "Skull", 
					_ => "?", 
				};
			}

			public override void ReceiveQuery(long sender, ZPackage package)
			{
				//IL_000f: Unknown result type (might be due to invalid IL or missing references)
				//IL_0014: Unknown result type (might be due to invalid IL or missing references)
				//IL_00eb: Unknown result type (might be due to invalid IL or missing references)
				//IL_00f0: 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_00f3: Unknown result type (might be due to invalid IL or missing references)
				//IL_00f5: Unknown result type (might be due to invalid IL or missing references)
				//IL_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_0129: Unknown result type (might be due to invalid IL or missing references)
				//IL_0130: Expected O, but got Unknown
				//IL_0153: Unknown result type (might be due to invalid IL or missing references)
				//IL_0158: 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)
				string text = package.ReadString();
				string text2 = package.ReadString();
				Vector3 val = package.ReadVector3();
				float num = -1f;
				if (GetLocationTypeFromID(text) == LocationType.Mine)
				{
					num = Instance.config_mineDetectionRadius.Value;
				}
				else if (GetLocationTypeFromID(text) == LocationType.Skull)
				{
					num = Instance.config_skullDetectionRadius.Value;
				}
				Logger.LogInfo((object)$"SendFinderPackage: {text}, {text2}, {((object)(Vector3)(ref val)).ToString()}, {num}");
				List<LocationInstance> list = new List<LocationInstance>();
				List<LocationInstance> collection = new List<LocationInstance>();
				ZoneSystem.instance.FindLocations(text, ref list);
				ZoneSystem.instance.FindLocations(text2, ref collection);
				list.AddRange(collection);
				Logger.LogInfo((object)$"total locations found: {list.Count}");
				List<Vector3> list2 = new List<Vector3>();
				foreach (LocationInstance item in list)
				{
					if (VectorExtensions.DistanceTo(val, item.m_position) <= num)
					{
						list2.Add(item.m_position);
					}
				}
				ZPackage val2 = new ZPackage();
				val2.Write(text);
				val2.Write(list2.Count);
				foreach (Vector3 item2 in list2)
				{
					val2.Write(item2);
				}
				SendResponse(val2);
			}

			public override void ReceiveResponse(long sender, ZPackage package)
			{
				//IL_0024: Unknown result type (might be due to invalid IL or missing references)
				//IL_0029: 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_006e: Unknown result type (might be due to invalid IL or missing references)
				//IL_0073: Unknown result type (might be due to invalid IL or missing references)
				//IL_007a: 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)
				//IL_008a: 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_00c4: 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)
				Logger.LogInfo((object)"ProcessFinderPackage");
				string text = package.ReadString();
				int num = package.ReadInt();
				List<Vector3> list = new List<Vector3>();
				for (int i = 0; i < num; i++)
				{
					Vector3 item = package.ReadVector3();
					list.Add(item);
				}
				Logger.LogInfo((object)$"Response: {text}, {num}");
				string mapStringForLocationType = GetMapStringForLocationType(GetLocationTypeFromID(text));
				foreach (Vector3 item2 in list)
				{
					Minimap.instance.AddPin(item2, (PinType)3, mapStringForLocationType, true, false, 0L, default(PlatformUserID));
				}
				InventoryGui.instance.Hide();
				Vector3 position = ((Component)Player.m_localPlayer).transform.position;
				Minimap.instance.ShowPointOnMap(position);
			}
		}

		public const string PluginGUID = "sephalon.MistFinders";

		public const string PluginName = "MistFinders";

		public const string PluginVersion = "1.0.0";

		public static MistFinders Instance;

		private ConfigEntry<int> config_mineDetectionRadius;

		private ConfigEntry<int> config_skullDetectionRadius;

		public LocationQueryRPC m_locRPC = new LocationQueryRPC();

		public void Awake()
		{
			//IL_0044: Unknown result type (might be due to invalid IL or missing references)
			//IL_004e: Expected O, but got Unknown
			//IL_0074: Unknown result type (might be due to invalid IL or missing references)
			//IL_007e: Expected O, but got Unknown
			Instance = this;
			PrefabManager.OnVanillaPrefabsAvailable += CreateCustomPrefabs;
			((BaseUnityPlugin)this).Config.SaveOnConfigSet = true;
			config_mineDetectionRadius = ((BaseUnityPlugin)this).Config.Bind<int>("Config", "MineDetectionRadius", 400, new ConfigDescription("Maximum distance from the player that a mine can be to be detected", (AcceptableValueBase)null, Array.Empty<object>()));
			config_skullDetectionRadius = ((BaseUnityPlugin)this).Config.Bind<int>("Config", "SkullDetectionRadius", 400, new ConfigDescription("Maximum distance from the player that a mine can be to be detected", (AcceptableValueBase)null, Array.Empty<object>()));
			m_locRPC.Register("LocationQuery");
		}

		public void CreateCustomPrefabs()
		{
			CreateMineFinder();
			CreateSkullFinder();
			PrefabManager.OnVanillaPrefabsAvailable -= CreateCustomPrefabs;
		}

		public void CreateMineFinder()
		{
			//IL_001c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0022: Expected O, but got Unknown
			//IL_006b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0082: Unknown result type (might be due to invalid IL or missing references)
			//IL_0088: Expected O, but got Unknown
			//IL_00bf: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c5: Expected O, but got Unknown
			SE_InfestedMineFinder sE_InfestedMineFinder = ScriptableObject.CreateInstance<SE_InfestedMineFinder>();
			((Object)sE_InfestedMineFinder).name = "InfestedMineFinderStatusEffect";
			((StatusEffect)sE_InfestedMineFinder).m_name = "$SE_InfestedMine";
			CustomStatusEffect val = new CustomStatusEffect((StatusEffect)(object)sE_InfestedMineFinder, false);
			ItemManager.Instance.AddStatusEffect(val);
			GameObject val2 = PrefabManager.Instance.CreateClonedPrefab("MineFinder", "StaminaUpgrade_Greydwarf");
			SharedData shared = val2.GetComponent<ItemDrop>().m_itemData.m_shared;
			shared.m_name = "Mine Finder";
			shared.m_description = "Eat this to release your inner Seeker and sniff out the nearby mines";
			shared.m_itemType = (ItemType)2;
			shared.m_consumeStatusEffect = val.StatusEffect;
			shared.m_questItem = false;
			ItemConfig val3 = new ItemConfig();
			val3.Apply(val2);
			val3.CraftingStation = CraftingStations.Cauldron;
			val3.MinStationLevel = 5;
			val3.AddRequirement("TrophySeeker", 1, 1);
			val3.AddRequirement("BugMeat", 10, 1);
			CustomItem val4 = new CustomItem(val2, false, val3);
			ItemManager.Instance.AddItem(val4);
		}

		public void CreateSkullFinder()
		{
			//IL_001c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0022: Expected O, but got Unknown
			//IL_006b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0082: Unknown result type (might be due to invalid IL or missing references)
			//IL_0088: Expected O, but got Unknown
			//IL_00be: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c4: Expected O, but got Unknown
			SE_SkullFinder sE_SkullFinder = ScriptableObject.CreateInstance<SE_SkullFinder>();
			((Object)sE_SkullFinder).name = "SkullFinderStatusEffect";
			((StatusEffect)sE_SkullFinder).m_name = "$SE_Skull";
			CustomStatusEffect val = new CustomStatusEffect((StatusEffect)(object)sE_SkullFinder, false);
			ItemManager.Instance.AddStatusEffect(val);
			GameObject val2 = PrefabManager.Instance.CreateClonedPrefab("SkullFinder", "HealthUpgrade_GDKing");
			SharedData shared = val2.GetComponent<ItemDrop>().m_itemData.m_shared;
			shared.m_name = "Skull Finder";
			shared.m_description = "Eat this chewy treat to sniff out the nearby Jotunn skulls";
			shared.m_itemType = (ItemType)2;
			shared.m_consumeStatusEffect = val.StatusEffect;
			shared.m_questItem = false;
			ItemConfig val3 = new ItemConfig();
			val3.Apply(val2);
			val3.CraftingStation = CraftingStations.Cauldron;
			val3.MinStationLevel = 5;
			val3.AddRequirement("Bilebag", 1, 1);
			val3.AddRequirement("GiantBloodSack", 5, 1);
			CustomItem val4 = new CustomItem(val2, false, val3);
			ItemManager.Instance.AddItem(val4);
		}

		public void AddPins(PinType pinType, string text, List<Vector3> locations)
		{
			//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_0016: 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)
			//IL_001f: 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)
			foreach (Vector3 location in locations)
			{
				Minimap.instance.AddPin(location, pinType, text, true, false, 0L, default(PlatformUserID));
			}
		}
	}
	internal abstract class RPC
	{
		[CompilerGenerated]
		private sealed class <QueryClientReceive>d__9 : IEnumerator<object>, IDisposable, IEnumerator
		{
			private int <>1__state;

			private object <>2__current;

			public RPC <>4__this;

			public long sender;

			public ZPackage package;

			object IEnumerator<object>.Current
			{
				[DebuggerHidden]
				get
				{
					return <>2__current;
				}
			}

			object IEnumerator.Current
			{
				[DebuggerHidden]
				get
				{
					return <>2__current;
				}
			}

			[DebuggerHidden]
			public <QueryClientReceive>d__9(int <>1__state)
			{
				this.<>1__state = <>1__state;
			}

			[DebuggerHidden]
			void IDisposable.Dispose()
			{
				<>1__state = -2;
			}

			private bool MoveNext()
			{
				int num = <>1__state;
				RPC rPC = <>4__this;
				switch (num)
				{
				default:
					return false;
				case 0:
					<>1__state = -1;
					rPC.ReceiveResponse(sender, package);
					<>2__current = null;
					<>1__state = 1;
					return true;
				case 1:
					<>1__state = -1;
					return false;
				}
			}

			bool IEnumerator.MoveNext()
			{
				//ILSpy generated this explicit interface implementation from .override directive in MoveNext
				return this.MoveNext();
			}

			[DebuggerHidden]
			void IEnumerator.Reset()
			{
				throw new NotSupportedException();
			}
		}

		[CompilerGenerated]
		private sealed class <QueryServerReceive>d__7 : IEnumerator<object>, IDisposable, IEnumerator
		{
			private int <>1__state;

			private object <>2__current;

			public RPC <>4__this;

			public long sender;

			public ZPackage package;

			object IEnumerator<object>.Current
			{
				[DebuggerHidden]
				get
				{
					return <>2__current;
				}
			}

			object IEnumerator.Current
			{
				[DebuggerHidden]
				get
				{
					return <>2__current;
				}
			}

			[DebuggerHidden]
			public <QueryServerReceive>d__7(int <>1__state)
			{
				this.<>1__state = <>1__state;
			}

			[DebuggerHidden]
			void IDisposable.Dispose()
			{
				<>1__state = -2;
			}

			private bool MoveNext()
			{
				int num = <>1__state;
				RPC rPC = <>4__this;
				switch (num)
				{
				default:
					return false;
				case 0:
					<>1__state = -1;
					rPC.ReceiveQuery(sender, package);
					<>2__current = null;
					<>1__state = 1;
					return true;
				case 1:
					<>1__state = -1;
					return false;
				}
			}

			bool IEnumerator.MoveNext()
			{
				//ILSpy generated this explicit interface implementation from .override directive in MoveNext
				return this.MoveNext();
			}

			[DebuggerHidden]
			void IEnumerator.Reset()
			{
				throw new NotSupportedException();
			}
		}

		private CustomRPC m_rpc;

		public RPC()
		{
			m_rpc = null;
		}

		public bool IsServer()
		{
			return ZNet.instance.IsServer();
		}

		public virtual void Register(string name)
		{
			//IL_0012: Unknown result type (might be due to invalid IL or missing references)
			//IL_001e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0028: Expected O, but got Unknown
			//IL_0028: Expected O, but got Unknown
			m_rpc = NetworkManager.Instance.AddRPC("name", new CoroutineHandler(QueryServerReceive), new CoroutineHandler(QueryClientReceive));
		}

		public abstract void ReceiveQuery(long sender, ZPackage package);

		public abstract void ReceiveResponse(long sender, ZPackage package);

		public void SendQuery(ZPackage package)
		{
			m_rpc.SendPackage(ZRoutedRpc.instance.GetServerPeerID(), package);
		}

		[IteratorStateMachine(typeof(<QueryServerReceive>d__7))]
		public IEnumerator QueryServerReceive(long sender, ZPackage package)
		{
			//yield-return decompiler failed: Unexpected instruction in Iterator.Dispose()
			return new <QueryServerReceive>d__7(0)
			{
				<>4__this = this,
				sender = sender,
				package = package
			};
		}

		public void SendResponse(ZPackage package)
		{
			//IL_0017: Unknown result type (might be due to invalid IL or missing references)
			//IL_001d: Expected O, but got Unknown
			if (ZNet.instance.m_peers.Count == 0)
			{
				ZPackage package2 = new ZPackage(package.GetArray());
				ReceiveResponse(ZRoutedRpc.instance.m_id, package2);
			}
			else
			{
				Logger.LogInfo((object)$"Sending response package to {ZNet.instance.m_peers.Count} peers...");
				m_rpc.SendPackage(ZNet.instance.m_peers, package);
			}
		}

		[IteratorStateMachine(typeof(<QueryClientReceive>d__9))]
		public IEnumerator QueryClientReceive(long sender, ZPackage package)
		{
			//yield-return decompiler failed: Unexpected instruction in Iterator.Dispose()
			return new <QueryClientReceive>d__9(0)
			{
				<>4__this = this,
				sender = sender,
				package = package
			};
		}
	}
	internal class SE_InfestedMineFinder : StatusEffect
	{
		private bool shouldRemove;

		public override void UpdateStatusEffect(float dt)
		{
			//IL_001b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0020: 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)
			Logger.LogInfo((object)"SE_InfestedMineFinder UpdateStatusEffect");
			((StatusEffect)this).UpdateStatusEffect(dt);
			Vector3 position = ((Component)Player.m_localPlayer).transform.position;
			MistFinders.Instance.m_locRPC.RequestLocations("Mistlands_DvergrTownEntrance1", "Mistlands_DvergrTownEntrance2", position);
			shouldRemove = true;
			((Character)Player.m_localPlayer).Message((MessageType)2, "You sniff out some mines...", 0, (Sprite)null);
		}

		public override bool IsDone()
		{
			Logger.LogInfo((object)"SE_InfestedMineFinder isDone");
			if (!shouldRemove)
			{
				return ((StatusEffect)this).IsDone();
			}
			return true;
		}
	}
	internal class SE_SkullFinder : StatusEffect
	{
		private bool shouldRemove;

		public override void UpdateStatusEffect(float dt)
		{
			//IL_001b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0020: 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)
			Logger.LogInfo((object)"SE_SkullFinder UpdateStatusEffect");
			((StatusEffect)this).UpdateStatusEffect(dt);
			Vector3 position = ((Component)Player.m_localPlayer).transform.position;
			MistFinders.Instance.m_locRPC.RequestLocations("Mistlands_Excavation1", "Mistlands_Giant1", position);
			shouldRemove = true;
			((Character)Player.m_localPlayer).Message((MessageType)2, "You sniff out some skulls...", 0, (Sprite)null);
		}

		public override bool IsDone()
		{
			Logger.LogInfo((object)"SE_SkullFinder isDone");
			if (!shouldRemove)
			{
				return ((StatusEffect)this).IsDone();
			}
			return true;
		}
	}
}
namespace MistFinders.Properties
{
	[GeneratedCode("System.Resources.Tools.StronglyTypedResourceBuilder", "17.0.0.0")]
	[DebuggerNonUserCode]
	[CompilerGenerated]
	internal class Resources
	{
		private static ResourceManager resourceMan;

		private static CultureInfo resourceCulture;

		[EditorBrowsable(EditorBrowsableState.Advanced)]
		internal static ResourceManager ResourceManager
		{
			get
			{
				if (resourceMan == null)
				{
					resourceMan = new ResourceManager("MistFinders.Properties.Resources", typeof(Resources).Assembly);
				}
				return resourceMan;
			}
		}

		[EditorBrowsable(EditorBrowsableState.Advanced)]
		internal static CultureInfo Culture
		{
			get
			{
				return resourceCulture;
			}
			set
			{
				resourceCulture = value;
			}
		}

		internal Resources()
		{
		}
	}
}