Decompiled source of Summoned Ghost Configuration v3.1.1

plugins/Summoned Ghost Configuration.dll

Decompiled 2 weeks ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Diagnostics;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using Conjuration_Extended;
using HarmonyLib;
using MapMagic;
using SideLoader;
using SideLoader.Model;
using Summoned_Ghost_Configuration;
using UnityEngine;
using UnityEngine.SceneManagement;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: AssemblyTitle("Conjuration Extended")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("Conjuration Extended")]
[assembly: AssemblyCopyright("Copyright ©  2024")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("ff65a53d-0b52-41b0-8c46-6a77becc659c")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
[module: UnverifiableCode]
namespace Summoned_Ghost_Configuration
{
	public class InvokeHelper : MonoBehaviour
	{
		private static InvokeHelper instance;

		private Action pendingAction;

		public static InvokeHelper Instance
		{
			get
			{
				//IL_0016: Unknown result type (might be due to invalid IL or missing references)
				//IL_001c: Expected O, but got Unknown
				if ((Object)(object)instance == (Object)null)
				{
					GameObject val = new GameObject("InvokeHelper");
					instance = val.AddComponent<InvokeHelper>();
					Object.DontDestroyOnLoad((Object)(object)val);
				}
				return instance;
			}
		}

		public void InvokeDelayed(float delay, Action action)
		{
			((MonoBehaviour)this).Invoke("ExecuteAction", delay);
			pendingAction = action;
		}

		private void ExecuteAction()
		{
			pendingAction?.Invoke();
		}
	}
	public class SummonedGhostManager
	{
		private Dictionary<Character, Character> summonSummonerDictionary = new Dictionary<Character, Character>();

		private Dictionary<Character, Character> deadSummonSummonerDictionary = new Dictionary<Character, Character>();

		public int WindAltarActivated;

		private int ghostCount;

		public void TeleportAllGhosts()
		{
			//IL_005f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0065: Unknown result type (might be due to invalid IL or missing references)
			//IL_006a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0075: 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)
			foreach (KeyValuePair<Character, Character> item in summonSummonerDictionary)
			{
				Character key = item.Key;
				Character value = item.Value;
				if ((Object)(object)key != (Object)null && (Object)(object)value != (Object)null && !((Object)(object)value.CurrentSummon == (Object)(object)key))
				{
					key.Internal_SendTeleport(((Component)value).transform.position + DisplacementPositionVector(), Extensions.EulerToQuat(((Component)value).transform.eulerAngles));
				}
			}
		}

		public void TeleportGhost(Character ghost)
		{
			//IL_003a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0040: Unknown result type (might be due to invalid IL or missing references)
			//IL_0045: Unknown result type (might be due to invalid IL or missing references)
			//IL_005c: Unknown result type (might be due to invalid IL or missing references)
			if (ConfigElements.mode.Value != modMode.Vanilla)
			{
				Character val = summonSummonerDictionary[ghost];
				if ((Object)(object)val != (Object)null)
				{
					((Component)ghost).transform.position = ((Component)val).transform.position + DisplacementPositionVector();
					((Component)ghost).transform.rotation = ((Component)val).transform.rotation;
				}
			}
		}

		public void AddGhost(Character ghost, Character summoner)
		{
			summonSummonerDictionary.Add(ghost, summoner);
			if (ConfigElements.mode.Value == modMode.Custom && ConfigElements.ghostImpact.Value)
			{
				InvokeHelper.Instance.InvokeDelayed(1f, SetStatsDelayed);
			}
		}

		public void clearAllGhosts()
		{
			summonSummonerDictionary.Clear();
		}

		public void removeAllGhosts()
		{
			//IL_003c: Unknown result type (might be due to invalid IL or missing references)
			Character[] array = summonSummonerDictionary.Keys.ToArray();
			foreach (Character val in array)
			{
				val.Stats.SetHealth(0f);
				val.Die(new Vector3(0f, 0f, 0f), false);
			}
		}

		private void addToDeadDictionary(Character ghost, Character summoner)
		{
			if (!deadSummonSummonerDictionary.ContainsKey(ghost))
			{
				deadSummonSummonerDictionary.Add(ghost, summoner);
			}
		}

		public void RemoveStuckAliveDeadGhost()
		{
			if (deadSummonSummonerDictionary == null)
			{
				return;
			}
			for (int i = 0; i < deadSummonSummonerDictionary.Count; i++)
			{
				Character val = deadSummonSummonerDictionary.Keys.ElementAt(i);
				Character val2 = deadSummonSummonerDictionary.Values.ElementAt(i);
				if ((Object)(object)val != (Object)null && (Object)(object)val2 != (Object)null)
				{
					GameObject gameObject = ((Component)val).gameObject;
					GameObject gameObject2 = ((Component)val.FXTransform).gameObject;
					if ((Object)(object)gameObject != (Object)null && (Object)(object)gameObject2 != (Object)null)
					{
						Object.Destroy((Object)(object)gameObject);
						Object.Destroy((Object)(object)gameObject2);
					}
				}
			}
		}

		public void CheckRemoveGhost(Character ghost)
		{
			if (summonSummonerDictionary.ContainsKey(ghost))
			{
				addToDeadDictionary(ghost, summonSummonerDictionary[ghost]);
				summonSummonerDictionary.Remove(ghost);
				if (ConfigElements.mode.Value == modMode.Custom && ConfigElements.ghostImpact.Value)
				{
					InvokeHelper.Instance.InvokeDelayed(1f, SetStatsDelayed);
				}
			}
		}

		private void SetStatsDelayed()
		{
			setImpactDamage();
		}

		public int GetGhostCount()
		{
			return ghostCount = summonSummonerDictionary.Count;
		}

		public int GetGhostCount(Character summoner)
		{
			int num = 0;
			foreach (KeyValuePair<Character, Character> item in summonSummonerDictionary)
			{
				Character key = item.Key;
				Character value = item.Value;
				if ((Object)(object)summoner == (Object)(object)value)
				{
					num++;
				}
			}
			ghostCount = num;
			return num;
		}

		public Vector3 DisplacementPositionVector()
		{
			//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_0036: Unknown result type (might be due to invalid IL or missing references)
			return new Vector3(Random.Range(-1f, 1f), Random.Range(2f, 2.1f), Random.Range(-1f, 1f));
		}

		private void setImpactDamage()
		{
			Dictionary<Character, int> dictionary = new Dictionary<Character, int>();
			foreach (KeyValuePair<Character, Character> item in summonSummonerDictionary)
			{
				Character key = item.Key;
				Character value = item.Value;
				if (!dictionary.ContainsKey(value))
				{
					dictionary[value] = 0;
				}
				dictionary[value]++;
			}
			foreach (KeyValuePair<Character, int> item2 in dictionary)
			{
				Character summoner = item2.Key;
				int value2 = item2.Value;
				foreach (Character item3 in from x in summonSummonerDictionary
					where (Object)(object)x.Value == (Object)(object)summoner
					select x.Key)
				{
					setImpactDamageGhost(item3, value2);
				}
			}
		}

		private void setImpactDamageGhost(Character ghostCharacter, int summonedCount)
		{
			//IL_0017: Unknown result type (might be due to invalid IL or missing references)
			//IL_001d: Expected O, but got Unknown
			//IL_002f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0035: Expected O, but got Unknown
			if (summonedCount == 0)
			{
				return;
			}
			MeleeWeapon val = (MeleeWeapon)ghostCharacter.CurrentWeapon;
			if (!((Object)(object)val != (Object)null))
			{
				return;
			}
			WeaponStats val2 = (WeaponStats)((Item)val).m_stats;
			if (!((Object)(object)val2 != (Object)null))
			{
				return;
			}
			AttackData[] attacks = val2.Attacks;
			if (attacks != null)
			{
				AttackData[] array = attacks;
				foreach (AttackData val3 in array)
				{
					val3.Knockback = 37f * Mathf.Pow((float)summonedCount, -0.95f);
				}
			}
		}

		public void setWindAltarCount(int windAltarCount)
		{
			WindAltarActivated = windAltarCount;
		}
	}
}
namespace Conjuration_Extended
{
	public static class ConfigElements
	{
		public static ConfigEntry<modMode> mode;

		public static ConfigEntry<int> ghostHealth;

		public static ConfigEntry<float> ghostHealthRegen;

		public static ConfigEntry<float> ghostLifeTime;

		public static ConfigEntry<float> ghostRed;

		public static ConfigEntry<float> ghostGreen;

		public static ConfigEntry<float> ghostBlue;

		public static ConfigEntry<float> ghostAlpha;

		public static ConfigEntry<bool> canSpawnMultiple;

		public static ConfigEntry<float> ghostShareDamage;

		public static ConfigEntry<bool> ghostImpact;

		public static void Init(ConfigFile config)
		{
			//IL_0018: Unknown result type (might be due to invalid IL or missing references)
			//IL_0022: Expected O, but got Unknown
			//IL_004a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0054: Expected O, but got Unknown
			//IL_0083: Unknown result type (might be due to invalid IL or missing references)
			//IL_008d: Expected O, but got Unknown
			//IL_00bc: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c6: Expected O, but got Unknown
			//IL_00f5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ff: Expected O, but got Unknown
			//IL_012e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0138: Expected O, but got Unknown
			//IL_0167: Unknown result type (might be due to invalid IL or missing references)
			//IL_0171: Expected O, but got Unknown
			//IL_01a0: Unknown result type (might be due to invalid IL or missing references)
			//IL_01aa: Expected O, but got Unknown
			//IL_01c6: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d0: Expected O, but got Unknown
			//IL_01ec: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f6: Expected O, but got Unknown
			//IL_0225: Unknown result type (might be due to invalid IL or missing references)
			//IL_022f: Expected O, but got Unknown
			mode = config.Bind<modMode>("(1) Main", "Mode", modMode.BalanceTweaks, new ConfigDescription("The mode the mod runs in. For custom behavior set to 'Custom'", (AcceptableValueBase)null, Array.Empty<object>()));
			ghostHealth = config.Bind<int>("(2) In Custom Mode", "Stats, Health", 110, new ConfigDescription("The default health of the summoned ghost. (Vanilla = 110)", (AcceptableValueBase)(object)new AcceptableValueRange<int>(1, 1000), new object[0]));
			ghostHealthRegen = config.Bind<float>("(2) In Custom Mode", "Stats, Health Regen", 0f, new ConfigDescription("The health regeneration of the summoned ghost. (Vanilla = 0)", (AcceptableValueBase)(object)new AcceptableValueRange<float>(-2f, 2f), new object[0]));
			ghostLifeTime = config.Bind<float>("(2) In Custom Mode", "Stats, Lifetime", 280f, new ConfigDescription("The life span of the summoned ghost. (Vanilla = 280)", (AcceptableValueBase)(object)new AcceptableValueRange<float>(1f, 2400f), new object[0]));
			ghostRed = config.Bind<float>("(2) In Custom Mode", "Color, Red", 1.3235f, new ConfigDescription("The color of the summoned ghost. (Vanilla = 1.3235)", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0.01f, 10f), new object[0]));
			ghostGreen = config.Bind<float>("(2) In Custom Mode", "Color, Green", 1.5635f, new ConfigDescription("The color of the summoned ghost. (Vanilla = 1.5635)", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0.01f, 10f), new object[0]));
			ghostBlue = config.Bind<float>("(2) In Custom Mode", "Color, Blue", 4f, new ConfigDescription("The color of the summoned ghost. (Vanilla = 4)", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0.01f, 10f), new object[0]));
			ghostAlpha = config.Bind<float>("(2) In Custom Mode", "Color, Alpha", 1.3235f, new ConfigDescription("The transparency of the summoned ghost. (Vanilla = 1)", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0.01f, 1f), new object[0]));
			canSpawnMultiple = config.Bind<bool>("(2) In Custom Mode", "Multiple, Can Spawn Multiple?", false, new ConfigDescription("Allows additional ghosts to be summoned equal to the number of wind altars activated. If the player activates all 6 altars then they can summon as many as they wish. (Vanilla = Disabled)", (AcceptableValueBase)null, Array.Empty<object>()));
			ghostImpact = config.Bind<bool>("(2) In Custom Mode", "Multiple, Reduced Impact", false, new ConfigDescription("Ghosts deals reduced impact damage if there are multiple of them. (Vanilla = Disabled)", (AcceptableValueBase)null, Array.Empty<object>()));
			ghostShareDamage = config.Bind<float>("(2) In Custom Mode", "Other, Share Damage (%)", 0f, new ConfigDescription("A percentage of damage taken by the ghost is shared with the summoner. (Vanilla = 0%)", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0f, 1f), new object[0]));
		}
	}
	public enum modMode
	{
		[Description("Balance Tweaks")]
		BalanceTweaks,
		[Description("Vanilla")]
		Vanilla,
		[Description("Custom")]
		Custom
	}
	[BepInPlugin("johbenji.summonedghostconfiguration", "Summoned Ghost Configuration", "3.1.0")]
	public class ConjurationExtendedPlugin : BaseUnityPlugin
	{
		[HarmonyPatch(typeof(QuestEventManager), "Awake")]
		private class addQEManager_Patch
		{
			private static void Postfix(QuestEventManager __instance)
			{
				if ((Object)(object)manager == (Object)null)
				{
					manager = __instance;
				}
			}
		}

		[HarmonyPatch(typeof(QuestEventManager), "LoadEventList")]
		private class updateOnLoadQEDictionary_Patch
		{
			private static void Postfix(QuestEventManager __instance)
			{
				if ((Object)(object)__instance != (Object)null && (Object)(object)manager != (Object)null && (Object)(object)__instance == (Object)(object)manager)
				{
					updateQEDictionarySearch();
				}
			}
		}

		[HarmonyPatch(typeof(QuestEventManager), "AddEvent", new Type[]
		{
			typeof(string),
			typeof(int),
			typeof(bool)
		})]
		private class updateOnAddQEDictionary_Patch
		{
			private static void Postfix(QuestEventManager __instance)
			{
				if ((Object)(object)__instance != (Object)null && (Object)(object)manager != (Object)null && (Object)(object)__instance == (Object)(object)manager)
				{
					updateQEDictionarySearch();
				}
			}
		}

		[HarmonyPatch(typeof(Character), "SetIntantiationData")]
		public class MultipleGhost_Patch
		{
			private static bool Prefix(Character __instance, object[] _data)
			{
				//IL_005c: 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_00b2: Unknown result type (might be due to invalid IL or missing references)
				//IL_00b8: Invalid comparison between Unknown and I4
				//IL_018e: Unknown result type (might be due to invalid IL or missing references)
				if ((ConfigElements.mode.Value == modMode.BalanceTweaks || (ConfigElements.mode.Value == modMode.Custom && ConfigElements.canSpawnMultiple.Value)) && ((int)_data[0] == 3 || (int)_data[0] == 4))
				{
					__instance.m_instantiationType = (CharacterInstantiationTypes)(int)_data[0];
					__instance.m_prefabPath = (string)_data[1];
					__instance.m_uid = UID.op_Implicit((string)_data[2]);
					CharacterManager.Instance.AddCharacter(__instance);
					Character character = CharacterManager.Instance.GetCharacter((string)_data[3]);
					if (Object.op_Implicit((Object)(object)character))
					{
						if ((int)__instance.SummonType != 2)
						{
							if (PhotonNetwork.isMasterClient)
							{
								int num = 1;
								int windAltarCount = Instance.getWindAltarCount();
								if (ConfigElements.mode.Value == modMode.BalanceTweaks)
								{
									if (windAltarCount == 6)
									{
										num = 2;
									}
								}
								else if (ConfigElements.mode.Value == modMode.Custom && ConfigElements.canSpawnMultiple.Value)
								{
									num = 1 + SummonedGhostManager.WindAltarActivated;
								}
								int ghostCount = SummonedGhostManager.GetGhostCount(character);
								if (ghostCount >= num)
								{
									SummonedGhostManager.CheckRemoveGhost(character.CurrentSummon);
									character.DestroyCurrentSummon();
								}
							}
							character.SetCurrentSummon(__instance);
						}
						else
						{
							character.SetCurrentBloodSpirit(__instance);
						}
						__instance.m_summonerUID = UID.op_Implicit(character.UID);
					}
					else if (!NetworkLevelLoader.Instance.IsOverallLoadingDone && PhotonNetwork.isNonMasterClientInRoom)
					{
						__instance.m_summonerUID = (string)_data[3];
						__instance.m_summonLateInitRequired = true;
					}
					StartingEquipment component = ((Component)__instance).GetComponent<StartingEquipment>();
					if (Object.op_Implicit((Object)(object)component))
					{
						component.InitWanted();
					}
					return false;
				}
				return true;
			}
		}

		[HarmonyPatch(typeof(Character), "OnReceiveHit")]
		public class ShareDamage_Patch
		{
			private static void Postfix(Character __instance, Weapon _weapon, float _damage, DamageList _damageList, Vector3 _hitDir, Vector3 _hitPoint, float _angle, float _angleDir, Character _dealerChar, float _knockBack)
			{
				//IL_0063: Unknown result type (might be due to invalid IL or missing references)
				//IL_0065: Unknown result type (might be due to invalid IL or missing references)
				if (ConfigElements.mode.Value != modMode.Custom)
				{
					return;
				}
				float value = ConfigElements.ghostShareDamage.Value;
				if (value != 0f && __instance.SummonerUID != null)
				{
					Character character = CharacterManager.Instance.GetCharacter(__instance.m_summonerUID);
					if ((Object)(object)character != (Object)null)
					{
						character.ReceiveHit(_weapon, value * _damage, _hitDir, _hitPoint, _angle, _angleDir, _dealerChar, 0f * _knockBack);
					}
				}
			}
		}

		[HarmonyPatch(typeof(QuestEventManager), "AddEvent", new Type[]
		{
			typeof(string),
			typeof(int),
			typeof(bool)
		})]
		public class AddEvent_Patch
		{
			private static void Postfix(QuestEventManager __instance, string _eventUID, int _stackAmount = 1, bool _sendEvent = true)
			{
				if (!string.IsNullOrEmpty(_eventUID))
				{
					QuestEventData val = null;
					if (QuestEventManager.m_questEvents.TryGetValue(_eventUID, ref val) && val != null && Instance.questEventNames.Contains(val.Name))
					{
						Instance.getWindAltarCount();
					}
				}
			}
		}

		[HarmonyPatch(typeof(Character), "SetCurrentSummon")]
		public class SetCurrentSummon_Patch
		{
			private static void Postfix(Character __instance, Character _char)
			{
				SummonedGhostManager.AddGhost(_char, __instance);
				SummonedGhostManager.GetGhostCount();
				if (ConfigElements.mode.Value != modMode.Vanilla)
				{
					AdjustGhostStats(_char);
				}
			}
		}

		[HarmonyPatch(typeof(Character), "Die")]
		public class DieSummon_Patch
		{
			private static void Postfix(Character __instance)
			{
				SummonedGhostManager.CheckRemoveGhost(__instance);
				SummonedGhostManager.GetGhostCount();
			}
		}

		[HarmonyPatch(typeof(Character), "SendTeleport")]
		public class TeleportAllGhosts_Patch
		{
			private static void Postfix(Character __instance)
			{
				if (ConfigElements.mode.Value != modMode.Vanilla && IsPlayerCharacter(__instance))
				{
					((MonoBehaviour)Instance).StartCoroutine(Instance.TeleportSummonedGhosts());
				}
			}
		}

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

			private object <>2__current;

			public ConjurationExtendedPlugin <>4__this;

			private bool <repeat>5__1;

			private Scene <scene>5__2;

			private bool <inDungeon>5__3;

			private bool <olieleActive>5__4;

			private GameObject <Oliele>5__5;

			private Character[] <playerCharacters>5__6;

			private Character[] <>s__7;

			private int <>s__8;

			private Character <player>5__9;

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

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

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

			[DebuggerHidden]
			void IDisposable.Dispose()
			{
				<Oliele>5__5 = null;
				<playerCharacters>5__6 = null;
				<>s__7 = null;
				<player>5__9 = null;
				<>1__state = -2;
			}

			private bool MoveNext()
			{
				//IL_0033: Unknown result type (might be due to invalid IL or missing references)
				//IL_003d: Expected O, but got Unknown
				//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)
				switch (<>1__state)
				{
				default:
					return false;
				case 0:
					<>1__state = -1;
					<repeat>5__1 = true;
					break;
				case 1:
					<>1__state = -1;
					<scene>5__2 = SceneManager.GetActiveScene();
					<inDungeon>5__3 = true;
					if (((Scene)(ref <scene>5__2)).name != "Chersonese_Dungeon6")
					{
						<inDungeon>5__3 = false;
					}
					<olieleActive>5__4 = false;
					<Oliele>5__5 = GameObject.Find("UNPC_OlieleA");
					if ((Object)(object)<Oliele>5__5 != (Object)null)
					{
						<olieleActive>5__4 = <Oliele>5__5.activeSelf;
					}
					if (!<inDungeon>5__3)
					{
						<repeat>5__1 = false;
					}
					if (<olieleActive>5__4)
					{
						<repeat>5__1 = false;
						SummonedGhostManager.removeAllGhosts();
						<playerCharacters>5__6 = CharacterManager.Instance.Characters.ValuesArray.Where((Character x) => x.IsLocalPlayer).ToArray();
						<>s__7 = <playerCharacters>5__6;
						for (<>s__8 = 0; <>s__8 < <>s__7.Length; <>s__8++)
						{
							<player>5__9 = <>s__7[<>s__8];
							if (<player>5__9.IsLocalPlayer)
							{
								<player>5__9.CharacterUI.NotificationPanel.ShowNotification("Summoned ghosts won't work with this part of the quest. Please refrain from using them against the next fight inside this dungeon.", 10f);
							}
							<player>5__9 = null;
						}
						<>s__7 = null;
						<playerCharacters>5__6 = null;
					}
					<Oliele>5__5 = null;
					break;
				}
				if (<repeat>5__1)
				{
					<>2__current = (object)new WaitForSeconds(5f);
					<>1__state = 1;
					return true;
				}
				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 <TeleportSummonedGhosts>d__19 : IEnumerator<object>, IDisposable, IEnumerator
		{
			private int <>1__state;

			private object <>2__current;

			public ConjurationExtendedPlugin <>4__this;

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

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

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

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

			private bool MoveNext()
			{
				//IL_0026: Unknown result type (might be due to invalid IL or missing references)
				//IL_0030: Expected O, but got Unknown
				switch (<>1__state)
				{
				default:
					return false;
				case 0:
					<>1__state = -1;
					<>2__current = (object)new WaitForSecondsRealtime(1f);
					<>1__state = 1;
					return true;
				case 1:
					<>1__state = -1;
					if (ConfigElements.mode.Value != modMode.Vanilla)
					{
						SummonedGhostManager.TeleportAllGhosts();
					}
					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();
			}
		}

		public const string GUID = "johbenji.summonedghostconfiguration";

		public const string NAME = "Summoned Ghost Configuration";

		public const string VERSION = "3.1.0";

		internal static ManualLogSource Log;

		public static QuestEventManager manager;

		public static Dictionary<string, string> questEvents = new Dictionary<string, string>();

		public List<string> questEventNames = new List<string> { "Caldera_WindAltar_Activated", "Cierzo_WindAltar_Activated", "Enmerkar_WindAltar_Activated", "Harmattan_WindAltar_Activated", "Levant_WindAltar_Activated", "Monsoon_WindAltar_Activated" };

		public static ConjurationExtendedPlugin Instance { get; private set; }

		public static SummonedGhostManager SummonedGhostManager { get; private set; }

		internal void Awake()
		{
			//IL_00a5: Unknown result type (might be due to invalid IL or missing references)
			Instance = this;
			SummonedGhostManager = new SummonedGhostManager();
			Log = ((BaseUnityPlugin)this).Logger;
			ConfigElements.Init(((BaseUnityPlugin)this).Config);
			SL.OnPacksLoaded += SL_OnPacksLoaded;
			SceneManager.sceneLoaded += SceneManager_sceneLoaded;
			SL.OnGameplayResumedAfterLoading += OnResumedAfterLoading;
			foreach (string questEventName in questEventNames)
			{
				questEvents.Add(questEventName, null);
			}
			new Harmony("johbenji.summonedghostconfiguration").PatchAll();
		}

		internal void SceneManager_sceneLoaded(Scene Scene, LoadSceneMode LoadMode)
		{
			if (((Scene)(ref Scene)).name == "Chersonese_Dungeon6" && ConfigElements.mode.Value != modMode.Vanilla)
			{
				Log.LogMessage((object)"Entered Chersonese Dungeon, starting checks for quest events and potential issues with summoned ghosts.");
				((MonoBehaviour)Instance).StartCoroutine(FixQuestionsAndCorruption());
			}
			if (SummonedGhostManager != null && ConfigElements.mode.Value != modMode.Vanilla)
			{
				SummonedGhostManager.RemoveStuckAliveDeadGhost();
			}
		}

		internal void OnResumedAfterLoading()
		{
			int windAltarCount = Instance.getWindAltarCount();
		}

		public void SL_OnPacksLoaded()
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0007: Expected O, but got Unknown
			//IL_0046: Unknown result type (might be due to invalid IL or missing references)
			//IL_0054: Unknown result type (might be due to invalid IL or missing references)
			//IL_005a: Expected O, but got Unknown
			//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_007e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0080: Unknown result type (might be due to invalid IL or missing references)
			//IL_0085: Unknown result type (might be due to invalid IL or missing references)
			//IL_0087: 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)
			//IL_009c: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ac: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bb: Expected O, but got Unknown
			SL_StatusEffect val = new SL_StatusEffect();
			val.TargetStatusIdentifier = "Health Recovery 5";
			val.NewStatusID = -65100;
			val.StatusIdentifier = "Ghost Health Recovery";
			val.Description = "WIP";
			val.Lifespan = 2400f;
			val.EffectBehaviour = (EditBehaviours)2;
			SL_EffectTransform[] array = new SL_EffectTransform[1];
			SL_EffectTransform val2 = new SL_EffectTransform();
			val2.TransformName = "Normal";
			val2.Effects = (SL_Effect[])(object)new SL_Effect[1] { (SL_Effect)new SL_AffectHealth
			{
				Delay = 0f,
				SyncType = (SyncTypes)0,
				OverrideCategory = (EffectCategories)0,
				AffectQuantity = ConfigElements.ghostHealthRegen.Value,
				AffectQuantityAI = ConfigElements.ghostHealthRegen.Value,
				IsModifier = false,
				InformSourceCharacter = false
			} };
			array[0] = val2;
			val.Effects = (SL_EffectTransform[])(object)array;
			SL_StatusEffect val3 = val;
			((ContentTemplate)val3).ApplyTemplate();
		}

		[IteratorStateMachine(typeof(<TeleportSummonedGhosts>d__19))]
		public IEnumerator TeleportSummonedGhosts()
		{
			//yield-return decompiler failed: Unexpected instruction in Iterator.Dispose()
			return new <TeleportSummonedGhosts>d__19(0)
			{
				<>4__this = this
			};
		}

		[IteratorStateMachine(typeof(<FixQuestionsAndCorruption>d__20))]
		public IEnumerator FixQuestionsAndCorruption()
		{
			//yield-return decompiler failed: Unexpected instruction in Iterator.Dispose()
			return new <FixQuestionsAndCorruption>d__20(0)
			{
				<>4__this = this
			};
		}

		public static void AdjustGhostStats(Character character)
		{
			AdjustHP(character);
		}

		private static void AdjustHP(Character character)
		{
			if ((Object)(object)character == (Object)null || (Object)(object)character.Stats == (Object)null || ConfigElements.mode.Value == modMode.Vanilla)
			{
				return;
			}
			float num = 0f;
			if (ConfigElements.mode.Value == modMode.Custom)
			{
				num = (float)ConfigElements.ghostHealth.Value - 110f;
			}
			else
			{
				if (ConfigElements.mode.Value != 0)
				{
					return;
				}
				int windAltarActivated = SummonedGhostManager.WindAltarActivated;
				num = 10f * (float)windAltarActivated;
			}
			if (num != 0f)
			{
				float num2 = 110f;
				float num3 = 20f;
				character.Stats.BaseMaxHealth = num2 - num3 + num;
				character.Stats.CurrentHealth = num2 - num3 + num;
			}
		}

		private static void updateQEDictionarySearch()
		{
			Character[] array = CharacterManager.Instance.Characters.ValuesArray.Where((Character x) => x.IsLocalPlayer).ToArray();
			Character[] array2 = array;
			foreach (Character val in array2)
			{
				if (val.IsLocalPlayer)
				{
					updateQEDictionary(manager);
				}
			}
		}

		private static void updateQEDictionary(QuestEventManager questEventManager)
		{
			IList<QuestEventData> currentQuestEvents = questEventManager.CurrentQuestEvents;
			foreach (QuestEventData item in currentQuestEvents)
			{
				if (questEvents.ContainsKey(item.Name))
				{
					questEvents[item.Name] = item.m_signatureUID;
				}
			}
		}

		public int getWindAltarCount()
		{
			int num = 0;
			if ((Object)(object)manager != (Object)null && questEvents.Count > 0)
			{
				foreach (KeyValuePair<string, string> questEvent in questEvents)
				{
					if (questEvent.Value != null && !(questEvent.Value == ""))
					{
						string value = questEvent.Value;
						if (manager.GetEventCurrentStack(value) != 0)
						{
							num++;
						}
					}
				}
			}
			if (SummonedGhostManager != null && SummonedGhostManager.WindAltarActivated != num)
			{
				Log.LogMessage((object)"Wind altar count updated.");
				SummonedGhostManager.setWindAltarCount(num);
			}
			return num;
		}

		public static bool IsPlayerCharacter(Character character)
		{
			if ((Object)(object)character == (Object)null)
			{
				return false;
			}
			CharacterManager instance = CharacterManager.Instance;
			if ((Object)(object)instance == (Object)null)
			{
				return false;
			}
			List<string> list = instance.PlayerCharacters.Values.ToList();
			if (list.Count == 0)
			{
				return false;
			}
			foreach (string item in list)
			{
				Character character2 = instance.GetCharacter(item);
				if ((Object)(object)character2 != (Object)null)
				{
					return true;
				}
			}
			return false;
		}
	}
	public class SL_GhostColor : SL_Effect, ICustomModel
	{
		public Type SLTemplateModel => typeof(SL_GhostColor);

		public Type GameModel => typeof(GhostColor);

		public override void ApplyToComponent<T>(T component)
		{
			GhostColor ghostColor = component as GhostColor;
		}

		public override void SerializeEffect<T>(T effect)
		{
			GhostColor ghostColor = effect as GhostColor;
		}
	}
	public class GhostColor : Effect
	{
		public string StatusEffect = "Ghost Health Recovery";

		private float Red;

		private float Green;

		private float Blue;

		private float Alpha;

		public override void ActivateLocally(Character _affectedCharacter, object[] _infos)
		{
			//IL_0186: 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_018f: Unknown result type (might be due to invalid IL or missing references)
			//IL_014d: Unknown result type (might be due to invalid IL or missing references)
			//IL_01dd: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e1: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e6: Unknown result type (might be due to invalid IL or missing references)
			//IL_0234: Unknown result type (might be due to invalid IL or missing references)
			//IL_0238: Unknown result type (might be due to invalid IL or missing references)
			//IL_023d: Unknown result type (might be due to invalid IL or missing references)
			//IL_028b: Unknown result type (might be due to invalid IL or missing references)
			//IL_028f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0294: 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_02e6: Unknown result type (might be due to invalid IL or missing references)
			//IL_02eb: Unknown result type (might be due to invalid IL or missing references)
			//IL_0339: Unknown result type (might be due to invalid IL or missing references)
			//IL_033d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0342: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)_affectedCharacter == (Object)null || (Object)(object)_affectedCharacter.CurrentSummon == (Object)null || ConfigElements.mode.Value == modMode.Vanilla || ConfigElements.mode.Value == modMode.BalanceTweaks)
			{
				return;
			}
			if (ConfigElements.mode.Value == modMode.Custom)
			{
				Red = ConfigElements.ghostRed.Value;
				Green = ConfigElements.ghostGreen.Value;
				Blue = ConfigElements.ghostBlue.Value;
				Alpha = ConfigElements.ghostAlpha.Value;
				Color val = default(Color);
				((Color)(ref val))..ctor(Red, Green, Blue, Alpha);
				Character currentSummon = _affectedCharacter.CurrentSummon;
				float value = ConfigElements.ghostHealthRegen.Value;
				if (!((Object)(object)currentSummon != (Object)null))
				{
					return;
				}
				GameObject gameObject = ((Component)currentSummon).gameObject;
				Transform val2 = gameObject.transform.Find("NewGhostOneHandedAlly_v/mdl_cha_GhostTwoHanded");
				if ((Object)(object)val2 != (Object)null)
				{
					SkinnedMeshRenderer component = ((Component)val2).GetComponent<SkinnedMeshRenderer>();
					if ((Object)(object)component != (Object)null)
					{
						Material material = ((Renderer)component).material;
						if ((Object)(object)material != (Object)null)
						{
							material.SetColor("_Color", val);
						}
					}
				}
				Transform val3 = gameObject.transform.Find("NewGhostOneHandedAlly_v/SkinnedGhostParticleTest");
				ParticleSystem component2 = ((Component)val3).GetComponent<ParticleSystem>();
				if ((Object)(object)component2 != (Object)null)
				{
					component2.startColor = ColorEvaluator(val, component2.startColor);
				}
				else
				{
					ConjurationExtendedPlugin.Log.LogMessage((object)"JohBenjiConjurationExtended: particleTest = null");
				}
				Transform val4 = gameObject.transform.Find("NewGhostOneHandedAlly_v/BurningMan_arma.001/pelvis/spine/Torso/neck/head/GhostEyesEmbers");
				ParticleSystem component3 = ((Component)val4).GetComponent<ParticleSystem>();
				if ((Object)(object)component3 != (Object)null)
				{
					component3.startColor = ColorEvaluator(val, component3.startColor);
				}
				else
				{
					ConjurationExtendedPlugin.Log.LogMessage((object)"JohBenjiConjurationExtended: particleEyesEmbers = null");
				}
				Transform val5 = gameObject.transform.Find("NewGhostOneHandedAlly_v/BurningMan_arma.001/pelvis/spine/Torso/Clavicle_R/topArm_right/Arm2_right/hand_right/SkinnedGhostParticleTestSmoke (1)");
				ParticleSystem component4 = ((Component)val5).GetComponent<ParticleSystem>();
				if ((Object)(object)component4 != (Object)null)
				{
					component4.startColor = ColorEvaluator(val, component4.startColor);
				}
				else
				{
					ConjurationExtendedPlugin.Log.LogMessage((object)"JohBenjiConjurationExtended: particleEyesEmbers = null");
				}
				Transform val6 = gameObject.transform.Find("NewGhostOneHandedAlly_v/VFXDeathGhost (1)/PlayParticles/DeadParticles");
				ParticleSystem component5 = ((Component)val6).GetComponent<ParticleSystem>();
				if ((Object)(object)component5 != (Object)null)
				{
					component5.startColor = ColorEvaluator(val, component5.startColor);
				}
				else
				{
					ConjurationExtendedPlugin.Log.LogMessage((object)"JohBenjiConjurationExtended: deadParticle = null");
				}
				Transform val7 = gameObject.transform.Find("NewGhostOneHandedAlly_v/VFXDeathGhost (1)/PlayParticles/DeadParticles/Embers");
				ParticleSystem component6 = ((Component)val7).GetComponent<ParticleSystem>();
				if ((Object)(object)component6 != (Object)null)
				{
					component6.startColor = ColorEvaluator(val, component6.startColor);
				}
				else
				{
					ConjurationExtendedPlugin.Log.LogMessage((object)"JohBenjiConjurationExtended: emberParticle = null");
				}
				Transform val8 = gameObject.transform.Find("NewGhostOneHandedAlly_v/VFXDeathGhost (1)/PlayParticles/DeadParticles/SkinnedGhostParticles");
				ParticleSystem component7 = ((Component)val8).GetComponent<ParticleSystem>();
				if ((Object)(object)component7 != (Object)null)
				{
					component7.startColor = ColorEvaluator(val, component7.startColor);
				}
				else
				{
					ConjurationExtendedPlugin.Log.LogMessage((object)"JohBenjiConjurationExtended: skinnedGhostParticles = null");
				}
			}
			else
			{
				ConjurationExtendedPlugin.Log.LogMessage((object)"Invalid mod mode. Defaulting to Vanilla behavior.");
			}
		}

		private Color ColorEvaluator(Color inputColor, Color referenceColor)
		{
			//IL_009a: Unknown result type (might be due to invalid IL or missing references)
			//IL_009c: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a0: Unknown result type (might be due to invalid IL or missing references)
			float num = ((Color)(ref inputColor))[0];
			float num2 = ((Color)(ref inputColor))[1];
			float num3 = ((Color)(ref inputColor))[2];
			float num4 = (float)Math.Sqrt(num * num + num2 * num2 + num3 * num3);
			float num5 = ((Color)(ref inputColor))[0];
			float num6 = ((Color)(ref inputColor))[1];
			float num7 = ((Color)(ref inputColor))[2];
			float num8 = ((Color)(ref inputColor))[3];
			float num9 = (float)Math.Sqrt(num5 * num5 + num6 * num6 + num7 * num7);
			float num10 = num * num9 / num4;
			float num11 = num2 * num9 / num4;
			float num12 = num3 * num9 / num4;
			Color result = default(Color);
			((Color)(ref result))..ctor(num10, num11, num12, num8);
			return result;
		}
	}
	public class SL_GhostRegen : SL_Effect, ICustomModel
	{
		public Type SLTemplateModel => typeof(SL_GhostRegen);

		public Type GameModel => typeof(GhostRegen);

		public override void ApplyToComponent<T>(T component)
		{
			GhostRegen ghostRegen = component as GhostRegen;
		}

		public override void SerializeEffect<T>(T effect)
		{
			GhostRegen ghostRegen = effect as GhostRegen;
		}
	}
	public class GhostRegen : Effect
	{
		public string StatusEffect = "Ghost Health Recovery";

		public override void ActivateLocally(Character _affectedCharacter, object[] _infos)
		{
			if (ConfigElements.mode.Value == modMode.Vanilla || ConfigElements.mode.Value == modMode.BalanceTweaks)
			{
				return;
			}
			if (ConfigElements.mode.Value == modMode.Custom)
			{
				if (!((Object)(object)_affectedCharacter == (Object)null) && !((Object)(object)_affectedCharacter.CurrentSummon == (Object)null))
				{
					Character currentSummon = _affectedCharacter.CurrentSummon;
					float value = ConfigElements.ghostHealthRegen.Value;
					if ((Object)(object)currentSummon != (Object)null)
					{
						currentSummon.StatusEffectMngr.AddStatusEffect("Ghost Health Recovery");
					}
				}
			}
			else
			{
				ConjurationExtendedPlugin.Log.Log((LogLevel)4, (object)"Invalid mod mode. Defaulting to Vanilla behavior.");
			}
		}
	}
	public class SL_GhostInfiniteLifeSpan : SL_Effect, ICustomModel
	{
		public Type SLTemplateModel => typeof(SL_GhostInfiniteLifeSpan);

		public Type GameModel => typeof(GhostInfiniteLifeSpan);

		public override void ApplyToComponent<T>(T component)
		{
			GhostInfiniteLifeSpan ghostInfiniteLifeSpan = component as GhostInfiniteLifeSpan;
		}

		public override void SerializeEffect<T>(T effect)
		{
			GhostInfiniteLifeSpan ghostInfiniteLifeSpan = effect as GhostInfiniteLifeSpan;
		}
	}
	public class GhostInfiniteLifeSpan : Effect
	{
		public float LifeSpan;

		public override void ActivateLocally(Character _affectedCharacter, object[] _infos)
		{
			if ((Object)(object)_affectedCharacter == (Object)null || (Object)(object)_affectedCharacter.CurrentSummon == (Object)null || ConfigElements.mode.Value == modMode.Vanilla)
			{
				return;
			}
			if (ConfigElements.mode.Value == modMode.BalanceTweaks)
			{
				Character currentSummon = _affectedCharacter.CurrentSummon;
				float num = 20f * (float)ConjurationExtendedPlugin.SummonedGhostManager.WindAltarActivated;
				if (currentSummon.Lifetime != -1f)
				{
					currentSummon.Lifetime += num;
					currentSummon.m_remainingLifespan += num;
				}
			}
			else if (ConfigElements.mode.Value == modMode.Custom)
			{
				Character currentSummon2 = _affectedCharacter.CurrentSummon;
				LifeSpan = ConfigElements.ghostLifeTime.Value;
				if (currentSummon2.Lifetime != -1f)
				{
					currentSummon2.Lifetime = LifeSpan;
					currentSummon2.m_remainingLifespan = LifeSpan;
				}
			}
			else
			{
				ConjurationExtendedPlugin.Log.LogMessage((object)"Invalid mod mode. Defaulting to Vanilla behavior.");
			}
		}
	}
}