Decompiled source of WakeBerry v1.0.1

plugins/com.github.MiiMii1205.WakeBerry.dll

Decompiled 3 days ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Logging;
using Microsoft.CodeAnalysis;
using PEAKLib.Core;
using PEAKLib.Core.Extensions;
using Peak;
using Peak.Afflictions;
using Photon.Pun;
using Photon.Realtime;
using UnityEngine;
using UnityEngine.SceneManagement;
using WakeBerry.Behaviours;
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.MiiMii1205.WakeBerry")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.1.0")]
[assembly: AssemblyInformationalVersion("1.0.1+f754d32a3e1073441633bb61b437bfe13505bafa")]
[assembly: AssemblyProduct("com.github.MiiMii1205.WakeBerry")]
[assembly: AssemblyTitle("WakeBerry")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.1.0")]
[module: UnverifiableCode]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[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]
	[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]
	[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 WakeBerry
{
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	[BepInPlugin("com.github.MiiMii1205.WakeBerry", "WakeBerry", "1.0.1")]
	public class Plugin : BaseUnityPlugin
	{
		private const float WAKEBERRY_SPANW_CHANCE = 0.05f;

		private static readonly TimeSpan CycleLength = new TimeSpan(208, 0, 0, 0);

		private static readonly DateTime ConsoleUpdateReleaseDay = new DateTime(2026, 10, 22).Date;

		private static readonly Dictionary<BiomeType, State> BiomeSeeds = new Dictionary<BiomeType, State>();

		private static readonly int FirstConsoleUpdateReleaseLevel = 79;

		public const string CreationTimeKey = "RoomCreationTime";

		private const int MAX_WAKEBERRY_NB = 5;

		public const string Id = "com.github.MiiMii1205.WakeBerry";

		internal static ManualLogSource Log { get; private set; } = null;

		public static GameObject WakeBerrySpawnPrefab { get; private set; } = null;

		public static string Name => "WakeBerry";

		public static string Version => "1.0.1";

		private void Awake()
		{
			Log = ((BaseUnityPlugin)this).Logger;
			AddLocalizedTextCsv();
			BundleLoader.LoadBundleWithName((BaseUnityPlugin)(object)this, "wakeberry.peakbundle", (Action<PeakBundle>)LoadWakeberry);
			Log.LogInfo((object)("Plugin " + Name + " is loaded!"));
		}

		private void OnEnable()
		{
			SceneManager.sceneLoaded += OnSceneLoaded;
		}

		private void OnSceneLoaded(Scene scene, LoadSceneMode loadSceneMode)
		{
			//IL_0075: Unknown result type (might be due to invalid IL or missing references)
			//IL_007a: 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_009a: Invalid comparison between Unknown and I4
			//IL_02e7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ab: Unknown result type (might be due to invalid IL or missing references)
			//IL_02cb: Unknown result type (might be due to invalid IL or missing references)
			//IL_02d0: Unknown result type (might be due to invalid IL or missing references)
			//IL_0152: Unknown result type (might be due to invalid IL or missing references)
			//IL_0195: Unknown result type (might be due to invalid IL or missing references)
			//IL_019c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0260: Unknown result type (might be due to invalid IL or missing references)
			if (!((Scene)(ref scene)).name.StartsWith("Level_") && !((Scene)(ref scene)).name.Equals("WilIsland"))
			{
				return;
			}
			LevelGeneration gens = default(LevelGeneration);
			if ((Object)(object)Singleton<MapHandler>.Instance != (Object)null && Singleton<MapHandler>.Instance.BiomeIsPresent((BiomeType)6) && ((Component)Singleton<MapHandler>.Instance).gameObject.TryGetComponent<LevelGeneration>(ref gens))
			{
				Log.LogInfo((object)"GENERATING WAKEBERRY SEEDS!!!");
				GenerateSeedStates(gens);
				State state = Random.state;
				MapSegment[] segments = Singleton<MapHandler>.Instance.segments;
				Dynamite val3 = default(Dynamite);
				foreach (MapSegment val in segments)
				{
					if ((int)val.biome != 6)
					{
						continue;
					}
					Random.state = BiomeSeeds[val._biome];
					Transform parent = val.segmentParent.transform.parent.parent;
					List<Vector3> list = new List<Vector3>();
					SingleItemSpawner[] componentsInChildren = ((Component)parent).GetComponentsInChildren<SingleItemSpawner>(true);
					int num = 0;
					SingleItemSpawner[] array = componentsInChildren;
					foreach (SingleItemSpawner val2 in array)
					{
						if (val2.prefab.gameObject.TryGetComponent<Dynamite>(ref val3) && IsFarEnoughFromOthers(((Component)val2).transform, list) && IsEligible(((Component)val2).transform) && IsLucky(0.05f))
						{
							Log.LogDebug((object)$"Placing a Wakeberry Plant @ {((Component)val2).transform.position}");
							Transform transform = ((Component)val2).transform;
							Transform parent2 = ((Component)val2).transform.parent;
							GameObject val4 = Object.Instantiate<GameObject>(WakeBerrySpawnPrefab, parent2, true);
							val4.transform.SetPositionAndRotation(transform.position, transform.rotation);
							Object.Destroy((Object)(object)((Component)val2).gameObject);
							int num2 = FakeItemManager.Instance.GetAvailableIndex();
							OrbThatMakesYouAwake component = val4.GetComponent<OrbThatMakesYouAwake>();
							if (num2 >= FakeItemManager.Instance.allFakeItems.Count)
							{
								num2 = FakeItemManager.Instance.allFakeItems.Count;
								FakeItemManager.Instance.allFakeItems.Add(component.fakeBerry);
							}
							else
							{
								FakeItemManager.Instance.allFakeItems[num2] = component.fakeBerry;
							}
							component.fakeBerry.index = num2;
							Log.LogDebug((object)$"Wakeberry Plant #{num + 1}'s fake item IDX is {component.fakeBerry.index}!");
							list.Add(val4.transform.position);
							num++;
							Log.LogDebug((object)$"Placed ({num}/{5}) Wakeberry Plants");
						}
						if (num >= 5)
						{
							Log.LogInfo((object)$"Placed the last possible Wakeberry Plant! ({num} Wakeberry Plants total)");
							break;
						}
					}
					BiomeSeeds[val._biome] = Random.state;
				}
				Random.state = state;
			}
			else
			{
				Log.LogInfo((object)"Mesa was not active this map. No need to generate Wakeberries.");
			}
		}

		private bool IsEligible(Transform sisTransform)
		{
			bool flag = !(((Object)sisTransform.parent.parent).name == "mineshaft");
			if (!flag)
			{
				Log.LogDebug((object)(((Object)((Component)sisTransform).gameObject).name + " is a mine shaft dynamite, can't make it a Wakeberry Plant."));
			}
			return flag;
		}

		private bool IsFarEnoughFromOthers(Transform sisTransform, List<Vector3> berryPos)
		{
			//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_0011: 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)
			foreach (Vector3 berryPo in berryPos)
			{
				float num = Vector3.Distance(berryPo, sisTransform.position);
				if (num < 10f)
				{
					Log.LogDebug((object)$"{((Object)((Component)sisTransform).gameObject).name} is too close to another Wakeberry Plant (distance={num}).");
					return false;
				}
			}
			return true;
		}

		public static bool IsLucky(float baseChance = 0.025f)
		{
			return Random.value < baseChance;
		}

		private void GenerateSeedStates(LevelGeneration gens)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0005: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_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_0181: 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_018d: 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)
			State state = Random.state;
			DateTime date;
			if (((Dictionary<object, object>)(object)((RoomInfo)PhotonNetwork.CurrentRoom).CustomProperties).TryGetValue((object)"RoomCreationTime", out object value) && value is long ticks)
			{
				date = new DateTime(ticks, DateTimeKind.Utc).Date;
				Log.LogDebug((object)string.Format("Retrieved {0}: ({1:m})", "RoomCreationTime", date));
			}
			else
			{
				date = DateTime.UtcNow.Date;
				Log.LogDebug((object)string.Format("No {0}. Fallback to ({1:m})", "RoomCreationTime", date));
			}
			DateTime dateTime = ConsoleUpdateReleaseDay.AddDays(-FirstConsoleUpdateReleaseLevel);
			float num = (float)(date.Date - dateTime).Ticks / (float)CycleLength.Ticks;
			int num2 = Mathf.FloorToInt(num);
			int num3 = gens.seed + num2;
			Log.LogDebug((object)$"PEAK is on cycle #{num2 + 1}... (original seed:{gens.seed}, cycle-corrected seed: {gens.seed} + {num2} = {num3})");
			Random.InitState(num3);
			foreach (BiomeType value2 in Enum.GetValues(typeof(BiomeType)))
			{
				int num4 = Random.Range(int.MinValue, int.MaxValue);
				State state2 = Random.state;
				Random.InitState(num4);
				BiomeSeeds[value2] = Random.state;
				Random.state = state2;
			}
			Random.state = state;
		}

		private static Quaternion GetSpawnRotation()
		{
			//IL_001c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0021: Unknown result type (might be due to invalid IL or missing references)
			//IL_002e: Unknown result type (might be due to invalid IL or missing references)
			//IL_002f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0030: Unknown result type (might be due to invalid IL or missing references)
			//IL_0031: Unknown result type (might be due to invalid IL or missing references)
			//IL_000c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0043: 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_003d: Unknown result type (might be due to invalid IL or missing references)
			if (!Object.op_Implicit((Object)(object)MainCamera.instance))
			{
				return Quaternion.identity;
			}
			Vector3 forward = ((Component)MainCamera.instance).transform.forward;
			forward.y = 0f;
			Vector3 val = forward;
			if (!(val != Vector3.zero))
			{
				return Quaternion.identity;
			}
			return Quaternion.LookRotation(val);
		}

		private static Vector3 GetSpawnPosition()
		{
			//IL_0033: 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_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_006d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0077: 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_004a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0051: Unknown result type (might be due to invalid IL or missing references)
			//IL_005b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0060: Unknown result type (might be due to invalid IL or missing references)
			if (!Object.op_Implicit((Object)(object)MainCamera.instance))
			{
				Log.LogWarning((object)"GetSpawnPosition: MainCamera not found, using default position");
				return Vector3.zero;
			}
			Transform transform = ((Component)MainCamera.instance).transform;
			float num = 5000f;
			RaycastHit val = default(RaycastHit);
			if (Physics.Raycast(transform.position, transform.forward, ref val, num))
			{
				return ((RaycastHit)(ref val)).point + ((RaycastHit)(ref val)).normal * 0.1f;
			}
			return transform.position + transform.forward * 25f;
		}

		private void OnDisable()
		{
			SceneManager.sceneLoaded -= OnSceneLoaded;
		}

		private void AddLocalizedTextCsv()
		{
			using StreamReader streamReader = new StreamReader(Path.Join((ReadOnlySpan<char>)Path.GetDirectoryName(((BaseUnityPlugin)this).Info.Location), (ReadOnlySpan<char>)"WakeberryLocalizedText.csv"));
			int num = 0;
			while (!streamReader.EndOfStream)
			{
				string text = streamReader.ReadLine();
				if (text == null)
				{
					break;
				}
				num++;
				List<string> list = new List<string>(CSVReader.SplitCsvLine(text, true));
				string text2 = ExtCollections.Deque<string>(list);
				string text3 = ExtCollections.Pop<string>(list);
				if (text3 != "ENDLINE")
				{
					Log.LogError((object)$"Invalid localization at line {num}");
				}
				if (text2 != "CURRENT_LANGUAGE")
				{
					LocalizedText.mainTable[text2] = list;
					Log.LogDebug((object)("Added localization of " + text2));
				}
			}
			Log.LogDebug((object)$"Added {num - 1} localizations");
		}

		private void LoadWakeberry(PeakBundle b)
		{
			GameObject val = b.LoadAsset<GameObject>("Wakeberry.prefab");
			ItemOptimizer orAddComponent = ExtGameObject.GetOrAddComponent<ItemOptimizer>(val);
			orAddComponent.item = val.GetComponent<Item>();
			ExtGameObject.GetOrAddComponent<PhotonCleanupHelper>(val);
			Action_WakeUp action_WakeUp = val.AddComponent<Action_WakeUp>();
			((ItemAction)action_WakeUp).OnConsumed = true;
			action_WakeUp.m_extraStamAmountIfAwake = 0.175f;
			ShaderExtensions.ReplaceShaders(val);
			Log.LogInfo((object)"Loaded wakeberry item!");
			GameObject val2 = b.LoadAsset<GameObject>("WakeBerrySpawn.prefab");
			OrbThatMakesYouSleepy component = val2.GetComponent<OrbThatMakesYouSleepy>();
			OrbThatMakesYouAwake orbThatMakesYouAwake = val2.AddComponent<OrbThatMakesYouAwake>();
			orbThatMakesYouAwake.ambientParticles = component.ambientParticles;
			orbThatMakesYouAwake.orb = component.orb;
			orbThatMakesYouAwake.maxDistance = component.maxDistance;
			orbThatMakesYouAwake.minHotPerSecond = component.minDrowsyPerSecond;
			orbThatMakesYouAwake.maxHotPerSecond = component.maxDrowsyPerSecond;
			orbThatMakesYouAwake.minHotPerTick = component.minDrowsyPerTick;
			orbThatMakesYouAwake.maxHotPerTick = component.maxDrowsyPerTick;
			orbThatMakesYouAwake.particle = component.particle;
			orbThatMakesYouAwake.anim = component.anim;
			orbThatMakesYouAwake.animSpeed = component.animSpeed;
			orbThatMakesYouAwake.fakeBerry = component.fakeBerry;
			Object.DestroyImmediate((Object)(object)component);
			ShaderExtensions.ReplaceShaders(val2);
			orbThatMakesYouAwake.fakeBerry.realItemPrefab = val.GetComponent<Item>();
			WakeBerrySpawnPrefab = val2;
			Log.LogInfo((object)"Loaded wakeberry plant prefab!");
			b.Mod.RegisterContent();
			Log.LogInfo((object)"Wakeberry is loaded!");
		}
	}
}
namespace WakeBerry.Behaviours
{
	public class Action_WakeUp : ItemAction
	{
		public float m_extraStamAmountIfAwake = 0.35f;

