Decompiled source of JordsCompanions v0.5.8

BepInEx/plugins/JordsCompanions/JordsCompanions.dll

Decompiled 12 hours ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using HarmonyLib;
using Jotunn.Configs;
using Jotunn.Entities;
using Jotunn.Managers;
using Microsoft.CodeAnalysis;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("JordsCompanions")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("0.5.8.0")]
[assembly: AssemblyInformationalVersion("0.5.8")]
[assembly: AssemblyProduct("JordsCompanions")]
[assembly: AssemblyTitle("JordsCompanions")]
[assembly: AssemblyVersion("0.5.8.0")]
[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 JordsCompanions
{
	[BepInPlugin("com.jordscompanions.valheim", "Jord's Companions", "0.5.8")]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	public class Plugin : BaseUnityPlugin
	{
		private sealed class ReferenceEqualityComparer : IEqualityComparer<object>
		{
			public static readonly ReferenceEqualityComparer Instance = new ReferenceEqualityComparer();

			public new bool Equals(object x, object y)
			{
				return x == y;
			}

			public int GetHashCode(object obj)
			{
				return RuntimeHelpers.GetHashCode(obj);
			}
		}

		private static class PortalTravel
		{
			private sealed class Journey
			{
				public Player Player;

				public Vector3 Origin;

				public float Deadline;

				public readonly List<ZDOID> Companions = new List<ZDOID>();
			}

			private const string TravelUntilKey = "JC_PortalTravelUntil";

			private const float GatherRadius = 50f;

			private const float TravelTimeoutSeconds = 60f;

			private static Journey journey;

			private static long NetworkTicks()
			{
				if (!((Object)(object)ZNet.instance != (Object)null))
				{
					return 0L;
				}
				return ZNet.instance.GetTime().Ticks;
			}

			public static void Begin(Player player, bool distantTeleport)
			{
				//IL_004f: 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)
				if ((Object)(object)player == (Object)null || (Object)(object)player != (Object)(object)Player.m_localPlayer || ZDOMan.instance == null || (Object)(object)ZNetScene.instance == (Object)null)
				{
					return;
				}
				if (PortalTravel.journey != null)
				{
					Cancel("a new teleport began before the previous trip completed");
				}
				Journey journey = new Journey
				{
					Player = player,
					Origin = ((Component)player).transform.position,
					Deadline = Time.unscaledTime + 60f
				};
				string playerName = player.GetPlayerName();
				if (!string.IsNullOrEmpty(playerName))
				{
					GatherPrefab(journey, player, playerName, "JC_SpiritBoar");
					GatherPrefab(journey, player, playerName, "JC_SpiritWolf");
					if (journey.Companions.Count == 0)
					{
						Log.LogDebug((object)("Portal travel: no owned Spirit Boar/Wolf companions found within " + 50f + "m."));
						return;
					}
					PortalTravel.journey = journey;
					Log.LogInfo((object)("Portal travel started (" + (distantTeleport ? "portal/distant" : "short/dungeon") + "): secured " + journey.Companions.Count + " existing Boar/Wolf companion(s) for " + playerName + "."));
				}
			}

			private static void GatherPrefab(Journey pending, Player player, string ownerName, string prefabName)
			{
				//IL_00c8: Unknown result type (might be due to invalid IL or missing references)
				//IL_00d3: Unknown result type (might be due to invalid IL or missing references)
				//IL_0135: Unknown result type (might be due to invalid IL or missing references)
				//IL_014b: Unknown result type (might be due to invalid IL or missing references)
				//IL_01a9: Unknown result type (might be due to invalid IL or missing references)
				//IL_01bb: Unknown result type (might be due to invalid IL or missing references)
				List<ZDO> list = new List<ZDO>();
				int num = 0;
				try
				{
					while (!ZDOMan.instance.GetAllZDOsWithPrefabIterative(prefabName, list, ref num))
					{
					}
				}
				catch (Exception ex)
				{
					Log.LogError((object)("Portal travel: failed scanning " + prefabName + " ZDOs: " + ex));
					return;
				}
				long num2 = NetworkTicks() + TimeSpan.FromSeconds(60.0).Ticks;
				foreach (ZDO item in list)
				{
					if (item == null || !item.IsValid() || !string.Equals(item.GetString(ZDOVars.s_follow, ""), ownerName, StringComparison.Ordinal) || item.GetFloat(ZDOVars.s_health, 1f) <= 0f)
					{
						continue;
					}
					float num3 = Vector3.Distance(item.GetPosition(), ((Component)player).transform.position);
					if (num3 > 50f)
					{
						Log.LogDebug((object)("Portal travel: leaving " + prefabName + " outside gather radius (" + num3.ToString("0.0") + "m)."));
					}
					else if (!pending.Companions.Contains(item.m_uid))
					{
						GameObject val = ZNetScene.instance.FindInstance(item.m_uid);
						ZNetView val2 = (((Object)(object)val != (Object)null) ? val.GetComponent<ZNetView>() : null);
						if ((Object)(object)val2 != (Object)null && val2.IsValid())
						{
							val2.ClaimOwnership();
						}
						else
						{
							item.SetOwner(ZDOMan.GetSessionID());
						}
						item.Set("JC_PortalTravelUntil", num2);
						ZDOMan.instance.ForceSendZDO(item.m_uid);
						pending.Companions.Add(item.m_uid);
					}
				}
			}

			public static bool IsProtectedFromSummonCleanup(Tameable tameable)
			{
				if ((Object)(object)tameable == (Object)null || (Object)(object)ZNet.instance == (Object)null)
				{
					return false;
				}
				ZNetView component = ((Component)tameable).GetComponent<ZNetView>();
				if ((Object)(object)component == (Object)null || !component.IsValid())
				{
					return false;
				}
				ZDO zDO = component.GetZDO();
				if (zDO != null)
				{
					return zDO.GetLong("JC_PortalTravelUntil", 0L) > NetworkTicks();
				}
				return false;
			}

			public static void Finish(Player player)
			{
				//IL_003d: Unknown result type (might be due to invalid IL or missing references)
				//IL_0043: 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)
				//IL_0084: Unknown result type (might be due to invalid IL or missing references)
				//IL_0089: Unknown result type (might be due to invalid IL or missing references)
				//IL_008e: 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_0106: Unknown result type (might be due to invalid IL or missing references)
				//IL_0107: Unknown result type (might be due to invalid IL or missing references)
				//IL_010b: Unknown result type (might be due to invalid IL or missing references)
				//IL_011a: Unknown result type (might be due to invalid IL or missing references)
				//IL_013b: Unknown result type (might be due to invalid IL or missing references)
				//IL_01e9: Unknown result type (might be due to invalid IL or missing references)
				//IL_017e: Unknown result type (might be due to invalid IL or missing references)
				//IL_0192: Unknown result type (might be due to invalid IL or missing references)
				//IL_01b1: Unknown result type (might be due to invalid IL or missing references)
				//IL_01bd: Unknown result type (might be due to invalid IL or missing references)
				//IL_01c9: Unknown result type (might be due to invalid IL or missing references)
				//IL_01d8: Unknown result type (might be due to invalid IL or missing references)
				if (PortalTravel.journey == null || (Object)(object)player == (Object)null || (Object)(object)PortalTravel.journey.Player != (Object)(object)player)
				{
					return;
				}
				Journey journey = PortalTravel.journey;
				PortalTravel.journey = null;
				if (((Character)player).IsDead() || !(Vector3.Distance(((Component)player).transform.position, journey.Origin) > 2f))
				{
					ClearTravelMarkers(journey);
					Log.LogWarning((object)"Portal travel: teleport did not move the player; companions remain at their departure location.");
					return;
				}
				Vector3 val = ((Component)player).transform.position + Vector3.up * 0.15f;
				int num = 0;
				int num2 = 0;
				for (int i = 0; i < journey.Companions.Count; i++)
				{
					ZDO val2 = ((ZDOMan.instance != null) ? ZDOMan.instance.GetZDO(journey.Companions[i]) : null);
					if (val2 == null || !val2.IsValid() || val2.GetFloat(ZDOVars.s_health, 1f) <= 0f)
					{
						num2++;
						continue;
					}
					val2.SetOwner(ZDOMan.GetSessionID());
					val2.Set("JC_PortalTravelUntil", 0L);
					Vector3 position = val;
					val2.SetPosition(position);
					val2.SetRotation(((Component)player).transform.rotation);
					GameObject val3 = (((Object)(object)ZNetScene.instance != (Object)null) ? ZNetScene.instance.FindInstance(val2.m_uid) : null);
					if ((Object)(object)val3 != (Object)null)
					{
						ZNetView component = val3.GetComponent<ZNetView>();
						if ((Object)(object)component != (Object)null && component.IsValid())
						{
							component.ClaimOwnership();
						}
						val3.transform.position = position;
						val3.transform.rotation = ((Component)player).transform.rotation;
						Rigidbody component2 = val3.GetComponent<Rigidbody>();
						if ((Object)(object)component2 != (Object)null)
						{
							component2.linearVelocity = Vector3.zero;
							component2.angularVelocity = Vector3.zero;
							component2.position = position;
							component2.rotation = ((Component)player).transform.rotation;
						}
					}
					ZDOMan.instance.ForceSendZDO(val2.m_uid);
					num++;
				}
				Log.LogInfo((object)("Portal travel completed: relocated " + num + " existing companion(s) beside " + player.GetPlayerName() + "; missing/dead during travel=" + num2 + ". No summon costs charged."));
			}

			private static void ClearTravelMarkers(Journey pending)
			{
				//IL_001b: Unknown result type (might be due to invalid IL or missing references)
				//IL_0020: Unknown result type (might be due to invalid IL or missing references)
				//IL_0026: Unknown result type (might be due to invalid IL or missing references)
				//IL_0055: Unknown result type (might be due to invalid IL or missing references)
				if (pending == null || ZDOMan.instance == null)
				{
					return;
				}
				foreach (ZDOID companion in pending.Companions)
				{
					ZDO zDO = ZDOMan.instance.GetZDO(companion);
					if (zDO != null && zDO.IsValid())
					{
						zDO.SetOwner(ZDOMan.GetSessionID());
						zDO.Set("JC_PortalTravelUntil", 0L);
						ZDOMan.instance.ForceSendZDO(companion);
					}
				}
			}

			public static void CheckTimeout()
			{
				if (journey != null && !(Time.unscaledTime <= journey.Deadline))
				{
					Journey pending = journey;
					journey = null;
					ClearTravelMarkers(pending);
					Log.LogWarning((object)"Portal travel timed out; cleared temporary companion travel protection.");
				}
			}

			private static void Cancel(string reason)
			{
				Journey pending = journey;
				journey = null;
				ClearTravelMarkers(pending);
				Log.LogWarning((object)("Portal travel cancelled: " + reason + "."));
			}
		}

		[HarmonyPatch(typeof(Player), "TeleportTo", new Type[]
		{
			typeof(Vector3),
			typeof(Quaternion),
			typeof(bool)
		})]
		private static class CompanionTravelStartPatch
		{
			private static void Postfix(Player __instance, bool distantTeleport, bool __result)
			{
				if (__result && (Object)(object)__instance == (Object)(object)Player.m_localPlayer)
				{
					PortalTravel.Begin(__instance, distantTeleport);
				}
			}
		}

		[HarmonyPatch(typeof(Player), "UpdateTeleport")]
		private static class CompanionTravelFinishPatch
		{
			private static void Prefix(Player __instance, out bool __state)
			{
				__state = (Object)(object)__instance != (Object)null && ((Character)__instance).IsTeleporting();
			}

			private static void Postfix(Player __instance, bool __state)
			{
				if (__state && (Object)(object)__instance != (Object)null && !((Character)__instance).IsTeleporting())
				{
					PortalTravel.Finish(__instance);
				}
			}
		}

		[HarmonyPatch(typeof(Tameable), "UpdateSummon")]
		private static class CompanionTravelSummonProtectionPatch
		{
			private static bool Prefix(Tameable __instance)
			{
				if ((Object)(object)__instance == (Object)null || !IsAnySpirit(((Component)__instance).gameObject))
				{
					return true;
				}
				return !PortalTravel.IsProtectedFromSummonCleanup(__instance);
			}
		}

		[HarmonyPatch(typeof(Tameable), "UpdateSavedFollowTarget")]
		private static class CompanionTravelFollowProtectionPatch
		{
			private static bool Prefix(Tameable __instance)
			{
				if ((Object)(object)__instance == (Object)null || !IsAnySpirit(((Component)__instance).gameObject))
				{
					return true;
				}
				return !PortalTravel.IsProtectedFromSummonCleanup(__instance);
			}
		}

		[HarmonyPatch(typeof(Attack), "Start", new Type[]
		{
			typeof(Humanoid),
			typeof(Rigidbody),
			typeof(ZSyncAnimation),
			typeof(CharacterAnimEvent),
			typeof(VisEquipment),
			typeof(ItemData),
			typeof(Attack),
			typeof(float),
			typeof(float)
		})]
		private static class BoarNatureMagicCostPatch
		{
			private static void Prefix(Attack __instance, Humanoid character, ItemData weapon)
			{
				//IL_0024: Unknown result type (might be due to invalid IL or missing references)
				//IL_002d: Unknown result type (might be due to invalid IL or missing references)
				if (__instance != null && character is Player && (IsBoarStaff(weapon) || IsWolfStaff(weapon) || IsBearStaff(weapon)) && (int)NatureMagicSkillType != 0)
				{
					float num = Mathf.Clamp(((Character)character).GetSkillLevel(NatureMagicSkillType), 0f, 100f);
					float num2 = 40f - num * 0.2f;
					float num3 = ((!IsWolfStaff(weapon)) ? ((boarStaminaCost != null) ? boarStaminaCost.Value : 20f) : ((wolfStaminaCost != null) ? wolfStaminaCost.Value : 20f));
					float num4 = num3 * (1f - num * 0.005f);
					__instance.m_attackHealth = 0f;
					__instance.m_attackHealthPercentage = Mathf.Clamp(num2, 20f, 40f);
					__instance.m_attackStamina = Mathf.Max(num3 * 0.5f, num4);
					__instance.m_attackEitr = 0f;
				}
			}
		}

		[HarmonyPatch(typeof(SpawnAbility), "Setup", new Type[]
		{
			typeof(Character),
			typeof(Vector3),
			typeof(float),
			typeof(HitData),
			typeof(ItemData),
			typeof(ItemData)
		})]
		private static class BoarSpawnSetupPatch
		{
			private static void Prefix(SpawnAbility __instance, ItemData item)
			{
				//IL_003c: 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_0043: 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_004f: 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_0062: Expected O, but got Unknown
				if (!((Object)(object)__instance == (Object)null) && IsAnyCompanionStaff(item))
				{
					__instance.m_minToSpawn = 1;
					__instance.m_maxToSpawn = 1;
					__instance.m_maxSpawned = 0;
					__instance.m_commandOnSpawn = true;
					__instance.m_setMaxInstancesFromWeaponLevel = true;
					__instance.m_levelUpSettings = new List<LevelUpSettings>
					{
						new LevelUpSettings
						{
							m_skill = (SkillType)0,
							m_skillLevel = 0,
							m_setLevel = 1,
							m_maxSpawns = 1
						}
					};
				}
			}
		}

		[HarmonyPatch(typeof(Tameable), "UnsummonMaxInstances", new Type[] { typeof(int) })]
		private static class BoarSummonCapacityPatch
		{
			private static void Prefix(Tameable __instance, ref int maxInstances)
			{
				if (!((Object)(object)__instance == (Object)null) && IsAnySpirit(((Component)__instance).gameObject))
				{
					maxInstances = GetBoarCapacityForQuality(maxInstances);
				}
			}
		}

		[HarmonyPatch(typeof(Humanoid), "StartAttack", new Type[]
		{
			typeof(Character),
			typeof(bool)
		})]
		private static class BoarSecondaryAttackPatch
		{
			private static bool Prefix(Humanoid __instance, bool secondaryAttack, ref bool __result)
			{
				if (secondaryAttack)
				{
					Player val = (Player)(object)((__instance is Player) ? __instance : null);
					if (val != null)
					{
						ItemData currentWeapon = __instance.GetCurrentWeapon();
						if (!IsAnyCompanionStaff(currentWeapon))
						{
							return true;
						}
						bool flag = IsBearStaff(currentWeapon);
						bool flag2 = IsWolfStaff(currentWeapon);
						int num = (flag ? DismissOwnedGreatBear(val) : DismissOwnedCompanions(val, flag2));
						string text = (flag ? "Spirit of the Great Bear" : (flag2 ? "Spirit of the Wolf" : "Spirit of the Boar"));
						if (num > 0)
						{
							((Character)val).Message((MessageType)2, "Dismissed " + num + ((num == 1) ? (" " + text + ".") : (" " + text + " companions.")), 0, (Sprite)null, false);
						}
						else
						{
							((Character)val).Message((MessageType)2, "You have no " + text + " companions to dismiss.", 0, (Sprite)null, false);
						}
						__result = true;
						return false;
					}
				}
				return true;
			}
		}

		[HarmonyPatch(typeof(Character), "Damage", new Type[] { typeof(HitData) })]
		private static class GreatBearOutgoingDamageDiagnosticPatch
		{
			private static void Prefix(Character __instance, HitData hit)
			{
				//IL_006e: Unknown result type (might be due to invalid IL or missing references)
				if (hit == null || (Object)(object)__instance == (Object)null)
				{
					return;
				}
				try
				{
					Character attacker = hit.GetAttacker();
					if ((Object)(object)attacker == (Object)null || !IsGreatBear(((Component)attacker).gameObject))
					{
						return;
					}
					ZNetView component = ((Component)attacker).GetComponent<ZNetView>();
					ZDO val = (((Object)(object)component != (Object)null && component.IsValid()) ? component.GetZDO() : null);
					float num = ((val != null) ? val.GetFloat("JC_GreatBearNatureDamageMultiplier", 1f) : 1f);
					object obj = hit.m_damage;
					if (obj != null && num > 1f)
					{
						FieldInfo[] fields = obj.GetType().GetFields(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
						foreach (FieldInfo fieldInfo in fields)
						{
							if (!(fieldInfo.FieldType != typeof(float)))
							{
								float num2 = (float)fieldInfo.GetValue(obj);
								if (num2 != 0f)
								{
									fieldInfo.SetValue(obj, num2 * num);
								}
							}
						}
						FieldInfo fieldInfo2 = FindField(typeof(HitData), "m_damage");
						if (fieldInfo2 != null)
						{
							fieldInfo2.SetValue(hit, obj);
						}
					}
					if (bearDamageDiagnostics == null || !bearDamageDiagnostics.Value)
					{
						return;
					}
					List<string> list = new List<string>();
					if (obj != null)
					{
						FieldInfo[] fields = obj.GetType().GetFields(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
						foreach (FieldInfo fieldInfo3 in fields)
						{
							if (fieldInfo3.FieldType == typeof(float))
							{
								float num3 = (float)fieldInfo3.GetValue(obj);
								if (num3 != 0f)
								{
									list.Add(fieldInfo3.Name + "=" + num3.ToString("0.##"));
								}
							}
						}
					}
					string name = ((Object)((Component)attacker).gameObject).name;
					string text = "<attack unavailable>";
					Humanoid val2 = (Humanoid)(object)((attacker is Humanoid) ? attacker : null);
					if ((Object)(object)val2 != (Object)null)
					{
						FieldInfo fieldInfo4 = FindField(typeof(Humanoid), "m_currentAttack");
						object obj2 = ((fieldInfo4 != null) ? fieldInfo4.GetValue(val2) : null);
						if (obj2 != null)
						{
							FieldInfo fieldInfo5 = FindField(obj2.GetType(), "m_attackAnimation");
							FieldInfo fieldInfo6 = FindField(obj2.GetType(), "m_attackType");
							string text2 = ((fieldInfo5 != null) ? Convert.ToString(fieldInfo5.GetValue(obj2)) : "");
							string text3 = ((fieldInfo6 != null) ? Convert.ToString(fieldInfo6.GetValue(obj2)) : "");
							text = "animation='" + text2 + "', type='" + text3 + "'";
						}
					}
					ManualLogSource log = Log;
					if (log != null)
					{
						log.LogInfo((object)("[Great Bear Damage] attacker=" + name + ", attack=" + text + ", target=" + ((Object)((Component)__instance).gameObject).name + ", damage=" + string.Join(", ", list.ToArray()) + ", NatureMagicMultiplier=" + num.ToString("0.###") + ", total=" + hit.GetTotalDamage().ToString("0.##")));
					}
				}
				catch (Exception ex)
				{
					ManualLogSource log2 = Log;
					if (log2 != null)
					{
						log2.LogWarning((object)("[Great Bear Damage] Could not inspect outgoing hit: " + ex.Message));
					}
				}
			}
		}

		[HarmonyPatch(typeof(Tameable), "Command", new Type[]
		{
			typeof(Humanoid),
			typeof(bool)
		})]
		private static class CompanionNatureMagicStatsPatch
		{
			private static void Postfix(Tameable __instance, Humanoid user)
			{
				ApplyNatureMagicStats(__instance, user);
				if (!((Object)(object)__instance == (Object)null) && IsGreatBear(((Component)__instance).gameObject) && !((Object)(object)user == (Object)null))
				{
					ItemData currentWeapon = user.GetCurrentWeapon();
					int quality = ((currentWeapon == null || currentWeapon.m_shared == null || !string.Equals(currentWeapon.m_shared.m_name, "$item_jc_spiritbear", StringComparison.Ordinal)) ? 1 : Mathf.Clamp(currentWeapon.m_quality, 1, 4));
					GreatBearSummonLifetime component = ((Component)__instance).GetComponent<GreatBearSummonLifetime>();
					if ((Object)(object)component != (Object)null)
					{
						component.Begin(quality);
					}
				}
			}
		}

		public const string PluginGuid = "com.jordscompanions.valheim";

		public const string PluginName = "Jord's Companions";

		public const string PluginVersion = "0.5.8";

		private const string BoarStaffPrefabName = "JC_StaffSpiritBoar";

		private const string BoarSpiritPrefabName = "JC_SpiritBoar";

		private const string BoarProjectilePrefabName = "JC_SpiritBoar_Projectile";

		private const string WolfStaffPrefabName = "JC_StaffSpiritWolf";

		private const string WolfSpiritPrefabName = "JC_SpiritWolf";

		private const string WolfProjectilePrefabName = "JC_SpiritWolf_Projectile";

		private const string BearStaffPrefabName = "JC_StaffSpiritBear";

		private const string BearSpiritPrefabName = "JC_SpiritBear";

		private const string BearProjectilePrefabName = "JC_SpiritBear_Projectile";

		private const string BoarCastingEffectPrefabName = "JC_fx_summon_skeleton_Boar";

		private const string WolfCastingEffectPrefabName = "JC_fx_summon_skeleton_Wolf";

		private const string BearCastingEffectPrefabName = "JC_fx_summon_skeleton_Bear";

		private const string VanillaCastingEffectPrefabName = "fx_summon_skeleton";

		private const string VanillaBearSpiritPrefabName = "Bjorn_spiritcaller";

		private const string VanillaStaffPrefabName = "StaffSpiritCaller";

		private const string VanillaBoarSpiritPrefabName = "Boar_spiritcaller";

		private const string VanillaWolfSpiritPrefabName = "Wolf_spiritcaller";

		private const string NatureMagicIdentifier = "com.jordscompanions.naturemagic";

		private static Texture2D natureMagicTexture;

		private static Sprite natureMagicIcon;

		private static Sprite spiritBoarStaffIcon;

		private static Sprite spiritWolfStaffIcon;

		private static Sprite spiritBearStaffIcon;

		private static readonly string StaffIconDirectoryName = Path.Combine("Assets", "Icons");

		internal static ManualLogSource Log;

		private static ConfigEntry<float> boarStaminaCost;

		private static ConfigEntry<float> wolfStaminaCost;

		private static ConfigEntry<bool> bearDamageDiagnostics;

		private Harmony harmony;

		private AssetBundle companionAssetBundle;

		private GameObject spiritBoarSkullModel;

		private GameObject spiritWolfSkullModel;

		private GameObject spiritBearSkullModel;

		private const string CompanionAssetBundleFileName = "jordscompanions";

		private const string SpiritBoarSkullAssetName = "SpiritBoarSkull";

		private const string SpiritWolfSkullAssetName = "SpiritWolfSkull";

		private const string SpiritBearSkullAssetName = "SpiritBearSkull";

		private bool extractionStarted;

		private float nextCompanionRecoveryTime;

		private static float nextCompanionRecoveryDiagnosticTime;

		private bool companionRecoveryManagerStarted;

		private const float CompanionRecoveryInterval = 2f;

		private const float CompanionRecoveryDistance = 50f;

		private const float CompanionRecoveryPlacementRadius = 2.75f;

		private static readonly string[] TrophyPrefabs = new string[7] { "TrophyBoar", "TrophyWolf", "TrophyBjorn", "TrophySGolem", "TrophySurtling", "TrophyLox", "TrophyAsksvin" };

		public static SkillType NatureMagicSkillType { get; private set; }

		private void Awake()
		{
			//IL_001d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0027: Expected O, but got Unknown
			Log = ((BaseUnityPlugin)this).Logger;
			LoadCompanionAssetBundle();
			LoadStaffIcons();
			harmony = new Harmony("com.jordscompanions.valheim");
			harmony.PatchAll(typeof(Plugin).Assembly);
			Log.LogInfo((object)"Installed companion summon, Nature Magic cost, capacity, and dismissal patches.");
			boarStaminaCost = ((BaseUnityPlugin)this).Config.Bind<float>("Spirit of the Boar", "Stamina Cost", 20f, "Base stamina cost before Nature Magic reduces it.");
			wolfStaminaCost = ((BaseUnityPlugin)this).Config.Bind<float>("Spirit of the Wolf", "Stamina Cost", 20f, "Base stamina cost before Nature Magic reduces it.");
			bearDamageDiagnostics = ((BaseUnityPlugin)this).Config.Bind<bool>("Spirit of the Great Bear", "Log Outgoing Attack Damage", true, "Logs each hit dealt by the summoned Spirit Bear after Nature Magic scaling, including its damage-type breakdown. This setting controls logging only.");
			AddLocalizations();
			RegisterNatureMagicSkill();
			PrefabManager.OnVanillaPrefabsAvailable += RegisterSpiritOfTheBoar;
			PrefabManager.OnVanillaPrefabsAvailable += RegisterSpiritOfTheWolf;
			PrefabManager.OnVanillaPrefabsAvailable += RegisterSpiritOfTheGreatBear;
			Log.LogInfo((object)"Jord's Companions 0.5.8 loaded.");
		}

		private void OnDestroy()
		{
			if ((Object)(object)companionAssetBundle != (Object)null)
			{
				companionAssetBundle.Unload(false);
				companionAssetBundle = null;
				spiritBoarSkullModel = null;
				spiritWolfSkullModel = null;
				spiritBearSkullModel = null;
			}
			if (harmony != null)
			{
				harmony.UnpatchSelf();
				harmony = null;
			}
			PrefabManager.OnVanillaPrefabsAvailable -= RegisterSpiritOfTheBoar;
			PrefabManager.OnVanillaPrefabsAvailable -= RegisterSpiritOfTheWolf;
			PrefabManager.OnVanillaPrefabsAvailable -= RegisterSpiritOfTheGreatBear;
		}

		private void LoadCompanionAssetBundle()
		{
			string directoryName = Path.GetDirectoryName(((BaseUnityPlugin)this).Info.Location);
			if (string.IsNullOrEmpty(directoryName))
			{
				Log.LogError((object)"Could not determine the Jord's Companions plugin directory.");
				return;
			}
			string text = Path.Combine(directoryName, "jordscompanions");
			if (!File.Exists(text))
			{
				Log.LogWarning((object)("AssetBundle not found: " + text + ". Copy the built 'jordscompanions' file beside JordsCompanions.dll."));
				return;
			}
			try
			{
				companionAssetBundle = AssetBundle.LoadFromFile(text);
				if ((Object)(object)companionAssetBundle == (Object)null)
				{
					Log.LogError((object)("Unity failed to load the AssetBundle: " + text));
					return;
				}
				Log.LogInfo((object)("Loaded Jord's Companions AssetBundle: " + text));
				spiritBoarSkullModel = companionAssetBundle.LoadAsset<GameObject>("SpiritBoarSkull");
				if ((Object)(object)spiritBoarSkullModel == (Object)null)
				{
					Log.LogError((object)"AssetBundle loaded, but prefab 'SpiritBoarSkull' was not found. Confirm SpiritBoarSkull is assigned to the jordscompanions bundle and rebuild it.");
					return;
				}
				Log.LogInfo((object)("Loaded custom skull prefab: " + ((Object)spiritBoarSkullModel).name));
				spiritWolfSkullModel = companionAssetBundle.LoadAsset<GameObject>("SpiritWolfSkull");
				if ((Object)(object)spiritWolfSkullModel == (Object)null)
				{
					Log.LogError((object)"AssetBundle loaded, but prefab 'SpiritWolfSkull' was not found. Confirm SpiritWolfSkull is assigned to the jordscompanions bundle and rebuild it.");
					return;
				}
				Log.LogInfo((object)("Loaded custom skull prefab: " + ((Object)spiritWolfSkullModel).name));
				spiritBearSkullModel = companionAssetBundle.LoadAsset<GameObject>("SpiritBearSkull");
				if ((Object)(object)spiritBearSkullModel == (Object)null)
				{
					Log.LogError((object)"AssetBundle loaded, but prefab 'SpiritBearSkull' was not found. Confirm SpiritBearSkull is assigned to the jordscompanions bundle and rebuild it.");
				}
				else
				{
					Log.LogInfo((object)("Loaded custom skull prefab: " + ((Object)spiritBearSkullModel).name));
				}
			}
			catch (Exception ex)
			{
				Log.LogError((object)("Failed to load Jord's Companions AssetBundle: " + ex));
				if ((Object)(object)companionAssetBundle != (Object)null)
				{
					companionAssetBundle.Unload(false);
					companionAssetBundle = null;
				}
			}
		}

		private void LoadStaffIcons()
		{
			string directoryName = Path.GetDirectoryName(((BaseUnityPlugin)this).Info.Location);
			if (string.IsNullOrEmpty(directoryName))
			{
				Log.LogError((object)"Could not determine the plugin directory; custom staff icons cannot be loaded.");
				return;
			}
			string iconDirectory = Path.Combine(directoryName, StaffIconDirectoryName);
			spiritBoarStaffIcon = LoadStaffIcon(iconDirectory, "SpiritBoarSkull.png", "Spirit of the Boar");
			spiritWolfStaffIcon = LoadStaffIcon(iconDirectory, "SpiritWolfSkull.png", "Spirit of the Wolf");
			spiritBearStaffIcon = LoadStaffIcon(iconDirectory, "SpiritBearSkull.png", "Spirit of the Great Bear");
		}

		private Sprite LoadStaffIcon(string iconDirectory, string fileName, string displayName)
		{
			//IL_0031: Unknown result type (might be due to invalid IL or missing references)
			//IL_0037: Expected O, but got Unknown
			//IL_009f: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ae: Unknown result type (might be due to invalid IL or missing references)
			string text = Path.Combine(iconDirectory, fileName);
			if (!File.Exists(text))
			{
				Log.LogError((object)("Missing " + displayName + " inventory icon: " + text));
				return null;
			}
			Texture2D val = new Texture2D(2, 2, (TextureFormat)4, false);
			try
			{
				byte[] array = File.ReadAllBytes(text);
				if (!ImageConversion.LoadImage(val, array, false))
				{
					Log.LogError((object)("Unity could not decode " + displayName + " inventory icon: " + text));
					Object.Destroy((Object)(object)val);
					return null;
				}
				((Object)val).name = fileName;
				((Texture)val).filterMode = (FilterMode)1;
				((Texture)val).wrapMode = (TextureWrapMode)1;
				Sprite val2 = Sprite.Create(val, new Rect(0f, 0f, (float)((Texture)val).width, (float)((Texture)val).height), new Vector2(0.5f, 0.5f), 100f);
				if ((Object)(object)val2 == (Object)null)
				{
					Log.LogError((object)("Unity could not create the " + displayName + " inventory sprite."));
					Object.Destroy((Object)(object)val);
					return null;
				}
				((Object)val2).name = Path.GetFileNameWithoutExtension(fileName);
				Log.LogInfo((object)("Loaded " + displayName + " inventory icon: " + ((Texture)val).width + "x" + ((Texture)val).height + " from " + text));
				return val2;
			}
			catch (Exception ex)
			{
				Log.LogError((object)("Failed loading " + displayName + " inventory icon: " + ex));
				Object.Destroy((Object)(object)val);
				return null;
			}
		}

		private static bool ApplyStaffIcon(ItemDrop itemDrop, Sprite icon, string displayName)
		{
			if ((Object)(object)itemDrop == (Object)null || itemDrop.m_itemData == null || itemDrop.m_itemData.m_shared == null)
			{
				Log.LogError((object)("Cannot assign " + displayName + " icon: staff ItemDrop/shared data is missing."));
				return false;
			}
			if ((Object)(object)icon == (Object)null)
			{
				Log.LogError((object)("Cannot assign " + displayName + " icon: sprite failed to load."));
				return false;
			}
			itemDrop.m_itemData.m_shared.m_icons = (Sprite[])(object)new Sprite[1] { icon };
			Log.LogInfo((object)("Assigned custom inventory icon to " + displayName + "."));
			return true;
		}

		private void Update()
		{
			if (!(Time.time < nextCompanionRecoveryTime))
			{
				nextCompanionRecoveryTime = Time.time + 2f;
				if (!companionRecoveryManagerStarted && (Object)(object)Player.m_localPlayer != (Object)null)
				{
					companionRecoveryManagerStarted = true;
					Log.LogInfo((object)("Player-driven companion recovery manager started for local player '" + Player.m_localPlayer.GetPlayerName() + "'. Check interval=" + 2f + "s; distance threshold=" + 50f + "m."));
				}
				RecoverLocalPlayerCompanions();
				PortalTravel.CheckTimeout();
			}
		}

		private static void RecoverLocalPlayerCompanions()
		{
			Player localPlayer = Player.m_localPlayer;
			if ((Object)(object)localPlayer == (Object)null)
			{
				Log.LogDebug((object)"Companion recovery: waiting for local player.");
			}
			else
			{
				if (((Character)localPlayer).IsTeleporting())
				{
					return;
				}
				if (ZDOMan.instance == null || (Object)(object)ZNet.instance == (Object)null || (Object)(object)ZNetScene.instance == (Object)null)
				{
					Log.LogDebug((object)"Companion recovery: waiting for ZDOMan, ZNet, or ZNetScene.");
					return;
				}
				string playerName = localPlayer.GetPlayerName();
				if (string.IsNullOrEmpty(playerName))
				{
					Log.LogWarning((object)"Companion recovery: local player name is empty; cannot match followers.");
					return;
				}
				RecoverCompanionPrefab(localPlayer, playerName, "JC_SpiritBoar");
				RecoverCompanionPrefab(localPlayer, playerName, "JC_SpiritWolf");
				if (Time.time >= nextCompanionRecoveryDiagnosticTime)
				{
					nextCompanionRecoveryDiagnosticTime = Time.time + 10f;
				}
			}
		}

		private unsafe static void RecoverCompanionPrefab(Player player, string ownerName, string prefabName)
		{
			//IL_0610: Unknown result type (might be due to invalid IL or missing references)
			//IL_0615: Unknown result type (might be due to invalid IL or missing references)
			//IL_0769: Unknown result type (might be due to invalid IL or missing references)
			//IL_076e: Unknown result type (might be due to invalid IL or missing references)
			//IL_017e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0189: Unknown result type (might be due to invalid IL or missing references)
			//IL_019c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0243: Unknown result type (might be due to invalid IL or missing references)
			//IL_0248: Unknown result type (might be due to invalid IL or missing references)
			//IL_068b: Unknown result type (might be due to invalid IL or missing references)
			//IL_069a: Unknown result type (might be due to invalid IL or missing references)
			//IL_06ab: Unknown result type (might be due to invalid IL or missing references)
			//IL_06df: Unknown result type (might be due to invalid IL or missing references)
			//IL_06e4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fb: Unknown result type (might be due to invalid IL or missing references)
			//IL_0100: Unknown result type (might be due to invalid IL or missing references)
			//IL_029b: Unknown result type (might be due to invalid IL or missing references)
			//IL_02a0: Unknown result type (might be due to invalid IL or missing references)
			//IL_0146: Unknown result type (might be due to invalid IL or missing references)
			//IL_014b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0383: Unknown result type (might be due to invalid IL or missing references)
			//IL_0388: Unknown result type (might be due to invalid IL or missing references)
			//IL_0310: Unknown result type (might be due to invalid IL or missing references)
			//IL_0315: Unknown result type (might be due to invalid IL or missing references)
			//IL_0391: Unknown result type (might be due to invalid IL or missing references)
			//IL_03a5: Unknown result type (might be due to invalid IL or missing references)
			//IL_0421: Unknown result type (might be due to invalid IL or missing references)
			//IL_0430: Unknown result type (might be due to invalid IL or missing references)
			//IL_0441: Unknown result type (might be due to invalid IL or missing references)
			//IL_044d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0458: Unknown result type (might be due to invalid IL or missing references)
			//IL_03d7: Unknown result type (might be due to invalid IL or missing references)
			//IL_03ea: Unknown result type (might be due to invalid IL or missing references)
			//IL_03f6: Unknown result type (might be due to invalid IL or missing references)
			//IL_0402: Unknown result type (might be due to invalid IL or missing references)
			//IL_0561: Unknown result type (might be due to invalid IL or missing references)
			//IL_0566: Unknown result type (might be due to invalid IL or missing references)
			//IL_05bf: Unknown result type (might be due to invalid IL or missing references)
			//IL_05c4: Unknown result type (might be due to invalid IL or missing references)
			//IL_0494: Unknown result type (might be due to invalid IL or missing references)
			//IL_0499: Unknown result type (might be due to invalid IL or missing references)
			//IL_050b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0510: Unknown result type (might be due to invalid IL or missing references)
			List<ZDO> list = new List<ZDO>();
			int num = 0;
			int num2 = 0;
			int num3 = 0;
			int num4 = 0;
			int num5 = 0;
			int num6 = 0;
			int num7 = 0;
			int num8 = 0;
			int num9 = 0;
			try
			{
				while (!ZDOMan.instance.GetAllZDOsWithPrefabIterative(prefabName, list, ref num))
				{
				}
			}
			catch (Exception ex)
			{
				Log.LogError((object)("Companion recovery: ZDO scan failed for " + prefabName + ": " + ex));
				return;
			}
			foreach (ZDO item in list)
			{
				if (item == null || !item.IsValid())
				{
					continue;
				}
				string text = item.GetString(ZDOVars.s_follow, "");
				Vector3 position;
				if (!string.Equals(text, ownerName, StringComparison.Ordinal))
				{
					if (string.IsNullOrEmpty(text))
					{
						num8++;
					}
					else
					{
						num7++;
					}
					if (num9 < 3 && Time.time >= nextCompanionRecoveryDiagnosticTime)
					{
						ManualLogSource log = Log;
						string[] obj = new string[11]
						{
							"Companion recovery diagnostic: found ", prefabName, " ZDO ", null, null, null, null, null, null, null,
							null
						};
						ZDOID uid = item.m_uid;
						obj[3] = ((object)(*(ZDOID*)(&uid))/*cast due to .constrained prefix*/).ToString();
						obj[4] = " but s_follow='";
						obj[5] = (string.IsNullOrEmpty(text) ? "<empty>" : text);
						obj[6] = "', local player='";
						obj[7] = ownerName;
						obj[8] = "', position=";
						position = item.GetPosition();
						obj[9] = ((Vector3)(ref position)).ToString("F1");
						obj[10] = ".";
						log.LogInfo((object)string.Concat(obj));
						num9++;
					}
					continue;
				}
				num2++;
				float num10 = Vector3.Distance(item.GetPosition(), ((Component)player).transform.position);
				GameObject val = ZNetScene.instance.FindInstance(item.m_uid);
				if (num10 <= 50f)
				{
					if ((Object)(object)val != (Object)null)
					{
						num4++;
					}
					else
					{
						num5++;
					}
					continue;
				}
				num3++;
				if ((Object)(object)val != (Object)null)
				{
					num4++;
					Character component = val.GetComponent<Character>();
					ZNetView component2 = val.GetComponent<ZNetView>();
					MonsterAI component3 = val.GetComponent<MonsterAI>();
					if ((Object)(object)component == (Object)null || (Object)(object)component2 == (Object)null || !component2.IsValid())
					{
						ManualLogSource log2 = Log;
						string[] obj2 = new string[5] { "Companion recovery: ", prefabName, " ZDO ", null, null };
						ZDOID uid = item.m_uid;
						obj2[3] = ((object)(*(ZDOID*)(&uid))/*cast due to .constrained prefix*/).ToString();
						obj2[4] = " is loaded but Character/ZNetView is missing or invalid.";
						log2.LogWarning((object)string.Concat(obj2));
						continue;
					}
					if (!component2.IsOwner())
					{
						ManualLogSource log3 = Log;
						string[] obj3 = new string[6] { "Companion recovery: loaded ", prefabName, " ", null, null, null };
						ZDOID uid = item.m_uid;
						obj3[3] = ((object)(*(ZDOID*)(&uid))/*cast due to .constrained prefix*/).ToString();
						obj3[4] = " is owned by another peer; waiting. ZDO owner=";
						obj3[5] = item.GetOwner().ToString();
						log3.LogDebug((object)string.Concat(obj3));
						continue;
					}
					if ((Object)(object)component3 != (Object)null && ((BaseAI)component3).IsAlerted())
					{
						ManualLogSource log4 = Log;
						string[] obj4 = new string[7] { "Companion recovery: deferred loaded ", prefabName, " ", null, null, null, null };
						ZDOID uid = item.m_uid;
						obj4[3] = ((object)(*(ZDOID*)(&uid))/*cast due to .constrained prefix*/).ToString();
						obj4[4] = " because it is alerted (";
						obj4[5] = num10.ToString("0.0");
						obj4[6] = "m away).";
						log4.LogInfo((object)string.Concat(obj4));
						continue;
					}
					if (!TryGetCompanionRecoveryPosition(player, out var destination))
					{
						Log.LogWarning((object)("Companion recovery: no safe landing point found for loaded " + prefabName + "."));
						continue;
					}
					Vector3 position2 = ((Component)component).transform.position;
					try
					{
						((Component)component).transform.position = destination;
						((Component)component).transform.rotation = ((Component)player).transform.rotation;
						Rigidbody[] componentsInChildren = ((Component)component).GetComponentsInChildren<Rigidbody>();
						foreach (Rigidbody val2 in componentsInChildren)
						{
							if (!((Object)(object)val2 == (Object)null))
							{
								val2.position = ((Component)val2).transform.position;
								val2.rotation = ((Component)val2).transform.rotation;
								val2.linearVelocity = Vector3.zero;
								val2.angularVelocity = Vector3.zero;
							}
						}
						Physics.SyncTransforms();
						item.SetPosition(destination);
						item.SetRotation(((Component)player).transform.rotation);
						ZDOMan.instance.ForceSendZDO(item.m_uid);
						float num11 = Vector3.Distance(item.GetPosition(), ((Component)player).transform.position);
						if (num11 > 50f)
						{
							ManualLogSource log5 = Log;
							string[] obj5 = new string[15]
							{
								"Companion recovery: moved loaded ", prefabName, " ", null, null, null, null, null, null, null,
								null, null, null, null, null
							};
							ZDOID uid = item.m_uid;
							obj5[3] = ((object)(*(ZDOID*)(&uid))/*cast due to .constrained prefix*/).ToString();
							obj5[4] = " but its ZDO is still ";
							obj5[5] = num11.ToString("0.0");
							obj5[6] = "m from ";
							obj5[7] = ownerName;
							obj5[8] = ". Old position=";
							obj5[9] = ((Vector3)(ref position2)).ToString("F1");
							obj5[10] = ", destination=";
							obj5[11] = ((Vector3)(ref destination)).ToString("F1");
							obj5[12] = ", ZDO position=";
							position = item.GetPosition();
							obj5[13] = ((Vector3)(ref position)).ToString("F1");
							obj5[14] = ".";
							log5.LogWarning((object)string.Concat(obj5));
						}
						else
						{
							num6++;
							ManualLogSource log6 = Log;
							string[] obj6 = new string[13]
							{
								"Companion recovery: moved loaded ", prefabName, " ", null, null, null, null, null, null, null,
								null, null, null
							};
							ZDOID uid = item.m_uid;
							obj6[3] = ((object)(*(ZDOID*)(&uid))/*cast due to .constrained prefix*/).ToString();
							obj6[4] = " from ";
							obj6[5] = num10.ToString("0.0");
							obj6[6] = "m to ";
							obj6[7] = num11.ToString("0.0");
							obj6[8] = "m from ";
							obj6[9] = ownerName;
							obj6[10] = ". New position=";
							position = item.GetPosition();
							obj6[11] = ((Vector3)(ref position)).ToString("F1");
							obj6[12] = ".";
							log6.LogInfo((object)string.Concat(obj6));
						}
					}
					catch (Exception ex2)
					{
						ManualLogSource log7 = Log;
						string[] obj7 = new string[6] { "Companion recovery: failed to move loaded ", prefabName, " ZDO ", null, null, null };
						ZDOID uid = item.m_uid;
						obj7[3] = ((object)(*(ZDOID*)(&uid))/*cast due to .constrained prefix*/).ToString();
						obj7[4] = ": ";
						obj7[5] = ex2?.ToString();
						log7.LogError((object)string.Concat(obj7));
					}
					continue;
				}
				num5++;
				if (!TryGetCompanionRecoveryPosition(player, out var destination2))
				{
					Log.LogWarning((object)("Companion recovery: no safe landing point found for unloaded " + prefabName + "."));
					continue;
				}
				try
				{
					item.SetOwner(ZDOMan.GetSessionID());
					item.SetPosition(destination2);
					item.SetRotation(((Component)player).transform.rotation);
					ZDOMan.instance.ForceSendZDO(item.m_uid);
					num6++;
					ManualLogSource log8 = Log;
					string[] obj8 = new string[11]
					{
						"Companion recovery: repositioned unloaded ", prefabName, " ZDO ", null, null, null, null, null, null, null,
						null
					};
					ZDOID uid = item.m_uid;
					obj8[3] = ((object)(*(ZDOID*)(&uid))/*cast due to .constrained prefix*/).ToString();
					obj8[4] = " for ";
					obj8[5] = ownerName;
					obj8[6] = " from ";
					obj8[7] = num10.ToString("0.0");
					obj8[8] = "m away. New position=";
					obj8[9] = ((Vector3)(ref destination2)).ToString("F1");
					obj8[10] = ".";
					log8.LogInfo((object)string.Concat(obj8));
				}
				catch (Exception ex3)
				{
					ManualLogSource log9 = Log;
					string[] obj9 = new string[6] { "Companion recovery: failed to reposition unloaded ", prefabName, " ZDO ", null, null, null };
					ZDOID uid = item.m_uid;
					obj9[3] = ((object)(*(ZDOID*)(&uid))/*cast due to .constrained prefix*/).ToString();
					obj9[4] = ": ";
					obj9[5] = ex3?.ToString();
					log9.LogError((object)string.Concat(obj9));
				}
			}
			if (Time.time >= nextCompanionRecoveryDiagnosticTime)
			{
				Log.LogInfo((object)("Companion recovery scan: " + prefabName + " ZDOs=" + list.Count + ", following local player=" + num2 + ", empty follow target=" + num8 + ", other follow target=" + num7 + ", beyond 50m=" + num3 + ", loaded=" + num4 + ", unloaded=" + num5 + ", recovered this scan=" + num6 + "."));
			}
		}

		private static bool TryGetCompanionRecoveryPosition(Player player, out Vector3 destination)
		{
			//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_0011: 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_0044: Unknown result type (might be due to invalid IL or missing references)
			//IL_0049: 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_0079: Unknown result type (might be due to invalid IL or missing references)
			//IL_007a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0084: Unknown result type (might be due to invalid IL or missing references)
			//IL_0089: 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_0091: Unknown result type (might be due to invalid IL or missing references)
			//IL_009b: 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)
			//IL_00a6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ab: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c2: 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_00cd: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00de: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fb: Unknown result type (might be due to invalid IL or missing references)
			//IL_0100: Unknown result type (might be due to invalid IL or missing references)
			//IL_0107: 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_0112: Unknown result type (might be due to invalid IL or missing references)
			//IL_0064: Unknown result type (might be due to invalid IL or missing references)
			//IL_0069: Unknown result type (might be due to invalid IL or missing references)
			//IL_0122: Unknown result type (might be due to invalid IL or missing references)
			//IL_0129: Unknown result type (might be due to invalid IL or missing references)
			//IL_012e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0133: Unknown result type (might be due to invalid IL or missing references)
			//IL_013d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0142: Unknown result type (might be due to invalid IL or missing references)
			//IL_0147: Unknown result type (might be due to invalid IL or missing references)
			//IL_015f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0173: Unknown result type (might be due to invalid IL or missing references)
			//IL_0178: Unknown result type (might be due to invalid IL or missing references)
			//IL_0182: Unknown result type (might be due to invalid IL or missing references)
			//IL_0187: Unknown result type (might be due to invalid IL or missing references)
			//IL_018c: Unknown result type (might be due to invalid IL or missing references)
			destination = Vector3.zero;
			Vector3 forward = ((Component)player).transform.forward;
			forward.y = 0f;
			if (((Vector3)(ref forward)).sqrMagnitude < 0.001f)
			{
				forward = Vector3.forward;
			}
			((Vector3)(ref forward)).Normalize();
			Vector3 right = ((Component)player).transform.right;
			right.y = 0f;
			if (((Vector3)(ref right)).sqrMagnitude < 0.001f)
			{
				right = Vector3.right;
			}
			((Vector3)(ref right)).Normalize();
			Vector3[] array = (Vector3[])(object)new Vector3[6]
			{
				-forward * 2.75f,
				-forward * 2.75f + right * 1.25f,
				-forward * 2.75f - right * 1.25f,
				right * 2.75f,
				-right * 2.75f,
				forward * 2.75f
			};
			RaycastHit val = default(RaycastHit);
			for (int i = 0; i < array.Length; i++)
			{
				if (Physics.Raycast(((Component)player).transform.position + array[i] + Vector3.up * 8f, Vector3.down, ref val, 24f, -5, (QueryTriggerInteraction)1) && !(((RaycastHit)(ref val)).normal.y < 0.55f))
				{
					destination = ((RaycastHit)(ref val)).point + Vector3.up * 0.2f;
					return true;
				}
			}
			return false;
		}

		private void AddLocalizations()
		{
			CustomLocalization localization = LocalizationManager.Instance.GetLocalization();
			string text = "English";
			localization.AddTranslation(ref text, new Dictionary<string, string>
			{
				{ "item_jc_spiritboar", "Spirit of the Boar" },
				{ "item_jc_spiritboar_desc", "Calls forth a spectral boar to fight at your side." },
				{ "jc_spiritboar_name", "Spirit of the Boar" },
				{ "item_jc_spiritwolf", "Spirit of the Wolf" },
				{ "item_jc_spiritwolf_desc", "Calls forth a spectral wolf to fight at your side." },
				{ "jc_spiritwolf_name", "Spirit of the Wolf" },
				{ "item_jc_spiritbear", "Spirit of the Great Bear" },
				{ "item_jc_spiritbear_desc", "Calls forth a powerful spectral bear for a limited time." },
				{ "jc_spiritbear_name", "Spirit of the Great Bear" },
				{ "skill_jc_naturemagic", "Nature Magic" },
				{ "skill_jc_naturemagic_desc", "Harness the living forces of nature to empower spirit callers and command companions." }
			});
		}

		private void RegisterNatureMagicSkill()
		{
			//IL_0047: Unknown result type (might be due to invalid IL or missing references)
			//IL_004c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0057: 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_006d: 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_0084: Expected O, but got Unknown
			//IL_008a: Unknown result type (might be due to invalid IL or missing references)
			//IL_009e: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a3: Unknown result type (might be due to invalid IL or missing references)
			try
			{
				if (SkillManager.Instance == null)
				{
					Log.LogError((object)"Jotunn SkillManager is unavailable. Nature Magic was not registered.");
					return;
				}
				natureMagicIcon = LoadNatureMagicIcon();
				if ((Object)(object)natureMagicIcon == (Object)null)
				{
					Log.LogError((object)"Could not load the embedded Nature Magic icon. Nature Magic was not registered.");
					return;
				}
				SkillConfig val = new SkillConfig
				{
					Identifier = "com.jordscompanions.naturemagic",
					Name = "$skill_jc_naturemagic",
					Description = "$skill_jc_naturemagic_desc",
					Icon = natureMagicIcon,
					IncreaseStep = 1f
				};
				NatureMagicSkillType = SkillManager.Instance.AddSkill(val);
				Log.LogInfo((object)("Registered Nature Magic skill. Identifier: com.jordscompanions.naturemagic, SkillType: " + ((object)NatureMagicSkillType/*cast due to .constrained prefix*/).ToString()));
			}
			catch (Exception ex)
			{
				Log.LogError((object)("Failed to register Nature Magic: " + ex));
			}
		}

		private Sprite LoadNatureMagicIcon()
		{
			//IL_0091: Unknown result type (might be due to invalid IL or missing references)
			//IL_009b: Expected O, but got Unknown
			//IL_0108: Unknown result type (might be due to invalid IL or missing references)
			//IL_0117: Unknown result type (might be due to invalid IL or missing references)
			Assembly executingAssembly = Assembly.GetExecutingAssembly();
			string text = null;
			string[] manifestResourceNames = executingAssembly.GetManifestResourceNames();
			foreach (string text2 in manifestResourceNames)
			{
				if (text2.EndsWith("Assets.SkillNatureMagic.png", StringComparison.OrdinalIgnoreCase))
				{
					text = text2;
					break;
				}
			}
			if (text == null)
			{
				Log.LogError((object)("Embedded resource ending in 'Assets.SkillNatureMagic.png' was not found. Available resources: " + string.Join(", ", executingAssembly.GetManifestResourceNames())));
				return null;
			}
			using Stream stream = executingAssembly.GetManifestResourceStream(text);
			if (stream == null)
			{
				return null;
			}
			using MemoryStream memoryStream = new MemoryStream();
			stream.CopyTo(memoryStream);
			byte[] array = memoryStream.ToArray();
			natureMagicTexture = new Texture2D(2, 2, (TextureFormat)4, false);
			((Object)natureMagicTexture).name = "JC_SkillNatureMagic";
			((Texture)natureMagicTexture).filterMode = (FilterMode)1;
			((Texture)natureMagicTexture).wrapMode = (TextureWrapMode)1;
			if (!ImageConversion.LoadImage(natureMagicTexture, array))
			{
				Object.Destroy((Object)(object)natureMagicTexture);
				natureMagicTexture = null;
				return null;
			}
			return Sprite.Create(natureMagicTexture, new Rect(0f, 0f, (float)((Texture)natureMagicTexture).width, (float)((Texture)natureMagicTexture).height), new Vector2(0.5f, 0.5f), 100f);
		}

		private void DiagnoseGreaterBearAssets()
		{
			PrefabManager.OnVanillaPrefabsAvailable -= DiagnoseGreaterBearAssets;
			Log.LogInfo((object)"[Greater Bear] Beginning read-only prefab discovery scan.");
			string[] array = new string[2] { "Bjorn_spiritcaller", "TrophyBjorn" };
			for (int i = 0; i < array.Length; i++)
			{
				LogGreaterBearPrefab(array[i]);
			}
			GameObject[] array2 = Resources.FindObjectsOfTypeAll<GameObject>();
			HashSet<string> hashSet = new HashSet<string>(StringComparer.OrdinalIgnoreCase);
			int num = 0;
			foreach (GameObject val in array2)
			{
				if (!((Object)(object)val == (Object)null))
				{
					string text = ((Object)val).name ?? string.Empty;
					if ((string.Equals(text, "Bjorn_spiritcaller", StringComparison.Ordinal) || string.Equals(text, "TrophyBjorn", StringComparison.Ordinal)) && hashSet.Add(text))
					{
						num++;
						LogGreaterBearObject(val, "Loaded object");
					}
				}
			}
			Log.LogInfo((object)("[Greater Bear] Final targeted scan complete. Matching loaded object names=" + num + ". No prefabs were modified or registered."));
		}

		private static void LogGreaterBearPrefab(string prefabName)
		{
			GameObject prefab = PrefabManager.Instance.GetPrefab(prefabName);
			if ((Object)(object)prefab == (Object)null)
			{
				Log.LogInfo((object)("[Greater Bear] Registered prefab lookup did not find: " + prefabName));
			}
			else
			{
				LogGreaterBearObject(prefab, "Registered prefab lookup");
			}
		}

		private static void LogGreaterBearObject(GameObject prefab, string source)
		{
			//IL_0058: Unknown result type (might be due to invalid IL or missing references)
			//IL_005d: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)prefab == (Object)null)
			{
				return;
			}
			Log.LogInfo((object)("[Greater Bear] " + source + ": name='" + ((Object)prefab).name + "', active=" + prefab.activeSelf + ", hideFlags=" + ((object)((Object)prefab).hideFlags/*cast due to .constrained prefix*/).ToString() + "."));
			Character component = prefab.GetComponent<Character>();
			if ((Object)(object)component != (Object)null)
			{
				Log.LogInfo((object)("[Greater Bear]   Character.m_name='" + component.m_name + "', m_health=" + component.m_health + "."));
				LogGreaterBearFieldValues(component, "Character");
				LogGreaterBearDamageModifiers(component);
			}
			Humanoid component2 = prefab.GetComponent<Humanoid>();
			if ((Object)(object)component2 != (Object)null)
			{
				LogGreaterBearAttackGraph(component2, "Humanoid");
			}
			MonsterAI component3 = prefab.GetComponent<MonsterAI>();
			if ((Object)(object)component3 != (Object)null)
			{
				LogGreaterBearAttackGraph(component3, "MonsterAI");
			}
			Log.LogInfo((object)("[Greater Bear]   Tameable=" + ((Object)(object)prefab.GetComponent<Tameable>() != (Object)null) + ", MonsterAI=" + ((Object)(object)prefab.GetComponent<MonsterAI>() != (Object)null) + ", Humanoid=" + ((Object)(object)prefab.GetComponent<Humanoid>() != (Object)null) + ", ZNetView=" + ((Object)(object)prefab.GetComponent<ZNetView>() != (Object)null) + "."));
			Component[] components = prefab.GetComponents<Component>();
			foreach (Component val in components)
			{
				if ((Object)(object)val == (Object)null)
				{
					Log.LogInfo((object)"[Greater Bear]   Root component: <missing script>");
					continue;
				}
				Log.LogInfo((object)("[Greater Bear]   Root component: " + ((object)val).GetType().FullName));
				if (val is Humanoid || val is MonsterAI || val is Character || ((object)val).GetType().Name.IndexOf("Attack", StringComparison.OrdinalIgnoreCase) >= 0)
				{
					LogGreaterBearFieldValues(val, ((object)val).GetType().Name);
				}
			}
			Transform[] componentsInChildren = prefab.GetComponentsInChildren<Transform>(true);
			Log.LogInfo((object)("[Greater Bear]   Hierarchy transform count=" + componentsInChildren.Length + "."));
			for (int j = 0; j < componentsInChildren.Length; j++)
			{
				Log.LogInfo((object)("[Greater Bear]     Node='" + GetTransformPath(componentsInChildren[j], prefab.transform) + "', active=" + ((Component)componentsInChildren[j]).gameObject.activeSelf + "."));
			}
			Renderer[] componentsInChildren2 = prefab.GetComponentsInChildren<Renderer>(true);
			Log.LogInfo((object)("[Greater Bear]   Renderer count=" + componentsInChildren2.Length + "."));
			foreach (Renderer val2 in componentsInChildren2)
			{
				if ((Object)(object)val2 == (Object)null)
				{
					continue;
				}
				Material[] sharedMaterials = val2.sharedMaterials;
				string text = string.Empty;
				for (int l = 0; l < sharedMaterials.Length; l++)
				{
					if (l > 0)
					{
						text += ", ";
					}
					text += (((Object)(object)sharedMaterials[l] == (Object)null) ? "<null>" : ((Object)sharedMaterials[l]).name);
				}
				Log.LogInfo((object)("[Greater Bear]     Renderer='" + ((Object)val2).name + "', type=" + ((object)val2).GetType().Name + ", materials=[" + text + "]."));
			}
		}

		private static void LogGreaterBearAttackGraph(object root, string rootLabel)
		{
			if (root != null)
			{
				Log.LogInfo((object)("[Greater Bear]   Beginning targeted attack graph scan: " + rootLabel + "."));
				HashSet<object> visited = new HashSet<object>(ReferenceEqualityComparer.Instance);
				int inspected = 0;
				LogGreaterBearAttackGraphRecursive(root, rootLabel, 0, visited, ref inspected);
				Log.LogInfo((object)("[Greater Bear]   Completed " + rootLabel + " attack graph scan; inspected " + inspected + " object(s)."));
			}
		}

		private static void LogGreaterBearAttackGraphRecursive(object instance, string path, int depth, HashSet<object> visited, ref int inspected)
		{
			if (instance == null || depth > 5 || inspected >= 180)
			{
				return;
			}
			Type type = instance.GetType();
			if (type.IsPrimitive || type.IsEnum || type == typeof(string) || type == typeof(decimal) || instance is Object || (!type.IsValueType && !visited.Add(instance)))
			{
				return;
			}
			inspected++;
			if (instance is IEnumerable enumerable)
			{
				int num = 0;
				{
					foreach (object item in enumerable)
					{
						if (item != null)
						{
							string text = path + "[" + num + "]";
							Type type2 = item.GetType();
							if (type2.Name.IndexOf("Attack", StringComparison.OrdinalIgnoreCase) >= 0 || type2.Name.IndexOf("HitData", StringComparison.OrdinalIgnoreCase) >= 0)
							{
								Log.LogInfo((object)("[Greater Bear]   Attack graph node " + text + " type=" + type2.FullName + "."));
								LogGreaterBearAttackGraphRecursive(item, text, depth + 1, visited, ref inspected);
							}
						}
						num++;
						if (num >= 40 || inspected >= 180)
						{
							break;
						}
					}
					return;
				}
			}
			FieldInfo[] fields;
			try
			{
				fields = type.GetFields(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
			}
			catch
			{
				return;
			}
			for (int i = 0; i < fields.Length && inspected < 180; i++)
			{
				FieldInfo fieldInfo = fields[i];
				if (fieldInfo.IsStatic)
				{
					continue;
				}
				Type fieldType = fieldInfo.FieldType;
				if (fieldInfo.Name.IndexOf("Attack", StringComparison.OrdinalIgnoreCase) < 0 && fieldType.Name.IndexOf("Attack", StringComparison.OrdinalIgnoreCase) < 0 && fieldType.Name.IndexOf("HitData", StringComparison.OrdinalIgnoreCase) < 0)
				{
					continue;
				}
				object value;
				try
				{
					value = fieldInfo.GetValue(instance);
				}
				catch (Exception ex)
				{
					Log.LogDebug((object)("[Greater Bear]   Could not read " + path + "." + fieldInfo.Name + ": " + ex.Message));
					continue;
				}
				string text2 = path + "." + fieldInfo.Name;
				if (value == null)
				{
					Log.LogInfo((object)("[Greater Bear]   Attack graph reference " + text2 + " = <null> (declared type " + fieldType.FullName + ")."));
					continue;
				}
				Type type3 = value.GetType();
				Log.LogInfo((object)("[Greater Bear]   Attack graph reference " + text2 + " type=" + type3.FullName + "."));
				if (value is IEnumerable || type3.Name.IndexOf("Attack", StringComparison.OrdinalIgnoreCase) >= 0 || type3.Name.IndexOf("HitData", StringComparison.OrdinalIgnoreCase) >= 0)
				{
					LogGreaterBearAttackGraphRecursive(value, text2, depth + 1, visited, ref inspected);
				}
				else
				{
					LogGreaterBearFieldValues(value, text2);
				}
			}
			if (type.Name.IndexOf("Attack", StringComparison.OrdinalIgnoreCase) < 0 && type.Name.IndexOf("HitData", StringComparison.OrdinalIgnoreCase) < 0 && type.Name.IndexOf("Damage", StringComparison.OrdinalIgnoreCase) < 0)
			{
				return;
			}
			for (int j = 0; j < fields.Length; j++)
			{
				if (inspected >= 180)
				{
					break;
				}
				FieldInfo fieldInfo2 = fields[j];
				if (fieldInfo2.IsStatic)
				{
					continue;
				}
				Type fieldType2 = fieldInfo2.FieldType;
				if (!fieldType2.IsPrimitive && !fieldType2.IsEnum && !(fieldType2 == typeof(string)) && !(fieldType2 == typeof(float)) && !(fieldType2 == typeof(double)) && fieldType2.Name.IndexOf("Damage", StringComparison.OrdinalIgnoreCase) < 0 && fieldType2.Name.IndexOf("HitData", StringComparison.OrdinalIgnoreCase) < 0)
				{
					continue;
				}
				try
				{
					object value2 = fieldInfo2.GetValue(instance);
					Log.LogInfo((object)("[Greater Bear]     " + path + "." + fieldInfo2.Name + " = " + ((value2 == null) ? "<null>" : value2.ToString()) + "."));
					if (value2 != null && !fieldType2.IsPrimitive && !fieldType2.IsEnum && fieldType2 != typeof(string) && !(value2 is Object))
					{
						LogGreaterBearAttackGraphRecursive(value2, path + "." + fieldInfo2.Name, depth + 1, visited, ref inspected);
					}
				}
				catch (Exception ex2)
				{
					Log.LogDebug((object)("[Greater Bear]   Could not read attack value " + path + "." + fieldInfo2.Name + ": " + ex2.Message));
				}
			}
		}

		private static void LogGreaterBearDamageModifiers(Character character)
		{
			if ((Object)(object)character == (Object)null)
			{
				return;
			}
			try
			{
				FieldInfo field = typeof(Character).GetField("m_damageModifiers", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
				if (field == null)
				{
					Log.LogInfo((object)"[Greater Bear]   Damage modifiers field not found on Character.");
					return;
				}
				object value = field.GetValue(character);
				if (value == null)
				{
					Log.LogInfo((object)"[Greater Bear]   Damage modifiers value is null.");
					return;
				}
				Type type = value.GetType();
				Log.LogInfo((object)("[Greater Bear]   Damage modifier structure=" + type.FullName + "."));
				FieldInfo[] fields = type.GetFields(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
				for (int i = 0; i < fields.Length; i++)
				{
					try
					{
						object value2 = fields[i].GetValue(value);
						Log.LogInfo((object)("[Greater Bear]     Resistance " + fields[i].Name + "=" + ((value2 == null) ? "<null>" : value2.ToString()) + "."));
					}
					catch (Exception ex)
					{
						Log.LogDebug((object)("[Greater Bear]     Could not read resistance " + fields[i].Name + ": " + ex.Message));
					}
				}
			}
			catch (Exception ex2)
			{
				Log.LogWarning((object)("[Greater Bear] Could not inspect damage modifiers: " + ex2.Message));
			}
		}

		private static void LogGreaterBearFieldValues(object instance, string section)
		{
			if (instance == null)
			{
				return;
			}
			Type type = instance.GetType();
			while (type != null && type != typeof(object))
			{
				FieldInfo[] fields = type.GetFields(BindingFlags.DeclaredOnly | BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
				foreach (FieldInfo fieldInfo in fields)
				{
					if (fieldInfo.IsStatic)
					{
						continue;
					}
					Type fieldType = fieldInfo.FieldType;
					if (fieldType.IsPrimitive || fieldType.IsEnum || fieldType == typeof(string) || fieldType == typeof(float) || fieldType == typeof(double) || typeof(Object).IsAssignableFrom(fieldType) || fieldType.Name.IndexOf("HitData", StringComparison.OrdinalIgnoreCase) >= 0 || fieldType.Name.IndexOf("Damage", StringComparison.OrdinalIgnoreCase) >= 0 || fieldType.Name.IndexOf("Attack", StringComparison.OrdinalIgnoreCase) >= 0)
					{
						try
						{
							object value = fieldInfo.GetValue(instance);
							string text = ((value == null) ? "<null>" : value.ToString());
							Log.LogInfo((object)("[Greater Bear]       " + section + "." + fieldInfo.Name + " = " + text));
						}
						catch (Exception ex)
						{
							Log.LogDebug((object)("[Greater Bear]       Could not read " + section + "." + fieldInfo.Name + ": " + ex.Message));
						}
					}
				}
				type = type.BaseType;
			}
		}

		private static string GetTransformPath(Transform transform, Transform root)
		{
			if ((Object)(object)transform == (Object)null)
			{
				return "<null>";
			}
			string text = ((Object)transform).name;
			Transform parent = transform.parent;
			while ((Object)(object)parent != (Object)null && (Object)(object)parent != (Object)(object)root)
			{
				text = ((Object)parent).name + "/" + text;
				parent = parent.parent;
			}
			return text;
		}

		private static void LogStaffVisualHierarchy(GameObject staffPrefab)
		{
			//IL_00b5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ba: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00da: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fb: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)staffPrefab == (Object)null)
			{
				return;
			}
			Log.LogInfo((object)("[Boar Staff Visual Diagnostic] Beginning read-only hierarchy inspection for '" + ((Object)staffPrefab).name + "'. No transforms, renderers, or animations will be changed."));
			Transform[] componentsInChildren = staffPrefab.GetComponentsInChildren<Transform>(true);
			Log.LogInfo((object)("[Boar Staff Visual Diagnostic] Transform count=" + componentsInChildren.Length + "."));
			foreach (Transform val in componentsInChildren)
			{
				string transformPath = GetTransformPath(val, staffPrefab.transform);
				ManualLogSource log = Log;
				string[] obj = new string[11]
				{
					"[Boar Staff Visual Diagnostic] Node='",
					transformPath,
					"', active=",
					((Component)val).gameObject.activeSelf.ToString(),
					", localPosition=",
					null,
					null,
					null,
					null,
					null,
					null
				};
				Vector3 val2 = val.localPosition;
				obj[5] = ((Vector3)(ref val2)).ToString("F4");
				obj[6] = ", localRotation=";
				val2 = val.localEulerAngles;
				obj[7] = ((Vector3)(ref val2)).ToString("F2");
				obj[8] = ", localScale=";
				val2 = val.localScale;
				obj[9] = ((Vector3)(ref val2)).ToString("F4");
				obj[10] = ".";
				log.LogInfo((object)string.Concat(obj));
			}
			Renderer[] componentsInChildren2 = staffPrefab.GetComponentsInChildren<Renderer>(true);
			Log.LogInfo((object)("[Boar Staff Visual Diagnostic] Renderer count=" + componentsInChildren2.Length + "."));
			foreach (Renderer val3 in componentsInChildren2)
			{
				if (!((Object)(object)val3 == (Object)null))
				{
					Log.LogInfo((object)("[Boar Staff Visual Diagnostic] Renderer='" + GetTransformPath(((Component)val3).transform, staffPrefab.transform) + "', type=" + ((object)val3).GetType().Name + ", enabled=" + val3.enabled + "."));
				}
			}
			Log.LogInfo((object)"[Boar Staff Visual Diagnostic] Inspection complete.");
		}

		private static void LogStaffAttackEffectDiagnostics(GameObject staffPrefab, string displayName)
		{
			if (!((Object)(object)staffPrefab == (Object)null))
			{
				ItemDrop component = staffPrefab.GetComponent<ItemDrop>();
				if ((Object)(object)component == (Object)null || component.m_itemData == null || component.m_itemData.m_shared == null)
				{
					Log.LogWarning((object)("[Attack Effect Diagnostic] " + displayName + ": ItemDrop/shared data unavailable."));
					return;
				}
				SharedData shared = component.m_itemData.m_shared;
				Log.LogInfo((object)("[Attack Effect Diagnostic] ===== " + displayName + " ====="));
				LogAttackEffectField(shared, "SharedData", "m_attack", 0, new HashSet<object>());
				LogAttackEffectField(shared, "SharedData", "m_secondaryAttack", 0, new HashSet<object>());
				Log.LogInfo((object)("[Attack Effect Diagnostic] ===== End " + displayName + " ====="));
			}
		}

		private static void LogAttackEffectField(object owner, string path, string fieldName, int depth, HashSet<object> visited)
		{
			if (owner == null || depth > 4)
			{
				return;
			}
			FieldInfo fieldInfo = FindField(owner.GetType(), fieldName);
			if (!(fieldInfo == null))
			{
				object value;
				try
				{
					value = fieldInfo.GetValue(owner);
				}
				catch (Exception ex)
				{
					Log.LogWarning((object)("[Attack Effect Diagnostic] Could not read " + path + "." + fieldName + ": " + ex.Message));
					return;
				}
				LogAttackEffectValue(value, path + "." + fieldName, depth, visited);
			}
		}

		private static void LogAttackEffectValue(object value, string path, int depth, HashSet<object> visited)
		{
			//IL_0014: Unknown result type (might be due to invalid IL or missing references)
			//IL_001a: Expected O, but got Unknown
			//IL_013b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0140: Unknown result type (might be due to invalid IL or missing references)
			//IL_0144: Unknown result type (might be due to invalid IL or missing references)
			//IL_0149: Unknown result type (might be due to invalid IL or missing references)
			//IL_0182: Unknown result type (might be due to invalid IL or missing references)
			//IL_0187: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a3: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a8: Unknown result type (might be due to invalid IL or missing references)
			//IL_0219: 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_030d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0312: Unknown result type (might be due to invalid IL or missing references)
			//IL_0343: Unknown result type (might be due to invalid IL or missing references)
			//IL_0348: Unknown result type (might be due to invalid IL or missing references)
			if (value == null || depth > 4)
			{
				return;
			}
			if (value is Object)
			{
				Object val = (Object)value;
				Log.LogInfo((object)("[Attack Effect Diagnostic] Reference " + path + " = '" + val.name + "' (" + ((object)val).GetType().Name + ")."));
				GameObject val2 = (GameObject)(object)((val is GameObject) ? val : null);
				if (!((Object)(object)val2 != (Object)null))
				{
					return;
				}
				ParticleSystem[] componentsInChildren = val2.GetComponentsInChildren<ParticleSystem>(true);
				Light[] componentsInChildren2 = val2.GetComponentsInChildren<Light>(true);
				Renderer[] componentsInChildren3 = val2.GetComponentsInChildren<Renderer>(true);
				Log.LogInfo((object)("[Attack Effect Diagnostic] PrefabSummary '" + ((Object)val2).name + "': transforms=" + val2.GetComponentsInChildren<Transform>(true).Length + ", particles=" + componentsInChildren.Length + ", lights=" + componentsInChildren2.Length + ", renderers=" + componentsInChildren3.Length + "."));
				Color color;
				for (int i = 0; i < componentsInChildren.Length; i++)
				{
					MainModule main = componentsInChildren[i].main;
					MinMaxGradient startColor = ((MainModule)(ref main)).startColor;
					ManualLogSource log = Log;
					string[] obj = new string[7]
					{
						"[Attack Effect Diagnostic]   Particle '",
						GetTransformPath(((Component)componentsInChildren[i]).transform, val2.transform),
						"' colorMode=",
						((object)((MinMaxGradient)(ref startColor)).mode/*cast due to .constrained prefix*/).ToString(),
						", color=",
						null,
						null
					};
					color = ((MinMaxGradient)(ref startColor)).color;
					obj[5] = ((Color)(ref color)).ToString("F3");
					obj[6] = ".";
					log.LogInfo((object)string.Concat(obj));
				}
				for (int j = 0; j < componentsInChildren2.Length; j++)
				{
					ManualLogSource log2 = Log;
					string[] obj2 = new string[5]
					{
						"[Attack Effect Diagnostic]   Light '",
						GetTransformPath(((Component)componentsInChildren2[j]).transform, val2.transform),
						"' color=",
						null,
						null
					};
					color = componentsInChildren2[j].color;
					obj2[3] = ((Color)(ref color)).ToString("F3");
					obj2[4] = ".";
					log2.LogInfo((object)string.Concat(obj2));
				}
				for (int k = 0; k < componentsInChildren3.Length; k++)
				{
					Material[] sharedMaterials = componentsInChildren3[k].sharedMaterials;
					foreach (Material val3 in sharedMaterials)
					{
						if (!((Object)(object)val3 == (Object)null))
						{
							string text = "[Attack Effect Diagnostic]   Renderer '" + GetTransformPath(((Component)componentsInChildren3[k]).transform, val2.transform) + "' material='" + ((Object)val3).name + "' shader='" + (((Object)(object)val3.shader == (Object)null) ? "<null>" : ((Object)val3.shader).name) + "'";
							if (val3.HasProperty("_Color"))
							{
								string text2 = text;
								color = val3.GetColor("_Color");
								text = text2 + " _Color=" + ((Color)(ref color)).ToString("F3");
							}
							if (val3.HasProperty("_BaseColor"))
							{
								string text3 = text;
								color = val3.GetColor("_BaseColor");
								text = text3 + " _BaseColor=" + ((Color)(ref color)).ToString("F3");
							}
							Log.LogInfo((object)(text + "."));
						}
					}
				}
				return;
			}
			Type type = value.GetType();
			if (type.IsPrimitive || type.IsEnum || value is string || value is decimal || (!type.IsValueType && !visited.Add(value)))
			{
				return;
			}
			if (value is IEnumerable enumerable)
			{
				int num = 0;
				{
					foreach (object item in enumerable)
					{
						LogAttackEffectValue(item, path + "[" + num + "]", depth + 1, visited);
						num++;
						if (num >= 64)
						{
							break;
						}
					}
					return;
				}
			}
			Log.LogInfo((object)("[Attack Effect Diagnostic] Object " + path + " type='" + type.FullName + "'."));
			Type type2 = type;
			while (type2 != null)
			{
				FieldInfo[] fields = type2.GetFields(BindingFlags.DeclaredOnly | BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
				foreach (FieldInfo fieldInfo in fields)
				{
					if (!fieldInfo.IsStatic && (!(type.Name == "Attack") || fieldInfo.Name.IndexOf("effect", StringComparison.OrdinalIgnoreCase) >= 0))
					{
						object value2;
						try
						{
							value2 = fieldInfo.GetValue(value);
						}
						catch
						{
							continue;
						}
						if (value2 != null)
						{
							LogAttackEffectValue(value2, path + "." + fieldInfo.Name, depth + 1, visited);
						}
					}
				}
				type2 = type2.BaseType;
			}
		}

		private static void LogStaffCastingEffectDiagnostics(GameObject staffPrefab, string displayName)
		{
			//IL_00c8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cd: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d6: Unknown result type (might be due to invalid IL or missing references)
			//IL_012d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0132: Unknown result type (might be due to invalid IL or missing references)
			//IL_014e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0153: Unknown result type (might be due to invalid IL or missing references)
			//IL_016f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0174: Unknown result type (might be due to invalid IL or missing references)
			//IL_0178: Unknown result type (might be due to invalid IL or missing references)
			//IL_017d: Unknown result type (might be due to invalid IL or missing references)
			//IL_019b: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a0: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a4: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a9: Unknown result type (might be due to invalid IL or missing references)
			//IL_0259: Unknown result type (might be due to invalid IL or missing references)
			//IL_025e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0295: Unknown result type (might be due to invalid IL or missing references)
			//IL_029a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0537: Unknown result type (might be due to invalid IL or missing references)
			//IL_053e: Expected O, but got Unknown
			//IL_0555: Unknown result type (might be due to invalid IL or missing references)
			//IL_055a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0575: Unknown result type (might be due to invalid IL or missing references)
			//IL_057a: Unknown result type (might be due to invalid IL or missing references)
			//IL_05a8: Unknown result type (might be due to invalid IL or missing references)
			//IL_05af: Expected O, but got Unknown
			//IL_05c6: Unknown result type (might be due to invalid IL or missing references)
			//IL_05cb: Unknown result type (might be due to invalid IL or missing references)
			//IL_05e6: Unknown result type (might be due to invalid IL or missing references)
			//IL_05eb: Unknown result type (might be due to invalid IL or missing references)
			//IL_04dc: Unknown result type (might be due to invalid IL or missing references)
			//IL_04e1: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)staffPrefab == (Object)null)
			{
				return;
			}
			Transform val = staffPrefab.transform.Find("attach/fi_vil_combs_props_bone_skull");
			if ((Object)(object)val == (Object)null)
			{
				Log.LogWarning((object)("[Casting Effect Diagnostic] " + displayName + ": could not find attach/fi_vil_combs_props_bone_skull; no effect inspection performed."));
				return;
			}
			Log.LogInfo((object)("[Casting Effect Diagnostic] ===== " + displayName + " ====="));
			Log.LogInfo((object)("[Casting Effect Diagnostic] Root='" + GetTransformPath(val, staffPrefab.transform) + "'. Read-only inspection; no settings changed."));
			ParticleSystem[] componentsInChildren = ((Component)val).GetComponentsInChildren<ParticleSystem>(true);
			Log.LogInfo((object)("[Casting Effect Diagnostic] ParticleSystem count=" + componentsInChildren.Length + "."));
			Color val3;
			foreach (ParticleSystem val2 in componentsInChildren)
			{
				if (!((Object)(object)val2 == (Object)null))
				{
					MainModule main = val2.main;
					MinMaxGradient startColor = ((MainModule)(ref main)).startColor;
					ManualLogSource log = Log;
					string[] obj = new string[13]
					{
						"[Casting Effect Diagnostic] ParticleSystem='",
						GetTransformPath(((Component)val2).transform, staffPrefab.transform),
						"', active=",
						((Component)val2).gameObject.activeSelf.ToString(),
						", startColorMode=",
						((object)((MinMaxGradient)(ref startColor)).mode/*cast due to .constrained prefix*/).ToString(),
						", startColor=",
						null,
						null,
						null,
						null,
						null,
						null
					};
					val3 = ((MinMaxGradient)(ref startColor)).color;
					obj[7] = ((Color)(ref val3)).ToString("F3");
					obj[8] = ", startSizeMode=";
					MinMaxCurve val4 = ((MainModule)(ref main)).startSize;
					obj[9] = ((object)((MinMaxCurve)(ref val4)).mode/*cast due to .constrained prefix*/).ToString();
					obj[10] = ", startSpeedMode=";
					val4 = ((MainModule)(ref main)).startSpeed;
					obj[11] = ((object)((MinMaxCurve)(ref val4)).mode/*cast due to .constrained prefix*/).ToString();
					obj[12] = ".";
					log.LogInfo((object)string.Concat(obj));
				}
			}
			Light[] componentsInChildren2 = ((Component)val).GetComponentsInChildren<Light>(true);
			Log.LogInfo((object)("[Casting Effect Diagnostic] Light count=" + componentsInChildren2.Length + "."));
			foreach (Light val5 in componentsInChildren2)
			{
				if (!((Object)(object)val5 == (Object)null))
				{
					ManualLogSource log2 = Log;
					string[] obj2 = new string[13]
					{
						"[Casting Effect Diagnostic] Light='",
						GetTransformPath(((Component)val5).transform, staffPrefab.transform),
						"', type=",
						((object)val5.type/*cast due to .constrained prefix*/).ToString(),
						", enabled=",
						((Behaviour)val5).enabled.ToString(),
						", color=",
						null,
						null,
						null,
						null,
						null,
						null
					};
					val3 = val5.color;
					obj2[7] = ((Color)(ref val3)).ToString("F3");
					obj2[8] = ", intensity=";
					obj2[9] = val5.intensity.ToString("F3");
					obj2[10] = ", range=";
					obj2[11] = val5.range.ToString("F3");
					obj2[12] = ".";
					log2.LogInfo((object)string.Concat(obj2));
				}
			}
			Renderer[] componentsInChildren3 = ((Component)val).GetComponentsInChildren<Renderer>(true);
			int num = 0;
			foreach (Renderer val6 in componentsInChildren3)
			{
				if ((Object)(object)val6 == (Object)null || (!(val6 is ParticleSystemRenderer) && !(val6 is TrailRenderer) && !(val6 is LineRenderer)))
				{
					continue;
				}
				num++;
				Material[] sharedMaterials = val6.sharedMaterials;
				Log.LogInfo((object)("[Casting Effect Diagnostic] EffectRenderer='" + GetTransformPath(((Component)val6).transform, staffPrefab.transform) + "', type=" + ((object)val6).GetType().Name + ", materialCount=" + sharedMaterials.Length + "."));
				for (int l = 0; l < sharedMaterials.Length; l++)
				{
					Material val7 = sharedMaterials[l];
					if ((Object)(object)val7 == (Object)null)
					{
						Log.LogInfo((object)("[Casting Effect Diagnostic]   Material[" + l + "]=<null>."));
						continue;
					}
					string text = "[Casting Effect Diagnostic]   Material[" + l + "]='" + ((Object)val7).name + "', shader='" + (((Object)(object)val7.shader == (Object)null) ? "<null>" : ((Object)val7.shader).name) + "'";
					string[] array = new string[5] { "_Color", "_BaseColor", "_TintColor", "_EmissionColor", "_EmissiveColor" };
					foreach (string text2 in array)
					{
						if (val7.HasProperty(text2))
						{
							string[] obj3 = new string[5] { text, ", ", text2, "=", null };
							val3 = val7.GetColor(text2);
							obj3[4] = ((Color)(ref val3)).ToString("F3");
							text = string.Concat(obj3);
						}
					}
					Log.LogInfo((object)(text + "."));
				}
				if (val6 is TrailRenderer)
				{
					TrailRenderer val8 = (TrailRenderer)val6;
					ManualLogSource log3 = Log;
					string[] obj4 = new string[5] { "[Casting Effect Diagnostic]   Trail startColor=", null, null, null, null };
					val3 = val8.startColor;
					obj4[1] = ((Color)(ref val3)).ToString("F3");
					obj4[2] = ", endColor=";
					val3 = val8.endColor;
					obj4[3] = ((Color)(ref val3)).ToString("F3");
					obj4[4] = ".";
					log3.LogInfo((object)string.Concat(obj4));
				}
				else if (val6 is LineRenderer)
				{
					LineRenderer val9 = (LineRenderer)val6;
					ManualLogSource log4 = Log;
					string[] obj5 = new string[5] { "[Casting Effect Diagnostic]   Line startColor=", null, null, null, null };
					val3 = val9.startColor;
					obj5[1] = ((Color)(ref val3)).ToString("F3");
					obj5[2] = ", endColor=";
					val3 = val9.endColor;
					obj5[3] = ((Color)(ref val3)).ToString("F3");
					obj5[4] = ".";
					log4.LogInfo((object)string.Concat(obj5));
				}
			}
			Log.LogInfo((object)("[Casting Effect Diagnostic] Trail/line/particle renderer count=" + num + "."));
			Log.LogInfo((object)("[Casting Effect Diagnostic] ===== End " + displayName + " ====="));
		}

		private static void LogProjectileEffectDiagnostics(GameObject projectilePrefab, string displayName)
		{
			//IL_00cd: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d2: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ed: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f2: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f6: Unknown result type (might be due to invalid IL or missing references)
			//IL_01fb: Unknown result type (might be due to invalid IL or missing references)
			//IL_02a6: Unknown result type (might be due to invalid IL or missing references)
			//IL_02ab: Unknown result type (might be due to invalid IL or missing references)
			//IL_02c9: Unknown result type (might be due to invalid IL or missing references)
			//IL_02ce: 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_02f0: Unknown result type (might be due to invalid IL or missing references)
			//IL_030d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0312: Unknown result type (might be due to invalid IL or missing references)
			//IL_032f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0334: Unknown result type (might be due to invalid IL or missing references)
			//IL_0338: Unknown result type (might be due to invalid IL or missing references)
			//IL_033d: Unknown result type (might be due to invalid IL or missing references)
			//IL_035b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0360: Unknown result type (might be due to invalid IL or missing references)
			//IL_0364: Unknown result type (might be due to invalid IL or missing references)
			//IL_0369: Unknown result type (might be due to invalid IL or missing references)
			//IL_0434: Unknown result type (might be due to invalid IL or missing references)
			//IL_0439: Unknown result type (might be due to invalid IL or missing references)
			//IL_06d1: Unknown result type (might be due to invalid IL or missing references)
			//IL_06d8: Expected O, but got Unknown
			//IL_06ef: Unknown result type (might be due to invalid IL or missing references)
			//IL_06f4: Unknown result type (might be due to invalid IL or missing references)
			//IL_070f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0714: Unknown result type (might be due to invalid IL or missing references)
			//IL_0742: Unknown result type (might be due to invalid IL or missing references)
			//IL_0749: Expected O, but got Unknown
			//IL_0760: Unknown result type (might be due to invalid IL or missing references)
			//IL_0765: Unknown result type (might be due to invalid IL or missing references)
			//IL_0780: Unknown result type (might be due to invalid IL or missing references)
			//IL_0785: Unknown result type (might be due to invalid IL or missing references)
			//IL_0676: Unknown result type (might be due to invalid IL or missing references)
			//IL_067b: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)projectilePrefab == (Object)null)
			{
				return;
			}
			Log.LogInfo((object)("[Projectile Effect Diagnostic] ===== " + displayName + " ====="));
			Log.LogInfo((object)("[Projectile Effect Diagnostic] Prefab='" + ((Object)projectilePrefab).name + "'. Read-only inspection; no settings changed."));
			Transform[] componentsInChildren = projectilePrefab.GetComponentsInChildren<Transform>(true);
			Log.LogInfo((object)("[Projectile Effect Diagnostic] Transform count=" + componentsInChildren.Length + "."));
			foreach (Transform val in componentsInChildren)
			{
				ManualLogSource log = Log;
				string[] obj = new string[7]
				{
					"[Projectile Effect Diagnostic] Node='",
					GetTransformPath(val, projectilePrefab.transform),
					"', active=",
					((Component)val).gameObject.activeSelf.ToString(),
					", localPosition=",
					null,
					null
				};
				Vector3 localPosition = val.localPosition;
				obj[5] = ((Vector3)(ref localPosition)).ToString("F3");
				obj[6] = ".";
				log.LogInfo((object)string.Concat(obj));
			}
			Component[] componentsInChildren2 = projectilePrefab.GetComponentsInChildren<Component>(true);
			Log.LogInfo((object)("[Projectile Effect Diagnostic] Component count=" + componentsInChildren2.Length + "."));
			foreach (Component val2 in componentsInChildren2)
			{
				if (!((Object)(object)val2 == (Object)null))
				{
					Log.LogInfo((object)("[Projectile Effect Diagnostic] Component='" + GetTransformPath(val2.transform, projectilePrefab.transform) + "', type=" + ((object)val2).GetType().FullName + "."));
				}
			}
			ParticleSystem[] componentsInChildren3 = projectilePrefab.GetComponentsInChildren<ParticleSystem>(true);
			Log.LogInfo((object)("[Projectile Effect Diagnostic] ParticleSystem count=" + componentsInChildren3.Length + "."));
			Color val4;
			foreach (ParticleSystem val3 in componentsInChildren3)
			{
				if (!((Object)(object)val3 == (Object)null))
				{
					MainModule main = val3.main;
					MinMaxGradient startColor = ((MainModule)(ref main)).startColor;
					ManualLogSource log2 = Log;
					string[] obj2 = new string[23]
					{
						"[Projectile Effect Diagnostic] ParticleSystem='",
						GetTransformPath(((Component)val3).transform, projectilePrefab.transform),
						"', active=",
						((Component)val3).gameObject.activeSelf.ToString(),
						", isPlaying=",
						val3.isPlaying.ToString(),
						", isEmitting=",
						val3.isEmitting.ToString(),
						", playOnAwake=",
						((MainModule)(ref main)).playOnAwake.ToString(),
						", startColorMode=",
						((object)((MinMaxGradient)(ref startColor)).mode/*cast due to .constrained prefix*/).ToString(),
						", color=",
						null,
						null,
						null,
						null,
						null,
						null,
						null,
						null,
						null,
						null
					};
					val4 = ((MinMaxGradient)(ref startColor)).color;
					obj2[13] = ((Color)(ref val4)).ToString("F3");
					obj2[14] = ", colorMin=";
					val4 = ((MinMaxGradient)(ref startColor)).colorMin;
					obj2[15] = ((Color)(ref val4)).ToString("F3");
					obj2[16] = ", colorMax=";
					val4 = ((MinMaxGradient)(ref startColor)).colorMax;
					obj2[17] = ((Color)(ref val4)).ToString("F3");
					obj2[18] = ", startSizeMode=";
					MinMaxCurve val5 = ((MainModule)(ref main)).startSize;
					obj2[19] = ((object)((MinMaxCurve)(ref val5)).mode/*cast due to .constrained prefix*/).ToString();
					obj2[20] = ", startSpeedMode=";
					val5 = ((MainModule)(ref main)).startSpeed;
					obj2[21] = ((object)((MinMaxCurve)(ref val5)).mode/*cast due to .constrained prefix*/).ToString();
					obj2[22] = ".";
					log2.LogInfo((object)string.Concat(obj2));
				}
			}
			Light[] componentsInChildren4 = projectilePrefab.GetComponentsInChildren<Light>(true);
			Log.LogInfo((object)("[Projectile Effect Diagnostic] Light count=" + componentsInChildren4.Length + "."));
			foreach (Light val6 in componentsInChildren4)
			{
				if (!((Object)(object)val6 == (Object)null))
				{
					ManualLogSource log3 = Log;
					string[] obj3 = new string[11]
					{
						"[Projectile Effect Diagnostic] Light='",
						GetTransformPath(((Component)val6).transform, projectilePrefab.transform),
						"', enabled=",
						((Behaviour)val6).enabled.ToString(),
						", color=",
						null,
						null,
						null,
						null,
						null,
						null
					};
					val4 = val6.color;
					obj3[5] = ((Color)(ref val4)).ToString("F3");
					obj3[6] = ", intensity=";
					obj3[7] = val6.intensity.ToString("F3");
					obj3[8] = ", range=";
					obj3[9] = val6.range.ToString("F3");
					obj3[10] = ".";
					log3.LogInfo((object)string.Concat(obj3));
				}
			}
			Renderer[] componentsInChildren5 = projectilePrefab.GetComponentsInChildren<Renderer>(true);
			Log.LogInfo((object)("[Projectile Effect Diagnostic] Renderer count=" + componentsInChildren5.Length + "."));
			foreach (Renderer val7 in componentsInChildren5)
			{
				if ((Object)(object)val7 == (Object)null)
				{
					continue;
				}
				Material[] sharedMaterials = val7.sharedMaterials;
				Log.LogInfo((object)("[Projectile Effect Diagnostic] Renderer='" + GetTransformPath(((Component)val7).transform, projectilePrefab.transform) + "', type=" + ((object)val7).GetType().Name + ", enabled=" + val7.enabled + ", materialCount=" + sharedMaterials.Length + "."));
				for (int n = 0; n < sharedMaterials.Length; n++)
				{
					Material val8 = sharedMaterials[n];
					if ((Object)(object)val8 == (Object)null)
					{
						continue;
					}
					string text = "[Projectile Effect Diagnostic]   Material[" + n + "]='" + ((Object)val8).name + "', shader='" + (((Object)(object)val8.shader == (Object)null) ? "<null>" : ((Object)val8.shader).name) + "'";
					string[] array = new string[5] { "_Color", "_BaseColor", "_TintColor", "_EmissionColor", "_EmissiveColor" };
					for (int num = 0; num < array.Length; num++)
					{
						if (val8.HasProperty(array[num]))
						{
							string[] obj4 = new string[5]
							{
								text,
								", ",
								array[num],
								"=",
								null
							};
							val4 = val8.GetColor(array[num]);
							obj4[4] = ((Color)(ref val4)).ToString("F3");
							text = string.Concat(obj4);
						}
					}
					Log.LogInfo((object)(text + "."));
				}
				if (val7 is TrailRenderer)
				{
					TrailRenderer val9 = (TrailRenderer)val7;
					ManualLogSource log4 = Log;
					string[] obj5 = new string[5] { "[Projectile Effect Diagnostic]   Trail startColor=", null, null, null, null };
					val4 = val9.startColor;
					obj5[1] = ((Color)(ref val4)).ToString("F3");
					obj5[2] = ", endColor=";
					val4 = val9.endColor;
					obj5[3] = ((Color)(ref val4)).ToString("F3");
					obj5[4] = ".";
					log4.LogInfo((object)string.Concat(obj5));
				}
				else if (val7 is LineRenderer)
				{
					LineRenderer val10 = (LineRenderer)val7;
					ManualLogSource log5 = Log;
					string[] obj6 = new string[5] { "[Projectile Effect Diagnostic]   Line startColor=", null, null, null, null };
					val4 = val10.startColor;
					obj6[1] = ((Color)(ref val4)).ToString("F3");
					obj6[2] = ", endColor=";
					val4 = val10.endColor;
					obj6[3] = ((Color)(ref val4)).ToString("F3");
					obj6[4] = ".";
					log5.LogInfo((object)string.Concat(obj6));
				}
			}
			Log.LogInfo((object)("[Projectile Effect Diagnostic] ===== End " + displayName + " ====="));
		}

		private static bool InstallStaffCastingEffect(GameObject staffPrefab, string displayName, string uniqueEffectPrefabName, Color shadowColor, Color highlightColor)
		{
			//IL_0099: Unknown result type (might be due to invalid IL or missing references)
			//IL_009e: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ab: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b1: Invalid comparison between Unknown and I4
			//IL_00c6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d9: 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_00f5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fa: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e6: Unknown