Decompiled source of VikingMushrooms v1.0.0

BepInEx/plugins/VikingMushrooms/VikingMushrooms.dll

Decompiled 3 weeks ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security.Cryptography;
using System.Text;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using SoftReferenceableAssets;
using TMPro;
using UnityEngine;
using UnityEngine.Animations;
using UnityEngine.Audio;
using UnityEngine.Playables;
using UnityEngine.Rendering;
using UnityEngine.SceneManagement;
using UnityEngine.UI;
using VikingMushrooms.Model;
using VikingMushrooms.Systems;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("VikingMushrooms")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("VikingMushrooms")]
[assembly: AssemblyTitle("VikingMushrooms")]
[assembly: AssemblyVersion("1.0.0.0")]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[Embedded]
	[AttributeUsage(AttributeTargets.Module, AllowMultiple = false, Inherited = false)]
	internal sealed class RefSafetyRulesAttribute : Attribute
	{
		public readonly int Version;

		public RefSafetyRulesAttribute(int P_0)
		{
			Version = P_0;
		}
	}
}
namespace VikingMushrooms
{
	internal static class ModConfig
	{
		private static readonly Dictionary<string, ConfigEntryBase> Entries = new Dictionary<string, ConfigEntryBase>();

		private static ConfigFile File;

		internal static bool B(string key)
		{
			return ((ConfigEntry<bool>)(object)Entries[key]).Value;
		}

		internal static float F(string key)
		{
			float value = ((ConfigEntry<float>)(object)Entries[key]).Value;
			if (!float.IsNaN(value) && !float.IsInfinity(value))
			{
				return value;
			}
			return (float)Entries[key].DefaultValue;
		}

		internal static string S(string key)
		{
			return ((ConfigEntry<string>)(object)Entries[key]).Value;
		}

		internal static void Set(string key, string value)
		{
			((ConfigEntry<string>)(object)Entries[key]).Value = value;
		}

		private static void Bind<T>(string key, T value, string description = "")
		{
			int num = key.IndexOf('.');
			Entries[key] = (ConfigEntryBase)(object)File.Bind<T>(key.Substring(0, num), key.Substring(num + 1), value, description);
		}

		private static void Number(string key, float value, float min = 0f, float max = 10000f)
		{
			//IL_0037: Unknown result type (might be due to invalid IL or missing references)
			//IL_0041: Expected O, but got Unknown
			int num = key.IndexOf('.');
			Entries[key] = (ConfigEntryBase)(object)File.Bind<float>(key.Substring(0, num), key.Substring(num + 1), value, new ConfigDescription("See docs/CONFIG_SPEC.md. Changes apply locally; use matching gameplay settings on all clients.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(min, max), Array.Empty<object>()));
		}

		internal static void Bind(ConfigFile config)
		{
			File = config;
			VisualFxLab.BindSettings(Number);
			Bind("General.Enabled", value: true);
			Bind("General.DebugLogging", value: false);
			Bind("General.EnableFxLab", value: false, "Enable the optional F8 visual testing panel. Only released trances are available.");
			Bind("General.AllowTranceReplacement", value: true);
			Bind("General.Language", "es", "HUD language: es or en.");
			Bind("CookedFood.Enabled", value: true, "Enable 75%-potency trances from cooked mushroom foods. Disabling ends active cooked-food trances; raw mushrooms are unaffected. Outstanding blood debt is preserved. Re-enabling requires eating again.");
			Bind("Items.LogUnmappedMushroomLikeItems", value: true);
			string[] array = new string[6] { "RedMushroom", "YellowMushroom", "Magecap", "JotunPuff", "SmokePuff", "Toadstool" };
			foreach (string text in array)
			{
				Bind("Items." + text + "Prefab", "", "Exact ObjectDB prefab ID. Empty: use the asset-manifest candidate, then validate against ObjectDB. Unknown candidates are never mapped.");
			}
			Bind("Berserker.RequireNoMetalChest", value: true);
			Bind("Berserker.RequireRestrictionThroughoutTrance", value: true);
			Bind("Berserker.BlockedChestPrefabs", "ArmorBronzeChest,ArmorIronChest,ArmorWolfChest,ArmorPaddedCuirass,ArmorCarapaceChest,ArmorFlametalChest", "Comma-separated exact chest prefab IDs, verified in the installed asset manifest. Add custom or new metal armor explicitly; no guessed isMetal flag.");
			Number("Berserker.HealthFloor", 1f, 0.1f, 10f);
			Number("Berserker.DebtMaxHealthFactor", 1f, 0.01f, 10f);
			Number("Berserker.MaxMeleeDamageBonus", 0.5f, 0f, 5f);
			Number("Berserker.MaxAttackSpeedBonus", 0.3f, 0f, 2f);
			Number("Berserker.MaxMoveSpeedBonus", 0.1f, 0f, 2f);
			Number("Berserker.MaxStaggerResistanceBonus", 0.75f, 0f, 1f);
			Number("Berserker.HealingDebtEfficiency", 0.5f, 0f, 1f);
			Number("Berserker.LastBreathSeconds", 5f, 0.1f, 60f);
			Number("HelVision.Range", 22f, 1f, 100f);
			Bind("HelVision.LoadedEnemyAuras", value: true, "Reveal already loaded enemies beyond the fixed pulse radius.");
			Number("HelVision.MaxMarkedEnemies", 64f, 12f, 128f);
			Number("HelVision.PulseInterval", 2f, 0.2f, 60f);
			Number("HelVision.HighlightSeconds", 0.8f, 0.1f, 5f);
			Bind("HelVision.RequireLineOfSight", value: false);
			Number("HelVision.PhantomRatePerMinute", 8f, 0f, 60f);
			Bind("EitrOverload.CapacityMode", "MaxOf100OrMaxEitr", "Fixed or MaxOf100OrMaxEitr.");
			Number("EitrOverload.FixedCapacity", 100f, 1f);
			Bind("EitrVisual.CreatureAuras", value: true);
			Number("EitrVisual.MaxAuraCreatures", 10f, 1f, 16f);
			Number("Audio.EitrEchoWetMix", 0.08f, 0f, 0.2f);
			Number("EitrVisual.MinClusters", 2f, 1f, 6f);
			Number("EitrVisual.MaxClusters", 4f, 1f, 6f);
			Number("EitrVisual.MinMembers", 2f, 1f, 8f);
			Number("EitrVisual.MaxMembers", 7f, 1f, 8f);
			Number("EitrVisual.MaxRunes", 12f, 0f, 18f);
			Number("EitrVisual.MaxFractures", 6f, 0f, 10f);
			Number("EitrVisual.MaxAnimals", 2f, 0f, 3f);
			Number("EitrVisual.MaxRootIllusions", 3f, 0f, 4f);
			Number("EitrVisual.ViewDistance", 45f, 20f, 65f);
			Number("EitrOverload.ChargePerEitr", 1f, 0f, 10f);
			Number("EitrOverload.MagicBonusPerQuarter", 0.05f, 0f, 1f);
			Number("EitrOverload.FullChargeMagicBonus", 0.5f, 0f, 0.5f);
			Number("EitrOverload.RuptureChance", 0.25f, 0f, 1f);
			Number("EitrOverload.RuptureRegenLockSeconds", 2f, 0f, 30f);
			Bind("EitrOverload.EnableExtraProjectile", value: true);
			Number("EitrOverload.MaxCastSpeedBonus", 0.2f, 0f, 2f);
			Number("EitrOverload.MaxEitrRegenBonus", 0.3f, 0f, 5f);
			Bind("Jotunn.Enabled", value: true, "Experimental Jotunn Blood; numeric defaults are provisional tuning values.");
			Number("Jotunn.AuraExtraHeads", 4f, 0f, 4f);
			Number("Jotunn.TiltShiftBlurPixels", 12f, 0f, 24f);
			Number("Jotunn.TiltShiftFocusBand", 0.16f, 0.08f, 0.35f);
			Number("Jotunn.CameraHeightOffset", 0.65f, 0f, 1.2f);
			Number("Jotunn.MovementSpeedMultiplier", 1.2f, 1f, 1.3f);
			Number("Jotunn.JumpVelocityMultiplier", 1.2f, 1f, 1.4f);
			Number("Jotunn.MomentumWalkGain", 4f, 0f, 50f);
			Number("Jotunn.MomentumRunGain", 14f, 0f, 80f);
			Number("Jotunn.HeavyPushMultiplier", 1.8f, 1f, 3f);
			Number("Jotunn.MaxPushSpeed", 60f, 1f, 100f);
			Number("Jotunn.BossMaxPushSpeed", 3f, 0f, 8f);
			Number("Jotunn.HallucinationInterval", 40f, 15f, 300f);
			Number("Jotunn.MaxLocalHallucinations", 2f, 0f, 3f);
			Number("Jotunn.GiantVisionInterval", 240f, 120f, 1200f);
			Number("Jotunn.GiantImpactVolumeMultiplier", 3f, 0f, 4f);
			Number("Jotunn.CoastalVisionRange", 100f, 30f, 160f);
			Number("Jotunn.MomentumMax", 100f, 1f);
			Number("Jotunn.MomentumDecayDelay", 0.75f);
			Number("Jotunn.MomentumDecayPerSecond", 12f);
			Number("Jotunn.MaxBonusPush", 6f, 0f, 10f);
			Number("Jotunn.MaxBonusStagger", 4f, 0f, 10f);
			Number("Jotunn.FallDamageReduction", 0.6f, 0f, 1f);
			Number("Jotunn.KnockbackResistance", 0.75f, 0f, 1f);
			Number("Jotunn.StaggerResistance", 0.5f, 0f, 1f);
			Bind("AshBody.Enabled", value: true, "Enable Smoke Puff / Ash Body. Initial tuning values are configurable; presentation is local.");
			Number("AshBody.DensityMax", 100f, 1f);
			Number("Hud.DensityWidth", 280f, 160f, 600f);
			Number("Hud.DensityBottomOffset", 160f, 40f, 600f);
			Number("AshBody.RegenDelay", 4f);
			Number("AshBody.RegenPerSecond", 12f);
			Number("AshBody.AshFormVisualIntensity", 1f, 0f, 2f);
			Number("AshBody.BodyTransparency", 0.45f, 0f, 0.9f);
			Number("AshBody.SmokeIntensity", 1f, 0f, 2f);
			Number("AshBody.WorldHallucinationIntensity", 1f, 0f, 2f);
			Number("AshBody.AshlandsEnvironmentIntensity", 0.8f, 0f, 1f);
			Number("AshBody.WaterLavaIntensity", 0.9f, 0f, 1f);
			Number("AshBody.SurtlingInterval", 18f, 3f, 300f);
			Number("AshBody.MaxSurtlingHallucinations", 2f, 0f, 4f);
			Number("AshBody.SurtlingMinDistance", 22f, 12f, 80f);
			Number("AshBody.SurtlingMaxDistance", 48f, 15f, 120f);
			Number("AshBody.CorpseInterval", 3f, 1f, 300f);
			Number("AshBody.MaxCorpseHallucinations", 10f, 0f, 16f);
			Number("AshBody.CharredStoneInterval", 35f, 5f, 600f);
			Number("AshBody.MaxCharredStoneHallucinations", 2f, 0f, 3f);
			Number("AshBody.HeatDistortionIntensity", 0.55f, 0f, 2f);
			Number("AshBody.AudioVolume", 0.45f, 0f, 1f);
			Bind("Visual.PreferValheimAssets", value: true, "Read native particle materials and audio clips at runtime; never clone gameplay prefabs.");
			Number("Audio.Volume", 0.25f, 0f, 1f);
			Number("Visual.HallucinationIntensity", 1f, 0f, 1f);
			Number("Visual.DistortionGain", 4f, 0f, 8f);
			Bind("Visual.EnablePostProcessing", value: true, "Local fullscreen shader for Delirium prototype. Does not modify shared postprocessing profiles.");
			Bind("Visual.EnablePhantomSilhouettes", value: true);
			Bind("Visual.EnablePhantomAudio", value: true);
			Bind("Visual.EnableFOVEffects", value: true);
			Bind("Visual.EnableCameraShake", value: true);
			Bind("Visual.EnableCameraSway", value: true);
			Bind("Visual.EnableCameraRoll", value: true);
			Bind("Visual.EnableScreenDistortion", value: true);
			Bind("Visual.EnableColorGrading", value: true);
			Bind("Visual.EnableGammaShift", value: true);
			Bind("Visual.EnableAfterimages", value: true);
			Bind("Visual.EnableDoubleVision", value: true);
			Bind("Hud.ShowTranceStatus", value: true);
			Bind("Hud.ShowResourceMeters", value: true);
			Bind("Visual.EnableChromaticEffects", value: true, "RGB separation in the Delirium fullscreen shader.");
			Number("Visual.MaxLocalPhantoms", 6f, 0f, 20f);
			Number("Hud.Scale", 1f, 0.5f, 2f);
			Bind("Hud.Enabled", value: true);
			Number("Hud.DebtBarGap", 10f, 0f, 200f);
			Bind("Hud.DebtAvoidOverlap", value: true, "Keep the debt bar above health, avoiding existing stamina/eitr/adrenaline bars. Does not move vanilla bars.");
		}
	}
	[BepInPlugin("TheLionCid.VikingMushrooms", "Viking mushrooms", "1.0.0")]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	public sealed class Plugin : BaseUnityPlugin
	{
		public const string PluginGuid = "TheLionCid.VikingMushrooms";

		public const string PluginName = "Viking mushrooms";

		public const string PluginVersion = "1.0.0";

		internal static ManualLogSource Log;

		private Harmony harmony;

		private void Awake()
		{
			//IL_0016: Unknown result type (might be due to invalid IL or missing references)
			//IL_001b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0067: Unknown result type (might be due to invalid IL or missing references)
			//IL_0071: Expected O, but got Unknown
			//IL_003f: 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)
			Log = ((BaseUnityPlugin)this).Logger;
			ModConfig.Bind(((BaseUnityPlugin)this).Config);
			if (((object)Version.CurrentVersion/*cast due to .constrained prefix*/).ToString() != "1.0.20")
			{
				Log.LogWarning((object)("Valheim version " + ((object)Version.CurrentVersion/*cast due to .constrained prefix*/).ToString() + " differs from the reference version 1.0.20. Continuing with Harmony patch validation; compatibility with this version is not yet confirmed in-game."));
			}
			harmony = new Harmony("TheLionCid.VikingMushrooms");
			try
			{
				harmony.PatchAll(typeof(Plugin).Assembly);
			}
			catch (Exception ex)
			{
				harmony.UnpatchSelf();
				((Behaviour)this).enabled = false;
				Log.LogError((object)("Patch installation failed; rolled back: " + ex));
				return;
			}
			PrefabRegistry.Resolve(ObjectDB.instance);
			Log.LogInfo((object)"Viking mushrooms 1.0.0 loaded. Owner-authoritative gameplay; client-local presentation.");
		}

		private void Update()
		{
			DeliriumArrival.Tick();
			MushroomEffectManager.Tick(Time.deltaTime);
			VisualFxLab.Tick();
		}

		private void LateUpdate()
		{
			DeliriumAudioEnvironment.LateTick();
			BloodDebtHud.Tick();
			TranceStatusHud.Tick();
			SecondaryResourceHud.Tick();
			BerserkPresentation.LateTick();
			HelPresentation.LateTick();
			EitrAuras.LateTick();
			DeliriumWorldDirector.LateTick();
			JotunnPresentation.LateTick();
		}

		private void OnGUI()
		{
			HudSystem.Draw();
			VisualFxLab.Draw();
		}

		private void OnDisable()
		{
			MushroomEffectManager.Clear();
			JotunnCamera.Clear();
			HallucinationSystem.Clear();
			VisualFxLab.Clear();
			TranceStatusHud.Clear();
			SecondaryResourceHud.Clear();
			BloodDebtHud.Clear();
		}

		private void OnDestroy()
		{
			MushroomEffectManager.Clear();
			BloodDebtHud.Clear();
			Harmony obj = harmony;
			if (obj != null)
			{
				obj.UnpatchSelf();
			}
		}
	}
}
namespace VikingMushrooms.Systems
{
	internal sealed class AshAudioEnvironment
	{
		private readonly Dictionary<AudioSource, bool> Muted = new Dictionary<AudioSource, bool>();