		public const float FULL_HEAL = 5f;

		public const float FULL_BAR = 1f;

		public Affliction m_toGiveIfAwake;

		public override void RunAction()
		{
			//IL_01cb: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d7: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ef: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f2: Invalid comparison between Unknown and I4
			//IL_015c: Unknown result type (might be due to invalid IL or missing references)
			//IL_015e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0161: Invalid comparison between Unknown and I4
			//IL_0208: Unknown result type (might be due to invalid IL or missing references)
			//IL_020b: Invalid comparison between Unknown and I4
			//IL_01f4: Unknown result type (might be due to invalid IL or missing references)
			//IL_0163: Unknown result type (might be due to invalid IL or missing references)
			//IL_0167: Invalid comparison between Unknown and I4
			//IL_020d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0211: Invalid comparison between Unknown and I4
			//IL_01fb: Unknown result type (might be due to invalid IL or missing references)
			//IL_01fe: Invalid comparison between Unknown and I4
			//IL_0216: Unknown result type (might be due to invalid IL or missing references)
			//IL_021a: Invalid comparison between Unknown and I4
			//IL_05d3: 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_061e: Unknown result type (might be due to invalid IL or missing references)
			//IL_064a: Unknown result type (might be due to invalid IL or missing references)
			//IL_04e0: Unknown result type (might be due to invalid IL or missing references)
			//IL_050c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0364: Unknown result type (might be due to invalid IL or missing references)
			//IL_044d: Unknown result type (might be due to invalid IL or missing references)
			bool passedOut = ((ItemActionBase)this).character.data.passedOut;
			Character val = default(Character);
			bool flag = ((ItemActionBase)this).item.TryGetFeeder(ref val);
			float num = 0f;
			Action_RestoreHunger[] components = ((Component)((ItemActionBase)this).item).gameObject.GetComponents<Action_RestoreHunger>();
			foreach (Action_RestoreHunger val2 in components)
			{
				num += val2.restorationAmount;
			}
			bool flag2 = (double)(((ItemActionBase)this).character.refs.afflictions.statusSum + num) > 0.9900000095367432;
			if (((ItemActionBase)this).character.data.passedOut || flag2)
			{
				Plugin.Log.LogInfo((object)("Waking up " + ((ItemActionBase)this).character.characterName + "..."));
				while (((ItemActionBase)this).character.refs.afflictions.shouldPassOut)
				{
					int num2 = -1;
					float num3 = float.NegativeInfinity;
					int j = 0;
					for (int num4 = ((ItemActionBase)this).character.refs.afflictions.currentStatuses.Length; j < num4; j++)
					{
						float num5 = ((ItemActionBase)this).character.refs.afflictions.currentStatuses[j];
						if (num5 <= 0f)
						{
							Plugin.Log.LogDebug((object)$"Status {(object)(STATUSTYPE)j} is not on {((ItemActionBase)this).character.characterName}. Skipping...");
							continue;
						}
						if (j == 13)
						{
							Plugin.Log.LogDebug((object)$"Can't wake up from Status {(object)(STATUSTYPE)j}. Skipping...");
							continue;
						}
						STATUSTYPE val3 = (STATUSTYPE)j;
						if ((int)val3 != 7)
						{
							if ((int)val3 == 13)
							{
								num5 = float.NegativeInfinity;
							}
						}
						else
						{
							num5 *= 1E-05f;
						}
						if (num5 > num3)
						{
							num2 = j;
							num3 = num5;
						}
					}
					if (num2 == -1)
					{
						Plugin.Log.LogWarning((object)("No largest status effect were found, yet " + ((ItemActionBase)this).character.characterName + " is STILL passed out. Something is wrong!"));
						break;
					}
					STATUSTYPE val4 = (STATUSTYPE)num2;
					Plugin.Log.LogDebug((object)$"Biggest status: {val4} @ {num3}");
					if ((int)val4 <= 3)
					{
						if ((int)val4 == 0)
						{
							if (flag)
							{
								int num6 = Mathf.RoundToInt(Mathf.Min(((ItemActionBase)this).character.refs.afflictions.GetCurrentStatus((STATUSTYPE)0), Mathf.Abs(5f)) * 100f);
								GameUtils.instance.IncrementFriendHealing(num6, ((MonoBehaviourPun)val).photonView.Owner);
							}
							Plugin.Log.LogInfo((object)$"Removing {val4} from {((ItemActionBase)this).character.characterName}...");
							((ItemActionBase)this).character.refs.afflictions.SubtractStatus(val4, Mathf.Abs(5f), false, false);
							continue;
						}
						if ((int)val4 == 3)
						{
							((ItemActionBase)this).character.refs.afflictions.ClearPoisonAfflictions();
							int num7 = Mathf.RoundToInt(Mathf.Min(((ItemActionBase)this).character.refs.afflictions.GetCurrentStatus((STATUSTYPE)3), Mathf.Abs(5f)) * 100f);
							if (flag)
							{
								GameUtils.instance.IncrementFriendPoisonHealing(num7, ((MonoBehaviourPun)val).photonView.Owner);
							}
							else
							{
								Singleton<AchievementManager>.Instance.IncrementSteamStat((STEAMSTATTYPE)4, num7);
							}
							Plugin.Log.LogInfo((object)$"Removing {val4} from {((ItemActionBase)this).character.characterName}...");
							((ItemActionBase)this).character.refs.afflictions.SubtractStatus(val4, Mathf.Abs(5f), false, false);
							foreach (KeyValuePair<Bugfix, Character> allAttachedBug in Bugfix.AllAttachedBugs)
							{
								if ((Object)(object)allAttachedBug.Value == (Object)(object)((ItemActionBase)this).character)
								{
									allAttachedBug.Key.Interact(((ItemActionBase)this).character);
									break;
								}
							}
							continue;
						}
					}
					else
					{
						if ((int)val4 == 7)
						{
							if (((ItemActionBase)this).character.data.IsCarryingCharacter)
							{
								if (((ItemActionBase)this).character.data.fullyPassedOut)
								{
									Plugin.Log.LogWarning((object)$"{((ItemActionBase)this).character.characterName} is FULLY passed out and carrying {((ItemActionBase)this).character.data.carriedPlayer}, which should NOT happen! Dropping {((ItemActionBase)this).character.data.carriedPlayer} anyway...");
								}
								((ItemActionBase)this).character.DropCarriedCharacter(false);
							}
							Plugin.Log.LogWarning((object)("Weight is the biggest status. Dropping all items from " + ((ItemActionBase)this).character.characterName + "..."));
							((ItemActionBase)this).character.refs.items.DropAllItems(true);
							continue;
						}
						if ((int)val4 == 9)
						{
							foreach (ThornOnMe physicalThorn in ((ItemActionBase)this).character.refs.afflictions.physicalThorns)
							{
								if (physicalThorn.isThorn)
								{
									Plugin.Log.LogInfo((object)$"Removing {physicalThorn} from {((ItemActionBase)this).character.characterName}...");
									((ItemActionBase)this).character.refs.afflictions.RemoveThorn(physicalThorn, false);
								}
							}
							foreach (StickyItemComponent aLL_STUCK_ITEM in StickyItemComponent.ALL_STUCK_ITEMS)
							{
								((MonoBehaviour)this).StartCoroutine(DestroyStuckItems(aLL_STUCK_ITEM));
							}
							((ItemActionBase)this).character.refs.afflictions.SubtractStatus(val4, Mathf.Abs(5f), false, false);
							continue;
						}
						if ((int)val4 == 12)
						{
							foreach (ThornOnMe physicalThorn2 in ((ItemActionBase)this).character.refs.afflictions.physicalThorns)
							{
								if (physicalThorn2.isArrow)
								{
									Plugin.Log.LogInfo((object)$"Removing {physicalThorn2} from {((ItemActionBase)this).character.characterName}...");
									((ItemActionBase)this).character.refs.afflictions.RemoveThorn(physicalThorn2, false);
								}
							}
							((ItemActionBase)this).character.refs.afflictions.SubtractStatus(val4, Mathf.Abs(5f), false, false);
							continue;
						}
					}
					Plugin.Log.LogInfo((object)$"Removing {val4} from {((ItemActionBase)this).character.characterName}...");
					((ItemActionBase)this).character.refs.afflictions.SubtractStatus(val4, Mathf.Abs(5f), false, false);
				}
			}
			else
			{
				Plugin.Log.LogInfo((object)("Burning up " + ((ItemActionBase)this).character.characterName + "..."));
				((ItemActionBase)this).character.AddExtraStamina(m_extraStamAmountIfAwake);
				((ItemActionBase)this).character.refs.afflictions.AddStatus((STATUSTYPE)8, Mathf.Abs(1f), false, true, true, false, false);
			}
			((ItemActionBase)this).character.refs.afflictions.SubtractStatus((STATUSTYPE)6, Mathf.Abs(5f), false, false);
			if (passedOut && ((ItemActionBase)this).character.refs.afflictions.statusSum <= 1f && flag)
			{
				GameUtils.instance.ThrowEmergencyPreparednessAchievement(((MonoBehaviourPun)val).photonView.Owner);
			}
		}

