Decompiled source of MoreRoutes v1.0.0

MoreRoutes.dll

Decompiled 2 days ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
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 HarmonyLib;
using Il2CppFluffyUnderware.DevTools.Extensions;
using Il2CppInterop.Runtime.InteropTypes.Arrays;
using Il2CppScheduleOne.Employees;
using Il2CppScheduleOne.Management;
using Il2CppScheduleOne.UI.Management;
using MelonLoader;
using Microsoft.CodeAnalysis;
using MoreRoutes;
using UnityEngine;
using UnityEngine.UI;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: MelonInfo(typeof(Core), "MoreRoutes", "1.0.0", "SleepyStew", null)]
[assembly: MelonGame("TVGS", "Schedule I")]
[assembly: TargetFramework(".NETCoreApp,Version=v6.0", FrameworkDisplayName = ".NET 6.0")]
[assembly: AssemblyCompany("MoreRoutes")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("MoreRoutes")]
[assembly: AssemblyTitle("MoreRoutes")]
[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;
		}
	}
}
namespace MoreRoutes
{
	public class Core : MelonMod
	{
		[HarmonyPatch(typeof(PackagerConfiguration), "ShouldSave")]
		private static class PatchPackagerConfigurationShouldSave
		{
			private static bool Prefix(ref bool __result)
			{
				__result = true;
				return false;
			}
		}

		[HarmonyPatch(typeof(Packager), "NetworkInitialize___Early")]
		private static class PatchPackagerAwake
		{
			private static void Postfix(ref Packager __instance)
			{
				MelonCoroutines.Start(ConfigureDelayed(__instance));
			}
		}

		[CompilerGenerated]
		private sealed class <ConfigureDelayed>d__7 : IEnumerator<object>, IEnumerator, IDisposable
		{
			private int <>1__state;

			private object <>2__current;

			public Packager __instance;

			object IEnumerator<object>.Current
			{
				[DebuggerHidden]
				get
				{
					return <>2__current;
				}
			}

			object IEnumerator.Current
			{
				[DebuggerHidden]
				get
				{
					return <>2__current;
				}
			}

			[DebuggerHidden]
			public <ConfigureDelayed>d__7(int <>1__state)
			{
				this.<>1__state = <>1__state;
			}

			[DebuggerHidden]
			void IDisposable.Dispose()
			{
				<>1__state = -2;
			}

			private bool MoveNext()
			{
				//IL_0026: Unknown result type (might be due to invalid IL or missing references)
				//IL_0030: Expected O, but got Unknown
				switch (<>1__state)
				{
				default:
					return false;
				case 0:
					<>1__state = -1;
					<>2__current = (object)new WaitForSeconds(1f);
					<>1__state = 1;
					return true;
				case 1:
				{
					<>1__state = -1;
					Packager _instance = __instance;
					if (((_instance != null) ? _instance.configuration : null) == null)
					{
						MelonLogger.Msg("Instance was null");
					}
					else if (__instance.configuration.Routes.MaxRoutes != MAX_ROUTES)
					{
						__instance.configuration.Routes.MaxRoutes = MAX_ROUTES;
						MelonLogger.Msg($"Max routes set to {MAX_ROUTES} for a packager.");
					}
					return false;
				}
				}
			}

			bool IEnumerator.MoveNext()
			{
				//ILSpy generated this explicit interface implementation from .override directive in MoveNext
				return this.MoveNext();
			}

			[DebuggerHidden]
			void IEnumerator.Reset()
			{
				throw new NotSupportedException();
			}
		}

		private bool loaded = false;

		private static int MAX_ROUTES = 15;

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

		public override void OnSceneWasInitialized(int buildIndex, string sceneName)
		{
			if (!(loaded | (sceneName != "Main")))
			{
				((MelonBase)this).LoggerInstance.Msg($"Setup running... {MAX_ROUTES} routes available.");
				InitializeRouteOverride();
				loaded = true;
			}
		}