		private readonly List<AudioClip> Clips = new List<AudioClip>();

		private GameObject Root;

		private AudioSource Ambient;

		private AudioSource Lava;

		private AudioSource Event;

		private AudioSource Ocean;

		private AudioMan Manager;

		private float NextEvent;

		private float NextScan;

		private bool LavaEvent;

		private AudioSource Source(string name, bool loop, float spatial)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			AudioSource obj = new GameObject(name).AddComponent<AudioSource>();
			((Component)obj).transform.SetParent(Root.transform, false);
			obj.playOnAwake = false;
			obj.loop = loop;
			obj.spatialBlend = spatial;
			obj.dopplerLevel = 0f;
			obj.minDistance = 8f;
			obj.maxDistance = 70f;
			obj.outputAudioMixerGroup = Manager.m_ambientMixer;
			obj.volume = 0f;
			return obj;
		}

		private void Mute(AudioSource source)
		{
			if (Object.op_Implicit((Object)(object)source))
			{
				if (!Muted.ContainsKey(source))
				{
					Muted.Add(source, source.mute);
				}
				source.mute = true;
			}
		}

		private void Unmute(AudioSource source)
		{
			if (Object.op_Implicit((Object)(object)source) && Muted.TryGetValue(source, out var value))
			{
				source.mute = value;
				Muted.Remove(source);
			}
		}

		private void Restore()
		{
			foreach (KeyValuePair<AudioSource, bool> item in Muted)
			{
				if (Object.op_Implicit((Object)(object)item.Key))
				{
					item.Key.mute = item.Value;
				}
			}
			Muted.Clear();
		}

		private void Ensure(Transform parent, EnvSetup env)
		{
			//IL_0045: Unknown result type (might be due to invalid IL or missing references)
			//IL_004f: Expected O, but got Unknown
			if (Object.op_Implicit((Object)(object)Root) && (Object)(object)Manager == (Object)(object)AudioMan.instance)
			{
				return;
			}
			Dispose();
			Manager = AudioMan.instance;
			if (!Object.op_Implicit((Object)(object)Manager))
			{
				return;
			}
			Root = new GameObject("VM.Ash.Soundscape");
			Root.transform.SetParent(parent, false);
			Ambient = Source("VM.Ash.Ambient", loop: true, 0f);
			Ambient.clip = env.m_ambientLoop;
			Lava = Source("VM.Ash.LavaLoop", loop: true, 0.75f);
			Lava.minDistance = 40f;
			Lava.maxDistance = 128f;
			Lava.rolloffMode = (AudioRolloffMode)1;
			GameObject lavaLoopPrefab = Manager.m_lavaLoopPrefab;
			if (Object.op_Implicit((Object)(object)lavaLoopPrefab))
			{
				ZSFX[] componentsInChildren = lavaLoopPrefab.GetComponentsInChildren<ZSFX>(true);
				foreach (ZSFX val in componentsInChildren)
				{
					if (val.m_audioClips != null && val.m_audioClips.Length != 0)
					{
						Lava.clip = val.m_audioClips[0];
						break;
					}
				}
				if (!Object.op_Implicit((Object)(object)Lava.clip))
				{
					AudioSource componentInChildren = lavaLoopPrefab.GetComponentInChildren<AudioSource>(true);
					if (Object.op_Implicit((Object)(object)componentInChildren))
					{
						Lava.clip = componentInChildren.clip;
					}
				}
			}
			Event = Source("VM.Ash.AmbientEvent", loop: false, 1f);
			NextEvent = Time.time + 3f;
			NextScan = 0f;
			Plugin.Log.LogInfo((object)("Ash soundscape: environment=" + (Object.op_Implicit((Object)(object)Ambient.clip) ? ((Object)Ambient.clip).name : "unavailable") + "; native lava=" + (Object.op_Implicit((Object)(object)Lava.clip) ? ((Object)Lava.clip).name : "unavailable")));
		}

		internal void Tick(Player player, Transform parent, EnvSetup env, float intensity)
		{
			//IL_0257: Unknown result type (might be due to invalid IL or missing references)
			//IL_0245: Unknown result type (might be due to invalid IL or missing references)
			//IL_043a: Unknown result type (might be due to invalid IL or missing references)
			//IL_043f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0443: Unknown result type (might be due to invalid IL or missing references)
			//IL_0451: Unknown result type (might be due to invalid IL or missing references)
			//IL_0456: Unknown result type (might be due to invalid IL or missing references)
			//IL_0468: Unknown result type (might be due to invalid IL or missing references)
			//IL_046d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0478: Unknown result type (might be due to invalid IL or missing references)
			//IL_047e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0483: Unknown result type (might be due to invalid IL or missing references)
			//IL_0360: Unknown result type (might be due to invalid IL or missing references)
			//IL_0367: Unknown result type (might be due to invalid IL or missing references)
			if (!ModConfig.B("Visual.EnablePhantomAudio") || ModConfig.F("Audio.Volume") <= 0f || ModConfig.F("AshBody.AudioVolume") <= 0f || intensity <= 0f)
			{
				Restore();
				if (Object.op_Implicit((Object)(object)Ambient))
				{
					Ambient.Stop();
				}
				if (Object.op_Implicit((Object)(object)Lava))
				{
					Lava.Stop();
				}
				if (Object.op_Implicit((Object)(object)Event))
				{
					Event.Stop();
				}
				return;
			}
			Ensure(parent, env);
			if (!Object.op_Implicit((Object)(object)Root))
			{
				return;
			}
			float num = ModConfig.F("Audio.Volume") * ModConfig.F("AshBody.AudioVolume") * Mathf.Clamp01(intensity);
			if (Time.time >= NextScan)
			{
				NextScan = Time.time + 1f;
				Transform val = ((Component)Manager).transform.Find("ocean_ambient_loop");
				Ocean = (Object.op_Implicit((Object)(object)val) ? ((Component)val).GetComponent<AudioSource>() : null);
				if (Object.op_Implicit((Object)(object)Ambient.clip))
				{
					Transform val2 = ((Component)Manager).transform.Find("ambient_loop");
					if (Object.op_Implicit((Object)(object)val2))
					{
						Mute(((Component)val2).GetComponent<AudioSource>());
					}
				}
			}
			bool flag = ModConfig.F("AshBody.WaterLavaIntensity") > 0f && !((Character)player).InInterior();
			if (Object.op_Implicit((Object)(object)Lava.clip) && flag)
			{
				Mute(Ocean);
			}
			else
			{
				Unmute(Ocean);
			}
			if (Object.op_Implicit((Object)(object)Ambient.clip))
			{
				Ambient.volume = Mathf.MoveTowards(Ambient.volume, num * Mathf.Clamp01(env.m_ambientVol), Time.deltaTime * 0.3f);
				if (!Ambient.isPlaying)
				{
					Ambient.Play();
				}
			}
			float num2 = ((Object.op_Implicit((Object)(object)Ocean) && flag) ? Ocean.volume : 0f);
			if (Object.op_Implicit((Object)(object)Lava.clip))
			{
				((Component)Lava).transform.position = (Object.op_Implicit((Object)(object)Ocean) ? ((Component)Ocean).transform.position : ((Component)player).transform.position);
				Lava.volume = Mathf.MoveTowards(Lava.volume, num * num2, Time.deltaTime * 0.35f);
				if (!Lava.isPlaying)
				{
					Lava.Play();
				}
			}
			Event.volume = num * 0.7f;
			if (Time.time < NextEvent || Event.isPlaying)
			{
				return;
			}
			NextEvent = Time.time + (float)Random.Range(8, 16);
			Clips.Clear();
			LavaEvent = !LavaEvent;
			if (LavaEvent && num2 > 0.01f && Manager.m_randomLavaNoises != null)
			{
				Clips.AddRange(Manager.m_randomLavaNoises);
			}
			if (Clips.Count == 0)
			{
				foreach (BiomeAmbients randomAmbient in Manager.m_randomAmbients)
				{
					if ((randomAmbient.m_biome & 0x20) != 0 || (!string.IsNullOrEmpty(env.m_ambientList) && randomAmbient.m_name == env.m_ambientList))
					{
						Clips.AddRange(randomAmbient.m_randomAmbientClips);
						Clips.AddRange(EnvMan.IsDaylight() ? randomAmbient.m_randomAmbientClipsDay : randomAmbient.m_randomAmbientClipsNight);
						break;
					}
				}
			}
			Clips.RemoveAll((AudioClip c) => !Object.op_Implicit((Object)(object)c));
			if (Clips.Count != 0)
			{
				Event.clip = Clips[Random.Range(0, Clips.Count)];
				Vector2 insideUnitCircle = Random.insideUnitCircle;
				Vector2 val3 = ((Vector2)(ref insideUnitCircle)).normalized * (float)Random.Range(6, 15);
				((Component)Event).transform.position = ((Component)player).transform.position + new Vector3(val3.x, 1f, val3.y);
				Event.Play();
			}
		}

