Decompiled source of RandomEvents v0.1.1

plugins/com.github.Wesmania.RandomEvents.dll

Decompiled 5 days ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Logging;
using ExitGames.Client.Photon;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using Photon.Pun;
using Photon.Realtime;
using TMPro;
using UnityEngine;
using UnityEngine.Networking;
using UnityEngine.UI;
using Zorro.Core;
using pworld.Scripts.Extensions;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: IgnoresAccessChecksTo("Assembly-CSharp")]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("com.github.Wesmania.RandomEvents")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("0.1.1.0")]
[assembly: AssemblyInformationalVersion("0.1.1+6f19dfb13c8aab928916c75413af5d8e4e8c8cc0")]
[assembly: AssemblyProduct("com.github.Wesmania.RandomEvents")]
[assembly: AssemblyTitle("RandomEvents")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("0.1.1.0")]
[module: UnverifiableCode]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	[AttributeUsage(AttributeTargets.Class | AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Event | AttributeTargets.Parameter | AttributeTargets.ReturnValue | AttributeTargets.GenericParameter, AllowMultiple = false, Inherited = false)]
	internal sealed class NullableAttribute : Attribute
	{
		public readonly byte[] NullableFlags;

		public NullableAttribute(byte P_0)
		{
			NullableFlags = new byte[1] { P_0 };
		}

		public NullableAttribute(byte[] P_0)
		{
			NullableFlags = P_0;
		}
	}
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	[AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Method | AttributeTargets.Interface | AttributeTargets.Delegate, AllowMultiple = false, Inherited = false)]
	internal sealed class NullableContextAttribute : Attribute
	{
		public readonly byte Flag;

		public NullableContextAttribute(byte P_0)
		{
			Flag = P_0;
		}
	}
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.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 BepInEx
{
	[AttributeUsage(AttributeTargets.Class, Inherited = false, AllowMultiple = false)]
	[Conditional("CodeGeneration")]
	internal sealed class BepInAutoPluginAttribute : Attribute
	{
		public BepInAutoPluginAttribute(string? id = null, string? name = null, string? version = null)
		{
		}
	}
}
namespace BepInEx.Preloader.Core.Patching
{
	[AttributeUsage(AttributeTargets.Class, Inherited = false, AllowMultiple = false)]
	[Conditional("CodeGeneration")]
	internal sealed class PatcherAutoPluginAttribute : Attribute
	{
		public PatcherAutoPluginAttribute(string? id = null, string? name = null, string? version = null)
		{
		}
	}
}
namespace RandomEvents
{
	internal static class Stuff
	{
		public static void NewEvents(bool is_first, OurBiome biome)
		{
			if (Messages.IsMaster())
			{
				string text = Plugin.pick_events.PickNewEvents(is_first, biome);
				if (text != null)
				{
					Plugin.m.SendEvent(MessageType.STOP_EVENTS, "", (ReceiverGroup)1, reliable: true);
					Plugin.m.SendEvent(MessageType.NEW_EVENTS, text, (ReceiverGroup)1, reliable: true);
				}
			}
		}
	}
	[HarmonyPatch(typeof(AirportCheckInKiosk), "LoadIslandMaster")]
	public static class ChangeMapPatch1
	{
		public static void Postfix(AirportCheckInKiosk __instance, int ascent)
		{
			Stuff.NewEvents(is_first: true, OurBiome.Shore);
		}
	}
	[HarmonyPatch(typeof(Campfire))]
	public static class ChangeMapPatch2
	{
		[HarmonyPostfix]
		[HarmonyPatch("Light_Rpc")]
		public static void LightPostfix(Campfire __instance)
		{
			//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_001d: Unknown result type (might be due to invalid IL or missing references)
			//IL_001f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0024: Unknown result type (might be due to invalid IL or missing references)
			//IL_0025: Unknown result type (might be due to invalid IL or missing references)
			//IL_0026: Unknown result type (might be due to invalid IL or missing references)
			MapHandler instance = Singleton<MapHandler>.Instance;
			if (!((Object)(object)instance == (Object)null))
			{
				Segment advanceToSegment = __instance.advanceToSegment;
				BiomeType biome = instance.segments[advanceToSegment].biome;
				OurBiome biome2 = BiomeConv.FromSegmentBiome(advanceToSegment, biome);
				Stuff.NewEvents(is_first: false, biome2);
			}
		}
	}
	public class EventInterface
	{
		private List<NiceText> start_texts = new List<NiceText>();

		public bool is_first;

		public void AddEnableLine(NiceText line)
		{
			start_texts.Add(line);
		}

		public void AddEnableLine(string line)
		{
			//IL_000e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0013: Unknown result type (might be due to invalid IL or missing references)
			AddEnableLine(new NiceText
			{
				s = line,
				c = Color.white
			});
		}

		public void RunInterface(float delay)
		{
			SoulmateTextPatch.setter?.ShowCard(start_texts, delay);
			start_texts.Clear();
		}
	}
	public enum OurBiome
	{
		Shore,
		Tropics,
		Roots,
		Alpine,
		Mesa,
		Caldera,
		Kiln,
		Peak
	}
	public struct IEventFactory
	{
		public Func<OurBiome, IEvent> New;

