Decompiled source of ServersideQoL SuperWishbone BETA v1.99.8

ServersideQoL.SuperWishbone.dll

Decompiled 13 hours ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Linq.Expressions;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Text;
using System.Text.RegularExpressions;
using BepInEx;
using BepInEx.Configuration;
using Microsoft.CodeAnalysis;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("ArgusMagnus")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyCopyright("ArgusMagnus")]
[assembly: AssemblyDescription("Introduces additional effects with increasing player skill levels")]
[assembly: AssemblyFileVersion("1.99.8.0")]
[assembly: AssemblyInformationalVersion("1.99.8-beta+328851184cc278c858ffbc70e717af9f9d7b6973")]
[assembly: AssemblyProduct("ServersideQoL.SuperWishbone")]
[assembly: AssemblyTitle("ServersideQoL.SuperWishbone")]
[assembly: AssemblyMetadata("RepositoryUrl", "https://github.com/ArgusMagnus/ValheimServersideQoL")]
[assembly: AssemblyVersion("1.99.8.0")]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[Embedded]
	[AttributeUsage(AttributeTargets.Class | AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Event | AttributeTargets.Parameter | AttributeTargets.ReturnValue | AttributeTargets.GenericParameter, AllowMultiple = false, Inherited = false)]
	internal sealed class NullableAttribute : Attribute
	{
		public readonly byte[] NullableFlags;

		public NullableAttribute(byte P_0)
		{
			NullableFlags = new byte[1] { P_0 };
		}

		public NullableAttribute(byte[] P_0)
		{
			NullableFlags = P_0;
		}
	}
	[CompilerGenerated]
	[Embedded]
	[AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Method | AttributeTargets.Interface | AttributeTargets.Delegate, AllowMultiple = false, Inherited = false)]
	internal sealed class NullableContextAttribute : Attribute
	{
		public readonly byte Flag;

		public NullableContextAttribute(byte P_0)
		{
			Flag = P_0;
		}
	}
	[CompilerGenerated]
	[Embedded]
	[AttributeUsage(AttributeTargets.Module, AllowMultiple = false, Inherited = false)]
	internal sealed class RefSafetyRulesAttribute : Attribute
	{
		public readonly int Version;

		public RefSafetyRulesAttribute(int P_0)
		{
			Version = P_0;
		}
	}
}
namespace ServersideQoL.SuperWishbone
{
	public sealed class Config : ConfigBase<Config>
	{
		private const string Section = "SuperWishbone";

		public override ConfigEntry<bool> Enabled { get; } = ConfigBase<Config>.BindEx<bool>(cfg, "SuperWishbone", true, "Enables/disables the entire mod", (AcceptableValueBase)null, (Deprecated<Config>)null, "Enabled");

		public ConfigEntry<bool> FindDungeons { get; } = ConfigBase<Config>.BindEx<bool>(cfg, "SuperWishbone", true, "True to make the wishbone find dungeons", (AcceptableValueBase)null, (Deprecated<Config>)null, "FindDungeons");

		public ConfigEntry<bool> FindVegvisir { get; } = ConfigBase<Config>.BindEx<bool>(cfg, "SuperWishbone", true, "True to make the wishbone find vegvisirs", (AcceptableValueBase)null, (Deprecated<Config>)null, "FindVegvisir");

		public ConfigEntry<string> FindLocationObjectRegex { get; } = ConfigBase<Config>.BindEx<string>(cfg, "SuperWishbone", "", "The wishbone will find locations which contain an object whose (prefab) name matches this regular expression.\r\nExample: Beehive|goblin_totempole|giant_brain|dvergrprops_crate\\w*", (AcceptableValueBase)null, (Deprecated<Config>)null, "FindLocationObjectRegex");

		public ConfigEntry<float> Range { get; } = ConfigBase<Config>.BindEx<float>(cfg, "SuperWishbone", Mathf.Max(Minimap.instance.m_exploreRadius, 64f), "Radius in which the wishbone will react to dungeons/locations", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0f, Mathf.Floor(128f * Mathf.Sqrt(2f))), (Deprecated<Config>)null, "Range");