		internal void Dispose()
		{
			Restore();
			if (Object.op_Implicit((Object)(object)Root))
			{
				Root.SetActive(false);
				Object.Destroy((Object)(object)Root);
			}
			Root = null;
			Ambient = (Lava = (Event = (Ocean = null)));
			Manager = null;
			Clips.Clear();
		}
	}
	internal static class AshBodySystem
	{
		internal static bool Dodging
		{
			get
			{
				if (Object.op_Implicit((Object)(object)MushroomEffectManager.Owner))
				{
					return ((Character)MushroomEffectManager.Owner).InDodge();
				}
				return false;
			}
		}

		internal static float Ratio(PlayerTranceState s)
		{
			return AshMath.EffectiveRatio(s.Density, ModConfig.F("AshBody.DensityMax"), Dodging);
		}

		internal static bool Regenerating(PlayerTranceState s)
		{
			if (!Dodging && s.Density < ModConfig.F("AshBody.DensityMax"))
			{
				return Time.time - s.LastDamage >= ModConfig.F("AshBody.RegenDelay") * s.Potency;
			}
			return false;
		}

		internal static bool AvoidAttack(PlayerTranceState s)
		{
			s.LastDamage = Time.time;
			return AshMath.AvoidAttack(ref s.Density, ModConfig.F("AshBody.DensityMax"), s.Potency, Dodging, Random.value);
		}

		internal static void Tick(PlayerTranceState s, float dt)
		{
			if (!Dodging)
			{
				s.Density = AshMath.Regenerate(s.Density, ModConfig.F("AshBody.DensityMax"), Time.time - s.LastDamage, ModConfig.F("AshBody.RegenDelay"), ModConfig.F("AshBody.RegenPerSecond"), dt, s.Potency);
			}
		}
	}
	public static class AshMath
	{
		private static float Finite(float v)
		{
			if (!float.IsNaN(v) && !float.IsInfinity(v))
			{
				return v;
			}
			return 0f;
		}

		public static float Ratio(float density, float max)
		{
			if (!(max > 0f))
			{
				return 0f;
			}
			return Math.Max(0f, Math.Min(1f, Finite(density) / max));
		}

		public static float AvoidChance(float density, float max, float potency)
		{
			float num = Ratio(density, max);
			if (num <= 0f)
			{
				return 0f;
			}
			int num2 = (int)Math.Floor((1f - num) * 5f + 1E-06f);
			return (1f - (float)num2 * 0.2f) * Math.Max(0f, Math.Min(1f, Finite(potency)));
		}

		public static float EffectiveRatio(float density, float max, bool dodging)
		{
			if (!dodging)
			{
				return Ratio(density, max);
			}
			return 1f;
		}

		public static bool AvoidAttack(ref float density, float max, float potency, bool dodging, float roll)
		{
			if (dodging)
			{
				return true;
			}
			float num = AvoidChance(density, max, potency);
			density = Math.Max(0f, Math.Min(Math.Max(0f, Finite(max)), Finite(density)) - Math.Max(0f, Finite(max)) * 0.1f * Math.Max(0f, Math.Min(1f, Finite(potency))));
			if (!(num >= 1f))
			{
				if (num > 0f)
				{
					return Math.Max(0f, Math.Min(1f, Finite(roll))) < num;
				}
				return false;
			}
			return true;
		}

		public static float Regenerate(float density, float max, float sinceDamage, float delay, float rate, float dt, float potency)
		{
			max = Math.Max(0f, Finite(max));
			potency = Math.Max(0f, Math.Min(1f, Finite(potency)));
			density = Math.Max(0f, Math.Min(Math.Max(0f, Finite(max)), Finite(density)));
			if (sinceDamage < Math.Max(0f, delay) * potency)
			{
				return density;
			}
			return Math.Min(max, density + Math.Max(0f, Finite(rate)) * potency * Math.Max(0f, Math.Min(1f, Finite(dt))));
		}

		public static float WorldPresence(float ratio)
		{
			return 0.65f + 0.35f * Math.Max(0f, Math.Min(1f, Finite(ratio)));
		}
	}
	internal sealed class AshNativeLava
	{
		private Camera Camera;

		private CommandBuffer Buffer;

		private Material Material;

		private Texture2D Mask;

		private Mesh Mesh;

		private readonly List<(Renderer renderer, bool hidden)> Hidden = new List<(Renderer, bool)>();

		private bool Failed;

		private float[] ShapeFade;

		private Vector3[] BaseVertices;

		private Vector3[] Deformed;

		private Vector3[] Normals;

		private Vector4[] Tangents;

		private float NextShape;

		private Vector3 LastOrigin;

		private bool Ensure(Camera camera)
		{
			//IL_00b6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bb: 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_00d3: Expected O, but got Unknown
			//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_00e9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fc: Expected O, but got Unknown
			//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_012d: Unknown result type (might be due to invalid IL or missing references)
			//IL_012e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0135: 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_013d: 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_0267: Unknown result type (might be due to invalid IL or missing references)
			//IL_026c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0285: Unknown result type (might be due to invalid IL or missing references)
			//IL_0291: Unknown result type (might be due to invalid IL or missing references)
			//IL_02c2: Unknown result type (might be due to invalid IL or missing references)
			//IL_02c4: Unknown result type (might be due to invalid IL or missing references)
			//IL_02d1: Unknown result type (might be due to invalid IL or missing references)
			//IL_02d6: Unknown result type (might be due to invalid IL or missing references)
			//IL_02f7: Unknown result type (might be due to invalid IL or missing references)
			//IL_02fc: Unknown result type (might be due to invalid IL or missing references)
			//IL_031c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0330: Unknown result type (might be due to invalid IL or missing references)
			//IL_0335: Unknown result type (might be due to invalid IL or missing references)
			//IL_0347: Unknown result type (might be due to invalid IL or missing references)
			//IL_034c: Unknown result type (might be due to invalid IL or missing references)
			//IL_035c: Expected O, but got Unknown
			if (Failed)
			{
				return false;
			}
			if (Object.op_Implicit((Object)(object)Material) && Object.op_Implicit((Object)(object)Mesh) && Buffer != null)
			{
				return true;
			}
			Material val = null;
			foreach (Heightmap allHeightmap in Heightmap.GetAllHeightmaps())
			{
				if (Object.op_Implicit((Object)(object)allHeightmap) && Object.op_Implicit((Object)(object)allHeightmap.m_material))
				{
					val = allHeightmap.m_material;
					break;
				}
			}
			if (!Object.op_Implicit((Object)(object)val))
			{
				return false;
			}
			if (!val.HasProperty("_ClearedMaskTex") || !val.HasProperty("_DiffuseArrayTex") || !Object.op_Implicit((Object)(object)val.GetTexture("_DiffuseArrayTex")))
			{
				return false;
			}
			Material = new Material(val)
			{
				name = "VM.Ash.NativeHeightmapLava",
				hideFlags = (HideFlags)61
			};
			Mask = new Texture2D(2, 2, (TextureFormat)4, false, true)
			{
				name = "VM.Ash.LavaMask",
				wrapMode = (TextureWrapMode)1,
				filterMode = (FilterMode)0
			};
			Color val2 = default(Color);
			((Color)(ref val2))..ctor(0f, 0f, 0f, 1f);
			Mask.SetPixels((Color[])(object)new Color[4] { val2, val2, val2, val2 });
			Mask.Apply(false, true);
			Material.SetTexture("_ClearedMaskTex", (Texture)(object)Mask);
			Material.SetFloat("_IsDistantLod", 0f);
			Material.DisableKeyword("_ISDISTANTLOD_ON");
			Material.SetFloat("_WaterLevel", -10000f);
			Material.SetFloat("_LodHideDistance", 100000f);
			Material.SetFloat("_LodHideModifier", 0f);
			Material.SetFloat("_LodMod", 0f);
			Mesh = BuildMesh();
			Mesh.MarkDynamic();
			BaseVertices = Mesh.vertices;
			Deformed = (Vector3[])(object)new Vector3[BaseVertices.Length];
			Normals = (Vector3[])(object)new Vector3[BaseVertices.Length];
			Tangents = (Vector4[])(object)new Vector4[BaseVertices.Length];
			ShapeFade = new float[BaseVertices.Length];
			for (int i = 0; i < BaseVertices.Length; i++)
			{
				Vector3 val3 = BaseVertices[i];
				ShapeFade[i] = 1f - Mathf.SmoothStep(0f, 1f, Mathf.Clamp01((Mathf.Max(Mathf.Abs(val3.x), Mathf.Abs(val3.z)) - 100f) / 400f));
				Deformed[i] = val3;
				Normals[i] = Vector3.up;
				Tangents[i] = new Vector4(1f, 0f, 0f, -1f);
			}
			Mesh.bounds = new Bounds(Vector3.zero, new Vector3(8192f, 4f, 8192f));
			Camera = camera;
			Buffer = new CommandBuffer
			{
				name = "VM.Ash.VanillaLava"
			};
			Camera.AddCommandBuffer((CameraEvent)16, Buffer);
			Plugin.Log.LogInfo((object)("Ash lava: native " + ((Object)val.shader).name + " with Ashlands vertex colours and lava mask; no cloned game textures."));
			return true;
		}

		private static Mesh BuildMesh()
		{
			//IL_0034: 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_026f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0274: Unknown result type (might be due to invalid IL or missing references)
			//IL_027f: Unknown result type (might be due to invalid IL or missing references)
			//IL_028b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0298: Unknown result type (might be due to invalid IL or missing references)
			//IL_02a4: Unknown result type (might be due to invalid IL or missing references)
			//IL_02b1: Unknown result type (might be due to invalid IL or missing references)
			//IL_02b7: Unknown result type (might be due to invalid IL or missing references)
			//IL_02bd: Unknown result type (might be due to invalid IL or missing references)
			//IL_02c4: Expected O, but got Unknown
			List<Vector3> vertices = new List<Vector3>();
			List<Vector2> uv = new List<Vector2>();
			List<Color32> colors = new List<Color32>();
			List<int> indices = new List<int>();
			Color32 ash = Heightmap.GetBiomeColor((Biome)32);
			for (int i = 0; i <= 128; i++)
			{
				for (int j = 0; j <= 128; j++)
				{
					Add(-128f + (float)(j * 2), -128f + (float)(i * 2));
				}
			}
			for (int k = 0; k < 128; k++)
			{
				for (int l = 0; l < 128; l++)
				{
					int num = k * 129 + l;
					Quad(num, num + 1, num + 128 + 1, num + 128 + 2);
				}
			}
			int[] array = new int[512];
			for (int m = 0; m < 128; m++)
			{
				array[m] = m;
				array[128 + m] = m * 129 + 128;
				array[256 + m] = 16640 - m;
				array[384 + m] = (128 - m) * 129;
			}
			float[] array2 = new float[5] { 256f, 512f, 1024f, 2048f, 4096f };
			foreach (float num2 in array2)
			{
				int[] array3 = new int[512];
				for (int num3 = 0; num3 < 4; num3++)
				{
					for (int num4 = 0; num4 < 128; num4++)
					{
						float num5 = (float)num4 / 128f;
						int num6 = num3 * 128 + num4;
						array3[num6] = vertices.Count;
						switch (num3)
						{
						case 0:
							Add(Mathf.Lerp(0f - num2, num2, num5), 0f - num2);
							break;
						case 1:
							Add(num2, Mathf.Lerp(0f - num2, num2, num5));
							break;
						case 2:
							Add(Mathf.Lerp(num2, 0f - num2, num5), num2);
							break;
						default:
							Add(0f - num2, Mathf.Lerp(num2, 0f - num2, num5));
							break;
						}
					}
				}
				for (int num7 = 0; num7 < array.Length; num7++)
				{
					int num8 = (num7 + 1) % array.Length;
					Quad(array3[num7], array3[num8], array[num7], array[num8]);
				}
				array = array3;
			}
			Mesh val = new Mesh
			{
				name = "VM.Ash.VisualSea"
			};
			val.SetVertices(vertices);
			val.SetUVs(0, uv);
			val.SetColors(colors);
			val.SetTriangles(indices, 0);
			val.RecalculateNormals();
			val.RecalculateTangents();
			val.RecalculateBounds();
			return val;
			void Add(float x, float z)
			{
				//IL_000d: 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_0048: Unknown result type (might be due to invalid IL or missing references)
				vertices.Add(new Vector3(x, 0f, z));
				uv.Add(new Vector2((x + 4096f) / 8192f, (z + 4096f) / 8192f));
				colors.Add(ash);
			}
			void Quad(int a, int b, int c, int d)
			{
				indices.Add(a);
				indices.Add(c);
				indices.Add(b);
				indices.Add(b);
				indices.Add(c);
				indices.Add(d);
			}
		}