		private IEnumerator DestroyStuckItems(StickyItemComponent stuckItem)
		{
			if (!((Object)(object)stuckItem.stuckToCharacter == (Object)(object)((ItemActionBase)this).character) || !(stuckItem is CactusBall))
			{
				yield break;
			}
			if ((int)((MonoBehaviourPun)stuckItem).photonView.OwnershipTransfer != 0)
			{
				if (!((MonoBehaviourPun)stuckItem).photonView.IsMine)
				{
					((MonoBehaviourPun)stuckItem).photonView.RequestOwnership();
					yield return (object)new WaitUntil((Func<bool>)(() => ((MonoBehaviourPun)stuckItem).photonView.IsMine));
				}
				Plugin.Log.LogInfo((object)$"Destroying {stuckItem} from {((ItemActionBase)this).character.characterName}...");
				PhotonNetwork.Destroy(((Component)stuckItem).gameObject);
			}
			else
			{
				Plugin.Log.LogWarning((object)$"Can't gain ownership of {((Object)stuckItem).name}. Ownership transfer is set to {((MonoBehaviourPun)stuckItem).photonView.OwnershipTransfer}");
			}
		}
	}
	public class OrbThatMakesYouAwake : MonoBehaviour
	{
		public Transform orb;

		public float maxDistance;