		public Config(ConfigFile cfg, Logger logger)
			: base(cfg, logger)
		{
		}
	}
	[Processor("82b4ec36-75f1-4924-a202-2934d4144915")]
	public sealed class LocationProxyProcessor : Processor<LocationProxyProcessor.PrefabInfo>
	{
		public sealed record PrefabInfo(LocationProxy? LocationProxy, Beacon? Beacon) : ProcessorPrefabInfo()
		{
			public override bool IsValid
			{
				get
				{
					if (LocationProxy == null)
					{
						return ((ProcessorPrefabInfo)this).PrefabInfo.PrefabHash == BeaconPrefabHash;
					}
					return true;
				}
			}

			[CompilerGenerated]
			public override string ToString()
			{
				StringBuilder stringBuilder = new StringBuilder();
				stringBuilder.Append("PrefabInfo");
				stringBuilder.Append(" { ");
				if (((ProcessorPrefabInfo)this).PrintMembers(stringBuilder))
				{
					stringBuilder.Append(' ');
				}
				stringBuilder.Append('}');
				return stringBuilder.ToString();
			}

			[CompilerGenerated]
			protected override bool PrintMembers(StringBuilder builder)
			{
				if (((ProcessorPrefabInfo)this).PrintMembers(builder))
				{
					builder.Append(", ");
				}
				builder.Append("LocationProxy = ");
				builder.Append(LocationProxy);
				builder.Append(", Beacon = ");
				builder.Append(Beacon);
				return true;
			}

			[CompilerGenerated]
			public override int GetHashCode()
			{
				return (((ProcessorPrefabInfo)this).GetHashCode() * -1521134295 + EqualityComparer<LocationProxy>.Default.GetHashCode(LocationProxy)) * -1521134295 + EqualityComparer<Beacon>.Default.GetHashCode(Beacon);
			}

			[CompilerGenerated]
			public sealed override bool Equals(ProcessorPrefabInfo? other)
			{
				return ((object)this).Equals((object?)other);
			}

			[CompilerGenerated]
			public bool Equals(PrefabInfo? other)
			{
				if ((object)this != other)
				{
					if (((ProcessorPrefabInfo)this).Equals((ProcessorPrefabInfo)(object)other) && EqualityComparer<LocationProxy>.Default.Equals(LocationProxy, other.LocationProxy))
					{
						return EqualityComparer<Beacon>.Default.Equals(Beacon, other.Beacon);
					}
					return false;
				}
				return true;
			}

			[CompilerGenerated]
			private PrefabInfo(PrefabInfo original)
				: base((ProcessorPrefabInfo)(object)original)
			{
				LocationProxy = original.LocationProxy;
				Beacon = original.Beacon;
			}
		}

		private readonly Dictionary<ServersideQoLZDO, ServersideQoLZDO> _zdosByBeacon = new Dictionary<ServersideQoLZDO, ServersideQoLZDO>();

		private Regex? _regex;

		private static int __beaconFound = ServersideQoLPluginBase<SuperWishbonePlugin, Config>.RegisterServerVar("BeaconState");

		private static int BeaconPrefabHash => Prefabs.MountainRemainsBuried;

		protected override void Initialize()
		{
			_regex = null;
			string text = ConfigBase<Config>.Instance.FindLocationObjectRegex.Value.Trim();
			if (!string.IsNullOrEmpty(text))
			{
				try
				{
					_regex = new Regex(text);
				}
				catch (Exception arg)
				{
					((Processor)this).Logger.LogError((object)$"Invalid regex pattern: {text}{Environment.NewLine}    {arg}");
				}
			}
		}

		protected override ProcessResult Process(ServersideQoLZDO zdo, IReadOnlyList<Peer> peers, PrefabInfo prefabInfo)
		{
			//IL_00d5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00da: Unknown result type (might be due to invalid IL or missing references)
			//IL_014e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0153: Unknown result type (might be due to invalid IL or missing references)
			//IL_0161: Unknown result type (might be due to invalid IL or missing references)
			//IL_0166: Unknown result type (might be due to invalid IL or missing references)
			//IL_0174: Unknown result type (might be due to invalid IL or missing references)
			//IL_018a: Unknown result type (might be due to invalid IL or missing references)
			//IL_02e2: Unknown result type (might be due to invalid IL or missing references)
			//IL_02f5: Unknown result type (might be due to invalid IL or missing references)
			//IL_031c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0321: Unknown result type (might be due to invalid IL or missing references)
			//IL_0323: 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_0338: Unknown result type (might be due to invalid IL or missing references)
			if (_zdosByBeacon.TryGetValue(zdo, out ServersideQoLZDO value))
			{
				if (peers.Any((Peer x) => Utils.DistanceXZ(x.RefPos, zdo.ZDO.GetPosition()) < 2f))
				{
					((Processor)this).DestroyObject(zdo);
					_zdosByBeacon.Remove(zdo);
					SetBeaconFound(value, value: true);
				}
				return (ProcessResult)32;
			}
			if (prefabInfo.LocationProxy != null && !(ConfigBase<Config>.Instance.Range.Value <= 0f))
			{
				Config instance = ConfigBase<Config>.Instance;
				if (instance != null)
				{
					ConfigEntry<bool> findDungeons = instance.FindDungeons;
					if (findDungeons != null && !findDungeons.Value)
					{
						ConfigEntry<bool> findVegvisir = instance.FindVegvisir;
						if (findVegvisir != null && !findVegvisir.Value && _regex == null)
						{
							return (ProcessResult)2;
						}
					}
				}
				if (!GetBeaconFound(zdo))
				{
					ZDOVars vars = zdo.Vars;
					int location = ((ZDOVars)(ref vars)).GetLocation(0);
					if (location != 0)
					{
						if (PrivateAccessor.GetLocationsByHash(ZoneSystem.instance).TryGetValue(location, out var value2) && value2.m_prefab.IsValid)
						{
							if (!value2.m_prefab.IsLoaded)
							{
								if (!value2.m_prefab.IsLoading)
								{
									value2.m_prefab.LoadAsync();
								}
								return (ProcessResult)32;
							}
							GameObject asset = value2.m_prefab.Asset;
							Vector3 position = asset.gameObject.transform.position;
							Quaternion rotation = asset.gameObject.transform.rotation;
							asset.gameObject.transform.position = Vector3.zero;
							asset.gameObject.transform.rotation = Quaternion.identity;
							List<RandomSpawn> activeRandomSpawns = null;
							List<Vector3> positions = null;
							HashSet<GameObject> hashSet = null;
							if (ConfigBase<Config>.Instance.FindDungeons.Value)
							{
								Teleport[] componentsInChildren = asset.GetComponentsInChildren<Teleport>();
								foreach (Teleport val in componentsInChildren)
								{
									if ((hashSet ?? (hashSet = new HashSet<GameObject>())).Add(((Component)val).gameObject))
									{
										AddBeaconPosition(ref positions, (Component?)(object)val, ref activeRandomSpawns, asset, zdo);
									}
								}
							}
							if (ConfigBase<Config>.Instance.FindVegvisir.Value)
							{
								Vegvisir[] componentsInChildren2 = asset.GetComponentsInChildren<Vegvisir>();
								foreach (Vegvisir val2 in componentsInChildren2)
								{
									if ((hashSet ?? (hashSet = new HashSet<GameObject>())).Add(((Component)val2).gameObject))
									{
										AddBeaconPosition(ref positions, (Component?)(object)val2, ref activeRandomSpawns, asset, zdo);
									}
								}
							}
							if (_regex != null)
							{
								Component[] componentsInChildren3 = asset.GetComponentsInChildren<Component>();
								foreach (Component val3 in componentsInChildren3)
								{
									if ((hashSet ?? (hashSet = new HashSet<GameObject>())).Add(val3.gameObject) && _regex.IsMatch(Utils.GetPrefabName(val3.gameObject)))
									{
										AddBeaconPosition(ref positions, val3, ref activeRandomSpawns, asset, zdo);
									}
								}
							}
							asset.gameObject.transform.position = position;
							asset.gameObject.transform.rotation = rotation;
							if (positions != null && positions.Count > 0)
							{
								foreach (Vector3 item3 in positions)
								{
									Vector3 val4 = item3;
									val4.y -= 4f;
									ServersideQoLZDO val5 = ((Processor)this).PlaceObject(val4, BeaconPrefabHash, 0f, (CreatorMarkers)0, 0L);
									val5.Fields<Beacon>().Set((Func<Expression<Func<Beacon, float>>>)(() => (Beacon x) => x.m_range), ConfigBase<Config>.Instance.Range.Value, "C:\\repos\\Valheim.ServersideQoL\\ServersideQoL.SuperWishbone\\LocationProxyProcessor.cs", 115);
									_zdosByBeacon.Add(val5, zdo);
								}
								return (ProcessResult)2;
							}
							return (ProcessResult)2;
						}
						return (ProcessResult)2;
					}
					return (ProcessResult)0;
				}
				return (ProcessResult)2;
			}
			return (ProcessResult)2;
			static void AddBeaconPosition(ref List<Vector3>? reference, Component? component, ref List<RandomSpawn>? reference2, GameObject val7, ServersideQoLZDO val6)
			{
				//IL_0015: Unknown result type (might be due to invalid IL or missing references)
				//IL_0021: Unknown result type (might be due to invalid IL or missing references)
				//IL_0031: Unknown result type (might be due to invalid IL or missing references)
				//IL_0036: Unknown result type (might be due to invalid IL or missing references)
				//IL_003b: 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_006d: Unknown result type (might be due to invalid IL or missing references)
				//IL_0072: Unknown result type (might be due to invalid IL or missing references)
				//IL_0076: 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_0051: Unknown result type (might be due to invalid IL or missing references)
				//IL_0157: Unknown result type (might be due to invalid IL or missing references)
				//IL_0163: Unknown result type (might be due to invalid IL or missing references)
				//IL_0173: Unknown result type (might be due to invalid IL or missing references)
				//IL_0178: Unknown result type (might be due to invalid IL or missing references)
				//IL_017d: Unknown result type (might be due to invalid IL or missing references)
				//IL_0182: Unknown result type (might be due to invalid IL or missing references)
				//IL_0194: Unknown result type (might be due to invalid IL or missing references)
				//IL_00ab: Unknown result type (might be due to invalid IL or missing references)
				//IL_00b0: Unknown result type (might be due to invalid IL or missing references)
				//IL_00b9: Unknown result type (might be due to invalid IL or missing references)
				//IL_00c5: Unknown result type (might be due to invalid IL or missing references)
				//IL_00ca: Unknown result type (might be due to invalid IL or missing references)
				//IL_00cc: Unknown result type (might be due to invalid IL or missing references)
				//IL_00d1: Unknown result type (might be due to invalid IL or missing references)
				//IL_00d6: Unknown result type (might be due to invalid IL or missing references)
				//IL_00e1: Unknown result type (might be due to invalid IL or missing references)
				//IL_013f: Unknown result type (might be due to invalid IL or missing references)
				if (component != null)
				{
					RandomSpawn component2 = component.GetComponent<RandomSpawn>();
					if (component2 == null)
					{
						Vector3 item = val6.ZDO.GetPosition() + val6.ZDO.GetRotation() * component.gameObject.transform.position;
						(reference ?? (reference = new List<Vector3>())).Add(item);
					}
					else
					{
						if (reference2 == null)
						{
							reference2 = new List<RandomSpawn>();
							RandomSpawn[] enabledComponentsInChildren = Utils.GetEnabledComponentsInChildren<RandomSpawn>(val7);
							State state = Random.state;
							ZDOVars vars2 = val6.Vars;
							Random.InitState(((ZDOVars)(ref vars2)).GetSeed(0));
							Location val8 = null;
							RandomSpawn[] array = enabledComponentsInChildren;
							foreach (RandomSpawn val9 in array)
							{
								Vector3 position2 = ((Component)val9).gameObject.transform.position;
								position2 = val6.ZDO.GetPosition() + val6.ZDO.GetRotation() * position2;
								val9.Prepare();
								val9.Randomize(position2, val8 ?? (val8 = val7.GetComponent<Location>()), (DungeonGenerator)null);
								if (((Component)val9).gameObject.activeSelf)
								{
									reference2.Add(val9);
								}
								val9.Reset();
								ZNetView component3 = ((Component)val9).GetComponent<ZNetView>();
								if (component3 != null)
								{
									((Component)component3).gameObject.SetActive(true);
								}
							}
							Random.state = state;
						}
						if (reference2.Contains(component2))
						{
							Vector3 item2 = val6.ZDO.GetPosition() + val6.ZDO.GetRotation() * ((Component)component2).gameObject.transform.position;
							(reference ?? (reference = new List<Vector3>())).Add(item2);
						}
					}
				}
			}
		}

		private static bool GetBeaconFound(ServersideQoLZDO zdo, bool defaultValue = false)
		{
			return zdo.ZDO.GetBool(__beaconFound, defaultValue);
		}

		private static void SetBeaconFound(ServersideQoLZDO zdo, bool value)
		{
			zdo.ZDO.Set(__beaconFound, value);
		}
	}
	[BepInPlugin("ArgusMagnus.ServersideQoL.SuperWishbone", "ServersideQoL.SuperWishbone", "1.99.8")]
	public sealed class SuperWishbonePlugin : ServersideQoLPluginBase<SuperWishbonePlugin, Config>
	{
		public const string Author = "ArgusMagnus";

		public const string PluginName = "ServersideQoL.SuperWishbone";

		public const string PluginGuid = "ArgusMagnus.ServersideQoL.SuperWishbone";

		public const string PluginVersion = "1.99.8";

		public const string PluginInformationalVersion = "1.99.8-beta";

		private DateTimeOffset BuildTimestamp { get; } = new DateTimeOffset(639215507745084996L, default(TimeSpan));

		protected override Config CreateConfigSingleton(ConfigFile configFile, Logger logger)
		{
			return new Config(configFile, logger);
		}

		protected override void RegisterProcessors(IProcessorCollection processors)
		{
			processors.Add<LocationProxyProcessor>();
		}

		private void Awake()
		{
			ServersideQoLPluginBase<SuperWishbonePlugin, Config>.Logger.LogWarning((object)string.Format("You are running a pre-release version: {0} ({1})", "1.99.8-beta", BuildTimestamp.LocalDateTime));
		}
	}
}