Decompiled source of MoreRealisticSleeping v1.0.3

mods/MoreRealisticSleeping.dll

Decompiled 3 months ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Resources;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using Il2CppFluffyUnderware.DevTools.Extensions;
using Il2CppInterop.Runtime.InteropTypes.Arrays;
using Il2CppScheduleOne.DevUtilities;
using Il2CppScheduleOne.GameTime;
using Il2CppScheduleOne.Law;
using Il2CppScheduleOne.Money;
using Il2CppScheduleOne.Networking;
using Il2CppScheduleOne.PlayerScripts;
using Il2CppScheduleOne.Properties;
using Il2CppScheduleOne.UI;
using Il2CppSystem;
using MelonLoader;
using MelonLoader.Utils;
using Microsoft.CodeAnalysis;
using MoreRealisticSleeping;
using MoreRealisticSleeping.Config;
using MoreRealisticSleeping.EventManager;
using MoreRealisticSleeping.PhoneApp;
using MoreRealisticSleeping.Util;
using Newtonsoft.Json;
using UnityEngine;
using UnityEngine.Events;
using UnityEngine.UI;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: MelonInfo(typeof(MRSCore), "MoreRealisticSleeping", "1.0.2", "KampfBallerina", null)]
[assembly: MelonGame("TVGS", "Schedule I")]
[assembly: TargetFramework(".NETCoreApp,Version=v6.0", FrameworkDisplayName = ".NET 6.0")]
[assembly: AssemblyCompany("MoreRealisticSleeping")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0+2a90cd21512538c4efabeb39eaab19c448d3166d")]
[assembly: AssemblyProduct("MoreRealisticSleeping")]
[assembly: AssemblyTitle("MoreRealisticSleeping")]
[assembly: NeutralResourcesLanguage("en-US")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.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.Module, AllowMultiple = false, Inherited = false)]
	internal sealed class RefSafetyRulesAttribute : Attribute
	{
		public readonly int Version;

		public RefSafetyRulesAttribute(int P_0)
		{
			Version = P_0;
		}
	}
}
public class PropertyManager
{
	private readonly Dictionary<string, Action<Player>> negativeProperties;

	private readonly Dictionary<string, Action<Player>> positiveProperties;

	public string appliedEffect;

	public AntiGravity antiGravity = new AntiGravity();

	public Athletic athletic = new Athletic();

	public Balding balding = new Balding();

	public BrightEyed brightEyed = new BrightEyed();

	public Calming calming = new Calming();

	public CalorieDense calorieDense = new CalorieDense();

	public Cyclopean cyclopean = new Cyclopean();

	public Disorienting disorienting = new Disorienting();

	public Electrifying electrifying = new Electrifying();

	public Energizing energizing = new Energizing();

	public Euphoric euphoric = new Euphoric();

	public Explosive explosive = new Explosive();

	public Focused focused = new Focused();

	public Foggy foggy = new Foggy();

	public Gingeritis gingeritis = new Gingeritis();

	public Glowie glowie = new Glowie();

	public Jennerising jennerising = new Jennerising();

	public Laxative laxative = new Laxative();

	public Lethal lethal = new Lethal();

	public LongFaced longFaced = new LongFaced();

	public Munchies munchies = new Munchies();

	public Paranoia paranoia = new Paranoia();

	public Refreshing refreshing = new Refreshing();

	public Schizophrenic schizophrenic = new Schizophrenic();

	public Sedating sedating = new Sedating();

	public Seizure seizure = new Seizure();

	public Shrinking shrinking = new Shrinking();

	public Slippery slippery = new Slippery();

	public Smelly smelly = new Smelly();

	public Sneaky sneaky = new Sneaky();

	public Spicy spicy = new Spicy();

	public ThoughtProvoking thoughtProvoking = new ThoughtProvoking();

	public Toxic toxic = new Toxic();

	public TropicThunder tropicThunder = new TropicThunder();

	public Zombifying zombifying = new Zombifying();

	private static readonly string ConfigFolder = Path.Combine(MelonEnvironment.UserDataDirectory, "MoreRealisticSleeping");

	private static readonly string EffectImagesFolder = Path.Combine(ConfigFolder, "EffectImages");

	private static readonly string FilePath = Path.Combine(ConfigFolder, "SleepingAppIcon.png");

	public static Sprite appIconSprite;

	public Coroutine removeEffectCoroutine;

	public PropertyManager()
	{
		//IL_0001: Unknown result type (might be due to invalid IL or missing references)
		//IL_000b: Expected O, but got Unknown
		//IL_000c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0016: Expected O, but got Unknown
		//IL_0017: Unknown result type (might be due to invalid IL or missing references)
		//IL_0021: Expected O, but got Unknown
		//IL_0022: Unknown result type (might be due to invalid IL or missing references)
		//IL_002c: Expected O, but got Unknown
		//IL_002d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0037: Expected O, but got Unknown
		//IL_0038: Unknown result type (might be due to invalid IL or missing references)
		//IL_0042: Expected O, but got Unknown
		//IL_0043: Unknown result type (might be due to invalid IL or missing references)
		//IL_004d: Expected O, but got Unknown
		//IL_004e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0058: Expected O, but got Unknown
		//IL_0059: Unknown result type (might be due to invalid IL or missing references)
		//IL_0063: Expected O, but got Unknown
		//IL_0064: Unknown result type (might be due to invalid IL or missing references)
		//IL_006e: Expected O, but got Unknown
		//IL_006f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0079: Expected O, but got Unknown
		//IL_007a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0084: Expected O, but got Unknown
		//IL_0085: Unknown result type (might be due to invalid IL or missing references)
		//IL_008f: Expected O, but got Unknown
		//IL_0090: Unknown result type (might be due to invalid IL or missing references)
		//IL_009a: Expected O, but got Unknown
		//IL_009b: Unknown result type (might be due to invalid IL or missing references)
		//IL_00a5: Expected O, but got Unknown
		//IL_00a6: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b0: Expected O, but got Unknown
		//IL_00b1: Unknown result type (might be due to invalid IL or missing references)
		//IL_00bb: Expected O, but got Unknown
		//IL_00bc: Unknown result type (might be due to invalid IL or missing references)
		//IL_00c6: Expected O, but got Unknown
		//IL_00c7: Unknown result type (might be due to invalid IL or missing references)
		//IL_00d1: Expected O, but got Unknown
		//IL_00d2: Unknown result type (might be due to invalid IL or missing references)
		//IL_00dc: Expected O, but got Unknown
		//IL_00dd: Unknown result type (might be due to invalid IL or missing references)
		//IL_00e7: Expected O, but got Unknown
		//IL_00e8: Unknown result type (might be due to invalid IL or missing references)
		//IL_00f2: Expected O, but got Unknown
		//IL_00f3: Unknown result type (might be due to invalid IL or missing references)
		//IL_00fd: Expected O, but got Unknown
		//IL_00fe: Unknown result type (might be due to invalid IL or missing references)
		//IL_0108: Expected O, but got Unknown
		//IL_0109: Unknown result type (might be due to invalid IL or missing references)
		//IL_0113: Expected O, but got Unknown
		//IL_0114: Unknown result type (might be due to invalid IL or missing references)
		//IL_011e: Expected O, but got Unknown
		//IL_011f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0129: Expected O, but got Unknown
		//IL_012a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0134: Expected O, but got Unknown
		//IL_0135: Unknown result type (might be due to invalid IL or missing references)
		//IL_013f: Expected O, but got Unknown
		//IL_0140: Unknown result type (might be due to invalid IL or missing references)
		//IL_014a: Expected O, but got Unknown
		//IL_014b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0155: Expected O, but got Unknown
		//IL_0156: Unknown result type (might be due to invalid IL or missing references)
		//IL_0160: Expected O, but got Unknown
		//IL_0161: Unknown result type (might be due to invalid IL or missing references)
		//IL_016b: Expected O, but got Unknown
		//IL_016c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0176: Expected O, but got Unknown
		//IL_0177: Unknown result type (might be due to invalid IL or missing references)
		//IL_0181: Expected O, but got Unknown
		positiveProperties = new Dictionary<string, Action<Player>>
		{
			{
				"Anti_Gravity",
				delegate(Player player)
				{
					//IL_0000: Unknown result type (might be due to invalid IL or missing references)
					((Property)new AntiGravity()).ApplyToPlayer(player);
				}
			},
			{
				"Athletic",
				delegate(Player player)
				{
					//IL_0000: Unknown result type (might be due to invalid IL or missing references)
					((Property)new Athletic()).ApplyToPlayer(player);
				}
			},
			{
				"Bright_Eyed",
				delegate(Player player)
				{
					//IL_0000: Unknown result type (might be due to invalid IL or missing references)
					((Property)new BrightEyed()).ApplyToPlayer(player);
				}
			},
			{
				"Calming",
				delegate(Player player)
				{
					//IL_0000: Unknown result type (might be due to invalid IL or missing references)
					((Property)new Calming()).ApplyToPlayer(player);
				}
			},
			{
				"Calorie_Dense",
				delegate(Player player)
				{
					//IL_0000: Unknown result type (might be due to invalid IL or missing references)
					((Property)new CalorieDense()).ApplyToPlayer(player);
				}
			},
			{
				"Electrifying",
				delegate(Player player)
				{
					//IL_0000: Unknown result type (might be due to invalid IL or missing references)
					((Property)new Electrifying()).ApplyToPlayer(player);
				}
			},
			{
				"Energizing",
				delegate(Player player)
				{
					//IL_0000: Unknown result type (might be due to invalid IL or missing references)
					((Property)new Energizing()).ApplyToPlayer(player);
				}
			},
			{
				"Euphoric",
				delegate(Player player)
				{
					//IL_0000: Unknown result type (might be due to invalid IL or missing references)
					((Property)new Euphoric()).ApplyToPlayer(player);
				}
			},
			{
				"Focused",
				delegate(Player player)
				{
					//IL_0000: Unknown result type (might be due to invalid IL or missing references)
					((Property)new Focused()).ApplyToPlayer(player);
				}
			},
			{
				"Munchies",
				delegate(Player player)
				{
					//IL_0000: Unknown result type (might be due to invalid IL or missing references)
					((Property)new Munchies()).ApplyToPlayer(player);
				}
			},
			{
				"Refreshing",
				delegate(Player player)
				{
					//IL_0000: Unknown result type (might be due to invalid IL or missing references)
					((Property)new Refreshing()).ApplyToPlayer(player);
				}
			},
			{
				"Sneaky",
				delegate(Player player)
				{
					//IL_0000: Unknown result type (might be due to invalid IL or missing references)
					((Property)new Sneaky()).ApplyToPlayer(player);
				}
			}
		};
		negativeProperties = new Dictionary<string, Action<Player>>
		{
			{
				"Balding",
				delegate(Player player)
				{
					//IL_0000: Unknown result type (might be due to invalid IL or missing references)
					((Property)new Balding()).ApplyToPlayer(player);
				}
			},
			{
				"Bright_Eyed",
				delegate(Player player)
				{
					//IL_0000: Unknown result type (might be due to invalid IL or missing references)
					((Property)new BrightEyed()).ApplyToPlayer(player);
				}
			},
			{
				"Calming",
				delegate(Player player)
				{
					//IL_0000: Unknown result type (might be due to invalid IL or missing references)
					((Property)new Calming()).ApplyToPlayer(player);
				}
			},
			{
				"Calorie_Dense",
				delegate(Player player)
				{
					//IL_0000: Unknown result type (might be due to invalid IL or missing references)
					((Property)new CalorieDense()).ApplyToPlayer(player);
				}
			},
			{
				"Cyclopean",
				delegate(Player player)
				{
					//IL_0000: Unknown result type (might be due to invalid IL or missing references)
					((Property)new Cyclopean()).ApplyToPlayer(player);
				}
			},
			{
				"Disorienting",
				delegate(Player player)
				{
					//IL_0000: Unknown result type (might be due to invalid IL or missing references)
					((Property)new Disorienting()).ApplyToPlayer(player);
				}
			},
			{
				"Electrifying",
				delegate(Player player)
				{
					//IL_0000: Unknown result type (might be due to invalid IL or missing references)
					((Property)new Electrifying()).ApplyToPlayer(player);
				}
			},
			{
				"Explosive",
				delegate(Player player)
				{
					//IL_0000: Unknown result type (might be due to invalid IL or missing references)
					((Property)new Explosive()).ApplyToPlayer(player);
				}
			},
			{
				"Foggy",
				delegate(Player player)
				{
					//IL_0000: Unknown result type (might be due to invalid IL or missing references)
					((Property)new Foggy()).ApplyToPlayer(player);
				}
			},
			{
				"Gingeritis",
				delegate(Player player)
				{
					//IL_0000: Unknown result type (might be due to invalid IL or missing references)
					((Property)new Gingeritis()).ApplyToPlayer(player);
				}
			},
			{
				"Glowing",
				delegate(Player player)
				{
					//IL_0000: Unknown result type (might be due to invalid IL or missing references)
					((Property)new Glowie()).ApplyToPlayer(player);
				}
			},
			{
				"Laxative",
				delegate(Player player)
				{
					//IL_0000: Unknown result type (might be due to invalid IL or missing references)
					((Property)new Laxative()).ApplyToPlayer(player);
				}
			},
			{
				"Long_Faced",
				delegate(Player player)
				{
					//IL_0000: Unknown result type (might be due to invalid IL or missing references)
					((Property)new LongFaced()).ApplyToPlayer(player);
				}
			},
			{
				"Paranoia",
				delegate(Player player)
				{
					//IL_0000: Unknown result type (might be due to invalid IL or missing references)
					((Property)new Paranoia()).ApplyToPlayer(player);
				}
			},
			{
				"Sedating",
				delegate(Player player)
				{
					//IL_0000: Unknown result type (might be due to invalid IL or missing references)
					((Property)new Sedating()).ApplyToPlayer(player);
				}
			},
			{
				"Seizure_Inducing",
				delegate(Player player)
				{
					//IL_0000: Unknown result type (might be due to invalid IL or missing references)
					((Property)new Seizure()).ApplyToPlayer(player);
				}
			},
			{
				"Shrinking",
				delegate(Player player)
				{
					//IL_0000: Unknown result type (might be due to invalid IL or missing references)
					((Property)new Shrinking()).ApplyToPlayer(player);
				}
			},
			{
				"Slippery",
				delegate(Player player)
				{
					//IL_0000: Unknown result type (might be due to invalid IL or missing references)
					((Property)new Slippery()).ApplyToPlayer(player);
				}
			},
			{
				"Smelly",
				delegate(Player player)
				{
					//IL_0000: Unknown result type (might be due to invalid IL or missing references)
					((Property)new Smelly()).ApplyToPlayer(player);
				}
			},
			{
				"Spicy",
				delegate(Player player)
				{
					//IL_0000: Unknown result type (might be due to invalid IL or missing references)
					((Property)new Spicy()).ApplyToPlayer(player);
				}
			},
			{
				"Lethal",
				delegate(Player player)
				{
					//IL_0000: Unknown result type (might be due to invalid IL or missing references)
					((Property)new Lethal()).ApplyToPlayer(player);
				}
			},
			{
				"Jennerising",
				delegate(Player player)
				{
					//IL_0000: Unknown result type (might be due to invalid IL or missing references)
					((Property)new Jennerising()).ApplyToPlayer(player);
				}
			},
			{
				"Schizophrenic",
				delegate(Player player)
				{
					//IL_0000: Unknown result type (might be due to invalid IL or missing references)
					((Property)new Schizophrenic()).ApplyToPlayer(player);
				}
			},
			{
				"Thought_Provoking",
				delegate(Player player)
				{
					//IL_0000: Unknown result type (might be due to invalid IL or missing references)
					((Property)new ThoughtProvoking()).ApplyToPlayer(player);
				}
			},
			{
				"Toxic",
				delegate(Player player)
				{
					//IL_0000: Unknown result type (might be due to invalid IL or missing references)
					((Property)new Toxic()).ApplyToPlayer(player);
				}
			},
			{
				"Tropic_Thunder",
				delegate(Player player)
				{
					//IL_0000: Unknown result type (might be due to invalid IL or missing references)
					((Property)new TropicThunder()).ApplyToPlayer(player);
				}
			},
			{
				"Zombifying",
				delegate(Player player)
				{
					//IL_0000: Unknown result type (might be due to invalid IL or missing references)
					((Property)new Zombifying()).ApplyToPlayer(player);
				}
			}
		};
	}

