Decompiled source of Favor of the Gods v1.1.0

Gods.dll

Decompiled a week ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.Globalization;
using System.IO;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Text;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using HarmonyLib;
using Jotunn.Configs;
using Jotunn.Entities;
using Jotunn.Managers;
using Jotunn.Utils;
using TMPro;
using UnityEngine;
using UnityEngine.Audio;
using UnityEngine.EventSystems;
using UnityEngine.Events;
using UnityEngine.Networking;
using UnityEngine.Rendering;
using UnityEngine.UI;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: AssemblyVersion("0.0.0.0")]
namespace Gods;

internal static class Blessings
{
	private static readonly int[,] BlessHash = new int[5, 4];

	private static readonly SE_Stats[,] BlessSE = new SE_Stats[5, 4];

	private static readonly int[] WrathHash = new int[5];

	private static readonly SE_Stats[] WrathSE = (SE_Stats[])(object)new SE_Stats[5];

	private static float _timer;

	private static int _forsakenHash;

	private static readonly Random Rnd = new Random();

	private static FieldInfo _skillsPlayer;

	private static FieldInfo _pickPicked;

	private static FieldInfo _pickView;

	private static float _baseExplore = -1f;

	private static float _setExplore = -1f;

	public static void CreateStatusEffects()
	{
		//IL_00ac: Unknown result type (might be due to invalid IL or missing references)
		//IL_0498: 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_053a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0544: Expected O, but got Unknown
		//IL_01ac: Unknown result type (might be due to invalid IL or missing references)
		//IL_01b9: Unknown result type (might be due to invalid IL or missing references)
		//IL_01c1: Unknown result type (might be due to invalid IL or missing references)
		//IL_01d0: 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_040c: Expected O, but got Unknown
		string[] roman = GodDefs.Roman;
		CreateForsaken();
		for (int i = 0; i < 5; i++)
		{
			for (int j = 0; j < 4; j++)
			{
				SE_Stats val = ScriptableObject.CreateInstance<SE_Stats>();
				((Object)val).name = "Gods_Bless_" + GodDefs.Key(i) + (j + 1);
				((StatusEffect)val).m_name = Loc.T("se_bless", GodDefs.Gen(i), roman[j]);
				((StatusEffect)val).m_ttl = 0f;
				((StatusEffect)val).m_icon = ShrineModel.Symbols[i];
				string text = "";
				switch (i)
				{
				case 0:
					val.m_raiseSkill = (SkillType)999;
					val.m_raiseSkillModifier = GodDefs.OdinSkill[j];
					if (GodDefs.OdinExplore[j] > 0f)
					{
						text = text + Loc.T("b_odin_explore", GodDefs.Pct(GodDefs.OdinExplore[j])) + "\n";
					}
					if (GodDefs.OdinDeathLoss[j] > 0f)
					{
						text = text + Loc.T("b_odin_death", GodDefs.Pct(GodDefs.OdinDeathLoss[j])) + "\n";
					}
					break;
				case 1:
					val.m_addMaxCarryWeight = GodDefs.ThorCarry[j];
					if (GodDefs.ThorLightning[j] > 0f)
					{
						text = text + Loc.T("b_thor_lightning", GodDefs.Pct(GodDefs.ThorLightning[j]), GodDefs.Pct(GodDefs.ThorLightningDamage[j])) + "\n";
					}
					if (j >= 2)
					{
						DamageModPair item = new DamageModPair
						{
							m_type = (DamageType)128,
							m_modifier = (DamageModifier)1
						};
						val.m_mods = new List<DamageModPair> { item };
					}
					break;
				case 2:
					val.m_fallDamageModifier = 0f - GodDefs.FreyaFall[j];
					if (j == 3)
					{
						val.m_maxMaxFallSpeed = 5f;
					}
					text = text + Loc.T("b_freya_food", GodDefs.Pct(GodDefs.FreyaFood[j])) + "\n";
					if (GodDefs.FreyaHarvest[j] > 0f)
					{
						text = text + Loc.T("b_freya_harvest", GodDefs.Pct(GodDefs.FreyaHarvest[j])) + "\n";
					}
					if (j == 3)
					{
						text = text + Loc.T("b_freya_glide") + "\n";
					}
					break;
				case 3:
					val.m_swimStaminaUseModifier = 0f - GodDefs.NjordSwimStamina[j];
					val.m_swimSpeedModifier = GodDefs.NjordSwimSpeed[j];
					text = text + ((GodDefs.NjordWind[j] >= 1f) ? Loc.T("b_njord_wind_full") : Loc.T("b_njord_wind", GodDefs.Pct(GodDefs.NjordWind[j]))) + "\n";
					break;
				default:
					val.m_speedModifier = GodDefs.LokiSpeed[j];
					val.m_skillLevel = (SkillType)101;
					val.m_skillLevelModifier = GodDefs.LokiSneak[j];
					val.m_dodgeStaminaUseModifier = 0f - GodDefs.LokiDodge[j];
					if (GodDefs.LokiEvade[j] > 0f)
					{
						text = text + Loc.T("b_loki_evade", GodDefs.Pct(GodDefs.LokiEvade[j])) + "\n";
					}
					text = text + Loc.T("b_loki_pranks") + "\n";
					break;
				}
				((StatusEffect)val).m_tooltip = Loc.T("se_bless_tip", GodDefs.Name(i)) + ((text.Length > 0) ? ("\n" + text.TrimEnd('\n')) : "");
				BlessSE[i, j] = val;
				BlessHash[i, j] = StringExtensionMethods.GetStableHashCode(((Object)val).name);
				ItemManager.Instance.AddStatusEffect(new CustomStatusEffect((StatusEffect)(object)val, false));
			}
			SE_Stats val2 = ScriptableObject.CreateInstance<SE_Stats>();
			((Object)val2).name = "Gods_Wrath_" + GodDefs.Key(i);
			((StatusEffect)val2).m_name = Loc.T("se_wrath", GodDefs.Gen(i));
			((StatusEffect)val2).m_ttl = 0f;
			((StatusEffect)val2).m_icon = ShrineModel.WrathIcons[i];
			switch (i)
			{
			case 0:
				val2.m_raiseSkill = (SkillType)999;
				val2.m_raiseSkillModifier = -0.5f;
				break;
			case 1:
				val2.m_addMaxCarryWeight = -50f;
				break;
			case 2:
				val2.m_healthRegenMultiplier = 0.7f;
				break;
			case 3:
				val2.m_swimStaminaUseModifier = 0.5f;
				break;
			default:
				val2.m_staminaRegenMultiplier = 0.8f;
				break;
			}
			((StatusEffect)val2).m_tooltip = Loc.T("se_wrath_tip", GodDefs.Name(i)) + "\n" + GodDefs.WrathText(i);
			WrathSE[i] = val2;
			WrathHash[i] = StringExtensionMethods.GetStableHashCode(((Object)val2).name);
			ItemManager.Instance.AddStatusEffect(new CustomStatusEffect((StatusEffect)(object)val2, false));
		}
	}

	private static void CreateForsaken()
	{
		//IL_0074: Unknown result type (might be due to invalid IL or missing references)
		//IL_007e: Expected O, but got Unknown
		SE_Stats val = ScriptableObject.CreateInstance<SE_Stats>();
		((Object)val).name = "Gods_Forsaken";
		((StatusEffect)val).m_name = Loc.T("se_forsaken");
		((StatusEffect)val).m_ttl = 0f;
		((StatusEffect)val).m_icon = ShrineModel.ForsakenIcon;
		val.m_healthRegenMultiplier = 0.8f;
		val.m_staminaRegenMultiplier = 0.85f;
		((StatusEffect)val).m_tooltip = Loc.T("se_forsaken_tip");
		_forsakenHash = StringExtensionMethods.GetStableHashCode(((Object)val).name);
		ItemManager.Instance.AddStatusEffect(new CustomStatusEffect((StatusEffect)(object)val, false));
	}

	public static void SetIcons()
	{
		for (int i = 0; i < 5; i++)
		{
			for (int j = 0; j < 4; j++)
			{
				if ((Object)(object)BlessSE[i, j] != (Object)null && (Object)(object)((StatusEffect)BlessSE[i, j]).m_icon == (Object)null)
				{
					((StatusEffect)BlessSE[i, j]).m_icon = ShrineModel.Symbols[i];
				}
			}
			if ((Object)(object)WrathSE[i] != (Object)null && (Object)(object)((StatusEffect)WrathSE[i]).m_icon == (Object)null)
			{
				((StatusEffect)WrathSE[i]).m_icon = ShrineModel.WrathIcons[i];
			}
		}
	}

	public static void Update()
	{
		_timer -= Time.deltaTime;
		if (_timer > 0f)
		{
			return;
		}
		_timer = 0.5f;
		Player localPlayer = Player.m_localPlayer;
		if ((Object)(object)localPlayer == (Object)null || ((Character)localPlayer).IsDead())
		{
			return;
		}
		try
		{
			SEMan sEMan = ((Character)localPlayer).GetSEMan();
			for (int i = 0; i < 5; i++)
			{
				int num = GodsClient.ActiveTier(i);
				for (int j = 0; j < 4; j++)
				{
					int num2 = BlessHash[i, j];
					if (num2 != 0)
					{
						bool flag = num == j + 1;
						bool flag2 = sEMan.HaveStatusEffect(num2);
						if (flag && !flag2)
						{
							sEMan.AddStatusEffect(num2, false, 0, 0f, (short)(-1));
						}
						else if (!flag && flag2)
						{
							sEMan.RemoveStatusEffect(num2, true);
						}
					}
				}
				if (i == 0 && _forsakenHash != 0)
				{
					bool forsaken = GodsClient.Forsaken;
					bool flag3 = sEMan.HaveStatusEffect(_forsakenHash);
					if (forsaken && !flag3)
					{
						sEMan.AddStatusEffect(_forsakenHash, false, 0, 0f, (short)(-1));
					}
					else if (!forsaken && flag3)
					{
						sEMan.RemoveStatusEffect(_forsakenHash, true);
					}
				}
				int num3 = WrathHash[i];
				if (num3 != 0)
				{
					bool flag4 = GodsClient.HasData && GodsClient.Angry[i];
					bool flag5 = sEMan.HaveStatusEffect(num3);
					if (flag4 && !flag5)
					{
						sEMan.AddStatusEffect(num3, false, 0, 0f, (short)(-1));
					}
					else if (!flag4 && flag5)
					{
						sEMan.RemoveStatusEffect(num3, true);
					}
				}
			}
		}
		catch (Exception ex)
		{
			Plugin.Log.LogWarning((object)("Blessings update: " + ex.Message));
			_timer = 10f;
		}
	}

	public static void Apply(Harmony h)
	{
		_skillsPlayer = AccessTools.Field(typeof(Skills), "m_player");
		_pickPicked = AccessTools.Field(typeof(Pickable), "m_picked");
		_pickView = AccessTools.Field(typeof(Pickable), "m_nview");
		TryPatch(h, typeof(Skills), "LowerAllSkills", "LowerSkillsPrefix", null, "Odin: smaller skill loss");
		TryPatch(h, typeof(Minimap), "UpdateExplore", "ExplorePrefix", null, "Odin: map exploration");
		TryPatch(h, typeof(Character), "Damage", "DamagePrefix", null, "Thor: lightning on hit");
		TryPatch(h, typeof(Character), "RPC_Damage", "RpcDamagePrefix", null, "Loki: evading blows");
		TryPatch(h, typeof(Pickable), "Interact", "PickPrefix", "PickPostfix", "Freya: double harvest");
		TryPatch(h, typeof(Player), "UpdateFood", "FoodPrefix", null, "Freya: longer food");
		TryPatch(h, typeof(Ship), "GetWindAngleFactor", null, "WindPostfix", "Njord: favorable wind");
	}