		internal void Begin(Camera camera, IReadOnlyList<Renderer> waters)
		{
			//IL_010c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0111: Unknown result type (might be due to invalid IL or missing references)
			//IL_0114: Unknown result type (might be due to invalid IL or missing references)
			//IL_0132: Unknown result type (might be due to invalid IL or missing references)
			//IL_014f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0155: Unknown result type (might be due to invalid IL or missing references)
			//IL_0156: Unknown result type (might be due to invalid IL or missing references)
			//IL_015b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0160: Unknown result type (might be due to invalid IL or missing references)
			//IL_0165: Unknown result type (might be due to invalid IL or missing references)
			//IL_0188: Unknown result type (might be due to invalid IL or missing references)
			End();
			if (Buffer != null)
			{
				Buffer.Clear();
			}
			Player localPlayer = Player.m_localPlayer;
			if (!Object.op_Implicit((Object)(object)localPlayer) || ((Character)localPlayer).InInterior() || ModConfig.F("AshBody.WaterLavaIntensity") <= 0f || AshPresentation.World <= 0.001f)
			{
				return;
			}
			try
			{
				if (Object.op_Implicit((Object)(object)Camera) && (Object)(object)Camera != (Object)(object)camera)
				{
					Dispose();
				}
				if (!Ensure(camera))
				{
					return;
				}
				float num = (Object.op_Implicit((Object)(object)ZoneSystem.instance) ? ZoneSystem.instance.m_waterLevel : 30f);
				foreach (Renderer item in waters)
				{
					if (Object.op_Implicit((Object)(object)item) && item.enabled && ((Component)item).gameObject.activeInHierarchy)
					{
						Hidden.Add((item, item.forceRenderingOff));
						item.forceRenderingOff = true;
					}
				}
				Vector3 position = ((Component)localPlayer).transform.position;
				Vector3 val = default(Vector3);
				((Vector3)(ref val))..ctor(Mathf.Floor(position.x / 64f) * 64f, num - 0.8f, Mathf.Floor(position.z / 64f) * 64f);
				Shape(val);
				Matrix4x4 val2 = Matrix4x4.TRS(val, Quaternion.identity, Vector3.one);
				Buffer.SetGlobalFloat("_Wet", 0f);
				Buffer.DrawMesh(Mesh, val2, Material, 0, 0);
				Buffer.SetGlobalFloat("_Wet", Shader.GetGlobalFloat("_Wet"));
			}
			catch (Exception ex)
			{
				End();
				if (Buffer != null)
				{
					Buffer.Clear();
				}
				Failed = true;
				Plugin.Log.LogWarning((object)("Ash native lava disabled: " + ex.Message));
			}
		}

		internal void End()
		{
			foreach (var item in Hidden)
			{
				if (Object.op_Implicit((Object)(object)item.renderer))
				{
					item.renderer.forceRenderingOff = item.hidden;
				}
			}
			Hidden.Clear();
		}

		private void Shape(Vector3 origin)
		{
			//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_000d: Unknown result type (might be due to invalid IL or missing references)
			//IL_000f: 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_005c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0062: Unknown result type (might be due to invalid IL or missing references)
			//IL_006a: 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_00e0: 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)
			//IL_0134: Unknown result type (might be due to invalid IL or missing references)
			//IL_0139: Unknown result type (might be due to invalid IL or missing references)
			//IL_013d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0142: Unknown result type (might be due to invalid IL or missing references)
			//IL_0153: Unknown result type (might be due to invalid IL or missing references)
			//IL_0158: Unknown result type (might be due to invalid IL or missing references)
			//IL_015c: 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)
			//IL_016a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0171: Unknown result type (might be due to invalid IL or missing references)
			//IL_0182: Unknown result type (might be due to invalid IL or missing references)
			//IL_0187: Unknown result type (might be due to invalid IL or missing references)
			if (Time.time < NextShape && origin == LastOrigin)
			{
				return;
			}
			NextShape = Time.time + 0.08f;
			LastOrigin = origin;
			for (int i = 0; i < BaseVertices.Length; i++)
			{
				float num = ShapeFade[i];
				if (num != 0f)
				{
					Vector3 val = BaseVertices[i];
					float num2 = val.x + origin.x;
					float num3 = val.z + origin.z;
					float num4 = num2 * 0.18f + num3 * 0.09f + Time.time * 0.14f;
					float num5 = num3 * 0.32f - num2 * 0.12f - Time.time * 0.11f;
					val.y = (0.36f * Mathf.Sin(num4) + 0.19f * Mathf.Sin(num5)) * num;
					Deformed[i] = val;
					float num6 = Mathf.Cos(num4);
					float num7 = Mathf.Cos(num5);
					float num8 = (0.0648f * num6 - 0.0228f * num7) * num;
					float num9 = (0.0324f * num6 + 0.0608f * num7) * num;
					Vector3[] normals = Normals;
					int num10 = i;
					Vector3 val2 = new Vector3(0f - num8, 1f, 0f - num9);
					normals[num10] = ((Vector3)(ref val2)).normalized;
					val2 = new Vector3(1f, num8, 0f);
					Vector3 normalized = ((Vector3)(ref val2)).normalized;
					Tangents[i] = new Vector4(normalized.x, normalized.y, 0f, -1f);
				}
			}
			Mesh.vertices = Deformed;
			Mesh.normals = Normals;
			Mesh.tangents = Tangents;
		}

		internal void Reset()
		{
			CommandBuffer buffer = Buffer;
			if (buffer != null)
			{
				buffer.Clear();
			}
		}

		internal void Dispose()
		{
			End();
			if (Buffer != null)
			{
				if (Object.op_Implicit((Object)(object)Camera))
				{
					Camera.RemoveCommandBuffer((CameraEvent)16, Buffer);
				}
				Buffer.Release();
				Buffer = null;
			}
			if (Object.op_Implicit((Object)(object)Material))
			{
				Object.Destroy((Object)(object)Material);
			}
			if (Object.op_Implicit((Object)(object)Mesh))
			{
				Object.Destroy((Object)(object)Mesh);
			}
			if (Object.op_Implicit((Object)(object)Mask))
			{
				Object.Destroy((Object)(object)Mask);
			}
			Material = null;
			Mask = null;
			Mesh = null;
			Camera = null;
			BaseVertices = (Deformed = (Normals = null));
			Tangents = null;
			ShapeFade = null;
			NextShape = 0f;
		}
	}
	internal static class AshNativeSources
	{
		private sealed class Entry
		{
			internal SoftReference<GameObject> Asset;

			internal bool Held;

			internal bool Done;

			internal GameObject Value;
		}

		private static readonly Dictionary<string, Entry> Entries = new Dictionary<string, Entry>(StringComparer.OrdinalIgnoreCase);

		private static bool Started;

		private static float RequestedAt;

		private static readonly string[] Names = new string[9] { "Spawner_CharredCross", "Charred_Melee", "Ashlands_AshRain", "Ashlands_CinderRain", "fx_lavabubbling", "fx_lavasplash_medium", "cliff_ashlands4", "Pickable_Charredskull", "crypt_skeleton_laying" };

		internal static bool Ready()
		{
			//IL_0110: 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_0117: Unknown result type (might be due to invalid IL or missing references)
			if (!Started)
			{
				Started = true;
				RequestedAt = Time.realtimeSinceStartup;
				string[] names = Names;
				foreach (string key in names)
				{
					Entries[key] = new Entry();
				}
				string path = Path.Combine(Application.streamingAssetsPath, "SoftRef", "manifest_extended");
				string text = null;
				if (File.Exists(path))
				{
					AssetID val = default(AssetID);
					foreach (string item in File.ReadLines(path))
					{
						string text2 = item.Trim();
						if (text2.StartsWith("- asset ID: "))
						{
							text = text2.Substring(12).Trim();
						}
						else
						{
							if (!text2.StartsWith("path in bundle: ") || !text2.EndsWith(".prefab", StringComparison.OrdinalIgnoreCase))
							{
								continue;
							}
							string fileNameWithoutExtension = Path.GetFileNameWithoutExtension(text2.Substring(16).Trim());
							if (Entries.TryGetValue(fileNameWithoutExtension, out var value) && !value.Held && AssetID.TryParse(text ?? "", ref val))
							{
								value.Asset = new SoftReference<GameObject>(val);
								if (value.Asset.IsValid)
								{
									value.Asset.LoadAsync();
									value.Held = true;
								}
							}
						}
					}
				}
				foreach (KeyValuePair<string, Entry> entry in Entries)
				{
					if (!entry.Value.Held)
					{
						entry.Value.Value = (Object.op_Implicit((Object)(object)ZNetScene.instance) ? ZNetScene.instance.GetPrefab(entry.Key) : null);
						entry.Value.Done = true;
						if (!Object.op_Implicit((Object)(object)entry.Value.Value))
						{
							Plugin.Log.LogWarning((object)("Ash source not found in native manifest: " + entry.Key));
						}
					}
				}
			}
			bool result = true;
			foreach (KeyValuePair<string, Entry> entry2 in Entries)
			{
				Entry value2 = entry2.Value;
				if (!value2.Done)
				{
					if (value2.Asset.IsLoaded)
					{
						value2.Value = value2.Asset.Asset;
						value2.Done = true;
					}
					else if (Time.realtimeSinceStartup - RequestedAt > 30f)
					{
						value2.Done = true;
						Plugin.Log.LogWarning((object)("Ash asset load timed out: " + entry2.Key));
					}
					else
					{
						result = false;
					}
				}
			}
			return result;
		}

		internal static GameObject Get(string name)
		{
			if (!Entries.TryGetValue(name, out var value))
			{
				return null;
			}
			return value.Value;
		}

		internal static void Clear()
		{
			foreach (Entry value in Entries.Values)
			{
				if (value.Held)
				{
					value.Asset.Release();
				}
			}
			Entries.Clear();
			Started = false;
		}
	}
	internal sealed class AshParticles
	{
		internal GameObject Root;

		internal readonly List<ParticleSystem> Systems = new List<ParticleSystem>();

		private readonly List<float> Rates = new List<float>();

		private readonly List<Material> OwnedMaterials = new List<Material>();