	public void ApplyNegativePropertyToPlayer(Player player, string propertyName = null)
	{
		//IL_01c1: Unknown result type (might be due to invalid IL or missing references)
		//IL_01cb: Expected O, but got Unknown
		if ((Object)(object)player == (Object)null)
		{
			MelonLogger.Warning("Player is null. Cannot apply property.");
			return;
		}
		if (MRSCore.Instance.config == null || MRSCore.Instance.config.EffectSettings == null)
		{
			MelonLogger.Warning("Config or EffectSettings is null. Cannot apply property.");
			return;
		}
		try
		{
			if (string.IsNullOrEmpty(propertyName))
			{
				List<string> list = new List<string>();
				foreach (string key in negativeProperties.Keys)
				{
					if (ConfigManager.GetNegativePropertyValue(MRSCore.Instance.config, key))
					{
						list.Add(key);
					}
				}
				if (list.Count == 0)
				{
					MelonLogger.Warning("No enabled negative properties found in the config.");
					return;
				}
				Random random = new Random();
				propertyName = list[random.Next(list.Count)];
			}
			if (!ConfigManager.GetNegativePropertyValue(MRSCore.Instance.config, propertyName))
			{
				MelonLogger.Msg("Property '" + propertyName + "' is disabled in the config. Skipping.");
			}
			else if (appliedEffect == null)
			{
				MelonCoroutines.Start(AddPropertyToPlayer(player, propertyName));
				MelonLogger.Msg("Applied '" + propertyName + "' to player: " + ((Object)player).name);
				appliedEffect = propertyName;
				float num = MRSCore.Instance.config.SleepSettings.Negative_Effects_Duration;
				if (num <= 0f || float.IsNaN(num))
				{
					num = 60f;
				}
				if (MRSCore.Instance.config.SleepSettings.Enable_Effect_Notifications)
				{
					string text = FormatPropertyName(propertyName);
					Sprite val = LoadSpriteFromUserData(text);
					MRSCore.Instance.notificationsManager.SendNotification("Negative Effect", text ?? "", val, num, true);
				}
				removeEffectCoroutine = (Coroutine)MelonCoroutines.Start(RemovePropertyFromPlayerAfterTime(player, num, appliedEffect));
			}
		}
		catch (Exception ex)
		{
			MelonLogger.Error("Error while applying property: " + ex.Message + "\n" + ex.StackTrace);
		}
	}

	public void ApplyPositivePropertyToPlayer(Player player, string propertyName = null)
	{
		if ((Object)(object)player == (Object)null)
		{
			MelonLogger.Warning("Player is null. Cannot apply property.");
			return;
		}
		if (MRSCore.Instance.config == null || MRSCore.Instance.config.EffectSettings == null)
		{
			MelonLogger.Warning("Config or EffectSettings is null. Cannot apply property.");
			return;
		}
		try
		{
			if (string.IsNullOrEmpty(propertyName))
			{
				List<string> list = new List<string>();
				foreach (string key in positiveProperties.Keys)
				{
					if (ConfigManager.GetPositivePropertyValue(MRSCore.Instance.config, key))
					{
						list.Add(key);
					}
				}
				if (list.Count == 0)
				{
					MelonLogger.Warning("No enabled positive properties found in the config.");
					return;
				}
				Random random = new Random();
				propertyName = list[random.Next(list.Count)];
			}
			if (!ConfigManager.GetPositivePropertyValue(MRSCore.Instance.config, propertyName))
			{
				MelonLogger.Warning("Property '" + propertyName + "' is disabled in the config. Skipping.");
				return;
			}
			if (appliedEffect != null)
			{
				MelonLogger.Warning($"Property '{appliedEffect}' is already applied to player: {((Object)player).name}. Skipping.");
				return;
			}
			MelonCoroutines.Start(AddPropertyToPlayer(player, propertyName));
			appliedEffect = propertyName;
			float num = MRSCore.Instance.config.SleepSettings.Positive_Effects_Duration;
			if (num <= 0f || float.IsNaN(num))
			{
				num = 60f;
			}
			MelonLogger.Msg($"Applied {propertyName} to player: {((Object)player).name} for {num} seconds.");
			if (MRSCore.Instance.config.SleepSettings.Enable_Effect_Notifications)
			{
				string text = FormatPropertyName(propertyName);
				Sprite val = LoadSpriteFromUserData(text);
				MRSCore.Instance.notificationsManager.SendNotification("Positive Effect", text ?? "", val, num, true);
			}
			MelonCoroutines.Start(RemovePropertyFromPlayerAfterTime(player, num, appliedEffect));
		}
		catch (Exception ex)
		{
			MelonLogger.Error("Error while applying property: " + ex.Message + "\n" + ex.StackTrace);
		}
	}

	public static string FormatPropertyName(string propertyName)
	{
		if (string.IsNullOrEmpty(propertyName))
		{
			return string.Empty;
		}
		string text = propertyName.Replace("_", " ");
		return CultureInfo.CurrentCulture.TextInfo.ToTitleCase(text.ToLower());
	}

	public IEnumerator RemovePropertyFromPlayerAfterTime(Player player, float timeInSeconds, string propertyName)
	{
		if ((Object)(object)player == (Object)null)
		{
			MelonLogger.Warning("Player is null. Cannot remove property.");
			yield break;
		}
		yield return (object)new WaitForSeconds(timeInSeconds);
		appliedEffect = null;
		switch (propertyName.ToLower())
		{
		case "antigravitiy":
		case "anti_gravity":
			if ((Object)(object)antiGravity == (Object)null)
			{
				antiGravity = new AntiGravity();
			}
			if ((Object)(object)antiGravity != (Object)null)
			{
				((Property)antiGravity).ClearFromPlayer(player);
			}
			break;
		case "athletic":
			if ((Object)(object)athletic == (Object)null)
			{
				athletic = new Athletic();
			}
			if ((Object)(object)athletic != (Object)null)
			{
				((Property)athletic).ClearFromPlayer(player);
			}
			break;
		case "balding":
			if ((Object)(object)balding == (Object)null)
			{
				balding = new Balding();
			}
			if ((Object)(object)balding != (Object)null)
			{
				((Property)balding).ClearFromPlayer(player);
			}
			break;
		case "brighteyed":
		case "bright_eyed":
			if ((Object)(object)brightEyed == (Object)null)
			{
				brightEyed = new BrightEyed();
			}
			if ((Object)(object)brightEyed != (Object)null)
			{
				((Property)brightEyed).ClearFromPlayer(player);
			}
			break;
		case "calming":
			if ((Object)(object)calming == (Object)null)
			{
				calming = new Calming();
			}
			if ((Object)(object)calming != (Object)null)
			{
				((Property)calming).ClearFromPlayer(player);
			}
			break;
		case "caloriedense":
		case "calorie_dense":
			if ((Object)(object)calorieDense == (Object)null)
			{
				calorieDense = new CalorieDense();
			}
			if ((Object)(object)calorieDense != (Object)null)
			{
				((Property)calorieDense).ClearFromPlayer(player);
			}
			break;
		case "cyclopean":
			if ((Object)(object)cyclopean == (Object)null)
			{
				cyclopean = new Cyclopean();
			}
			if ((Object)(object)cyclopean != (Object)null)
			{
				((Property)cyclopean).ClearFromPlayer(player);
			}
			break;
		case "disorienting":
			if ((Object)(object)disorienting == (Object)null)
			{
				disorienting = new Disorienting();
			}
			if ((Object)(object)disorienting != (Object)null)
			{
				((Property)disorienting).ClearFromPlayer(player);
			}
			break;
		case "electrifying":
			if ((Object)(object)electrifying == (Object)null)
			{
				electrifying = new Electrifying();
			}
			if ((Object)(object)electrifying != (Object)null)
			{
				((Property)electrifying).ClearFromPlayer(player);
			}
			break;
		case "energizing":
			if ((Object)(object)energizing == (Object)null)
			{
				energizing = new Energizing();
			}
			if ((Object)(object)energizing != (Object)null)
			{
				((Property)energizing).ClearFromPlayer(player);
			}
			break;
		case "euphoric":
			if ((Object)(object)euphoric == (Object)null)
			{
				euphoric = new Euphoric();
			}
			if ((Object)(object)euphoric != (Object)null)
			{
				((Property)euphoric).ClearFromPlayer(player);
			}
			break;
		case "explosive":
			if ((Object)(object)explosive == (Object)null)
			{
				explosive = new Explosive();
			}
			if ((Object)(object)explosive != (Object)null)
			{
				((Property)explosive).ClearFromPlayer(player);
			}
			break;
		case "foggy":
			if ((Object)(object)foggy == (Object)null)
			{
				foggy = new Foggy();
			}
			if ((Object)(object)foggy != (Object)null)
			{
				((Property)foggy).ClearFromPlayer(player);
			}
			break;
		case "focused":
			if ((Object)(object)focused == (Object)null)
			{
				focused = new Focused();
			}
			if ((Object)(object)focused != (Object)null)
			{
				((Property)focused).ClearFromPlayer(player);
			}
			break;
		case "gingeritis":
			if ((Object)(object)gingeritis == (Object)null)
			{
				gingeritis = new Gingeritis();
			}
			if ((Object)(object)gingeritis != (Object)null)
			{
				((Property)gingeritis).ClearFromPlayer(player);
			}
			break;
		case "glowing":
		case "glowie":
			if ((Object)(object)glowie == (Object)null)
			{
				glowie = new Glowie();
			}
			if ((Object)(object)glowie != (Object)null)
			{
				((Property)glowie).ClearFromPlayer(player);
			}
			break;
		case "jennerising":
			if ((Object)(object)jennerising == (Object)null)
			{
				jennerising = new Jennerising();
			}
			if ((Object)(object)jennerising != (Object)null)
			{
				((Property)jennerising).ClearFromPlayer(player);
			}
			break;
		case "laxative":
			if ((Object)(object)laxative == (Object)null)
			{
				laxative = new Laxative();
			}
			if ((Object)(object)laxative != (Object)null)
			{
				((Property)laxative).ClearFromPlayer(player);
			}
			break;
		case "lethal":
			if ((Object)(object)lethal == (Object)null)
			{
				lethal = new Lethal();
			}
			if ((Object)(object)lethal != (Object)null)
			{
				((Property)lethal).ClearFromPlayer(player);
			}
			break;
		case "long_faced":
		case "longfaced":
			if ((Object)(object)longFaced == (Object)null)
			{
				longFaced = new LongFaced();
			}
			if ((Object)(object)longFaced != (Object)null)
			{
				((Property)longFaced).ClearFromPlayer(player);
			}
			break;
		case "munchies":
			if ((Object)(object)munchies == (Object)null)
			{
				munchies = new Munchies();
			}
			if ((Object)(object)munchies != (Object)null)
			{
				((Property)munchies).ClearFromPlayer(player);
			}
			break;
		case "paranoia":
			if ((Object)(object)paranoia == (Object)null)
			{
				paranoia = new Paranoia();
			}
			if ((Object)(object)paranoia != (Object)null)
			{
				((Property)paranoia).ClearFromPlayer(player);
			}
			break;
		case "refreshing":
			if ((Object)(object)refreshing == (Object)null)
			{
				refreshing = new Refreshing();
			}
			if ((Object)(object)refreshing != (Object)null)
			{
				((Property)refreshing).ClearFromPlayer(player);
			}
			break;
		case "schizophrenic":
			if ((Object)(object)schizophrenic == (Object)null)
			{
				schizophrenic = new Schizophrenic();
			}
			if ((Object)(object)schizophrenic != (Object)null)
			{
				((Property)schizophrenic).ClearFromPlayer(player);
			}
			break;
		case "sedating":
			if ((Object)(object)sedating == (Object)null)
			{
				sedating = new Sedating();
			}
			if ((Object)(object)sedating != (Object)null)
			{
				((Property)sedating).ClearFromPlayer(player);
			}
			break;
		case "seizure":
		case "seizure_inducing":
		case "seizureinducing":
			if ((Object)(object)seizure == (Object)null)
			{
				seizure = new Seizure();
			}
			if ((Object)(object)seizure != (Object)null)
			{
				((Property)seizure).ClearFromPlayer(player);
			}
			break;
		case "shrinking":
			if ((Object)(object)shrinking == (Object)null)
			{
				shrinking = new Shrinking();
			}
			if ((Object)(object)shrinking != (Object)null)
			{
				((Property)shrinking).ClearFromPlayer(player);
			}
			break;
		case "slippery":
			if ((Object)(object)slippery == (Object)null)
			{
				slippery = new Slippery();
			}
			if ((Object)(object)slippery != (Object)null)
			{
				((Property)slippery).ClearFromPlayer(player);
			}
			break;
		case "smelly":
			if ((Object)(object)smelly == (Object)null)
			{
				smelly = new Smelly();
			}
			if ((Object)(object)smelly != (Object)null)
			{
				((Property)smelly).ClearFromPlayer(player);
			}
			break;
		case "sneaky":
			if ((Object)(object)sneaky == (Object)null)
			{
				sneaky = new Sneaky();
			}
			if ((Object)(object)sneaky != (Object)null)
			{
				((Property)sneaky).ClearFromPlayer(player);
			}
			break;
		case "spicy":
			if ((Object)(object)spicy == (Object)null)
			{
				spicy = new Spicy();
			}
			if ((Object)(object)spicy != (Object)null)
			{
				((Property)spicy).ClearFromPlayer(player);
			}
			break;
		case "thoughtprovoking":
		case "thought_provoking":
			if ((Object)(object)thoughtProvoking == (Object)null)
			{
				thoughtProvoking = new ThoughtProvoking();
			}
			if ((Object)(object)thoughtProvoking != (Object)null)
			{
				((Property)thoughtProvoking).ClearFromPlayer(player);
			}
			break;
		case "toxic":
			if ((Object)(object)toxic == (Object)null)
			{
				toxic = new Toxic();
			}
			if ((Object)(object)toxic != (Object)null)
			{
				((Property)toxic).ClearFromPlayer(player);
			}
			break;
		case "tropicthunder":
		case "tropic_thunder":
			if ((Object)(object)tropicThunder == (Object)null)
			{
				tropicThunder = new TropicThunder();
			}
			if ((Object)(object)tropicThunder != (Object)null)
			{
				((Property)tropicThunder).ClearFromPlayer(player);
			}
			break;
		case "zombifying":
			if ((Object)(object)zombifying == (Object)null)
			{
				zombifying = new Zombifying();
			}
			if ((Object)(object)zombifying != (Object)null)
			{
				((Property)zombifying).ClearFromPlayer(player);
			}
			break;
		default:
			MelonLogger.Warning("Property '" + propertyName + "' not found in the available properties.");
			break;
		}
	}