	private static void TryPatch(Harmony h, Type type, string method, string prefix, string postfix, string what)
	{
		//IL_0044: 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)
		try
		{
			MethodInfo methodInfo = AccessTools.Method(type, method, (Type[])null, (Type[])null);
			if (methodInfo == null)
			{
				Plugin.Log.LogWarning((object)("Game method for " + what + " not found — effect disabled."));
			}
			else
			{
				h.Patch((MethodBase)methodInfo, (prefix == null) ? ((HarmonyMethod)null) : new HarmonyMethod(typeof(Blessings), prefix, (Type[])null), (postfix == null) ? ((HarmonyMethod)null) : new HarmonyMethod(typeof(Blessings), postfix, (Type[])null), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
			}
		}
		catch (Exception ex)
		{
			Plugin.Log.LogWarning((object)("Patch for " + what + " failed: " + ex.Message));
		}
	}

	private static bool IsLocal(Character c)
	{
		if ((Object)(object)c != (Object)null)
		{
			return (Object)(object)c == (Object)(object)Player.m_localPlayer;
		}
		return false;
	}

	private static void LowerSkillsPrefix(Skills __instance, ref float factor)
	{
		try
		{
			if (!(_skillsPlayer == null) && !((Object)/*isinst with value type is only supported in some contexts*/ != (Object)(object)Player.m_localPlayer))
			{
				int num = GodsClient.ActiveTier(0);
				if (num > 0)
				{
					factor *= 1f - GodDefs.OdinDeathLoss[num - 1];
				}
			}
		}
		catch
		{
		}
	}

	private static void ExplorePrefix(Minimap __instance)
	{
		float exploreRadius = __instance.m_exploreRadius;
		if (_baseExplore < 0f || Mathf.Abs(exploreRadius - _setExplore) > 0.01f)
		{
			_baseExplore = exploreRadius;
		}
		int num = GodsClient.ActiveTier(0);
		_setExplore = (__instance.m_exploreRadius = _baseExplore * (1f + ((num > 0) ? GodDefs.OdinExplore[num - 1] : 0f)));
	}

	private static void DamagePrefix(Character __instance, HitData hit)
	{
		//IL_00c7: Unknown result type (might be due to invalid IL or missing references)
		//IL_00cc: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ce: Unknown result type (might be due to invalid IL or missing references)
		//IL_00cf: Unknown result type (might be due to invalid IL or missing references)
		//IL_00d9: 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_00e3: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ed: Unknown result type (might be due to invalid IL or missing references)
		//IL_00f2: Unknown result type (might be due to invalid IL or missing references)
		//IL_00f7: Unknown result type (might be due to invalid IL or missing references)
		try
		{
			if (hit == null || (Object)(object)__instance == (Object)null || hit.m_ranged)
			{
				return;
			}
			Player localPlayer = Player.m_localPlayer;
			if ((Object)(object)localPlayer == (Object)null || (Object)(object)__instance == (Object)(object)localPlayer || __instance.IsPlayer() || __instance.IsTamed())
			{
				return;
			}
			int num = GodsClient.ActiveTier(1);
			if (num != 0 && !(GodDefs.ThorLightning[num - 1] <= 0f) && !((Object)(object)hit.GetAttacker() != (Object)(object)localPlayer))
			{
				float totalDamage = hit.GetTotalDamage();
				if (!(totalDamage <= 0f) && !(Rnd.NextDouble() >= (double)GodDefs.ThorLightning[num - 1]))
				{
					ref DamageTypes damage = ref hit.m_damage;
					damage.m_lightning += Mathf.Max(5f, totalDamage * GodDefs.ThorLightningDamage[num - 1]);
					Vector3 centerPoint = __instance.GetCenterPoint();
					Fx.Broadcast(2, centerPoint + Vector3.up * 14f + Random.insideUnitSphere * 2f, centerPoint, 1);
				}
			}
		}
		catch
		{
		}
	}

	private static bool RpcDamagePrefix(Character __instance, HitData hit)
	{
		//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)
		try
		{
			if (!IsLocal(__instance) || hit == null)
			{
				return true;
			}
			int num = GodsClient.ActiveTier(4);
			if (num == 0 || GodDefs.LokiEvade[num - 1] <= 0f)
			{
				return true;
			}
			if ((Object)(object)hit.GetAttacker() == (Object)null || hit.GetTotalDamage() <= 0f)
			{
				return true;
			}
			if (Rnd.NextDouble() >= (double)GodDefs.LokiEvade[num - 1])
			{
				return true;
			}
			__instance.Message((MessageType)1, Loc.T("loki_evade"), 0, (Sprite)null, false);
			Fx.Broadcast(3, ((Component)__instance).transform.position + Vector3.up, 4);
			return false;
		}
		catch
		{
			return true;
		}
	}

	private static void PickPrefix(Pickable __instance, Humanoid character, ref bool __state)
	{
		__state = false;
		try
		{
			if (IsLocal((Character)(object)character) && GodsClient.ActiveTier(2) != 0 && (!(_pickPicked != null) || !(bool)_pickPicked.GetValue(__instance)))
			{
				ZNetView val = (ZNetView)((_pickView != null) ? /*isinst with value type is only supported in some contexts*/: null);
				if (!((Object)(object)val == (Object)null) && val.IsValid())
				{
					__state = true;
				}
			}
		}
		catch
		{
		}
	}

	private static void PickPostfix(Pickable __instance, Humanoid character, bool __state)
	{
		//IL_00a0: 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_00af: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b4: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b9: Unknown result type (might be due to invalid IL or missing references)
		//IL_00c3: 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_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_00d4: Unknown result type (might be due to invalid IL or missing references)
		//IL_010c: 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)
		if (!__state)
		{
			return;
		}
		try
		{
			int num = GodsClient.ActiveTier(2);
			if (num != 0 && !(GodDefs.FreyaHarvest[num - 1] <= 0f) && !(Rnd.NextDouble() >= (double)GodDefs.FreyaHarvest[num - 1]))
			{
				GameObject itemPrefab = __instance.m_itemPrefab;
				ItemDrop val = (((Object)(object)itemPrefab != (Object)null) ? itemPrefab.GetComponent<ItemDrop>() : null);
				if (!((Object)(object)val == (Object)null) && IsPlant(((Object)itemPrefab).name, val.m_itemData.m_shared))
				{
					ItemData val2 = val.m_itemData.Clone();
					val2.m_dropPrefab = itemPrefab;
					int num2 = Mathf.Max(1, __instance.m_amount);
					Vector3 val3 = ((Component)__instance).transform.position + Vector3.up * 0.6f + Random.insideUnitSphere * 0.2f;
					ItemDrop.DropItem(val2, num2, val3, Quaternion.identity);
					((Character)character).Message((MessageType)1, Loc.T("freya_harvest", val2.m_shared.m_name), 0, (Sprite)null, false);
					Fx.Burst(val3, GodDefs.Glow(2), 12);
				}
			}
		}
		catch (Exception ex)
		{
			Plugin.Log.LogWarning((object)("Freya harvest: " + ex.Message));
		}
	}

	private static bool IsPlant(string prefab, SharedData s)
	{
		//IL_000e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0014: Invalid comparison between Unknown and I4
		if (s.m_food > 0f || (int)s.m_itemType == 2)
		{
			return true;
		}
		string text = prefab.ToLowerInvariant();
		if (!text.Contains("seed"))
		{
			switch (text)
			{
			default:
				if (!text.Contains("mushroom") && !text.Contains("berr"))
				{
					switch (text)
					{
					default:
						return text == "pukeberries";
					case "fiddleheadfern":
					case "smokepuff":
					case "vineberry":
						break;
					}
				}
				break;
			case "flax":
			case "barley":
			case "thistle":
			case "dandelion":
				break;
			}
		}
		return true;
	}

	private static void FoodPrefix(Player __instance, ref float dt)
	{
		if (!((Object)(object)__instance != (Object)(object)Player.m_localPlayer))
		{
			int num = GodsClient.ActiveTier(2);
			if (num > 0 && GodDefs.FreyaFood[num - 1] > 0f)
			{
				dt /= 1f + GodDefs.FreyaFood[num - 1];
			}
		}
	}

	private static void WindPostfix(Ship __instance, ref float __result)
	{
		Player localPlayer = Player.m_localPlayer;
		if ((Object)(object)localPlayer == (Object)null)
		{
			return;
		}
		try
		{
			if ((Object)(object)localPlayer.GetControlledShip() != (Object)(object)__instance)
			{
				return;
			}
		}
		catch
		{
			return;
		}
		if (Powers.CalmSeas(localPlayer))
		{
			__result = 1f;
			return;
		}
		if (Wrath.Headwind || (GodsClient.HasData && GodsClient.Angry[3]))
		{
			__result = Mathf.Min(__result, 0.3f);
			return;
		}
		int num = GodsClient.ActiveTier(3);
		if (num > 0)
		{
			__result = Mathf.Max(__result, GodDefs.NjordWind[num - 1]);
		}
	}
}
public class BlotState
{
	public bool Active;

	public int God = -1;

	public long EndsAt;

	public float Meter;

	public float Goal = 3000f;

	public float Multiplier = 2f;

	public int BlessingGod = -1;

	public int BlessingTier = 2;

	public long BlessingUntil;

	public int Contributors;

	public bool Completed => Meter >= Goal - 0.01f;

	public void Write(ZPackage pkg)
	{
		pkg.Write(Active);
		pkg.Write(God);
		pkg.Write(EndsAt);
		pkg.Write(Meter);
		pkg.Write(Goal);
		pkg.Write(Multiplier);
		pkg.Write(BlessingGod);
		pkg.Write(BlessingTier);
		pkg.Write(BlessingUntil);
		pkg.Write(Contributors);
	}

	public static BlotState Read(ZPackage pkg)
	{
		BlotState blotState = new BlotState();
		blotState.Active = pkg.ReadBool();
		blotState.God = pkg.ReadInt();
		blotState.EndsAt = pkg.ReadLong();
		blotState.Meter = pkg.ReadSingle();
		blotState.Goal = pkg.ReadSingle();
		blotState.Multiplier = pkg.ReadSingle();
		blotState.BlessingGod = pkg.ReadInt();
		blotState.BlessingTier = pkg.ReadInt();
		blotState.BlessingUntil = pkg.ReadLong();
		blotState.Contributors = pkg.ReadInt();
		return blotState;
	}
}
internal static class Blot
{
	public static BlotState State = new BlotState();

	private static string _path;

	private static int _lastWeek = -1;

	private static int _milestone;

	private static readonly HashSet<long> Contributors = new HashSet<long>();

	private static long _serverNow;

	private static float _receivedAt;

	public static long ServerNow
	{
		get
		{
			if (_serverNow == 0 || ((Object)(object)ZNet.instance != (Object)null && ZNet.instance.IsServer()))
			{
				return DateTime.UtcNow.Ticks;
			}
			return _serverNow + (long)((Time.realtimeSinceStartup - _receivedAt) * 10000000f);
		}
	}

	public static float SecondsLeft
	{
		get
		{
			if (!State.Active)
			{
				return 0f;
			}
			return Mathf.Max(0f, (float)(State.EndsAt - ServerNow) / 10000000f);
		}
	}

	public static float RewardSecondsLeft => Mathf.Max(0f, (float)(State.BlessingUntil - ServerNow) / 10000000f);

	private static int WeekKey(DateTime local)
	{
		return (int)(local.Date.AddDays(-((int)(local.DayOfWeek + 6) % 7)).Ticks / 864000000000L);
	}

	public static void Load(string dir, string world)
	{
		//IL_004d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0053: Expected O, but got Unknown
		_path = Path.Combine(dir, world + ".blot");
		State = new BlotState();
		Contributors.Clear();
		_lastWeek = -1;
		_milestone = 0;
		if (!File.Exists(_path))
		{
			return;
		}
		try
		{
			ZPackage val = new ZPackage(File.ReadAllBytes(_path));
			val.ReadInt();
			_lastWeek = val.ReadInt();
			_milestone = val.ReadInt();
			State = BlotState.Read(val);
			int num = val.ReadInt();
			for (int i = 0; i < num; i++)
			{
				Contributors.Add(val.ReadLong());
			}
		}
		catch (Exception ex)
		{
			Plugin.Log.LogWarning((object)("Could not read Blót state: " + ex.Message));
		}
	}

	public static void Save()
	{
		//IL_000d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0013: Expected O, but got Unknown
		if (string.IsNullOrEmpty(_path))
		{
			return;
		}
		try
		{
			ZPackage val = new ZPackage();
			val.Write(1);
			val.Write(_lastWeek);
			val.Write(_milestone);
			State.Write(val);
			val.Write(Contributors.Count);
			foreach (long contributor in Contributors)
			{
				val.Write(contributor);
			}
			File.WriteAllBytes(_path, val.GetArray());
		}
		catch (Exception ex)
		{
			Plugin.Log.LogWarning((object)("Could not save Blót state: " + ex.Message));
		}
	}

	public static void MinuteTick()
	{
		long ticks = DateTime.UtcNow.Ticks;
		if (State.Active && ticks >= State.EndsAt)
		{
			End();
		}
		if (!Plugin.BlotEnabled.Value || State.Active)
		{
			return;
		}
		DateTime now = DateTime.Now;
		int num = WeekKey(now);
		if (num != _lastWeek && now.DayOfWeek == Plugin.BlotDay.Value)
		{
			int num2 = Plugin.BlotHour.Value * 60;
			int num3 = now.Hour * 60 + now.Minute;
			if (num3 >= num2 && num3 < num2 + Plugin.BlotDurationMinutes.Value)
			{
				Start(-1, num2 + Plugin.BlotDurationMinutes.Value - num3);
			}
		}
	}

