Decompiled source of Cute And Funny Framework v0.2.0

Mods/Cute&FunnyFramework.dll

Decompiled 3 months ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using System.Text;
using Cunny;
using Il2CppFishNet.Managing;
using Il2CppFishNet.Managing.Object;
using Il2CppFishNet.Object;
using Il2CppInterop.Runtime;
using Il2CppInterop.Runtime.InteropTypes.Arrays;
using Il2CppScheduleOne.NPCs;
using Il2CppScheduleOne.NPCs.Schedules;
using Il2CppScheduleOne.UI;
using Il2CppSystem;
using MelonLoader;
using MelonLoader.Utils;
using UnityEngine;
using UnityEngine.UI;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: MelonInfo(typeof(Core), "CUNNY", "0.1.0", "Fear&Delight", null)]
[assembly: MelonGame(null, null)]
[assembly: AssemblyTitle("CuteAndFunnyFramework")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("CuteAndFunnyFramework")]
[assembly: AssemblyCopyright("Copyright ©  2025")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("2123f85f-7bf1-428e-9d45-6ce3d55478a3")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")]
[assembly: AssemblyVersion("1.0.0.0")]
namespace Cunny
{
	public class Schedule
	{
		public static void CreateNotification(string title, string subtitle, Sprite icon, float duration = 5f, bool playSound = true)
		{
			GameObject.Find("UI/HUD/NotificationContainer").GetComponent<NotificationsManager>().SendNotification(title, subtitle, icon, duration, playSound);
			((MelonBase)Core.Instance).LoggerInstance.Warning("[CUNNY] Schedule.CreateNotification() is a deprecated function that will be removed in future versions! Please use Il2CppScheduleOne.UI.NotificationsManager.Instance.SendNotification() instead!");
		}
	}
	public class LocatorUtils
	{
		private static List<GameObject> cachedNPCs;

		private static List<GameObject> cachedPlayers;

		private static float lastUpdateTime;

		public static GameObject GetAppIconByName(string Name, int? Index)
		{
			int valueOrDefault = Index.GetValueOrDefault();
			return (from t in (IEnumerable<Transform>)GameObject.Find("Player_Local/CameraContainer/Camera/OverlayCamera/GameplayMenu/Phone/phone/HomeScreen/Viewport/Content/").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()[valueOrDefault];
		}

		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 void PrintAllPrefabs()
		{
			PrefabObjects spawnablePrefabs = Core.Instance.networkManager.SpawnablePrefabs;
			List<string> list = new List<string>();
			for (int i = 0; i < spawnablePrefabs.GetObjectCount(); i++)
			{
				NetworkObject @object = spawnablePrefabs.GetObject(true, i);
				list.Add(((Object)((Component)@object).gameObject).name);
			}
			list.Sort();
			((MelonBase)Core.Instance).LoggerInstance.Msg("---PRINTING ALL PREFABS FROM NETWORK MANAGER---");
			foreach (string item in list)
			{
				((MelonBase)Core.Instance).LoggerInstance.Msg(item);
			}
		}

		public static NetworkObject GetPrefabByName(string PrefabName)
		{
			PrefabObjects spawnablePrefabs = Core.Instance.networkManager.SpawnablePrefabs;
			for (int i = 0; i < spawnablePrefabs.GetObjectCount(); i++)
			{
				NetworkObject @object = spawnablePrefabs.GetObject(true, i);
				if (((Object)((Component)@object).gameObject).name == PrefabName)
				{
					return @object;
				}
			}
			((MelonBase)Core.Instance).LoggerInstance.Error("Could not find prefab named: " + PrefabName);
			return null;
		}

		public static void PrintStreamingAssets()
		{
			((MelonBase)Core.Instance).LoggerInstance.Msg("---PRINTING ALL ASSETS FROM STREAMING ASSETS---");
			string streamingAssetsPath = Application.streamingAssetsPath;
			if (!Directory.Exists(streamingAssetsPath))
			{
				((MelonBase)Core.Instance).LoggerInstance.Msg("StreamingAssets folder does not exist at: " + streamingAssetsPath);
			}
			else
			{
				PrintDirectoryTree(streamingAssetsPath, streamingAssetsPath, 0);
			}
		}

		private static void PrintDirectoryTree(string rootPath, string currentPath, int indent)
		{
			string text = new string(' ', indent * 2);
			string[] directories = Directory.GetDirectories(currentPath);
			foreach (string text2 in directories)
			{
				string fileName = Path.GetFileName(text2);
				((MelonBase)Core.Instance).LoggerInstance.Msg(text + "[Folder] " + fileName);
				PrintDirectoryTree(rootPath, text2, indent + 1);
			}
			directories = Directory.GetFiles(currentPath);
			for (int i = 0; i < directories.Length; i++)
			{
				string fileName2 = Path.GetFileName(directories[i]);
				((MelonBase)Core.Instance).LoggerInstance.Msg(text + "[File] " + fileName2);
			}
		}

		public static void PrintResources()
		{
			//IL_0053: Unknown result type (might be due to invalid IL or missing references)
			//IL_005a: Expected O, but got Unknown
			((MelonBase)Core.Instance).LoggerInstance.Msg("---PRINTING ALL RESOURCES FROM RESOURCES---");
			Object[] array = (Object[])(object)Il2CppArrayBase<Object>.op_Implicit((Il2CppArrayBase<Object>)(object)Resources.LoadAll("", Il2CppType.Of<Object>()));
			Object[] array2 = array;
			if (array2.Length == 0)
			{
				((MelonBase)Core.Instance).LoggerInstance.Msg("No assets found in the Resources folder.");
				return;
			}
			Dictionary<string, List<Object>> dictionary = new Dictionary<string, List<Object>>();
			array = array2;
			for (int i = 0; i < array.Length; i++)
			{
				Object val = (Object)array[i];
				string[] array3 = val.name.Split(new char[1] { '/' });
				string key = ((array3.Length > 1) ? string.Join("/", array3, 0, array3.Length - 1) : "(root)");
				if (!dictionary.ContainsKey(key))
				{
					dictionary[key] = new List<Object>();
				}
				dictionary[key].Add(val);
			}
			foreach (KeyValuePair<string, List<Object>> item in dictionary.OrderBy((KeyValuePair<string, List<Object>> f) => f.Key))
			{
				((MelonBase)Core.Instance).LoggerInstance.Msg("[Psuedo-Folder] " + item.Key);
				foreach (Object item2 in item.Value)
				{
					((MelonBase)Core.Instance).LoggerInstance.Msg("  [File] " + item2.name + " (" + ((object)item2).GetType().Name + ")");
				}
			}
		}

		public static void PrintAllVariablesOfTypeAll<T>() where T : Object
		{
			T[] array = Il2CppArrayBase<T>.op_Implicit(Resources.FindObjectsOfTypeAll<T>());
			if (array == null || array.Length == 0)
			{
				((MelonBase)Core.Instance).LoggerInstance.Msg("No instances of " + typeof(T).Name + " found.");
				return;
			}
			((MelonBase)Core.Instance).LoggerInstance.Msg($"---Found {array.Length} instances of {typeof(T).Name}: ---");
			T[] array2 = array;
			for (int i = 0; i < array2.Length; i++)
			{
				DumpObject(array2[i]);
			}
		}

		public static void DumpObject(object obj)
		{
			if (obj == null)
			{
				((MelonBase)Core.Instance).LoggerInstance.Msg("Null object passed to DumpObject.");
				return;
			}
			Type type = obj.GetType();
			((MelonBase)Core.Instance).LoggerInstance.Warning("      ");
			Instance loggerInstance = ((MelonBase)Core.Instance).LoggerInstance;
			string[] obj2 = new string[5] { "--- ", type.Name, ": ", null, null };
			Object val = (Object)((obj is Object) ? obj : null);
			obj2[3] = ((val != null) ? val.name : "Unnamed");
			obj2[4] = " ---";
			loggerInstance.Msg(string.Concat(obj2));
			FieldInfo[] fields = type.GetFields(BindingFlags.Instance | BindingFlags.Public);
			foreach (FieldInfo fieldInfo in fields)
			{
				object value = fieldInfo.GetValue(obj);
				((MelonBase)Core.Instance).LoggerInstance.Msg(fieldInfo.Name + ": " + FormatValue(value));
			}
			PropertyInfo[] properties = type.GetProperties(BindingFlags.Instance | BindingFlags.Public);
			foreach (PropertyInfo propertyInfo in properties)
			{
				if (propertyInfo.GetIndexParameters().Length == 0 && propertyInfo.CanRead)
				{
					object value2 = propertyInfo.GetValue(obj, null);
					((MelonBase)Core.Instance).LoggerInstance.Msg(propertyInfo.Name + ": " + FormatValue(value2));
				}
			}
		}

		private static string FormatValue(object value)
		{
			if (value == null)
			{
				return "null";
			}
			if (value is IEnumerable enumerable && !(value is string))
			{
				StringBuilder stringBuilder = new StringBuilder();
				stringBuilder.Append("[");
				foreach (object item in enumerable)
				{
					stringBuilder.Append(item?.ToString() + ", ");
				}
				if (stringBuilder.Length > 1)
				{
					stringBuilder.Length -= 2;
				}
				stringBuilder.Append("]");
				return stringBuilder.ToString();
			}
			return value.ToString();
		}

		public static void PrintAllHairStyles()
		{
		}
	}
	public class Utils
	{
		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_0033: Unknown result type (might be due to invalid IL or missing references)
			//IL_0038: Unknown result type (might be due to invalid IL or missing references)
			//IL_0044: Expected O, but got Unknown
			//IL_0046: 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("[CUNNY] 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;
		}
	}
	public class CoroutineUtils
	{
		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 IEnumerator Wait(float delay, Action callback)
		{
			yield return (object)new WaitForSeconds(delay);
			callback?.Invoke();
		}
	}
	public class Core : MelonMod
	{
		public static Core Instance;

		private ScrollRect HomeScreenScrollRect;

		private GameObject IconsPageTemplate;

		private GameObject CompatabilityIconsPage;

		private GameObject HomeScreenScrollRectContent;

		private HorizontalLayoutGroup HomeScreenHorizontalLayoutGroup;

		public List<GameObject> UIAppPages = new List<GameObject>();

		public List<List<GameObject>> AllApps = new List<List<GameObject>>();

		private int currentAppPage;

		private bool IsHomeScreenSnapped;

		private float snapSpeed;

		private float snapForce = 50f;

		private float snapOffset = -30f;

		private float snapDuration = 0.15f;

		private float snapVelocity;

		private float snapVelocityThreshold = 200f;

		private bool isInitialSnapDone;

		private RectTransform contentRect;

		private bool isDraggingBlocked;

		private float mouseDownTime;

		private Vector2 mouseDownPosition;

		private float minHoldDuration = 0.15f;

		private float dragThreshold = 15f;

		public GameObject networkManagerObj;

		public NetworkManager networkManager;

		public bool IsCunnyLoaded;

		public override void OnInitializeMelon()
		{
			Instance = this;
		}

		public override void OnUpdate()
		{
			//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_0092: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ae: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b9: Unknown result type (might be due to invalid IL or missing references)
			//IL_0105: Unknown result type (might be due to invalid IL or missing references)
			//IL_015e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0163: Unknown result type (might be due to invalid IL or missing references)
			//IL_017f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0262: Unknown result type (might be due to invalid IL or missing references)
			//IL_0267: Unknown result type (might be due to invalid IL or missing references)
			//IL_023b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0245: Unknown result type (might be due to invalid IL or missing references)
			//IL_0286: Unknown result type (might be due to invalid IL or missing references)
			if (!IsCunnyLoaded)
			{
				return;
			}
			if ((Object)(object)contentRect == (Object)null)
			{
				contentRect = HomeScreenScrollRectContent.GetComponent<RectTransform>();
				if ((Object)(object)contentRect == (Object)null)
				{
					return;
				}
			}
			((Behaviour)HomeScreenScrollRect).enabled = UIAppPages.Count > 1;
			if (!((Behaviour)HomeScreenScrollRect).enabled)
			{
				if (!isInitialSnapDone)
				{
					SnapImmediately(0);
					isInitialSnapDone = true;
				}
				return;
			}
			if (Input.GetMouseButtonDown(0))
			{
				mouseDownTime = Time.time;
				mouseDownPosition = Vector2.op_Implicit(Input.mousePosition);
				isDraggingBlocked = true;
			}
			if (Input.GetMouseButton(0) && isDraggingBlocked)
			{
				float num = Vector2.Distance(Vector2.op_Implicit(Input.mousePosition), mouseDownPosition);
				if (Time.time - mouseDownTime >= minHoldDuration || num >= dragThreshold)
				{
					isDraggingBlocked = false;
				}
			}
			if (isDraggingBlocked && HomeScreenScrollRect.m_Dragging)
			{
				HomeScreenScrollRect.velocity = Vector2.zero;
				SnapImmediately(currentAppPage);
				HomeScreenScrollRect.StopMovement();
			}
			if (!isInitialSnapDone)
			{
				SnapImmediately(0);
				isInitialSnapDone = true;
				return;
			}
			int count = UIAppPages.Count;
			if (count == 0)
			{
				return;
			}
			Rect rect = UIAppPages[0].GetComponent<RectTransform>().rect;
			float num2 = ((Rect)(ref rect)).width + ((HorizontalOrVerticalLayoutGroup)HomeScreenHorizontalLayoutGroup).spacing;
			float x = contentRect.anchoredPosition.x;
			currentAppPage = Mathf.Clamp(Mathf.RoundToInt((0f - x - snapOffset) / num2), 0, count - 1);
			float num3 = (float)(-currentAppPage) * num2 - snapOffset;
			float num4 = 0f - ((float)(count - 1) * num2 + snapOffset);
			float num5 = 0f - snapOffset;
			if (x < num4 || x > num5 || (!HomeScreenScrollRect.m_Dragging && Mathf.Abs(x - num3) < 1f))
			{
				SnapImmediately(currentAppPage);
				return;
			}
			if (!HomeScreenScrollRect.m_Dragging && !isDraggingBlocked)
			{
				contentRect.anchoredPosition = new Vector2(Mathf.SmoothDamp(x, num3, ref snapVelocity, snapDuration), contentRect.anchoredPosition.y);
			}
			if (!HomeScreenScrollRect.m_Dragging)
			{
				Vector2 velocity = HomeScreenScrollRect.velocity;
				if (!(((Vector2)(ref velocity)).magnitude > snapVelocityThreshold))
				{
					return;
				}
			}
			if (!isDraggingBlocked)
			{
				HomeScreenScrollRect.velocity = Vector2.zero;
				snapVelocity = 0f;
			}
		}

		private void SnapImmediately(int page)
		{
			//IL_001f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0024: Unknown result type (might be due to invalid IL or missing references)
			//IL_0077: Unknown result type (might be due to invalid IL or missing references)
			//IL_0081: Unknown result type (might be due to invalid IL or missing references)
			if (UIAppPages.Count != 0)
			{
				Rect rect = UIAppPages[0].GetComponent<RectTransform>().rect;
				float num = ((Rect)(ref rect)).width + ((HorizontalOrVerticalLayoutGroup)HomeScreenHorizontalLayoutGroup).spacing;
				float num2 = Mathf.Clamp((float)(-page) * num - snapOffset, 0f - ((float)(UIAppPages.Count - 1) * num + snapOffset), 0f - snapOffset);
				contentRect.anchoredPosition = new Vector2(num2, contentRect.anchoredPosition.y);
				snapVelocity = 0f;
			}
		}

		public override void OnLateUpdate()
		{
			bool toggle = false;
			if (IsCunnyLoaded && CompatabilityIconsPage.GetComponentsInChildren<Transform>().Count > 1)
			{
				((MelonBase)this).LoggerInstance.Msg("Missing app found, attempting to patch. Count: " + (CompatabilityIconsPage.GetComponentsInChildren<Transform>().Count - 1));
				GameObject[] array = (from t in (IEnumerable<Transform>)CompatabilityIconsPage.GetComponentsInChildren<Transform>(true)
					select ((Component)t).gameObject into obj
					where (Object)(object)obj.transform != (Object)(object)CompatabilityIconsPage
					select obj).ToArray();
				foreach (GameObject child2 in array)
				{
					MelonCoroutines.Start(Patcher(child2));
				}
			}
			IEnumerator Patcher(GameObject child)
			{
				while (!toggle)
				{
					toggle = true;
					yield return (object)new WaitForSeconds(5f);
				}
				RegisterApp(child);
				toggle = false;
			}
		}

		public override void OnSceneWasLoaded(int buildIndex, string sceneName)
		{
			((MelonBase)this).LoggerInstance.Msg($"Scene loaded: {sceneName} ({buildIndex})");
			if (sceneName.Equals("Main", StringComparison.OrdinalIgnoreCase))
			{
				FullCunnyReset();
				((MelonBase)this).LoggerInstance.Msg("Initializing Framework");
				PreInitCunny();
				MelonCoroutines.Start(InitCunny());
			}
			else if (sceneName.Equals("Menu", StringComparison.OrdinalIgnoreCase))
			{
				FullCunnyReset();
			}
		}

		private void FullCunnyReset()
		{
			networkManagerObj = null;
			networkManager = null;
			HomeScreenScrollRect = null;
			IconsPageTemplate = null;
			HomeScreenScrollRectContent = null;
			HomeScreenHorizontalLayoutGroup = null;
			CompatabilityIconsPage = null;
			UIAppPages.Clear();
			AllApps.Clear();
			currentAppPage = 0;
			IsHomeScreenSnapped = false;
			snapSpeed = 0f;
			snapForce = 100f;
			snapOffset = -30f;
			snapDuration = 0.15f;
			snapVelocity = 0f;
			isInitialSnapDone = false;
			IsCunnyLoaded = false;
		}

		private void PreInitCunny()
		{
			networkManagerObj = GameObject.Find("NetworkManager");
			networkManager = Object.FindObjectOfType<NetworkManager>();
		}

		private IEnumerator InitCunny()
		{
			GameObject Icons = null;
			yield return MelonCoroutines.Start(CoroutineUtils.WaitForObjectByFrame("Player_Local/CameraContainer/Camera/OverlayCamera/GameplayMenu/Phone/phone/HomeScreen/AppIcons/", delegate(GameObject obj)
			{
				Icons = obj;
			}));
			((MelonBase)this).LoggerInstance.Msg("Editing Homescreen");
			GameObject val = GameObject.Find("Player_Local/CameraContainer/Camera/OverlayCamera/GameplayMenu/Phone/phone/HomeScreen");
			ScrollRect val2 = val.AddComponent<ScrollRect>();
			val2.horizontal = true;
			val2.vertical = false;
			HomeScreenScrollRect = val2;
			GameObject val3 = new GameObject("Viewport", (Type[])(object)new Type[3]
			{
				Il2CppType.Of<RectTransform>(),
				Il2CppType.Of<Image>(),
				Il2CppType.Of<Mask>()
			});
			RectTransform component = val3.GetComponent<RectTransform>();
			val3.transform.SetParent(val.transform, false);
			component.anchorMin = Vector2.zero;
			component.anchorMax = Vector2.one;
			component.offsetMin = Vector2.zero;
			component.offsetMax = Vector2.zero;
			val3.GetComponent<Mask>().showMaskGraphic = false;
			GameObject val4 = (HomeScreenScrollRectContent = new GameObject("Content", (Type[])(object)new Type[1] { Il2CppType.Of<RectTransform>() }));
			RectTransform component2 = val4.GetComponent<RectTransform>();
			val4.transform.SetParent(val3.transform, false);
			component2.anchorMin = new Vector2(0f, 0.5f);
			component2.anchorMax = new Vector2(0f, 0.5f);
			component2.pivot = new Vector2(0f, 0.5f);
			component2.anchoredPosition = Vector2.zero;
			component2.sizeDelta = new Vector2(1000f, 200f);
			((Transform)component2).localPosition = new Vector3(((Transform)component2).localPosition.x, 300f, ((Transform)component2).localPosition.z);
			val4.AddComponent<ContentSizeFitter>().horizontalFit = (FitMode)2;
			val2.viewport = component;
			val2.content = component2;
			val2.m_Dragging = true;
			val2.m_ScrollSensitivity = 0f;
			HorizontalLayoutGroup val5 = val4.AddComponent<HorizontalLayoutGroup>();
			((HorizontalOrVerticalLayoutGroup)val5).childForceExpandHeight = false;
			((HorizontalOrVerticalLayoutGroup)val5).childForceExpandWidth = false;
			((HorizontalOrVerticalLayoutGroup)val5).spacing = 100f;
			HomeScreenHorizontalLayoutGroup = val5;
			Icons.transform.SetParent(val4.transform, true);
			UIAppPages.Add(Icons);
			AllApps.Add(new List<GameObject>());
			GameObject[] array = (from t in (IEnumerable<Transform>)Icons.GetComponentsInChildren<Transform>(true)
				select ((Component)t).gameObject into g
				where ((Object)g).name.StartsWith("AppIcon(Clone)")
				select g).ToArray();
			for (int i = 0; i < array.Length; i++)
			{
				AllApps[0].Add(array[i]);
			}
			((MelonBase)this).LoggerInstance.Msg("App & Page List Established");
			IconsPageTemplate = Object.Instantiate<GameObject>(Icons, (Transform)null);
			Utils.ClearChildren(IconsPageTemplate.transform);
			CompatabilityIconsPage = new GameObject("AppIcons", (Type[])(object)new Type[1] { Il2CppType.Of<RectTransform>() });
			CompatabilityIconsPage.transform.SetParent(val.transform, true);
			((MelonBase)this).LoggerInstance.Msg("[INIT COMPLETE] Cloned & Cleaned AppUI");
			IsCunnyLoaded = true;
		}

		public void ChangeAppIconImage(GameObject appIcon, string ImagePath)
		{
			//IL_0070: Unknown result type (might be due to invalid IL or missing references)
			//IL_007f: Unknown result type (might be due to invalid IL or missing references)
			if (ImagePath == null)
			{
				ImagePath = "CunnyFramework\\ExampleIco.png";
			}
			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")
		{
			if (AllApps[AllApps.Count - 1].Count >= 12)
			{
				((MelonBase)this).LoggerInstance.Msg("Exceeded Space For Page: " + (AllApps.Count - 1) + " Creating New Page");
				AllApps.Add(new List<GameObject>());
				UIAppPages.Add(Object.Instantiate<GameObject>(IconsPageTemplate, HomeScreenScrollRectContent.transform));
				((Behaviour)UIAppPages[UIAppPages.Count - 1].GetComponent<GridLayoutGroup>()).enabled = true;
				((Object)UIAppPages[UIAppPages.Count - 1]).name = "AppIcons" + UIAppPages.Count;
			}
			AllApps[AllApps.Count - 1].Add(App);
			App.transform.SetParent(UIAppPages[UIAppPages.Count - 1].transform, false);
			((MelonBase)this).LoggerInstance.Msg("Added " + Title + " to Page: " + AllApps.Count);
		}

		public void UnregisterApp(GameObject App)
		{
		}

		public IEnumerator CreateApp(string IDName, string Title, bool IsRotated = true, string IconPath = null)
		{
			GameObject CloningCandiate = null;
			string CloningName = null;
			GameObject icons = null;
			yield return MelonCoroutines.Start(CoroutineUtils.WaitForObject("Player_Local/CameraContainer/Camera/OverlayCamera/GameplayMenu/Phone/phone/HomeScreen/Viewport/Content/AppIcons/", delegate(GameObject obj)
			{
				icons = obj;
			}));
			if (IsRotated)
			{
				yield return MelonCoroutines.Start(CoroutineUtils.WaitForObject("Player_Local/CameraContainer/Camera/OverlayCamera/GameplayMenu/Phone/phone/AppsCanvas/ProductManagerApp", delegate(GameObject obj)
				{
					CloningCandiate = obj;
					CloningName = "Products";
				}));
			}
			else
			{
				yield return MelonCoroutines.Start(CoroutineUtils.WaitForObject("Player_Local/CameraContainer/Camera/OverlayCamera/GameplayMenu/Phone/phone/AppsCanvas/Messages", delegate(GameObject obj)
				{
					CloningCandiate = obj;
					CloningName = "Messages";
				}));
			}
			GameObject val = GameObject.Find("Player_Local/CameraContainer/Camera/OverlayCamera/GameplayMenu/Phone/phone/AppsCanvas/");
			GameObject obj2 = Object.Instantiate<GameObject>(CloningCandiate, val.transform);
			Utils.ClearChildren(obj2.transform.Find("Container"), (GameObject go) => ((Object)go).name == "Background");
			((Graphic)((Component)obj2.transform.Find("Container/Background")).GetComponent<Image>()).color = Color32.op_Implicit(new Color32((byte)240, (byte)240, (byte)240, byte.MaxValue));
			((Object)obj2).name = IDName;
			GameObject appIconByName = LocatorUtils.GetAppIconByName(CloningName, 1);
			Transform val2 = appIconByName.transform.Find("Label");
			GameObject val3 = (((Object)(object)val2 != (Object)null) ? ((Component)val2).gameObject : null);
			if ((Object)(object)val3 != (Object)null)
			{
				Text component = val3.GetComponent<Text>();
				if ((Object)(object)component != (Object)null)
				{
					component.text = Title;
				}
			}
			ChangeAppIconImage(appIconByName, IconPath);
			RegisterApp(appIconByName, Title);
		}
	}
}
namespace Cunny.Advanced
{
	public class NPCHandler
	{
		public static T AddToNPCSchedule<T>(GameObject NPC, Action<T> configure = null) where T : NPCAction
		{
			//IL_0016: Unknown result type (might be due to invalid IL or missing references)
			//IL_001b: Unknown result type (might be due to invalid IL or missing references)
			Transform parent = NPC.transform.Find("Schedule");
			GameObject val = new GameObject("Custom Action");
			val.transform.parent = parent;
			T val2 = val.AddComponent<T>();
			configure?.Invoke(val2);
			return val2;
		}

		public static void InitNPC(GameObject NPC)
		{
			((MelonBase)Core.Instance).LoggerInstance.Warning("---INIT NPC---");
			NPC.SetActive(true);
			((Component)NPC.transform.Find("Avatar")).gameObject.SetActive(true);
			_ = ((Component)NPC.transform.Find("Schedule")).gameObject;
			NPC component = NPC.gameObject.GetComponent<NPC>();
			component.Start();
			component.SetVisible(true);
			NPCHealth component2 = NPC.gameObject.GetComponent<NPCHealth>();
			component2.MaxHealth = 100f;
			component2.Health = 100f;
		}

		public static GameObject SpawnCivPrefab(string FullName = "First Last")
		{
			//IL_0076: Unknown result type (might be due to invalid IL or missing references)
			string text = FullName.Split(new char[1] { ' ' })[0];
			string text2 = FullName.Split(new char[1] { ' ' })[1];
			NetworkObject prefabByName = LocatorUtils.GetPrefabByName("CivilianNPC");
			((MelonBase)Core.Instance).LoggerInstance.Msg("PREFAB SPAWNING IS: " + ((Object)(object)prefabByName == (Object)null));
			NetworkObject obj = Object.Instantiate<NetworkObject>(prefabByName);
			((Component)obj).transform.position = new Vector3(-61.3939f, 0.975f, 84.0066f);
			((Object)((Component)obj).gameObject).name = text;
			NPC component = ((Component)obj).gameObject.GetComponent<NPC>();
			component.FirstName = text;
			component.LastName = text2;
			component.ID = text + "_" + text2;
			return ((Component)obj).gameObject;
		}
	}
}