	public IEnumerator AddPropertyToPlayer(Player player, string propertyName)
	{
		if ((Object)(object)player == (Object)null)
		{
			MelonLogger.Warning("Player is null. Cannot remove property.");
			yield break;
		}
		if (propertyName == null)
		{
			MelonLogger.Warning("Property name is null. Cannot remove property.");
			yield break;
		}
		switch (propertyName.ToLower())
		{
		case "antigravitiy":
		case "anti_gravity":
			if ((Object)(object)antiGravity == (Object)null)
			{
				antiGravity = new AntiGravity();
			}
			if ((Object)(object)antiGravity != (Object)null)
			{
				((Property)antiGravity).ApplyToPlayer(player);
			}
			break;
		case "athletic":
			if ((Object)(object)athletic == (Object)null)
			{
				athletic = new Athletic();
			}
			if ((Object)(object)athletic != (Object)null)
			{
				((Property)athletic).ApplyToPlayer(player);
			}
			break;
		case "balding":
			if ((Object)(object)balding == (Object)null)
			{
				balding = new Balding();
			}
			if ((Object)(object)balding != (Object)null)
			{
				((Property)balding).ApplyToPlayer(player);
			}
			break;
		case "brighteyed":
		case "bright_eyed":
			if ((Object)(object)brightEyed == (Object)null)
			{
				brightEyed = new BrightEyed();
			}
			if ((Object)(object)brightEyed != (Object)null)
			{
				((Property)brightEyed).ApplyToPlayer(player);
			}
			break;
		case "calming":
			if ((Object)(object)calming == (Object)null)
			{
				calming = new Calming();
			}
			if ((Object)(object)calming != (Object)null)
			{
				((Property)calming).ApplyToPlayer(player);
			}
			break;
		case "caloriedense":
		case "calorie_dense":
			if ((Object)(object)calorieDense == (Object)null)
			{
				calorieDense = new CalorieDense();
			}
			if ((Object)(object)calorieDense != (Object)null)
			{
				((Property)calorieDense).ApplyToPlayer(player);
			}
			break;
		case "cyclopean":
			if ((Object)(object)cyclopean == (Object)null)
			{
				cyclopean = new Cyclopean();
			}
			if ((Object)(object)cyclopean != (Object)null)
			{
				((Property)cyclopean).ApplyToPlayer(player);
			}
			break;
		case "disorienting":
			if ((Object)(object)disorienting == (Object)null)
			{
				disorienting = new Disorienting();
			}
			if ((Object)(object)disorienting != (Object)null)
			{
				((Property)disorienting).ApplyToPlayer(player);
			}
			break;
		case "electrifying":
			if ((Object)(object)electrifying == (Object)null)
			{
				electrifying = new Electrifying();
			}
			if ((Object)(object)electrifying != (Object)null)
			{
				((Property)electrifying).ApplyToPlayer(player);
			}
			break;
		case "energizing":
			if ((Object)(object)energizing == (Object)null)
			{
				energizing = new Energizing();
			}
			if ((Object)(object)energizing != (Object)null)
			{
				((Property)energizing).ApplyToPlayer(player);
			}
			break;
		case "euphoric":
			if ((Object)(object)euphoric == (Object)null)
			{
				euphoric = new Euphoric();
			}
			if ((Object)(object)euphoric != (Object)null)
			{
				((Property)euphoric).ApplyToPlayer(player);
			}
			break;
		case "explosive":
			if ((Object)(object)explosive == (Object)null)
			{
				explosive = new Explosive();
			}
			if ((Object)(object)explosive != (Object)null)
			{
				((Property)explosive).ApplyToPlayer(player);
			}
			break;
		case "foggy":
			if ((Object)(object)foggy == (Object)null)
			{
				foggy = new Foggy();
			}
			if ((Object)(object)foggy != (Object)null)
			{
				((Property)foggy).ApplyToPlayer(player);
			}
			break;
		case "focused":
			if ((Object)(object)focused == (Object)null)
			{
				focused = new Focused();
			}
			if ((Object)(object)focused != (Object)null)
			{
				((Property)focused).ApplyToPlayer(player);
			}
			break;
		case "gingeritis":
			if ((Object)(object)gingeritis == (Object)null)
			{
				gingeritis = new Gingeritis();
			}
			if ((Object)(object)gingeritis != (Object)null)
			{
				((Property)gingeritis).ApplyToPlayer(player);
			}
			break;
		case "glowing":
		case "glowie":
			if ((Object)(object)glowie == (Object)null)
			{
				glowie = new Glowie();
			}
			if ((Object)(object)glowie != (Object)null)
			{
				((Property)glowie).ApplyToPlayer(player);
			}
			break;
		case "jennerising":
			if ((Object)(object)jennerising == (Object)null)
			{
				jennerising = new Jennerising();
			}
			if ((Object)(object)jennerising != (Object)null)
			{
				((Property)jennerising).ApplyToPlayer(player);
			}
			break;
		case "laxative":
			if ((Object)(object)laxative == (Object)null)
			{
				laxative = new Laxative();
			}
			if ((Object)(object)laxative != (Object)null)
			{
				((Property)laxative).ApplyToPlayer(player);
			}
			break;
		case "lethal":
			if ((Object)(object)lethal == (Object)null)
			{
				lethal = new Lethal();
			}
			if ((Object)(object)lethal != (Object)null)
			{
				((Property)lethal).ApplyToPlayer(player);
			}
			break;
		case "long_faced":
		case "longfaced":
			if ((Object)(object)longFaced == (Object)null)
			{
				longFaced = new LongFaced();
			}
			if ((Object)(object)longFaced != (Object)null)
			{
				((Property)longFaced).ApplyToPlayer(player);
			}
			break;
		case "munchies":
			if ((Object)(object)munchies == (Object)null)
			{
				munchies = new Munchies();
			}
			if ((Object)(object)munchies != (Object)null)
			{
				((Property)munchies).ApplyToPlayer(player);
			}
			break;
		case "paranoia":
			if ((Object)(object)paranoia == (Object)null)
			{
				paranoia = new Paranoia();
			}
			if ((Object)(object)paranoia != (Object)null)
			{
				((Property)paranoia).ApplyToPlayer(player);
			}
			break;
		case "refreshing":
			if ((Object)(object)refreshing == (Object)null)
			{
				refreshing = new Refreshing();
			}
			if ((Object)(object)refreshing != (Object)null)
			{
				((Property)refreshing).ApplyToPlayer(player);
			}
			break;
		case "schizophrenic":
			if ((Object)(object)schizophrenic == (Object)null)
			{
				schizophrenic = new Schizophrenic();
			}
			if ((Object)(object)schizophrenic != (Object)null)
			{
				((Property)schizophrenic).ApplyToPlayer(player);
			}
			break;
		case "sedating":
			if ((Object)(object)sedating == (Object)null)
			{
				sedating = new Sedating();
			}
			if ((Object)(object)sedating != (Object)null)
			{
				((Property)sedating).ApplyToPlayer(player);
			}
			break;
		case "seizure":
		case "seizure_inducing":
		case "seizureinducing":
			if ((Object)(object)seizure == (Object)null)
			{
				seizure = new Seizure();
			}
			if ((Object)(object)seizure != (Object)null)
			{
				((Property)seizure).ApplyToPlayer(player);
			}
			break;
		case "shrinking":
			if ((Object)(object)shrinking == (Object)null)
			{
				shrinking = new Shrinking();
			}
			if ((Object)(object)shrinking != (Object)null)
			{
				((Property)shrinking).ApplyToPlayer(player);
			}
			break;
		case "slippery":
			if ((Object)(object)slippery == (Object)null)
			{
				slippery = new Slippery();
			}
			if ((Object)(object)slippery != (Object)null)
			{
				((Property)slippery).ApplyToPlayer(player);
			}
			break;
		case "smelly":
			if ((Object)(object)smelly == (Object)null)
			{
				smelly = new Smelly();
			}
			if ((Object)(object)smelly != (Object)null)
			{
				((Property)smelly).ApplyToPlayer(player);
			}
			break;
		case "sneaky":
			if ((Object)(object)sneaky == (Object)null)
			{
				sneaky = new Sneaky();
			}
			if ((Object)(object)sneaky != (Object)null)
			{
				((Property)sneaky).ApplyToPlayer(player);
			}
			break;
		case "spicy":
			if ((Object)(object)spicy == (Object)null)
			{
				spicy = new Spicy();
			}
			if ((Object)(object)spicy != (Object)null)
			{
				((Property)spicy).ApplyToPlayer(player);
			}
			break;
		case "thoughtprovoking":
		case "thought_provoking":
			if ((Object)(object)thoughtProvoking == (Object)null)
			{
				thoughtProvoking = new ThoughtProvoking();
			}
			if ((Object)(object)thoughtProvoking != (Object)null)
			{
				((Property)thoughtProvoking).ApplyToPlayer(player);
			}
			break;
		case "toxic":
			if ((Object)(object)toxic == (Object)null)
			{
				toxic = new Toxic();
			}
			if ((Object)(object)toxic != (Object)null)
			{
				((Property)toxic).ApplyToPlayer(player);
			}
			break;
		case "tropicthunder":
		case "tropic_thunder":
			if ((Object)(object)tropicThunder == (Object)null)
			{
				tropicThunder = new TropicThunder();
			}
			if ((Object)(object)tropicThunder != (Object)null)
			{
				((Property)tropicThunder).ApplyToPlayer(player);
			}
			break;
		case "zombifying":
			if ((Object)(object)zombifying == (Object)null)
			{
				zombifying = new Zombifying();
			}
			if ((Object)(object)zombifying != (Object)null)
			{
				((Property)zombifying).ApplyToPlayer(player);
			}
			break;
		default:
			MelonLogger.Warning("Property '" + propertyName + "' not found in the available properties.");
			break;
		}
	}