	public static int GodOfWeek()
	{
		string text = (Plugin.BlotGod.Value ?? "").Trim().ToLowerInvariant();
		for (int i = 0; i < 5; i++)
		{
			if (GodDefs.Id(i) == text || (text == "freyja" && i == 2))
			{
				return i;
			}
		}
		return WeekKey(DateTime.Now) / 7 % 5;
	}

	public static void Start(int god, int minutes)
	{
		if (god < 0)
		{
			god = GodOfWeek();
		}
		State.Active = true;
		State.God = god;
		State.EndsAt = DateTime.UtcNow.Ticks + (long)Math.Max(1, minutes) * 600000000L;
		State.Meter = 0f;
		State.Goal = Plugin.BlotGoal.Value;
		State.Multiplier = Plugin.BlotFavorMultiplier.Value;
		State.BlessingTier = Plugin.BlotBlessingTier.Value;
		State.Contributors = 0;
		Contributors.Clear();
		_milestone = 0;
		_lastWeek = WeekKey(DateTime.Now);
		Save();
		GodsServer.AuditPublic("BLOT", 0L, "Blót of " + GodDefs.Key(god) + " started for " + minutes + " min, goal " + State.Goal);
		Announce("blot_start", "@godg_" + GodDefs.Id(god), OfferFormat.Favor(State.Multiplier), OfferFormat.Favor(State.Goal), GodsServer.SpanMinutes(minutes));
		Broadcast(horn: true);
	}

	public static void End()
	{
		if (State.Active)
		{
			State.Active = false;
			Save();
			GodsServer.AuditPublic("BLOT", 0L, "Blót of " + GodDefs.Key(State.God) + " ended: " + F(State.Meter) + "/" + F(State.Goal) + ", " + State.Contributors + " players");
			if (!State.Completed)
			{
				Announce("blot_failed", "@godg_" + GodDefs.Id(State.God), OfferFormat.Favor(State.Meter), OfferFormat.Favor(State.Goal));
			}
			else
			{
				Announce("blot_end", "@godg_" + GodDefs.Id(State.God), State.Contributors);
			}
			Broadcast(horn: false);
		}
	}

	public static void AddOffering(long pid, string name, float gain)
	{
		if (State.Active && !(gain <= 0f))
		{
			bool completed = State.Completed;
			State.Meter = Mathf.Min(State.Goal, State.Meter + gain);
			if (Contributors.Add(pid))
			{
				State.Contributors = Contributors.Count;
			}
			int num = Mathf.FloorToInt(State.Meter / Mathf.Max(1f, State.Goal) * 100f);
			int num2 = ((num >= 100) ? 4 : (num / 25));
			if (!completed && State.Completed)
			{
				State.BlessingGod = State.God;
				State.BlessingUntil = DateTime.UtcNow.Ticks + (long)(Plugin.BlotBlessingHours.Value * 3.6E+10f);
				_milestone = 4;
				GodsServer.AuditPublic("BLOT", pid, "Blót goal reached (last offering by " + name + ")");
				Announce("blot_done", "@godg_" + GodDefs.Id(State.God), "@tier_" + State.BlessingTier, OfferFormat.Favor(Plugin.BlotBlessingHours.Value));
			}
			else if (num2 > _milestone && num2 < 4)
			{
				_milestone = num2;
				Announce("blot_progress", "@godg_" + GodDefs.Id(State.God), num2 * 25, OfferFormat.Favor(State.Meter), OfferFormat.Favor(State.Goal));
			}
			Save();
			Broadcast(horn: false);
		}
	}

	private static string F(float v)
	{
		return OfferFormat.Favor(v);
	}

	public static void Broadcast(bool horn)
	{
		//IL_0008: Unknown result type (might be due to invalid IL or missing references)
		//IL_000e: Expected O, but got Unknown
		if (ZRoutedRpc.instance != null)
		{
			ZPackage val = new ZPackage();
			val.Write(horn);
			val.Write(DateTime.UtcNow.Ticks);
			State.Write(val);
			ZRoutedRpc.instance.InvokeRoutedRPC(0L, "Gods_Blot", new object[1] { val });
		}
	}

	public static void SendTo(long target)
	{
		//IL_000d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0013: Expected O, but got Unknown
		if (ZRoutedRpc.instance != null && target != 0)
		{
			ZPackage val = new ZPackage();
			val.Write(false);
			val.Write(DateTime.UtcNow.Ticks);
			State.Write(val);
			ZRoutedRpc.instance.InvokeRoutedRPC(target, "Gods_Blot", new object[1] { val });
		}
	}

	private static void Announce(string key, params object[] args)
	{
		GodsServer.AnnouncePublic(key, args);
		string text = (Plugin.BlotDiscordWebhook.Value ?? "").Trim();
		if (text.StartsWith("https://") && (Object)(object)Plugin.Instance != (Object)null)
		{
			string text2 = Loc.T(key, args).Replace("<b>", "**").Replace("</b>", "**");
			((MonoBehaviour)Plugin.Instance).StartCoroutine(PostDiscord(text, "ᛗ " + text2));
		}
	}

	private static IEnumerator PostDiscord(string url, string text)
	{
		string json = "{\"content\":\"" + text.Replace("\\", "\\\\").Replace("\"", "\\\"").Replace("\n", "\\n") + "\"}";
		UnityWebRequest req = new UnityWebRequest(url, "POST");
		try
		{
			req.uploadHandler = (UploadHandler)new UploadHandlerRaw(Encoding.UTF8.GetBytes(json));
			req.downloadHandler = (DownloadHandler)new DownloadHandlerBuffer();
			req.SetRequestHeader("Content-Type", "application/json");
			req.timeout = 15;
			yield return req.SendWebRequest();
			if ((int)req.result != 1)
			{
				Plugin.Log.LogWarning((object)("Discord webhook failed: " + req.error));
			}
		}
		finally
		{
			((IDisposable)req)?.Dispose();
		}
	}

	public static void RPC_Blot(long sender, ZPackage pkg)
	{
		//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_0073: 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)
		try
		{
			bool flag = pkg.ReadBool();
			_serverNow = pkg.ReadLong();
			_receivedAt = Time.realtimeSinceStartup;
			BlotState blotState = BlotState.Read(pkg);
			if (!((Object)(object)ZNet.instance != (Object)null) || !ZNet.instance.IsServer())
			{
				State = blotState;
			}
			if (flag && (Object)(object)Player.m_localPlayer != (Object)null && !GUIManager.IsHeadless())
			{
				Fx.PlayLocal(7, ((Component)Player.m_localPlayer).transform.position + Vector3.up * 2f, blotState.God);
			}
			GodsUI.OnStateChanged();
		}
		catch (Exception ex)
		{
			Plugin.Log.LogWarning((object)("Bad Blót state: " + ex.Message));
		}
	}

	public static int RewardTier(int g)
	{
		if (State.BlessingGod != g || State.BlessingUntil <= ServerNow)
		{
			return 0;
		}
		return Mathf.Clamp(State.BlessingTier, 1, 4);
	}
}
public class ItemRecord
{
	private const int Version = 1;

	public string Prefab = "";

	public int Stack = 1;

	public int Quality = 1;

	public int Variant;

	public float Durability;

	public long CrafterID;

	public string CrafterName = "";

	public int WorldLevel;

	public Dictionary<string, string> CustomData = new Dictionary<string, string>();

	public void Write(ZPackage pkg)
	{
		pkg.Write(1);
		pkg.Write(Prefab);
		pkg.Write(Stack);
		pkg.Write(Quality);
		pkg.Write(Variant);
		pkg.Write(Durability);
		pkg.Write(CrafterID);
		pkg.Write(CrafterName ?? "");
		pkg.Write(WorldLevel);
		pkg.Write(CustomData.Count);
		foreach (KeyValuePair<string, string> customDatum in CustomData)
		{
			pkg.Write(customDatum.Key);
			pkg.Write(customDatum.Value ?? "");
		}
	}

	public static ItemRecord Read(ZPackage pkg)
	{
		ItemRecord itemRecord = new ItemRecord();
		pkg.ReadInt();
		itemRecord.Prefab = pkg.ReadString();
		itemRecord.Stack = pkg.ReadInt();
		itemRecord.Quality = pkg.ReadInt();
		itemRecord.Variant = pkg.ReadInt();
		itemRecord.Durability = pkg.ReadSingle();
		itemRecord.CrafterID = pkg.ReadLong();
		itemRecord.CrafterName = pkg.ReadString();
		itemRecord.WorldLevel = pkg.ReadInt();
		int num = pkg.ReadInt();
		for (int i = 0; i < num; i++)
		{
			string key = pkg.ReadString();
			itemRecord.CustomData[key] = pkg.ReadString();
		}
		return itemRecord;
	}

	public ItemRecord Clone(int stack)
	{
		ItemRecord itemRecord = (ItemRecord)MemberwiseClone();
		itemRecord.CustomData = new Dictionary<string, string>(CustomData);
		itemRecord.Stack = stack;
		return itemRecord;
	}

	public static ItemRecord FromItem(ItemData item, int amount)
	{
		ItemRecord itemRecord = new ItemRecord();
		itemRecord.Prefab = (((Object)(object)item.m_dropPrefab != (Object)null) ? ((Object)item.m_dropPrefab).name : "");
		itemRecord.Stack = amount;
		itemRecord.Quality = item.m_quality;
		itemRecord.Variant = item.m_variant;
		itemRecord.Durability = item.m_durability;
		itemRecord.CrafterID = item.m_crafterID;
		itemRecord.CrafterName = item.m_crafterName ?? "";
		itemRecord.WorldLevel = item.m_worldLevel;
		if (item.m_customData != null)
		{
			itemRecord.CustomData = new Dictionary<string, string>(item.m_customData);
		}
		return itemRecord;
	}

	public static ItemDrop PrefabDrop(string prefab)
	{
		if ((Object)(object)ObjectDB.instance == (Object)null || string.IsNullOrEmpty(prefab))
		{
			return null;
		}
		GameObject itemPrefab = ObjectDB.instance.GetItemPrefab(prefab);
		if (!((Object)(object)itemPrefab != (Object)null))
		{
			return null;
		}
		return itemPrefab.GetComponent<ItemDrop>();
	}

	public ItemData ToItemData()
	{
		ItemDrop val = PrefabDrop(Prefab);
		if ((Object)(object)val == (Object)null)
		{
			return null;
		}
		ItemData val2 = val.m_itemData.Clone();
		val2.m_dropPrefab = ((Component)val).gameObject;
		val2.m_stack = Stack;
		val2.m_quality = Quality;
		val2.m_variant = Variant;
		val2.m_durability = Durability;
		val2.m_crafterID = CrafterID;
		val2.m_crafterName = CrafterName;
		val2.m_worldLevel = WorldLevel;
		val2.m_customData = new Dictionary<string, string>(CustomData);
		val2.m_equipped = false;
		return val2;
	}
}
public class Faith
{
	public long Pid;

	public string Name = "";

	public long OnlineMinutes;

	public readonly float[] Favor = new float[5];

	public readonly long[] LastOffer = new long[5];

	public readonly bool[] Wrath = new bool[5];

	public readonly float[] Today = new float[5];

	public readonly long[] RenouncedUntil = new long[5];

	public readonly int[] Offerings = new int[5];

	public int Day;

	public int Patron = -1;

	public long ForsakenUntil;

	public Faith()
	{
		for (int i = 0; i < 5; i++)
		{
			LastOffer[i] = -1L;
		}
	}

	public void Write(ZPackage pkg)
	{
		pkg.Write(Pid);
		pkg.Write(Name ?? "");
		pkg.Write(OnlineMinutes);
		pkg.Write(Day);
		pkg.Write(Patron);
		pkg.Write(ForsakenUntil);
		for (int i = 0; i < 5; i++)
		{
			pkg.Write(Favor[i]);
			pkg.Write(LastOffer[i]);
			pkg.Write(Wrath[i]);
			pkg.Write(Today[i]);
			pkg.Write(RenouncedUntil[i]);
			pkg.Write(Offerings[i]);
		}
	}

	public static Faith Read(ZPackage pkg, int version)
	{
		Faith faith = new Faith();
		faith.Pid = pkg.ReadLong();
		faith.Name = pkg.ReadString();
		faith.OnlineMinutes = pkg.ReadLong();
		faith.Day = pkg.ReadInt();
		if (version >= 2)
		{
			faith.Patron = pkg.ReadInt();
		}
		if (version >= 3)
		{
			faith.ForsakenUntil = pkg.ReadLong();
		}
		for (int i = 0; i < 5; i++)
		{
			faith.Favor[i] = pkg.ReadSingle();
			faith.LastOffer[i] = pkg.ReadLong();
			faith.Wrath[i] = pkg.ReadBool();
			faith.Today[i] = pkg.ReadSingle();
			faith.RenouncedUntil[i] = pkg.ReadLong();
			faith.Offerings[i] = pkg.ReadInt();
		}
		return faith;
	}
}
public class Settings
{
	public float FavorMax = 2000f;