		public void InitializeRouteOverride()
		{
			RouteListFieldUI componentInChildren = ((Component)((IEnumerable<RouteListFieldUI>)Resources.FindObjectsOfTypeAll<RouteListFieldUI>()).First((RouteListFieldUI o) => !((Behaviour)o).isActiveAndEnabled)).GetComponentInChildren<RouteListFieldUI>();
			Transform obj = ((Component)componentInChildren).gameObject.transform.FindChild("Contents");
			if (((obj != null) ? new int?(obj.childCount) : null) < MAX_ROUTES + 1)
			{
				MelonLogger.Msg("Generating more components...");
				for (int i = 5; i < MAX_ROUTES; i++)
				{
					Transform obj2 = ((Component)componentInChildren).gameObject.transform.FindChild("Contents");
					object obj3;
					if (obj2 == null)
					{
						obj3 = null;
					}
					else
					{
						Transform obj4 = obj2.FindChild($"Entry ({i})");
						obj3 = ((obj4 != null) ? ((Component)obj4).gameObject : null);
					}
					if (!Object.op_Implicit((Object)obj3))
					{
						Transform obj5 = ((Component)componentInChildren).gameObject.transform.FindChild("Contents");
						object obj6;
						if (obj5 == null)
						{
							obj6 = null;
						}
						else
						{
							Transform obj7 = obj5.FindChild("Entry");
							obj6 = ((obj7 != null) ? ((Component)obj7).gameObject : null);
						}
						GameObject val = (GameObject)obj6;
						GameObject val2 = GameObjectExt.DuplicateGameObject(val, val.transform.parent, false);
						((Object)val2).name = $"Entry ({i})";
					}
				}
				Transform obj8 = ((Component)componentInChildren).gameObject.transform.FindChild("Contents");
				if (obj8 != null)
				{
					((Component)obj8.FindChild("AddNew")).transform.SetAsLastSibling();
				}
			}
			componentInChildren = ((Component)((IEnumerable<RouteListFieldUI>)Resources.FindObjectsOfTypeAll<RouteListFieldUI>()).First((RouteListFieldUI o) => !((Behaviour)o).isActiveAndEnabled)).GetComponentInChildren<RouteListFieldUI>();
			if ((Object)(object)componentInChildren != (Object)null)
			{
				Il2CppReferenceArray<RouteEntryUI> routeEntries = componentInChildren.RouteEntries;
				if (routeEntries != null)
				{
					RouteEntryUI[] array = (RouteEntryUI[])(object)new RouteEntryUI[MAX_ROUTES];
					for (int j = 0; j < MAX_ROUTES; j++)
					{
						if (j < ((Il2CppArrayBase<RouteEntryUI>)(object)routeEntries).Length)
						{
							array[j] = ((Il2CppArrayBase<RouteEntryUI>)(object)routeEntries)[j];
						}
						bool flag = true;
						Transform obj9 = ((Component)componentInChildren).gameObject.transform.FindChild("Contents");
						object obj10;
						if (obj9 == null)
						{
							obj10 = null;
						}
						else
						{
							Transform obj11 = obj9.FindChild((j != 0) ? $"Entry ({j})" : "Entry");
							obj10 = ((obj11 != null) ? ((Component)obj11).gameObject.GetComponentInChildren<RouteEntryUI>() : null);
						}
						RouteEntryUI val3 = (RouteEntryUI)obj10;
						if (Object.op_Implicit((Object)(object)val3))
						{
							array[j] = val3;
						}
					}
					componentInChildren.RouteEntries = Il2CppReferenceArray<RouteEntryUI>.op_Implicit(array);
				}
			}
			MakeScrollable(componentInChildren);
		}

		[IteratorStateMachine(typeof(<ConfigureDelayed>d__7))]
		public static IEnumerator ConfigureDelayed(Packager __instance)
		{
			//yield-return decompiler failed: Unexpected instruction in Iterator.Dispose()
			return new <ConfigureDelayed>d__7(0)
			{
				__instance = __instance
			};
		}

		private void MakeScrollable(RouteListFieldUI parent)
		{
			//IL_0065: Unknown result type (might be due to invalid IL or missing references)
			//IL_007b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0091: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bd: Unknown result type (might be due to invalid IL or missing references)
			//IL_011a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0131: Unknown result type (might be due to invalid IL or missing references)
			if (!Object.op_Implicit((Object)(object)((Component)parent).transform.FindChild("ScrollArea")))
			{
				parent.FieldText = "Routes (Drag to Scroll)";
				GameObject val = ComponentExt.AddChildGameObject((Component)(object)parent, "ScrollArea");
				val.AddComponent<RectTransform>();
				val.AddComponent<RectMask2D>();
				RectTransform component = ((Component)val.transform).GetComponent<RectTransform>();
				ScrollRect val2 = val.AddComponent<ScrollRect>();
				component.anchoredPosition = new Vector2(0f, -62.52f);
				component.sizeDelta = new Vector2(0f, 170f);
				component.pivot = new Vector2(0f, 1f);
				component.anchorMax = new Vector2(1f, 1f);
				component.anchorMin = new Vector2(0f, 1f);
				GameObject gameObject = ((Component)((Component)parent).transform.FindChild("Contents")).gameObject;
				ContentSizeFitter val3 = gameObject.AddComponent<ContentSizeFitter>();
				val3.verticalFit = (FitMode)1;
				gameObject.transform.SetParent(val.transform);
				RectTransform component2 = ((Component)gameObject.transform).GetComponent<RectTransform>();
				component2.anchoredPosition = new Vector2(0f, 0f);
				component2.pivot = new Vector2(0f, 1f);
				val2.content = component2;
				val2.horizontal = false;
				val2.scrollSensitivity = 5f;
				val2.viewport = component;
			}
		}
	}
}