	private static Sprite LoadSpriteFromUserData(string fileName)
	{
		//IL_002f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0035: Expected O, but got Unknown
		//IL_005f: Unknown result type (might be due to invalid IL or missing references)
		//IL_006e: Unknown result type (might be due to invalid IL or missing references)
		//IL_00aa: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b1: Expected O, but got Unknown
		//IL_00dc: Unknown result type (might be due to invalid IL or missing references)
		//IL_00eb: Unknown result type (might be due to invalid IL or missing references)
		string text = Path.Combine(EffectImagesFolder, fileName + ".png");
		if (!string.IsNullOrEmpty(text) && File.Exists(text))
		{
			byte[] array = File.ReadAllBytes(text);
			Texture2D val = new Texture2D(2, 2);
			if (ImageConversion.LoadImage(val, Il2CppStructArray<byte>.op_Implicit(array)))
			{
				return Sprite.Create(val, new Rect(0f, 0f, (float)((Texture)val).width, (float)((Texture)val).height), new Vector2(0.5f, 0.5f));
			}
		}
		else
		{
			if (Object.op_Implicit((Object)(object)appIconSprite))
			{
				return appIconSprite;
			}
			if (!string.IsNullOrEmpty(FilePath) && File.Exists(FilePath))
			{
				byte[] array2 = File.ReadAllBytes(FilePath);
				Texture2D val2 = new Texture2D(2, 2);
				if (ImageConversion.LoadImage(val2, Il2CppStructArray<byte>.op_Implicit(array2)))
				{
					appIconSprite = Sprite.Create(val2, new Rect(0f, 0f, (float)((Texture)val2).width, (float)((Texture)val2).height), new Vector2(0.5f, 0.5f));
					return appIconSprite;
				}
			}
		}
		return null;
	}
}
namespace MoreRealisticSleeping
{
	public class MRSCore : MelonMod
	{
		public bool isLegitVersion;

		public bool canTriggerSleep = true;

		private bool isCooldownActive;

		private bool isForcedSleep;

		private bool isFirstSleep = true;

		public SleepCanvas sleepCanvas;

		public DailySummary dailySummary;

		public TimeManager timeManager;

		public ConfigState config;

		private static readonly string ConfigFolder = Path.Combine(MelonEnvironment.UserDataDirectory, "MoreRealisticSleeping");

		private static readonly string AppIconFilePath = Path.Combine(ConfigFolder, "SleepingAppIcon.png");

		private static readonly string UIElementsFolder = Path.Combine(ConfigFolder, "UIElements");

		public NotificationsManager notificationsManager;

		public MoneyManager moneyManager;

		public PropertyManager propertyManager;

		public MoreRealisticSleeping.EventManager.EventManager eventManager;

		public static SleepingApp sleepingApp = new SleepingApp();

		public bool isMonitorTimeForSleepRunning;

		public bool isStartCooldownRunning;

		public Coroutine monitorTimeForSleepCoroutine;

		public Coroutine startCooldownCoroutine;

		public Coroutine forceSleepDelayCoroutine;

		public Coroutine initializeLaunderAppCoroutine;

		public Coroutine waitForSleepingAppCoroutine;

		public Coroutine startAppCoroutinesAfterDelayCoroutine;

		public Coroutine initTimeManagerCoroutine;

		public Coroutine initLocalPlayerCoroutine;

		public Coroutine murderPlayerCoroutine;

		public Coroutine onLocalPlayerInitializedCoroutine;

		private bool isFirstStart = true;

		private string sSceneName;

		public static MRSCore Instance { get; private set; }

		public Player localPlayer { get; private set; }

		public PlayerCrimeData localPlayerCrimeData { get; private set; }

		public override void OnInitializeMelon()
		{
			((MelonBase)this).LoggerInstance.Msg("Initialized.");
			Instance = this;
		}

		public override void OnSceneWasInitialized(int buildIndex, string sceneName)
		{
			//IL_00b4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00be: Expected O, but got Unknown
			//IL_00ca: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d4: Expected O, but got Unknown
			//IL_00e0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ea: Expected O, but got Unknown
			if (sceneName == "Main")
			{
				isFirstStart = false;
				sSceneName = sceneName.ToString();
				Instance.config = ConfigManager.Load();
				Instance.propertyManager = new PropertyManager();
				Instance.moneyManager = Object.FindObjectOfType<MoneyManager>();
				Instance.notificationsManager = Object.FindObjectOfType<NotificationsManager>();
				Instance.eventManager = new MoreRealisticSleeping.EventManager.EventManager();
				if (Instance.config.Use_Legit_Version)
				{
					((MelonBase)this).LoggerInstance.Msg("Use_Legit_Version is enabled. Adjusting behavior accordingly.");
					isLegitVersion = true;
				}
				else
				{
					((MelonBase)this).LoggerInstance.Msg("Use_Legit_Version is disabled. Proceeding with default behavior.");
					startAppCoroutinesAfterDelayCoroutine = (Coroutine)MelonCoroutines.Start(StartAppCoroutinesAfterDelay());
				}
				initLocalPlayerCoroutine = (Coroutine)MelonCoroutines.Start(InitializeLocalPlayer());
				initTimeManagerCoroutine = (Coroutine)MelonCoroutines.Start(InitTimeManager());
				_ = Singleton<Lobby>.Instance.IsHost;
			}
			else if (sceneName.Equals("Menu", StringComparison.OrdinalIgnoreCase) && !isFirstStart)
			{
				sSceneName = sceneName.ToString();
				ResetAllVariables();
				isFirstStart = false;
				_ = Singleton<Lobby>.Instance.IsHost;
			}
		}

		private void ResetAllVariables()
		{
			if (initializeLaunderAppCoroutine != null)
			{
				MelonCoroutines.Stop((object)initializeLaunderAppCoroutine);
				initializeLaunderAppCoroutine = null;
				((MelonBase)this).LoggerInstance.Msg("Stopped InitializeLaunderApp coroutine.");
			}
			if (waitForSleepingAppCoroutine != null)
			{
				MelonCoroutines.Stop((object)waitForSleepingAppCoroutine);
				waitForSleepingAppCoroutine = null;
				((MelonBase)this).LoggerInstance.Msg("Stopped WaitForSleepingAppAndCreateEntry coroutine.");
			}
			if (startAppCoroutinesAfterDelayCoroutine != null)
			{
				MelonCoroutines.Stop((object)startAppCoroutinesAfterDelayCoroutine);
				startAppCoroutinesAfterDelayCoroutine = null;
				((MelonBase)this).LoggerInstance.Msg("Stopped StartAppCoroutinesAfterDelay coroutine.");
			}
			if (initTimeManagerCoroutine != null)
			{
				MelonCoroutines.Stop((object)initTimeManagerCoroutine);
				initTimeManagerCoroutine = null;
				((MelonBase)this).LoggerInstance.Msg("Stopped InitTimeManager coroutine.");
			}
			if (propertyManager != null && propertyManager.removeEffectCoroutine != null)
			{
				MelonCoroutines.Stop((object)propertyManager.removeEffectCoroutine);
				propertyManager.removeEffectCoroutine = null;
				((MelonBase)this).LoggerInstance.Msg("Stopped RemoveEffect coroutine.");
			}
			if (murderPlayerCoroutine != null)
			{
				MelonCoroutines.Stop((object)murderPlayerCoroutine);
				murderPlayerCoroutine = null;
				((MelonBase)this).LoggerInstance.Msg("Stopped MurderPlayer coroutine.");
			}
			StopAllCoroutines();
			Instance.config = null;
			isLegitVersion = false;
			timeManager = null;
			sleepCanvas = null;
			dailySummary = null;
			eventManager = null;
			localPlayer = null;
			isFirstSleep = true;
			isForcedSleep = false;
			canTriggerSleep = true;
			isCooldownActive = false;
			propertyManager = null;
			notificationsManager = null;
			moneyManager = null;
			isMonitorTimeForSleepRunning = false;
			isStartCooldownRunning = false;
			sleepingApp._isSleepingAppLoaded = false;
			((MelonBase)this).LoggerInstance.Msg("All variables reset.");
		}

		public IEnumerator InitTimeManager()
		{
			while ((Object)(object)timeManager == (Object)null)
			{
				timeManager = Object.FindObjectOfType<TimeManager>();
				if ((Object)(object)timeManager != (Object)null)
				{
					Instance.sleepCanvas = Object.FindObjectOfType<SleepCanvas>();
					if ((Object)(object)Instance.sleepCanvas != (Object)null && isFirstSleep)
					{
						Instance.sleepCanvas.onSleepEndFade.AddListener(UnityAction.op_Implicit((Action)FuncThatCallsOtherFunc));
						Instance.sleepCanvas.onSleepEndFade.AddListener(UnityAction.op_Implicit((Action)FuncThatCallsCooldownFunc));
						isFirstSleep = false;
					}
					monitorTimeForSleepCoroutine = (Coroutine)MelonCoroutines.Start(MonitorTimeForSleep());
					break;
				}
				yield return (object)new WaitForSeconds(2f);
			}
			void FuncThatCallsCooldownFunc()
			{
				//IL_0028: Unknown result type (might be due to invalid IL or missing references)
				//IL_0032: Expected O, but got Unknown
				if (Instance.startCooldownCoroutine == null && !Instance.isStartCooldownRunning)
				{
					Instance.startCooldownCoroutine = (Coroutine)MelonCoroutines.Start(StartCooldown());
				}
			}
			void FuncThatCallsOtherFunc()
			{
				TriggerAfterSleepEffect();
			}
		}

		private IEnumerator InitializeLocalPlayer()
		{
			MelonLogger.Msg("Searching for local player...");
			while ((Object)(object)localPlayer == (Object)null)
			{
				localPlayer = ((IEnumerable<Player>)Object.FindObjectsOfType<Player>())?.FirstOrDefault((Func<Player, bool>)((Player player) => player.IsLocalPlayer));
				if ((Object)(object)localPlayer == (Object)null)
				{
					yield return (object)new WaitForSeconds(0.5f);
				}
			}
			localPlayerCrimeData = localPlayer.CrimeData;
			MelonLogger.Msg("Local player found: " + ((Object)localPlayer).name);
			initLocalPlayerCoroutine = null;
		}

		public void StopAllCoroutines()
		{
			if (forceSleepDelayCoroutine != null)
			{
				MelonCoroutines.Stop((object)forceSleepDelayCoroutine);
				((MelonBase)this).LoggerInstance.Msg("Stopped ForceSleepDelay coroutine.");
				forceSleepDelayCoroutine = null;
			}
			if (monitorTimeForSleepCoroutine != null)
			{
				MelonCoroutines.Stop((object)monitorTimeForSleepCoroutine);
				monitorTimeForSleepCoroutine = null;
				isMonitorTimeForSleepRunning = false;
				((MelonBase)this).LoggerInstance.Msg("Stopped MonitorTimeForSleep coroutine.");
			}
			if (startCooldownCoroutine != null)
			{
				MelonCoroutines.Stop((object)startCooldownCoroutine);
				startCooldownCoroutine = null;
				isStartCooldownRunning = false;
				((MelonBase)this).LoggerInstance.Msg("Stopped StartCooldown coroutine.");
			}
			if (initLocalPlayerCoroutine != null)
			{
				MelonCoroutines.Stop((object)initLocalPlayerCoroutine);
				initLocalPlayerCoroutine = null;
				((MelonBase)this).LoggerInstance.Msg("Stopped InitializeLocalPlayer coroutine.");
			}
			isForcedSleep = false;
			canTriggerSleep = true;
			isCooldownActive = false;
		}

		public IEnumerator MonitorTimeForSleep()
		{
			isMonitorTimeForSleepRunning = true;
			((MelonBase)this).LoggerInstance.Msg("Monitoring time for sleep...");
			while (true)
			{
				if ((Object)(object)timeManager != (Object)null)
				{
					if (400 <= timeManager.CurrentTime && timeManager.CurrentTime < 650 && canTriggerSleep && !isStartCooldownRunning)
					{
						if (Instance.config.SleepSettings.Enable_Forced_Sleep)
						{
							if (forceSleepDelayCoroutine == null)
							{
								((MelonBase)this).LoggerInstance.Msg("Triggering sleep delay as CurrentTime is 4:00AM.");
								forceSleepDelayCoroutine = (Coroutine)MelonCoroutines.Start(ForceSleepDelay());
							}
						}
						else
						{
							((MelonBase)this).LoggerInstance.Msg("Forced sleep is disabled in the config.");
							if (startCooldownCoroutine == null)
							{
								startCooldownCoroutine = (Coroutine)MelonCoroutines.Start(StartCooldown());
							}
						}
					}
				}
				else
				{
					((MelonBase)this).LoggerInstance.Warning("TimeManager is null. Waiting for initialization...");
				}
				yield return (object)new WaitForSeconds(5f);
			}
		}