	public float[] Tiers = new float[4] { 150f, 500f, 1100f, 1800f };

	public float DailyCap = 200f;

	public float DecayPerHour = 10f;

	public float NeglectHours = 3f;

	public float AppeaseFavor = 25f;

	public float RenounceHours = 24f;

	public int SeveranceBase = 300;

	public int SeverancePerTier = 300;

	public float ForsakenHours = 3f;

	public float ForsakenFavor = 0.5f;

	public bool BlotOn = true;

	public int BlotDay = 6;

	public int BlotHour = 20;

	public int BlotGoal = 3000;

	public float BlotMult = 2f;

	public bool WrathEvents = true;

	public float WrathMinutes = 15f;

	public bool ThorBuildings = true;

	public bool LokiPranks = true;

	public float PrankMinutes = 30f;

	public bool LokiTheft = true;

	public bool LokiRandom = true;

	public string[] Rules = new string[5];

	public static Settings FromConfig()
	{
		Settings settings = new Settings();
		settings.FavorMax = Plugin.FavorMax.Value;
		settings.Tiers = ParseTiers(Plugin.TierThresholds.Value, settings.FavorMax);
		settings.DailyCap = Plugin.DailyFavorCap.Value;
		settings.DecayPerHour = Plugin.DecayPerHour.Value;
		settings.NeglectHours = Plugin.NeglectHours.Value;
		settings.AppeaseFavor = Plugin.AppeaseFavor.Value;
		settings.RenounceHours = Plugin.RenounceCooldownHours.Value;
		settings.SeveranceBase = Plugin.SeveranceCoins.Value;
		settings.SeverancePerTier = Plugin.SeveranceCoinsPerTier.Value;
		settings.ForsakenHours = Plugin.ForsakenHours.Value;
		settings.ForsakenFavor = Plugin.ForsakenFavorMultiplier.Value;
		settings.BlotOn = Plugin.BlotEnabled.Value;
		settings.BlotDay = (int)Plugin.BlotDay.Value;
		settings.BlotHour = Plugin.BlotHour.Value;
		settings.BlotGoal = Plugin.BlotGoal.Value;
		settings.BlotMult = Plugin.BlotFavorMultiplier.Value;
		settings.WrathEvents = Plugin.WrathEvents.Value;
		settings.WrathMinutes = Plugin.WrathIntervalMinutes.Value;
		settings.ThorBuildings = Plugin.ThorStrikesBuildings.Value;
		settings.LokiPranks = Plugin.LokiPranks.Value;
		settings.PrankMinutes = Plugin.LokiPrankIntervalMinutes.Value;
		settings.LokiTheft = Plugin.LokiStealsCoins.Value;
		settings.LokiRandom = Plugin.LokiRandomFavor.Value;
		for (int i = 0; i < 5; i++)
		{
			settings.Rules[i] = Plugin.Offerings[i].Value;
		}
		return settings;
	}

	public static float[] ParseTiers(string text, float max)
	{
		float[] result = new float[4] { 150f, 500f, 1100f, 1800f };
		string[] array = (text ?? "").Split(',');
		if (array.Length != 4)
		{
			return result;
		}
		float[] array2 = new float[4];
		for (int i = 0; i < array2.Length; i++)
		{
			if (!float.TryParse(array[i].Trim(), NumberStyles.Float, CultureInfo.InvariantCulture, out array2[i]))
			{
				return result;
			}
			if (array2[i] <= 0f || (i > 0 && array2[i] <= array2[i - 1]) || array2[i] > max)
			{
				return result;
			}
		}
		return array2;
	}

	public int RiteCost(int patron, float favor, bool angry)
	{
		if (patron < 0 || (favor < 1f && !angry))
		{
			return 0;
		}
		return SeveranceBase + SeverancePerTier * Tier(favor);
	}

	public int Tier(float favor)
	{
		int result = 0;
		for (int i = 0; i < Tiers.Length; i++)
		{
			if (favor >= Tiers[i])
			{
				result = i + 1;
			}
		}
		return result;
	}

	public void Write(ZPackage pkg)
	{
		pkg.Write(FavorMax);
		for (int i = 0; i < 4; i++)
		{
			pkg.Write(Tiers[i]);
		}
		pkg.Write(DailyCap);
		pkg.Write(DecayPerHour);
		pkg.Write(NeglectHours);
		pkg.Write(AppeaseFavor);
		pkg.Write(RenounceHours);
		pkg.Write(SeveranceBase);
		pkg.Write(SeverancePerTier);
		pkg.Write(ForsakenHours);
		pkg.Write(ForsakenFavor);
		pkg.Write(BlotOn);
		pkg.Write(BlotDay);
		pkg.Write(BlotHour);
		pkg.Write(BlotGoal);
		pkg.Write(BlotMult);
		pkg.Write(WrathEvents);
		pkg.Write(WrathMinutes);
		pkg.Write(ThorBuildings);
		pkg.Write(LokiPranks);
		pkg.Write(PrankMinutes);
		pkg.Write(LokiTheft);
		pkg.Write(LokiRandom);
		for (int j = 0; j < 5; j++)
		{
			pkg.Write(Rules[j] ?? "");
		}
	}

	public static Settings Read(ZPackage pkg)
	{
		Settings settings = new Settings();
		settings.FavorMax = pkg.ReadSingle();
		for (int i = 0; i < 4; i++)
		{
			settings.Tiers[i] = pkg.ReadSingle();
		}
		settings.DailyCap = pkg.ReadSingle();
		settings.DecayPerHour = pkg.ReadSingle();
		settings.NeglectHours = pkg.ReadSingle();
		settings.AppeaseFavor = pkg.ReadSingle();
		settings.RenounceHours = pkg.ReadSingle();
		settings.SeveranceBase = pkg.ReadInt();
		settings.SeverancePerTier = pkg.ReadInt();
		settings.ForsakenHours = pkg.ReadSingle();
		settings.ForsakenFavor = pkg.ReadSingle();
		settings.BlotOn = pkg.ReadBool();
		settings.BlotDay = pkg.ReadInt();
		settings.BlotHour = pkg.ReadInt();
		settings.BlotGoal = pkg.ReadInt();
		settings.BlotMult = pkg.ReadSingle();
		settings.WrathEvents = pkg.ReadBool();
		settings.WrathMinutes = pkg.ReadSingle();
		settings.ThorBuildings = pkg.ReadBool();
		settings.LokiPranks = pkg.ReadBool();
		settings.PrankMinutes = pkg.ReadSingle();
		settings.LokiTheft = pkg.ReadBool();
		settings.LokiRandom = pkg.ReadBool();
		for (int j = 0; j < 5; j++)
		{
			settings.Rules[j] = pkg.ReadString();
		}
		return settings;
	}
}
internal static class Rpc
{
	public const string Request = "Gods_Request";

	public const string Offer = "Gods_Offer";

	public const string Renounce = "Gods_Renounce";

	public const string Pledge = "Gods_Pledge";

	public const string Admin = "Gods_Admin";

	public const string State = "Gods_State";

	public const string Result = "Gods_Result";

	public const string Deliver = "Gods_Deliver";

	public const string Announce = "Gods_Announce";

	public const string FxEvent = "Gods_Fx";

	public const string BlotEvent = "Gods_Blot";

	public static void Register()
	{
		ZRoutedRpc instance = ZRoutedRpc.instance;
		if (instance != null)
		{
			instance.Register("Gods_Request", (Action<long>)GodsServer.RPC_Request);
			instance.Register<ZPackage>("Gods_Offer", (Action<long, ZPackage>)GodsServer.RPC_Offer);
			instance.Register<ZPackage>("Gods_Renounce", (Action<long, ZPackage>)GodsServer.RPC_Renounce);
			instance.Register<ZPackage>("Gods_Pledge", (Action<long, ZPackage>)GodsServer.RPC_Pledge);
			instance.Register<string>("Gods_Admin", (Action<long, string>)GodsServer.RPC_Admin);
			instance.Register<ZPackage>("Gods_State", (Action<long, ZPackage>)GodsClient.RPC_State);
			instance.Register<ZPackage>("Gods_Result", (Action<long, ZPackage>)GodsClient.RPC_Result);
			instance.Register<ZPackage>("Gods_Deliver", (Action<long, ZPackage>)GodsClient.RPC_Deliver);
			instance.Register<ZPackage>("Gods_Announce", (Action<long, ZPackage>)GodsClient.RPC_Announce);
			instance.Register<ZPackage>("Gods_Fx", (Action<long, ZPackage>)Fx.RPC_Fx);
			instance.Register<ZPackage>("Gods_Blot", (Action<long, ZPackage>)Blot.RPC_Blot);
		}
	}

	public static long ServerId()
	{
		if ((Object)(object)ZNet.instance == (Object)null)
		{
			return 0L;
		}
		if (ZNet.instance.IsServer())
		{
			return ZDOMan.GetSessionID();
		}
		return ZNet.instance.GetServerPeer()?.m_uid ?? 0;
	}
}
internal static class FavorHud
{
	private const float Width = 330f;

	private const float Height = 56f;

	private static GameObject _root;

	private static Image _icon;

	private static Image _fillImg;

	private static RectTransform _fill;

	private static Text _top;

	private static Text _power;

	private static Text _status;

	private static Text _blot;

	private static readonly RectTransform[] _ticks = (RectTransform[])(object)new RectTransform[4];

	private static float _timer;

	private static int _builtFor = -1;

	public static void Update()
	{
		_timer -= Time.deltaTime;
		if (_timer > 0f)
		{
			return;
		}
		_timer = 0.25f;
		try
		{
			Refresh();
		}
		catch (Exception ex)
		{
			Plugin.Log.LogWarning((object)("Favor HUD disabled after an error: " + ex.Message));
			_timer = float.MaxValue;
		}
	}

