Decompiled source of Ritual do Fenrir v0.4.0

plugins/AshStaff.dll

Decompiled a week ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using HarmonyLib;
using Jotunn.Configs;
using Jotunn.Entities;
using Jotunn.Managers;
using Jotunn.Utils;
using Microsoft.CodeAnalysis;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: AssemblyMetadata("AI_Assisted_Creation", "This assembly was created with the assistance of Generative AI (code generation).")]
[assembly: AssemblyMetadata("AI_Model_Vendor", "Anthropic (Claude)")]
[assembly: AssemblyVersion("0.0.0.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 AshStaff
{
	[BepInPlugin("pandherya.ashstaff", "Ritual do Fenrir (Pandherya)", "0.4.0")]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	[NetworkCompatibility(/*Could not decode attribute arguments.*/)]
	[SynchronizationMode(/*Could not decode attribute arguments.*/)]
	public class Plugin : BaseUnityPlugin
	{
		public const string GUID = "pandherya.ashstaff";

		public const string ItemId = "StaffAshPandherya";

		internal static ConfigEntry<string> Mobs;

		internal static ConfigEntry<int> MaxSpawned;

		internal static ConfigEntry<float> Duration;

		internal static ConfigEntry<float> HealthCost;

		internal static ConfigEntry<float> EitrCost;

		internal static ConfigEntry<KeyboardShortcut> HostileKey;

		public const string ZOwner = "ash_owner";

		public const string ZHostile = "ash_hostile";

		internal static ManualLogSource Log;

		private static readonly List<GameObject> _minions = new List<GameObject>();

		private static SpawnAbility _spawn;

		private static SharedData _shared;

		private static float _origHealth;

		private static float _origEitr;

		private static int _origMax;

		private static readonly MethodInfo TakeInput = AccessTools.Method(typeof(Player), "TakeInput", (Type[])null, (Type[])null);

		internal static ConfigurationManagerAttributes Admin()
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0005: Unknown result type (might be due to invalid IL or missing references)
			//IL_000d: Expected O, but got Unknown
			return new ConfigurationManagerAttributes
			{
				IsAdminOnly = true
			};
		}

		private void Awake()
		{
			//IL_0034: Unknown result type (might be due to invalid IL or missing references)
			//IL_003e: Expected O, but got Unknown
			//IL_0068: Unknown result type (might be due to invalid IL or missing references)
			//IL_0072: Expected O, but got Unknown
			//IL_00a0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00aa: Expected O, but got Unknown
			//IL_00d8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e2: Expected O, but got Unknown
			//IL_0110: Unknown result type (might be due to invalid IL or missing references)
			//IL_011a: Expected O, but got Unknown
			//IL_0136: Unknown result type (might be due to invalid IL or missing references)
			//IL_014f: Unknown result type (might be due to invalid IL or missing references)
			Log = ((BaseUnityPlugin)this).Logger;
			Mobs = ((BaseUnityPlugin)this).Config.Bind<string>("Cajado", "Mobs", "Charred_Melee,Charred_Archer", new ConfigDescription("Carbonizados conjurados (sorteados a cada invocação). Opções: Charred_Melee, Charred_Archer, Charred_Mage, Charred_Twitcher. Mudar a lista exige reiniciar o jogo.", (AcceptableValueBase)null, new object[1] { Admin() }));
			MaxSpawned = ((BaseUnityPlugin)this).Config.Bind<int>("Cajado", "MaximoAoMesmoTempo", 3, new ConfigDescription("Quantos podem existir ao mesmo tempo (0 = usa o do cajado original).", (AcceptableValueBase)null, new object[1] { Admin() }));
			Duration = ((BaseUnityPlugin)this).Config.Bind<float>("Cajado", "Duracao", 120f, new ConfigDescription("Segundos até cada um voltar às cinzas.", (AcceptableValueBase)null, new object[1] { Admin() }));
			HealthCost = ((BaseUnityPlugin)this).Config.Bind<float>("Cajado", "CustoVida", -1f, new ConfigDescription("Vida gasta por invocação (-1 = igual ao cajado original).", (AcceptableValueBase)null, new object[1] { Admin() }));
			EitrCost = ((BaseUnityPlugin)this).Config.Bind<float>("Cajado", "CustoEitr", -1f, new ConfigDescription("Eitr gasto por invocação (-1 = igual ao cajado original).", (AcceptableValueBase)null, new object[1] { Admin() }));
			HostileKey = ((BaseUnityPlugin)this).Config.Bind<KeyboardShortcut>("Cajado", "TeclaAtacarJogadores", new KeyboardShortcut((KeyCode)112, Array.Empty<KeyCode>()), "Liga/desliga: seus Carbonizados atacam outros jogadores (independente de PvP). Você nunca é atacado pelos seus.");
			new Harmony("pandherya.ashstaff").PatchAll(typeof(Plugin).Assembly);
			MaxSpawned.SettingChanged += delegate
			{
				ApplyLive();
			};
			Duration.SettingChanged += delegate
			{
				ApplyLive();
			};
			HealthCost.SettingChanged += delegate
			{
				ApplyLive();
			};
			EitrCost.SettingChanged += delegate
			{
				ApplyLive();
			};
			ConfigReload.Watch((BaseUnityPlugin)(object)this, ((BaseUnityPlugin)this).Config, "pandherya.ashstaff", ApplyLive);
			PrefabManager.OnVanillaPrefabsAvailable += Build;
		}

		private void Build()
		{
			//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_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_006a: Expected O, but got Unknown
			//IL_0073: Unknown result type (might be due to invalid IL or missing references)
			//IL_007d: Expected O, but got Unknown
			//IL_0088: Unknown result type (might be due to invalid IL or missing references)
			//IL_0092: Expected O, but got Unknown
			//IL_009b: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a5: Expected O, but got Unknown
			//IL_00b0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b6: Expected O, but got Unknown
			//IL_00e5: Unknown result type (might be due to invalid IL or missing references)
			PrefabManager.OnVanillaPrefabsAvailable -= Build;
			try
			{
				if ((Object)(object)PrefabManager.Instance.GetPrefab("StaffSkeleton") == (Object)null)
				{
					Log.LogError((object)"StaffSkeleton não encontrado.");
					return;
				}
				ItemConfig val = new ItemConfig
				{
					Name = "Ritual do Fenrir",
					Description = "Floki cravejou runas nessa caveira para que Fenrir possa evocar algo bem mais sombrio que meras caveiras...",
					CraftingStation = "piece_magetable",
					MinStationLevel = 2
				};
				val.AddRequirement(new RequirementConfig("StaffSkeleton", 1, 0, false));
				val.AddRequirement(new RequirementConfig("CharredBone", 20, 10, true));
				val.AddRequirement(new RequirementConfig("MoltenCore", 2, 1, true));
				CustomItem val2 = new CustomItem("StaffAshPandherya", "StaffSkeleton", val);
				_shared = val2.ItemDrop.m_itemData.m_shared;
				Darken(val2.ItemPrefab, _shared, new Color(0.16f, 0.06f, 0.24f));
				Attack attack = _shared.m_attack;
				if (!ReplaceSpawner(attack))
				{
					Log.LogError((object)"Não achei o SpawnAbility do Ressuscitador; o cajado novo vai conjurar esqueletos.");
				}
				_origHealth = attack.m_attackHealth;
				_origEitr = attack.m_attackEitr;
				ItemManager.Instance.AddItem(val2);
				ApplyLive();
				Log.LogInfo((object)"Cajado das Cinzas registrado.");
			}
			catch (Exception ex)
			{
				Log.LogError((object)("Falha ao criar o Cajado das Cinzas: " + ex));
			}
		}

		private static void Darken(GameObject prefab, SharedData shared, Color c)
		{
			//IL_0221: Unknown result type (might be due to invalid IL or missing references)
			//IL_0226: Unknown result type (might be due to invalid IL or missing references)
			//IL_023a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0241: Expected O, but got Unknown
			//IL_025f: 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_0069: Expected O, but got Unknown
			//IL_02c5: Unknown result type (might be due to invalid IL or missing references)
			//IL_02d4: Unknown result type (might be due to invalid IL or missing references)
			//IL_02d9: Unknown result type (might be due to invalid IL or missing references)
			//IL_02f4: Unknown result type (might be due to invalid IL or missing references)
			//IL_02f6: Unknown result type (might be due to invalid IL or missing references)
			//IL_0340: Unknown result type (might be due to invalid IL or missing references)
			//IL_034f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0138: Unknown result type (might be due to invalid IL or missing references)
			//IL_015e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0172: Unknown result type (might be due to invalid IL or missing references)
			//IL_0177: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fc: Unknown result type (might be due to invalid IL or missing references)
			Dictionary<Texture, Texture2D> dictionary = new Dictionary<Texture, Texture2D>();
			Dictionary<Material, Material> dictionary2 = new Dictionary<Material, Material>();
			Renderer[] componentsInChildren = prefab.GetComponentsInChildren<Renderer>(true);
			foreach (Renderer val in componentsInChildren)
			{
				if (val is ParticleSystemRenderer)
				{
					continue;
				}
				Material[] sharedMaterials = val.sharedMaterials;
				for (int j = 0; j < sharedMaterials.Length; j++)
				{
					Material val2 = sharedMaterials[j];
					if ((Object)(object)val2 == (Object)null)
					{
						continue;
					}
					if (!dictionary2.TryGetValue(val2, out var value))
					{
						value = new Material(val2);
						string[] texturePropertyNames = value.GetTexturePropertyNames();
						foreach (string text in texturePropertyNames)
						{
							string text2 = text.ToLowerInvariant();
							if (!text2.Contains("tex") || text2.Contains("bump") || text2.Contains("normal") || text2.Contains("metal") || text2.Contains("mask"))
							{
								continue;
							}
							Texture texture = value.GetTexture(text);
							if (!((Object)(object)texture == (Object)null))
							{
								if (!dictionary.TryGetValue(texture, out var value2))
								{
									value2 = Readable(texture);
									PaintTex(value2, c);
									dictionary[texture] = value2;
								}
								value.SetTexture(text, (Texture)(object)value2);
							}
						}
						if (value.HasProperty("_Color"))
						{
							value.color = Color.white;
						}
						if (value.HasProperty("_EmissionColor"))
						{
							value.SetColor("_EmissionColor", value.GetColor("_EmissionColor") * new Color(0.7f, 0.3f, 1f));
						}
						dictionary2[val2] = value;
					}
					sharedMaterials[j] = value;
				}
				val.sharedMaterials = sharedMaterials;
			}
			if (shared.m_icons == null)
			{
				return;
			}
			for (int l = 0; l < shared.m_icons.Length; l++)
			{
				Sprite val3 = shared.m_icons[l];
				if ((Object)(object)val3 == (Object)null)
				{
					continue;
				}
				try
				{
					RenderTexture temporary = RenderTexture.GetTemporary(((Texture)val3.texture).width, ((Texture)val3.texture).height, 0, (RenderTextureFormat)0, (RenderTextureReadWrite)2);
					RenderTexture active = RenderTexture.active;
					Graphics.Blit((Texture)(object)val3.texture, temporary);
					RenderTexture.active = temporary;
					Rect textureRect = val3.textureRect;
					Texture2D val4 = new Texture2D((int)((Rect)(ref textureRect)).width, (int)((Rect)(ref textureRect)).height, (TextureFormat)4, false);
					val4.ReadPixels(new Rect(((Rect)(ref textureRect)).x, ((Rect)(ref textureRect)).y, ((Rect)(ref textureRect)).width, ((Rect)(ref textureRect)).height), 0, 0);
					RenderTexture.active = active;
					RenderTexture.ReleaseTemporary(temporary);
					Color[] pixels = val4.GetPixels();
					for (int m = 0; m < pixels.Length; m++)
					{
						float num = pixels[m].r * 0.3f + pixels[m].g * 0.59f + pixels[m].b * 0.11f;
						Color val5 = c * (0.6f + num * 2.2f);
						val5.a = pixels[m].a;
						pixels[m] = val5;
					}
					val4.SetPixels(pixels);
					val4.Apply();
					shared.m_icons[l] = Sprite.Create(val4, new Rect(0f, 0f, (float)((Texture)val4).width, (float)((Texture)val4).height), new Vector2(0.5f, 0.5f), val3.pixelsPerUnit);
				}
				catch (Exception ex)
				{
					Log.LogWarning((object)("Ícone não recolorido: " + ex.Message));
				}
			}
		}

		private static Texture2D Readable(Texture src)
		{
			//IL_0036: Unknown result type (might be due to invalid IL or missing references)
			//IL_003b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0054: Unknown result type (might be due to invalid IL or missing references)
			//IL_0060: Unknown result type (might be due to invalid IL or missing references)
			//IL_0073: Expected O, but got Unknown
			RenderTexture temporary = RenderTexture.GetTemporary(src.width, src.height, 0, (RenderTextureFormat)0, (RenderTextureReadWrite)2);
			RenderTexture active = RenderTexture.active;
			Graphics.Blit(src, temporary);
			RenderTexture.active = temporary;
			Texture2D val = new Texture2D(src.width, src.height, (TextureFormat)4, true);
			val.ReadPixels(new Rect(0f, 0f, (float)src.width, (float)src.height), 0, 0);
			val.Apply();
			RenderTexture.active = active;
			RenderTexture.ReleaseTemporary(temporary);
			return val;
		}

		private static void PaintTex(Texture2D t, Color c)
		{
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			//IL_000d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0021: Unknown result type (might be due to invalid IL or missing references)
			//IL_002b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0030: Unknown result type (might be due to invalid IL or missing references)
			//IL_0071: Unknown result type (might be due to invalid IL or missing references)
			//IL_007f: 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_0086: Unknown result type (might be due to invalid IL or missing references)
			//IL_00aa: Unknown result type (might be due to invalid IL or missing references)
			//IL_00af: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c8: Unknown result type (might be due to invalid IL or missing references)
			Color[] pixels = t.GetPixels();
			Color val = Color.Lerp(c * 4f, new Color(0.75f, 0.45f, 1f), 0.4f);
			for (int i = 0; i < pixels.Length; i++)
			{
				float num = pixels[i].r * 0.3f + pixels[i].g * 0.59f + pixels[i].b * 0.11f;
				Color val2 = Color.Lerp(c * (0.35f + num * 1.2f), val * num, Mathf.SmoothStep(0f, 1f, Mathf.InverseLerp(0.55f, 0.85f, num)));
				val2.a = pixels[i].a;
				pixels[i] = val2;
			}
			t.SetPixels(pixels);
			t.Apply(true);
		}

		private static bool ReplaceSpawner(Attack atk)
		{
			//IL_015e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0168: Expected O, but got Unknown
			//IL_0144: Unknown result type (might be due to invalid IL or missing references)
			//IL_014e: Expected O, but got Unknown
			GameObject val = (((Object)(object)atk.m_attackProjectile != (Object)null) ? atk.m_attackProjectile : atk.m_spawnOnTrigger);
			if ((Object)(object)val == (Object)null)
			{
				return false;
			}
			Log.LogInfo((object)("Ataque do Ressuscitador: tipo=" + ((object)Unsafe.As<AttackType, AttackType>(ref atk.m_attackType)/*cast due to .constrained prefix*/).ToString() + " projétil=" + (Object.op_Implicit((Object)(object)atk.m_attackProjectile) ? ((Object)atk.m_attackProjectile).name : "-") + " spawnOnTrigger=" + (Object.op_Implicit((Object)(object)atk.m_spawnOnTrigger) ? ((Object)atk.m_spawnOnTrigger).name : "-")));
			GameObject val2 = PrefabManager.Instance.CreateClonedPrefab(((Object)val).name + "_cinzas", val);
			SpawnAbility componentInChildren = val2.GetComponentInChildren<SpawnAbility>(true);
			if ((Object)(object)componentInChildren == (Object)null)
			{
				Projectile component = val2.GetComponent<Projectile>();
				GameObject val3 = (((Object)(object)component != (Object)null) ? component.m_spawnOnHit : null);
				if ((Object)(object)val3 == (Object)null || (Object)(object)val3.GetComponentInChildren<SpawnAbility>(true) == (Object)null)
				{
					return false;
				}
				GameObject val4 = (component.m_spawnOnHit = PrefabManager.Instance.CreateClonedPrefab(((Object)val3).name + "_cinzas", val3));
				PrefabManager.Instance.AddPrefab(new CustomPrefab(val4, true));
				componentInChildren = val4.GetComponentInChildren<SpawnAbility>(true);
			}
			PrefabManager.Instance.AddPrefab(new CustomPrefab(val2, true));
			if ((Object)(object)atk.m_attackProjectile == (Object)(object)val)
			{
				atk.m_attackProjectile = val2;
			}
			else
			{
				atk.m_spawnOnTrigger = val2;
			}
			GameObject val5 = ((componentInChildren.m_spawnPrefab != null && componentInChildren.m_spawnPrefab.Length != 0) ? componentInChildren.m_spawnPrefab[0] : null);
			if ((Object)(object)val5 == (Object)null)
			{
				return false;
			}
			Log.LogInfo((object)("Esqueleto aliado de referência: " + ((Object)val5).name + " (componentes: " + string.Join(", ", from c in val5.GetComponents<Component>()
				select ((object)c).GetType().Name) + ")"));
			List<GameObject> list = new List<GameObject>();
			string[] array = Mobs.Value.Split(new char[3] { ',', ';', ' ' }, StringSplitOptions.RemoveEmptyEntries);
			for (int num = 0; num < array.Length; num++)
			{
				GameObject val6 = MakeFriendly(array[num].Trim(), val5);
				if ((Object)(object)val6 != (Object)null)
				{
					list.Add(val6);
				}
			}
			if (list.Count == 0)
			{
				return false;
			}
			componentInChildren.m_spawnPrefab = list.ToArray();
			_spawn = componentInChildren;
			_origMax = componentInChildren.m_maxSpawned;
			return true;
		}

		private static GameObject MakeFriendly(string id, GameObject friendly)
		{
			//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_0222: Unknown result type (might be due to invalid IL or missing references)
			//IL_022c: Expected O, but got Unknown
			GameObject prefab = PrefabManager.Instance.GetPrefab(id);
			if ((Object)(object)prefab == (Object)null)
			{
				Log.LogWarning((object)("Mob não encontrado: " + id));
				return null;
			}
			GameObject val = PrefabManager.Instance.CreateClonedPrefab(id + "_PandheryaAliado", prefab);
			Log.LogInfo((object)("Carbonizado " + id + " (componentes: " + string.Join(", ", from c in val.GetComponents<Component>()
				select ((object)c).GetType().Name) + ")"));
			Character component = friendly.GetComponent<Character>();
			Character component2 = val.GetComponent<Character>();
			if ((Object)(object)component != (Object)null && (Object)(object)component2 != (Object)null)
			{
				component2.m_faction = component.m_faction;
				component2.m_name = "Carbonizado aliado";
			}
			MonsterAI component3 = friendly.GetComponent<MonsterAI>();
			MonsterAI component4 = val.GetComponent<MonsterAI>();
			if ((Object)(object)component3 != (Object)null && (Object)(object)component4 != (Object)null)
			{
				string[] array = new string[4] { "m_enableHuntPlayer", "m_attackPlayerObjects", "m_aggravatable", "m_passiveAggresive" };
				foreach (string name in array)
				{
					CopyField(component3, component4, typeof(MonsterAI), name);
				}
			}
			Component[] components = friendly.GetComponents<Component>();
			foreach (Component val2 in components)
			{
				Type type = ((object)val2).GetType();
				if (!(type == typeof(Transform)) && !((Object)(object)val.GetComponent(type) != (Object)null) && val2 is MonoBehaviour && !(type == typeof(CharacterDrop)))
				{
					Component to = val.AddComponent(type);
					CopyAll(val2, to);
					Log.LogInfo((object)("  + copiado do aliado: " + type.Name));
				}
			}
			CharacterDrop component5 = val.GetComponent<CharacterDrop>();
			if ((Object)(object)component5 != (Object)null)
			{
				Object.DestroyImmediate((Object)(object)component5);
			}
			val.AddComponent<MinionTag>();
			PrefabManager.Instance.AddPrefab(new CustomPrefab(val, true));
			_minions.Add(val);
			return val;
		}

		private static void CopyField(object from, object to, Type t, string name)
		{
			FieldInfo fieldInfo = AccessTools(t, name);
			if (fieldInfo != null)
			{
				fieldInfo.SetValue(to, fieldInfo.GetValue(from));
			}
		}

		private static FieldInfo AccessTools(Type t, string name)
		{
			Type type = t;
			while (type != null)
			{
				FieldInfo field = type.GetField(name, BindingFlags.DeclaredOnly | BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
				if (field != null)
				{
					return field;
				}
				type = type.BaseType;
			}
			return null;
		}

		private static void CopyAll(Component from, Component to)
		{
			Type type = ((object)from).GetType();
			while (type != null && type != typeof(MonoBehaviour))
			{
				FieldInfo[] fields = type.GetFields(BindingFlags.DeclaredOnly | BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
				foreach (FieldInfo fieldInfo in fields)
				{
					if (!fieldInfo.IsNotSerialized && (fieldInfo.IsPublic || ((MemberInfo)fieldInfo).GetCustomAttribute<SerializeField>() != null))
					{
						try
						{
							fieldInfo.SetValue(to, fieldInfo.GetValue(from));
						}
						catch
						{
						}
					}
				}
				type = type.BaseType;
			}
		}

		private void Update()
		{
			//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)
			Player localPlayer = Player.m_localPlayer;
			if ((Object)(object)localPlayer == (Object)null)
			{
				return;
			}
			bool flag = false;
			try
			{
				flag = (bool)TakeInput.Invoke(localPlayer, null);
			}
			catch
			{
			}
			if (!flag)
			{
				return;
			}
			KeyboardShortcut value = HostileKey.Value;
			if (((KeyboardShortcut)(ref value)).IsDown())
			{
				ZNetView component = ((Component)localPlayer).GetComponent<ZNetView>();
				if (!((Object)(object)component == (Object)null) && component.IsValid())
				{
					bool flag2 = !component.GetZDO().GetBool("ash_hostile", false);
					component.GetZDO().Set("ash_hostile", flag2);
					((Character)localPlayer).Message((MessageType)2, flag2 ? "Carbonizados: atacando outros jogadores" : "Carbonizados: poupando jogadores", 0, (Sprite)null, false);
				}
			}
		}

		internal static void ApplyLive()
		{
			if ((Object)(object)_spawn != (Object)null)
			{
				_spawn.m_maxSpawned = ((MaxSpawned.Value > 0) ? MaxSpawned.Value : _origMax);
			}
			foreach (GameObject minion in _minions)
			{
				if (!((Object)(object)minion == (Object)null))
				{
					CharacterTimedDestruction component = minion.GetComponent<CharacterTimedDestruction>();
					if ((Object)(object)component != (Object)null)
					{
						component.m_timeoutMin = Duration.Value;
						component.m_timeoutMax = Duration.Value;
					}
				}
			}
			if (_shared != null)
			{
				_shared.m_attack.m_attackHealth = ((HealthCost.Value >= 0f) ? HealthCost.Value : _origHealth);
				_shared.m_attack.m_attackEitr = ((EitrCost.Value >= 0f) ? EitrCost.Value : _origEitr);
			}
			GameObject val = (((Object)(object)ObjectDB.instance != (Object)null) ? ObjectDB.instance.GetItemPrefab("StaffAshPandherya") : null);
			ItemDrop val2 = (((Object)(object)val != (Object)null) ? val.GetComponent<ItemDrop>() : null);
			if ((Object)(object)val2 != (Object)null && _shared != null && val2.m_itemData.m_shared != _shared)
			{
				val2.m_itemData.m_shared.m_attack.m_attackHealth = _shared.m_attack.m_attackHealth;
				val2.m_itemData.m_shared.m_attack.m_attackEitr = _shared.m_attack.m_attackEitr;
			}
		}
	}
	public class MinionTag : MonoBehaviour
	{
		private ZNetView _nv;

		private MonsterAI _ai;

		private float _next;

		internal long OwnerId;

		internal bool Hostile;

		private void Awake()
		{
			_nv = ((Component)this).GetComponent<ZNetView>();
			_ai = ((Component)this).GetComponent<MonsterAI>();
		}

		private void Start()
		{
			//IL_0065: Unknown result type (might be due to invalid IL or missing references)
			//IL_0070: Unknown result type (might be due to invalid IL or missing references)
			if (!((Object)(object)_nv == (Object)null) && _nv.IsValid())
			{
				ZDO zDO = _nv.GetZDO();
				OwnerId = zDO.GetLong("ash_owner", 0L);
				Player localPlayer = Player.m_localPlayer;
				if (OwnerId == 0L && _nv.IsOwner() && (Object)(object)localPlayer != (Object)null && Vector3.Distance(((Component)localPlayer).transform.position, ((Component)this).transform.position) < 40f)
				{
					OwnerId = localPlayer.GetPlayerID();
					zDO.Set("ash_owner", OwnerId);
				}
			}
		}

		private void Update()
		{
			if (Time.time < _next || (Object)(object)_nv == (Object)null || !_nv.IsValid())
			{
				return;
			}
			_next = Time.time + 0.5f;
			ZDO zDO = _nv.GetZDO();
			if (OwnerId == 0L)
			{
				OwnerId = zDO.GetLong("ash_owner", 0L);
			}
			Player val = ((OwnerId != 0L) ? Player.GetPlayer(OwnerId) : null);
			ZNetView val2 = (((Object)(object)val != (Object)null) ? ((Component)val).GetComponent<ZNetView>() : null);
			if ((Object)(object)val2 != (Object)null && val2.IsValid())
			{
				Hostile = val2.GetZDO().GetBool("ash_hostile", false);
				if (_nv.IsOwner() && zDO.GetBool("ash_hostile", false) != Hostile)
				{
					zDO.Set("ash_hostile", Hostile);
				}
			}
			else
			{
				Hostile = zDO.GetBool("ash_hostile", false);
			}
			if ((Object)(object)_ai != (Object)null)
			{
				_ai.m_enableHuntPlayer = Hostile;
			}
		}

		internal static MinionTag Of(Character c)
		{
			if (!((Object)(object)c != (Object)null))
			{
				return null;
			}
			return ((Component)c).GetComponent<MinionTag>();
		}
	}
	[HarmonyPatch(typeof(BaseAI), "IsEnemy", new Type[]
	{
		typeof(Character),
		typeof(Character)
	})]
	internal static class MinionEnemy
	{
		private static void Postfix(Character a, Character b, ref bool __result)
		{
			MinionTag minionTag = MinionTag.Of(a);
			if ((Object)(object)minionTag != (Object)null)
			{
				Decide(minionTag, b, ref __result);
				return;
			}
			MinionTag minionTag2 = MinionTag.Of(b);
			if ((Object)(object)minionTag2 != (Object)null)
			{
				Decide(minionTag2, a, ref __result);
			}
		}

		private static void Decide(MinionTag t, Character other, ref bool result)
		{
			if ((Object)(object)other == (Object)null)
			{
				return;
			}
			Player val = (Player)(object)((other is Player) ? other : null);
			if (val != null)
			{
				if (t.OwnerId != 0L && val.GetPlayerID() == t.OwnerId)
				{
					result = false;
				}
				else if (t.Hostile)
				{
					result = true;
				}
			}
			else
			{
				MinionTag minionTag = MinionTag.Of(other);
				if ((Object)(object)minionTag != (Object)null && minionTag.OwnerId == t.OwnerId)
				{
					result = false;
				}
			}
		}
	}
	internal class ConfigReload : MonoBehaviour
	{
		private ConfigFile _cfg;

		private Action _after;

		private volatile bool _dirty;

		private float _at;

		internal static void Watch(BaseUnityPlugin plugin, ConfigFile cfg, string guid, Action after = null)
		{
			ConfigReload r = ((Component)plugin).gameObject.AddComponent<ConfigReload>();
			r._cfg = cfg;
			r._after = after;
			try
			{
				FileSystemWatcher fileSystemWatcher = new FileSystemWatcher(Paths.ConfigPath, guid + ".cfg");
				fileSystemWatcher.NotifyFilter = NotifyFilters.FileName | NotifyFilters.Size | NotifyFilters.LastWrite;
				fileSystemWatcher.Changed += delegate
				{
					r._dirty = true;
				};
				fileSystemWatcher.Created += delegate
				{
					r._dirty = true;
				};
				fileSystemWatcher.Renamed += delegate
				{
					r._dirty = true;
				};
				fileSystemWatcher.EnableRaisingEvents = true;
			}
			catch (Exception ex)
			{
				Plugin.Log.LogWarning((object)("Sem recarga automática do cfg: " + ex.Message));
			}
		}

		private void Update()
		{
			if (_dirty)
			{
				_dirty = false;
				_at = Time.time + 0.3f;
			}
			if (_at > 0f && Time.time >= _at)
			{
				_at = 0f;
				try
				{
					_cfg.Reload();
					_after?.Invoke();
					Plugin.Log.LogInfo((object)"Config recarregada.");
				}
				catch (Exception ex)
				{
					Plugin.Log.LogWarning((object)("Falha ao recarregar cfg: " + ex.Message));
				}
			}
		}
	}
}