Decompiled source of CrossProperty Transportation Mono v1.0.1

CrossPropertyTransport.dll

Decompiled 5 months ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;
using System.Resources;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using CrossPropertyTransportMono;
using HarmonyLib;
using MelonLoader;
using Microsoft.CodeAnalysis;
using ScheduleOne.DevUtilities;
using ScheduleOne.Employees;
using ScheduleOne.EntityFramework;
using ScheduleOne.Management;
using ScheduleOne.NPCs;
using ScheduleOne.NPCs.Behaviour;
using ScheduleOne.PlayerScripts;
using ScheduleOne.Property;
using ScheduleOne.UI;
using ScheduleOne.UI.Management;
using TMPro;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: MelonInfo(typeof(CrossPropertyTransport), "CrossPropertyTransport", "1.0.1", "NanobotZ", null)]
[assembly: MelonGame("TVGS", "Schedule I")]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("CrossPropertyTransport")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("CrossPropertyTransport")]
[assembly: AssemblyTitle("CrossPropertyTransport")]
[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 CrossPropertyTransportMono
{
	public class CrossPropertyTransport : MelonMod
	{
		internal static List<Property> teleportProperties;

		internal static Vector3 playerTeleportPosition;

		internal static Vector3 playerTeleportForward;

		internal static int? playerTeleportIndex;

		internal static bool PlayerWasTeleporting => playerTeleportIndex.HasValue;

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

		public override void OnUpdate()
		{
			HandleTeleportLogic();
		}

		private static void HandleTeleportLogic()
		{
			//IL_0125: Unknown result type (might be due to invalid IL or missing references)
			//IL_012a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0134: Unknown result type (might be due to invalid IL or missing references)
			//IL_0139: 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_0158: Unknown result type (might be due to invalid IL or missing references)
			if (teleportProperties == null)
			{
				return;
			}
			int num = 0;
			if (Input.GetKeyDown((KeyCode)273))
			{
				num = 1;
			}
			if (Input.GetKeyDown((KeyCode)274))
			{
				num = -1;
			}
			if (num == 0)
			{
				return;
			}
			if (!playerTeleportIndex.HasValue)
			{
				if (num > 0)
				{
					playerTeleportIndex = 1;
				}
				else
				{
					playerTeleportIndex = teleportProperties.Count - 1;
				}
			}
			else
			{
				playerTeleportIndex += num;
				if (playerTeleportIndex >= teleportProperties.Count)
				{
					playerTeleportIndex = 0;
				}
				else if (playerTeleportIndex < 0)
				{
					playerTeleportIndex = teleportProperties.Count - 1;
				}
			}
			Property property = teleportProperties[playerTeleportIndex.Value];
			Transform propertyCrossTransform = Helpers.GetPropertyCrossTransform(null, property);
			PlayerSingleton<PlayerMovement>.Instance.Teleport(propertyCrossTransform.position + Vector3.up * 1f);
			((Component)Player.Local).transform.forward = propertyCrossTransform.forward * -1f;
		}

		internal static void OpenManagementUI()
		{
			//IL_005e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0063: Unknown result type (might be due to invalid IL or missing references)
			//IL_0072: 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)
			List<Property> list = new List<Property>();
			foreach (Property ownedProperty in Property.OwnedProperties)
			{
				if (!((Object)(object)ownedProperty == (Object)null))
				{
					list.Add(ownedProperty);
				}
			}
			if (list.Count > 1)
			{
				teleportProperties = list;
				playerTeleportPosition = ((Component)Player.Local).transform.position;
				playerTeleportForward = ((Component)Player.Local).transform.forward;
			}
		}

		internal static void CloseManagementUI()
		{
			//IL_000c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0020: Unknown result type (might be due to invalid IL or missing references)
			if (PlayerWasTeleporting)
			{
				PlayerSingleton<PlayerMovement>.Instance.Teleport(playerTeleportPosition);
				((Component)Player.Local).transform.forward = playerTeleportForward;
				playerTeleportIndex = null;
			}
			teleportProperties = null;
		}
	}
	internal static class Helpers
	{
		internal static FieldInfo field_HUD_topScreenText;

		internal static FieldInfo field_HUD_topScreenText_Background;

		internal static FieldInfo field_TransitEntitySelector_selectionTitle;

		internal static MethodInfo method_TransitEntitySelector_UpdateInstructions;

		internal static FieldInfo field_ObjectSelector_selectionTitle;

		internal static MethodInfo method_ObjectSelector_UpdateInstructions;

		internal static FieldInfo field_NPCMovement_npc;

		internal static FieldInfo field_MoveItemBehaviour_assignedRoute;

		private static readonly Dictionary<string, Transform> propertyCrossTransformDict;

		internal static TextMeshProUGUI Get_topScreenText(this HUD hud)
		{
			//IL_000b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0011: Expected O, but got Unknown
			return (TextMeshProUGUI)field_HUD_topScreenText.GetValue(hud);
		}

		internal static RectTransform Get_topScreenText_Background(this HUD hud)
		{
			//IL_000b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0011: Expected O, but got Unknown
			return (RectTransform)field_HUD_topScreenText_Background.GetValue(hud);
		}

		internal static string Get_selectionTitle(this TransitEntitySelector tes)
		{
			return (string)field_TransitEntitySelector_selectionTitle.GetValue(tes);
		}

		internal static void Set_selectionTitle(this TransitEntitySelector tes, string value)
		{
			field_TransitEntitySelector_selectionTitle.SetValue(tes, value);
		}

		internal static void Invoke_UpdateInstructions(this TransitEntitySelector tes)
		{
			method_TransitEntitySelector_UpdateInstructions.Invoke(tes, null);
		}

		internal static string Get_selectionTitle(this ObjectSelector os)
		{
			return (string)field_ObjectSelector_selectionTitle.GetValue(os);
		}

		internal static void Set_selectionTitle(this ObjectSelector os, string value)
		{
			field_ObjectSelector_selectionTitle.SetValue(os, value);
		}

		internal static void Invoke_UpdateInstructions(this ObjectSelector os)
		{
			method_ObjectSelector_UpdateInstructions.Invoke(os, null);
		}

		internal static NPC Get_npc(this NPCMovement npcMovement)
		{
			//IL_000b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0011: Expected O, but got Unknown
			return (NPC)field_NPCMovement_npc.GetValue(npcMovement);
		}

		internal static TransitRoute Get_assignedRoute(this MoveItemBehaviour mib)
		{
			//IL_000b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0011: Expected O, but got Unknown
			return (TransitRoute)field_MoveItemBehaviour_assignedRoute.GetValue(mib);
		}

		static Helpers()
		{
			//IL_00f6: Unknown result type (might be due to invalid IL or missing references)
			//IL_010a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0128: Unknown result type (might be due to invalid IL or missing references)
			//IL_013c: Unknown result type (might be due to invalid IL or missing references)
			//IL_015a: Unknown result type (might be due to invalid IL or missing references)
			//IL_016e: Unknown result type (might be due to invalid IL or missing references)
			//IL_018c: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a0: 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)
			//IL_01d2: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f0: Unknown result type (might be due to invalid IL or missing references)
			//IL_0204: Unknown result type (might be due to invalid IL or missing references)
			//IL_0222: Unknown result type (might be due to invalid IL or missing references)
			//IL_0236: Unknown result type (might be due to invalid IL or missing references)
			field_HUD_topScreenText = typeof(HUD).GetField("topScreenText", BindingFlags.Instance | BindingFlags.NonPublic);
			field_HUD_topScreenText_Background = typeof(HUD).GetField("topScreenText_Background", BindingFlags.Instance | BindingFlags.NonPublic);
			field_TransitEntitySelector_selectionTitle = typeof(TransitEntitySelector).GetField("selectionTitle", BindingFlags.Instance | BindingFlags.NonPublic);
			method_TransitEntitySelector_UpdateInstructions = typeof(TransitEntitySelector).GetMethod("UpdateInstructions", BindingFlags.Instance | BindingFlags.NonPublic);
			field_ObjectSelector_selectionTitle = typeof(ObjectSelector).GetField("selectionTitle", BindingFlags.Instance | BindingFlags.NonPublic);
			method_ObjectSelector_UpdateInstructions = typeof(ObjectSelector).GetMethod("UpdateInstructions", BindingFlags.Instance | BindingFlags.NonPublic);
			field_NPCMovement_npc = typeof(NPCMovement).GetField("npc", BindingFlags.Instance | BindingFlags.NonPublic);
			field_MoveItemBehaviour_assignedRoute = typeof(MoveItemBehaviour).GetField("assignedRoute", BindingFlags.Instance | BindingFlags.NonPublic);
			propertyCrossTransformDict = new Dictionary<string, Transform>();
			CreateCrossPlatformGameObject("RV", new Vector3(11.543796f, 0.970375f, -75.74756f), new Vector3(-0.020820871f, -0.047304332f, 0.9986635f));
			CreateCrossPlatformGameObject("MotelRoom", new Vector3(-66.22975f, 1.6867679f, 82.86325f), new Vector3(0.99759513f, -0.0008907849f, 0.06930524f));
			CreateCrossPlatformGameObject("Sweatshop", new Vector3(-60.897114f, -3.034998f, 146.39929f), new Vector3(0.7232971f, -0.008608431f, 0.6904833f));
			CreateCrossPlatformGameObject("Bungalow", new Vector3(-160.01097f, -3.0348783f, 114.80028f), new Vector3(0.9974299f, 0.0034683319f, 0.07156569f));
			CreateCrossPlatformGameObject("Barn", new Vector3(177.10942f, 0.96622044f, -8.631995f), new Vector3(-0.9965599f, 0.02527189f, -0.078929305f));
			CreateCrossPlatformGameObject("DocksWarehouse", new Vector3(-73.51609f, -1.455f, -55.68945f), new Vector3(0.99936974f, -0.015709592f, 0.03183621f));
			CreateCrossPlatformGameObject("Manor", new Vector3(161.44713f, 10.99f, -74.11461f), new Vector3(0.32149658f, -0.061523672f, -0.94491005f));
		}

		private static void CreateCrossPlatformGameObject(string name, Vector3 position, Vector3 forward)
		{
			//IL_000b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0011: Expected O, but got Unknown
			//IL_001d: 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)
			GameObject val = new GameObject(name + "_CrossPlatform");
			Object.DontDestroyOnLoad((Object)(object)val);
			val.transform.position = position;
			val.transform.forward = forward;
			propertyCrossTransformDict.Add(name, val.transform);
		}

		internal static Transform GetCrossTransform(Employee employee, BuildableItem buildableItem)
		{
			if ((Object)(object)buildableItem == (Object)null || (Object)(object)buildableItem.ParentProperty == (Object)null)
			{
				return null;
			}
			if ((Object)(object)employee == (Object)null)
			{
				return null;
			}
			if ((Object)(object)employee.AssignedProperty == (Object)(object)buildableItem.ParentProperty)
			{
				return null;
			}
			return GetPropertyCrossTransform(employee, employee.AssignedProperty);
		}

		internal static Transform GetPropertyCrossTransform(Employee employee, Property property)
		{
			if (propertyCrossTransformDict.TryGetValue(((Object)((Component)property).gameObject).name, out var value))
			{
				return value;
			}
			Melon<CrossPropertyTransport>.Logger.Msg("Property '" + ((Object)((Component)property).gameObject).name + "' doesn't have a predetermined CrossTransform, using NPC's idle point");
			if ((Object)(object)employee != (Object)null)
			{
				Transform val = employee.WaitOutside?.IdlePoint ?? null;
				if ((Object)(object)val != (Object)null)
				{
					return val;
				}
				Melon<CrossPropertyTransport>.Logger.Msg("NPC doesn't have an idle point, using NPC's current positon");
				return ((Component)employee).transform;
			}
			return property.NPCSpawnPoint;
		}
	}
	[HarmonyPatch(typeof(ObjectSelector), "IsObjectTypeValid")]
	public static class Patch_ObjectSelector_IsObjectTypeValid
	{
		internal static void Postfix(ref string reason, ref bool __result)
		{
			if (reason == "Wrong property")
			{
				reason = string.Empty;
				__result = true;
			}
		}
	}
	[HarmonyPatch(typeof(MoveItemBehaviour), "GetSourceAccessPoint")]
	public static class Patch_MoveItemBehaviour_GetSourceAccessPoint
	{
		internal static bool Prefix(MoveItemBehaviour __instance, ref Transform __result, TransitRoute route)
		{
			if (route.Source == null)
			{
				return true;
			}
			ITransitEntity source = route.Source;
			BuildableItem buildableItem = (BuildableItem)(object)((source is BuildableItem) ? source : null);
			NPC npc = ((Behaviour)__instance).Npc;
			Transform crossTransform = Helpers.GetCrossTransform((Employee)(object)((npc is Employee) ? npc : null), buildableItem);
			if ((Object)(object)crossTransform != (Object)null)
			{
				__result = crossTransform;
				return false;
			}
			return true;
		}
	}
	[HarmonyPatch(typeof(MoveItemBehaviour), "GetDestinationAccessPoint")]
	public static class Patch_MoveItemBehaviour_GetDestinationAccessPoint
	{
		internal static bool Prefix(MoveItemBehaviour __instance, ref Transform __result, TransitRoute route)
		{
			if (route.Destination == null)
			{
				return true;
			}
			ITransitEntity destination = route.Destination;
			BuildableItem buildableItem = (BuildableItem)(object)((destination is BuildableItem) ? destination : null);
			NPC npc = ((Behaviour)__instance).Npc;
			Transform crossTransform = Helpers.GetCrossTransform((Employee)(object)((npc is Employee) ? npc : null), buildableItem);
			if ((Object)(object)crossTransform != (Object)null)
			{
				__result = crossTransform;
				return false;
			}
			return true;
		}
	}
	[HarmonyPatch(typeof(MoveItemBehaviour), "IsAtSource")]
	public static class Patch_MoveItemBehaviour_IsAtSource
	{
		internal static bool Prefix(MoveItemBehaviour __instance, ref bool __result)
		{
			//IL_0044: Unknown result type (might be due to invalid IL or missing references)
			//IL_0054: Unknown result type (might be due to invalid IL or missing references)
			TransitRoute obj = __instance.Get_assignedRoute();
			if (((obj != null) ? obj.Destination : null) == null)
			{
				return true;
			}
			ITransitEntity source = __instance.Get_assignedRoute().Source;
			BuildableItem buildableItem = (BuildableItem)(object)((source is BuildableItem) ? source : null);
			NPC npc = ((Behaviour)__instance).Npc;
			Transform crossTransform = Helpers.GetCrossTransform((Employee)(object)((npc is Employee) ? npc : null), buildableItem);
			if ((Object)(object)crossTransform != (Object)null)
			{
				__result = Vector3.Distance(crossTransform.position, ((Component)((Behaviour)__instance).Npc).transform.position) <= 2f;
				return false;
			}
			return true;
		}
	}
	[HarmonyPatch(typeof(MoveItemBehaviour), "IsAtDestination")]
	public static class Patch_MoveItemBehaviour_IsAtDestination
	{
		internal static bool Prefix(MoveItemBehaviour __instance, ref bool __result)
		{
			//IL_0044: Unknown result type (might be due to invalid IL or missing references)
			//IL_0054: Unknown result type (might be due to invalid IL or missing references)
			TransitRoute obj = __instance.Get_assignedRoute();
			if (((obj != null) ? obj.Destination : null) == null)
			{
				return true;
			}
			ITransitEntity destination = __instance.Get_assignedRoute().Destination;
			BuildableItem buildableItem = (BuildableItem)(object)((destination is BuildableItem) ? destination : null);
			NPC npc = ((Behaviour)__instance).Npc;
			Transform crossTransform = Helpers.GetCrossTransform((Employee)(object)((npc is Employee) ? npc : null), buildableItem);
			if ((Object)(object)crossTransform != (Object)null)
			{
				__result = Vector3.Distance(crossTransform.position, ((Component)((Behaviour)__instance).Npc).transform.position) <= 2f;
				return false;
			}
			return true;
		}
	}
	[HarmonyPatch(typeof(NPCMovement), "CanGetTo", new Type[]
	{
		typeof(ITransitEntity),
		typeof(float)
	})]
	public static class Patch_NPCMovement_CanGetTo
	{
		public static bool Prefix(NPCMovement __instance, ref bool __result, ITransitEntity entity)
		{
			NPC obj = __instance.Get_npc();
			Packager val = (Packager)(object)((obj is Packager) ? obj : null);
			if ((Object)(object)val == (Object)null)
			{
				return true;
			}
			BuildableItem val2 = (BuildableItem)(object)((entity is BuildableItem) ? entity : null);
			if ((Object)(object)val2 == (Object)null)
			{
				return true;
			}
			if ((Object)(object)((Employee)val).AssignedProperty == (Object)(object)val2.ParentProperty)
			{
				return true;
			}
			__result = true;
			return false;
		}
	}
	[HarmonyPatch(typeof(ObjectSelector), "Open")]
	public static class Patch_ObjectSelector_Open
	{
		public static void Postfix(ObjectSelector __instance)
		{
			if (__instance.Get_selectionTitle() != null)
			{
				string text = __instance.Get_selectionTitle().ToLower();
				if (text.Contains("source") || text.Contains("destination"))
				{
					__instance.Set_selectionTitle(__instance.Get_selectionTitle() + "<br><br>Use UP/DOWN arrow key<br>to teleport to other properties");
					__instance.Invoke_UpdateInstructions();
					CrossPropertyTransport.OpenManagementUI();
				}
			}
		}
	}
	[HarmonyPatch(typeof(ObjectSelector), "Close")]
	public static class Patch_ObjectSelector_Close
	{
		public static void Prefix()
		{
			CrossPropertyTransport.CloseManagementUI();
		}
	}
	[HarmonyPatch(typeof(TransitEntitySelector), "Open")]
	public static class Patch_TransitEntitySelector_Open
	{
		public static void Postfix(TransitEntitySelector __instance)
		{
			__instance.Set_selectionTitle(__instance.Get_selectionTitle() + "<br><br>Use UP/DOWN arrow key<br>to teleport to other properties");
			__instance.Invoke_UpdateInstructions();
			CrossPropertyTransport.OpenManagementUI();
		}
	}
	[HarmonyPatch(typeof(TransitEntitySelector), "Close")]
	public static class Patch_TransitEntitySelector_Close
	{
		public static void Prefix()
		{
			CrossPropertyTransport.CloseManagementUI();
		}
	}
	[HarmonyPatch(typeof(HUD), "ShowTopScreenText")]
	public static class Patch_HUD_ShowTopScreenText
	{
		internal static bool Prefix(HUD __instance, string t)
		{
			//IL_0034: Unknown result type (might be due to invalid IL or missing references)
			((TMP_Text)__instance.Get_topScreenText()).text = t;
			__instance.Get_topScreenText_Background().sizeDelta = new Vector2(((TMP_Text)__instance.Get_topScreenText()).preferredWidth + 30f, ((TMP_Text)__instance.Get_topScreenText()).preferredHeight + 30f);
			((Component)__instance.Get_topScreenText_Background()).gameObject.SetActive(true);
			return false;
		}
	}
}