	private static void Refresh()
	{
		//IL_00c0: 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_0563: 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)
		//IL_0101: Unknown result type (might be due to invalid IL or missing references)
		//IL_0216: Unknown result type (might be due to invalid IL or missing references)
		//IL_023f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0280: Unknown result type (might be due to invalid IL or missing references)
		//IL_0299: Unknown result type (might be due to invalid IL or missing references)
		//IL_02b3: Unknown result type (might be due to invalid IL or missing references)
		//IL_02b8: Unknown result type (might be due to invalid IL or missing references)
		Hud instance = Hud.instance;
		Player localPlayer = Player.m_localPlayer;
		bool flag = Blot.State.Active || Blot.RewardSecondsLeft > 0f;
		int patron = GodsClient.Patron;
		if (!Plugin.ShowFavorHud.Value || !((Object)(object)instance != (Object)null) || !((Object)(object)instance.m_rootObject != (Object)null) || !((Object)(object)localPlayer != (Object)null) || !GodsClient.HasData || (patron < 0 && !flag))
		{
			if ((Object)(object)_root != (Object)null)
			{
				_root.SetActive(false);
			}
			return;
		}
		if ((Object)(object)_root == (Object)null || _builtFor != ((Object)instance).GetInstanceID())
		{
			Build(instance);
		}
		_root.SetActive(true);
		((RectTransform)_root.transform).anchoredPosition = new Vector2((float)Plugin.FavorHudOffsetX.Value, (float)Plugin.FavorHudOffsetY.Value);
		Settings cfg = GodsClient.Cfg;
		if (patron >= 0)
		{
			int num = GodsClient.Tier(patron);
			Color val = GodDefs.Glow(patron);
			_icon.sprite = (GodsClient.Angry[patron] ? ShrineModel.WrathIcons[patron] : ShrineModel.Symbols[patron]);
			((Behaviour)_icon).enabled = (Object)(object)_icon.sprite != (Object)null;
			_top.text = "<color=#" + GodDefs.Hex(patron) + ">" + GodDefs.Name(patron) + "</color>" + ((num > 0) ? (" · " + GodDefs.Roman[num - 1]) : "") + "  <color=#C9C2B0>" + OfferFormat.Favor(GodsClient.Favor[patron]) + "/" + OfferFormat.Favor(cfg.FavorMax) + "</color>";
			float num2 = Mathf.Clamp01(GodsClient.Favor[patron] / Mathf.Max(1f, cfg.FavorMax));
			_fill.anchorMax = new Vector2(num2, 1f);
			((Graphic)_fillImg).color = new Color(val.r, val.g, val.b, 0.9f);
			for (int i = 0; i < 4; i++)
			{
				float num3 = Mathf.Clamp01(cfg.Tiers[i] / Mathf.Max(1f, cfg.FavorMax));
				_ticks[i].anchorMin = new Vector2(num3, 0f);
				_ticks[i].anchorMax = new Vector2(num3, 1f);
			}
			string text = ((object)Plugin.PowerKey.Value/*cast due to .constrained prefix*/).ToString();
			int num4 = Powers.EquippedAmulet(localPlayer);
			if (num == 0 || num4 != patron)
			{
				_power.text = "";
			}
			else
			{
				float num5 = Powers.CooldownLeft(localPlayer);
				bool flag2 = GodsClient.Angry[patron] || GodsClient.Forsaken;
				_power.text = (flag2 ? ("<color=#9A8A80>[" + text + "] " + Loc.T("hud_power_blocked") + "</color>") : ((num5 > 0f) ? ("<color=#C9C2B0>[" + text + "] " + Powers.Clock(num5) + "</color>") : ("<color=#9BE37A>[" + text + "] " + Loc.T("hud_power_ready") + "</color>")));
			}
			if (GodsClient.Forsaken)
			{
				_status.text = "<color=#C9A0FF>" + Loc.T("hud_forsaken", Span(GodsClient.ForsakenLeft)) + "</color>";
			}
			else if (GodsClient.Angry[patron])
			{
				_status.text = "<color=#FF6655>" + Loc.T("hud_wrath") + "</color>";
			}
			else if (num > 0 && GodsClient.SinceOffer[patron] >= 0)
			{
				float num6 = cfg.NeglectHours * 60f - ((float)GodsClient.SinceOffer[patron] + GodsClient.MinutesSinceState);
				_status.text = ((num6 < 30f) ? ("<color=#FFB060>" + Loc.T("hud_neglect", Span(Mathf.Max(0f, num6))) + "</color>") : ("<color=#A8A090>" + Loc.T("hud_neglect", Span(num6)) + "</color>"));
			}
			else
			{
				_status.text = "";
			}
		}
		else
		{
			_icon.sprite = null;
			((Behaviour)_icon).enabled = false;
			_top.text = "<color=#A8A090>" + Loc.T("hud_no_patron") + "</color>";
			_fill.anchorMax = new Vector2(0f, 1f);
			_power.text = "";
			_status.text = "";
		}
		if (Blot.State.Active)
		{
			BlotState state = Blot.State;
			_blot.text = "<color=#" + GodDefs.Hex(state.God) + ">" + Loc.T("hud_blot", GodDefs.Gen(state.God), OfferFormat.Favor(state.Meter), OfferFormat.Favor(state.Goal), Clock(Blot.SecondsLeft)) + "</color>";
		}
		else if (Blot.RewardSecondsLeft > 0f && Blot.State.BlessingGod >= 0)
		{
			_blot.text = "<color=#" + GodDefs.Hex(Blot.State.BlessingGod) + ">" + Loc.T("hud_blot_reward", GodDefs.Gen(Blot.State.BlessingGod), Clock(Blot.RewardSecondsLeft)) + "</color>";
		}
		else
		{
			_blot.text = "";
		}
	}

	private static string Span(float minutes)
	{
		int num = Mathf.CeilToInt(minutes);
		if (num < 60)
		{
			return num + " min";
		}
		return num / 60 + " h " + num % 60 + " min";
	}

	private static string Clock(float seconds)
	{
		int num = Mathf.CeilToInt(seconds);
		if (num < 3600)
		{
			return num / 60 + ":" + (num % 60).ToString("00");
		}
		return num / 3600 + ":" + (num % 3600 / 60).ToString("00") + ":" + (num % 60).ToString("00");
	}

	private static void Build(Hud hud)
	{
		//IL_004d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0057: Expected O, but got Unknown
		//IL_0091: Unknown result type (might be due to invalid IL or missing references)
		//IL_0097: Expected O, but got Unknown
		//IL_00a3: Unknown result type (might be due to invalid IL or missing references)
		//IL_00a8: Unknown result type (might be due to invalid IL or missing references)
		//IL_00a9: 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_00c2: 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_0101: 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_01d2: Unknown result type (might be due to invalid IL or missing references)
		//IL_0208: Unknown result type (might be due to invalid IL or missing references)
		//IL_020e: Expected O, but got Unknown
		//IL_0226: Unknown result type (might be due to invalid IL or missing references)
		//IL_0230: Expected O, but got Unknown
		//IL_0235: Unknown result type (might be due to invalid IL or missing references)
		//IL_024e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0267: Unknown result type (might be due to invalid IL or missing references)
		//IL_0280: Unknown result type (might be due to invalid IL or missing references)
		//IL_02d3: Unknown result type (might be due to invalid IL or missing references)
		//IL_02da: Expected O, but got Unknown
		//IL_02f4: Unknown result type (might be due to invalid IL or missing references)
		//IL_02fb: Expected O, but got Unknown
		//IL_0307: Unknown result type (might be due to invalid IL or missing references)
		//IL_031d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0333: Unknown result type (might be due to invalid IL or missing references)
		//IL_0349: Unknown result type (might be due to invalid IL or missing references)
		//IL_0372: Unknown result type (might be due to invalid IL or missing references)
		if ((Object)(object)_root != (Object)null)
		{
			Object.Destroy((Object)(object)_root);
		}
		_builtFor = ((Object)hud).GetInstanceID();
		_root = new GameObject("Gods_Hud", new Type[2]
		{
			typeof(RectTransform),
			typeof(Image)
		});
		_root.layer = hud.m_rootObject.layer;
		_root.transform.SetParent(hud.m_rootObject.transform, false);
		RectTransform val = (RectTransform)_root.transform;
		Vector2 anchorMin = (val.anchorMax = new Vector2(0.5f, 0f));
		val.anchorMin = anchorMin;
		val.pivot = new Vector2(0.5f, 0f);
		val.sizeDelta = new Vector2(330f, 56f);
		Image component = _root.GetComponent<Image>();
		((Graphic)component).color = new Color(0f, 0f, 0f, 0.5f);
		((Graphic)component).raycastTarget = false;
		_icon = Img(_root.transform, 5f, 9f, 38f, 38f, Color.white);
		_icon.preserveAspect = true;
		_top = Txt(_root.transform, 48f, 34f, 190f, 20f, (TextAnchor)3, 14);
		_power = Txt(_root.transform, 196f, 34f, 128f, 20f, (TextAnchor)5, 13);
		Image val3 = Img(_root.transform, 48f, 25f, 274f, 8f, new Color(0.18f, 0.13f, 0.08f, 0.95f));
		GameObject val4 = new GameObject("Fill", new Type[2]
		{
			typeof(RectTransform),
			typeof(Image)
		});
		val4.transform.SetParent(((Component)val3).transform, false);
		_fill = (RectTransform)val4.transform;
		_fill.anchorMin = Vector2.zero;
		_fill.anchorMax = new Vector2(0f, 1f);
		_fill.offsetMin = new Vector2(1f, 1f);
		_fill.offsetMax = new Vector2(-1f, -1f);
		_fillImg = val4.GetComponent<Image>();
		((Graphic)_fillImg).raycastTarget = false;
		for (int i = 0; i < 4; i++)
		{
			GameObject val5 = new GameObject("Tick", new Type[2]
			{
				typeof(RectTransform),
				typeof(Image)
			});
			val5.transform.SetParent(((Component)val3).transform, false);
			RectTransform val6 = (RectTransform)val5.transform;
			val6.pivot = new Vector2(0.5f, 0.5f);
			val6.sizeDelta = new Vector2(2f, 4f);
			val6.offsetMin = new Vector2(-1f, -2f);
			val6.offsetMax = new Vector2(1f, 2f);
			Image component2 = val5.GetComponent<Image>();
			((Graphic)component2).color = new Color(1f, 1f, 1f, 0.75f);
			((Graphic)component2).raycastTarget = false;
			_ticks[i] = val6;
		}
		_status = Txt(_root.transform, 48f, 4f, 150f, 18f, (TextAnchor)3, 12);
		_blot = Txt(_root.transform, 150f, 4f, 174f, 18f, (TextAnchor)5, 12);
	}

	private static Image Img(Transform parent, float x, float y, float w, float h, Color c)
	{
		//IL_0027: Unknown result type (might be due to invalid IL or missing references)
		//IL_002d: Expected O, but got Unknown
		//IL_0040: Unknown result type (might be due to invalid IL or missing references)
		//IL_0046: Expected O, but got Unknown
		//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_0058: Unknown result type (might be due to invalid IL or missing references)
		//IL_005f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0071: 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_008c: 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)
		GameObject val = new GameObject("Img", new Type[2]
		{
			typeof(RectTransform),
			typeof(Image)
		});
		val.transform.SetParent(parent, false);
		RectTransform val2 = (RectTransform)val.transform;
		Vector2 anchorMin = (val2.anchorMax = new Vector2(0f, 0f));
		val2.anchorMin = anchorMin;
		val2.pivot = new Vector2(0f, 0f);
		val2.anchoredPosition = new Vector2(x, y);
		val2.sizeDelta = new Vector2(w, h);
		Image component = val.GetComponent<Image>();
		((Graphic)component).color = c;
		((Graphic)component).raycastTarget = false;
		return component;
	}

	private static Text Txt(Transform parent, float x, float y, float w, float h, TextAnchor align, int size)
	{
		//IL_0015: 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_0029: Unknown result type (might be due to invalid IL or missing references)
		//IL_003f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0059: Unknown result type (might be due to invalid IL or missing references)
		//IL_006e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0074: Expected O, but got Unknown
		//IL_007f: Unknown result type (might be due to invalid IL or missing references)
		//IL_008c: Unknown result type (might be due to invalid IL or missing references)
		//IL_009a: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ac: Unknown result type (might be due to invalid IL or missing references)
		GameObject val = GUIManager.Instance.CreateText("", parent, new Vector2(0f, 0f), new Vector2(0f, 0f), Vector2.zero, GUIManager.Instance.AveriaSerifBold, size, GUIManager.Instance.ValheimBeige, true, new Color(0f, 0f, 0f, 0.9f), w, h, false);
		RectTransform val2 = (RectTransform)val.transform;
		val2.pivot = new Vector2(0f, 0f);
		val2.anchoredPosition = new Vector2(x, y);
		val2.sizeDelta = new Vector2(w, h);
		Text component = val.GetComponent<Text>();
		component.alignment = align;
		component.supportRichText = true;
		((Graphic)component).raycastTarget = false;
		component.horizontalOverflow = (HorizontalWrapMode)1;
		return component;
	}

	public static void Reset()
	{
		if ((Object)(object)_root != (Object)null)
		{
			Object.Destroy((Object)(object)_root);
		}
		_root = null;
		_builtFor = -1;
	}
}
internal static class Fx
{
	public const int Offering = 0;

	public const int Bolt = 1;

	public const int SmallBolt = 2;

	public const int LokiPuff = 3;

	public const int WrathPulse = 4;

	public const int Power = 5;

	public const int FreyaHeal = 6;

	public const int BlotHorn = 7;

	private const int Rate = 44100;

	private static Material _additive;

	private static Material _line;

	private static Texture2D _soft;

	private static AudioClip _thunder;

	private static AudioClip _chime;

	private static AudioClip _whoosh;

	private static AudioClip _drone;

	private static readonly AudioClip[] GodClips = (AudioClip[])(object)new AudioClip[5];

	private static Material _runeMat;

	private static AudioMixerGroup _sfx;

	private static bool _sfxSearched;

	public static void Broadcast(int kind, Vector3 pos, int god)
	{
		//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)
		Broadcast(kind, pos, pos, god);
	}

	public static void Broadcast(int kind, Vector3 pos, Vector3 to, int god)
	{
		//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_0018: Unknown result type (might be due to invalid IL or missing references)
		//IL_001e: Expected O, but got Unknown
		//IL_0026: 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 (!GUIManager.IsHeadless())
		{
			Play(kind, pos, to, god);
		}
		if (ZRoutedRpc.instance != null)
		{
			ZPackage val = new ZPackage();
			val.Write(kind);
			val.Write(pos);
			val.Write(to);
			val.Write(god);
			ZRoutedRpc.instance.InvokeRoutedRPC(0L, "Gods_Fx", new object[1] { val });
		}
	}

	public static void PlayLocal(int kind, Vector3 pos, int god)
	{
		//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)
		if (!GUIManager.IsHeadless())
		{
			Play(kind, pos, pos, god);
		}
	}

