Decompiled source of BiomeProgression v1.0.0

Cjayride.BiomeProgression.dll

Decompiled an hour ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: IgnoresAccessChecksTo("assembly_valheim")]
[assembly: TargetFramework(".NETFramework,Version=v4.8.1", FrameworkDisplayName = ".NET Framework 4.8.1")]
[assembly: AssemblyCompany("Cjayride.BiomeProgression")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("Cjayride.BiomeProgression")]
[assembly: AssemblyTitle("Cjayride.BiomeProgression")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
[module: UnverifiableCode]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[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 Cjayride.BiomeProgression
{
	internal static class HazardTick
	{
		private static float _nextTick;

		private static float _nextMessage;

		internal static void Tick()
		{
			//IL_0062: 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_006c: 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_0070: Invalid comparison between Unknown and I4
			//IL_00a9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ac: Invalid comparison between Unknown and I4
			if (!Settings.Enabled || (Object)(object)Player.m_localPlayer == (Object)null)
			{
				return;
			}
			float time = Time.time;
			if (time < _nextTick)
			{
				return;
			}
			float num = Settings.TickIntervalSeconds.Value;
			if (num < 0.5f)
			{
				num = 0.5f;
			}
			_nextTick = time + num;
			Player localPlayer = Player.m_localPlayer;
			if (!((Character)localPlayer).IsDead() && ((Character)localPlayer).IsOwner())
			{
				Biome val = Settings.BiomeAt(((Component)localPlayer).transform.position);
				if ((int)val == 64 && Settings.EnableDeepNorthFreeze.Value && !Settings.HasKey(localPlayer, Settings.DeepNorthKey.Value))
				{
					Apply(localPlayer, frost: true);
					MaybeMessage(localPlayer, Settings.DeepNorthTickMessage.Value, time);
				}
				else if ((int)val == 32 && Settings.EnableAshlandsBurn.Value && !Settings.HasKey(localPlayer, Settings.AshlandsKey.Value))
				{
					Apply(localPlayer, frost: false);
					MaybeMessage(localPlayer, Settings.AshlandsTickMessage.Value, time);
				}
			}
		}

		private static void MaybeMessage(Player player, string text, float now)
		{
			if (!(now < _nextMessage))
			{
				float num = Settings.MessageIntervalSeconds.Value;
				if (num < 2f)
				{
					num = 2f;
				}
				_nextMessage = now + num;
				Settings.CenterMessage(player, text);
			}
		}

		private static void Apply(Player player, bool frost)
		{
			//IL_0014: Unknown result type (might be due to invalid IL or missing references)
			//IL_001a: Expected O, but got Unknown
			//IL_001c: 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_0027: 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_0034: Unknown result type (might be due to invalid IL or missing references)
			float value = Settings.DamagePerTick.Value;
			if (!(value <= 0f))
			{
				HitData val = new HitData();
				val.m_point = ((Character)player).GetCenterPoint();
				val.m_dir = Vector3.up;
				val.m_hitType = (HitType)15;
				val.m_blockable = false;
				val.m_dodgeable = false;
				if (frost)
				{
					val.m_damage.m_frost = value;
				}
				else
				{
					val.m_damage.m_fire = value;
				}
				((Character)player).Damage(val);
			}
		}
	}
	[BepInPlugin("cjayride.BiomeProgression", "Biome Progression", "1.0.0")]
	public class Plugin : BaseUnityPlugin
	{
		public const string PluginGuid = "cjayride.BiomeProgression";

		public const string PluginName = "Biome Progression";

		public const string PluginVersion = "1.0.0";

		internal static ManualLogSource Log;

		private void Awake()
		{
			//IL_001b: Unknown result type (might be due to invalid IL or missing references)
			Log = ((BaseUnityPlugin)this).Logger;
			Settings.Bind(((BaseUnityPlugin)this).Config);
			new Harmony("cjayride.BiomeProgression").PatchAll();
			((BaseUnityPlugin)this).Logger.LogInfo((object)"Biome progression: personal boss keys gate Ashlands/Deep North ticks and portal destinations.");
		}

		private void Update()
		{
			HazardTick.Tick();
		}
	}
	[HarmonyPatch(typeof(TeleportWorld), "Teleport")]
	internal static class PortalGate
	{
		private unsafe static bool Prefix(TeleportWorld __instance, Player player)
		{
			//IL_0029: 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_0034: Unknown result type (might be due to invalid IL or missing references)
			if (!Settings.Enabled || !Settings.EnablePortalGates.Value || (Object)(object)player == (Object)null)
			{
				return true;
			}
			if (!__instance.TargetFound())
			{
				return true;
			}
			Biome biome = Settings.BiomeAt(Destination(__instance));
			if (!Settings.TryPortalKey(biome, out var key))
			{
				return true;
			}
			if (Settings.HasKey(player, key))
			{
				return true;
			}
			string text = Settings.PortalBlockedMessage.Value.Replace("{biome}", ((object)(*(Biome*)(&biome))/*cast due to .constrained prefix*/).ToString()).Replace("{key}", key);
			Settings.CenterMessage(player, text);
			return false;
		}

		private static Vector3 Destination(TeleportWorld portal)
		{
			//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_0016: Unknown result type (might be due to invalid IL or missing references)
			//IL_001b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0094: 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_0040: Unknown result type (might be due to invalid IL or missing references)
			//IL_0041: 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_0061: 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_0058: 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_0080: Unknown result type (might be due to invalid IL or missing references)
			//IL_0071: 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)
			try
			{
				ZNetView nview = portal.m_nview;
				if ((Object)(object)nview == (Object)null)
				{
					return ((Component)portal).transform.position;
				}
				ZDO zDO = nview.GetZDO();
				if (zDO == null)
				{
					return ((Component)portal).transform.position;
				}
				ZDOID connectionZDOID = zDO.GetConnectionZDOID((ConnectionType)1);
				if (connectionZDOID == ZDOID.None)
				{
					return ((Component)portal).transform.position;
				}
				ZDO zDO2 = ZDOMan.instance.GetZDO(connectionZDOID);
				if (zDO2 == null)
				{
					return ((Component)portal).transform.position;
				}
				return zDO2.GetPosition();
			}
			catch
			{
				return ((Component)portal).transform.position;
			}
		}
	}
	internal static class Settings
	{
		internal static ConfigEntry<bool> EnablePlugin;

		internal static ConfigEntry<bool> EnableDeepNorthFreeze;

		internal static ConfigEntry<string> DeepNorthKey;

		internal static ConfigEntry<bool> EnableAshlandsBurn;

		internal static ConfigEntry<string> AshlandsKey;

		internal static ConfigEntry<float> DamagePerTick;

		internal static ConfigEntry<float> TickIntervalSeconds;

		internal static ConfigEntry<float> MessageIntervalSeconds;

		internal static ConfigEntry<bool> EnablePortalGates;

		internal static ConfigEntry<string> PortalRequiredKeys;

		internal static ConfigEntry<string> DeepNorthTickMessage;

		internal static ConfigEntry<string> AshlandsTickMessage;

		internal static ConfigEntry<string> PortalBlockedMessage;

		private static Dictionary<Biome, string> _portalKeys;

		private static string _portalKeysRaw;

		internal static bool Enabled
		{
			get
			{
				if (EnablePlugin != null)
				{
					return EnablePlugin.Value;
				}
				return false;
			}
		}

		internal static void Bind(ConfigFile config)
		{
			//IL_00b8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c2: Expected O, but got Unknown
			//IL_00f0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fa: Expected O, but got Unknown
			//IL_0128: Unknown result type (might be due to invalid IL or missing references)
			//IL_0132: Expected O, but got Unknown
			EnablePlugin = config.Bind<bool>("General", "Enable", true, "Master switch. When false, ticks and portal gates are off.");
			EnableDeepNorthFreeze = config.Bind<bool>("Ticks", "Enable Deep North freeze", true, "Slow frost damage in Deep North until this player has the Deep North key (default Fader).");
			DeepNorthKey = config.Bind<string>("Ticks", "Deep North unique key", "defeated_fader", "Personal unique key (Player.HaveUniqueKey). Vanilla Fader is defeated_fader.");
			EnableAshlandsBurn = config.Bind<bool>("Ticks", "Enable Ashlands burn", true, "Slow fire damage in Ashlands until this player has the Ashlands key (default Moder).");
			AshlandsKey = config.Bind<string>("Ticks", "Ashlands unique key", "defeated_dragon", "Personal unique key. Vanilla Moder is defeated_dragon.");
			DamagePerTick = config.Bind<float>("Ticks", "Damage per tick", 8f, new ConfigDescription("Hit points of frost or fire per interval.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(1f, 200f), Array.Empty<object>()));
			TickIntervalSeconds = config.Bind<float>("Ticks", "Tick interval seconds", 2f, new ConfigDescription("Seconds between damage ticks.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0.5f, 30f), Array.Empty<object>()));
			MessageIntervalSeconds = config.Bind<float>("Ticks", "Message interval seconds", 10f, new ConfigDescription("Seconds between center messages while ticking.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(2f, 120f), Array.Empty<object>()));
			EnablePortalGates = config.Bind<bool>("Portals", "Enable portal gates", true, "Block inbound portal teleports into biomes this player has not unlocked.");
			PortalRequiredKeys = config.Bind<string>("Portals", "Required keys", "BlackForest:defeated_eikthyr,Swamp:defeated_gdking,Mountain:defeated_bonemass,Plains:defeated_dragon,Mistlands:defeated_goblinking,Ashlands:defeated_queen,DeepNorth:defeated_fader", "Comma list of Biome:uniqueKey. Destination biome is checked on the arriving player. Meadows needs no key.");
			DeepNorthTickMessage = config.Bind<string>("Messages", "Deep North tick", "The Deep North rejects you until Fader falls.", "Shown while freeze ticks apply.");
			AshlandsTickMessage = config.Bind<string>("Messages", "Ashlands tick", "Ashlands fire burns you until Moder falls.", "Shown while burn ticks apply.");
			PortalBlockedMessage = config.Bind<string>("Messages", "Portal blocked", "You cannot portal into {biome} until you have {key}.", "Placeholders: {biome} {key}.");
		}

		internal static bool TryPortalKey(Biome biome, out string key)
		{
			//IL_0003: Unknown result type (might be due to invalid IL or missing references)
			//IL_0005: Invalid comparison between Unknown and I4
			//IL_0007: 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)
			key = null;
			if ((int)biome == 1 || (int)biome == 0)
			{
				return false;
			}
			EnsurePortalMap();
			if (_portalKeys.TryGetValue(biome, out key))
			{
				return !string.IsNullOrWhiteSpace(key);
			}
			return false;
		}

		private static void EnsurePortalMap()
		{
			//IL_00b4: Unknown result type (might be due to invalid IL or missing references)
			string text = ((PortalRequiredKeys != null) ? PortalRequiredKeys.Value : "");
			if (_portalKeys != null && text == _portalKeysRaw)
			{
				return;
			}
			_portalKeysRaw = text;
			_portalKeys = new Dictionary<Biome, string>();
			if (string.IsNullOrWhiteSpace(text))
			{
				return;
			}
			string[] array = text.Split(new char[2] { ',', ';' }, StringSplitOptions.RemoveEmptyEntries);
			for (int i = 0; i < array.Length; i++)
			{
				string text2 = array[i].Trim();
				int num = text2.IndexOf(':');
				if (num > 0 && num < text2.Length - 1)
				{
					string name = text2.Substring(0, num).Trim();
					string value = text2.Substring(num + 1).Trim();
					if (TryParseBiome(name, out var biome))
					{
						_portalKeys[biome] = value;
					}
				}
			}
		}

		internal static bool TryParseBiome(string name, out Biome biome)
		{
			biome = (Biome)0;
			if (string.IsNullOrEmpty(name))
			{
				return false;
			}
			name = name.Replace(" ", "").Replace("_", "");
			if (name.Equals("DeepNorth", StringComparison.OrdinalIgnoreCase) || name.Equals("Deepnorth", StringComparison.OrdinalIgnoreCase))
			{
				biome = (Biome)64;
				return true;
			}
			if (name.Equals("Ashlands", StringComparison.OrdinalIgnoreCase) || name.Equals("AshLands", StringComparison.OrdinalIgnoreCase))
			{
				biome = (Biome)32;
				return true;
			}
			if (name.Equals("BlackForest", StringComparison.OrdinalIgnoreCase) || name.Equals("Forest", StringComparison.OrdinalIgnoreCase))
			{
				biome = (Biome)8;
				return true;
			}
			if (Enum.TryParse<Biome>(name, ignoreCase: true, out biome))
			{
				return (int)biome != 0;
			}
			return false;
		}

		internal static bool HasKey(Player player, string key)
		{
			if ((Object)(object)player == (Object)null || string.IsNullOrEmpty(key))
			{
				return true;
			}
			try
			{
				return ((Humanoid)player).HaveUniqueKey(key);
			}
			catch (Exception)
			{
				return false;
			}
		}

		internal static Biome BiomeAt(Vector3 pos)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0001: 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_000e: Unknown result type (might be due to invalid IL or missing references)
			try
			{
				return Heightmap.FindBiome(pos);
			}
			catch (Exception)
			{
			}
			return (Biome)0;
		}

		internal static void CenterMessage(Player player, string text)
		{
			if ((Object)(object)player == (Object)null || !((Character)player).IsOwner() || string.IsNullOrEmpty(text))
			{
				return;
			}
			try
			{
				((Character)player).Message((MessageType)2, text, 0, (Sprite)null, false);
			}
			catch (Exception)
			{
			}
		}
	}
}
namespace System.Runtime.CompilerServices
{
	[AttributeUsage(AttributeTargets.Assembly, AllowMultiple = true)]
	internal sealed class IgnoresAccessChecksToAttribute : Attribute
	{
		public IgnoresAccessChecksToAttribute(string assemblyName)
		{
		}
	}
}