		internal static AshParticles Create(Transform source, Transform parent, int budget, bool world = true)
		{
			//IL_0020: Unknown result type (might be due to invalid IL or missing references)
			//IL_002a: Expected O, but got Unknown
			//IL_0049: 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_008a: 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_012d: 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_0144: Unknown result type (might be due to invalid IL or missing references)
			//IL_0150: Unknown result type (might be due to invalid IL or missing references)
			//IL_0155: Unknown result type (might be due to invalid IL or missing references)
			//IL_0160: Unknown result type (might be due to invalid IL or missing references)
			//IL_0165: Unknown result type (might be due to invalid IL or missing references)
			//IL_016e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0173: Unknown result type (might be due to invalid IL or missing references)
			//IL_017e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0183: 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: Invalid comparison between Unknown and I4
			//IL_01ca: Unknown result type (might be due to invalid IL or missing references)
			//IL_018f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0196: Unknown result type (might be due to invalid IL or missing references)
			//IL_019e: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a5: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ad: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b4: Unknown result type (might be due to invalid IL or missing references)
			//IL_01bc: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e9: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ee: Unknown result type (might be due to invalid IL or missing references)
			if (!Object.op_Implicit((Object)(object)source))
			{
				return null;
			}
			AshParticles ashParticles = new AshParticles
			{
				Root = new GameObject("VM.Ash.Native." + ((Object)source).name)
			};
			ashParticles.Root.transform.SetParent(parent, false);
			ashParticles.Root.transform.rotation = source.rotation;
			ashParticles.Root.transform.localScale = source.lossyScale;
			if (Object.op_Implicit((Object)(object)Player.m_localPlayer))
			{
				ashParticles.Root.transform.position = ((Component)Player.m_localPlayer).transform.position;
			}
			ParticleSystem[] componentsInChildren = ((Component)source).GetComponentsInChildren<ParticleSystem>(true);
			int budget2 = Mathf.Max(16, budget / Mathf.Max(1, componentsInChildren.Length));
			ParticleSystem[] array = componentsInChildren;
			foreach (ParticleSystem val in array)
			{
				bool flag = true;
				Transform val2 = ((Component)val).transform;
				while (Object.op_Implicit((Object)(object)val2) && (Object)(object)val2 != (Object)(object)source)
				{
					if (!((Component)val2).gameObject.activeSelf)
					{
						flag = false;
						break;
					}
					val2 = val2.parent;
				}
				if (flag)
				{
					ParticleSystem val3 = Copy(val, ashParticles.Root.transform, budget2, world);
					((Component)val3).transform.localPosition = source.InverseTransformPoint(((Component)val).transform.position);
					((Component)val3).transform.localRotation = Quaternion.Inverse(source.rotation) * ((Component)val).transform.rotation;
					Vector3 lossyScale = source.lossyScale;
					Vector3 lossyScale2 = ((Component)val).transform.lossyScale;
					Transform transform = ((Component)val3).transform;
					MainModule main = val.main;
					transform.localScale = (Vector3)(((int)((MainModule)(ref main)).scalingMode == 1) ? ((Component)val).transform.localScale : new Vector3(lossyScale2.x / lossyScale.x, lossyScale2.y / lossyScale.y, lossyScale2.z / lossyScale.z));
					ashParticles.Systems.Add(val3);
					List<float> rates = ashParticles.Rates;
					EmissionModule emission = val.emission;
					rates.Add(((EmissionModule)(ref emission)).rateOverTimeMultiplier);
				}
			}
			return ashParticles;
		}

		internal void ScaleEmission(float multiplier, string onlyName = null)
		{
			for (int i = 0; i < Rates.Count; i++)
			{
				if (onlyName == null || ((Object)Systems[i]).name == onlyName)
				{
					Rates[i] *= multiplier;
				}
			}
		}

		internal void Strength(float value, bool black = false)
		{
			//IL_002c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0031: Unknown result type (might be due to invalid IL or missing references)
			//IL_004b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0050: 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_0073: Unknown result type (might be due to invalid IL or missing references)
			value = Mathf.Clamp(value, 0f, 2f);
			for (int i = 0; i < Systems.Count; i++)
			{
				ParticleSystem val = Systems[i];
				if (Object.op_Implicit((Object)(object)val))
				{
					EmissionModule emission = val.emission;
					((EmissionModule)(ref emission)).rateOverTimeMultiplier = Rates[i] * value;
					if (black)
					{
						MainModule main = val.main;
						((MainModule)(ref main)).startColor = MinMaxGradient.op_Implicit(new Color(0.025f, 0.022f, 0.02f, 0.88f * Mathf.Clamp01(value)));
					}
				}
			}
		}

		internal void PlayBurst()
		{
			foreach (ParticleSystem system in Systems)
			{
				system.Stop(false, (ParticleSystemStopBehavior)0);
				system.Play(false);
			}
		}

		internal void Stop()
		{
			foreach (ParticleSystem system in Systems)
			{
				system.Stop(false, (ParticleSystemStopBehavior)0);
			}
		}

		internal void DarkSmoke()
		{
			//IL_003c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0041: Unknown result type (might be due to invalid IL or missing references)
			//IL_004b: Expected O, but got Unknown
			//IL_0090: 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_00db: Unknown result type (might be due to invalid IL or missing references)
			foreach (ParticleSystem system in Systems)
			{
				ParticleSystemRenderer component = ((Component)system).GetComponent<ParticleSystemRenderer>();
				Material[] sharedMaterials = ((Renderer)component).sharedMaterials;
				for (int i = 0; i < sharedMaterials.Length; i++)
				{
					if (!Object.op_Implicit((Object)(object)sharedMaterials[i]))
					{
						continue;
					}
					Material val = new Material(sharedMaterials[i])
					{
						hideFlags = (HideFlags)61
					};
					OwnedMaterials.Add(val);
					sharedMaterials[i] = val;
					string[] array = new string[2] { "_Color", "_TintColor" };
					foreach (string text in array)
					{
						if (val.HasProperty(text))
						{
							val.GetColor(text);
							val.SetColor(text, new Color(0.035f, 0.03f, 0.027f, 1f));
						}
					}
					if (val.HasProperty("_EmissionColor"))
					{
						val.SetColor("_EmissionColor", Color.black);
					}
				}
				((Renderer)component).sharedMaterials = sharedMaterials;
			}
		}

		internal void Dispose()
		{
			if (Object.op_Implicit((Object)(object)Root))
			{
				Root.SetActive(false);
				Object.Destroy((Object)(object)Root);
			}
			foreach (Material ownedMaterial in OwnedMaterials)
			{
				if (Object.op_Implicit((Object)(object)ownedMaterial))
				{
					Object.Destroy((Object)(object)ownedMaterial);
				}
			}
			OwnedMaterials.Clear();
			Systems.Clear();
		}