	public static void RPC_Fx(long sender, ZPackage pkg)
	{
		//IL_0018: Unknown result type (might be due to invalid IL or missing references)
		//IL_001d: 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_0062: Unknown result type (might be due to invalid IL or missing references)
		//IL_0063: 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_004a: 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)
		if (GUIManager.IsHeadless() || sender == ZDOMan.GetSessionID())
		{
			return;
		}
		try
		{
			int kind = pkg.ReadInt();
			Vector3 pos = pkg.ReadVector3();
			Vector3 val = pkg.ReadVector3();
			int god = pkg.ReadInt();
			Player localPlayer = Player.m_localPlayer;
			if ((Object)(object)localPlayer != (Object)null)
			{
				Vector3 val2 = ((Component)localPlayer).transform.position - val;
				if (((Vector3)(ref val2)).sqrMagnitude > 22500f)
				{
					return;
				}
			}
			Play(kind, pos, val, god);
		}
		catch (Exception ex)
		{
			Plugin.Log.LogWarning((object)("Gods fx: " + ex.Message));
		}
	}

	private static void Play(int kind, Vector3 pos, Vector3 to, int god)
	{
		//IL_0008: Unknown result type (might be due to invalid IL or missing references)
		//IL_0015: Unknown result type (might be due to invalid IL or missing references)
		//IL_0010: Unknown result type (might be due to invalid IL or missing references)
		//IL_003f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0040: Unknown result type (might be due to invalid IL or missing references)
		//IL_0048: 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_0057: Unknown result type (might be due to invalid IL or missing references)
		//IL_0061: Unknown result type (might be due to invalid IL or missing references)
		//IL_0066: 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_0080: 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_0179: 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_0199: Unknown result type (might be due to invalid IL or missing references)
		//IL_019a: Unknown result type (might be due to invalid IL or missing references)
		//IL_019f: Unknown result type (might be due to invalid IL or missing references)
		//IL_01b3: Unknown result type (might be due to invalid IL or missing references)
		//IL_01cc: Unknown result type (might be due to invalid IL or missing references)
		//IL_01e2: Unknown result type (might be due to invalid IL or missing references)
		//IL_01e3: Unknown result type (might be due to invalid IL or missing references)
		//IL_01f3: Unknown result type (might be due to invalid IL or missing references)
		//IL_0203: Unknown result type (might be due to invalid IL or missing references)
		//IL_0213: Unknown result type (might be due to invalid IL or missing references)
		//IL_022c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0242: Unknown result type (might be due to invalid IL or missing references)
		//IL_0244: Unknown result type (might be due to invalid IL or missing references)
		//IL_0250: Unknown result type (might be due to invalid IL or missing references)
		//IL_0266: Unknown result type (might be due to invalid IL or missing references)
		//IL_0276: Unknown result type (might be due to invalid IL or missing references)
		//IL_0282: Unknown result type (might be due to invalid IL or missing references)
		//IL_0097: 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_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)
		//IL_00ae: 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_00b4: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b9: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ce: Unknown result type (might be due to invalid IL or missing references)
		//IL_00e5: Unknown result type (might be due to invalid IL or missing references)
		//IL_00e6: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ee: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ef: 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)
		//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_0107: 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_013e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0161: Unknown result type (might be due to invalid IL or missing references)
		Color c = ((god >= 0 && god < 5) ? GodDefs.Glow(god) : Color.white);
		switch (kind)
		{
		case 0:
			Burst(pos, c, 40);
			Runes(pos, c, 14, 2.2f);
			Flash(pos + Vector3.up * 0.5f, c, 3f, 8f, 0.6f);
			Sound(pos, GodSound(god), 0.75f, 1f);
			break;
		case 5:
			Burst(pos, c, 60);
			Runes(pos, c, 24, 3f);
			Flash(pos + Vector3.up, c, 5f, 14f, 0.8f);
			Sound(pos, GodSound(god), 1f, 1f);
			break;
		case 6:
			Burst(pos, c, 50);
			Runes(pos, c, 18, 2.5f);
			Flash(pos + Vector3.up, c, 4f, Mathf.Max(6f, to.y), 1f);
			Sound(pos, GodSound(2), 0.9f, 1f);
			Powers.ReceiveHeal(pos, to.x, to.y, to.z > 0.5f);
			break;
		case 7:
			Sound(pos, GodSound(0), 0.6f, 0.85f);
			break;
		case 1:
			Lightning(pos, to, new Color(0.75f, 0.85f, 1f), 0.35f, branches: true);
			Flash(to + Vector3.up, new Color(0.8f, 0.85f, 1f), 8f, 30f, 0.25f);
			Sound(to, Thunder(), 1f, 1f);
			break;
		case 2:
			Lightning(pos, to, new Color(1f, 0.92f, 0.6f), 0.14f, branches: false);
			Flash(to, new Color(1f, 0.9f, 0.6f), 3f, 8f, 0.15f);
			Sound(to, Thunder(), 0.45f, 1.6f);
			break;
		case 3:
			Burst(pos, GodDefs.Glow(4), 30);
			Sound(pos, Whoosh(), 0.7f, 1f);
			break;
		case 4:
			Burst(pos, new Color(1f, 0.25f, 0.15f), 24);
			Sound(pos, Drone(), 0.8f, 1f);
			break;
		}
	}

	public static Light AddLight(Transform parent, Vector3 local, Color c, float intensity, float range)
	{
		//IL_0005: Unknown result type (might be due to invalid IL or missing references)
		//IL_000b: Expected O, but got Unknown
		//IL_001e: 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)
		GameObject val = new GameObject("GodsLight");
		val.transform.SetParent(parent, false);
		val.transform.localPosition = local;
		Light val2 = val.AddComponent<Light>();
		val2.type = (LightType)2;
		val2.color = c;
		val2.intensity = intensity;
		val2.range = range;
		val2.shadows = (LightShadows)0;
		val2.renderMode = (LightRenderMode)0;
		return val2;
	}

	public static ParticleSystem AddFlame(Transform parent, Vector3 local, Color c)
	{
		//IL_0005: Unknown result type (might be due to invalid IL or missing references)
		//IL_000b: Expected O, but got Unknown
		//IL_001e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0039: Unknown result type (might be due to invalid IL or missing references)
		//IL_0053: Unknown result type (might be due to invalid IL or missing references)
		//IL_0058: 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_008f: 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_00c7: 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_00df: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ea: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ef: 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_0119: 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_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_015e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0163: Unknown result type (might be due to invalid IL or missing references)
		//IL_017a: Unknown result type (might be due to invalid IL or missing references)
		//IL_017f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0186: Unknown result type (might be due to invalid IL or missing references)
		//IL_018d: Expected O, but got Unknown
		//IL_0196: Unknown result type (might be due to invalid IL or missing references)
		GameObject val = new GameObject("GodsFlame");
		val.transform.SetParent(parent, false);
		val.transform.localPosition = local;
		val.transform.localRotation = Quaternion.Euler(-90f, 0f, 0f);
		ParticleSystem val2 = val.AddComponent<ParticleSystem>();
		val2.Stop(true, (ParticleSystemStopBehavior)0);
		MainModule main = val2.main;
		((MainModule)(ref main)).duration = 1f;
		((MainModule)(ref main)).loop = true;
		((MainModule)(ref main)).startLifetime = new MinMaxCurve(0.5f, 0.9f);
		((MainModule)(ref main)).startSpeed = new MinMaxCurve(0.5f, 0.9f);
		((MainModule)(ref main)).startSize = new MinMaxCurve(0.18f, 0.34f);
		((MainModule)(ref main)).simulationSpace = (ParticleSystemSimulationSpace)1;
		((MainModule)(ref main)).maxParticles = 80;
		((MainModule)(ref main)).gravityModifier = MinMaxCurve.op_Implicit(-0.05f);
		EmissionModule emission = val2.emission;
		((EmissionModule)(ref emission)).rateOverTime = MinMaxCurve.op_Implicit(34f);
		ShapeModule shape = val2.shape;
		((ShapeModule)(ref shape)).shapeType = (ParticleSystemShapeType)4;
		((ShapeModule)(ref shape)).angle = 6f;
		((ShapeModule)(ref shape)).radius = 0.16f;
		SetFlameColor(val2, c);
		SizeOverLifetimeModule sizeOverLifetime = val2.sizeOverLifetime;
		((SizeOverLifetimeModule)(ref sizeOverLifetime)).enabled = true;
		AnimationCurve val3 = new AnimationCurve((Keyframe[])(object)new Keyframe[3]
		{
			new Keyframe(0f, 0.6f),
			new Keyframe(0.3f, 1f),
			new Keyframe(1f, 0.1f)
		});
		((SizeOverLifetimeModule)(ref sizeOverLifetime)).size = new MinMaxCurve(1f, val3);
		ParticleSystemRenderer component = val.GetComponent<ParticleSystemRenderer>();
		((Renderer)component).material = Additive();
		component.renderMode = (ParticleSystemRenderMode)0;
		val2.Play();
		return val2;
	}

	public static void SetFlameColor(ParticleSystem ps, Color c)
	{
		//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_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_0014: Unknown result type (might be due to invalid IL or missing references)
		//IL_0019: Unknown result type (might be due to invalid IL or missing references)
		//IL_001a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0025: Unknown result type (might be due to invalid IL or missing references)
		//IL_002a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0033: Unknown result type (might be due to invalid IL or missing references)
		//IL_0039: Expected O, but got Unknown
		//IL_0048: 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_0053: 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)
		//IL_0062: Unknown result type (might be due to invalid IL or missing references)
		//IL_006e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0074: 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_0085: 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_0095: Unknown result type (might be due to invalid IL or missing references)
		//IL_009a: 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_00bf: 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_00db: Unknown result type (might be due to invalid IL or missing references)
		//IL_00f2: Unknown result type (might be due to invalid IL or missing references)
		//IL_00f7: 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_0113: 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)
		MainModule main = ps.main;
		((MainModule)(ref main)).startColor = new MinMaxGradient(Color.Lerp(c, Color.white, 0.45f), c);
		ColorOverLifetimeModule colorOverLifetime = ps.colorOverLifetime;
		((ColorOverLifetimeModule)(ref colorOverLifetime)).enabled = true;
		Gradient val = new Gradient();
		val.SetKeys((GradientColorKey[])(object)new GradientColorKey[3]
		{
			new GradientColorKey(Color.Lerp(c, Color.white, 0.6f), 0f),
			new GradientColorKey(c, 0.4f),
			new GradientColorKey(c * 0.6f, 1f)
		}, (GradientAlphaKey[])(object)new GradientAlphaKey[4]
		{
			new GradientAlphaKey(0f, 0f),
			new GradientAlphaKey(0.9f, 0.12f),
			new GradientAlphaKey(0.5f, 0.6f),
			new GradientAlphaKey(0f, 1f)
		});
		((ColorOverLifetimeModule)(ref colorOverLifetime)).color = new MinMaxGradient(val);
	}

