Decompiled source of PoisonAndTastyMeadVFX v1.0.0

BepInEx/plugins/PoisonAndTastyMeadVFX.dll

Decompiled 2 days ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Logging;
using HarmonyLib;
using Jotunn.Entities;
using Jotunn.Managers;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: AssemblyTitle("PoisonAndTastyMeadVFX")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("PoisonAndTastyMeadVFX")]
[assembly: AssemblyCopyright("Copyright ©  2026")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("d15808e3-1ad2-4b29-b708-c96d407a1f4d")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")]
[assembly: AssemblyVersion("1.0.0.0")]
namespace PoisonAndTastyMeadVFX;

[BepInPlugin("chase.poisonandtastymeadvfx", "Poison and Tasty Mead VFX", "1.0.0")]
[BepInDependency(/*Could not decode attribute arguments.*/)]
public class PoisonAndTastyMeadVFXPlugin : BaseUnityPlugin
{
	public const string PluginGUID = "chase.poisonandtastymeadvfx";

	public const string PluginName = "Poison and Tasty Mead VFX";

	public const string PluginVersion = "1.0.0";

	internal static ManualLogSource Log;

	private void Awake()
	{
		Log = ((BaseUnityPlugin)this).Logger;
		((Component)this).gameObject.AddComponent<PoisonMeadVFXPlugin>();
		((Component)this).gameObject.AddComponent<TastyMeadVFXPlugin>();
		Harmony.CreateAndPatchAll(typeof(PoisonAndTastyMeadVFXPlugin).Assembly, "chase.poisonandtastymeadvfx");
		Log.LogInfo((object)"Poison and Tasty Mead VFX loaded.");
	}
}
internal class PoisonMeadVFXPlugin : MonoBehaviour
{
	public const string PluginGUID = "chase.poisonmeadvfx";

	public const string PluginName = "Poison Mead VFX";

	public const string PluginVersion = "1.6.3";

	internal static PoisonMeadVFXPlugin Instance;

	private GameObject greenFx;

	private CustomRPC poisonVfxRpc;

	internal static bool SuppressNetworkBroadcast;

	private const float RemotePlayerResolveTimeoutSeconds = 1f;

	private readonly Color poisonGreen = new Color(0.15f, 1f, 0.15f, 1f);

	private void Awake()
	{
		//IL_0019: Unknown result type (might be due to invalid IL or missing references)
		//IL_0025: Unknown result type (might be due to invalid IL or missing references)
		//IL_002f: Expected O, but got Unknown
		//IL_002f: Expected O, but got Unknown
		Instance = this;
		poisonVfxRpc = NetworkManager.Instance.AddRPC("PoisonResistanceVFX", new CoroutineHandler(OnServerReceivePoisonVFX), new CoroutineHandler(OnClientReceivePoisonVFX));
		PrefabManager.OnVanillaPrefabsAvailable += CreateGreenEffect;
		ItemManager.OnItemsRegistered += ModifyPoisonStatusEffect;
	}

	internal void HandleStatusEffectStart(StatusEffect statusEffect)
	{
		//IL_009b: 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)
		if ((Object)(object)statusEffect == (Object)null || ((Object)statusEffect).name != "Potion_poisonresist")
		{
			return;
		}
		Character value = Traverse.Create((object)statusEffect).Field("m_character").GetValue<Character>();
		if ((Object)(object)value == (Object)null)
		{
			PoisonAndTastyMeadVFXPlugin.Log.LogWarning((object)"Poison Mead activation detected, but m_character was not available.");
		}
		else
		{
			if ((Object)(object)value != (Object)(object)Player.m_localPlayer)
			{
				return;
			}
			if ((Object)(object)greenFx == (Object)null)
			{
				PoisonAndTastyMeadVFXPlugin.Log.LogWarning((object)"Poison Mead activation detected, but the green VFX prefab is not available.");
				return;
			}
			GameObject val = Object.Instantiate<GameObject>(greenFx, value.GetCenterPoint(), ((Component)value).transform.rotation);
			if ((Object)(object)val != (Object)null)
			{
				val.transform.SetParent(((Component)value).transform, true);
			}
		}
	}

	private void CreateGreenEffect()
	{
		//IL_010a: Unknown result type (might be due to invalid IL or missing references)
		//IL_010f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0113: Unknown result type (might be due to invalid IL or missing references)
		//IL_0118: Unknown result type (might be due to invalid IL or missing references)
		//IL_011b: Unknown result type (might be due to invalid IL or missing references)
		//IL_011e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0123: Unknown result type (might be due to invalid IL or missing references)
		//IL_0128: Unknown result type (might be due to invalid IL or missing references)
		//IL_012c: 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)
		PrefabManager.OnVanillaPrefabsAvailable -= CreateGreenEffect;
		greenFx = PrefabManager.Instance.CreateClonedPrefab("fx_Potion_poisonresist_green", "fx_Potion_fireresist");
		if ((Object)(object)greenFx == (Object)null)
		{
			PoisonAndTastyMeadVFXPlugin.Log.LogError((object)"Failed to clone fx_Potion_fireresist.");
			return;
		}
		ZSyncTransform component = greenFx.GetComponent<ZSyncTransform>();
		if ((Object)(object)component != (Object)null)
		{
			Object.DestroyImmediate((Object)(object)component);
		}
		ZNetView component2 = greenFx.GetComponent<ZNetView>();
		if ((Object)(object)component2 != (Object)null)
		{
			Object.DestroyImmediate((Object)(object)component2);
		}
		if ((Object)(object)greenFx.GetComponent<PoisonVFXNetworkTrigger>() == (Object)null)
		{
			greenFx.AddComponent<PoisonVFXNetworkTrigger>();
		}
		ParticleSystem[] componentsInChildren = greenFx.GetComponentsInChildren<ParticleSystem>(true);
		ParticleSystem[] array = componentsInChildren;
		foreach (ParticleSystem val in array)
		{
			string name = ((Object)((Component)val).gameObject).name;
			if (name == "flare")
			{
				RecolorFlareMaterial(val);
				continue;
			}
			MainModule main = val.main;
			MinMaxGradient startColor = ((MainModule)(ref main)).startColor;
			MinMaxGradient startColor2 = RecolorGradient(startColor, poisonGreen);
			((MainModule)(ref main)).startColor = startColor2;
		}
		Light[] componentsInChildren2 = greenFx.GetComponentsInChildren<Light>(true);
		Light[] array2 = componentsInChildren2;
		foreach (Light val2 in array2)
		{
			val2.color = new Color(0.1f, 0.85f, 0.1f, 1f);
		}
	}

	private void RecolorFlareMaterial(ParticleSystem particle)
	{
		//IL_0051: Unknown result type (might be due to invalid IL or missing references)
		//IL_0057: Expected O, but got Unknown
		//IL_0096: Unknown result type (might be due to invalid IL or missing references)
		ParticleSystemRenderer component = ((Component)particle).GetComponent<ParticleSystemRenderer>();
		if ((Object)(object)component == (Object)null)
		{
			PoisonAndTastyMeadVFXPlugin.Log.LogError((object)"Flare ParticleSystemRenderer not found.");
			return;
		}
		Material sharedMaterial = ((Renderer)component).sharedMaterial;
		if ((Object)(object)sharedMaterial == (Object)null)
		{
			PoisonAndTastyMeadVFXPlugin.Log.LogError((object)"Flare material not found.");
			return;
		}
		Material val = new Material(sharedMaterial);
		((Object)val).name = "PoisonResist_Flare_Material";
		if (val.HasProperty("_TintColor"))
		{
			Color val2 = default(Color);
			((Color)(ref val2))..ctor(0.15f, 1.67f, 0.815f, 0.1f);
			val.SetColor("_TintColor", val2);
		}
		else
		{
			PoisonAndTastyMeadVFXPlugin.Log.LogWarning((object)"Flare material does not have _TintColor.");
		}
		((Renderer)component).sharedMaterial = val;
	}

	private MinMaxGradient RecolorGradient(MinMaxGradient original, Color newColor)
	{
		//IL_0003: Unknown result type (might be due to invalid IL or missing references)
		//IL_0008: Unknown result type (might be due to invalid IL or missing references)
		//IL_0009: Unknown result type (might be due to invalid IL or missing references)
		//IL_000a: Unknown result type (might be due to invalid IL or missing references)
		//IL_000b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0025: Expected I4, but got Unknown
		//IL_002d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0032: Unknown result type (might be due to invalid IL or missing references)
		//IL_0033: Unknown result type (might be due to invalid IL or missing references)
		//IL_003c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0049: 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_0069: Unknown result type (might be due to invalid IL or missing references)
		//IL_006a: Unknown result type (might be due to invalid IL or missing references)
		//IL_006f: 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_00fa: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ff: 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_007e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0082: Unknown result type (might be due to invalid IL or missing references)
		//IL_0087: Unknown result type (might be due to invalid IL or missing references)
		//IL_008b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0098: Unknown result type (might be due to invalid IL or missing references)
		//IL_00a5: 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_00bf: Unknown result type (might be due to invalid IL or missing references)
		//IL_00cc: Unknown result type (might be due to invalid IL or missing references)
		//IL_00d7: 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_00db: Unknown result type (might be due to invalid IL or missing references)
		//IL_00e0: Unknown result type (might be due to invalid IL or missing references)
		//IL_010f: Unknown result type (might be due to invalid IL or missing references)
		//IL_011f: Unknown result type (might be due to invalid IL or missing references)
		//IL_012b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0130: 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_0157: Unknown result type (might be due to invalid IL or missing references)
		//IL_0159: Unknown result type (might be due to invalid IL or missing references)
		//IL_018e: 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_0189: Unknown result type (might be due to invalid IL or missing references)
		//IL_018a: Unknown result type (might be due to invalid IL or missing references)
		ParticleSystemGradientMode mode = ((MinMaxGradient)(ref original)).mode;
		ParticleSystemGradientMode val = mode;
		switch ((int)val)
		{
		case 0:
		{
			Color color = ((MinMaxGradient)(ref original)).color;
			float a = color.a;
			color.r = newColor.r;
			color.g = newColor.g;
			color.b = newColor.b;
			color.a = a;
			return new MinMaxGradient(color);
		}
		case 2:
		{
			Color colorMin = ((MinMaxGradient)(ref original)).colorMin;
			Color colorMax = ((MinMaxGradient)(ref original)).colorMax;
			colorMin.r = newColor.r;
			colorMin.g = newColor.g;
			colorMin.b = newColor.b;
			colorMax.r = newColor.r;
			colorMax.g = newColor.g;
			colorMax.b = newColor.b;
			return new MinMaxGradient(colorMin, colorMax);
		}
		case 1:
		{
			Gradient val5 = RecolorUnityGradient(((MinMaxGradient)(ref original)).gradient, newColor);
			return new MinMaxGradient(val5);
		}
		case 3:
		{
			Gradient val3 = RecolorUnityGradient(((MinMaxGradient)(ref original)).gradientMin, newColor);
			Gradient val4 = RecolorUnityGradient(((MinMaxGradient)(ref original)).gradientMax, newColor);
			return new MinMaxGradient(val3, val4);
		}
		case 4:
		{
			Gradient val2 = RecolorUnityGradient(((MinMaxGradient)(ref original)).gradient, newColor);
			MinMaxGradient result = default(MinMaxGradient);
			((MinMaxGradient)(ref result))..ctor(val2);
			((MinMaxGradient)(ref result)).mode = (ParticleSystemGradientMode)4;
			return result;
		}
		default:
			PoisonAndTastyMeadVFXPlugin.Log.LogWarning((object)("Unknown particle gradient mode: " + $"{((MinMaxGradient)(ref original)).mode}"));
			return original;
		}
	}

	private Gradient RecolorUnityGradient(Gradient original, Color newColor)
	{
		//IL_0014: Unknown result type (might be due to invalid IL or missing references)
		//IL_001a: Expected O, but got Unknown
		//IL_0032: Unknown result type (might be due to invalid IL or missing references)
		//IL_0038: Unknown result type (might be due to invalid IL or missing references)
		//IL_003e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0051: Unknown result type (might be due to invalid IL or missing references)
		//IL_0060: Unknown result type (might be due to invalid IL or missing references)
		//IL_0065: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b3: 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_00dd: Unknown result type (might be due to invalid IL or missing references)
		if (original == null)
		{
			return null;
		}
		Gradient val = new Gradient();
		GradientColorKey[] colorKeys = original.colorKeys;
		GradientColorKey[] array = (GradientColorKey[])(object)new GradientColorKey[colorKeys.Length];
		Color val2 = default(Color);
		for (int i = 0; i < colorKeys.Length; i++)
		{
			((Color)(ref val2))..ctor(newColor.r, newColor.g, newColor.b, 1f);
			array[i] = new GradientColorKey(val2, colorKeys[i].time);
		}
		GradientAlphaKey[] alphaKeys = original.alphaKeys;
		GradientAlphaKey[] array2 = (GradientAlphaKey[])(object)new GradientAlphaKey[alphaKeys.Length];
		for (int j = 0; j < alphaKeys.Length; j++)
		{
			array2[j] = new GradientAlphaKey(alphaKeys[j].alpha, alphaKeys[j].time);
		}
		val.SetKeys(array, array2);
		val.mode = original.mode;
		return val;
	}

	private void ModifyPoisonStatusEffect()
	{
		//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_00d9: Unknown result type (might be due to invalid IL or missing references)
		//IL_00e1: Expected O, but got Unknown
		if ((Object)(object)ObjectDB.instance == (Object)null)
		{
			PoisonAndTastyMeadVFXPlugin.Log.LogError((object)"ObjectDB.instance is null.");
			return;
		}
		StatusEffect val = ((IEnumerable<StatusEffect>)ObjectDB.instance.m_StatusEffects).FirstOrDefault((Func<StatusEffect, bool>)((StatusEffect se) => (Object)(object)se != (Object)null && ((Object)se).name == "Potion_poisonresist"));
		if ((Object)(object)val == (Object)null)
		{
			PoisonAndTastyMeadVFXPlugin.Log.LogError((object)"Could not find runtime Potion_poisonresist.");
			return;
		}
		if ((Object)(object)greenFx == (Object)null)
		{
			PoisonAndTastyMeadVFXPlugin.Log.LogError((object)"Green Poison Resistance VFX was not created.");
			return;
		}
		GameObject prefab = PrefabManager.Instance.GetPrefab("sfx_Potion_fireresist_Start");
		if ((Object)(object)prefab == (Object)null)
		{
			PoisonAndTastyMeadVFXPlugin.Log.LogError((object)"Could not find sfx_Potion_fireresist_Start.");
			return;
		}
		EffectData val2 = new EffectData
		{
			m_prefab = prefab,
			m_enabled = true
		};
		val.m_startEffects.m_effectPrefabs = (EffectData[])(object)new EffectData[1] { val2 };
		PoisonAndTastyMeadVFXPlugin.Log.LogInfo((object)"Poison Resistance Mead VFX installed successfully.");
	}

	internal void BroadcastPoisonVFX(Vector3 position, Quaternion rotation)
	{
		//IL_0051: 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_0056: Unknown result type (might be due to invalid IL or missing references)
		//IL_006a: Unknown result type (might be due to invalid IL or missing references)
		//IL_006b: Unknown result type (might be due to invalid IL or missing references)
		//IL_006c: Unknown result type (might be due to invalid IL or missing references)
		//IL_009f: 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_00a1: Unknown result type (might be due to invalid IL or missing references)
		if (SuppressNetworkBroadcast || poisonVfxRpc == null || (Object)(object)ZNet.instance == (Object)null)
		{
			return;
		}
		long uID = ZNet.GetUID();
		Player localPlayer = Player.m_localPlayer;
		ZDOID playerZdoId = (((Object)(object)localPlayer != (Object)null) ? ((Character)localPlayer).GetZDOID() : ZDOID.None);
		if (ZNet.instance.IsServer())
		{
			ForwardPoisonVFXFromServer(uID, playerZdoId, position, rotation);
			return;
		}
		ZNetPeer serverPeer = ZNet.instance.GetServerPeer();
		if (serverPeer == null)
		{
			PoisonAndTastyMeadVFXPlugin.Log.LogWarning((object)"Could not send Poison VFX activation: server peer was not available.");
			return;
		}
		ZPackage val = CreateVFXPackage(uID, playerZdoId, position, rotation);
		poisonVfxRpc.SendPackage(serverPeer.m_uid, val);
	}

	private IEnumerator OnServerReceivePoisonVFX(long sender, ZPackage package)
	{
		long origin = package.ReadLong();
		ZDOID playerZdoId = package.ReadZDOID();
		Vector3 position = package.ReadVector3();
		Quaternion rotation = package.ReadQuaternion();
		if (origin != ZNet.GetUID())
		{
			SpawnRemoteVFX(playerZdoId, position, rotation);
		}
		ForwardPoisonVFXFromServer(origin, playerZdoId, position, rotation);
		yield break;
	}

	private IEnumerator OnClientReceivePoisonVFX(long sender, ZPackage package)
	{
		long origin = package.ReadLong();
		ZDOID playerZdoId = package.ReadZDOID();
		Vector3 position = package.ReadVector3();
		Quaternion rotation = package.ReadQuaternion();
		if (origin != ZNet.GetUID())
		{
			SpawnRemoteVFX(playerZdoId, position, rotation);
		}
		yield break;
	}

	private void ForwardPoisonVFXFromServer(long origin, ZDOID playerZdoId, Vector3 position, Quaternion rotation)
	{
		//IL_002f: 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_0031: Unknown result type (might be due to invalid IL or missing references)
		if (poisonVfxRpc != null && !((Object)(object)ZNet.instance == (Object)null) && ZNet.instance.IsServer())
		{
			ZPackage val = CreateVFXPackage(origin, playerZdoId, position, rotation);
			poisonVfxRpc.SendPackage(0L, val);
		}
	}

	private ZPackage CreateVFXPackage(long origin, ZDOID playerZdoId, Vector3 position, Quaternion rotation)
	{
		//IL_0001: Unknown result type (might be due to invalid IL or missing references)
		//IL_0007: Expected O, but got Unknown
		//IL_0010: Unknown result type (might be due to invalid IL or missing references)
		//IL_0018: 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)
		ZPackage val = new ZPackage();
		val.Write(origin);
		val.Write(playerZdoId);
		val.Write(position);
		val.Write(rotation);
		return val;
	}

	private void SpawnRemoteVFX(ZDOID playerZdoId, Vector3 position, Quaternion rotation)
	{
		//IL_0033: Unknown result type (might be due to invalid IL or missing references)
		//IL_0034: Unknown result type (might be due to invalid IL or missing references)
		//IL_0057: Unknown result type (might be due to invalid IL or missing references)
		//IL_0067: Unknown result type (might be due to invalid IL or missing references)
		if ((Object)(object)greenFx == (Object)null)
		{
			PoisonAndTastyMeadVFXPlugin.Log.LogWarning((object)"Could not spawn remote Poison VFX because the green prefab is not available.");
			return;
		}
		SuppressNetworkBroadcast = true;
		GameObject val = null;
		try
		{
			val = Object.Instantiate<GameObject>(greenFx, position, rotation);
		}
		finally
		{
			SuppressNetworkBroadcast = false;
		}
		if (!((Object)(object)val == (Object)null) && !TryAttachRemoteVFX(val, playerZdoId))
		{
			((MonoBehaviour)this).StartCoroutine(AttachRemoteVFXWhenPlayerReady(val, playerZdoId));
		}
	}

	private bool TryAttachRemoteVFX(GameObject remoteFx, ZDOID playerZdoId)
	{
		//IL_000a: Unknown result type (might be due to invalid IL or missing references)
		//IL_000b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0022: Unknown result type (might be due to invalid IL or missing references)
		if ((Object)(object)remoteFx == (Object)null || playerZdoId == ZDOID.None)
		{
			return false;
		}
		Player val = ResolvePlayer(playerZdoId);
		if ((Object)(object)val == (Object)null)
		{
			return false;
		}
		remoteFx.transform.SetParent(((Component)val).transform, true);
		return true;
	}

	private IEnumerator AttachRemoteVFXWhenPlayerReady(GameObject remoteFx, ZDOID playerZdoId)
	{
		//IL_0015: 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)
		float timeoutAt = Time.realtimeSinceStartup + 1f;
		while ((Object)(object)remoteFx != (Object)null && Time.realtimeSinceStartup < timeoutAt)
		{
			yield return null;
			if (TryAttachRemoteVFX(remoteFx, playerZdoId))
			{
				yield break;
			}
		}
		if ((Object)(object)remoteFx != (Object)null)
		{
			PoisonAndTastyMeadVFXPlugin.Log.LogWarning((object)("Remote Poison VFX could not resolve player " + $"{playerZdoId} within " + $"{1f:0.0}s; " + "leaving the VFX at its original world position."));
		}
	}

	private Player ResolvePlayer(ZDOID playerZdoId)
	{
		//IL_0001: Unknown result type (might be due to invalid IL or missing references)
		//IL_0002: Unknown result type (might be due to invalid IL or missing references)
		//IL_002a: Unknown result type (might be due to invalid IL or missing references)
		if (playerZdoId == ZDOID.None || (Object)(object)ZNetScene.instance == (Object)null)
		{
			return null;
		}
		GameObject val = ZNetScene.instance.FindInstance(playerZdoId);
		if ((Object)(object)val == (Object)null)
		{
			return null;
		}
		return val.GetComponent<Player>();
	}
}
internal class PoisonVFXNetworkTrigger : MonoBehaviour
{
	private void Awake()
	{
		//IL_0028: Unknown result type (might be due to invalid IL or missing references)
		//IL_0033: Unknown result type (might be due to invalid IL or missing references)
		if (!PoisonMeadVFXPlugin.SuppressNetworkBroadcast)
		{
			PoisonMeadVFXPlugin instance = PoisonMeadVFXPlugin.Instance;
			if (!((Object)(object)instance == (Object)null))
			{
				instance.BroadcastPoisonVFX(((Component)this).transform.position, ((Component)this).transform.rotation);
			}
		}
	}
}
internal class TastyMeadVFXPlugin : MonoBehaviour
{
	public const string PluginGUID = "chase.tastymeadvfx";

	public const string PluginName = "Tasty Mead VFX";

	public const string PluginVersion = "1.0.7";

	internal static TastyMeadVFXPlugin Instance;

	private GameObject tastyFx;

	private CustomRPC tastyVfxRpc;

	private StatusEffect tastyStatusEffect;

	internal static bool SuppressNetworkBroadcast;

	private const float RemotePlayerResolveTimeoutSeconds = 1f;

	internal static readonly Color StaminaYellow = new Color(1f, 0.82f, 0.12f, 1f);

	internal static readonly Color HealthPenaltyRed = new Color(1f, 0.12f, 0.08f, 1f);

	internal static readonly Color SupportingGold = new Color(1f, 0.72f, 0.12f, 1f);

	private const float FlareAlphaMultiplier = 0.9f;

	private void Awake()
	{
		//IL_0019: Unknown result type (might be due to invalid IL or missing references)
		//IL_0025: Unknown result type (might be due to invalid IL or missing references)
		//IL_002f: Expected O, but got Unknown
		//IL_002f: Expected O, but got Unknown
		Instance = this;
		tastyVfxRpc = NetworkManager.Instance.AddRPC("TastyMeadVFX", new CoroutineHandler(OnServerReceiveTastyVFX), new CoroutineHandler(OnClientReceiveTastyVFX));
		PrefabManager.OnVanillaPrefabsAvailable += CreateTastyEffect;
		ItemManager.OnItemsRegistered += CacheTastyStatusEffect;
	}

	private void CreateTastyEffect()
	{
		//IL_0127: 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_028e: Unknown result type (might be due to invalid IL or missing references)
		//IL_021d: Unknown result type (might be due to invalid IL or missing references)
		PrefabManager.OnVanillaPrefabsAvailable -= CreateTastyEffect;
		tastyFx = PrefabManager.Instance.CreateClonedPrefab("vfx_Potion_tasty_custom", "vfx_Potion_health_medium");
		if ((Object)(object)tastyFx == (Object)null)
		{
			PoisonAndTastyMeadVFXPlugin.Log.LogError((object)"Failed to clone vfx_Potion_health_medium.");
			return;
		}
		ZSyncTransform component = tastyFx.GetComponent<ZSyncTransform>();
		if ((Object)(object)component != (Object)null)
		{
			Object.DestroyImmediate((Object)(object)component);
		}
		ZNetView component2 = tastyFx.GetComponent<ZNetView>();
		if ((Object)(object)component2 != (Object)null)
		{
			Object.DestroyImmediate((Object)(object)component2);
		}
		if ((Object)(object)tastyFx.GetComponent<TastyVFXNetworkTrigger>() == (Object)null)
		{
			tastyFx.AddComponent<TastyVFXNetworkTrigger>();
		}
		ParticleSystem[] componentsInChildren = tastyFx.GetComponentsInChildren<ParticleSystem>(true);
		ParticleSystem val = ((IEnumerable<ParticleSystem>)componentsInChildren).FirstOrDefault((Func<ParticleSystem, bool>)((ParticleSystem p) => ((Object)((Component)p).gameObject).name == "trails"));
		if ((Object)(object)val == (Object)null)
		{
			PoisonAndTastyMeadVFXPlugin.Log.LogError((object)"Could not find the 'trails' ParticleSystem inside vfx_Potion_health_medium.");
			return;
		}
		((Object)((Component)val).gameObject).name = "trails_tasty_dynamic";
		RecolorParticleSystem(val, Color.white);
		if ((Object)(object)((Component)val).GetComponent<TastyTrailBirthClassifier>() == (Object)null)
		{
			((Component)val).gameObject.AddComponent<TastyTrailBirthClassifier>();
		}
		PoisonAndTastyMeadVFXPlugin.Log.LogInfo((object)"Tasty Mead VFX created successfully.");
		Transform val2 = tastyFx.transform.Find("flakes");
		if ((Object)(object)val2 != (Object)null)
		{
			ParticleSystem component3 = ((Component)val2).GetComponent<ParticleSystem>();
			if ((Object)(object)component3 != (Object)null)
			{
				RecolorParticleSystem(component3, SupportingGold);
			}
			else
			{
				PoisonAndTastyMeadVFXPlugin.Log.LogWarning((object)"Found 'flakes' object but it has no ParticleSystem.");
			}
		}
		else
		{
			PoisonAndTastyMeadVFXPlugin.Log.LogWarning((object)"Could not find 'flakes' child on Tasty Mead VFX.");
		}
		Light[] componentsInChildren2 = tastyFx.GetComponentsInChildren<Light>(true);
		if (componentsInChildren2 != null && componentsInChildren2.Length != 0)
		{
			Light[] array = componentsInChildren2;
			foreach (Light val3 in array)
			{
				if ((Object)(object)val3 != (Object)null)
				{
					val3.color = SupportingGold;
				}
			}
		}
		else
		{
			PoisonAndTastyMeadVFXPlugin.Log.LogWarning((object)"No Light component found on Tasty Mead VFX.");
		}
		Transform val4 = tastyFx.transform.Find("flare");
		if ((Object)(object)val4 != (Object)null)
		{
			ParticleSystem component4 = ((Component)val4).GetComponent<ParticleSystem>();
			if ((Object)(object)component4 != (Object)null)
			{
				RecolorParticleSystem(component4, SupportingGold);
				MultiplyParticleAlpha(component4, 0.9f);
			}
			else
			{
				PoisonAndTastyMeadVFXPlugin.Log.LogWarning((object)"Found 'flare' child, but it has no ParticleSystem.");
			}
		}
		else
		{
			PoisonAndTastyMeadVFXPlugin.Log.LogWarning((object)"Could not find 'flare' child on Tasty Mead VFX.");
		}
	}

	private void RecolorParticleSystem(ParticleSystem particle, Color newColor)
	{
		//IL_0002: Unknown result type (might be due to invalid IL or missing references)
		//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_0012: Unknown result type (might be due to invalid IL or missing references)
		//IL_0013: Unknown result type (might be due to invalid IL or missing references)
		//IL_001f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0024: 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_004e: 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_003b: Unknown result type (might be due to invalid IL or missing references)
		//IL_003c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0062: Unknown result type (might be due to invalid IL or missing references)
		//IL_0067: Unknown result type (might be due to invalid IL or missing references)
		//IL_0068: Unknown result type (might be due to invalid IL or missing references)
		MainModule main = particle.main;
		((MainModule)(ref main)).startColor = RecolorGradient(((MainModule)(ref main)).startColor, newColor);
		ColorOverLifetimeModule colorOverLifetime = particle.colorOverLifetime;
		if (((ColorOverLifetimeModule)(ref colorOverLifetime)).enabled)
		{
			((ColorOverLifetimeModule)(ref colorOverLifetime)).color = RecolorGradient(((ColorOverLifetimeModule)(ref colorOverLifetime)).color, newColor);
		}
		ColorBySpeedModule colorBySpeed = particle.colorBySpeed;
		if (((ColorBySpeedModule)(ref colorBySpeed)).enabled)
		{
			((ColorBySpeedModule)(ref colorBySpeed)).color = RecolorGradient(((ColorBySpeedModule)(ref colorBySpeed)).color, newColor);
		}
	}

	private void MultiplyParticleAlpha(ParticleSystem particle, float multiplier)
	{
		//IL_0002: Unknown result type (might be due to invalid IL or missing references)
		//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_0013: Unknown result type (might be due to invalid IL or missing references)
		//IL_001f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0024: 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_004e: 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_003c: 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_0068: Unknown result type (might be due to invalid IL or missing references)
		MainModule main = particle.main;
		((MainModule)(ref main)).startColor = MultiplyGradientAlpha(((MainModule)(ref main)).startColor, multiplier);
		ColorOverLifetimeModule colorOverLifetime = particle.colorOverLifetime;
		if (((ColorOverLifetimeModule)(ref colorOverLifetime)).enabled)
		{
			((ColorOverLifetimeModule)(ref colorOverLifetime)).color = MultiplyGradientAlpha(((ColorOverLifetimeModule)(ref colorOverLifetime)).color, multiplier);
		}
		ColorBySpeedModule colorBySpeed = particle.colorBySpeed;
		if (((ColorBySpeedModule)(ref colorBySpeed)).enabled)
		{
			((ColorBySpeedModule)(ref colorBySpeed)).color = MultiplyGradientAlpha(((ColorBySpeedModule)(ref colorBySpeed)).color, multiplier);
		}
	}

	private MinMaxGradient MultiplyGradientAlpha(MinMaxGradient source, float multiplier)
	{
		//IL_0003: Unknown result type (might be due to invalid IL or missing references)
		//IL_0008: Unknown result type (might be due to invalid IL or missing references)
		//IL_0017: 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_0025: Unknown result type (might be due to invalid IL or missing references)
		//IL_0034: Unknown result type (might be due to invalid IL or missing references)
		//IL_003d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0042: Unknown result type (might be due to invalid IL or missing references)
		//IL_0051: Unknown result type (might be due to invalid IL or missing references)
		//IL_019d: Unknown result type (might be due to invalid IL or missing references)
		//IL_019e: Unknown result type (might be due to invalid IL or missing references)
		//IL_01a2: Unknown result type (might be due to invalid IL or missing references)
		Color color = ((MinMaxGradient)(ref source)).color;
		color.a *= multiplier;
		((MinMaxGradient)(ref source)).color = color;
		Color colorMin = ((MinMaxGradient)(ref source)).colorMin;
		colorMin.a *= multiplier;
		((MinMaxGradient)(ref source)).colorMin = colorMin;
		Color colorMax = ((MinMaxGradient)(ref source)).colorMax;
		colorMax.a *= multiplier;
		((MinMaxGradient)(ref source)).colorMax = colorMax;
		if (((MinMaxGradient)(ref source)).gradient != null)
		{
			Gradient gradient = ((MinMaxGradient)(ref source)).gradient;
			GradientAlphaKey[] alphaKeys = gradient.alphaKeys;
			for (int i = 0; i < alphaKeys.Length; i++)
			{
				alphaKeys[i].alpha *= multiplier;
			}
			gradient.SetKeys(gradient.colorKeys, alphaKeys);
			((MinMaxGradient)(ref source)).gradient = gradient;
		}
		if (((MinMaxGradient)(ref source)).gradientMin != null)
		{
			Gradient gradientMin = ((MinMaxGradient)(ref source)).gradientMin;
			GradientAlphaKey[] alphaKeys2 = gradientMin.alphaKeys;
			for (int j = 0; j < alphaKeys2.Length; j++)
			{
				alphaKeys2[j].alpha *= multiplier;
			}
			gradientMin.SetKeys(gradientMin.colorKeys, alphaKeys2);
			((MinMaxGradient)(ref source)).gradientMin = gradientMin;
		}
		if (((MinMaxGradient)(ref source)).gradientMax != null)
		{
			Gradient gradientMax = ((MinMaxGradient)(ref source)).gradientMax;
			GradientAlphaKey[] alphaKeys3 = gradientMax.alphaKeys;
			for (int k = 0; k < alphaKeys3.Length; k++)
			{
				alphaKeys3[k].alpha *= multiplier;
			}
			gradientMax.SetKeys(gradientMax.colorKeys, alphaKeys3);
			((MinMaxGradient)(ref source)).gradientMax = gradientMax;
		}
		return source;
	}

	private MinMaxGradient RecolorGradient(MinMaxGradient original, Color newColor)
	{
		//IL_0003: Unknown result type (might be due to invalid IL or missing references)
		//IL_0008: Unknown result type (might be due to invalid IL or missing references)
		//IL_0009: Unknown result type (might be due to invalid IL or missing references)
		//IL_000a: Unknown result type (might be due to invalid IL or missing references)
		//IL_000b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0025: Expected I4, but got Unknown
		//IL_002d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0032: Unknown result type (might be due to invalid IL or missing references)
		//IL_0033: Unknown result type (might be due to invalid IL or missing references)
		//IL_003c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0049: 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_0069: Unknown result type (might be due to invalid IL or missing references)
		//IL_006a: Unknown result type (might be due to invalid IL or missing references)
		//IL_006f: 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_00fa: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ff: 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_007e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0082: Unknown result type (might be due to invalid IL or missing references)
		//IL_0087: Unknown result type (might be due to invalid IL or missing references)
		//IL_008b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0098: Unknown result type (might be due to invalid IL or missing references)
		//IL_00a5: 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_00bf: Unknown result type (might be due to invalid IL or missing references)
		//IL_00cc: Unknown result type (might be due to invalid IL or missing references)
		//IL_00d7: 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_00db: Unknown result type (might be due to invalid IL or missing references)
		//IL_00e0: Unknown result type (might be due to invalid IL or missing references)
		//IL_010f: Unknown result type (might be due to invalid IL or missing references)
		//IL_011f: Unknown result type (might be due to invalid IL or missing references)
		//IL_012b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0130: 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_0157: Unknown result type (might be due to invalid IL or missing references)
		//IL_0159: Unknown result type (might be due to invalid IL or missing references)
		//IL_018e: 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_0189: Unknown result type (might be due to invalid IL or missing references)
		//IL_018a: Unknown result type (might be due to invalid IL or missing references)
		ParticleSystemGradientMode mode = ((MinMaxGradient)(ref original)).mode;
		ParticleSystemGradientMode val = mode;
		switch ((int)val)
		{
		case 0:
		{
			Color color = ((MinMaxGradient)(ref original)).color;
			float a = color.a;
			color.r = newColor.r;
			color.g = newColor.g;
			color.b = newColor.b;
			color.a = a;
			return new MinMaxGradient(color);
		}
		case 2:
		{
			Color colorMin = ((MinMaxGradient)(ref original)).colorMin;
			Color colorMax = ((MinMaxGradient)(ref original)).colorMax;
			colorMin.r = newColor.r;
			colorMin.g = newColor.g;
			colorMin.b = newColor.b;
			colorMax.r = newColor.r;
			colorMax.g = newColor.g;
			colorMax.b = newColor.b;
			return new MinMaxGradient(colorMin, colorMax);
		}
		case 1:
		{
			Gradient val5 = RecolorUnityGradient(((MinMaxGradient)(ref original)).gradient, newColor);
			return new MinMaxGradient(val5);
		}
		case 3:
		{
			Gradient val3 = RecolorUnityGradient(((MinMaxGradient)(ref original)).gradientMin, newColor);
			Gradient val4 = RecolorUnityGradient(((MinMaxGradient)(ref original)).gradientMax, newColor);
			return new MinMaxGradient(val3, val4);
		}
		case 4:
		{
			Gradient val2 = RecolorUnityGradient(((MinMaxGradient)(ref original)).gradient, newColor);
			MinMaxGradient result = default(MinMaxGradient);
			((MinMaxGradient)(ref result))..ctor(val2);
			((MinMaxGradient)(ref result)).mode = (ParticleSystemGradientMode)4;
			return result;
		}
		default:
			PoisonAndTastyMeadVFXPlugin.Log.LogWarning((object)("Unknown particle gradient mode: " + $"{((MinMaxGradient)(ref original)).mode}"));
			return original;
		}
	}

	private Gradient RecolorUnityGradient(Gradient original, Color newColor)
	{
		//IL_0014: Unknown result type (might be due to invalid IL or missing references)
		//IL_001a: Expected O, but got Unknown
		//IL_0032: Unknown result type (might be due to invalid IL or missing references)
		//IL_0038: Unknown result type (might be due to invalid IL or missing references)
		//IL_003e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0051: Unknown result type (might be due to invalid IL or missing references)
		//IL_0060: Unknown result type (might be due to invalid IL or missing references)
		//IL_0065: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b3: 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_00dd: Unknown result type (might be due to invalid IL or missing references)
		if (original == null)
		{
			return null;
		}
		Gradient val = new Gradient();
		GradientColorKey[] colorKeys = original.colorKeys;
		GradientColorKey[] array = (GradientColorKey[])(object)new GradientColorKey[colorKeys.Length];
		Color val2 = default(Color);
		for (int i = 0; i < colorKeys.Length; i++)
		{
			((Color)(ref val2))..ctor(newColor.r, newColor.g, newColor.b, 1f);
			array[i] = new GradientColorKey(val2, colorKeys[i].time);
		}
		GradientAlphaKey[] alphaKeys = original.alphaKeys;
		GradientAlphaKey[] array2 = (GradientAlphaKey[])(object)new GradientAlphaKey[alphaKeys.Length];
		for (int j = 0; j < alphaKeys.Length; j++)
		{
			array2[j] = new GradientAlphaKey(alphaKeys[j].alpha, alphaKeys[j].time);
		}
		val.SetKeys(array, array2);
		val.mode = original.mode;
		return val;
	}

	private void CacheTastyStatusEffect()
	{
		ItemManager.OnItemsRegistered -= CacheTastyStatusEffect;
		if ((Object)(object)ObjectDB.instance == (Object)null)
		{
			PoisonAndTastyMeadVFXPlugin.Log.LogError((object)"ObjectDB.instance is null.");
			return;
		}
		tastyStatusEffect = ((IEnumerable<StatusEffect>)ObjectDB.instance.m_StatusEffects).FirstOrDefault((Func<StatusEffect, bool>)((StatusEffect se) => (Object)(object)se != (Object)null && ((Object)se).name == "Potion_stamina"));
		if ((Object)(object)tastyStatusEffect == (Object)null)
		{
			tastyStatusEffect = ((IEnumerable<StatusEffect>)ObjectDB.instance.m_StatusEffects).FirstOrDefault((Func<StatusEffect, bool>)((StatusEffect se) => (Object)(object)se != (Object)null && (((Object)se).name.ToLowerInvariant().Contains("tasty") || (se.m_name != null && se.m_name.ToLowerInvariant().Contains("tasty")))));
		}
		if ((Object)(object)tastyStatusEffect == (Object)null)
		{
			PoisonAndTastyMeadVFXPlugin.Log.LogError((object)"Could not find the runtime Tasty Mead StatusEffect.");
		}
		else
		{
			InstallMinorStaminaStartSound();
		}
	}

	private void InstallMinorStaminaStartSound()
	{
		//IL_0052: 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_005e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0066: Expected O, but got Unknown
		if ((Object)(object)tastyStatusEffect == (Object)null)
		{
			PoisonAndTastyMeadVFXPlugin.Log.LogError((object)"Cannot install Tasty Mead sound because Potion_tasty is unavailable.");
			return;
		}
		GameObject prefab = PrefabManager.Instance.GetPrefab("sfx_Potion_stamina_Start");
		if ((Object)(object)prefab == (Object)null)
		{
			PoisonAndTastyMeadVFXPlugin.Log.LogError((object)"Could not find verified vanilla prefab 'sfx_Potion_stamina_Start'.");
			return;
		}
		EffectData val = new EffectData
		{
			m_prefab = prefab,
			m_enabled = true
		};
		tastyStatusEffect.m_startEffects.m_effectPrefabs = (EffectData[])(object)new EffectData[1] { val };
	}

	internal void HandleStatusEffectStart(StatusEffect statusEffect)
	{
		//IL_00fd: Unknown result type (might be due to invalid IL or missing references)
		//IL_0102: Unknown result type (might be due to invalid IL or missing references)
		//IL_0109: Unknown result type (might be due to invalid IL or missing references)
		//IL_010e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0115: Unknown result type (might be due to invalid IL or missing references)
		//IL_0116: Unknown result type (might be due to invalid IL or missing references)
		if ((Object)(object)statusEffect == (Object)null || (Object)(object)tastyStatusEffect == (Object)null || (!((Object)(object)statusEffect == (Object)(object)tastyStatusEffect) && !(((Object)statusEffect).name == ((Object)tastyStatusEffect).name) && (statusEffect.m_name == null || tastyStatusEffect.m_name == null || !(statusEffect.m_name == tastyStatusEffect.m_name))))
		{
			return;
		}
		Character value = Traverse.Create((object)statusEffect).Field("m_character").GetValue<Character>();
		if ((Object)(object)value == (Object)null)
		{
			PoisonAndTastyMeadVFXPlugin.Log.LogWarning((object)"Tasty Mead activation detected, but m_character was not available.");
		}
		else if (!((Object)(object)value != (Object)(object)Player.m_localPlayer))
		{
			if ((Object)(object)tastyFx == (Object)null)
			{
				PoisonAndTastyMeadVFXPlugin.Log.LogWarning((object)"Tasty Mead activation detected, but the custom VFX prefab is not available.");
				return;
			}
			Vector3 centerPoint = value.GetCenterPoint();
			Quaternion rotation = ((Component)value).transform.rotation;
			GameObject val = Object.Instantiate<GameObject>(tastyFx, centerPoint, rotation);
			val.transform.SetParent(((Component)value).transform, true);
		}
	}

	internal void BroadcastTastyVFX(Vector3 position, Quaternion rotation)
	{
		//IL_0051: 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_0056: Unknown result type (might be due to invalid IL or missing references)
		//IL_006a: Unknown result type (might be due to invalid IL or missing references)
		//IL_006b: Unknown result type (might be due to invalid IL or missing references)
		//IL_006c: Unknown result type (might be due to invalid IL or missing references)
		//IL_009f: 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_00a1: Unknown result type (might be due to invalid IL or missing references)
		if (SuppressNetworkBroadcast || tastyVfxRpc == null || (Object)(object)ZNet.instance == (Object)null)
		{
			return;
		}
		long uID = ZNet.GetUID();
		Player localPlayer = Player.m_localPlayer;
		ZDOID playerZdoId = (((Object)(object)localPlayer != (Object)null) ? ((Character)localPlayer).GetZDOID() : ZDOID.None);
		if (ZNet.instance.IsServer())
		{
			ForwardTastyVFXFromServer(uID, playerZdoId, position, rotation);
			return;
		}
		ZNetPeer serverPeer = ZNet.instance.GetServerPeer();
		if (serverPeer == null)
		{
			PoisonAndTastyMeadVFXPlugin.Log.LogWarning((object)"Could not send Tasty VFX activation: server peer was not available.");
			return;
		}
		ZPackage val = CreateVFXPackage(uID, playerZdoId, position, rotation);
		tastyVfxRpc.SendPackage(serverPeer.m_uid, val);
	}

	private IEnumerator OnServerReceiveTastyVFX(long sender, ZPackage package)
	{
		long origin = package.ReadLong();
		ZDOID playerZdoId = package.ReadZDOID();
		Vector3 position = package.ReadVector3();
		Quaternion rotation = package.ReadQuaternion();
		if (origin != ZNet.GetUID())
		{
			SpawnRemoteVFX(playerZdoId, position, rotation);
		}
		ForwardTastyVFXFromServer(origin, playerZdoId, position, rotation);
		yield break;
	}

	private IEnumerator OnClientReceiveTastyVFX(long sender, ZPackage package)
	{
		long origin = package.ReadLong();
		ZDOID playerZdoId = package.ReadZDOID();
		Vector3 position = package.ReadVector3();
		Quaternion rotation = package.ReadQuaternion();
		if (origin != ZNet.GetUID())
		{
			SpawnRemoteVFX(playerZdoId, position, rotation);
		}
		yield break;
	}

	private void ForwardTastyVFXFromServer(long origin, ZDOID playerZdoId, Vector3 position, Quaternion rotation)
	{
		//IL_002f: 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_0031: Unknown result type (might be due to invalid IL or missing references)
		if (tastyVfxRpc != null && !((Object)(object)ZNet.instance == (Object)null) && ZNet.instance.IsServer())
		{
			ZPackage val = CreateVFXPackage(origin, playerZdoId, position, rotation);
			tastyVfxRpc.SendPackage(0L, val);
		}
	}

	private ZPackage CreateVFXPackage(long origin, ZDOID playerZdoId, Vector3 position, Quaternion rotation)
	{
		//IL_0001: Unknown result type (might be due to invalid IL or missing references)
		//IL_0007: Expected O, but got Unknown
		//IL_0010: Unknown result type (might be due to invalid IL or missing references)
		//IL_0018: 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)
		ZPackage val = new ZPackage();
		val.Write(origin);
		val.Write(playerZdoId);
		val.Write(position);
		val.Write(rotation);
		return val;
	}

	private void SpawnRemoteVFX(ZDOID playerZdoId, Vector3 position, Quaternion rotation)
	{
		//IL_0033: Unknown result type (might be due to invalid IL or missing references)
		//IL_0034: Unknown result type (might be due to invalid IL or missing references)
		//IL_0057: Unknown result type (might be due to invalid IL or missing references)
		//IL_0067: Unknown result type (might be due to invalid IL or missing references)
		if ((Object)(object)tastyFx == (Object)null)
		{
			PoisonAndTastyMeadVFXPlugin.Log.LogWarning((object)"Could not spawn remote Tasty VFX because the custom prefab is not available.");
			return;
		}
		SuppressNetworkBroadcast = true;
		GameObject val = null;
		try
		{
			val = Object.Instantiate<GameObject>(tastyFx, position, rotation);
		}
		finally
		{
			SuppressNetworkBroadcast = false;
		}
		if (!((Object)(object)val == (Object)null) && !TryAttachRemoteVFX(val, playerZdoId))
		{
			((MonoBehaviour)this).StartCoroutine(AttachRemoteVFXWhenPlayerReady(val, playerZdoId));
		}
	}

	private bool TryAttachRemoteVFX(GameObject remoteFx, ZDOID playerZdoId)
	{
		//IL_000a: Unknown result type (might be due to invalid IL or missing references)
		//IL_000b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0022: Unknown result type (might be due to invalid IL or missing references)
		if ((Object)(object)remoteFx == (Object)null || playerZdoId == ZDOID.None)
		{
			return false;
		}
		Player val = ResolvePlayer(playerZdoId);
		if ((Object)(object)val == (Object)null)
		{
			return false;
		}
		remoteFx.transform.SetParent(((Component)val).transform, true);
		return true;
	}

	private IEnumerator AttachRemoteVFXWhenPlayerReady(GameObject remoteFx, ZDOID playerZdoId)
	{
		//IL_0015: 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)
		float timeoutAt = Time.realtimeSinceStartup + 1f;
		while ((Object)(object)remoteFx != (Object)null && Time.realtimeSinceStartup < timeoutAt)
		{
			yield return null;
			if (TryAttachRemoteVFX(remoteFx, playerZdoId))
			{
				yield break;
			}
		}
		if ((Object)(object)remoteFx != (Object)null)
		{
			PoisonAndTastyMeadVFXPlugin.Log.LogWarning((object)("Remote Tasty VFX could not resolve player " + $"{playerZdoId} within " + $"{1f:0.0}s; " + "leaving the VFX at its original world position."));
		}
	}

	private Player ResolvePlayer(ZDOID playerZdoId)
	{
		//IL_0001: Unknown result type (might be due to invalid IL or missing references)
		//IL_0002: Unknown result type (might be due to invalid IL or missing references)
		//IL_002a: Unknown result type (might be due to invalid IL or missing references)
		if (playerZdoId == ZDOID.None || (Object)(object)ZNetScene.instance == (Object)null)
		{
			return null;
		}
		GameObject val = ZNetScene.instance.FindInstance(playerZdoId);
		if ((Object)(object)val == (Object)null)
		{
			return null;
		}
		return val.GetComponent<Player>();
	}
}
[HarmonyPatch(typeof(StatusEffect), "TriggerStartEffects")]
internal static class MeadStatusEffectTriggerPatch
{
	[HarmonyPostfix]
	private static void Postfix(StatusEffect __instance)
	{
		PoisonMeadVFXPlugin instance = PoisonMeadVFXPlugin.Instance;
		if ((Object)(object)instance != (Object)null)
		{
			instance.HandleStatusEffectStart(__instance);
		}
		TastyMeadVFXPlugin instance2 = TastyMeadVFXPlugin.Instance;
		if ((Object)(object)instance2 != (Object)null)
		{
			instance2.HandleStatusEffectStart(__instance);
		}
	}
}
internal class TastyTrailBirthClassifier : MonoBehaviour
{
	private const float DirectionThreshold = 0.02f;

	private ParticleSystem particleSystem;

	private Particle[] particles;

	private readonly Dictionary<uint, float> firstLocalY = new Dictionary<uint, float>();

	private readonly Dictionary<uint, Color32> assignedColors = new Dictionary<uint, Color32>();

	private readonly HashSet<uint> aliveSeeds = new HashSet<uint>();

	private int totalYellowAssigned;

	private int totalRedAssigned;

	private void Awake()
	{
		//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)
		particleSystem = ((Component)this).GetComponent<ParticleSystem>();
		if ((Object)(object)particleSystem == (Object)null)
		{
			((Behaviour)this).enabled = false;
			return;
		}
		MainModule main = particleSystem.main;
		particles = (Particle[])(object)new Particle[Mathf.Max(64, ((MainModule)(ref main)).maxParticles)];
	}

	private void LateUpdate()
	{
		//IL_0046: Unknown result type (might be due to invalid IL or missing references)
		//IL_004b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0058: Unknown result type (might be due to invalid IL or missing references)
		//IL_008a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0099: 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_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_00e9: Unknown result type (might be due to invalid IL or missing references)
		//IL_00eb: Unknown result type (might be due to invalid IL or missing references)
		//IL_0118: Unknown result type (might be due to invalid IL or missing references)
		//IL_011d: Unknown result type (might be due to invalid IL or missing references)
		//IL_012f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0131: Unknown result type (might be due to invalid IL or missing references)
		//IL_0168: Unknown result type (might be due to invalid IL or missing references)
		//IL_016d: 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_014a: 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)
		//IL_0154: Unknown result type (might be due to invalid IL or missing references)
		//IL_018b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0195: 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_01a6: Unknown result type (might be due to invalid IL or missing references)
		if ((Object)(object)particleSystem == (Object)null)
		{
			return;
		}
		int num = particleSystem.GetParticles(particles);
		aliveSeeds.Clear();
		bool flag = false;
		for (int i = 0; i < num; i++)
		{
			Particle val = particles[i];
			uint randomSeed = ((Particle)(ref val)).randomSeed;
			float y = ((Particle)(ref val)).position.y;
			aliveSeeds.Add(randomSeed);
			if (assignedColors.TryGetValue(randomSeed, out var value))
			{
				((Particle)(ref val)).startColor = value;
				particles[i] = val;
				flag = true;
				continue;
			}
			if (!firstLocalY.TryGetValue(randomSeed, out var value2))
			{
				firstLocalY[randomSeed] = y;
				((Particle)(ref val)).startColor = Color32.op_Implicit(TastyMeadVFXPlugin.StaminaYellow);
				particles[i] = val;
				flag = true;
				continue;
			}
			float num2 = y - value2;
			if (Mathf.Abs(num2) <= 0.02f)
			{
				((Particle)(ref val)).startColor = Color32.op_Implicit(TastyMeadVFXPlugin.StaminaYellow);
				particles[i] = val;
				flag = true;
				continue;
			}
			if (num2 < 0f)
			{
				value = Color32.op_Implicit(TastyMeadVFXPlugin.HealthPenaltyRed);
				totalRedAssigned++;
			}
			else
			{
				value = Color32.op_Implicit(TastyMeadVFXPlugin.StaminaYellow);
				totalYellowAssigned++;
			}
			assignedColors[randomSeed] = value;
			((Particle)(ref val)).startColor = value;
			particles[i] = val;
			flag = true;
		}
		if (flag)
		{
			particleSystem.SetParticles(particles, num);
		}
		RemoveDeadEntries();
	}

	private void RemoveDeadEntries()
	{
		List<uint> list = null;
		foreach (uint key in firstLocalY.Keys)
		{
			if (!aliveSeeds.Contains(key))
			{
				if (list == null)
				{
					list = new List<uint>();
				}
				list.Add(key);
			}
		}
		if (list == null)
		{
			return;
		}
		foreach (uint item in list)
		{
			firstLocalY.Remove(item);
			assignedColors.Remove(item);
		}
	}
}
internal class TastyVFXNetworkTrigger : MonoBehaviour
{
	private void Awake()
	{
		//IL_0028: Unknown result type (might be due to invalid IL or missing references)
		//IL_0033: Unknown result type (might be due to invalid IL or missing references)
		if (!TastyMeadVFXPlugin.SuppressNetworkBroadcast)
		{
			TastyMeadVFXPlugin instance = TastyMeadVFXPlugin.Instance;
			if (!((Object)(object)instance == (Object)null))
			{
				instance.BroadcastTastyVFX(((Component)this).transform.position, ((Component)this).transform.rotation);
			}
		}
	}
}