Decompiled source of SaturatedZygon v0.4.4

SaturatedZygon.dll

Decompiled 2 weeks ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Logging;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using Pigeon.Math;
using Pigeon.Movement;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("DBR")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("0.0.1.0")]
[assembly: AssemblyInformationalVersion("0.0.1+78230f56c7e0a365bda7fb5760867663be7c7c26")]
[assembly: AssemblyProduct("Saturated Zygon")]
[assembly: AssemblyTitle("SaturatedZygon")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("0.0.1.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 SaturatedZygon
{
	[MycoMod(/*Could not decode attribute arguments.*/)]
	[BepInPlugin("DBR.SaturatedZygon", "SaturatedZygon", "0.4.4")]
	public class ZygonPlugin : BaseUnityPlugin
	{
		[HarmonyPatch(typeof(Keywords), "LoadKeywords")]
		public static class KeywordsPatch
		{
			[HarmonyPostfix]
			public static void Postfix()
			{
				UpgradeHelper.RegisterKeyword("wane", "<color=#9370db>Waning</color> activates after <color=#ccffcc>saturation</color> or <color=#DC3132>frenzy</color> expires.\n\nDuring <color=#9370db>waning</color>, only <color=#ccffcc>saturation</color> buffs remain active and elements can stack Saturated Zygon and Zygon Frenzy again.");
			}
		}

		[HarmonyPatch(typeof(PhotonDisc), "OnUpgradesEnabled")]
		public static class OnUpgradesEnabledPatch
		{
			[HarmonyPostfix]
			private static void Postfix(PhotonDisc __instance)
			{
				//IL_005e: Unknown result type (might be due to invalid IL or missing references)
				//IL_0068: Expected O, but got Unknown
				//IL_006f: Unknown result type (might be due to invalid IL or missing references)
				//IL_0079: Expected O, but got Unknown
				//IL_008a: Unknown result type (might be due to invalid IL or missing references)
				//IL_0094: Expected O, but got Unknown
				//IL_00fe: Unknown result type (might be due to invalid IL or missing references)
				//IL_0108: Unknown result type (might be due to invalid IL or missing references)
				//IL_010d: Unknown result type (might be due to invalid IL or missing references)
				//IL_00bc: Unknown result type (might be due to invalid IL or missing references)
				//IL_00c6: Expected O, but got Unknown
				PluginUpgradeStats InstanceStats = ZygonUpgrade.GetStats(__instance);
				if (InstanceStats.saturationDuration > 0f || InstanceStats.frenzyDuration > 0f)
				{
					Player player = ((Throwable)__instance).Player;
					damageCallback = (MutableDamageCallback)delegate(ref DamageCallbackData data)
					{
						ModifyOutgoingDamageZygon(ref data, InstanceStats, __instance);
					};
					killCallback = (KillCallback)delegate(in KillCallbackData data)
					{
						//IL_0002: Unknown result type (might be due to invalid IL or missing references)
						TrackKillSaturationProgress(data, InstanceStats);
					};
					player.OnBeforeDamage = (MutableDamageCallback)Delegate.Combine((Delegate?)(object)player.OnBeforeDamage, (Delegate?)(object)damageCallback);
					if (InstanceStats.saturationDuration > 0f)
					{
						player.OnKillTarget = (KillCallback)Delegate.Combine((Delegate?)(object)player.OnKillTarget, (Delegate?)(object)killCallback);
					}
				}
				if (InstanceStats.frenzySpeed > 0f)
				{
					speedDelegate = delegate(ref float speed)
					{
						ModifyMoveSpeed(ref speed, InstanceStats);
					};
					Player player2 = ((Throwable)__instance).Player;
					player2.OnSetMovementSpeed += speedDelegate;
				}
			}
		}

		[HarmonyPatch(typeof(PhotonDisc), "OnUpgradesDisabled")]
		public static class OnUpgradesDisabledPatch
		{
			[HarmonyPostfix]
			private static void Postfix(PhotonDisc __instance)
			{
				//IL_0042: Unknown result type (might be due to invalid IL or missing references)
				//IL_004c: Expected O, but got Unknown
				//IL_005e: Unknown result type (might be due to invalid IL or missing references)
				//IL_0068: Expected O, but got Unknown
				//IL_0083: Unknown result type (might be due to invalid IL or missing references)
				//IL_008d: Unknown result type (might be due to invalid IL or missing references)
				//IL_0092: Unknown result type (might be due to invalid IL or missing references)
				PluginUpgradeStats stats = ZygonUpgrade.GetStats(__instance);
				if (stats.saturationDuration > 0f || stats.frenzyDuration > 0f)
				{
					Player player = ((Throwable)__instance).Player;
					player.OnBeforeDamage = (MutableDamageCallback)Delegate.Remove((Delegate?)(object)player.OnBeforeDamage, (Delegate?)(object)damageCallback);
					player.OnKillTarget = (KillCallback)Delegate.Remove((Delegate?)(object)player.OnKillTarget, (Delegate?)(object)killCallback);
				}
				if (stats.frenzySpeed > 0f)
				{
					Player player2 = ((Throwable)__instance).Player;
					player2.OnSetMovementSpeed -= speedDelegate;
				}
			}
		}

		[HarmonyPatch(typeof(PhotonDisc), "Update")]
		public static class UpdateProgress
		{
			[HarmonyPostfix]
			public static void Postfix(PhotonDisc __instance)
			{
				//IL_00fe: Unknown result type (might be due to invalid IL or missing references)
				//IL_0103: Unknown result type (might be due to invalid IL or missing references)
				//IL_04e3: Unknown result type (might be due to invalid IL or missing references)
				//IL_043b: Unknown result type (might be due to invalid IL or missing references)
				//IL_0489: Unknown result type (might be due to invalid IL or missing references)
				//IL_04b5: Unknown result type (might be due to invalid IL or missing references)
				//IL_021e: Unknown result type (might be due to invalid IL or missing references)
				//IL_0223: Unknown result type (might be due to invalid IL or missing references)
				//IL_016e: 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_02c2: Unknown result type (might be due to invalid IL or missing references)
				//IL_02e9: 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_01cf: Unknown result type (might be due to invalid IL or missing references)
				//IL_028e: Unknown result type (might be due to invalid IL or missing references)
				//IL_0293: Unknown result type (might be due to invalid IL or missing references)
				PluginUpgradeStats stats = ZygonUpgrade.GetStats(__instance);
				if ((stats.saturationDuration > 0f || stats.frenzyDuration > 0f) && (stats.buffTimer == -1f || stats.waningDuration <= 0f || stats.saturationType == SaturationType.Waning))
				{
					foreach (KeyValuePair<IDamageSource, Dictionary<EffectType, PluginUpgradeStats.EffectProgress>> item in stats.GunZygonProgress.ToList())
					{
						IDamageSource key = item.Key;
						Dictionary<EffectType, PluginUpgradeStats.EffectProgress> dictionary = ProcessGunEffects(stats, item);
						if (dictionary.Count == 0)
						{
							stats.GunZygonProgress.Remove(key);
						}
						else
						{
							if (dictionary.Count != 3 || !dictionary.Values.All((PluginUpgradeStats.EffectProgress effect) => effect.Progress >= 1f))
							{
								continue;
							}
							stats.buffDuration = -1f;
							string text = "";
							Color val = Color.white;
							if (stats.saturationDuration > 0f && stats.frenzyDuration > 0f)
							{
								if (key is PhotonDisc && stats.saturationType == SaturationType.Waning)
								{
									stats.buffDuration = stats.frenzyDuration;
									stats.prevType = stats.saturationType;
									stats.saturationType = SaturationType.Frenzied;
									text = "Zygon - Frenzy";
									val = Color.softRed;
								}
								else if (!(key is PhotonDisc) && (stats.saturationType == SaturationType.Waning || stats.buffTimer == -1f))
								{
									stats.buffDuration = stats.saturationDuration;
									stats.prevType = stats.saturationType;
									stats.saturationType = SaturationType.Full;
									text = "Zygon - Saturation";
									val = Color.green;
								}
							}
							else if (!(key is PhotonDisc) && stats.saturationDuration > 0f)
							{
								stats.buffDuration = stats.saturationDuration;
								stats.prevType = stats.saturationType;
								stats.saturationType = SaturationType.Full;
								text = "Zygon - Saturation";
								val = Color.green;
							}
							else if (stats.frenzyDuration > 0f && key is PhotonDisc && (stats.saturationType == SaturationType.Waning || stats.buffTimer == -1f))
							{
								stats.buffDuration = stats.frenzyDuration;
								stats.prevType = stats.saturationType;
								stats.saturationType = SaturationType.Frenzied;
								text = "Zygon - Frenzy";
								val = Color.softRed;
							}
							if (stats.buffDuration > 0f)
							{
								((Throwable)__instance).Player.UpdateStackDisplay((object)typeof(UpgradeProperty_SaturatedZygon), text, SaturatedIcon, val, 1, true, stats.buffDuration);
								((Throwable)__instance).Player.UpdateStackDisplay((object)typeof(UpgradeProperty_SaturatedZygon), text, SaturatedIcon, val, 1, false, 0f);
								stats.buffTimer = 0f;
							}
							stats.GunZygonProgress.Clear();
							break;
						}
					}
				}
				if (!(stats.buffTimer >= 0f))
				{
					return;
				}
				if (stats.saturationType == SaturationType.Waning && stats.buffTimer <= 0.3f)
				{
					Player.LocalPlayer.ShowScreenEffect((EffectType)4);
				}
				else if (stats.saturationType == SaturationType.Frenzied && stats.buffTimer <= 0.6f)
				{
					Player.LocalPlayer.ShowScreenEffect((EffectType)1);
				}
				else if (stats.saturationType == SaturationType.Full && stats.prevType != SaturationType.Full && stats.buffTimer <= 0.6f)
				{
					Player.LocalPlayer.ShowScreenEffect((EffectType)5);
				}
				stats.buffTimer += Time.deltaTime;
				if (IsExpired(stats))
				{
					if (stats.waningDuration > 0f && stats.saturationType != SaturationType.Waning)
					{
						GameManager.PlaySound(Ice_Shard_Sound, ((Throwable)__instance).Player.InterpolatedPosition);
						stats.buffDuration = stats.waningDuration;
						stats.prevType = stats.saturationType;
						stats.saturationType = SaturationType.Waning;
						stats.buffTimer = 0f;
						Player.LocalPlayer.UpdateStackDisplay((object)typeof(UpgradeProperty_SaturatedZygon), "Zygon - Wane", SaturatedIcon, Color.mediumPurple, 1, true, stats.buffDuration);
						Player.LocalPlayer.UpdateStackDisplay((object)typeof(UpgradeProperty_SaturatedZygon), "Zygon - Wane", SaturatedIcon, Color.mediumPurple, 1, false, 0f);
					}
					else
					{
						stats.buffTimer = -1f;
						stats.buffDuration = -1f;
						stats.zygonDiscEffect = (EffectType)1;
						stats.saturationType = SaturationType.None;
						stats.prevType = SaturationType.None;
					}
				}
			}
		}

		[HarmonyPatch(typeof(StatusEffect), "Add")]
		public static class TrackEffectApplication
		{
			[HarmonyPrefix]
			public static void Prefix(float amount, IDamageSource damageSource, StatusEffect __instance)
			{
				//IL_0073: Unknown result type (might be due to invalid IL or missing references)
				IGear throwableGear = Player.LocalPlayer.ThrowableGear;
				PhotonDisc val = (PhotonDisc)(object)((throwableGear is PhotonDisc) ? throwableGear : null);
				if (val != null && __instance.Saturation < 1f)
				{
					PluginUpgradeStats stats = ZygonUpgrade.GetStats(val);
					if (stats.saturationBoost > 0f || stats.frenzyBoost > 0f)
					{
						float num = 10f * (1f - __instance.Saturation);
						float effectAmount = Mathf.Min(amount, num);
						TrackSaturationProgress(stats, damageSource, __instance.Type, effectAmount);
					}
				}
			}
		}

		[HarmonyPatch(typeof(PhotonDisc), "ModifyBulletData")]
		public static class ModifyOutgoingDisc
		{
			[HarmonyPostfix]
			private static void Postfix(ref BulletData data, PhotonDisc __instance)
			{
				//IL_0040: 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_0048: 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_0051: 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_0085: Unknown result type (might be due to invalid IL or missing references)
				PluginUpgradeStats stats = ZygonUpgrade.GetStats(__instance);
				if (stats.buffTimer >= 0f)
				{
					if (stats.turboSaturation)
					{
						int num = ((stats.turboFrenzy && stats.saturationType == SaturationType.Frenzied) ? 4 : 3);
						stats.zygonDiscEffect = (EffectType)(sbyte)(stats.zygonDiscEffect % num + 1);
						data.damageEffect = stats.zygonDiscEffect;
					}
					else if (stats.turboFrenzy && stats.saturationType == SaturationType.Frenzied && Random.Range(0, 4) == 0)
					{
						data.damageEffect = (EffectType)4;
					}
				}
			}
		}

		public const string PLUGIN_GUID = "DBR.SaturatedZygon";

		public const string PLUGIN_NAME = "SaturatedZygon";

		public const string PLUGIN_VERSION = "0.4.4";

		internal static Sprite SaturatedIcon;

		internal static Sprite FrenzyIcon;

		internal static uint Ice_Shard_Sound;

		internal static readonly string gearApiName = "photondisc";

		internal static readonly int upgradeID = 19998500;

		internal static ManualLogSource Logger;

		public static MutableDamageCallback damageCallback;

		public static KillCallback killCallback;

		public static RefAction<float> speedDelegate;

		private void Awake()
		{
			//IL_0021: Unknown result type (might be due to invalid IL or missing references)
			//IL_0027: Expected O, but got Unknown
			Logger = ((BaseUnityPlugin)this).Logger;
			Logger.LogInfo((object)"Plugin DBR.SaturatedZygon is loaded");
			Harmony val = new Harmony("DBR.SaturatedZygon");
			try
			{
				val.PatchAll();
			}
			catch (Exception ex)
			{
				Logger.LogError((object)("Error applying patches: " + ex.Message));
			}
			SaturatedIcon = UpgradeHelper.LoadExternalIcon("saturatedzygon.png", (BaseUnityPlugin)(object)this);
			FrenzyIcon = UpgradeHelper.LoadExternalIcon("zygonfrenzy.png", (BaseUnityPlugin)(object)this);
			((MonoBehaviour)this).StartCoroutine(UpgradeHelper.LoadSoundAfterWwise("Play_Ice_Shard", delegate(uint id)
			{
				Ice_Shard_Sound = id;
			}));
			PlayerData.AddRegisterUpgradesCallback((Action)RegisterSaturatedZygon.RegisterUpgrade);
			PlayerData.AddRegisterUpgradesCallback((Action)RegisterZygonFrenzy.RegisterUpgrade);
		}

		private static void ModifyMoveSpeed(ref float speed, PluginUpgradeStats stats)
		{
			if (stats.frenzySpeed > 0f && stats.saturationType == SaturationType.Frenzied)
			{
				speed += stats.frenzySpeed;
			}
		}

		public static Dictionary<EffectType, PluginUpgradeStats.EffectProgress> ProcessGunEffects(PluginUpgradeStats stats, KeyValuePair<IDamageSource, Dictionary<EffectType, PluginUpgradeStats.EffectProgress>> gun)
		{
			//IL_0046: Unknown result type (might be due to invalid IL or missing references)
			Dictionary<EffectType, PluginUpgradeStats.EffectProgress> value = gun.Value;
			foreach (KeyValuePair<EffectType, PluginUpgradeStats.EffectProgress> item in value.ToList())
			{
				if (Time.time - item.Value.Time >= stats.maxStackTimer)
				{
					value.Remove(item.Key);
				}
			}
			return value;
		}

		public static void TrackSaturationProgress(PluginUpgradeStats InstanceStats, IDamageSource damageSource, EffectType effect, float effectAmount)
		{
			//IL_0079: 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_00c4: Unknown result type (might be due to invalid IL or missing references)
			if (InstanceStats.saturationDuration > 0f && InstanceStats.frenzyDuration > 0f)
			{
				if ((InstanceStats.buffTimer == -1f && !(damageSource is PhotonDisc)) || InstanceStats.saturationType == SaturationType.Waning)
				{
					AddSaturationProgress(effectAmount, effect, InstanceStats, damageSource);
				}
			}
			else if (InstanceStats.saturationDuration > 0f && !(damageSource is PhotonDisc))
			{
				AddSaturationProgress(effectAmount, effect, InstanceStats, damageSource);
			}
			else if (InstanceStats.frenzyDuration > 0f && damageSource is PhotonDisc && (InstanceStats.buffTimer == -1f || InstanceStats.saturationType == SaturationType.Waning))
			{
				AddSaturationProgress(effectAmount, effect, InstanceStats, damageSource);
			}
		}

		public static void TrackKillSaturationProgress(KillCallbackData data, PluginUpgradeStats InstanceStats)
		{
			//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_0030: 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_0037: Unknown result type (might be due to invalid IL or missing references)
			//IL_003c: Unknown result type (might be due to invalid IL or missing references)
			float num = data.damageData.effectAmount;
			if (InstanceStats.saturationDuration > 0f)
			{
				num *= 1f + InstanceStats.killReduction;
			}
			TrackSaturationProgress(InstanceStats, data.source, data.damageData.effect, num);
		}

		public static void AddSaturationProgress(float effectAmount, EffectType effect, PluginUpgradeStats InstanceStats, IDamageSource damageSource)
		{
			//IL_0009: Unknown result type (might be due to invalid IL or missing references)
			//IL_000b: Invalid comparison between Unknown and I4
			//IL_000d: Unknown result type (might be due to invalid IL or missing references)
			//IL_000f: Invalid comparison between Unknown and I4
			//IL_004d: 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)
			float num = effectAmount * 0.1f;
			if ((int)effect > 0 && (int)effect <= 3)
			{
				if (!InstanceStats.GunZygonProgress.TryGetValue(damageSource, out var value))
				{
					value = new Dictionary<EffectType, PluginUpgradeStats.EffectProgress>();
					InstanceStats.GunZygonProgress[damageSource] = value;
				}
				if (!value.TryGetValue(effect, out var value2))
				{
					value2.Time = Time.time;
					value2.Progress = Math.Clamp(num, 0f, 1f);
				}
				else if (value2.Progress >= 2f)
				{
					value2.Time = Time.time;
					value2.Progress = 1f;
				}
				else
				{
					value2.Progress += num;
				}
				value[effect] = value2;
			}
		}

		private static void ModifyOutgoingDamageZygon(ref DamageCallbackData data, PluginUpgradeStats stats, PhotonDisc disc)
		{
			//IL_001c: 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)
			if (stats.buffTimer >= 0f && data.damageData.effect != disc.GrenadeData.attunedElement)
			{
				data.damageData.damage *= GetDamageModifier(stats);
			}
		}

		public static float GetDamageModifier(PluginUpgradeStats stats)
		{
			float num = 1f;
			if (stats.saturationDuration > 0f)
			{
				num += stats.saturationBoost;
			}
			if (stats.frenzyDuration > 0f && stats.saturationType == SaturationType.Frenzied)
			{
				num += stats.frenzyBoost;
			}
			return num;
		}

		public static bool IsExpired(PluginUpgradeStats stats)
		{
			if (stats.buffDuration == -1f)
			{
				Logger.LogError((object)"Expired check ran while buff duration was not set. \nbuffTimer should never be set without buffDuration");
			}
			return stats.buffTimer >= stats.buffDuration;
		}
	}
	internal static class RegisterSaturatedZygon
	{
		private static bool _registered;

		private static readonly string upgradeName = "Saturated Zygon";

		private static readonly string upgradeDescription = "Apply 10 stacks of <color=#ff6f2a>fire</color>, <color=#6be6ff>shock</color> and <color=#a8ff2e>acid</color> from a single non-disc weapon within 10 seconds to trigger <color=#ccffcc>saturation</color>, increasing <color=#c1ae8a>unattuned</color> damage. Killing with element damage adds reduced stacks.\n\nWhile Zygon Frenzy is equipped, elements no longer stack Saturated Zygon while <color=#ccffcc>saturation</color> or <color=#DC3132>frenzy</color> is active. Buffs also remain active during <color=#DC3132>frenzy</color>.";

		internal static void RegisterUpgrade()
		{
			if (_registered)
			{
				return;
			}
			ManualLogSource logger = ZygonPlugin.Logger;
			int num = ZygonPlugin.upgradeID + 1;
			try
			{
				if (UpgradeHelper.TryCreateGunUpgrade("DBR.SaturatedZygon", ZygonPlugin.gearApiName, num, upgradeName, upgradeDescription, (Rarity)3, (UpgradeProperty[])(object)new UpgradeProperty[1]
				{
					new UpgradeProperty_SaturatedZygon()
				}, CreatePattern(), (UpgradeFlags)73728, ZygonPlugin.SaturatedIcon, ZygonPlugin.Logger, out var _, 0, (CollectionSource)0))
				{
					_registered = true;
					logger.LogInfo((object)("Registered " + upgradeName + " on gear " + ZygonPlugin.gearApiName + " " + $"(id={num})."));
				}
			}
			catch (Exception arg)
			{
				logger.LogError((object)$"Upgrade Registration failed: {arg}");
			}
		}

		public static HexMap CreatePattern()
		{
			//IL_0003: Unknown result type (might be due to invalid IL or missing references)
			//IL_0009: Expected O, but got Unknown
			//IL_0020: Unknown result type (might be due to invalid IL or missing references)
			//IL_003d: Unknown result type (might be due to invalid IL or missing references)
			//IL_005a: 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)
			HexMap val = new HexMap(2, 4);
			val[1, 0].enabled = true;
			val[1, 0].connections = (Direction)8;
			val[1, 1].enabled = true;
			val[1, 1].connections = (Direction)24;
			val[1, 2].enabled = true;
			val[1, 2].connections = (Direction)16;
			val[0, 3].enabled = true;
			val[0, 3].connections = (Direction)1;
			val[0, 2].enabled = true;
			return val;
		}
	}
	internal static class RegisterZygonFrenzy
	{
		private static bool _registered;

		private static readonly string upgradeName = "Zygon Frenzy";

		private static readonly string upgradeDescription = "Apply 10 stacks of <color=#ff6f2a>fire</color>, <color=#6be6ff>shock</color> and <color=#a8ff2e>acid</color> with discs within 10 seconds to trigger <color=#DC3132>frenzy</color>, increasing <color=#c1ae8a>unattuned</color> damage. <color=#DC3132>Frenzy</color> cannot retrigger while a Zygon buff is active unless <link=wane><color=#9370db>waning</color></link>.\n\nWhile Saturated Zygon is equipped, discs no longer stack Zygon Frenzy outside of <color=#9370db>waning</color> and it now gains stacks from kills with element damage.";

		internal static void RegisterUpgrade()
		{
			if (_registered)
			{
				return;
			}
			ManualLogSource logger = ZygonPlugin.Logger;
			int num = ZygonPlugin.upgradeID + 2;
			try
			{
				if (UpgradeHelper.TryCreateGunUpgrade("DBR.SaturatedZygon", ZygonPlugin.gearApiName, num, upgradeName, upgradeDescription, (Rarity)3, (UpgradeProperty[])(object)new UpgradeProperty[1]
				{
					new UpgradeProperty_ZygonFrenzy()
				}, CreatePattern(), (UpgradeFlags)73728, ZygonPlugin.FrenzyIcon, ZygonPlugin.Logger, out var _, 0, (CollectionSource)0))
				{
					_registered = true;
					logger.LogInfo((object)("Registered " + upgradeName + " on gear " + ZygonPlugin.gearApiName + " " + $"(id={num})."));
				}
			}
			catch (Exception arg)
			{
				logger.LogError((object)$"Upgrade Registration failed: {arg}");
			}
		}

		public static HexMap CreatePattern()
		{
			//IL_0003: Unknown result type (might be due to invalid IL or missing references)
			//IL_0009: Expected O, but got Unknown
			//IL_0020: Unknown result type (might be due to invalid IL or missing references)
			//IL_003c: 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_0074: Unknown result type (might be due to invalid IL or missing references)
			HexMap val = new HexMap(3, 3);
			val[0, 2].enabled = true;
			val[0, 2].connections = (Direction)1;
			val[0, 1].enabled = true;
			val[0, 1].connections = (Direction)2;
			val[1, 0].enabled = true;
			val[1, 0].connections = (Direction)4;
			val[2, 1].enabled = true;
			val[2, 1].connections = (Direction)8;
			val[2, 2].enabled = true;
			return val;
		}
	}
	public enum SaturationType
	{
		None,
		Full,
		Frenzied,
		Waning
	}
	public static class ZygonUpgrade
	{
		private static readonly ConditionalWeakTable<PhotonDisc, PluginUpgradeStats> upgradeStats = new ConditionalWeakTable<PhotonDisc, PluginUpgradeStats>();

		public static PluginUpgradeStats GetStats(PhotonDisc disc)
		{
			return upgradeStats.GetOrCreateValue(disc);
		}

		public static void ResetPluginStats(PhotonDisc disc)
		{
			upgradeStats.Remove(disc);
		}
	}
	public class PluginUpgradeStats
	{
		public struct EffectProgress
		{
			public float Time;

			public float Progress;
		}

		public SaturationType saturationType = SaturationType.None;

		public SaturationType prevType = SaturationType.None;

		public float maxStackTimer = 10f;

		public float buffDuration = -1f;

		public bool turboSaturation = false;

		public bool turboFrenzy = false;

		public float killReduction;

		public float saturationDuration;

		public float frenzyDuration;

		public float waningDuration;

		public float saturationBoost;

		public float frenzyBoost;

		public float frenzySpeed;

		public float buffTimer = -1f;

		public const float vignetteDuration = 0.3f;

		public readonly Dictionary<IDamageSource, Dictionary<EffectType, EffectProgress>> GunZygonProgress = new Dictionary<IDamageSource, Dictionary<EffectType, EffectProgress>>();

		public EffectType zygonDiscEffect = (EffectType)1;

		public override string ToString()
		{
			//IL_0127: Unknown result type (might be due to invalid IL or missing references)
			string text = string.Join(", ", GunZygonProgress.Select((KeyValuePair<IDamageSource, Dictionary<EffectType, EffectProgress>> source) => string.Format("[{0}: {1}]", source.Key, string.Join(", ", source.Value.Select((KeyValuePair<EffectType, EffectProgress> effect) => $"{effect.Key} (Time={effect.Value.Time:F2}, Progress={effect.Value.Progress:P1})")))));
			return "PluginUpgradeStats {\n" + $"  SaturationType: {saturationType},\n" + $"  FullSaturationTimer: {maxStackTimer:F2},\n" + $"  BuffDuration: {buffDuration:F2},\n" + $"  SaturationDuration: {saturationDuration:F2},\n" + $"  FrenzyDuration: {frenzyDuration:F2},\n" + $"  WaningDuration: {waningDuration:F2},\n" + $"  SaturationBoost: {saturationBoost:F2},\n" + $"  FrenzyBoost: {frenzyBoost:F2},\n" + $"  BuffTimer: {buffTimer:F2},\n" + $"  ZygonDiscEffect: {zygonDiscEffect},\n" + "  GunZygonProgress: { " + text + " }\n}";
		}
	}
	internal static class UpgradeHelper
	{
		internal static void RegisterKeyword(string key, string description)
		{
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			//IL_0008: Expected O, but got Unknown
			//IL_0017: Unknown result type (might be due to invalid IL or missing references)
			//IL_001d: Expected O, but got Unknown
			//IL_0021: Unknown result type (might be due to invalid IL or missing references)
			//IL_0027: Expected O, but got Unknown
			//IL_0061: Unknown result type (might be due to invalid IL or missing references)
			//IL_0068: Expected O, but got Unknown
			//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)
			TextBlockGroup val = new TextBlockGroup(-1);
			val.blocks = (TextBlock[])(object)new TextBlock[2]
			{
				new TextBlock("", key),
				new TextBlock(description, key)
			};
			TextBlockGroup value = val;
			TextBlocks.strings[key] = value;
			FieldInfo field = typeof(Keywords).GetField("keywords", BindingFlags.Static | BindingFlags.NonPublic);
			Dictionary<string, Keyword> dictionary = (Dictionary<string, Keyword>)field.GetValue(null);
			Keyword val2 = new Keyword();
			val2.keys = new string[1] { key };
			val2.color = Color.white;
			val2.colorHex = "#FFFFFF";
			val2.descriptionID = key;
			dictionary[key] = val2;
		}

		internal static IEnumerator LoadSoundAfterWwise(string stringID, Action<uint> onLoaded)
		{
			while (!AkUnitySoundEngine.IsInitialized())
			{
				yield return null;
			}
			uint soundID = AkUnitySoundEngine.GetIDFromString(stringID);
			ZygonPlugin.Logger.LogInfo((object)$"Sound Loaded: {soundID}");
			onLoaded?.Invoke(soundID);
		}

		internal static Sprite LoadExternalIcon(string iconName, BaseUnityPlugin pluginInstance)
		{
			//IL_0035: Unknown result type (might be due to invalid IL or missing references)
			//IL_003c: Expected O, but got Unknown
			//IL_0061: 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)
			string path = Path.Combine(Path.GetDirectoryName(pluginInstance.Info.Location), iconName);
			if (!File.Exists(path))
			{
				return null;
			}
			try
			{
				byte[] array = File.ReadAllBytes(path);
				Texture2D val = new Texture2D(2, 2);
				ImageConversion.LoadImage(val, array);
				return Sprite.Create(val, new Rect(0f, 0f, (float)((Texture)val).width, (float)((Texture)val).height), new Vector2(0.5f, 0.5f));
			}
			catch (Exception ex)
			{
				ZygonPlugin.Logger.LogError((object)("Icon Load Failed: " + ex.Message));
				return null;
			}
		}

		public static bool TryCreateGunUpgrade(string modGuid, string gearApiName, int upgradeId, string name, string description, Rarity rarity, UpgradeProperty[] properties, HexMap pattern, UpgradeFlags flags, Sprite icon, ManualLogSource log, out Upgrade upgrade, int priority = 0, CollectionSource collectionSource = (CollectionSource)0)
		{
			//IL_00c3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c7: 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_00cf: 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_00e1: 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_00eb: Unknown result type (might be due to invalid IL or missing references)
			//IL_0111: Unknown result type (might be due to invalid IL or missing references)
			upgrade = null;
			if (string.IsNullOrEmpty(modGuid))
			{
				if (log != null)
				{
					log.LogError((object)"[UpgradeRegistration] modGuid is null/empty.");
				}
				return false;
			}
			if (properties == null || properties.Length == 0)
			{
				if (log != null)
				{
					log.LogError((object)"[UpgradeRegistration] properties array is null/empty.");
				}
				return false;
			}
			IUpgradable val = PlayerData.FindGear(gearApiName);
			if (val == null)
			{
				if (log != null)
				{
					log.LogError((object)("[UpgradeRegistration] FindGear(\"" + gearApiName + "\") returned null. Is the API name correct?"));
				}
				return false;
			}
			if (val is Character && log != null)
			{
				log.LogWarning((object)("[UpgradeRegistration] Gear '" + gearApiName + "' is a Character. CreateUpgrade will build a GenericPlayerUpgrade — ensure your properties use Apply(Player, ...)."));
			}
			CustomUpgradeParams val2 = CustomUpgradeParams.Create(val, upgradeId, name, description, rarity, icon);
			val2.flags = flags;
			val2.priority = priority;
			val2.collectionSource = collectionSource;
			val2.upgradeType = (Type)3;
			val2.useDefaultUnlockCost = true;
			if (pattern != null)
			{
				val2.pattern = pattern;
			}
			try
			{
				upgrade = PlayerData.CreateUpgrade(modGuid, val2, properties);
			}
			catch (Exception arg)
			{
				if (log != null)
				{
					log.LogError((object)$"[UpgradeRegistration] CreateUpgrade threw: {arg}");
				}
				upgrade = null;
				return false;
			}
			if ((Object)(object)upgrade == (Object)null)
			{
				if (log != null)
				{
					log.LogError((object)"[UpgradeRegistration] CreateUpgrade returned null.");
				}
				return false;
			}
			if (pattern != null)
			{
				upgrade.SetPattern(pattern);
			}
			return true;
		}
	}
	public class UpgradeProperty_SaturatedZygon : UpgradeProperty
	{
		public Range<float> saturationDurationRange = new Range<float>(8f, 10f);

		public Range<float> killReduction = new Range<float>(-0.8f, -0.75f);

		public Range<float> saturationBoostRange = new Range<float>(0.2f, 0.25f);

		public float turboSaturation = -2f;

		public override IEnumerator<StatData> GetStatData(Random rand, IUpgradable gear, UpgradeInstance upgrade)
		{
			//IL_000e: Unknown result type (might be due to invalid IL or missing references)
			//IL_000f: Unknown result type (might be due to invalid IL or missing references)
			float saturationDurationRatio = default(float);
			Range<float> saturationDuration = UpgradeProperty.ModifyAdditiveRangeFromPatternSize(saturationDurationRange, upgrade, ref saturationDurationRatio, false);
			StatData val = StatData.Create("Saturation Duration", saturationDuration, upgrade, ref rand, (OverrideType)1, (LabelType)1, default(BoostParams), (Range<float>?)null);
			yield return ((StatData)(ref val)).WithPatternRatio(saturationDurationRatio, false);
			float saturationBoostRatio = default(float);
			Range<float> saturationBoost = UpgradeProperty.ModifyAdditiveRangeFromPatternSize(saturationBoostRange, upgrade, ref saturationBoostRatio, false);
			val = StatData.Create("Saturation Damage", saturationBoost + 1f, upgrade, ref rand, (OverrideType)2, (LabelType)1, default(BoostParams), (Range<float>?)null);
			yield return ((StatData)(ref val)).WithPatternRatio(saturationBoostRatio, false);
			float killReductionRatio = default(float);
			Range<float> killProgress = UpgradeProperty.ModifyAdditiveRangeFromPatternSize(killReduction, upgrade, ref killReductionRatio, true);
			val = StatData.Create("Stacks on Kill", killProgress + 1f, upgrade, ref rand, (OverrideType)2, (LabelType)1, default(BoostParams), (Range<float>?)null);
			yield return ((StatData)(ref val)).WithPatternRatio(killReductionRatio, false);
			if (upgrade != null && upgrade.IsTurbocharged)
			{
				yield return UpgradeProperty.AddTurbochargedProperty(upgrade);
				yield return StatData.Create("Saturation Duration", turboSaturation, (OverrideType)1, (LabelType)1, (string)null);
				yield return new StatData("Thrown discs cycle between elements while <color=#ccffcc>saturated</color>");
			}
		}

		public override string GetTurbochargedInfo(Random rand, IUpgradable gear, UpgradeInstance upgrade)
		{
			//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)
			StatData val = StatData.Create("SATURATION DURATION", turboSaturation, (OverrideType)1, (LabelType)1, (string)null);
			string text = ((StatData)(ref val)).ToString(upgrade, true);
			text += "\n";
			return text + "Thrown discs cycle between elements while <color=#ccffcc>saturated</color>";
		}

		public override void Apply(IGear gear, UpgradeInstance upgrade, ref Random rand)
		{
			//IL_001c: 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_002a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0032: 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_0045: 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_0053: 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)
			//IL_0062: Unknown result type (might be due to invalid IL or missing references)
			//IL_006f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0078: Unknown result type (might be due to invalid IL or missing references)
			//IL_007d: 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_008c: Unknown result type (might be due to invalid IL or missing references)
			PhotonDisc val = (PhotonDisc)(object)((gear is PhotonDisc) ? gear : null);
			if (val != null)
			{
				PluginUpgradeStats stats = ZygonUpgrade.GetStats(val);
				float num = default(float);
				stats.saturationDuration = UpgradeProperty.ModifyAdditiveRangeFromPatternSize(saturationDurationRange, upgrade, ref num, false).GetValue(ref rand, upgrade, default(BoostParams));
				stats.saturationBoost = UpgradeProperty.ModifyAdditiveRangeFromPatternSize(saturationBoostRange, upgrade, ref num, false).GetValue(ref rand, upgrade, default(BoostParams));
				stats.killReduction = UpgradeProperty.ModifyAdditiveRangeFromPatternSize(killReduction, upgrade, ref num, false).GetValue(ref rand, upgrade, default(BoostParams));
				if (upgrade != null && upgrade.IsTurbocharged)
				{
					stats.saturationDuration += turboSaturation;
					stats.turboSaturation = true;
				}
			}
		}

		public override void Remove(IGear gear, IGear prefab, UpgradeInstance upgrade, ref Random rand)
		{
			PhotonDisc val = (PhotonDisc)(object)((gear is PhotonDisc) ? gear : null);
			if (val != null)
			{
				ZygonUpgrade.ResetPluginStats(val);
			}
		}
	}
	public class UpgradeProperty_ZygonFrenzy : UpgradeProperty
	{
		public Range<float> frenzyDurationRange = new Range<float>(10f, 12f);

		public Range<float> frenzyBoostRange = new Range<float>(0.2f, 0.25f);

		public float waningDuration = 5f;

		public float speedBonus = 5f;

		public override IEnumerator<StatData> GetStatData(Random rand, IUpgradable gear, UpgradeInstance upgrade)
		{
			//IL_000e: Unknown result type (might be due to invalid IL or missing references)
			//IL_000f: Unknown result type (might be due to invalid IL or missing references)
			float frenzyDurationRatio = default(float);
			Range<float> frenzyDuration = UpgradeProperty.ModifyAdditiveRangeFromPatternSize(frenzyDurationRange, upgrade, ref frenzyDurationRatio, false);
			StatData val = StatData.Create("Frenzy Duration", frenzyDuration, upgrade, ref rand, (OverrideType)1, (LabelType)1, default(BoostParams), (Range<float>?)null);
			yield return ((StatData)(ref val)).WithPatternRatio(frenzyDurationRatio, false);
			float frenzyBoostRatio = default(float);
			Range<float> frenzyBoost = UpgradeProperty.ModifyAdditiveRangeFromPatternSize(frenzyBoostRange, upgrade, ref frenzyBoostRatio, false);
			val = StatData.Create("Frenzy Damage", frenzyBoost + 1f, upgrade, ref rand, (OverrideType)2, (LabelType)1, default(BoostParams), (Range<float>?)null);
			yield return ((StatData)(ref val)).WithPatternRatio(frenzyBoostRatio, false);
			yield return StatData.Create("Waning Duration", waningDuration, (OverrideType)1, (LabelType)1, (string)null);
			if (upgrade != null && upgrade.IsTurbocharged)
			{
				yield return UpgradeProperty.AddTurbochargedProperty(upgrade);
				yield return StatData.Create("Speed while frenzied", speedBonus, (OverrideType)1, (LabelType)1, (string)null);
				yield return new StatData("Discs may <color=#D78FFF>decay</color> while <color=#DC3132>frenzied</color>");
			}
		}

		public override string GetTurbochargedInfo(Random rand, IUpgradable gear, UpgradeInstance upgrade)
		{
			//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)
			StatData val = StatData.Create("SPEED WHILE FRENZIED", speedBonus, (OverrideType)1, (LabelType)1, (string)null);
			string text = ((StatData)(ref val)).ToString(upgrade, true);
			text += "\n\n";
			return text + "Discs may <color=#D78FFF>decay</color> while <color=#DC3132>frenzied</color>";
		}

		public override void Apply(IGear gear, UpgradeInstance upgrade, ref Random rand)
		{
			//IL_0028: 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_003e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0044: 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_005a: 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_0068: 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)
			PhotonDisc val = (PhotonDisc)(object)((gear is PhotonDisc) ? gear : null);
			if (val != null)
			{
				PluginUpgradeStats stats = ZygonUpgrade.GetStats(val);
				stats.waningDuration = waningDuration;
				float num = default(float);
				stats.frenzyDuration = UpgradeProperty.ModifyAdditiveRangeFromPatternSize(frenzyDurationRange, upgrade, ref num, false).GetValue(ref rand, upgrade, default(BoostParams));
				stats.frenzyBoost = UpgradeProperty.ModifyAdditiveRangeFromPatternSize(frenzyBoostRange, upgrade, ref num, false).GetValue(ref rand, upgrade, default(BoostParams));
				if (upgrade != null && upgrade.IsTurbocharged)
				{
					stats.frenzySpeed = speedBonus;
					stats.turboFrenzy = true;
				}
			}
		}

		public override void Remove(IGear gear, IGear prefab, UpgradeInstance upgrade, ref Random rand)
		{
			PhotonDisc val = (PhotonDisc)(object)((gear is PhotonDisc) ? gear : null);
			if (val != null)
			{
				ZygonUpgrade.ResetPluginStats(val);
			}
		}
	}
}