	public static void Burst(Vector3 pos, Color c, int count)
	{
		//IL_0005: Unknown result type (might be due to invalid IL or missing references)
		//IL_000b: Expected O, but got Unknown
		//IL_0011: Unknown result type (might be due to invalid IL or missing references)
		//IL_002c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0046: Unknown result type (might be due to invalid IL or missing references)
		//IL_004b: 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_0082: 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_00b1: Unknown result type (might be due to invalid IL or missing references)
		//IL_00bd: Unknown result type (might be due to invalid IL or missing references)
		//IL_00be: 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_00cd: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ce: 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_00de: Unknown result type (might be due to invalid IL or missing references)
		//IL_00e6: 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_011b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0120: Unknown result type (might be due to invalid IL or missing references)
		//IL_0143: Unknown result type (might be due to invalid IL or missing references)
		//IL_0148: Unknown result type (might be due to invalid IL or missing references)
		//IL_0152: Unknown result type (might be due to invalid IL or missing references)
		//IL_0159: Expected O, but got Unknown
		//IL_016b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0175: Unknown result type (might be due to invalid IL or missing references)
		//IL_017a: 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_018d: 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_019f: Unknown result type (might be due to invalid IL or missing references)
		//IL_01a5: Unknown result type (might be due to invalid IL or missing references)
		//IL_01aa: Unknown result type (might be due to invalid IL or missing references)
		//IL_01cb: Unknown result type (might be due to invalid IL or missing references)
		//IL_01d0: Unknown result type (might be due to invalid IL or missing references)
		//IL_01e7: Unknown result type (might be due to invalid IL or missing references)
		//IL_01ec: Unknown result type (might be due to invalid IL or missing references)
		//IL_0203: Unknown result type (might be due to invalid IL or missing references)
		//IL_0208: Unknown result type (might be due to invalid IL or missing references)
		//IL_0218: Unknown result type (might be due to invalid IL or missing references)
		GameObject val = new GameObject("GodsBurst");
		val.transform.position = pos;
		val.transform.rotation = Quaternion.Euler(-90f, 0f, 0f);
		ParticleSystem val2 = val.AddComponent<ParticleSystem>();
		val2.Stop(true, (ParticleSystemStopBehavior)0);
		MainModule main = val2.main;
		((MainModule)(ref main)).duration = 0.5f;
		((MainModule)(ref main)).loop = false;
		((MainModule)(ref main)).startLifetime = new MinMaxCurve(0.8f, 1.6f);
		((MainModule)(ref main)).startSpeed = new MinMaxCurve(1.2f, 3.2f);
		((MainModule)(ref main)).startSize = new MinMaxCurve(0.08f, 0.2f);
		((MainModule)(ref main)).simulationSpace = (ParticleSystemSimulationSpace)1;
		((MainModule)(ref main)).gravityModifier = MinMaxCurve.op_Implicit(-0.1f);
		((MainModule)(ref main)).startColor = new MinMaxGradient(Color.Lerp(c, Color.white, 0.5f), c);
		EmissionModule emission = val2.emission;
		((EmissionModule)(ref emission)).rateOverTime = MinMaxCurve.op_Implicit(0f);
		((EmissionModule)(ref emission)).SetBursts((Burst[])(object)new Burst[1]
		{
			new Burst(0f, (short)count)
		});
		ShapeModule shape = val2.shape;
		((ShapeModule)(ref shape)).shapeType = (ParticleSystemShapeType)4;
		((ShapeModule)(ref shape)).angle = 28f;
		((ShapeModule)(ref shape)).radius = 0.25f;
		ColorOverLifetimeModule colorOverLifetime = val2.colorOverLifetime;
		((ColorOverLifetimeModule)(ref colorOverLifetime)).enabled = true;
		Gradient val3 = new Gradient();
		val3.SetKeys((GradientColorKey[])(object)new GradientColorKey[3]
		{
			new GradientColorKey(Color.white, 0f),
			new GradientColorKey(c, 0.3f),
			new GradientColorKey(c, 1f)
		}, (GradientAlphaKey[])(object)new GradientAlphaKey[3]
		{
			new GradientAlphaKey(1f, 0f),
			new GradientAlphaKey(0.8f, 0.5f),
			new GradientAlphaKey(0f, 1f)
		});
		((ColorOverLifetimeModule)(ref colorOverLifetime)).color = new MinMaxGradient(val3);
		ParticleSystemRenderer component = val.GetComponent<ParticleSystemRenderer>();
		((Renderer)component).material = Additive();
		val2.Play();
		Object.Destroy((Object)(object)val, 3f);
	}

	public static void Flash(Vector3 pos, Color c, float intensity, float range, float time)
	{
		//IL_0005: Unknown result type (might be due to invalid IL or missing references)
		//IL_000b: Expected O, but got Unknown
		//IL_0011: 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)
		GameObject val = new GameObject("GodsFlash");
		val.transform.position = pos;
		Light val2 = val.AddComponent<Light>();
		val2.type = (LightType)2;
		val2.color = c;
		val2.intensity = intensity;
		val2.range = range;
		val2.shadows = (LightShadows)0;
		val.AddComponent<FadeLight>().Setup(time);
	}

	public static void Lightning(Vector3 from, Vector3 to, Color c, float width, bool branches)
	{
		//IL_0000: Unknown result type (might be due to invalid IL or missing references)
		//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_0036: Unknown result type (might be due to invalid IL or missing references)
		//IL_0037: Unknown result type (might be due to invalid IL or missing references)
		//IL_0039: 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_003f: 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_008c: 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_008f: 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)
		Line(from, to, c, width, 14, 0.9f);
		if (branches)
		{
			Random random = new Random();
			for (int i = 0; i < 3; i++)
			{
				float num = 0.25f + (float)random.NextDouble() * 0.5f;
				Vector3 val = Vector3.Lerp(from, to, num);
				Vector3 to2 = val + new Vector3((float)(random.NextDouble() - 0.5) * 8f, (0f - (float)random.NextDouble()) * 6f - 2f, (float)(random.NextDouble() - 0.5) * 8f);
				Line(val, to2, c, width * 0.45f, 6, 0.6f);
			}
		}
	}

	private static void Line(Vector3 from, Vector3 to, Color c, float width, int segs, float jag)
	{
		//IL_0005: Unknown result type (might be due to invalid IL or missing references)
		//IL_000b: Expected O, but got Unknown
		//IL_002e: Unknown result type (might be due to invalid IL or missing references)
		//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_0035: 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_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_0047: Unknown result type (might be due to invalid IL or missing references)
		//IL_0065: Unknown result type (might be due to invalid IL or missing references)
		//IL_006a: Unknown result type (might be due to invalid IL or missing references)
		//IL_006b: 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)
		//IL_0074: 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_0056: Unknown result type (might be due to invalid IL or missing references)
		//IL_005b: 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_009a: Unknown result type (might be due to invalid IL or missing references)
		//IL_009d: 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_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_00e6: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b4: 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_00c1: 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_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_00dc: Unknown result type (might be due to invalid IL or missing references)
		//IL_00e1: Unknown result type (might be due to invalid IL or missing references)
		GameObject val = new GameObject("GodsBolt");
		LineRenderer val2 = val.AddComponent<LineRenderer>();
		val2.useWorldSpace = true;
		((Renderer)val2).material = LineMat();
		val2.positionCount = segs + 1;
		Vector3 val3 = to - from;
		Vector3 val4 = Vector3.Cross(((Vector3)(ref val3)).normalized, Vector3.up);
		if (((Vector3)(ref val4)).sqrMagnitude < 0.01f)
		{
			val4 = Vector3.right;
		}
		((Vector3)(ref val4)).Normalize();
		Vector3 val5 = Vector3.Cross(((Vector3)(ref val3)).normalized, val4);
		Vector3 normalized = ((Vector3)(ref val5)).normalized;
		float num = ((Vector3)(ref val3)).magnitude / (float)segs * jag;
		for (int i = 0; i <= segs; i++)
		{
			float num2 = (float)i / (float)segs;
			Vector3 val6 = from + val3 * num2;
			if (i > 0 && i < segs)
			{
				val6 += val4 * Random.Range(0f - num, num) + normalized * Random.Range(0f - num, num);
			}
			val2.SetPosition(i, val6);
		}
		val2.startWidth = width;
		val2.endWidth = width * 0.6f;
		val2.startColor = c;
		val2.endColor = Color.white;
		val.AddComponent<FadeLine>().Setup(0.32f);
	}

	private static Material LineMat()
	{
		//IL_0019: Unknown result type (might be due to invalid IL or missing references)
		//IL_0023: Expected O, but got Unknown
		if ((Object)(object)_line == (Object)null)
		{
			Shader val = Shader.Find("Sprites/Default");
			_line = new Material(val);
			((Object)_line).name = "GodsBoltMat";
		}
		return _line;
	}

	private static Material Additive()
	{
		//IL_0066: Unknown result type (might be due to invalid IL or missing references)
		//IL_0070: Expected O, but got Unknown
		//IL_00bd: Unknown result type (might be due to invalid IL or missing references)
		if ((Object)(object)_additive != (Object)null)
		{
			return _additive;
		}
		Shader val = null;
		string[] array = new string[4] { "Legacy Shaders/Particles/Additive", "Particles/Additive", "Mobile/Particles/Additive", "Sprites/Default" };
		foreach (string text in array)
		{
			val = Shader.Find(text);
			if ((Object)(object)val != (Object)null)
			{
				break;
			}
		}
		_additive = new Material(val);
		((Object)_additive).name = "GodsParticles";
		_additive.mainTexture = (Texture)(object)Soft();
		if (_additive.HasProperty("_TintColor"))
		{
			_additive.SetColor("_TintColor", new Color(0.5f, 0.5f, 0.5f, 0.5f));
		}
		return _additive;
	}

	private static Texture2D Soft()
	{
		//IL_0019: Unknown result type (might be due to invalid IL or missing references)
		//IL_0023: Expected O, but got Unknown
		//IL_00b9: Unknown result type (might be due to invalid IL or missing references)
		//IL_00be: Unknown result type (might be due to invalid IL or missing references)
		if ((Object)(object)_soft != (Object)null)
		{
			return _soft;
		}
		_soft = new Texture2D(64, 64, (TextureFormat)4, false);
		Color32[] array = (Color32[])(object)new Color32[4096];
		for (int i = 0; i < 64; i++)
		{
			for (int j = 0; j < 64; j++)
			{
				float num = ((float)j + 0.5f) / 64f * 2f - 1f;
				float num2 = ((float)i + 0.5f) / 64f * 2f - 1f;
				float num3 = Mathf.Clamp01(1f - Mathf.Sqrt(num * num + num2 * num2));
				num3 *= num3;
				ref Color32 reference = ref array[i * 64 + j];
				reference = new Color32(byte.MaxValue, byte.MaxValue, byte.MaxValue, (byte)(num3 * 255f));
			}
		}
		_soft.SetPixels32(array);
		_soft.Apply();
		((Texture)_soft).wrapMode = (TextureWrapMode)1;
		return _soft;
	}

	public static void Sound(Vector3 pos, AudioClip clip, float volume, float pitch)
	{
		//IL_0020: Unknown result type (might be due to invalid IL or missing references)
		//IL_0026: Expected O, but got Unknown
		//IL_002c: Unknown result type (might be due to invalid IL or missing references)
		if (!((Object)(object)clip == (Object)null) && !(Plugin.EffectsVolume.Value <= 0f))
		{
			GameObject val = new GameObject("GodsSound");
			val.transform.position = pos;
			AudioSource val2 = val.AddComponent<AudioSource>();
			val2.clip = clip;
			val2.volume = volume * Plugin.EffectsVolume.Value;
			val2.pitch = pitch;
			val2.spatialBlend = 1f;
			val2.minDistance = 6f;
			val2.maxDistance = 120f;
			val2.rolloffMode = (AudioRolloffMode)1;
			val2.dopplerLevel = 0f;
			AudioMixerGroup val3 = SfxGroup();
			if ((Object)(object)val3 != (Object)null)
			{
				val2.outputAudioMixerGroup = val3;
			}
			val2.Play();
			Object.Destroy((Object)(object)val, clip.length / Mathf.Max(0.1f, pitch) + 0.2f);
		}
	}

	private static AudioMixerGroup SfxGroup()
	{
		if ((Object)(object)_sfx != (Object)null || _sfxSearched)
		{
			return _sfx;
		}
		_sfxSearched = true;
		try
		{
			AudioSource[] array = Resources.FindObjectsOfTypeAll<AudioSource>();
			foreach (AudioSource val in array)
			{
				AudioMixerGroup outputAudioMixerGroup = val.outputAudioMixerGroup;
				if ((Object)(object)outputAudioMixerGroup != (Object)null && ((Object)outputAudioMixerGroup).name.ToLowerInvariant().Contains("sfx"))
				{
					_sfx = outputAudioMixerGroup;
					break;
				}
			}
			if ((Object)(object)_sfx == (Object)null && (Object)(object)AudioMan.instance != (Object)null)
			{
				_sfx = AudioMan.instance.m_ambientMixer;
			}
		}
		catch
		{
		}
		return _sfx;
	}

	public static AudioClip GodSound(int g)
	{
		if (g < 0 || g >= 5)
		{
			return Chime();
		}
		if ((Object)(object)GodClips[g] != (Object)null)
		{
			return GodClips[g];
		}
		float[] array = g switch
		{
			0 => Horn(), 
			1 => Hammer(), 
			2 => Harp(), 
			3 => Waves(), 
			_ => Laugh(), 
		};
		AudioClip val = AudioClip.Create("GodsVoice_" + GodDefs.Key(g), array.Length, 1, 44100, false);
		val.SetData(array, 0);
		GodClips[g] = val;
		return val;
	}

	private static float[] Horn()
	{
		int num = 132300;
		float[] array = new float[num];
		float[] array2 = new float[2] { 110f, 164.8f };
		float[] array3 = new float[2] { 0f, 0.45f };
		for (int i = 0; i < num; i++)
		{
			float num2 = (float)i / 44100f;
			float num3 = 0f;
			for (int j = 0; j < 2; j++)
			{
				float num4 = num2 - array3[j];
				if (!(num4 < 0f))
				{
					float num5 = Mathf.Clamp01(num4 / 0.3f) * ((num4 < 1.9f) ? 1f : Mathf.Exp((0f - (num4 - 1.9f)) * 3f));
					float num6 = 1f + 0.006f * Mathf.Sin((float)Math.PI * 10f * num4) * Mathf.Clamp01(num4 - 0.4f);
					float num7 = (float)Math.PI * 2f * array2[j] * num6 * num4;
					float num8 = 0f;
					for (int k = 1; k <= 9; k++)
					{
						num8 += Mathf.Sin(num7 * (float)k) / ((float)k * ((k > 3) ? 1.6f : 1f));
					}
					num3 += num8 * num5 * ((j == 0) ? 0.32f : 0.22f);
				}
			}
			array[i] = Mathf.Clamp(num3, -1f, 1f);
		}
		return array;
	}