		public IEnumerator StartAppCoroutinesAfterDelay()
		{
			bool delayedInit = false;
			while (!delayedInit && !isLegitVersion)
			{
				delayedInit = true;
				yield return (object)new WaitForSeconds(7f);
			}
			if (!isLegitVersion)
			{
				if (initializeLaunderAppCoroutine == null)
				{
					initializeLaunderAppCoroutine = (Coroutine)MelonCoroutines.Start(sleepingApp.InitializeLaunderApp());
				}
				else
				{
					((MelonBase)this).LoggerInstance.Msg("InitializeLaunderApp coroutine is already running. Skipping initialization.");
				}
				if (waitForSleepingAppCoroutine == null)
				{
					waitForSleepingAppCoroutine = (Coroutine)MelonCoroutines.Start(WaitForSleepingAppAndCreateEntry());
				}
				else
				{
					((MelonBase)this).LoggerInstance.Msg("WaitForSleepingAppAndCreateEntry coroutine is already running. Skipping initialization.");
				}
			}
		}

		private IEnumerator ForceSleepDelay()
		{
			float delayTime = Instance.config.SleepSettings.Forced_Sleep_Delay;
			if (delayTime <= 0f)
			{
				((MelonBase)this).LoggerInstance.Msg("Forced_Sleep_Delay is set to 0 or less. Skipping delay and triggering forced sleep immediately.");
				ForceSleep();
				if (startCooldownCoroutine == null)
				{
					startCooldownCoroutine = (Coroutine)MelonCoroutines.Start(StartCooldown());
				}
				forceSleepDelayCoroutine = null;
				yield break;
			}
			((MelonBase)this).LoggerInstance.Msg($"Force sleep delay started for {delayTime} seconds.");
			if ((Object)(object)localPlayer == (Object)null)
			{
				Player[] array = Il2CppArrayBase<Player>.op_Implicit(Object.FindObjectsOfType<Player>());
				foreach (Player val in array)
				{
					if (val.IsLocalPlayer)
					{
						localPlayer = val;
						break;
					}
				}
			}
			if ((Object)(object)localPlayer == (Object)null)
			{
				MelonLogger.Error("Local player not found. Cannot proceed with forced sleep.");
				forceSleepDelayCoroutine = null;
				yield break;
			}
			float elapsedTime = 0f;
			while (elapsedTime < delayTime)
			{
				if (localPlayer.IsSleeping || localPlayer.IsReadyToSleep)
				{
					((MelonBase)this).LoggerInstance.Msg("Player is already sleeping. Force sleep canceled.");
					forceSleepDelayCoroutine = null;
					yield break;
				}
				elapsedTime += 1f;
				yield return (object)new WaitForSeconds(1f);
			}
			((MelonBase)this).LoggerInstance.Msg("Force sleep delay ended. Triggering forced sleep.");
			ForceSleep();
			if (startCooldownCoroutine == null)
			{
				startCooldownCoroutine = (Coroutine)MelonCoroutines.Start(StartCooldown());
			}
			forceSleepDelayCoroutine = null;
		}

		private void ForceSleep()
		{
			if (!canTriggerSleep)
			{
				((MelonBase)this).LoggerInstance.Msg("TriggerSleep() is on cooldown. Skipping execution.");
				return;
			}
			try
			{
				if ((Object)(object)Instance.sleepCanvas == (Object)null)
				{
					Instance.sleepCanvas = Object.FindObjectOfType<SleepCanvas>();
				}
				if ((Object)(object)Instance.sleepCanvas != (Object)null)
				{
					if (isFirstSleep)
					{
						Instance.sleepCanvas.onSleepEndFade.AddListener(UnityAction.op_Implicit((Action)FuncThatCallsOtherFunc));
						Instance.sleepCanvas.onSleepEndFade.AddListener(UnityAction.op_Implicit((Action)FuncThatCallsCooldownFunc));
						isFirstSleep = false;
					}
					canTriggerSleep = false;
					Instance.sleepCanvas.SetIsOpen(true);
					Instance.sleepCanvas.SleepStart();
					if (Instance.config.SleepSettings.Auto_Skip_Daily_Summary)
					{
						MelonCoroutines.Start(DelayDailySummaryPress(3f));
					}
					isForcedSleep = true;
				}
				else
				{
					((MelonBase)this).LoggerInstance.Error("Could not find SleepCanvas instance.");
				}
			}
			catch (Exception ex)
			{
				((MelonBase)this).LoggerInstance.Error("Error in TriggerSleep: " + ex.Message + "\n" + ex.StackTrace);
			}
			void FuncThatCallsCooldownFunc()
			{
				//IL_0028: Unknown result type (might be due to invalid IL or missing references)
				//IL_0032: Expected O, but got Unknown
				if (Instance.startCooldownCoroutine == null && !Instance.isStartCooldownRunning)
				{
					Instance.startCooldownCoroutine = (Coroutine)MelonCoroutines.Start(StartCooldown());
				}
			}
			void FuncThatCallsOtherFunc()
			{
				TriggerAfterSleepEffect();
			}
		}

		public IEnumerator DelayDailySummaryPress(float seconds)
		{
			yield return (object)new WaitForSeconds(seconds);
			Instance.dailySummary = Object.FindObjectOfType<DailySummary>();
			if ((Object)(object)Instance.dailySummary != (Object)null)
			{
				((UnityEvent)((Component)((Component)Instance.dailySummary).transform.Find("Container/Continue")).GetComponent<Button>().onClick).Invoke();
				Instance.dailySummary.SleepEnd();
				Instance.dailySummary.Close();
			}
			else
			{
				((MelonBase)this).LoggerInstance.Error("Could not find DailySummary instance.");
			}
		}

		public IEnumerator StartCooldown()
		{
			if (!isCooldownActive && !isStartCooldownRunning && startCooldownCoroutine == null)
			{
				isStartCooldownRunning = true;
				float num = Instance.config.SleepSettings.Cooldown_Time;
				if (num <= 10f)
				{
					((MelonBase)this).LoggerInstance.Error("Cooldown time is not set or invalid. Using default (300sec).");
					num = 300f;
				}
				isCooldownActive = true;
				((MelonBase)this).LoggerInstance.Msg($"Started {num}sec cooldown before next sleep can be triggered.");
				canTriggerSleep = false;
				yield return (object)new WaitForSeconds(num);
				canTriggerSleep = true;
				isCooldownActive = false;
				isStartCooldownRunning = false;
				((MelonBase)this).LoggerInstance.Msg("Cooldown ended. Sleep triggering is now enabled again.");
				startCooldownCoroutine = null;
			}
		}

		private void TriggerAfterSleepEffect()
		{
			//IL_0280: Unknown result type (might be due to invalid IL or missing references)
			//IL_028a: Expected O, but got Unknown
			if (isForcedSleep)
			{
				if (Instance.config.SleepSettings.Enable_Negative_Effects)
				{
					Player[] array = Il2CppArrayBase<Player>.op_Implicit(Object.FindObjectsOfType<Player>());
					foreach (Player val in array)
					{
						if ((Object)(object)val != (Object)null && (Object)(object)((Component)val).gameObject != (Object)null)
						{
							float num = Instance.config.SleepSettings.Negative_Effects_Probability / 100f;
							if (new Random().NextDouble() <= (double)num)
							{
								propertyManager.ApplyNegativePropertyToPlayer(val);
							}
							else
							{
								((MelonBase)this).LoggerInstance.Msg("No negative effect applied due to probability.");
							}
							isForcedSleep = false;
						}
						else
						{
							((MelonBase)this).LoggerInstance.Error("Player or Player GameObject is null.");
						}
					}
				}
				else
				{
					((MelonBase)this).LoggerInstance.Msg("Negative effects are disabled in the config.");
				}
				if (Instance.config.ArrestedEventSettings.Enable_GetArrested_Event)
				{
					if ((Object)(object)localPlayer != (Object)null && (Object)(object)((Component)localPlayer).gameObject != (Object)null)
					{
						float num2 = Instance.config.ArrestedEventSettings.GetArrested_Event_Probability / 100f;
						if (new Random().NextDouble() <= (double)num2)
						{
							if (Instance.config.ArrestedEventSettings.Enable_GetArrested_Event_SaveSpaces && eventManager.IsPlayerNearSaveProperty())
							{
								((MelonBase)this).LoggerInstance.Msg("Not arrested due to save space proximity.");
								return;
							}
							eventManager.AddNewPublicSleepingCrime();
							localPlayer.Arrest();
						}
						else
						{
							((MelonBase)this).LoggerInstance.Msg("Not arrested due to probability.");
						}
						isForcedSleep = false;
					}
					else
					{
						((MelonBase)this).LoggerInstance.Error("Player or Player GameObject is null.");
					}
				}
				else
				{
					((MelonBase)this).LoggerInstance.Msg("Arrested Event is disabled in the config.");
				}
				if (Instance.config.MurderedEventSettings.Enable_GetMurdered_Event)
				{
					if (!((Object)(object)localPlayer != (Object)null) || !((Object)(object)((Component)localPlayer).gameObject != (Object)null))
					{
						return;
					}
					float num3 = Instance.config.MurderedEventSettings.GetMurdered_Event_Probability / 100f;
					if (new Random().NextDouble() <= (double)num3)
					{
						if (Instance.config.MurderedEventSettings.Enable_GetMurdered_Event_SaveSpaces && eventManager.IsPlayerNearSaveProperty())
						{
							((MelonBase)this).LoggerInstance.Msg("Not murdered due to save space proximity.");
						}
						else
						{
							murderPlayerCoroutine = (Coroutine)MelonCoroutines.Start(eventManager.MurderPlayer());
						}
					}
				}
				else
				{
					((MelonBase)this).LoggerInstance.Msg("Murdered Event is disabled in the config.");
				}
			}
			else if (Instance.config.SleepSettings.Enable_Positive_Effects)
			{
				Player[] array = Il2CppArrayBase<Player>.op_Implicit(Object.FindObjectsOfType<Player>());
				foreach (Player val2 in array)
				{
					if ((Object)(object)val2 != (Object)null && (Object)(object)((Component)val2).gameObject != (Object)null)
					{
						float num4 = Instance.config.SleepSettings.Positive_Effects_Probability / 100f;
						if (new Random().NextDouble() <= (double)num4)
						{
							propertyManager.ApplyPositivePropertyToPlayer(val2);
						}
						else
						{
							((MelonBase)this).LoggerInstance.Msg("No positive effect applied due to probability.");
						}
					}
					else
					{
						((MelonBase)this).LoggerInstance.Error("Player or Player GameObject is null.");
					}
				}
			}
			else
			{
				((MelonBase)this).LoggerInstance.Msg("Positive effects are disabled in the config.");
			}
		}

		private IEnumerator WaitForSleepingAppAndCreateEntry()
		{
			while (!sleepingApp._isSleepingAppLoaded)
			{
				yield return (object)new WaitForSeconds(2f);
			}
			CreateAppEntries();
		}

		public void CreateAppEntries()
		{
			//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_0088: Unknown result type (might be due to invalid IL or missing references)
			//IL_008d: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fc: Unknown result type (might be due to invalid IL or missing references)
			//IL_0101: Unknown result type (might be due to invalid IL or missing references)
			//IL_0136: Unknown result type (might be due to invalid IL or missing references)
			//IL_013b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0029: Unknown result type (might be due to invalid IL or missing references)
			//IL_0033: Expected O, but got Unknown
			if (!isLegitVersion)
			{
				if (!sleepingApp._isSleepingAppLoaded && waitForSleepingAppCoroutine == null)
				{
					waitForSleepingAppCoroutine = (Coroutine)MelonCoroutines.Start(WaitForSleepingAppAndCreateEntry());
					return;
				}
				sleepingApp.AddEntryFromTemplate("GeneralSettingsSection", "General Settings", "~Forced Sleep, Enable/Disable Effects, Probabilitys, Durations~", null, Color32.op_Implicit(ColorUtil.GetColor("Cyan")), Path.Combine(UIElementsFolder, "Settings.png"));
				sleepingApp.AddEntryFromTemplate("PositiveEffectsSection", "Positive Effects", "~Choose positive Early-Sleep-Effects~", null, Color32.op_Implicit(ColorUtil.GetColor("Cyan")), Path.Combine(UIElementsFolder, "PositiveEffects.png"));
				sleepingApp.AddEntryFromTemplate("NegativeEffectsSection", "Negative Effects", "~Choose negative Forced-Sleep-Effects~", null, Color32.op_Implicit(ColorUtil.GetColor("Cyan")), Path.Combine(UIElementsFolder, "NegativeEffects.png"));
				sleepingApp.AddEntryFromTemplate("ArrestedEventSection", "Arrested Event", "~Adjust settings for the Arrested Event~", null, Color32.op_Implicit(ColorUtil.GetColor("Cyan")), Path.Combine(UIElementsFolder, "ArrestedEvent.png"));
				sleepingApp.AddEntryFromTemplate("MurderedEventSection", "Murdered Event", "~Adjust settings for the Murdered Event~", null, Color32.op_Implicit(ColorUtil.GetColor("Cyan")), Path.Combine(UIElementsFolder, "MurderedEvent.png"));
			}
		}