		internal static ParticleSystem Copy(ParticleSystem source, Transform parent, int budget, bool world)
		{
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_000b: Unknown result type (might be due to invalid IL or missing references)
			//IL_001c: 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_003f: 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_0073: Unknown result type (might be due to invalid IL or missing references)
			//IL_0081: 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_00e0: 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_00c2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d0: 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_0105: 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_0121: 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_014d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0177: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a6: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ab: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ad: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b2: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c6: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d4: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ff: Unknown result type (might be due to invalid IL or missing references)
			//IL_0204: Unknown result type (might be due to invalid IL or missing references)
			//IL_020c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0211: Unknown result type (might be due to invalid IL or missing references)
			//IL_021f: Unknown result type (might be due to invalid IL or missing references)
			//IL_022d: Unknown result type (might be due to invalid IL or missing references)
			//IL_022f: 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_0251: Unknown result type (might be due to invalid IL or missing references)
			//IL_0254: Unknown result type (might be due to invalid IL or missing references)
			//IL_0259: Unknown result type (might be due to invalid IL or missing references)
			//IL_026d: Unknown result type (might be due to invalid IL or missing references)
			//IL_02c1: Unknown result type (might be due to invalid IL or missing references)
			//IL_02cf: Unknown result type (might be due to invalid IL or missing references)
			//IL_02dd: Unknown result type (might be due to invalid IL or missing references)
			//IL_032f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0336: Invalid comparison between Unknown and I4
			//IL_035c: Unknown result type (might be due to invalid IL or missing references)
			//IL_033a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0341: Invalid comparison between Unknown and I4
			//IL_0367: Unknown result type (might be due to invalid IL or missing references)
			//IL_036c: Unknown result type (might be due to invalid IL or missing references)
			//IL_036f: 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_0388: Unknown result type (might be due to invalid IL or missing references)
			//IL_0396: Unknown result type (might be due to invalid IL or missing references)
			//IL_03a4: Unknown result type (might be due to invalid IL or missing references)
			//IL_03b2: Unknown result type (might be due to invalid IL or missing references)
			//IL_03c0: Unknown result type (might be due to invalid IL or missing references)
			//IL_03ce: Unknown result type (might be due to invalid IL or missing references)
			//IL_03dc: Unknown result type (might be due to invalid IL or missing references)
			//IL_03ea: Unknown result type (might be due to invalid IL or missing references)
			//IL_03f8: Unknown result type (might be due to invalid IL or missing references)
			//IL_0403: Unknown result type (might be due to invalid IL or missing references)
			//IL_0408: Unknown result type (might be due to invalid IL or missing references)
			//IL_040b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0410: Unknown result type (might be due to invalid IL or missing references)
			//IL_0424: Unknown result type (might be due to invalid IL or missing references)
			//IL_0432: Unknown result type (might be due to invalid IL or missing references)
			//IL_0440: Unknown result type (might be due to invalid IL or missing references)
			//IL_044e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0467: Unknown result type (might be due to invalid IL or missing references)
			//IL_046c: Unknown result type (might be due to invalid IL or missing references)
			//IL_046f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0474: Unknown result type (might be due to invalid IL or missing references)
			//IL_0488: Unknown result type (might be due to invalid IL or missing references)
			//IL_0493: 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_049b: Unknown result type (might be due to invalid IL or missing references)
			//IL_04a0: Unknown result type (might be due to invalid IL or missing references)
			//IL_04c2: Unknown result type (might be due to invalid IL or missing references)
			//IL_04d0: Unknown result type (might be due to invalid IL or missing references)
			//IL_04de: Unknown result type (might be due to invalid IL or missing references)
			//IL_04e9: Unknown result type (might be due to invalid IL or missing references)
			//IL_04ee: Unknown result type (might be due to invalid IL or missing references)
			//IL_04f1: Unknown result type (might be due to invalid IL or missing references)
			//IL_04f6: Unknown result type (might be due to invalid IL or missing references)
			//IL_0518: Unknown result type (might be due to invalid IL or missing references)
			//IL_0526: Unknown result type (might be due to invalid IL or missing references)
			//IL_0534: Unknown result type (might be due to invalid IL or missing references)
			//IL_053f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0544: Unknown result type (might be due to invalid IL or missing references)
			//IL_0547: Unknown result type (might be due to invalid IL or missing references)
			//IL_054c: Unknown result type (might be due to invalid IL or missing references)
			//IL_056e: Unknown result type (might be due to invalid IL or missing references)
			//IL_057c: Unknown result type (might be due to invalid IL or missing references)
			//IL_058a: Unknown result type (might be due to invalid IL or missing references)
			//IL_05a6: Unknown result type (might be due to invalid IL or missing references)
			//IL_05ec: Unknown result type (might be due to invalid IL or missing references)
			//IL_05f7: Unknown result type (might be due to invalid IL or missing references)
			//IL_05fc: Unknown result type (might be due to invalid IL or missing references)
			//IL_05ff: Unknown result type (might be due to invalid IL or missing references)
			//IL_0604: Unknown result type (might be due to invalid IL or missing references)
			//IL_0626: Unknown result type (might be due to invalid IL or missing references)
			//IL_0634: Unknown result type (might be due to invalid IL or missing references)
			//IL_0642: Unknown result type (might be due to invalid IL or missing references)
			//IL_065e: Unknown result type (might be due to invalid IL or missing references)
			//IL_066c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0677: Unknown result type (might be due to invalid IL or missing references)
			//IL_067c: Unknown result type (might be due to invalid IL or missing references)
			//IL_067f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0684: Unknown result type (might be due to invalid IL or missing references)
			//IL_0698: Unknown result type (might be due to invalid IL or missing references)
			//IL_06a4: Unknown result type (might be due to invalid IL or missing references)
			//IL_06cb: Unknown result type (might be due to invalid IL or missing references)
			//IL_06d9: Unknown result type (might be due to invalid IL or missing references)
			//IL_06e7: Unknown result type (might be due to invalid IL or missing references)
			//IL_0736: Unknown result type (might be due to invalid IL or missing references)
			//IL_073b: Unknown result type (might be due to invalid IL or missing references)
			//IL_073e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0743: Unknown result type (might be due to invalid IL or missing references)
			//IL_0769: Unknown result type (might be due to invalid IL or missing references)
			//IL_076d: Unknown result type (might be due to invalid IL or missing references)
			//IL_076f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0774: Unknown result type (might be due to invalid IL or missing references)
			//IL_0778: Unknown result type (might be due to invalid IL or missing references)
			//IL_077a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0781: Unknown result type (might be due to invalid IL or missing references)
			//IL_0784: Invalid comparison between Unknown and I4
			//IL_0798: Unknown result type (might be due to invalid IL or missing references)
			//IL_079b: Invalid comparison between Unknown and I4
			//IL_0788: Unknown result type (might be due to invalid IL or missing references)
			//IL_078c: Unknown result type (might be due to invalid IL or missing references)
			//IL_078e: Unknown result type (might be due to invalid IL or missing references)
			//IL_08e3: Unknown result type (might be due to invalid IL or missing references)
			//IL_08e8: Unknown result type (might be due to invalid IL or missing references)
			//IL_08f3: Unknown result type (might be due to invalid IL or missing references)
			//IL_08f8: Unknown result type (might be due to invalid IL or missing references)
			//IL_0903: Unknown result type (might be due to invalid IL or missing references)
			//IL_0908: Unknown result type (might be due to invalid IL or missing references)
			//IL_0913: Unknown result type (might be due to invalid IL or missing references)
			//IL_0918: Unknown result type (might be due to invalid IL or missing references)
			//IL_0819: Unknown result type (might be due to invalid IL or missing references)
			//IL_0825: Unknown result type (might be due to invalid IL or missing references)
			//IL_082b: Invalid comparison between Unknown and I4
			//IL_079f: Unknown result type (might be due to invalid IL or missing references)
			//IL_07aa: Unknown result type (might be due to invalid IL or missing references)
			//IL_083f: Unknown result type (might be due to invalid IL or missing references)
			//IL_084d: Unknown result type (might be due to invalid IL or missing references)
			//IL_08a1: Unknown result type (might be due to invalid IL or missing references)
			//IL_07ba: Unknown result type (might be due to invalid IL or missing references)
			//IL_07c0: Unknown result type (might be due to invalid IL or missing references)
			//IL_07c4: Unknown result type (might be due to invalid IL or missing references)
			GameObject val = new GameObject(((Object)source).name)
			{
				layer = ((Component)source).gameObject.layer
			};
			val.transform.SetParent(parent, false);
			ParticleSystem val2 = val.AddComponent<ParticleSystem>();
			val2.Stop(true, (ParticleSystemStopBehavior)0);
			MainModule main = source.main;
			MainModule main2 = val2.main;
			((MainModule)(ref main2)).duration = ((MainModule)(ref main)).duration;
			((MainModule)(ref main2)).loop = ((MainModule)(ref main)).loop;
			((MainModule)(ref main2)).prewarm = ((MainModule)(ref main)).prewarm;
			((MainModule)(ref main2)).startDelay = ((MainModule)(ref main)).startDelay;
			((MainModule)(ref main2)).startLifetime = ((MainModule)(ref main)).startLifetime;
			((MainModule)(ref main2)).startSpeed = ((MainModule)(ref main)).startSpeed;
			((MainModule)(ref main2)).startSize3D = ((MainModule)(ref main)).startSize3D;
			if (((MainModule)(ref main)).startSize3D)
			{
				((MainModule)(ref main2)).startSizeX = ((MainModule)(ref main)).startSizeX;
				((MainModule)(ref main2)).startSizeY = ((MainModule)(ref main)).startSizeY;
				((MainModule)(ref main2)).startSizeZ = ((MainModule)(ref main)).startSizeZ;
			}
			else
			{
				((MainModule)(ref main2)).startSize = ((MainModule)(ref main)).startSize;
			}
			((MainModule)(ref main2)).startRotation3D = ((MainModule)(ref main)).startRotation3D;
			if (((MainModule)(ref main)).startRotation3D)
			{
				((MainModule)(ref main2)).startRotationX = ((MainModule)(ref main)).startRotationX;
				((MainModule)(ref main2)).startRotationY = ((MainModule)(ref main)).startRotationY;
				((MainModule)(ref main2)).startRotationZ = ((MainModule)(ref main)).startRotationZ;
			}
			else
			{
				((MainModule)(ref main2)).startRotation = ((MainModule)(ref main)).startRotation;
			}
			((MainModule)(ref main2)).startColor = ((MainModule)(ref main)).startColor;
			((MainModule)(ref main2)).gravityModifier = ((MainModule)(ref main)).gravityModifier;
			((MainModule)(ref main2)).simulationSpeed = ((MainModule)(ref main)).simulationSpeed;
			((MainModule)(ref main2)).simulationSpace = (ParticleSystemSimulationSpace)(world ? 1 : 0);
			((MainModule)(ref main2)).scalingMode = ((MainModule)(ref main)).scalingMode;
			((MainModule)(ref main2)).playOnAwake = false;
			((MainModule)(ref main2)).maxParticles = Mathf.Min(((MainModule)(ref main)).maxParticles, budget);
			((MainModule)(ref main2)).stopAction = (ParticleSystemStopAction)0;
			EmissionModule emission = source.emission;
			EmissionModule emission2 = val2.emission;
			((EmissionModule)(ref emission2)).enabled = ((EmissionModule)(ref emission)).enabled;
			((EmissionModule)(ref emission2)).rateOverTime = ((EmissionModule)(ref emission)).rateOverTime;
			((EmissionModule)(ref emission2)).rateOverDistance = ((EmissionModule)(ref emission)).rateOverDistance;
			Burst[] array = (Burst[])(object)new Burst[((EmissionModule)(ref emission)).burstCount];
			((EmissionModule)(ref emission)).GetBursts(array);
			for (int i = 0; i < array.Length; i++)
			{
				Burst val3 = array[i];
				float num = budget;
				MinMaxCurve count = ((Burst)(ref val3)).count;
				((Burst)(ref val3)).count = new MinMaxCurve(Mathf.Min(num, ((MinMaxCurve)(ref count)).constantMax));
				array[i] = val3;
			}
			((EmissionModule)(ref emission2)).SetBursts(array);
			ShapeModule shape = source.shape;
			ShapeModule shape2 = val2.shape;
			((ShapeModule)(ref shape2)).enabled = ((ShapeModule)(ref shape)).enabled;
			((ShapeModule)(ref shape2)).shapeType = ((ShapeModule)(ref shape)).shapeType;
			((ShapeModule)(ref shape2)).angle = ((ShapeModule)(ref shape)).angle;
			((ShapeModule)(ref shape2)).radius = ((ShapeModule)(ref shape)).radius;
			((ShapeModule)(ref shape2)).radiusThickness = ((ShapeModule)(ref shape)).radiusThickness;
			((ShapeModule)(ref shape2)).arc = ((ShapeModule)(ref shape)).arc;
			((ShapeModule)(ref shape2)).length = ((ShapeModule)(ref shape)).length;
			((ShapeModule)(ref shape2)).position = ((ShapeModule)(ref shape)).position;
			((ShapeModule)(ref shape2)).rotation = ((ShapeModule)(ref shape)).rotation;
			((ShapeModule)(ref shape2)).scale = ((ShapeModule)(ref shape)).scale;
			((ShapeModule)(ref shape2)).mesh = ((ShapeModule)(ref shape)).mesh;
			((ShapeModule)(ref shape2)).randomDirectionAmount = ((ShapeModule)(ref shape)).randomDirectionAmount;
			((ShapeModule)(ref shape2)).sphericalDirectionAmount = ((ShapeModule)(ref shape)).sphericalDirectionAmount;
			((ShapeModule)(ref shape2)).randomPositionAmount = ((ShapeModule)(ref shape)).randomPositionAmount;
			((ShapeModule)(ref shape2)).alignToDirection = ((ShapeModule)(ref shape)).alignToDirection;
			if ((int)((ShapeModule)(ref shape)).shapeType == 14 || (int)((ShapeModule)(ref shape)).shapeType == 13)
			{
				((ShapeModule)(ref shape2)).shapeType = (ParticleSystemShapeType)5;
				((ShapeModule)(ref shape2)).scale = new Vector3(0.5f, 1.2f, 0.35f);
			}
			VelocityOverLifetimeModule velocityOverLifetime = source.velocityOverLifetime;
			VelocityOverLifetimeModule velocityOverLifetime2 = val2.velocityOverLifetime;
			((VelocityOverLifetimeModule)(ref velocityOverLifetime2)).enabled = ((VelocityOverLifetimeModule)(ref velocityOverLifetime)).enabled;
			((VelocityOverLifetimeModule)(ref velocityOverLifetime2)).space = ((VelocityOverLifetimeModule)(ref velocityOverLifetime)).space;
			((VelocityOverLifetimeModule)(ref velocityOverLifetime2)).x = ((VelocityOverLifetimeModule)(ref velocityOverLifetime)).x;
			((VelocityOverLifetimeModule)(ref velocityOverLifetime2)).y = ((VelocityOverLifetimeModule)(ref velocityOverLifetime)).y;
			((VelocityOverLifetimeModule)(ref velocityOverLifetime2)).z = ((VelocityOverLifetimeModule)(ref velocityOverLifetime)).z;
			((VelocityOverLifetimeModule)(ref velocityOverLifetime2)).orbitalX = ((VelocityOverLifetimeModule)(ref velocityOverLifetime)).orbitalX;
			((VelocityOverLifetimeModule)(ref velocityOverLifetime2)).orbitalY = ((VelocityOverLifetimeModule)(ref velocityOverLifetime)).orbitalY;
			((VelocityOverLifetimeModule)(ref velocityOverLifetime2)).orbitalZ = ((VelocityOverLifetimeModule)(ref velocityOverLifetime)).orbitalZ;
			((VelocityOverLifetimeModule)(ref velocityOverLifetime2)).radial = ((VelocityOverLifetimeModule)(ref velocityOverLifetime)).radial;
			((VelocityOverLifetimeModule)(ref velocityOverLifetime2)).speedModifier = ((VelocityOverLifetimeModule)(ref velocityOverLifetime)).speedModifier;
			ForceOverLifetimeModule forceOverLifetime = source.forceOverLifetime;
			ForceOverLifetimeModule forceOverLifetime2 = val2.forceOverLifetime;
			((ForceOverLifetimeModule)(ref forceOverLifetime2)).enabled = ((ForceOverLifetimeModule)(ref forceOverLifetime)).enabled;
			((ForceOverLifetimeModule)(ref forceOverLifetime2)).space = ((ForceOverLifetimeModule)(ref forceOverLifetime)).space;
			((ForceOverLifetimeModule)(ref forceOverLifetime2)).x = ((ForceOverLifetimeModule)(ref forceOverLifetime)).x;
			((ForceOverLifetimeModule)(ref forceOverLifetime2)).y = ((ForceOverLifetimeModule)(ref forceOverLifetime)).y;
			((ForceOverLifetimeModule)(ref forceOverLifetime2)).z = ((ForceOverLifetimeModule)(ref forceOverLifetime)).z;
			((ForceOverLifetimeModule)(ref forceOverLifetime2)).randomized = ((ForceOverLifetimeModule)(ref forceOverLifetime)).randomized;
			ColorOverLifetimeModule colorOverLifetime = source.colorOverLifetime;
			ColorOverLifetimeModule colorOverLifetime2 = val2.colorOverLifetime;
			((ColorOverLifetimeModule)(ref colorOverLifetime2)).enabled = ((ColorOverLifetimeModule)(ref colorOverLifetime)).enabled;
			((ColorOverLifetimeModule)(ref colorOverLifetime2)).color = ((ColorOverLifetimeModule)(ref colorOverLifetime)).color;
			SizeOverLifetimeModule sizeOverLifetime = source.sizeOverLifetime;
			SizeOverLifetimeModule sizeOverLifetime2 = val2.sizeOverLifetime;
			((SizeOverLifetimeModule)(ref sizeOverLifetime2)).enabled = ((SizeOverLifetimeModule)(ref sizeOverLifetime)).enabled;
			((SizeOverLifetimeModule)(ref sizeOverLifetime2)).separateAxes = ((SizeOverLifetimeModule)(ref sizeOverLifetime)).separateAxes;
			((SizeOverLifetimeModule)(ref sizeOverLifetime2)).x = ((SizeOverLifetimeModule)(ref sizeOverLifetime)).x;
			((SizeOverLifetimeModule)(ref sizeOverLifetime2)).y = ((SizeOverLifetimeModule)(ref sizeOverLifetime)).y;
			((SizeOverLifetimeModule)(ref sizeOverLifetime2)).z = ((SizeOverLifetimeModule)(ref sizeOverLifetime)).z;
			RotationOverLifetimeModule rotationOverLifetime = source.rotationOverLifetime;
			RotationOverLifetimeModule rotationOverLifetime2 = val2.rotationOverLifetime;
			((RotationOverLifetimeModule)(ref rotationOverLifetime2)).enabled = ((RotationOverLifetimeModule)(ref rotationOverLifetime)).enabled;
			((RotationOverLifetimeModule)(ref rotationOverLifetime2)).separateAxes = ((RotationOverLifetimeModule)(ref rotationOverLifetime)).separateAxes;
			((RotationOverLifetimeModule)(ref rotationOverLifetime2)).x = ((RotationOverLifetimeModule)(ref rotationOverLifetime)).x;
			((RotationOverLifetimeModule)(ref rotationOverLifetime2)).y = ((RotationOverLifetimeModule)(ref rotationOverLifetime)).y;
			((RotationOverLifetimeModule)(ref rotationOverLifetime2)).z = ((RotationOverLifetimeModule)(ref rotationOverLifetime)).z;
			NoiseModule noise = source.noise;
			NoiseModule noise2 = val2.noise;
			((NoiseModule)(ref noise2)).enabled = ((NoiseModule)(ref noise)).enabled;
			((NoiseModule)(ref noise2)).separateAxes = ((NoiseModule)(ref noise)).separateAxes;
			((NoiseModule)(ref noise2)).strengthX = ((NoiseModule)(ref noise)).strengthX;
			((NoiseModule)(ref noise2)).strengthY = ((NoiseModule)(ref noise)).strengthY;
			((NoiseModule)(ref noise2)).strengthZ = ((NoiseModule)(ref noise)).strengthZ;
			((NoiseModule)(ref noise2)).frequency = ((NoiseModule)(ref noise)).frequency;
			((NoiseModule)(ref noise2)).scrollSpeed = ((NoiseModule)(ref noise)).scrollSpeed;
			((NoiseModule)(ref noise2)).damping = ((NoiseModule)(ref noise)).damping;
			((NoiseModule)(ref noise2)).octaveCount = ((NoiseModule)(ref noise)).octaveCount;
			((NoiseModule)(ref noise2)).octaveMultiplier = ((NoiseModule)(ref noise)).octaveMultiplier;
			((NoiseModule)(ref noise2)).octaveScale = ((NoiseModule)(ref noise)).octaveScale;
			((NoiseModule)(ref noise2)).quality = ((NoiseModule)(ref noise)).quality;
			LimitVelocityOverLifetimeModule limitVelocityOverLifetime = source.limitVelocityOverLifetime;
			LimitVelocityOverLifetimeModule limitVelocityOverLifetime2 = val2.limitVelocityOverLifetime;
			((LimitVelocityOverLifetimeModule)(ref limitVelocityOverLifetime2)).enabled = ((LimitVelocityOverLifetimeModule)(ref limitVelocityOverLifetime)).enabled;
			((LimitVelocityOverLifetimeModule)(ref limitVelocityOverLifetime2)).separateAxes = ((LimitVelocityOverLifetimeModule)(ref limitVelocityOverLifetime)).separateAxes;
			((LimitVelocityOverLifetimeModule)(ref limitVelocityOverLifetime2)).limitX = ((LimitVelocityOverLifetimeModule)(ref limitVelocityOverLifetime)).limitX;
			((LimitVelocityOverLifetimeModule)(ref limitVelocityOverLifetime2)).limitY = ((LimitVelocityOverLifetimeModule)(ref limitVelocityOverLifetime)).limitY;
			((LimitVelocityOverLifetimeModule)(ref limitVelocityOverLifetime2)).limitZ = ((LimitVelocityOverLifetimeModule)(ref limitVelocityOverLifetime)).limitZ;
			((LimitVelocityOverLifetimeModule)(ref limitVelocityOverLifetime2)).dampen = ((LimitVelocityOverLifetimeModule)(ref limitVelocityOverLifetime)).dampen;
			((LimitVelocityOverLifetimeModule)(ref limitVelocityOverLifetime2)).drag = ((LimitVelocityOverLifetimeModule)(ref limitVelocityOverLifetime)).drag;
			((LimitVelocityOverLifetimeModule)(ref limitVelocityOverLifetime2)).space = ((LimitVelocityOverLifetimeModule)(ref limitVelocityOverLifetime)).space;
			TextureSheetAnimationModule textureSheetAnimation = source.textureSheetAnimation;
			TextureSheetAnimationModule textureSheetAnimation2 = val2.textureSheetAnimation;
			((TextureSheetAnimationModule)(ref textureSheetAnimation2)).enabled = ((TextureSheetAnimationModule)(ref textureSheetAnimation)).enabled;
			((TextureSheetAnimationModule)(ref textureSheetAnimation2)).mode = ((TextureSheetAnimationModule)(ref textureSheetAnimation)).mode;
			if ((int)((TextureSheetAnimationModule)(ref textureSheetAnimation)).mode == 0)
			{
				((TextureSheetAnimationModule)(ref textureSheetAnimation2)).numTilesX = ((TextureSheetAnimationModule)(ref textureSheetAnimation)).numTilesX;
				((TextureSheetAnimationModule)(ref textureSheetAnimation2)).numTilesY = ((TextureSheetAnimationModule)(ref textureSheetAnimation)).numTilesY;
				((TextureSheetAnimationModule)(ref textureSheetAnimation2)).animation = ((TextureSheetAnimationModule)(ref textureSheetAnimation)).animation;
				((TextureSheetAnimationModule)(ref textureSheetAnimation2)).frameOverTime = ((TextureSheetAnimationModule)(ref textureSheetAnimation)).frameOverTime;
				((TextureSheetAnimationModule)(ref textureSheetAnimation2)).startFrame = ((TextureSheetAnimationModule)(ref textureSheetAnimation)).startFrame;
				((TextureSheetAnimationModule)(ref textureSheetAnimation2)).cycleCount = ((TextureSheetAnimationModule)(ref textureSheetAnimation)).cycleCount;
				((TextureSheetAnimationModule)(ref textureSheetAnimation2)).rowIndex = ((TextureSheetAnimationModule)(ref textureSheetAnimation)).rowIndex;
			}
			else
			{
				for (int j = 0; j < ((TextureSheetAnimationModule)(ref textureSheetAnimation)).spriteCount; j++)
				{
					((TextureSheetAnimationModule)(ref textureSheetAnimation2)).AddSprite(((TextureSheetAnimationModule)(ref textureSheetAnimation)).GetSprite(j));
				}
			}
			CustomDataModule customData = source.customData;
			CustomDataModule customData2 = val2.customData;
			((CustomDataModule)(ref customData2)).enabled = ((CustomDataModule)(ref customData)).enabled;
			ParticleSystemCustomData[] array2 = (ParticleSystemCustomData[])(object)new ParticleSystemCustomData[2]
			{
				default(ParticleSystemCustomData),
				(ParticleSystemCustomData)1
			};
			foreach (ParticleSystemCustomData val4 in array2)
			{
				ParticleSystemCustomDataMode mode = ((CustomDataModule)(ref customData)).GetMode(val4);
				((CustomDataModule)(ref customData2)).SetMode(val4, mode);
				if ((int)mode == 2)
				{
					((CustomDataModule)(ref customData2)).SetColor(val4, ((CustomDataModule)(ref customData)).GetColor(val4));
				}
				if ((int)mode == 1)
				{
					int vectorComponentCount = ((CustomDataModule)(ref customData)).GetVectorComponentCount(val4);
					((CustomDataModule)(ref customData2)).SetVectorComponentCount(val4, vectorComponentCount);
					for (int l = 0; l < vectorComponentCount; l++)
					{
						((CustomDataModule)(ref customData2)).SetVector(val4, l, ((CustomDataModule)(ref customData)).GetVector(val4, l));
					}
				}
			}
			ParticleSystemRenderer component = ((Component)val2).GetComponent<ParticleSystemRenderer>();
			ParticleSystemRenderer component2 = ((Component)source).GetComponent<ParticleSystemRenderer>();
			if (Object.op_Implicit((Object)(object)component2))
			{
				((Renderer)component).sharedMaterials = ((Renderer)component2).sharedMaterials;
				component.renderMode = component2.renderMode;
				if ((int)component2.renderMode == 4)
				{
					component.mesh = component2.mesh;
				}
				component.alignment = component2.alignment;
				component.pivot = component2.pivot;
				component.lengthScale = component2.lengthScale;
				component.velocityScale = component2.velocityScale;
				component.normalDirection = component2.normalDirection;
				component.minParticleSize = component2.minParticleSize;
				component.maxParticleSize = component2.maxParticleSize;
				component.sortMode = component2.sortMode;
				component.sortingFudge = component2.sortingFudge;
				List<ParticleSystemVertexStream> list = new List<ParticleSystemVertexStream>();
				component2.GetActiveVertexStreams(list);
				component.SetActiveVertexStreams(list);
			}
			((Renderer)component).shadowCastingMode = (ShadowCastingMode)0;
			((Renderer)component).receiveShadows = false;
			CollisionModule collision = val2.collision;
			((CollisionModule)(ref collision)).enabled = false;
			TriggerModule trigger = val2.trigger;
			((TriggerModule)(ref trigger)).enabled = false;
			SubEmittersModule subEmitters = val2.subEmitters;
			((SubEmittersModule)(ref subEmitters)).enabled = false;
			LightsModule lights = val2.lights;
			((LightsModule)(ref lights)).enabled = false;
			val2.Play(false);
			return val2;
		}
	}
	internal static class AshPresentation
	{
		private sealed class Vision
		{
			internal readonly List<HelNativeVisual> Pile = new List<HelNativeVisual>();