	private static float[] Hammer()
	{
		int num = 105840;
		float[] array = new float[num];
		float[] array2 = new float[6] { 182f, 433f, 707f, 1121f, 1687f, 2390f };
		float[] array3 = new float[6] { 3.5f, 5f, 7f, 9f, 12f, 16f };
		Random random = new Random(9);
		float num2 = 0f;
		for (int i = 0; i < num; i++)
		{
			float num3 = (float)i / 44100f;
			float num4 = 0f;
			for (int j = 0; j < array2.Length; j++)
			{
				num4 += Mathf.Sin((float)Math.PI * 2f * array2[j] * num3) * Mathf.Exp((0f - num3) * array3[j]) * (0.5f / (float)(j + 1));
			}
			float num5 = (float)(random.NextDouble() * 2.0 - 1.0);
			if (num3 < 0.03f)
			{
				num4 += num5 * (1f - num3 / 0.03f) * 0.8f;
			}
			num2 = Mathf.Clamp(num2 + num5 * 0.02f, -1f, 1f) * 0.997f;
			num4 += num2 * 2f * Mathf.Clamp01((num3 - 0.05f) / 0.1f) * Mathf.Exp((0f - num3) * 1.8f);
			array[i] = Mathf.Clamp(num4 * 0.85f, -1f, 1f);
		}
		return array;
	}

	private static float[] Harp()
	{
		int num = 132300;
		float[] array = new float[num];
		float[] array2 = new float[7] { 392f, 440f, 523.25f, 587.33f, 659.25f, 783.99f, 880f };
		Random random = new Random(3);
		for (int i = 0; i < array2.Length; i++)
		{
			int num2 = (int)(4851f * (float)i);
			int num3 = Math.Max(2, (int)(44100f / array2[i]));
			float[] array3 = new float[num3];
			for (int j = 0; j < num3; j++)
			{
				array3[j] = (float)(random.NextDouble() * 2.0 - 1.0);
			}
			int num4 = 0;
			for (int k = num2; k < num; k++)
			{
				float num5 = array3[num4];
				int num6 = (num4 + 1) % num3;
				array3[num4] = 0.4985f * (array3[num4] + array3[num6]);
				num4 = num6;
				array[k] += num5 * 0.28f;
			}
		}
		for (int l = 0; l < num; l++)
		{
			array[l] = Mathf.Clamp(array[l], -1f, 1f);
		}
		return array;
	}

	private static float[] Waves()
	{
		int num = 141120;
		float[] array = new float[num];
		Random random = new Random(4);
		float num2 = 0f;
		float num3 = 0f;
		for (int i = 0; i < num; i++)
		{
			float num4 = (float)i / 44100f;
			float num5 = Mathf.Max(Mathf.Exp(0f - Mathf.Pow((num4 - 0.9f) / 0.45f, 2f)), 0.8f * Mathf.Exp(0f - Mathf.Pow((num4 - 2.2f) / 0.5f, 2f)));
			float num6 = 0.03f + 0.22f * num5;
			float num7 = (float)(random.NextDouble() * 2.0 - 1.0);
			num2 += (num7 - num2) * num6;
			num3 += (num2 - num3) * num6;
			array[i] = Mathf.Clamp(num3 * 3.2f * (0.15f + num5), -1f, 1f);
		}
		return array;
	}

	private static float[] Laugh()
	{
		int num = 70560;
		float[] array = new float[num];
		float y = 0f;
		float y2 = 0f;
		float y3 = 0f;
		float y4 = 0f;
		float num2 = 0f;
		for (int i = 0; i < num; i++)
		{
			float num3 = (float)i / 44100f;
			int num4 = (int)(num3 / 0.19f);
			float num5 = num3 - (float)num4 * 0.19f;
			float num6 = ((num4 < 7) ? (Mathf.Clamp01(num5 / 0.015f) * Mathf.Clamp01((0.13f - num5) / 0.04f) * (1f - (float)num4 * 0.08f)) : 0f);
			float num7 = 210f + (float)num4 * 14f - num5 * 120f;
			num2 += num7 / 44100f;
			float x = ((num2 % 1f < 0.12f) ? 1f : (-0.14f));
			float num8 = Reso(x, 760f, 90f, ref y, ref y2);
			float num9 = Reso(x, 1180f, 110f, ref y3, ref y4);
			array[i] = Mathf.Clamp((num8 * 0.9f + num9 * 0.6f) * num6 * 0.18f, -1f, 1f);
		}
		return array;
	}

	private static float Reso(float x, float f, float bw, ref float y1, ref float y2)
	{
		float num = Mathf.Exp(-(float)Math.PI * bw / 44100f);
		float num2 = 2f * num * Mathf.Cos((float)Math.PI * 2f * f / 44100f);
		float num3 = (0f - num) * num;
		float num4 = (1f - num) * x + num2 * y1 + num3 * y2;
		y2 = y1;
		y1 = num4;
		return num4;
	}

	public static void Runes(Vector3 pos, Color c, int count, float height)
	{
		//IL_0059: Unknown result type (might be due to invalid IL or missing references)
		//IL_005f: Expected O, but got Unknown
		//IL_0065: Unknown result type (might be due to invalid IL or missing references)
		//IL_0080: Unknown result type (might be due to invalid IL or missing references)
		//IL_009a: 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_00c0: 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_00f0: 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_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)
		//IL_0120: Unknown result type (might be due to invalid IL or missing references)
		//IL_0125: Unknown result type (might be due to invalid IL or missing references)
		//IL_0126: 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_0136: Unknown result type (might be due to invalid IL or missing references)
		//IL_013f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0164: Unknown result type (might be due to invalid IL or missing references)
		//IL_0169: Unknown result type (might be due to invalid IL or missing references)
		//IL_0181: Unknown result type (might be due to invalid IL or missing references)
		//IL_0186: Unknown result type (might be due to invalid IL or missing references)
		//IL_0193: Unknown result type (might be due to invalid IL or missing references)
		//IL_0198: 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)
		//IL_01c0: Unknown result type (might be due to invalid IL or missing references)
		//IL_01de: Unknown result type (might be due to invalid IL or missing references)
		//IL_01f4: Unknown result type (might be due to invalid IL or missing references)
		//IL_020a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0220: Unknown result type (might be due to invalid IL or missing references)
		//IL_0236: Unknown result type (might be due to invalid IL or missing references)
		//IL_024c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0262: Unknown result type (might be due to invalid IL or missing references)
		//IL_026d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0272: Unknown result type (might be due to invalid IL or missing references)
		//IL_0293: Unknown result type (might be due to invalid IL or missing references)
		//IL_02a9: Unknown result type (might be due to invalid IL or missing references)
		//IL_02b4: Unknown result type (might be due to invalid IL or missing references)
		//IL_02b9: Unknown result type (might be due to invalid IL or missing references)
		//IL_02c3: Unknown result type (might be due to invalid IL or missing references)
		//IL_02ca: Expected O, but got Unknown
		//IL_02dc: Unknown result type (might be due to invalid IL or missing references)
		//IL_02e6: Unknown result type (might be due to invalid IL or missing references)
		//IL_02eb: Unknown result type (might be due to invalid IL or missing references)
		//IL_02f8: Unknown result type (might be due to invalid IL or missing references)
		//IL_02fe: Unknown result type (might be due to invalid IL or missing references)
		//IL_0303: 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_0316: Unknown result type (might be due to invalid IL or missing references)
		//IL_031b: Unknown result type (might be due to invalid IL or missing references)
		//IL_033c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0341: Unknown result type (might be due to invalid IL or missing references)
		//IL_0358: Unknown result type (might be due to invalid IL or missing references)
		//IL_035d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0374: Unknown result type (might be due to invalid IL or missing references)
		//IL_0379: Unknown result type (might be due to invalid IL or missing references)
		//IL_0390: Unknown result type (might be due to invalid IL or missing references)
		//IL_0395: 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_0030: Unknown result type (might be due to invalid IL or missing references)
		//IL_003a: Expected O, but got Unknown
		if ((Object)(object)_runeMat == (Object)null)
		{
			Texture2D val = ShrineModel.LoadTexture("runes.png", mips: true, linear: false);
			if ((Object)(object)val == (Object)null)
			{
				return;
			}
			((Texture)val).wrapMode = (TextureWrapMode)1;
			_runeMat = new Material(Additive());
			((Object)_runeMat).name = "GodsRunes";
			_runeMat.mainTexture = (Texture)(object)val;
		}
		GameObject val2 = new GameObject("GodsRunes");
		val2.transform.position = pos;
		val2.transform.rotation = Quaternion.Euler(-90f, 0f, 0f);
		ParticleSystem val3 = val2.AddComponent<ParticleSystem>();
		val3.Stop(true, (ParticleSystemStopBehavior)0);
		MainModule main = val3.main;
		((MainModule)(ref main)).duration = 0.6f;
		((MainModule)(ref main)).loop = false;
		((MainModule)(ref main)).startLifetime = new MinMaxCurve(1.6f, 2.6f);
		((MainModule)(ref main)).startSpeed = new MinMaxCurve(height * 0.35f, height * 0.6f);
		((MainModule)(ref main)).startSize = new MinMaxCurve(0.18f, 0.32f);
		((MainModule)(ref main)).simulationSpace = (ParticleSystemSimulationSpace)1;
		((MainModule)(ref main)).gravityModifier = MinMaxCurve.op_Implicit(0.02f);
		((MainModule)(ref main)).startColor = new MinMaxGradient(Color.Lerp(c, Color.white, 0.35f), c);
		EmissionModule emission = val3.emission;
		((EmissionModule)(ref emission)).rateOverTime = MinMaxCurve.op_Implicit(0f);
		((EmissionModule)(ref emission)).SetBursts((Burst[])(object)new Burst[2]
		{
			new Burst(0f, (short)(count / 2)),
			new Burst(0.3f, (short)(count - count / 2))
		});
		ShapeModule shape = val3.shape;
		((ShapeModule)(ref shape)).shapeType = (ParticleSystemShapeType)4;
		((ShapeModule)(ref shape)).angle = 18f;
		((ShapeModule)(ref shape)).radius = 0.35f;
		VelocityOverLifetimeModule velocityOverLifetime = val3.velocityOverLifetime;
		((VelocityOverLifetimeModule)(ref velocityOverLifetime)).enabled = true;
		((VelocityOverLifetimeModule)(ref velocityOverLifetime)).space = (ParticleSystemSimulationSpace)1;
		((VelocityOverLifetimeModule)(ref velocityOverLifetime)).orbitalY = new MinMaxCurve(0.6f, 1.2f);
		((VelocityOverLifetimeModule)(ref velocityOverLifetime)).x = new MinMaxCurve(0f, 0f);
		((VelocityOverLifetimeModule)(ref velocityOverLifetime)).y = new MinMaxCurve(0f, 0f);
		((VelocityOverLifetimeModule)(ref velocityOverLifetime)).z = new MinMaxCurve(0f, 0f);
		((VelocityOverLifetimeModule)(ref velocityOverLifetime)).orbitalX = new MinMaxCurve(0f, 0f);
		((VelocityOverLifetimeModule)(ref velocityOverLifetime)).orbitalZ = new MinMaxCurve(0f, 0f);
		((VelocityOverLifetimeModule)(ref velocityOverLifetime)).radial = new MinMaxCurve(0.05f, 0.2f);
		TextureSheetAnimationModule textureSheetAnimation = val3.textureSheetAnimation;
		((TextureSheetAnimationModule)(ref textureSheetAnimation)).enabled = true;
		((TextureSheetAnimationModule)(ref textureSheetAnimation)).numTilesX = 4;
		((TextureSheetAnimationModule)(ref textureSheetAnimation)).numTilesY = 4;
		((TextureSheetAnimationModule)(ref textureSheetAnimation)).frameOverTime = new MinMaxCurve(0f);
		((TextureSheetAnimationModule)(ref textureSheetAnimation)).startFrame = new MinMaxCurve(0f, 15.99f);
		ColorOverLifetimeModule colorOverLifetime = val3.colorOverLifetime;
		((ColorOverLifetimeModule)(ref colorOverLifetime)).enabled = true;
		Gradient val4 = new Gradient();
		val4.SetKeys((GradientColorKey[])(object)new GradientColorKey[3]
		{
			new Gradien