		public void ChangeAppIconImage(GameObject appIcon, string ImagePath)
		{
			//IL_0075: Unknown result type (might be due to invalid IL or missing references)
			//IL_0084: Unknown result type (might be due to invalid IL or missing references)
			if (ImagePath == null)
			{
				MelonLogger.Msg("ImagePath is null, skipping image change.");
				return;
			}
			Transform val = appIcon.transform.Find("Mask/Image");
			GameObject val2 = (((Object)(object)val != (Object)null) ? ((Component)val).gameObject : null);
			if ((Object)(object)val2 == (Object)null)
			{
				return;
			}
			Image component = val2.GetComponent<Image>();
			if (!((Object)(object)component == (Object)null))
			{
				Texture2D val3 = Utils.LoadCustomImage(ImagePath);
				if (!((Object)(object)val3 == (Object)null))
				{
					Sprite sprite = Sprite.Create(val3, new Rect(0f, 0f, (float)((Texture)val3).width, (float)((Texture)val3).height), new Vector2(0.5f, 0.5f));
					component.sprite = sprite;
				}
				else
				{
					((MelonBase)this).LoggerInstance.Msg("Custom image failed to load");
				}
			}
		}

		public void RegisterApp(GameObject App, string Title = "Unknown App")
		{
			GameObject val = GameObject.Find("Player_Local/CameraContainer/Camera/OverlayCamera/GameplayMenu/Phone/phone/HomeScreen/AppIcons");
			App.transform.SetParent(val.transform, false);
			((MelonBase)this).LoggerInstance.Msg("Added " + Title + " to Homescreen.");
		}
	}
}
namespace MoreRealisticSleeping.Util
{
	public static class FontLoader
	{
		public static Font openSansBold;

		public static bool openSansBoldIsInitialized;

		public static Font openSansSemiBold;

		public static bool openSansSemiBoldIsInitialized;

		public static IEnumerator InitializeFonts()
		{
			openSansBold = FindFontFromOtherApp("openSansBold");
			openSansSemiBold = FindFontFromOtherApp("openSansSemiBold");
			yield break;
		}

		public static Font FindFontFromOtherApp(string fontName)
		{
			Font result = Resources.GetBuiltinResource<Font>("Arial.ttf");
			if (fontName == "openSansBold")
			{
				Text componentInChildren = Utils.GetAppCanvasByName("ProductManagerApp/Container/Topbar").GetComponentInChildren<Text>();
				if ((Object)(object)componentInChildren != (Object)null)
				{
					result = componentInChildren.font;
					openSansBoldIsInitialized = true;
				}
				else
				{
					MelonLogger.Msg("openSansBold Font not found");
				}
				return result;
			}
			if (fontName == "openSansSemiBold")
			{
				Text componentInChildren2 = Utils.GetAppCanvasByName("DeliveryApp/Container/Scroll View/Viewport/Content/Albert Hoover/Header").GetComponentInChildren<Text>();
				if ((Object)(object)componentInChildren2 != (Object)null)
				{
					result = componentInChildren2.font;
					openSansSemiBoldIsInitialized = true;
				}
				else
				{
					MelonLogger.Msg("openSansSemiBold Font not found");
				}
				return result;
			}
			return Resources.GetBuiltinResource<Font>("Arial.ttf");
		}
	}
	public static class ColorUtil
	{
		public static Dictionary<string, Color32> GetColors()
		{
			//IL_0016: 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_004f: Unknown result type (might be due to invalid IL or missing references)
			//IL_006a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0088: 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_00be: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f4: Unknown result type (might be due to invalid IL or missing references)
			//IL_0115: Unknown result type (might be due to invalid IL or missing references)
			//IL_0133: Unknown result type (might be due to invalid IL or missing references)
			//IL_014e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0169: Unknown result type (might be due to invalid IL or missing references)
			//IL_018d: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a8: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c3: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e7: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ff: Unknown result type (might be due to invalid IL or missing references)
			return new Dictionary<string, Color32>
			{
				{
					"Dark Blue",
					new Color32((byte)33, (byte)64, (byte)115, byte.MaxValue)
				},
				{
					"Light Blue",
					new Color32((byte)83, (byte)126, (byte)158, byte.MaxValue)
				},
				{
					"Light Purple",
					new Color32((byte)87, (byte)82, (byte)153, (byte)127)
				},
				{
					"Purple",
					new Color32((byte)108, (byte)35, (byte)114, byte.MaxValue)
				},
				{
					"Bright Green",
					new Color32((byte)85, (byte)198, (byte)30, byte.MaxValue)
				},
				{
					"Olive Green",
					new Color32((byte)67, (byte)99, (byte)33, byte.MaxValue)
				},
				{
					"Dark Green",
					new Color32((byte)91, (byte)127, (byte)9, byte.MaxValue)
				},
				{
					"Cyan",
					new Color32((byte)9, (byte)115, (byte)119, byte.MaxValue)
				},
				{
					"Dark Red",
					new Color32((byte)99, (byte)33, (byte)37, byte.MaxValue)
				},
				{
					"Yellow",
					new Color32((byte)208, (byte)174, (byte)54, byte.MaxValue)
				},
				{
					"Orange",
					new Color32((byte)178, (byte)78, (byte)44, byte.MaxValue)
				},
				{
					"Grey",
					new Color32((byte)49, (byte)49, (byte)49, byte.MaxValue)
				},
				{
					"Light Grey",
					new Color32((byte)90, (byte)90, (byte)90, byte.MaxValue)
				},
				{
					"Ultra Light Grey",
					new Color32((byte)150, (byte)150, (byte)150, byte.MaxValue)
				},
				{
					"Dark Grey",
					new Color32((byte)30, (byte)30, (byte)30, byte.MaxValue)
				},
				{
					"Redpurple",
					new Color32((byte)112, (byte)21, (byte)37, byte.MaxValue)
				},
				{
					"White",
					new Color32(byte.MaxValue, byte.MaxValue, byte.MaxValue, byte.MaxValue)
				},
				{
					"Black",
					new Color32((byte)0, (byte)0, (byte)0, byte.MaxValue)
				}
			};
		}

		public static Color32 GetColor(string colorName)
		{
			//IL_000f: Unknown result type (might be due to invalid IL or missing references)
			if (GetColors().TryGetValue(colorName, out var value))
			{
				return value;
			}
			throw new KeyNotFoundException("Color '" + colorName + "' not found.");
		}
	}
	public static class Utils
	{
		public static GameObject GetAppIconByName(string Name, int? Index, string newObjectName = null)
		{
			int valueOrDefault = Index.GetValueOrDefault();
			GameObject[] array = (from t in (IEnumerable<Transform>)GameObject.Find("Player_Local/CameraContainer/Camera/OverlayCamera/GameplayMenu/Phone/phone/HomeScreen/AppIcons/").GetComponentsInChildren<Transform>(true)
				let labelTransform = ((Component)t).gameObject.transform.Find("Label")
				let textComponent = ((Object)(object)labelTransform != (Object)null) ? ((Component)labelTransform).GetComponent<Text>() : null
				where (Object)(object)textComponent != (Object)null && textComponent.text != null && textComponent.text.StartsWith(Name)
				select ((Component)t).gameObject).ToArray();
			if (valueOrDefault >= array.Length)
			{
				MelonLogger.Error($"Index {valueOrDefault} is out of range. Returning null.");
				return null;
			}
			GameObject val = array[valueOrDefault];
			if (newObjectName != null)
			{
				((Object)val).name = newObjectName;
			}
			return val;
		}

		public static GameObject ChangeLabelFromAppIcon(string appIconName, string newLabel)
		{
			if (string.IsNullOrEmpty(appIconName) || string.IsNullOrEmpty(newLabel))
			{
				MelonLogger.Error("AppIcon name or new label is null or empty.");
				return null;
			}
			GameObject appIconByName = GetAppIconByName(appIconName, 1, newLabel);
			Transform val = appIconByName.transform.Find("Label");
			GameObject val2 = (((Object)(object)appIconByName != (Object)null) ? ((Component)val).gameObject : null);
			if ((Object)(object)val2 != (Object)null)
			{
				Text component = val2.GetComponent<Text>();
				if ((Object)(object)component != (Object)null)
				{
					component.text = newLabel;
				}
			}
			return appIconByName;
		}

		public static GameObject GetAppCanvasByName(string Name)
		{
			return ((Component)GameObject.Find("Player_Local/CameraContainer/Camera/OverlayCamera/GameplayMenu/Phone/phone/AppsCanvas/").transform.Find(Name)).gameObject;
		}

		public static IEnumerator WaitForObjectByFrame(string path, Action<GameObject> callback)
		{
			GameObject obj = null;
			while ((Object)(object)obj == (Object)null)
			{
				obj = GameObject.Find(path);
				yield return null;
			}
			callback?.Invoke(obj);
		}

		public static IEnumerator WaitForObject(string path, Action<GameObject> callback, float timeout = 30f)
		{
			GameObject obj = null;
			float timer = 0f;
			while ((Object)(object)obj == (Object)null && timer < timeout)
			{
				obj = GameObject.Find(path);
				if ((Object)(object)obj != (Object)null)
				{
					break;
				}
				yield return (object)new WaitForSeconds(0.1f);
				timer += 0.1f;
			}
			callback?.Invoke(obj);
		}

		public static void ClearChildren(Transform parent, Func<GameObject, bool> keepFilter = null)
		{
			GameObject[] array = (from t in (IEnumerable<Transform>)((Component)parent).GetComponentsInChildren<Transform>(true)
				select ((Component)t).gameObject into obj
				where (Object)(object)obj.transform != (Object)(object)parent
				select obj).ToArray();
			foreach (GameObject val in array)
			{
				if (keepFilter == null || !keepFilter(val))
				{
					val.transform.parent = null;
					Object.Destroy((Object)(object)val);
				}
			}
		}

		public static Texture2D LoadCustomImage(string path)
		{
			//IL_0030: Unknown result type (might be due to invalid IL or missing references)
			//IL_0035: Unknown result type (might be due to invalid IL or missing references)
			//IL_0041: Expected O, but got Unknown
			//IL_0043: Expected O, but got Unknown
			string path2 = Path.Combine(MelonEnvironment.UserDataDirectory, path);
			Texture2D result;
			if (!File.Exists(path2))
			{
				result = null;
				Debug.LogError(Object.op_Implicit("Specified path does not exist."));
			}
			else
			{
				byte[] array = File.ReadAllBytes(path2);
				Texture2D val = new Texture2D(2, 2);
				ImageConversion.LoadImage(val, Il2CppStructArray<byte>.op_Implicit(array));
				result = val;
			}
			return result;
		}
	}
}
namespace MoreRealisticSleeping.EventManager
{
	public class EventManager
	{
		private class SaveProperty
		{
			public Vector3 Position { get; }

			public float Radius { get; }

			public SaveProperty(Vector3 position, float radius)
			{
				//IL_0007: Unknown result type (might be due to invalid IL or missing references)
				//IL_0008: Unknown result type (might be due to invalid IL or missing references)
				Position = position;
				Radius = radius;
			}
		}

		private DeathScreen cachedDeathScreen;

		public string[] crimeNames = new string[42]
		{
			"Street Snoozing", "Sidewalk Slumber", "Public Napping", "Unauthorized Resting", "Curbside Coma", "Dreaming on Duty", "Concrete Cuddling", "Nap Dealing", "Loitering Horizontal", "Dozing Without Permit",
			"Urban Hibernation", "Bench Bedtime", "Crash Landing", "Sleep Trafficking", "Illegal REM Cycle", "Pavement Pilgrimage", "Vagrancy Nap Offense", "Blocking the park bench", "Passing Out Publicly", "Slumber Under Surveillance",
			"Unauthorized Zoning", "Resting in Restricted Area", "Curbside Nap Offense", "Public Resting Violation", "Unauthorized Siesta", "Street Slumbering", "Sidewalk Snoozing", "Public Dozing", "Unauthorized Napping", "Curbside Sleeping",
			"Dreaming on the Job", "Concrete Sleeping", "Nap Trafficking", "Loitering in a Horizontal Position", "Dozing Without a Permit", "Urban Sleeping", "Bench Sleeping", "Crash Sleeping", "Sleep Smuggling", "Illegal REM Offense",
			"Pavement Sleeping", "Vagrancy Sleeping Offense"
		};

		private Dictionary<string, SaveProperty> SaveProperties = new Dictionary<string, SaveProperty>
		{
			{
				"Laundromat",
				new SaveProperty(new Vector3(-28.689548f, 1.5649998f, 25.043943f), 6f)
			},
			{
				"Post Office",
				new SaveProperty(new Vector3(47.377815f, 1.1149997f, 0.7196727f), 7f)
			},
			{
				"Car Wash",
				new SaveProperty(new Vector3(-4.6848783f, 1.215f, -18.462233f), 5f)
			},
			{
				"Taco Ticklers",
				new SaveProperty(new Vector3(-30.715487f, 1.065f, 73.0847f), 12f)
			},
			{
				"RV",
				new SaveProperty(new Vector3(13.743962f, 2.040004f, -83.97922f), 5f)
			},
			{
				"Storage Unit",
				new SaveProperty(new Vector3(-2.3448243f, 1.0649998f, 103.91907f), 10f)
			},
			{
				"Motel Room",
				new SaveProperty(new Vector3(-71.374756f, 2.8194952f, 84.27474f), 5f)
			},
			{
				"Sweatshop",
				new SaveProperty(new Vector3(-61.0836f, 0.8124299f, 141.54001f), 6.5f)
			},
			{
				"Bungalow",
				new SaveProperty(new Vector3(-171.36903f, -2.7349997f, 115.365295f), 10f)
			},
			{
				"Barn",
				new SaveProperty(new Vector3(190.93658f, 1.0649998f, -10.902634f), 20f)
			},
			{
				"Docks Warehouse",
				new SaveProperty(new Vector3(-90.65439f, -1.2549964f, -51.6541f), 15f)
			},
			{
				"Manor",
				new SaveProperty(new Vector3(163.3927f, 11.464999f, -57.151375f), 25f)
			}
		};