		public Func<JObject, IEvent> FromJson;
	}
	public enum AllEvents
	{
		GREAT_MAGICIAN = 1,
		EMISSIONS,
		CURSE_DAMAGE,
		FREE_BALLOON,
		NO_SCUTTLING,
		SUPER_RESCUE_HOOKS,
		DOOM_MODE,
		FROSTBITE,
		BOUNCY,
		ALL_SHROOMS
	}
	public static class BiomeConv
	{
		public static OurBiome FromSegmentBiome(Segment s, BiomeType b)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_001e: Expected I4, but got Unknown
			//IL_0026: Unknown result type (might be due to invalid IL or missing references)
			//IL_0028: Invalid comparison between Unknown and I4
			//IL_002e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0030: Invalid comparison between Unknown and I4
			switch ((int)s)
			{
			case 3:
				return OurBiome.Caldera;
			case 4:
				return OurBiome.Kiln;
			case 5:
				return OurBiome.Peak;
			case 1:
				if ((int)b == 7)
				{
					return OurBiome.Roots;
				}
				return OurBiome.Tropics;
			case 2:
				if ((int)b == 2)
				{
					return OurBiome.Alpine;
				}
				return OurBiome.Mesa;
			default:
				return OurBiome.Shore;
			}
		}
	}
	public interface IEvent
	{
		static Dictionary<AllEvents, IEventFactory> all_events = new Dictionary<AllEvents, IEventFactory>
		{
			{
				AllEvents.GREAT_MAGICIAN,
				GreatMagicianEvent.factory()
			},
			{
				AllEvents.EMISSIONS,
				HeatEmissionEvent.factory()
			},
			{
				AllEvents.CURSE_DAMAGE,
				CurseDamageEvent.factory()
			},
			{
				AllEvents.FREE_BALLOON,
				FreeBalloonEvent.factory()
			},
			{
				AllEvents.NO_SCUTTLING,
				NoScuttlingEvent.factory()
			},
			{
				AllEvents.SUPER_RESCUE_HOOKS,
				SuperRescueHookEvent.factory()
			},
			{
				AllEvents.DOOM_MODE,
				DoomModeEvent.factory()
			},
			{
				AllEvents.FROSTBITE,
				FrostbiteEvent.factory()
			},
			{
				AllEvents.BOUNCY,
				BouncyEvent.factory()
			},
			{
				AllEvents.ALL_SHROOMS,
				AllShroomsEvent.factory()
			}
		};

		JObject to_json();

		void Enable(EventInterface eintf);

		void LateEnable(EventInterface eintf)
		{
		}

		void Disable(EventInterface eintf);

		HashSet<OurBiome> ZoneLimit()
		{
			return new HashSet<OurBiome>();
		}

		HashSet<AllEvents> ExcludeEvents()
		{
			return new HashSet<AllEvents>();
		}
	}
	public struct EnableMessage
	{
		public Dictionary<AllEvents, JObject> events;

		public bool is_first;
	}
	public class LateEventCaller : MonoBehaviour
	{
		public void LoadEvents(List<IEvent> events, EventInterface eintf, float delay)
		{
			((MonoBehaviour)this).StartCoroutine(DoLoadEvents(events, eintf, delay));
		}

		private IEnumerator DoLoadEvents(List<IEvent> events, EventInterface eintf, float delay)
		{
			yield return (object)new WaitForSeconds(delay);
			foreach (IEvent @event in events)
			{
				@event.LateEnable(eintf);
			}
		}
	}
	public class PickEvents
	{
		private static int EVENT_COUNT = 2;

		private List<IEvent> events = new List<IEvent>();

		public bool is_first = true;

		public string? PickNewEvents(bool is_first, OurBiome biome)
		{
			if (!Messages.IsMaster())
			{
				return null;
			}
			List<AllEvents> source = Enum.GetValues(typeof(AllEvents)).Cast<AllEvents>().ToList();
			List<(AllEvents, IEvent)> list = (from e in source
				select (e, IEvent.all_events[e].New(biome)) into e
				where e.e.ZoneLimit().Count == 0 || e.e.ZoneLimit().Contains(biome)
				select e).ToList();
			ExtCollections.Shuffle<(AllEvents, IEvent)>((IList<(AllEvents, IEvent)>)list);
			HashSet<AllEvents> excludes = new HashSet<AllEvents>();
			HashSet<AllEvents> already_selected = new HashSet<AllEvents>();
			List<(AllEvents, IEvent)> source2 = list.Where<(AllEvents, IEvent)>(delegate((AllEvents id, IEvent e) e)
			{
				if (excludes.Contains(e.id))
				{
					return false;
				}
				HashSet<AllEvents> hashSet = e.e.ExcludeEvents();
				if (!hashSet.Any())
				{
					already_selected.Add(e.id);
					return true;
				}
				if (hashSet.Intersect(already_selected).Count() > 0)
				{
					return false;
				}
				excludes.UnionWith(hashSet);
				already_selected.Add(e.id);
				return true;
			}).ToList();
			Dictionary<AllEvents, JObject> dictionary = (from e in source2.Take(Math.Min(EVENT_COUNT, list.Count()))
				select (e.id, e.e.to_json())).ToDictionary<(AllEvents, JObject), AllEvents, JObject>(((AllEvents id, JObject json) e) => e.id, ((AllEvents id, JObject json) e) => e.json);
			EnableMessage enableMessage = default(EnableMessage);
			enableMessage.events = dictionary;
			enableMessage.is_first = is_first;
			EnableMessage enableMessage2 = enableMessage;
			return JsonConvert.SerializeObject((object)enableMessage2);
		}

		public void UnloadEvents(EventInterface eintf)
		{
			foreach (IEvent @event in events)
			{
				@event.Disable(eintf);
			}
			events = new List<IEvent>();
		}

		public void LoadNewEvents(string s, EventInterface eintf)
		{
			EnableMessage enableMessage = JsonConvert.DeserializeObject<EnableMessage>(s);
			is_first = enableMessage.is_first;
			eintf.is_first = is_first;
			events = enableMessage.events.Select<KeyValuePair<AllEvents, JObject>, IEvent>((KeyValuePair<AllEvents, JObject> kv) => IEvent.all_events[kv.Key].FromJson(kv.Value)).ToList();
			foreach (IEvent @event in events)
			{
				@event.Enable(eintf);
			}
			GlobalBehaviours.late_events.LoadEvents(events, eintf, is_first ? 15f : 0f);
		}
	}
	public class AllShroomsGlobals
	{
		public static bool enabled = false;

		public static bool in_check = false;

		private static List<string> prefab_names = new List<string>(5) { "Shroomberry_Red", "Shroomberry_Yellow", "Shroomberry_Green", "Shroomberry_Blue", "Shroomberry_Purple" };

		private static List<GameObject>? shroom_objs = null;

		private static List<GameObject> get_shroom_objs()
		{
			if (shroom_objs == null)
			{
				shroom_objs = prefab_names.Select(delegate(string name)
				{
					//IL_0000: Unknown result type (might be due to invalid IL or missing references)
					//IL_0006: Expected O, but got Unknown
					GameObject val = new GameObject();
					((Object)val).name = name;
					return val;
				}).ToList();
			}
			return shroom_objs;
		}

		public static List<GameObject> getShrooms(int count, bool canRepeat)
		{
			List<GameObject> source = get_shroom_objs();
			List<GameObject> list = source.ToList();
			List<GameObject> list2 = new List<GameObject>();
			for (int i = 0; i < count; i++)
			{
				GameObject item = Util.RandomSelection<GameObject>((IEnumerable<GameObject>)list, (Func<GameObject, int>)((GameObject _) => 1));
				list2.Add(item);
				if (!canRepeat)
				{
					if (list.Count <= 1)
					{
						list = source.ToList();
					}
					list.Remove(item);
				}
			}
			return list2;
		}
	}
	[HarmonyPatch(typeof(SpawnList), "GetSpawns")]
	public class AllShroomSpawnPatch
	{
		private static bool Prefix(SpawnList __instance, int count, bool canRepeat, ref List<GameObject> __result)
		{
			if (AllShroomsGlobals.enabled && AllShroomsGlobals.in_check)
			{
				__result = AllShroomsGlobals.getShrooms(count, canRepeat);
				return false;
			}
			return true;
		}
	}
	[HarmonyPatch(typeof(LootData), "GetRandomItem")]
	public class AllShroomsLootPatch
	{
		public static bool Prefix(SpawnPool spawnPool, ref GameObject __result)
		{
			if (AllShroomsGlobals.enabled && AllShroomsGlobals.in_check)
			{
				List<GameObject> shrooms = AllShroomsGlobals.getShrooms(1, canRepeat: true);
				__result = shrooms[0];
				return false;
			}
			return true;
		}
	}
	[HarmonyPatch(typeof(GroundPlaceSpawner), "SpawnItems")]
	public class AllShroomsGroundHook
	{
		private static void Prefix(GroundPlaceSpawner __instance, List<Transform> spawnSpots)
		{
			AllShroomsGlobals.in_check = true;
		}

		private static void Postfix(GroundPlaceSpawner __instance, List<Transform> spawnSpots)
		{
			AllShroomsGlobals.in_check = false;
		}
	}
	[HarmonyPatch(typeof(BerryBush), "SpawnItems")]
	public class AllShroomsBerryBushHook
	{
		private static void Prefix(BerryBush __instance, List<Transform> spawnSpots)
		{
			AllShroomsGlobals.in_check = true;
		}

		private static void Postfix(BerryBush __instance, List<Transform> spawnSpots)
		{
			AllShroomsGlobals.in_check = false;
		}
	}
	[HarmonyPatch(typeof(BerryVine), "SpawnItems")]
	public class AllShroomsBerryVineHook
	{
		private static void Prefix(BerryVine __instance, List<Transform> spawnSpots)
		{
			AllShroomsGlobals.in_check = true;
		}

		private static void Postfix(BerryVine __instance, List<Transform> spawnSpots)
		{
			AllShroomsGlobals.in_check = false;
		}
	}
	public class AllShroomsEvent : IEvent
	{
		public void Disable(EventInterface eintf)
		{
			AllShroomsGlobals.enabled = false;
		}

		public void Enable(EventInterface eintf)
		{
			eintf.AddEnableLine("All natural food is shroomberries.");
			AllShroomsGlobals.enabled = true;
		}

		public JObject to_json()
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0006: Expected O, but got Unknown
			return new JObject();
		}

		public static IEventFactory factory()
		{
			IEventFactory result = default(IEventFactory);
			result.New = (OurBiome _) => new AllShroomsEvent();
			result.FromJson = (JObject _) => new AllShroomsEvent();
			return result;
		}

		public HashSet<OurBiome> ZoneLimit()
		{
			return new HashSet<OurBiome>
			{
				OurBiome.Shore,
				OurBiome.Tropics,
				OurBiome.Roots,
				OurBiome.Alpine,
				OurBiome.Mesa
			};
		}
	}
	[HarmonyPatch(typeof(Character), "OnLand")]
	public class CharacterLandPatch
	{
		public static bool enabled;

		private static bool nested;

		private static void Postfix(Character __instance, float sinceGrounded)
		{
			//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_00ba: Unknown result type (might be due to invalid IL or missing references)
			if (enabled && !nested)
			{
				nested = true;
				Plugin.Log.LogInfo((object)"Bounce start");
				float knockback = 5000f;
				Parasol val = default(Parasol);
				if (Object.op_Implicit((Object)(object)__instance.data.currentItem) && ((Component)__instance.data.currentItem).TryGetComponent<Parasol>(ref val) && val.isOpen)
				{
					knockback = 1000f;
				}
				if (__instance.data.fallSeconds > 0f || __instance.refs.afflictions.shouldPassOut)
				{
					knockback = 0f;
				}
				__instance.AddStamina(0.2f);
				Vector3 groundNormal = __instance.data.groundNormal;
				SmoothBounce smoothBounce = ((Component)__instance).GetComponent<SmoothBounce>() ?? ((Component)__instance).gameObject.AddComponent<SmoothBounce>();
				((MonoBehaviour)smoothBounce).StartCoroutine(smoothBounce.BounceRoutine(knockback, __instance, groundNormal));
				Plugin.Log.LogInfo((object)"Bounce end");
				nested = false;
			}
		}
	}
	public class SmoothBounce : MonoBehaviour
	{
		public IEnumerator BounceRoutine(float knockback, Character character, Vector3 kb)
		{
			//IL_0015: Unknown result type (might be due to invalid IL or missing references)
			//IL_0016: Unknown result type (might be due to invalid IL or missing references)
			float t = 0f;
			while (t < 1f)
			{
				Plugin.Log.LogInfo((object)$"Bounce t={t}");
				character.AddForce(kb * knockback * (1f - t) * Time.fixedDeltaTime, 1f, 1f);
				character.data.sinceGrounded = Mathf.Clamp(character.data.sinceGrounded, 0f, 0.5f);
				t += Time.fixedDeltaTime;
				yield return (object)new WaitForFixedUpdate();
			}
		}
	}
	public class BouncyEvent : IEvent
	{
		public void Disable(EventInterface eintf)
		{
			CharacterLandPatch.enabled = false;
		}

		public void Enable(EventInterface eintf)
		{
			CharacterLandPatch.enabled = true;
			eintf.AddEnableLine("All scouts are bouncy.");
		}

		public JObject to_json()
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0006: Expected O, but got Unknown
			return new JObject();
		}

		public static IEventFactory factory()
		{
			IEventFactory result = default(IEventFactory);
			result.New = (OurBiome _) => new BouncyEvent();
			result.FromJson = (JObject _) => new BouncyEvent();
			return result;
		}
	}
	public static class Extensions
	{
		private static HashSet<STATUSTYPE> NonCursables = new HashSet<STATUSTYPE>
		{
			(STATUSTYPE)7,
			(STATUSTYPE)9,
			(STATUSTYPE)1,
			(STATUSTYPE)5,
			(STATUSTYPE)11
		};

		public static bool isCursable(this STATUSTYPE t)
		{
			//IL_0005: Unknown result type (might be due to invalid IL or missing references)
			return !NonCursables.Contains(t);
		}
	}
	[HarmonyPatch(typeof(CharacterAfflictions))]
	public class SharedDamagePatch
	{
		public static bool enabled = false;

		private static float multiplier = 0.05f;

		private static float too_much_curse = 0.5f;

		[HarmonyPrefix]
		[HarmonyPatch("SetStatus", new Type[]
		{
			typeof(STATUSTYPE),
			typeof(float),
			typeof(bool)
		})]
		public static void SetStatusPrefix(CharacterAfflictions __instance, ref STATUSTYPE statusType, ref float amount, bool pushStatus)
		{
			if (!enabled || !statusType.isCursable())
			{
				return;
			}
			float currentStatus = __instance.GetCurrentStatus(statusType);
			if (!(currentStatus > amount))
			{
				float num = (amount - currentStatus) * multiplier;
				float num2 = __instance.GetCurrentStatus((STATUSTYPE)5) + num;
				if (!(num2 > too_much_curse))
				{
					statusType = (STATUSTYPE)5;
					amount = num2;
				}
			}
		}

		[HarmonyPrefix]
		[HarmonyPatch("AddStatus", new Type[]
		{
			typeof(STATUSTYPE),
			typeof(float),
			typeof(bool),
			typeof(bool)
		})]
		public static void AddStatusPrefix(CharacterAfflictions __instance, ref STATUSTYPE statusType, ref float amount, bool fromRPC, ref bool playEffects)
		{
			if (!enabled || !statusType.isCursable() || amount < 0f)
			{
				return;
			}
			float num = __instance.GetCurrentStatus((STATUSTYPE)5) + amount * multiplier;
			if (!(num > too_much_curse))
			{
				statusType = (STATUSTYPE)5;
				amount *= multiplier;
				if ((double)amount < 0.025)
				{
					playEffects = false;
				}
			}
		}

		[HarmonyPrefix]
		[HarmonyPatch("SubtractStatus", new Type[]
		{
			typeof(STATUSTYPE),
			typeof(float),
			typeof(bool),
			typeof(bool)
		})]
		public static void SubtractStatusPrefix(CharacterAfflictions __instance, ref STATUSTYPE statusType, ref float amount, bool fromRPC, bool decreasedNaturally)
		{
			if (enabled && statusType.isCursable() && !(amount > 0f))
			{
				float num = __instance.GetCurrentStatus((STATUSTYPE)5) - amount * multiplier;
				if (!(num > too_much_curse))
				{
					statusType = (STATUSTYPE)5;
					amount *= multiplier;
				}
			}
		}
	}
	public class CurseDamageEvent : IEvent
	{
		public void Disable(EventInterface eintf)
		{
			SharedDamagePatch.enabled = false;
		}

		public void Enable(EventInterface eintf)
		{
			//IL_0012: Unknown result type (might be due to invalid IL or missing references)
			//IL_0017: Unknown result type (might be due to invalid IL or missing references)
			//IL_0033: 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)
			eintf.AddEnableLine(new NiceText
			{
				s = "All damage is reduced by 95%.",
				c = Color.green
			});
			eintf.AddEnableLine(new NiceText
			{
				s = "All damage is curse damage.",
				c = Color.red
			});
			SharedDamagePatch.enabled = true;
		}

		public JObject to_json()
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0006: Expected O, but got Unknown
			return new JObject();
		}

		public static IEventFactory factory()
		{
			IEventFactory result = default(IEventFactory);
			result.New = (OurBiome _) => new CurseDamageEvent();
			result.FromJson = (JObject _) => new CurseDamageEvent();
			return result;
		}

		public HashSet<AllEvents> Conflicts()
		{
			return new HashSet<AllEvents>
			{
				AllEvents.FROSTBITE,
				AllEvents.EMISSIONS
			};
		}
	}
	[HarmonyPatch(typeof(CharacterMovement), "GetMovementForce")]
	public class MovementSpeedPatch
	{
		public static bool doom_mode;

		private static void Postfix(CharacterMovement __instance, ref float __result)
		{
			if (doom_mode)
			{
				__result *= 2.5f;
			}
		}
	}
	[HarmonyPatch(typeof(CharacterMovement), "TryToJump")]
	public class JumpPatch
	{
		public static bool doom_mode;

		private static bool Prefix(CharacterMovement __instance)
		{
			bool? flag = __instance.character.refs?.afflictions.isWebbed;
			if (flag.HasValue && flag.Value)
			{
				return true;
			}
			return !doom_mode;
		}
	}
	public class DoomMusic : MonoBehaviour
	{
		private AudioClip? e1m1;

		private GameObject? musicObj;

		public void Start()
		{
			((MonoBehaviour)this).StartCoroutine(GetMusic());
		}

		private IEnumerator GetMusic()
		{
			string text = "file://" + Application.dataPath + "/../BepInEx/plugins/RandomEvents_e1m1.mp3";
			UnityWebRequest e1m1r = UnityWebRequestMultimedia.GetAudioClip(text, (AudioType)13);
			try
			{
				yield return e1m1r.SendWebRequest();
				if ((int)e1m1r.result == 1)
				{
					e1m1 = DownloadHandlerAudioClip.GetContent(e1m1r);
				}
				else
				{
					Plugin.Log.LogError((object)"No doom music!");
				}
			}
			finally
			{
				((IDisposable)e1m1r)?.Dispose();
			}
		}

		public void TriggerMusic()
		{
			((MonoBehaviour)this).StartCoroutine(DoTriggerMusic());
		}

		private IEnumerator DoTriggerMusic()
		{
			yield return (object)new WaitForSeconds(15f);
			if ((Object)(object)e1m1 != (Object)null)
			{
				if ((Object)(object)musicObj != (Object)null)
				{
					Object.Destroy((Object)(object)musicObj);
				}
				musicObj = new GameObject("RandomEventsDoomModeMusic");
				AudioSource val = musicObj.AddComponent<AudioSource>();
				val.clip = e1m1;
				val.volume = 0.5f;
				val.Play();
			}
		}
	}
	public class DoomModeEvent : IEvent
	{
		public void Disable(EventInterface eintf)
		{
			MovementSpeedPatch.doom_mode = false;
			JumpPatch.doom_mode = false;
		}

		public void Enable(EventInterface eintf)
		{
			eintf.AddEnableLine("DOOM mode!");
			MovementSpeedPatch.doom_mode = true;
			JumpPatch.doom_mode = true;
			GlobalBehaviours.doom_music?.TriggerMusic();
		}

		public JObject to_json()
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0006: Expected O, but got Unknown
			return new JObject();
		}

		public static IEventFactory factory()
		{
			IEventFactory result = default(IEventFactory);
			result.New = (OurBiome _) => new DoomModeEvent();
			result.FromJson = (JObject _) => new DoomModeEvent();
			return result;
		}
	}
	[HarmonyPatch(typeof(TiedBalloon))]
	public class TiedBalloonPatch
	{
		private static TiedBalloon? my_balloon;

		[HarmonyPrefix]
		[HarmonyPatch("Pop")]
		private static bool PopPrefix(TiedBalloon __instance)
		{
			if (__instance == my_balloon)
			{
				__instance.popHeight += 100f;
				__instance.popTime += 100f;
				return false;
			}
			return true;
		}

		public static void AddPermaBalloonToMe()
		{
			//IL_0049: Unknown result type (might be due to invalid IL or missing references)
			//IL_004e: Unknown result type (might be due to invalid IL or missing references)
			//IL_006b: 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)
			if ((Object)(object)my_balloon != (Object)null)
			{
				return;
			}
			Character localCharacter = Character.localCharacter;
			if (!((Object)(object)localCharacter == (Object)null))
			{
				Character val = localCharacter;
				CharacterBalloons balloons = val.refs.balloons;
				SFX_Instance[] balloonTie = balloons.balloonTie;
				int num = Random.Range(0, balloons.balloonColors.Length);
				my_balloon = PhotonNetwork.Instantiate("TiedBalloon", val.Center, Quaternion.identity, (byte)0, (object[])null).GetComponent<TiedBalloon>();
				my_balloon.Init(balloons, val.Center.y, num);
				for (int i = 0; i < balloonTie.Length; i++)
				{
					balloonTie[i].Play(val.Center);
				}
			}
		}

		public static void RemovePermaBalloonFromMe()
		{
			if (!((Object)(object)my_balloon == (Object)null))
			{
				TiedBalloon val = my_balloon;
				my_balloon = null;
				val.Pop();
			}
		}
	}
	public class FreeBalloonEvent : IEvent
	{
		public void Disable(EventInterface eintf)
		{
			TiedBalloonPatch.RemovePermaBalloonFromMe();
		}

		public void Enable(EventInterface eintf)
		{
			eintf.AddEnableLine("Everyone gets a free balloon :)");
		}

		public void LateEnable(EventInterface eintf)
		{
			TiedBalloonPatch.AddPermaBalloonToMe();
		}

		public JObject to_json()
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0006: Expected O, but got Unknown
			return new JObject();
		}

		public static IEventFactory factory()
		{
			IEventFactory result = default(IEventFactory);
			result.New = (OurBiome _) => new FreeBalloonEvent();
			result.FromJson = (JObject _) => new FreeBalloonEvent();
			return result;
		}
	}
	[HarmonyPatch(typeof(CharacterAfflictions))]
	public class FrostbitePatch
	{
		public static FrostbitePatch instance = new FrostbitePatch();

		public bool enabled;

		public STATUSTYPE kind = (STATUSTYPE)2;

		private float lastTick = Time.time;

		private static float threshold = 0.5f;

		private float damageChance()
		{
			float time = Time.time;
			float num = lastTick;
			return Math.Min(time - num, 2f) * 0.15f;
		}

		[HarmonyPrefix]
		[HarmonyPatch("SubtractStatus", new Type[]
		{
			typeof(STATUSTYPE),
			typeof(float),
			typeof(bool),
			typeof(bool)
		})]
		public static void SubtractStatusPrefix(CharacterAfflictions __instance, STATUSTYPE statusType, float amount, bool fromRPC, bool decreasedNaturally, out float __state)
		{
			//IL_001d: Unknown result type (might be due to invalid IL or missing references)
			if (!instance.enabled)
			{
				__state = -1f;
			}
			else
			{
				__state = __instance.GetCurrentStatus(instance.kind);
			}
		}

		[HarmonyPostfix]
		[HarmonyPatch("SubtractStatus", new Type[]
		{
			typeof(STATUSTYPE),
			typeof(float),
			typeof(bool),
			typeof(bool)
		})]
		public static void SubtractStatusPostfix(CharacterAfflictions __instance, STATUSTYPE statusType, float amount, bool fromRPC, bool decreasedNaturally, float __state)
		{
			//IL_0010: Unknown result type (might be due to invalid IL or missing references)
			//IL_002c: Unknown result type (might be due to invalid IL or missing references)
			if (__state == -1f)
			{
				return;
			}
			float currentStatus = __instance.GetCurrentStatus(instance.kind);
			if (currentStatus < threshold)
			{
				return;
			}
			float num = __state - __instance.GetCurrentStatus(instance.kind);
			if (!(num < 0.0249f) && !(num > 0.0251f))
			{
				Plugin.Log.LogInfo((object)$"Chance {instance.damageChance()}");
				if (Random.Range(0f, 1f) <= instance.damageChance())
				{
					__instance.AddStatus((STATUSTYPE)0, 0.025f, false, false);
				}
				instance.lastTick = Time.time;
			}
		}

		[HarmonyPrefix]
		[HarmonyPatch("AddStatus", new Type[]
		{
			typeof(STATUSTYPE),
			typeof(float),
			typeof(bool),
			typeof(bool)
		})]
		public static void AddStatusPrefix(CharacterAfflictions __instance, ref STATUSTYPE statusType, ref float amount, bool fromRPC, ref bool playEffects)
		{
			//IL_0014: Unknown result type (might be due to invalid IL or missing references)
			//IL_0019: Invalid comparison between I4 and Unknown
			//IL_0022: Unknown result type (might be due to invalid IL or missing references)
			if (instance.enabled && (int)statusType == (int)instance.kind)
			{
				float currentStatus = __instance.GetCurrentStatus(instance.kind);
				if (currentStatus < threshold && currentStatus + amount >= threshold)
				{
					instance.lastTick = Time.time;
				}
			}
		}
	}
	public enum FrostbiteType
	{
		FROSTBITE,
		BURNS
	}
	public class FrostbiteEvent : IEvent
	{
		private FrostbiteType f;

		private FrostbiteEvent(FrostbiteType _f)
		{
			f = _f;
		}

		public HashSet<OurBiome> ZoneLimit()
		{
			return new HashSet<OurBiome>
			{
				OurBiome.Alpine,
				OurBiome.Mesa,
				OurBiome.Caldera,
				OurBiome.Kiln
			};
		}

		private FrostbiteEvent(OurBiome b)
		{
			f = ((b != OurBiome.Alpine) ? FrostbiteType.BURNS : FrostbiteType.FROSTBITE);
		}

		private static (string, string, Color) Fstr(FrostbiteType f)
		{
			//IL_0024: 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)
			if (f == FrostbiteType.FROSTBITE)
			{
				return ("Cold", "frostbite", Color.cyan);
			}
			return ("Heat", "burns", Color.red);
		}

		private static STATUSTYPE ToStatType(FrostbiteType f)
		{
			return (STATUSTYPE)(f switch
			{
				FrostbiteType.FROSTBITE => 2, 
				_ => 8, 
			});
		}

		public void Disable(EventInterface eintf)
		{
			FrostbitePatch.instance.enabled = false;
		}

		public void Enable(EventInterface eintf)
		{
			//IL_000b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0010: Unknown result type (might be due to invalid IL or missing references)
			//IL_0039: Unknown result type (might be due to invalid IL or missing references)
			//IL_003e: Unknown result type (might be due to invalid IL or missing references)
			//IL_005d: Unknown result type (might be due to invalid IL or missing references)
			//IL_005e: Unknown result type (might be due to invalid IL or missing references)
			FrostbitePatch.instance.kind = ToStatType(f);
			FrostbitePatch.instance.enabled = true;
			var (text, text2, c) = Fstr(f);
			eintf.AddEnableLine(new NiceText
			{
				s = text + " might cause " + text2 + ".",
				c = c
			});
		}

		public static IEventFactory factory()
		{
			IEventFactory result = default(IEventFactory);
			result.New = (OurBiome b) => new FrostbiteEvent(b);
			result.FromJson = delegate(JObject o)
			{
				FrostbiteType valueOrDefault = (FrostbiteType)((int?)o.GetValue("f")).GetValueOrDefault(9);
				return new FrostbiteEvent(valueOrDefault);
			};
			return result;
		}

		public JObject to_json()
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0006: Expected O, but got Unknown
			JObject val = new JObject();
			val.Add("f", JToken.op_Implicit((int)f));
			return val;
		}
	}
	[HarmonyPatch(typeof(CharacterClimbing), "StartClimbRpc")]
	public class CharacterClimbingPatch
	{
		public static bool allow_scuttling = true;

		private static bool Prefix(CharacterClimbing __instance, Vector3 climbPos, Vector3 climbNormal)
		{
			//IL_001e: Unknown result type (might be due to invalid IL or missing references)
			//IL_001f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0020: 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_003a: 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_0049: Unknown result type (might be due to invalid IL or missing references)
			//IL_004a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0050: Unknown result type (might be due to invalid IL or missing references)
			//IL_0055: Unknown result type (might be due to invalid IL or missing references)
			//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_0122: Unknown result type (might be due to invalid IL or missing references)
			//IL_0127: Unknown result type (might be due to invalid IL or missing references)
			//IL_0137: Unknown result type (might be due to invalid IL or missing references)
			//IL_0138: Unknown result type (might be due to invalid IL or missing references)
			//IL_0148: Unknown result type (might be due to invalid IL or missing references)
			//IL_0149: Unknown result type (might be due to invalid IL or missing references)
			//IL_007c: Unknown result type (might be due to invalid IL or missing references)
			//IL_007d: Unknown result type (might be due to invalid IL or missing references)
			float num = 0f;
			if (__instance.character.data.hasClimbedSinceGrounded)
			{
				Vector3 val = __instance.GetVisualClimberPos(climbPos, climbNormal) - (__instance.character.Center + Vector3.up * 0.5f);
				val = Vector3.ProjectOnPlane(val * 1.5f, climbNormal);
				float num2 = ((Vector3)(ref val)).magnitude;
				float num3 = (allow_scuttling ? 0f : ((0f - num2) / 2f));
				if (Vector3.Dot(val, Vector3.up) < num3)
				{
					num2 = 0f;
				}
				num2 = Mathf.Max(num2, 0.1f);
				__instance.character.UseStamina(0.15f * num2, true);
				if (__instance.character.OutOfStamina())
				{
					num += (0f - num2) * __instance.outOfStamAttachSlide;
				}
			}
			if (__instance.character.data.avarageVelocity.y < 0f)
			{
				num += __instance.character.data.avarageVelocity.y * 1.5f;
			}
			__instance.character.OutOfStamina();
			__instance.playerSlide = new Vector2(__instance.playerSlide.x, num);
			__instance.character.data.climbPos = climbPos;
			__instance.character.data.climbNormal = climbNormal;
			__instance.character.data.hasClimbedSinceGrounded = true;
			__instance.character.data.isClimbing = true;
			__instance.character.data.isGrounded = false;
			__instance.character.data.sinceStartClimb = 0f;
			__instance.character.OnStartClimb();
			return false;
		}
	}
	public class NoScuttlingEvent : IEvent
	{
		public void Disable(EventInterface eintf)
		{
			CharacterClimbingPatch.allow_scuttling = true;
		}

		public void Enable(EventInterface eintf)
		{
			eintf.AddEnableLine("No scuttling!");
			CharacterClimbingPatch.allow_scuttling = false;
		}

		public JObject to_json()
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0006: Expected O, but got Unknown
			return new JObject();
		}

		public static IEventFactory factory()
		{
			IEventFactory result = default(IEventFactory);
			result.New = (OurBiome _) => new NoScuttlingEvent();
			result.FromJson = (JObject _) => new NoScuttlingEvent();
			return result;
		}
	}
	public enum EmissionType
	{
		HEAT,
		COLD,
		ENERGY
	}
	public class PlayerEmission
	{
		public EmissionType emitting_e;

		private static Dictionary<Color, EmissionType>? colors = null;

		private static Dictionary<SkinColor, EmissionType> s2e = new Dictionary<SkinColor, EmissionType>
		{
			{
				SkinColor.RED,
				EmissionType.HEAT
			},
			{
				SkinColor.ORANGE,
				EmissionType.HEAT
			},
			{
				SkinColor.PINK,
				EmissionType.HEAT
			},
			{
				SkinColor.BLUE,
				EmissionType.COLD
			},
			{
				SkinColor.PURPLE,
				EmissionType.COLD
			},
			{
				SkinColor.CYAN,
				EmissionType.COLD
			},
			{
				SkinColor.GREEN,
				EmissionType.ENERGY
			},
			{
				SkinColor.LIME,
				EmissionType.ENERGY
			},
			{
				SkinColor.YELLOW,
				EmissionType.ENERGY
			}
		};

		public PlayerEmission(EmissionType _e)
		{
			emitting_e = _e;
		}

		private Dictionary<Color, EmissionType> GetColors()
		{
			if (colors == null)
			{
				colors = Singleton<Customization>.Instance.skins.Select((CustomizationOption x, int i) => (x.color, s2e[(SkinColor)i])).ToDictionary<(Color, EmissionType), Color, EmissionType>(((Color color, EmissionType) x) => x.color, ((Color color, EmissionType) x) => x.Item2);
			}
			return colors;
		}

		public EmissionType? CheckEmit(Character emitter, Character emittee)
		{
			//IL_0012: Unknown result type (might be due to invalid IL or missing references)
			//IL_0017: Unknown result type (might be due to invalid IL or missing references)
			//IL_0019: Unknown result type (might be due to invalid IL or missing references)
			//IL_002d: Unknown result type (might be due to invalid IL or missing references)
			//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_0046: Unknown result type (might be due to invalid IL or missing references)
			//IL_005a: Unknown result type (might be due to invalid IL or missing references)
			Dictionary<Color, EmissionType> dictionary = GetColors();
			Color playerColor = emitter.refs.customization.PlayerColor;
			if (!dictionary.ContainsKey(playerColor))
			{
				return null;
			}
			EmissionType emissionType = dictionary[playerColor];
			playerColor = emittee.refs.customization.PlayerColor;
			if (!dictionary.ContainsKey(playerColor))
			{
				return null;
			}
			EmissionType emissionType2 = dictionary[playerColor];
			if (emissionType != emitting_e)
			{
				return null;
			}
			if (emissionType == emissionType2)
			{
				return null;
			}
			return emissionType;
		}
	}
	[HarmonyPatch(typeof(CharacterHeatEmission))]
	public static class HeatEmissionsPatch
	{
		public static PlayerEmission? activeEmission;

		[HarmonyPostfix]
		[HarmonyPatch("Update")]
		public static void UpdatePostfix(CharacterHeatEmission __instance)
		{
			//IL_003b: 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)
			if (__instance.counter != 0f || activeEmission == null)
			{
				return;
			}
			Character character = __instance.character;
			foreach (Character allCharacter in Character.AllCharacters)
			{
				if (Vector3.Distance(((Component)__instance).transform.position, allCharacter.Center) < __instance.radius)
				{
					Character emittee = allCharacter;
					EmissionType? emissionType = activeEmission?.CheckEmit(character, emittee);
					if (!emissionType.HasValue)
					{
						break;
					}
					switch (emissionType)
					{
					case EmissionType.HEAT:
						allCharacter.refs.afflictions.AddStatus((STATUSTYPE)8, __instance.heatAmount, false, true);
						break;
					case EmissionType.COLD:
						allCharacter.refs.afflictions.AddStatus((STATUSTYPE)2, __instance.heatAmount * 2f, false, true);
						break;
					case EmissionType.ENERGY:
						allCharacter.AddExtraStamina(0f - __instance.heatAmount);
						break;
					}
				}
			}
		}
	}
	public class HeatEmissionEvent : IEvent
	{
		private PlayerEmission e;

		public HeatEmissionEvent(EmissionType et)
		{
			e = new PlayerEmission(et);
		}

		public HeatEmissionEvent()
		{
			EmissionType emissionType = (EmissionType)Random.Range(0, 3);
			e = new PlayerEmission(emissionType);
		}

		public void Disable(EventInterface eintf)
		{
			HeatEmissionsPatch.activeEmission = null;
		}

		public void Enable(EventInterface eintf)
		{
			//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_0032: 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_0040: Unknown result type (might be due to invalid IL or missing references)
			//IL_0045: Unknown result type (might be due to invalid IL or missing references)
			//IL_004e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0053: Unknown result type (might be due to invalid IL or missing references)
			//IL_0062: Unknown result type (might be due to invalid IL or missing references)
			//IL_0063: Unknown result type (might be due to invalid IL or missing references)
			string s = "";
			Color c = Color.white;
			switch (e.emitting_e)
			{
			case EmissionType.HEAT:
				s = "Reddish scouts are hot.";
				c = Color.red;
				break;
			case EmissionType.COLD:
				s = "Blueish scouts are cold.";
				c = Color.blue;
				break;
			case EmissionType.ENERGY:
				s = "Greenish scouts eat your energy.";
				c = Color.green;
				break;
			}
			eintf.AddEnableLine(new NiceText
			{
				s = s,
				c = c
			});
			HeatEmissionsPatch.activeEmission = e;
		}

		public JObject to_json()
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0006: Expected O, but got Unknown
			JObject val = new JObject();
			val.Add("et", JToken.op_Implicit((int)e.emitting_e));
			return val;
		}

		public static IEventFactory factory()
		{
			IEventFactory result = default(IEventFactory);
			result.New = (OurBiome _) => new HeatEmissionEvent();
			result.FromJson = delegate(JObject o)
			{
				EmissionType valueOrDefault = (EmissionType)((int?)o.GetValue("et")).GetValueOrDefault(0);
				return new HeatEmissionEvent(valueOrDefault);
			};
			return result;
		}
	}
	internal enum SkinColor
	{
		RED,
		ORANGE,
		YELLOW,
		LIME,
		GREEN,
		CYAN,
		BLUE,
		PURPLE,
		PINK,
		RANDOM
	}
	internal class DelayedMagic : MonoBehaviour
	{
		public void DelayedSetColor(int c)
		{
			((MonoBehaviour)this).StartCoroutine(Do());
			IEnumerator Do()
			{
				yield return (object)new WaitForSeconds(10f);
				CharacterCustomization.SetCharacterSkinColor(c);
			}
		}
	}
	public class GreatMagicianEvent : IEvent
	{
		private SkinColor sc;

		private GameObject o;

		private int original_color = -1;

		private GameObject SetGo()
		{
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_0010: Expected O, but got Unknown
			o = new GameObject("Great Magician");
			o.AddComponent<DelayedMagic>();
			return o;
		}

		private GreatMagicianEvent(SkinColor _sc)
		{
			sc = _sc;
			o = SetGo();
		}

		private GreatMagicianEvent()
		{
			if (Random.Range(0, 4) > 0)
			{
				sc = SkinColor.RANDOM;
			}
			else
			{
				sc = (SkinColor)Random.Range(0, 9);
			}
			o = SetGo();
		}

		private static string ScStr(SkinColor sc)
		{
			return sc switch
			{
				SkinColor.RED => "red", 
				SkinColor.ORANGE => "orange", 
				SkinColor.YELLOW => "yellow", 
				SkinColor.LIME => "lime", 
				SkinColor.GREEN => "green", 
				SkinColor.CYAN => "cyan", 
				SkinColor.BLUE => "blue", 
				SkinColor.PURPLE => "purple", 
				SkinColor.PINK => "pink", 
				_ => "random", 
			};
		}

		private static int ToSkinColor(SkinColor sc)
		{
			if (sc == SkinColor.RANDOM)
			{
				return Random.Range(0, 9);
			}
			return (int)sc;
		}

		public void Disable(EventInterface eintf)
		{
			CharacterCustomization.SetCharacterSkinColor(original_color);
		}

		public void Enable(EventInterface eintf)
		{
			//IL_0018: Unknown result type (might be due to invalid IL or missing references)
			//IL_001d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0040: 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)
			int num = ToSkinColor(sc);
			Color color = Singleton<Customization>.Instance.skins[num].color;
			eintf.AddEnableLine(new NiceText
			{
				s = "I am a great magician. Your scout is " + ScStr((SkinColor)num) + ".",
				c = color
			});
			CharacterCustomizationData customizationData = CharacterCustomization.GetCustomizationData(PhotonNetwork.LocalPlayer);
			original_color = customizationData.currentSkin;
			DelayedMagic component = o.GetComponent<DelayedMagic>();
			component.DelayedSetColor(num);
		}

		public static IEventFactory factory()
		{
			IEventFactory result = default(IEventFactory);
			result.New = (OurBiome _) => new GreatMagicianEvent();
			result.FromJson = delegate(JObject o)
			{
				SkinColor valueOrDefault = (SkinColor)((int?)o.GetValue("sc")).GetValueOrDefault(9);
				return new GreatMagicianEvent(valueOrDefault);
			};
			return result;
		}

		public JObject to_json()
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0006: Expected O, but got Unknown
			JObject val = new JObject();
			val.Add("sc", JToken.op_Implicit((int)sc));
			return val;
		}
	}
	internal class SuperRescueHook
	{
		private static string item_name = "RescueHook";

		private static ushort item_id = 100;

		public static void GiveEveryoneHooks()
		{
			//IL_0024: Unknown result type (might be due to invalid IL or missing references)
			//IL_002a: Expected O, but got Unknown
			//IL_008d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0094: Unknown result type (might be due to invalid IL or missing references)
			//IL_009e: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bb: Unknown result type (might be due to invalid IL or missing references)
			ItemSlot val3 = default(ItemSlot);
			foreach (Character allCharacter in Character.AllCharacters)
			{
				Player player = allCharacter.player;
				ItemInstanceData val = new ItemInstanceData(Guid.NewGuid());
				OptionableIntItemData val2 = val.RegisterNewEntry<OptionableIntItemData>((DataEntryKey)2);
				val2.HasData = false;
				ItemInstanceDataHandler.AddInstanceData(val);
				if (!player.itemSlots.Any((ItemSlot s) => s.IsEmpty()) || !player.AddItem(item_id, val, ref val3))
				{
					Transform transform = ((Component)allCharacter.GetBodypart((BodypartType)0)).transform;
					Vector3 val4 = transform.position + transform.forward * 0.6f;
					GameObject val5 = PhotonNetwork.Instantiate("0_Items/" + item_name, val4, Quaternion.identity, (byte)0, (object[])null);
					PhotonView component = val5.GetComponent<PhotonView>();
					component.RPC("SetItemInstanceDataRPC", (RpcTarget)0, new object[1] { val });
				}
			}
		}

		public static void CleanupAllHooks()
		{
			BackpackData val = default(BackpackData);
			foreach (Character allCharacter in Character.AllCharacters)
			{
				Player p = allCharacter.player;
				ItemSlot[] itemSlots = p.itemSlots;
				ItemSlot[] array = itemSlots;
				foreach (ItemSlot itemSlot2 in array)
				{
					cleanSlot(itemSlot2, delegate(ItemSlot s)
					{
						//IL_000c: Unknown result type (might be due to invalid IL or missing references)
						p.EmptySlot(Optionable<byte>.Some(s.itemSlotID));
					});
				}
				cleanSlot(p.tempFullSlot, delegate(ItemSlot s)
				{
					//IL_000c: Unknown result type (might be due to invalid IL or missing references)
					p.EmptySlot(Optionable<byte>.Some(s.itemSlotID));
				});
				if (((ItemSlot)p.backpackSlot).IsEmpty() || !((ItemSlot)p.backpackSlot).data.TryGetDataEntry<BackpackData>((DataEntryKey)7, ref val) || val?.itemSlots == null)
				{
					continue;
				}
				ItemSlot[] itemSlots2 = val.itemSlots;
				foreach (ItemSlot itemSlot3 in itemSlots2)
				{
					cleanSlot(itemSlot3, delegate(ItemSlot s)
					{
						//IL_000d: Unknown result type (might be due to invalid IL or missing references)
						//IL_0017: Expected O, but got Unknown
						s.prefab = null;
						s.data = new ItemInstanceData(Guid.NewGuid());
					});
				}
			}
			Item[] array2 = Object.FindObjectsByType<Item>((FindObjectsSortMode)0);
			Item[] array3 = array2;
			Item[] array4 = array3;
			foreach (Item val2 in array4)
			{
				if (val2.itemID == item_id)
				{
					OptionableIntItemData data = val2.GetData<OptionableIntItemData>((DataEntryKey)2);
					if (!data.HasData)
					{
						PhotonNetwork.Destroy(((MonoBehaviourPun)val2).photonView);
					}
				}
			}
			Backpack[] array5 = Object.FindObjectsByType<Backpack>((FindObjectsSortMode)0);
			foreach (Backpack val3 in array5)
			{
				BackpackData data2 = ((Item)val3).GetData<BackpackData>((DataEntryKey)7);
				if (data2?.itemSlots == null)
				{
					continue;
				}
				ItemSlot[] itemSlots3 = data2.itemSlots;
				foreach (ItemSlot itemSlot4 in itemSlots3)
				{
					cleanSlot(itemSlot4, delegate(ItemSlot s)
					{
						//IL_000d: Unknown result type (might be due to invalid IL or missing references)
						//IL_0017: Expected O, but got Unknown
						s.prefab = null;
						s.data = new ItemInstanceData(Guid.NewGuid());
					});
				}
			}
			static void cleanSlot(ItemSlot itemSlot, Action<ItemSlot> clean)
			{
				OptionableIntItemData val4 = default(OptionableIntItemData);
				if (!itemSlot.IsEmpty() && (Object)(object)itemSlot.prefab != (Object)null && itemSlot.prefab.itemID == item_id && itemSlot.data != null && itemSlot.data.TryGetDataEntry<OptionableIntItemData>((DataEntryKey)2, ref val4) && val4 != null && !val4.HasData)
				{
					clean(itemSlot);
				}
			}
		}
	}
	[HarmonyPatch(typeof(Character), "UseStamina")]
	public class CharacterUseStaminaPatch
	{
		public static bool increase_cost;

		private static void Prefix(Character __instance, ref float usage, bool useBonusStamina)
		{
			if (increase_cost)
			{
				usage *= 2.5f;
			}
		}
	}
	public class SuperRescueHookEvent : IEvent
	{
		public void Disable(EventInterface eintf)
		{
			if (Messages.IsMaster())
			{
				SuperRescueHook.CleanupAllHooks();
			}
			CharacterUseStaminaPatch.increase_cost = false;
		}

		public void Enable(EventInterface eintf)
		{
			//IL_0012: Unknown result type (might be due to invalid IL or missing references)
			//IL_0017: Unknown result type (might be due to invalid IL or missing references)
			//IL_0033: 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)
			eintf.AddEnableLine(new NiceText
			{
				s = "Infinite rescue claws.",
				c = Color.green
			});
			eintf.AddEnableLine(new NiceText
			{
				s = "Climbing costs much more stamina.",
				c = Color.red
			});
			CharacterUseStaminaPatch.increase_cost = true;
		}

		public void LateEnable(EventInterface eintf)
		{
			if (Messages.IsMaster())
			{
				SuperRescueHook.GiveEveryoneHooks();
			}
		}

		public JObject to_json()
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0006: Expected O, but got Unknown
			return new JObject();
		}

		public static IEventFactory factory()
		{
			IEventFactory result = default(IEventFactory);
			result.New = (OurBiome _) => new SuperRescueHookEvent();
			result.FromJson = (JObject _) => new SuperRescueHookEvent();
			return result;
		}
	}
	public enum MessageType
	{
		NEW_EVENTS = 1,
		STOP_EVENTS
	}
	public class Messages
	{
		private static byte CODE = 197;

		private Action<EventData> cb;

		public Messages(Action<EventData> _cb)
		{
			cb = _cb;
			PhotonNetwork.NetworkingClient.EventReceived += OnEvent;
		}

		private void OnEvent(EventData photonEvent)
		{
			if (photonEvent.Code == CODE)
			{
				cb(photonEvent);
			}
		}

		public static bool IsMaster()
		{
			return PhotonNetwork.IsMasterClient;
		}

		public void SendEvent(MessageType t, string e, ReceiverGroup who, bool reliable = false)
		{
			//IL_002e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0033: Unknown result type (might be due to invalid IL or missing references)
			//IL_0034: 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_003b: Expected O, but got Unknown
			//IL_0046: 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_004b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0053: Unknown result type (might be due to invalid IL or missing references)
			Plugin.Log.LogInfo((object)$"Sending event {t}");
			object[] array = new object[2]
			{
				(int)t,
				e
			};
			RaiseEventOptions val = new RaiseEventOptions
			{
				Receivers = who
			};
			SendOptions val2 = (reliable ? SendOptions.SendReliable : SendOptions.SendUnreliable);
			PhotonNetwork.RaiseEvent(CODE, (object)array, val, val2);
		}

		public void SendEventTo(MessageType t, string e, int[] targets, bool reliable = false)
		{
			//IL_0014: Unknown result type (might be due to invalid IL or missing references)
			//IL_0019: Unknown result type (might be due to invalid IL or missing references)
			//IL_0021: Expected O, but got Unknown
			//IL_002c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0025: Unknown result type (might be due to invalid IL or missing references)
			//IL_0031: 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)
			object[] array = new object[2]
			{
				(int)t,
				e
			};
			RaiseEventOptions val = new RaiseEventOptions
			{
				TargetActors = targets
			};
			SendOptions val2 = (reliable ? SendOptions.SendReliable : SendOptions.SendUnreliable);
			PhotonNetwork.RaiseEvent(CODE, (object)array, val, val2);
		}
	}
	[HarmonyPatch(typeof(GUIManager))]
	public static class GlobalBehaviours
	{
		public static DoomMusic? doom_music;

		public static LateEventCaller? late_events;

		[HarmonyPostfix]
		[HarmonyPatch("Start")]
		public static void StartPostfix(GUIManager __instance)
		{
			doom_music = ((Component)__instance).gameObject.AddComponent<DoomMusic>();
			late_events = ((Component)__instance).gameObject.AddComponent<LateEventCaller>();
		}
	}
	[BepInPlugin("com.github.Wesmania.RandomEvents", "RandomEvents", "0.1.1")]
	public class Plugin : BaseUnityPlugin
	{
		public static ManualLogSource Log = null;

		public static PickEvents pick_events = new PickEvents();

		public static Messages m = new Messages(HandleMessages);

		public static EventInterface eintf = new EventInterface();

		public const string Id = "com.github.Wesmania.RandomEvents";

		public static string Name => "RandomEvents";

		public static string Version => "0.1.1";

		private void Awake()
		{
			//IL_0005: Unknown result type (might be due to invalid IL or missing references)
			//IL_000b: Expected O, but got Unknown
			Harmony val = new Harmony("com.github.Wesmania.RandomEvents");
			try
			{
				val.PatchAll();
			}
			catch (Exception arg)
			{
				Log.LogError((object)$"Failed to load mod: {arg}");
			}
			Log = ((BaseUnityPlugin)this).Logger;
			Log.LogInfo((object)("Plugin " + Name + " is loaded!"));
		}

		private static void HandleMessages(EventData photonEvent)
		{
			object[] array = (object[])photonEvent.CustomData;
			MessageType messageType = (MessageType)(int)array[0];
			string s = (string)array[1];
			Log.LogInfo((object)$"Receiving event {messageType}");
			switch (messageType)
			{
			case MessageType.NEW_EVENTS:
				pick_events.LoadNewEvents(s, eintf);
				eintf.RunInterface(eintf.is_first ? 10f : 5f);
				break;
			case MessageType.STOP_EVENTS:
				pick_events.UnloadEvents(eintf);
				break;
			}
		}
	}
	public class NiceText
	{
		public string s = "";

		public Color c;
	}
	public class DoText : MonoBehaviour
	{
		private Transform? transform_;

		private Canvas? c;

		private TMP_FontAsset? f;

		private GameObject[] at = Array.Empty<GameObject>();

		public void Init(TMP_FontAsset? ft, Transform _pt)
		{
			f = ft;
			transform_ = _pt;
		}

		public void Awake()
		{
			//IL_0005: Unknown result type (might be due to invalid IL or missing references)
			//IL_000b: Expected O, but got Unknown
			//IL_0076: Unknown result type (might be due to invalid IL or missing references)
			GameObject val = new GameObject("SoulmatePrompt");
			val.transform.SetParent(transform_, false);
			c = val.AddComponent<Canvas>();
			c.renderMode = (RenderMode)1;
			CanvasScaler val2 = ((Component)c).GetComponent<CanvasScaler>() ?? ((Component)c).gameObject.AddComponent<CanvasScaler>();
			val2.referencePixelsPerUnit = 100f;
			val2.matchWidthOrHeight = 1f;
			val2.referenceResolution = new Vector2(1920f, 1080f);
			val2.scaleFactor = 1f;
			val2.screenMatchMode = (ScreenMatchMode)0;
			val2.uiScaleMode = (ScaleMode)1;
			try
			{
				GUIManager instance = GUIManager.instance;
				object obj;
				if (instance == null)
				{
					obj = null;
				}
				else
				{
					TextMeshProUGUI itemPromptDrop = instance.itemPromptDrop;
					obj = ((itemPromptDrop != null) ? ((TMP_Text)itemPromptDrop).font : null);
				}
				f = (TMP_FontAsset?)obj;
			}
			catch
			{
			}
		}

		public void PlaceText(List<NiceText> lines)
		{
			GameObject[] array = at;
			foreach (GameObject val in array)
			{
				Object.Destroy((Object)(object)val);
			}
			IEnumerable<GameObject> collection = lines.Select(delegate(NiceText l, int i)
			{
				//IL_0005: Unknown result type (might be due to invalid IL or missing references)
				//IL_000b: Expected O, but got Unknown
				//IL_0037: Unknown result type (might be due to invalid IL or missing references)
				//IL_0083: Unknown result type (might be due to invalid IL or missing references)
				//IL_0098: Unknown result type (might be due to invalid IL or missing references)
				//IL_00c4: Unknown result type (might be due to invalid IL or missing references)
				//IL_00d6: Unknown result type (might be due to invalid IL or missing references)
				GameObject val2 = new GameObject("TextChat");
				val2.transform.SetParent(((Component)c).transform, false);
				TextMeshProUGUI val3 = val2.AddComponent<TextMeshProUGUI>();
				((TMP_Text)val3).text = l.s;
				((Graphic)val3).color = l.c;
				if ((Object)(object)f != (Object)null)
				{
					((TMP_Text)val3).font = f;
				}
				((TMP_Text)val3).alignment = (TextAlignmentOptions)258;
				((TMP_Text)val3).fontSize = 32f;
				RectTransform component = val2.GetComponent<RectTransform>();
				component.anchorMin = new Vector2(0.2f, 0.8f);
				component.anchorMax = new Vector2(0.8f, 0.8f);
				float num = ((TMP_Text)val3).fontSize * (float)i * 1.5f;
				component.offsetMin = new Vector2(0f, ((TMP_Text)val3).fontSize * 1.5f);
				component.offsetMax = new Vector2(0f, 0f - num);
				return val2;
			});
			List<GameObject> list = new List<GameObject>();
			list.AddRange(collection);
			at = list.ToArray();
		}

		public void Show()
		{
			GameObject[] array = at;
			foreach (GameObject val in array)
			{
				val.SetActive(true);
			}
		}

		public void Hide()
		{
			GameObject[] array = at;
			foreach (GameObject val in array)
			{
				val.SetActive(false);
			}
		}
	}
	[HarmonyPatch(typeof(GUIManager))]
	public static class SoulmateTextPatch
	{
		public static DoText? t;

		public static TextSetter? setter;

		[HarmonyPostfix]
		[HarmonyPatch("Start")]
		public static void StartPostfix(GUIManager __instance)
		{
			if ((Object)(object)t != (Object)null)
			{
				return;
			}
			TMP_FontAsset ft = null;
			try
			{
				GUIManager instance = GUIManager.instance;
				object obj;
				if (instance == null)
				{
					obj = null;
				}
				else
				{
					TextMeshProUGUI itemPromptDrop = instance.itemPromptDrop;
					obj = ((itemPromptDrop != null) ? ((TMP_Text)itemPromptDrop).font : null);
				}
				ft = (TMP_FontAsset)obj;
			}
			catch
			{
			}
			t = ((Component)__instance).gameObject.AddComponent<DoText>();
			t.Init(ft, ((Component)__instance).transform);
			setter = ((Component)__instance).gameObject.AddComponent<TextSetter>();
			setter.Init(t);
		}
	}
	public class TextSetter : MonoBehaviour
	{
		private DoText? t;

		private bool keyShow;

		public void Init(DoText _t)
		{
			t = _t;
		}

		public void ShowCard(List<NiceText> start, float delay)
		{
			List<NiceText> _start = new List<NiceText>(start);
			((MonoBehaviour)this).StartCoroutine(DoShow());
			IEnumerator DoShow()
			{
				t.Hide();
				yield return (object)new WaitForSeconds(delay);
				t.PlaceText(_start);
				yield return (object)new WaitForSeconds(10f);
				t.Hide();
			}
		}

		public void Update()
		{
			if (Input.GetKeyDown((KeyCode)284))
			{
				keyShow = !keyShow;
				if (keyShow)
				{
					t?.Show();
				}
				else
				{
					t?.Hide();
				}
			}
		}
	}
}
namespace System.Runtime.CompilerServices
{
	[AttributeUsage(AttributeTargets.Assembly, AllowMultiple = true)]
	internal sealed class IgnoresAccessChecksToAttribute : Attribute
	{
		public IgnoresAccessChecksToAttribute(string assemblyName)
		{
		}
	}
}