			internal int Kind;

			internal HelNativeVisual Model;

			internal ParticleSystem Smoke;

			internal ParticleSystem Fire;

			internal float Born;

			internal float Life;

			internal float FloorOffset;

			internal bool Live;

			internal Quaternion PoseRotation;
		}

		private static GameObject Root;

		private static bool Failed;

		private static bool HeatAttempted;

		private static bool HeatFailed;

		private static readonly List<Vision> Visions = new List<Vision>();

		private static AshWorldEffects WorldEffects;

		private static readonly List<ParticleSystem> Columns = new List<ParticleSystem>();

		private static readonly HashSet<string> Missing = new HashSet<string>();

		private static readonly Dictionary<string, GameObject> Sources = new Dictionary<string, GameObject>();

		private static ParticleSystem Collapse;

		private static readonly AshAudioEnvironment Soundscape = new AshAudioEnvironment();

		private static Material Heat;

		private static Shader SurfaceShader;

		private static float NextSurtling;

		private static float NextCorpse;

		private static float NextStone;

		private static float NextColumn;

		private static float PreviousDensity = 1f;

		private static int CorpseCursor;

		private static bool CorpsePlaced;

		private static bool CorpseBlocked;

		private static readonly Vector4[] Hotspots = (Vector4[])(object)new Vector4[8];

		private static readonly MaterialPropertyBlock Tint = new MaterialPropertyBlock();

		internal static float PreviewDensity = 1f;

		internal static EnvSetup Environment { get; private set; }

		internal static bool Active
		{
			get
			{
				if (Object.op_Implicit((Object)(object)Root) && !Failed && TranceScreenProfile.Current == TranceType.AshBody)
				{
					return ModConfig.B("AshBody.Enabled");
				}
				return false;
			}
		}

		internal static float Density
		{
			get
			{
				if (!VisualFxLab.Preview)
				{
					if (MushroomEffectManager.State == null)
					{
						return 0f;
					}
					return AshBodySystem.Ratio(MushroomEffectManager.State);
				}
				return PreviewDensity;
			}
		}

		internal static float World
		{
			get
			{
				if (!Active)
				{
					return 0f;
				}
				return Mathf.Clamp01(VisualFxLab.Intensity) * AshMath.WorldPresence(Density) * ModConfig.F("AshBody.WorldHallucinationIntensity");
			}
		}

		private static GameObject Source(string name)
		{
			if (Sources.TryGetValue(name, out var value))
			{
				return value;
			}
			value = AshNativeSources.Get(name);
			if (!Object.op_Implicit((Object)(object)value))
			{
				value = (Object.op_Implicit((Object)(object)ZNetScene.instance) ? ZNetScene.instance.GetPrefab(name) : null);
			}
			Sources[name] = value;
			if (!Object.op_Implicit((Object)(object)value) && Missing.Add(name))
			{
				Plugin.Log.LogWarning((object)("Ash native source unavailable: " + name + "; skipped for this activation."));
			}
			return value;
		}