		public IEnumerator MurderPlayer()
		{
			if (!((Object)(object)MRSCore.Instance.localPlayer != (Object)null))
			{
				yield break;
			}
			MRSCore.Instance.localPlayer.Health.TakeDamage(100f, true, true);
			DeathScreen deathScreen = Object.FindObjectOfType<DeathScreen>();
			if ((Object)(object)deathScreen != (Object)null)
			{
				cachedDeathScreen = deathScreen;
				MelonLogger.Msg("Death screen found.");
				while (!((Component)deathScreen.Container).gameObject.activeSelf)
				{
					yield return (object)new WaitForSeconds(1f);
				}
				if (MRSCore.Instance.config.MurderedEventSettings.Allow_GetMurdered_Event_Respawning)
				{
					deathScreen.RespawnClicked();
				}
			}
			else
			{
				MelonLogger.Warning("Death screen is not found.");
			}
		}

		public void AddNewPublicSleepingCrime()
		{
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			//IL_0008: Expected O, but got Unknown
			int num = 1;
			Vandalism val = new Vandalism();
			((Crime)val).CrimeName = crimeNames[Random.Range(0, crimeNames.Length)];
			MRSCore.Instance.localPlayerCrimeData.Crimes.Add((Crime)(object)val, num);
		}

		public bool IsPlayerNearSaveProperty(float tolerance = 10f)
		{
			//IL_003b: 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_0057: Unknown result type (might be due to invalid IL or missing references)
			//IL_005f: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)MRSCore.Instance.localPlayer != (Object)null && (Object)(object)((Component)MRSCore.Instance.localPlayer).transform != (Object)null)
			{
				Vector3 position = ((Component)MRSCore.Instance.localPlayer).transform.position;
				foreach (KeyValuePair<string, SaveProperty> saveProperty in SaveProperties)
				{
					if (Vector3.Distance(position, saveProperty.Value.Position) <= saveProperty.Value.Radius + tolerance)
					{
						return true;
					}
				}
				return false;
			}
			MelonLogger.Warning("Local player or player transform is null.");
			return false;
		}
	}
}
namespace MoreRealisticSleeping.PhoneApp
{
	public class SleepingApp
	{
		private static readonly string ConfigFolder = Path.Combine(MelonEnvironment.UserDataDirectory, "MoreRealisticSleeping");

		private static readonly string AppIconFilePath = Path.Combine(ConfigFolder, "SleepingAppIcon.png");

		private static readonly string UIElementsFolder = Path.Combine(ConfigFolder, "UIElements");

		public bool _isSleepingAppLoaded;

		private bool isSaveStillRunning;

		private Transform sleepingAppViewportContentTransform;

		public GameObject DansHardwareTemplate;

		public GameObject GasMartWestTemplate;

		private GameObject generalSettingsObject;

		private GameObject positiveEffectsObject;

		private GameObject negativeEffectsObject;

		private GameObject arrestedEventObject;

		private GameObject murderedEventObject;

		private GameObject checkboxTemplate;

		private GameObject viewPortContentSpaceTemplate;

		private GameObject detailsTitleObject;

		private GameObject detailsSubtitleObject;

		private Transform settingsContentTransform;

		private GameObject InstructionsTextObject;

		private Sprite appIconSprite;

		private Sprite saveButtonSprite;

		private Sprite inputBackgroundSprite;

		private Sprite settingsSprite;

		private Sprite positiveEffectsSprite;

		private Sprite negativeEffectsSprite;

		private Sprite arrestedEventSprite;

		private Sprite murderedEventSprite;

		public IEnumerator InitializeLaunderApp()
		{
			while (MRSCore.Instance == null)
			{
				MelonLogger.Msg("Waiting for Instance to be initialized...");
				yield return (object)new WaitForSeconds(1f);
			}
			MelonCoroutines.Start(FontLoader.InitializeFonts());
			while (!FontLoader.openSansBoldIsInitialized || !FontLoader.openSansSemiBoldIsInitialized)
			{
				MelonLogger.Msg("Waiting for Fonts to be loaded...");
				yield return (object)new WaitForSeconds(2f);
			}
			yield return MelonCoroutines.Start(CreateApp("SleepDose", "SleepDose", IsRotated: true, AppIconFilePath));
		}

		public IEnumerator CreateApp(string IDName, string Title, bool IsRotated = true, string IconPath = null)
		{
			GameObject cloningCandidateProducts = null;
			string cloningNameProducts = null;
			GameObject cloningCandidateDeliveries = null;
			string cloningNameDeliveries = null;
			GameObject cloningCandidateProductsCopy = null;
			string cloningNameProductsCopy = null;
			GameObject icons = null;
			yield return MelonCoroutines.Start(Utils.WaitForObject("Player_Local/CameraContainer/Camera/OverlayCamera/GameplayMenu/Phone/phone/HomeScreen/AppIcons/", delegate(GameObject obj)
			{
				icons = obj;
			}));
			if (IsRotated)
			{
				yield return MelonCoroutines.Start(Utils.WaitForObject("Player_Local/CameraContainer/Camera/OverlayCamera/GameplayMenu/Phone/phone/AppsCanvas/DeliveryApp", delegate(GameObject objD)
				{
					cloningCandidateDeliveries = objD;
					cloningNameDeliveries = "Deliveries";
				}));
				yield return MelonCoroutines.Start(Utils.WaitForObject("Player_Local/CameraContainer/Camera/OverlayCamera/GameplayMenu/Phone/phone/AppsCanvas/ProductManagerApp", delegate(GameObject objP)
				{
					cloningCandidateProductsCopy = objP;
					cloningNameProductsCopy = "Products";
				}));
				yield return MelonCoroutines.Start(Utils.WaitForObject("Player_Local/CameraContainer/Camera/OverlayCamera/GameplayMenu/Phone/phone/AppsCanvas/ProductManagerApp", delegate(GameObject obj)
				{
					cloningCandidateProducts = obj;
					cloningNameProducts = "Products";
				}));
			}
			GameObject val = GameObject.Find("Player_Local/CameraContainer/Camera/OverlayCamera/GameplayMenu/Phone/phone/AppsCanvas/");
			GameObject obj2 = Object.Instantiate<GameObject>(cloningCandidateDeliveries, val.transform);
			((Object)obj2).name = "DeliveriesTemp";
			GameObject val2 = Object.Instantiate<GameObject>(cloningCandidateProductsCopy, val.transform);
			((Object)obj2).name = "ProductsTemp";
			GameObject obj3 = Object.Instantiate<GameObject>(cloningCandidateProducts, val.transform);
			((Object)obj3).name = IDName;
			GameObject val3 = Utils.ChangeLabelFromAppIcon(cloningNameDeliveries, "DeliveriesCopy");
			GameObject val4 = Utils.ChangeLabelFromAppIcon(cloningNameProductsCopy, "ProductsCopy");
			Transform val5 = obj3.transform.Find("Container");
			Transform val6 = val5.Find("Topbar");
			if ((Object)(object)val6 != (Object)null)
			{
				((Graphic)((Component)val6).GetComponent<Image>()).color = Color32.op_Implicit(ColorUtil.GetColor("Cyan"));
				Transform val7 = val6.Find("Title");
				if ((Object)(object)val7 != (Object)null)
				{
					((Component)val7).GetComponent<Text>().text = Title;
				}
				Transform val8 = val6.Find("Subtitle");
				if ((Object)(object)val8 != (Object)null)
				{
					((Component)val8).GetComponent<Text>().text = "by KampfBallerina";
					((Component)val8).GetComponent<Text>().alignment = (TextAnchor)5;
					((Graphic)((Component)val8).GetComponent<Text>()).color = Color32.op_Implicit(ColorUtil.GetColor("White"));
					((Component)val8).GetComponent<RectTransform>().anchorMax = new Vector2(0.98f, 1f);
				}
			}
			Transform val9 = val5.Find("Scroll View");
			if ((Object)(object)val9 != (Object)null)
			{
				((Component)val9).gameObject.SetActive(false);
				((Object)((Component)val9).gameObject).name = "DeactivatedScrollView";
			}
			Transform val10 = obj2.transform.Find("Container");
			if ((Object)(object)val10 != (Object)null)
			{
				Transform val11 = val10.Find("Scroll View");
				if ((Object)(object)val11 != (Object)null)
				{
					Transform val12 = ((Component)val11).transform.Find("Viewport");
					if ((Object)(object)val12 != (Object)null)
					{
						((Component)val12).transform.Find("Content");
					}
					Transform val13 = ((Component)val11).transform.Find("OrderSubmitted");
					if ((Object)(object)val13 != (Object)null)
					{
						Object.DestroyImmediate((Object)(object)((Component)val13).gameObject);
					}
					((Component)((Component)val11).transform).GetComponent<RectTransform>().sizeDelta = new Vector2(-100f, -60f);
					((Component)((Component)val11).transform).GetComponent<RectTransform>().anchoredPosition = new Vector2(-50f, -30f);
					val11.SetParent(val5, false);
				}
			}
			Transform val14 = val5.Find("Details");
			if ((Object)(object)val14 != (Object)null)
			{
				((Object)val14).name = "Details";
				((Component)val14).GetComponent<RectTransform>().sizeDelta = new Vector2(95f, -60f);
				((Component)val14).GetComponent<RectTransform>().anchoredPosition = new Vector2(-47.5f, -30f);
				Transform val15 = val14.Find("Scroll View/Viewport/Content/Title");
				if ((Object)(object)val15 != (Object)null)
				{
					detailsTitleObject = ((Component)val15).gameObject;
					detailsTitleObject.SetActive(false);
					((Component)val15).GetComponent<Text>().text = "DetailsTitleText";
				}
				Transform val16 = val14.Find("Scroll View/Viewport/Content/Description");
				if ((Object)(object)val16 != (Object)null)
				{
					((Component)val16).GetComponent<Text>().text = "This is going to be the description of the app.";
					((Component)val16).GetComponent<RectTransform>().anchoredPosition = new Vector2(0f, 0f);
					((Component)val16).GetComponent<RectTransform>().sizeDelta = new Vector2(400f, 50f);
					((Component)val16).GetComponent<Text>().fontSize = 18;
					((Component)val16).gameObject.SetActive(false);
					detailsSubtitleObject = ((Component)val16).gameObject;
				}
				settingsContentTransform = val14.Find("Scroll View/Viewport/Content");
				ObjectExt.Destroy((Object)(object)((Component)settingsContentTransform.Find("Value")).gameObject);
				ObjectExt.Destroy((Object)(object)((Component)settingsContentTransform.Find("Effects")).gameObject);
				ObjectExt.Destroy((Object)(object)((Component)settingsContentTransform.Find("Addiction")).gameObject);
				ObjectExt.Destroy((Object)(object)((Component)settingsContentTransform.Find("Recipes")).gameObject);
				ObjectExt.Destroy((Object)(object)((Component)settingsContentTransform.Find("RecipesContainer")).gameObject);
				ObjectExt.Destroy((Object)(object)((Component)settingsContentTransform.Find("Listed")).gameObject);
				ObjectExt.Destroy((Object)(object)((Component)settingsContentTransform.Find("Delisted")).gameObject);
				ObjectExt.Destroy((Object)(object)((Component)settingsContentTransform.Find("NotDiscovered")).gameObject);
				ObjectExt.Destroy((Object)(object)((Component)settingsContentTransform.Find("Properties")).gameObject);
				Transform val17 = val14.Find("Instruction");
				if ((Object)(object)val17 != (Object)null)
				{
					InstructionsTextObject = ((Component)val17).gameObject;
					Text component = ((Component)val17).GetComponent<Text>();
					component.text = "Select a section to adjust settings";
					component.fontSize = 20;
				}
				Transform val18 = settingsContentTransform.Find("Space");
				if ((Object)(object)val18 != (Object)null)
				{
					((Component)val18).gameObject.SetActive(true);
					RectTransform component2 = ((Component)val18).GetComponent<RectTransform>();
					component2.sizeDelta = new Vector2(component2.sizeDelta.x, 200f);
				}
			}
			CreateTemplates(val5, settingsContentTransform);
			Object.DestroyImmediate((Object)(object)val3.gameObject);
			ObjectExt.Destroy((Object)(object)obj2);
			Object.DestroyImmediate((Object)(object)val4.gameObject);
			ObjectExt.Destroy((Object)(object)val2);
			GameObject val19 = Utils.ChangeLabelFromAppIcon(cloningNameProducts, Title);
			MRSCore.Instance.ChangeAppIconImage(val19, IconPath);
			MRSCore.Instance.RegisterApp(val19, Title);
			((Component)settingsContentTransform).gameObject.SetActive(true);
			AddUiForGeneralSettings(settingsContentTransform);
			AddUiForPositiveEffects(settingsContentTransform);
			AddUiForNegativeEffects(settingsContentTransform);
			AddUIForArrestedEvent(settingsContentTransform);
			AddUIForMurderedEvent(settingsContentTransform);
			_isSleepingAppLoaded = true;
		}