		public float minHotPerSecond;

		public float maxHotPerSecond;

		public float minHotPerTick;

		public float maxHotPerTick;

		public ParticleSystem particle;

		public Animator anim;

		public float animSpeed = 1f;

		public ParticleSystem ambientParticles;

		public FakeItem fakeBerry;

		public void Start()
		{
			anim.speed = animSpeed;
		}

		public void Tick()
		{
			if (RunSettings.GetValue((SETTINGTYPE)2400, false) != 0)
			{
				UpdateHot();
			}
		}

		public void LateUpdate()
		{
			//IL_005b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0070: Unknown result type (might be due to invalid IL or missing references)
			if (Object.op_Implicit((Object)(object)fakeBerry) && ((Component)fakeBerry).gameObject.activeInHierarchy)
			{
				anim.speed = animSpeed;
				((Component)ambientParticles).gameObject.SetActive(true);
				((Component)fakeBerry).transform.localPosition = new Vector3(-0.013f, -0.22f, 0.008f);
				((Component)fakeBerry).transform.localEulerAngles = Vector3.zero;
			}
			else
			{
				anim.speed = 0f;
				((Component)ambientParticles).gameObject.SetActive(false);
			}
		}

		public void UpdateHot(bool debug = false)
		{
			//IL_0058: Unknown result type (might be due to invalid IL or missing references)
			//IL_0068: Unknown result type (might be due to invalid IL or missing references)
			//IL_006d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0072: 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_00a4: 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_00b3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00db: Unknown result type (might be due to invalid IL or missing references)
			if (((Behaviour)this).enabled && Object.op_Implicit((Object)(object)fakeBerry) && ((Component)fakeBerry).gameObject.activeInHierarchy && ClassExtensionsMethods.UnityObjectExists<Character>(Character.localCharacter) && Character.localCharacter.data.fullyConscious)
			{
				Vector3 val = Character.localCharacter.Center - ((Component)orb).transform.position;
				if (((Vector3)(ref val)).magnitude <= maxDistance && GeometryUtility.TestPlanesAABB(GeometryUtility.CalculateFrustumPlanes(MainCamera.instance.cam), new Bounds(((Component)orb).transform.position, Vector3.one * 0.5f)))
				{
					float num = Vector3.Angle(-((Component)MainCamera.instance.cam).transform.forward, val);
					float num2 = Mathf.InverseLerp(maxDistance, 2f, ((Vector3)(ref val)).magnitude);
					float num3 = Mathf.Lerp(10f, 110f, num2);
					float num4 = Mathf.InverseLerp(num3, (float)((double)num3 / 2.0), num);
					float num5 = Mathf.Lerp(minHotPerTick, maxHotPerTick, Mathf.Min(num2, num4));
					Character.localCharacter.refs.afflictions.AddStatus((STATUSTYPE)8, num5, false, true, true, false, false);
					Character.localCharacter.refs.afflictions.AddStatus((STATUSTYPE)6, 0f - num5, false, true, true, false, false);
					particle.Play();
				}
			}
		}
	}
}
namespace System.Runtime.CompilerServices
{
	[AttributeUsage(AttributeTargets.Assembly, AllowMultiple = true)]
	internal sealed class IgnoresAccessChecksToAttribute : Attribute
	{
		public IgnoresAccessChecksToAttribute(string assemblyName)
		{
		}
	}
}