		internal static Material Surface(Material native)
		{
			//IL_0043: Unknown result type (might be due to invalid IL or missing references)
			//IL_0048: Unknown result type (might be due to invalid IL or missing references)
			//IL_0051: Expected O, but got Unknown
			//IL_0096: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e8: 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)
			if (!Object.op_Implicit((Object)(object)SurfaceShader))
			{
				SurfaceShader = FxBundle.Load<Shader>("Assets/AshSurface.shader");
			}
			if (!Object.op_Implicit((Object)(object)SurfaceShader) || !SurfaceShader.isSupported)
			{
				throw new InvalidOperationException("Ash surface shader unavailable");
			}
			Material val = new Material(SurfaceShader)
			{
				hideFlags = (HideFlags)61
			};
			if (Object.op_Implicit((Object)(object)native))
			{
				string[] array = new string[2] { "_MainTex", "_EmissionMap" };
				foreach (string text in array)
				{
					if (native.HasProperty(text))
					{
						val.SetTexture(text, native.GetTexture(text));
						val.SetTextureScale(text, native.GetTextureScale(text));
						val.SetTextureOffset(text, native.GetTextureOffset(text));
					}
				}
				array = new string[2] { "_Color", "_EmissionColor" };
				foreach (string text2 in array)
				{
					if (native.HasProperty(text2))
					{
						val.SetColor(text2, native.GetColor(text2));
					}
				}
				if (native.HasProperty("_SkinColor"))
				{
					val.SetColor("_Color", native.GetColor("_SkinColor"));
				}
			}
			return val;
		}

		internal static Material IllusionMaterial(Material native)
		{
			//IL_0031: Unknown result type (might be due to invalid IL or missing references)
			//IL_0036: Unknown result type (might be due to invalid IL or missing references)
			//IL_003f: Expected O, but got Unknown
			//IL_01b5: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ba: 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_01d3: 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_0102: Unknown result type (might be due to invalid IL or missing references)
			//IL_018f: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a5: Unknown result type (might be due to invalid IL or missing references)
			//IL_0134: Unknown result type (might be due to invalid IL or missing references)
			if (!Object.op_Implicit((Object)(object)native))
			{
				return null;
			}
			Shader val = FxBundle.Load<Shader>("Assets/AshIllusion.shader");
			if (!Object.op_Implicit((Object)(object)val) || !val.isSupported)
			{
				throw new InvalidOperationException("Ash illusion shader unavailable");
			}
			Material val2 = new Material(val)
			{
				hideFlags = (HideFlags)61
			};
			val2.SetFloat("_UseAlpha", (float)((native.renderQueue >= 2450 || native.GetTag("RenderType", false, "") == "TransparentCutout") ? 1 : 0));
			string[] array = new string[5] { "_MainTex", "_EmissionMap", "_Color", "_EmissionColor", "_Cutoff" };
			foreach (string text in array)
			{
				if (native.HasProperty(text))
				{
					switch (text)
					{
					case "_MainTex":
					case "_EmissionMap":
						val2.SetTexture(text, native.GetTexture(text));
						val2.SetTextureScale(text, native.GetTextureScale(text));
						val2.SetTextureOffset(text, native.GetTextureOffset(text));
						break;
					case "_Cutoff":
						val2.SetFloat(text, native.GetFloat(text));
						break;
					default:
						val2.SetColor(text, native.GetColor(text));
						break;
					}
				}
			}
			if (native.HasProperty("_EmissiveTex") && Object.op_Implicit((Object)(object)native.GetTexture("_EmissiveTex")))
			{
				val2.SetTexture("_EmissionMap", native.GetTexture("_EmissiveTex"));
				val2.SetTextureScale("_EmissionMap", native.GetTextureScale("_EmissiveTex"));
				val2.SetTextureOffset("_EmissionMap", native.GetTextureOffset("_EmissiveTex"));
			}
			Color color = val2.GetColor("_EmissionColor");
			val2.SetColor("_EmissionColor", color / Mathf.Max(1f, ((Color)(ref color)).maxColorComponent));
			return val2;
		}

		internal static void FadeIllusion(HelNativeVisual model, float fade)
		{
			foreach (Renderer renderer in model.Renderers)
			{
				if (Object.op_Implicit((Object)(object)renderer))
				{
					renderer.GetPropertyBlock(Tint);
					Tint.SetFloat("_Fade", fade);
					renderer.SetPropertyBlock(Tint);
				}
			}
		}

		private static ParticleSystem Particle(string prefab, string branch, Transform parent, bool smoke, float rate, float size)
		{
			GameObject val = Source(prefab);
			Transform val2 = ((!Object.op_Implicit((Object)(object)val)) ? null : ((branch == null) ? val.transform : val.transform.Find(branch)));
			ParticleSystem val3 = (Object.op_Implicit((Object)(object)val2) ? ((Component)val2).GetComponent<ParticleSystem>() : null);
			if (!Object.op_Implicit((Object)(object)val3))
			{
				if (Missing.Add(prefab + "/" + branch))
				{
					Plugin.Log.LogWarning((object)("Ash particle unavailable: " + prefab + "/" + branch));
				}
				return null;
			}
			return Particle(val3, parent, smoke, rate, size);
		}

		private static ParticleSystem Particle(ParticleSystem original, Transform parent, bool smoke, float rate, float size)
		{
			//IL_0011: Unknown result type (might be due to invalid IL or missing references)
			//IL_0016: Unknown result type (might be due to invalid IL or missing references)
			//IL_0040: 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_006c: Unknown result type (might be due to invalid IL or missing references)
			//IL_00aa: Unknown result type (might be due to invalid IL or missing references)
			//IL_008f: 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_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_00c3: 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_00d3: 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_00f8: 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_010f: Unknown result type (might be due to invalid IL or missing references)
			ParticleSystem obj = HelNativeVisual.CopyParticles(original, parent, fog: false);
			obj.Stop(true, (ParticleSystemStopBehavior)0);
			MainModule main = obj.main;
			((MainModule)(ref main)).maxParticles = (smoke ? 64 : 40);
			((MainModule)(ref main)).startLifetime = new MinMaxCurve((float)((!smoke) ? 1 : 2), smoke ? 4f : 2.5f);
			((MainModule)(ref main)).startSize = new MinMaxCurve(size * 0.65f, size);
			((MainModule)(ref main)).startSpeed = new MinMaxCurve(0.04f, 0.14f);
			((MainModule)(ref main)).startColor = MinMaxGradient.op_Implicit(smoke ? new Color(0.38f, 0.34f, 0.3f, 0.3f) : new Color(1f, 0.45f, 0.14f, 0.5f));
			EmissionModule emission = obj.emission;
			((EmissionModule)(ref emission)).rateOverTime = MinMaxCurve.op_Implicit(rate);
			ShapeModule shape = obj.shape;
			((ShapeModule)(ref shape)).shapeType = (ParticleSystemShapeType)5;
			((ShapeModule)(ref shape)).scale = new Vector3(0.65f, 1.25f, 0.4f);
			VelocityOverLifetimeModule velocityOverLifetime = obj.velocityOverLifetime;
			((VelocityOverLifetimeModule)(ref velocityOverLifetime)).y = new MinMaxCurve(smoke ? 0.25f : 0.5f);
			obj.Play();
			return obj;
		}

		private static bool Ensure()
		{
			//IL_009e: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a8: Expected O, but got Unknown
			if (Failed)
			{
				return false;
			}
			if (Object.op_Implicit((Object)(object)Root))
			{
				return true;
			}
			if (!Object.op_Implicit((Object)(object)EnvMan.instance) || !Object.op_Implicit((Object)(object)ZNetScene.instance))
			{
				return false;
			}
			if (!AshNativeSources.Ready())
			{
				return false;
			}
			foreach (EnvSetup environment in EnvMan.instance.m_environments)
			{
				if (environment.m_name == "Ashlands_ashrain")
				{
					Environment = environment;
					break;
				}
			}
			if (Environment == null)
			{
				throw new InvalidOperationException("Native Ashlands_ashrain environment not available");
			}
			Root = new GameObject("VM.Ash.LocalPresentation");
			WorldEffects = new AshWorldEffects(Root.transform);
			Collapse = Particle("smokebomb_explosion", "smoke particles", Root.transform, smoke: true, 0f, 0.8f);
			PreviousDensity = Density;
			NextSurtling = Time.time + 3f;
			NextCorpse = Time.time + 1f;
			NextStone = Time.time + 10f;
			NextColumn = Time.time + 8f;
			Plugin.Log.LogInfo((object)"Ash Body: native Ashlands environment, render-only illusions and local body phase ready.");
			return true;
		}

		private static bool Site(Player player, float min, float max, out Vector3 point)
		{
			//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_002b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0030: Unknown result type (might be due to invalid IL or missing references)
			//IL_0035: Unknown result type (might be due to invalid IL or missing references)
			//IL_003a: 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_0050: 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_006e: Unknown result type (might be due to invalid IL or missing references)
			//IL_006f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0081: Unknown result type (might be due to invalid IL or missing references)
			//IL_0086: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_009f: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cb: 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)
			//IL_0115: Unknown result type (might be due to invalid IL or missing references)
			//IL_011a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0124: Unknown result type (might be due to invalid IL or missing references)
			//IL_0129: Unknown result type (might be due to invalid IL or missing references)
			//IL_013d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0142: Unknown result type (might be due to invalid IL or missing references)
			//IL_016c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0173: Unknown result type (might be due to invalid IL or missing references)
			//IL_0178: Unknown result type (might be due to invalid IL or missing references)
			//IL_0182: Unknown result type (might be due to invalid IL or missing references)
			//IL_0187: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b2: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b7: Unknown result type (might be due to invalid IL or missing references)
			point = Vector3.zero;
			if (((Character)player).InInterior() || !Object.op_Implicit((Object)(object)Camera.main))
			{
				return false;
			}
			Vector3 val = Vector3.ProjectOnPlane(((Component)Camera.main).transform.forward, Vector3.up);
			Vector3 normalized = ((Vector3)(ref val)).normalized;
			RaycastHit val2 = default(RaycastHit);
			for (int i = 0; i < 5; i++)
			{
				if (Physics.Raycast(((Component)player).transform.position + Quaternion.Euler(0f, (float)Random.Range(-65, 65), 0f) * normalized * Random.Range(min, Mathf.Max(min, max)) + Vector3.up * 75f, Vector3.down, ref val2, 150f, LayerMask.GetMask(new string[1] { "terrain" }), (QueryTriggerInteraction)1) && !(((RaycastHit)(ref val2)).normal.y < 0.8f) && !(((RaycastHit)(ref val2)).point.y < (Object.op_Implicit((Object)(object)ZoneSystem.instance) ? ZoneSystem.instance.m_waterLevel : 30f) + 0.3f) && !Physics.CheckBox(((RaycastHit)(ref val2)).point + Vector3.up * 3f, new Vector3(4f, 3f, 4f), Quaternion.identity, LayerMask.GetMask(new string[1] { "piece" }), (QueryTriggerInteraction)1) && !Physics.Linecast(((Component)Camera.main).transform.position, ((RaycastHit)(ref val2)).point + Vector3.up * 2f, LayerMask.GetMask(new string[2] { "terrain", "piece" }), (QueryTriggerInteraction)1))
				{
					point = ((RaycastHit)(ref val2)).point;
					return true;
				}
			}
			return false;
		}

		private static bool CorpseSite(Player player, out Vector3 point)
		{
			//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_002b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0030: Unknown result type (might be due to invalid IL or missing references)
			//IL_0035: Unknown result type (might be due to invalid IL or missing references)
			//IL_003a: 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_0057: Unknown result type (might be due to invalid IL or missing references)
			//IL_005c: Unknown result type (might be due to invalid IL or missing references)
			//IL_008e: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ac: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cb: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d0: 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_00df: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fe: Unknown result type (might be due to invalid IL or missing references)
			//IL_0114: 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_014d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0157: Unknown result type (might be due to invalid IL or missing references)
			//IL_015c: Unknown result type (might be due to invalid IL or missing