		private void CreateTemplates(Transform deliveriesContainer, Transform productsContainer = null)
		{
			//IL_00f9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fe: Unknown result type (might be due to invalid IL or missing references)
			//IL_0125: Unknown result type (might be due to invalid IL or missing references)
			//IL_0201: Unknown result type (might be due to invalid IL or missing references)
			//IL_0206: Unknown result type (might be due to invalid IL or missing references)
			//IL_0233: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)deliveriesContainer == (Object)null)
			{
				MelonLogger.Error("Container not found!");
				return;
			}
			if ((Object)(object)productsContainer != (Object)null)
			{
				Transform val = productsContainer.Find("Toggle");
				if ((Object)(object)val != (Object)null)
				{
					_ = (Object)(object)((Component)val).GetComponent<RectTransform>() != (Object)null;
					if ((Object)(object)((Component)val).GetComponent<HorizontalLayoutGroup>() == (Object)null)
					{
						HorizontalLayoutGroup obj = ((Component)val).gameObject.AddComponent<HorizontalLayoutGroup>();
						((HorizontalOrVerticalLayoutGroup)obj).spacing = 100f;
						((HorizontalOrVerticalLayoutGroup)obj).childForceExpandWidth = false;
						((HorizontalOrVerticalLayoutGroup)obj).childForceExpandHeight = false;
						((HorizontalOrVerticalLayoutGroup)obj).childControlWidth = true;
						((HorizontalOrVerticalLayoutGroup)obj).childControlHeight = true;
						((LayoutGroup)obj).childAlignment = (TextAnchor)3;
					}
					if ((Object)(object)((Component)val).GetComponent<ContentSizeFitter>() == (Object)null)
					{
						ContentSizeFitter obj2 = ((Component)val).gameObject.AddComponent<ContentSizeFitter>();
						obj2.horizontalFit = (FitMode)2;
						obj2.verticalFit = (FitMode)0;
					}
					Transform val2 = val.Find("Text");
					if ((Object)(object)val2 != (Object)null)
					{
						Text component = ((Component)val2).GetComponent<Text>();
						component.font = FontLoader.openSansSemiBold ?? Resources.GetBuiltinResource<Font>("Arial.ttf");
						component.text = "toggleTransformText";
						((Graphic)component).color = Color32.op_Implicit(ColorUtil.GetColor("White"));
						component.fontSize = 18;
						val2.SetAsFirstSibling();
						((Component)val2).GetComponent<RectTransform>().sizeDelta = new Vector2(325f, 30f);
						if ((Object)(object)((Component)val2).GetComponent<LayoutElement>() == (Object)null)
						{
							((Component)val2).gameObject.AddComponent<LayoutElement>().minWidth = 325f;
						}
					}
					Toggle component2 = ((Component)val).GetComponent<Toggle>();
					if ((Object)(object)component2 != (Object)null)
					{
						component2.isOn = false;
						((UnityEventBase)component2.onValueChanged).RemoveAllListeners();
					}
					Transform val3 = val.Find("Background");
					if ((Object)(object)val3 != (Object)null)
					{
						((Object)val3).name = "CheckboxBackground";
						if ((Object)(object)((Component)val3).GetComponent<LayoutElement>() == (Object)null)
						{
							LayoutElement obj3 = ((Component)val3).gameObject.AddComponent<LayoutElement>();
							obj3.minWidth = 30f;
							obj3.preferredWidth = 30f;
							obj3.minHeight = 30f;
							obj3.preferredHeight = 30f;
						}
					}
					Transform val4 = val3.Find("Checkmark");
					if ((Object)(object)val4 != (Object)null)
					{
						((Graphic)((Component)val4).GetComponent<Image>()).color = Color32.op_Implicit(ColorUtil.GetColor("Cyan"));
					}
					RectTransform component3 = ((Component)val).gameObject.GetComponent<RectTransform>();
					if ((Object)(object)component3 != (Object)null)
					{
						component3.sizeDelta = new Vector2(30f, 30f);
					}
					checkboxTemplate = Object.Instantiate<GameObject>(((Component)val).gameObject);
					((Object)checkboxTemplate).name = "Checkbox Template";
					checkboxTemplate.SetActive(true);
					ObjectExt.Destroy((Object)(object)((Component)val).gameObject);
				}
			}
			Transform val5 = deliveriesContainer.Find("Scroll View");
			if (!((Object)(object)val5 != (Object)null))
			{
				return;
			}
			Transform val6 = val5.Find("OrderSubmitted");
			if ((Object)(object)val6 != (Object)null)
			{
				ObjectExt.Destroy((Object)(object)((Component)val6).gameObject);
			}
			Transform val7 = val5.Find("Viewport");
			if (!((Object)(object)val7 != (Object)null))
			{
				return;
			}
			Transform val8 = val7.Find("Content");
			if ((Object)(object)val8 != (Object)null)
			{
				sleepingAppViewportContentTransform = val8;
				GameObject gameObject = ((Component)val8.Find("Dan's Hardware")).gameObject;
				GameObject gameObject2 = ((Component)val8.Find("Gas-Mart (West)")).gameObject;
				GameObject gameObject3 = ((Component)val8.Find("Space")).gameObject;
				if ((Object)(object)gameObject != (Object)null && (Object)(object)DansHardwareTemplate == (Object)null)
				{
					DansHardwareTemplate = Object.Instantiate<GameObject>(gameObject);
					((Object)DansHardwareTemplate).name = "Dan's Hardware Template";
					DansHardwareTemplate.SetActive(false);
					Transform val9 = DansHardwareTemplate.transform.Find("Contents");
					if ((Object)(object)val9 != (Object)null)
					{
						Object.DestroyImmediate((Object)(object)((Component)val9).gameObject);
					}
					Object.Destroy((Object)(object)gameObject);
				}
				if ((Object)(object)gameObject2 != (Object)null && (Object)(object)GasMartWestTemplate == (Object)null)
				{
					GasMartWestTemplate = Object.Instantiate<GameObject>(gameObject2);
					((Object)GasMartWestTemplate).name = "Gas-Mart (West) Template";
					GasMartWestTemplate.SetActive(false);
					Transform val10 = GasMartWestTemplate.transform.Find("Contents");
					if ((Object)(object)val10 != (Object)null)
					{
						Object.DestroyImmediate((Object)(object)((Component)val10).gameObject);
					}
					Object.Destroy((Object)(object)gameObject2);
				}
				if ((Object)(object)gameObject3 != (Object)null && (Object)(object)viewPortContentSpaceTemplate == (Object)null)
				{
					viewPortContentSpaceTemplate = Object.Instantiate<GameObject>(gameObject3);
					((Object)viewPortContentSpaceTemplate).name = "Space Template";
					viewPortContentSpaceTemplate.SetActive(false);
					Object.Destroy((Object)(object)gameObject3);
				}
				Utils.ClearChildren(val8);
				AddSpaceFromTemplate(val8);
			}
			else
			{
				MelonLogger.Error("Viewport Content not found!");
			}
		}

		public void AddSpaceFromTemplate(Transform parentTransform = null)
		{
			if ((Object)(object)parentTransform == (Object)null)
			{
				parentTransform = sleepingAppViewportContentTransform;
				if ((Object)(object)parentTransform == (Object)null)
				{
					MelonLogger.Error("ViewportContentTransform is null!");
					return;
				}
			}
			if ((Object)(object)viewPortContentSpaceTemplate == (Object)null)
			{
				MelonLogger.Error("Can't find Space Template!");
				return;
			}
			Transform val = parentTransform.Find("Space");
			if ((Object)(object)val != (Object)null)
			{
				val.SetAsLastSibling();
				return;
			}
			GameObject obj = Object.Instantiate<GameObject>(viewPortContentSpaceTemplate, parentTransform);
			((Object)obj).name = "Space";
			obj.transform.SetAsLastSibling();
			obj.SetActive(true);
		}

		public void AddEntryFromTemplate(string newObjectName, string newTitle, string newSubtitle = null, GameObject template = null, Color newBackgroundColor = default(Color), string imagePath = null, Transform parentTransform = null, bool isFirstEntry = false)
		{
			//IL_013d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0141: Unknown result type (might be due to invalid IL or missing references)
			//IL_0147: Unknown result type (might be due to invalid IL or missing references)
			//IL_0152: Unknown result type (might be due to invalid IL or missing references)
			//IL_017c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0183: Expected O, but got Unknown
			//IL_01af: Unknown result type (might be due to invalid IL or missing references)
			//IL_01be: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)parentTransform == (Object)null)
			{
				if ((Object)(object)sleepingAppViewportContentTransform == (Object)null)
				{
					MelonLogger.Error("ViewportContentTransform is null!");
					return;
				}
				parentTransform = sleepingAppViewportContentTransform;
			}
			if ((Object)(object)template == (Object)null && imagePath != null && File.Exists(imagePath))
			{
				if (Object.op_Implicit((Object)(object)DansHardwareTemplate))
				{
					template = DansHardwareTemplate;
				}
				else if (Object.op_Implicit((Object)(object)GasMartWestTemplate))
				{
					template = GasMartWestTemplate;
				}
			}
			GameObject val = Object.Instantiate<GameObject>(template, parentTransform);
			((Object)val).name = newObjectName;
			Transform obj = val.transform.Find("Header");
			Transform val2 = obj.Find("Icon").Find("Image");
			Transform val3 = obj.Find("Title");
			Transform val4 = obj.Find("Description");
			((Component)obj.Find("Arrow")).gameObject.SetActive(false);
			Text component = ((Component)val3).GetComponent<Text>();
			if ((Object)(object)component != (Object)null)
			{
				component.text = newTitle;
			}
			Text component2 = ((Component)val4).GetComponent<Text>();
			if ((Object)(object)component2 != (Object)null)
			{
				if (string.IsNullOrEmpty(newSubtitle))
				{
					((Component)component2).gameObject.SetActive(false);
				}
				else
				{
					component2.text = newSubtitle;
					((Component)component2).gameObject.SetActive(true);
				}
			}
			Image component3 = ((Component)obj).GetComponent<Image>();
			if ((Object)(object)component3 != (Object)null && newBackgroundColor != default(Color))
			{
				((Graphic)component3).color = newBackgroundColor;
			}
			if (!string.IsNullOrEmpty(imagePath) && File.Exists(imagePath))
			{
				byte[] array = File.ReadAllBytes(imagePath);
				Texture2D val5 = new Texture2D(2, 2);
				if (ImageConversion.LoadImage(val5, Il2CppStructArray<byte>.op_Implicit(array)))
				{
					Sprite sprite = Sprite.Create(val5, new Rect(0f, 0f, (float)((Texture)val5).width, (float)((Texture)val5).height), new Vector2(0.5f, 0.5f));
					Image component4 = ((Component)val2).GetComponent<Image>();
					if ((Object)(object)component4 != (Object)null)
					{
						component4.sprite = sprite;
						if (imagePath.Contains("SleepingAppIcon.png"))
						{
							appIconSprite = sprite;
						}
					}
				}
				else
				{
					MelonLogger.Error("Failed to load image from path: " + imagePath);
				}
			}
			Button component5 = ((Component)obj).GetComponent<Button>();
			if ((Object)(object)component5 != (Object)null)
			{
				((Object)component5).name = newObjectName + " Button";
				((UnityEventBase)component5.onClick).RemoveAllListeners();
				switch (newObjectName)
				{
				case "GeneralSettingsSection":
					((UnityEvent)component5.onClick).AddListener(UnityAction.op_Implicit((Action)FuncThatCallsFunc));
					break;
				case "PositiveEffectsSection":
					((UnityEvent)component5.onClick).AddListener(UnityAction.op_Implicit((Action)FuncThatCallsFunc));
					break;
				case "NegativeEffectsSection":
					((UnityEvent)component5.onClick).AddListener(UnityAction.op_Implicit((Action)FuncThatCallsFunc));
					break;
				case "ArrestedEventSection":
					((UnityEvent)component5.onClick).AddListener(UnityAction.op_Implicit((Action)FuncThatCallsFunc));
					break;
				case "MurderedEventSection":
					((UnityEvent)component5.onClick).AddListener(UnityAction.op_Implicit((Action)FuncThatCallsFunc));
					break;
				default:
					((UnityEvent)component5.onClick).AddListener(UnityAction.op_Implicit((Action)FuncThatCallsFunc));
					break;
				}
				if (isFirstEntry)
				{
					val.transform.SetAsFirstSibling();
				}
				val.SetActive(true);
			}
			AddSpaceFromTemplate(parentTransform);
			static void FuncThatCallsFunc()
			{
				MelonLogger.Msg("Clicked.");
			}
			void FuncThatCallsFunc()
			{
				MurderedEventSectionClicked();
			}
			void FuncThatCallsFunc()
			{
				ArrestedEventSectionClicked();
			}
			void FuncThatCallsFunc()
			{
				NegativeEffectsSectionClicked();
			}
			void FuncThatCallsFunc()
			{
				PositiveEffectsSectionClicked();
			}
			void FuncThatCallsFunc()
			{
				GeneralSettingsSectionClicked();
			}
		}

		private void PositiveEffectsSectionClicked()
		{
			if (InstructionsTextObject.activeSelf)
			{
				InstructionsTextObject.SetActive(false);
			}
			if (!detailsTitleObject.activeSelf)
			{
				detailsTitleObject.SetActive(true);
			}
			detailsTitleObject.GetComponent<Text>().text = "Positive Effects";
			if (!detailsSubtitleObject.activeSelf)
			{
				detailsSubtitleObject.SetActive(true);
			}
			detailsSubtitleObject.GetComponent<Text>().text = "Choose which effects you would like to ad