Decompiled source of FastPhone v1.0.1

plugins/FastPhone/FastPhone.dll

Decompiled 4 months ago
using System;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using BepInEx;
using DG.Tweening;
using HarmonyLib;
using Reptile;
using Reptile.Phone;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: AssemblyTitle("FastPhone")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("FastPhone")]
[assembly: AssemblyCopyright("Copyright ©  2024")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("5ae173c5-dc96-460f-b735-4f892046db17")]
[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 FastPhone;

internal class PhonePatches : HarmonyPatch
{
	[HarmonyPatch(typeof(Phone), "InitTurnOnAnimation")]
	public static class Phone_InitTurnOnAnimation_Patch
	{
		public static bool Prefix(Phone __instance, ref Sequence ___m_PhoneAnimation, RectTransform ___m_PhoneOpenTransform, PhoneTransformState ___m_OpenState, RectTransform ___m_Screen, float ___phoneScale, App ___m_CurrentApp)
		{
			//IL_0062: Unknown result type (might be due to invalid IL or missing references)
			//IL_006c: Expected O, but got Unknown
			___m_PhoneAnimation = DOTween.Sequence();
			TweenSettingsExtensions.SetUpdate<Sequence>(___m_PhoneAnimation, (UpdateType)3);
			TweenSettingsExtensions.SetAutoKill<Sequence>(___m_PhoneAnimation, false);
			TweenExtensions.Pause<Sequence>(___m_PhoneAnimation);
			TweenSettingsExtensions.InsertCallback(___m_PhoneAnimation, 0f, (TweenCallback)delegate
			{
				//IL_000c: Unknown result type (might be due to invalid IL or missing references)
				//IL_0011: Unknown result type (might be due to invalid IL or missing references)
				//IL_0076: Unknown result type (might be due to invalid IL or missing references)
				___m_PhoneOpenTransform.anchoredPosition = Vector2.op_Implicit(___m_OpenState.Position);
				Type nestedType = ((object)__instance).GetType().GetNestedType("PhoneState", BindingFlags.Instance | BindingFlags.NonPublic);
				ReflectionCalls.SetFieldValue(__instance, "state", Enum.Parse(nestedType, "ON"));
				((Component)___m_Screen).gameObject.SetActive(true);
				((Transform)___m_Screen).localScale = new Vector3(___phoneScale, ___phoneScale, 1f);
				if ((Object)(object)___m_CurrentApp != (Object)null)
				{
					___m_CurrentApp.OnAppEnable();
				}
			});
			return false;
		}
	}

	[HarmonyPatch(typeof(Phone), "InitTurnOffAnimation")]
	public static class Phone_InitTurnOffAnimation_Patch
	{
		public static bool Prefix(Phone __instance, ref Sequence ___m_PhoneTurnOffAnimation, RectTransform ___m_PhoneOpenTransform, PhoneTransformState ___m_ClosedState)
		{
			//IL_0045: Unknown result type (might be due to invalid IL or missing references)
			//IL_004f: Expected O, but got Unknown
			___m_PhoneTurnOffAnimation = DOTween.Sequence();
			TweenSettingsExtensions.SetUpdate<Sequence>(___m_PhoneTurnOffAnimation, (UpdateType)3);
			TweenSettingsExtensions.SetAutoKill<Sequence>(___m_PhoneTurnOffAnimation, false);
			TweenExtensions.Pause<Sequence>(___m_PhoneTurnOffAnimation);
			TweenSettingsExtensions.AppendCallback(___m_PhoneTurnOffAnimation, (TweenCallback)delegate
			{
				//IL_000c: Unknown result type (might be due to invalid IL or missing references)
				//IL_0011: Unknown result type (might be due to invalid IL or missing references)
				___m_PhoneOpenTransform.anchoredPosition = Vector2.op_Implicit(___m_ClosedState.Position);
				ReflectionCalls.InvokeMethod(__instance, "DisableOS");
				ReflectionCalls.InvokeMethod(__instance, "SetPhoneUIEnabled", false, false);
			});
			return false;
		}
	}

	[HarmonyPatch(typeof(PhoneScroll), "SelectButton")]
	public static class PhoneScroll_SelectButton_Patch
	{
		public static void Prefix(ref bool skipAnimation)
		{
			skipAnimation = true;
		}
	}

	[HarmonyPatch(typeof(AppHomeScreen), "OpenApp")]
	public static class AppHomeScreen_OpenApp_Patch
	{
		public static bool Prefix(AppHomeScreen __instance, HomescreenButton appToOpen)
		{
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_000c: Invalid comparison between Unknown and I4
			if ((int)appToOpen.AssignedApp.AppType != 4)
			{
				WorldHandler instance = WorldHandler.instance;
				Phone fieldValue = ReflectionCalls.GetFieldValue<Phone>((instance != null) ? instance.GetCurrentPlayer() : null, "phone");
				if (fieldValue.AppInstances.TryGetValue(appToOpen.AssignedApp.AppName, out var value))
				{
					((object)value).GetType().GetProperty("HandleInput").SetValue(value, false, null);
					if (fieldValue != null)
					{
						fieldValue.OpenApp(((object)value).GetType());
					}
					waitForRelease = true;
				}
				return false;
			}
			return true;
		}
	}

	[HarmonyPatch(typeof(Phone), "GetInput")]
	public static class Phone_GetInput_Patch
	{
		public static bool Prefix(App app, GameInput ___gameInput)
		{
			if (waitForRelease && (___gameInput.GetButtonNew(21, 0) || ___gameInput.GetButtonHeld(29, 0)) && !___gameInput.GetButtonUp(29, 0))
			{
				return false;
			}
			if (waitForRelease)
			{
				((object)app).GetType().GetProperty("HandleInput").SetValue(app, true, null);
				waitForRelease = false;
				return false;
			}
			return true;
		}
	}

	[HarmonyPatch(typeof(Phone), "TurnOn")]
	public static class Phone_TurnOn_Patch
	{
		public static bool Prefix(GameInput ___gameInput)
		{
			if (___gameInput.GetButtonNew(57, 0))
			{
				return false;
			}
			Mapcontroller instance = Mapcontroller.Instance;
			if ((Object)(object)instance != (Object)null)
			{
				instance.EnableMapCamera();
				instance.RestoreDefaultMapControllerState();
			}
			return true;
		}
	}

	[HarmonyPatch(typeof(AppHomeScreen), "AwakeAnimation")]
	public static class AppHomeScreen_AwakeAnimation_Patch
	{
		public static bool Prefix(AppHomeScreen __instance, HomescreenScrollView ___m_ScrollView, RectTransform ___m_TopView)
		{
			//IL_0024: Unknown result type (might be due to invalid IL or missing references)
			//IL_0033: Unknown result type (might be due to invalid IL or missing references)
			//IL_0076: 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_007c: Unknown result type (might be due to invalid IL or missing references)
			//IL_009a: Unknown result type (might be due to invalid IL or missing references)
			//IL_009f: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ad: 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_00cc: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e1: Unknown result type (might be due to invalid IL or missing references)
			((Component)___m_ScrollView.OtherElementsParent).gameObject.SetActive(true);
			PhoneScrollButton selectedButtton = ((PhoneScroll)___m_ScrollView).SelectedButtton;
			((selectedButtton is HomescreenButton) ? selectedButtton : null).IsSelected = true;
			___m_TopView.sizeDelta = new Vector2(___m_TopView.sizeDelta.x, 775f);
			WorldHandler instance = WorldHandler.instance;
			if ((Object)(object)ReflectionCalls.GetFieldValue<Phone>((instance != null) ? instance.GetCurrentPlayer() : null, "phone") != (Object)null)
			{
				for (int i = 0; i < ((PhoneScroll)___m_ScrollView).GetScrollRange(); i++)
				{
					RectTransform obj = ComponentExtensions.RectTransform((Component)(object)((PhoneScroll)___m_ScrollView).GetButtonByRelativeIndex(i));
					Vector2 anchoredPosition = ___m_ScrollView.ButtonPos((float)i);
					obj.anchoredPosition = anchoredPosition;
				}
				Vector2 anchoredPosition2 = ComponentExtensions.RectTransform((Component)(object)___m_ScrollView.Selector).anchoredPosition;
				anchoredPosition2.y = ComponentExtensions.RectTransform((Component)(object)((PhoneScroll)___m_ScrollView).SelectedButtton).anchoredPosition.y;
				((Transform)ComponentExtensions.RectTransform((Component)(object)___m_ScrollView.Selector)).localScale = Vector2.op_Implicit(Vector2.one);
				ComponentExtensions.RectTransform((Component)(object)___m_ScrollView.Selector).anchoredPosition = anchoredPosition2;
			}
			App val = default(App);
			if (((Component)__instance).gameObject.TryGetComponent<App>(ref val))
			{
				((object)val).GetType().GetProperty("HandleInput").SetValue(val, true, null);
			}
			return false;
		}
	}

	private static bool waitForRelease;
}
[BepInPlugin("ninjacookie.brc.fastphone", "Fast Phone", "1.0.0")]
public class Plugin : BaseUnityPlugin
{
	public const string pluginGuid = "ninjacookie.brc.fastphone";

	public const string pluginName = "Fast Phone";

	public const string pluginVersion = "1.0.0";

	private void Awake()
	{
		//IL_0005: Unknown result type (might be due to invalid IL or missing references)
		new Harmony("ninjacookie.brc.fastphone").PatchAll();
	}
}
internal static class ReflectionCalls
{
	public static BindingFlags flags = BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic;

	public static void InvokeMethod(object reference, string method, params object[] parms)
	{
		reference.GetType().GetMethod(method, flags).Invoke(reference, parms);
	}

	public static void SetFieldValue<T>(object reference, string field, T value)
	{
		reference.GetType().GetField(field, flags).SetValue(reference, value);
	}

	public static T GetFieldValue<T>(object reference, string field)
	{
		return (T)reference.GetType().GetField(field, flags).GetValue(reference);
	}
}