Decompiled source of OutOfThePast v0.3.0

OutOfThePast.dll

Decompiled 5 days ago
using System;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Core.Logging.Interpolation;
using BepInEx.Logging;
using HarmonyLib;
using Il2CppSystem.Collections.Generic;
using Microsoft.CodeAnalysis;
using OutOfThePast.Patches.BugFixPatches;
using OutOfThePast.Patches.DialoguePatches;
using OutOfThePast.Patches.SideJobPatches;
using OutOfThePast.Patches.UIPatches;
using SOD.Common.BepInEx;
using SOD.Common.BepInEx.Configuration;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: TargetFramework(".NETCoreApp,Version=v6.0", FrameworkDisplayName = ".NET 6.0")]
[assembly: AssemblyCompany("OutOfThePast")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0+feec5216471b677e001dbddb949c4404fc426c0b")]
[assembly: AssemblyProduct("My first plugin")]
[assembly: AssemblyTitle("OutOfThePast")]
[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 OutOfThePast
{
	public interface IPluginBindings : IPatchToggleBindings, IAdjustPayphoneCallDelayBindings
	{
	}
	public interface IPatchToggleBindings
	{
		[Binding(true, "Enable Improved Payphone Call Delay", "PatchEnable.PayphoneCallDelay")]
		bool PatchEnablePayphoneCallDelay { get; set; }

		[Binding(true, "Enable Talking While Sitting", "PatchEnable.SitAndTalk")]
		bool PatchEnableSitAndTalk { get; set; }

		[Binding(true, "Enable Pass Time BugFixes", "PatchEnable.PassTimeBugFixes")]
		bool PatchEnablePassTimeBugFixes { get; set; }

		[Binding(true, "Suppress [Target] brackets on all action prompts", "PatchEnable.SuppressAllTargetBrackets")]
		bool SuppressAllTargetBrackets { get; set; }
	}
	public interface IAdjustPayphoneCallDelayBindings
	{
		[Binding(30, "Minimum delay (minutes) before Side Job phone rings", "PayphoneCallDelay.MinimumDelay")]
		int PayphoneCallDelayMinimumDelay { get; set; }

		[Binding(45, "Maximum delay (minutes) before Side Job phone rings", "PayphoneCallDelay.MaximumDelay")]
		int PayphoneCallDelayMaximumDelay { get; set; }
	}
	[BepInPlugin("Sclamy.OutOfThePast", "OutOfThePast", "0.3.0")]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	public class Plugin : PluginController<Plugin, IPluginBindings>
	{
		public const string PLUGIN_GUID = "Sclamy.OutOfThePast";

		public const string PLUGIN_NAME = "OutOfThePast";

		public const string PLUGIN_VERSION = "0.3.0";

		public override void Load()
		{
			//IL_007c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0082: Expected O, but got Unknown
			PatchIfEnabled(typeof(AdjustPayphoneCallDelay), base.Config.PatchEnablePayphoneCallDelay);
			PatchIfEnabled(typeof(SitAndTalk), base.Config.PatchEnableSitAndTalk);
			PatchIfEnabled(typeof(PassTimeImprovements), base.Config.PatchEnablePassTimeBugFixes);
			PatchIfEnabled(typeof(SuppressAllTargetBrackets), base.Config.SuppressAllTargetBrackets);
			ManualLogSource log = PluginController<Plugin, IPluginBindings>.Log;
			bool flag = default(bool);
			BepInExInfoLogInterpolatedStringHandler val = new BepInExInfoLogInterpolatedStringHandler(20, 2, ref flag);
			if (flag)
			{
				((BepInExLogInterpolatedStringHandler)val).AppendLiteral("Plugin ");
				((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>("Sclamy.OutOfThePast");
				((BepInExLogInterpolatedStringHandler)val).AppendLiteral(" v");
				((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>("0.3.0");
				((BepInExLogInterpolatedStringHandler)val).AppendLiteral(" is loaded!");
			}
			log.LogInfo(val);
		}

		private void PatchIfEnabled(Type patchType, bool enabled)
		{
			if (enabled)
			{
				base.Harmony.CreateClassProcessor(patchType).Patch();
				Type[] nestedTypes = patchType.GetNestedTypes(BindingFlags.Public | BindingFlags.NonPublic);
				foreach (Type type in nestedTypes)
				{
					base.Harmony.CreateClassProcessor(type).Patch();
				}
			}
		}
	}
	public static class MyPluginInfo
	{
		public const string PLUGIN_GUID = "OutOfThePast";

		public const string PLUGIN_NAME = "My first plugin";

		public const string PLUGIN_VERSION = "1.0.0";
	}
}
namespace OutOfThePast.Patches.UIPatches
{
	internal static class SuppressAllTargetBrackets
	{
		[HarmonyPatch(typeof(ControlDisplayController), "SetControlText")]
		internal static class SuppressAllBrackets
		{
			[HarmonyPrefix]
			private static void Prefix(ref bool useContext)
			{
				useContext = false;
			}
		}
	}
}
namespace OutOfThePast.Patches.SideJobPatches
{
	[HarmonyPatch(typeof(SideJob), "ObjectiveStateLoop")]
	internal static class AdjustPayphoneCallDelay
	{
		[HarmonyPrefix]
		private static void Prefix(SideJob __instance, ref float __state)
		{
			__state = __instance.gooseChaseCallTime;
		}

		[HarmonyPostfix]
		private static void Postfix(SideJob __instance, float __state)
		{
			if (__instance.gooseChaseCallTime != __state)
			{
				float num = ((PluginController<Plugin, IPluginBindings>)PluginController<Plugin, IPluginBindings>.Instance).Config.PayphoneCallDelayMinimumDelay;
				float num2 = ((PluginController<Plugin, IPluginBindings>)PluginController<Plugin, IPluginBindings>.Instance).Config.PayphoneCallDelayMaximumDelay;
				float num3 = Random.Range(num, num2);
				__instance.gooseChaseCallTime = SessionData.Instance.gameTime + num3 / 60f;
			}
		}
	}
}
namespace OutOfThePast.Patches.DialoguePatches
{
	internal static class SitAndTalk
	{
		[HarmonyPatch(typeof(Interactable), "UpdateCurrentActions")]
		internal static class PrioritizeTalkWhileSitting
		{
			[HarmonyPostfix]
			private static void Postfix(Interactable __instance)
			{
				//IL_00f7: Unknown result type (might be due to invalid IL or missing references)
				//IL_015b: Unknown result type (might be due to invalid IL or missing references)
				//IL_015d: Invalid comparison between Unknown and I4
				//IL_0170: Unknown result type (might be due to invalid IL or missing references)
				//IL_0197: Unknown result type (might be due to invalid IL or missing references)
				//IL_0149: 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_01fd: Unknown result type (might be due to invalid IL or missing references)
				//IL_0200: Invalid comparison between Unknown and I4
				//IL_0239: Unknown result type (might be due to invalid IL or missing references)
				//IL_023c: Unknown result type (might be due to invalid IL or missing references)
				//IL_0244: Unknown result type (might be due to invalid IL or missing references)
				//IL_024d: Unknown result type (might be due to invalid IL or missing references)
				//IL_0250: Invalid comparison between Unknown and I4
				//IL_020f: Unknown result type (might be due to invalid IL or missing references)
				//IL_025f: 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_01ea: Unknown result type (might be due to invalid IL or missing references)
				//IL_01ef: Unknown result type (might be due to invalid IL or missing references)
				if (__instance == null)
				{
					return;
				}
				InteractionController instance = InteractionController.Instance;
				Player instance2 = Player.Instance;
				if ((Object)(object)instance == (Object)null || (Object)(object)instance2 == (Object)null || instance.lockedInInteraction == null || instance.lockedInInteraction.usagePoint == null || __instance == instance.lockedInInteraction || (Object)(object)__instance.isActor == (Object)null || __instance.isActor.isDead || __instance.isActor.isAsleep || __instance.isActor.isStunned || (Object)(object)__instance.isActor.ai == (Object)null || __instance.isActor.ai.ko)
				{
					return;
				}
				InteractionKey val = (InteractionKey)0;
				Enumerator<InteractionKey, InteractableCurrentAction> enumerator = __instance.currentActions.GetEnumerator();
				while (enumerator.MoveNext())
				{
					KeyValuePair<InteractionKey, InteractableCurrentAction> current = enumerator.Current;
					InteractionAction currentAction = current.Value.currentAction;
					object obj;
					if (currentAction == null)
					{
						obj = null;
					}
					else
					{
						AIActionPreset action = currentAction.action;
						obj = ((action != null) ? ((SoCustomComparison)action).presetName : null);
					}
					if ((string?)obj == "TalkTo")
					{
						val = current.Key;
						break;
					}
				}
				if ((int)val == 0)
				{
					return;
				}
				InteractableCurrentAction val2 = __instance.currentActions[val];
				if (val2 == null)
				{
					return;
				}
				val2.enabled = true;
				val2.display = true;
				InteractionKey val3 = (InteractionKey)0;
				Enumerator<InteractionKey, InteractableCurrentAction> enumerator2 = __instance.currentActions.GetEnumerator();
				while (enumerator2.MoveNext())
				{
					KeyValuePair<InteractionKey, InteractableCurrentAction> current2 = enumerator2.Current;
					InteractionAction currentAction2 = current2.Value.currentAction;
					object obj2;
					if (currentAction2 == null)
					{
						obj2 = null;
					}
					else
					{
						AIActionPreset action2 = currentAction2.action;
						obj2 = ((action2 != null) ? ((SoCustomComparison)action2).presetName : null);
					}
					if ((string?)obj2 == "Inspect")
					{
						val3 = current2.Key;
						break;
					}
				}
				if ((int)val3 > 0)
				{
					InteractableCurrentAction val4 = __instance.currentActions[val3];
					if (val4 != null)
					{
						val4.enabled = true;
						val4.display = true;
					}
				}
				InteractionKey val5 = (InteractionKey)1;
				InteractionKey val6 = (InteractionKey)2;
				__instance.currentActions[val5] = val2;
				if ((int)val3 > 0)
				{
					__instance.currentActions[val6] = __instance.currentActions[val3];
				}
			}
		}

		[HarmonyPatch(typeof(NewAIController), "TalkTo", new Type[] { typeof(ConversationType) })]
		internal static class PreserveSittingDuringTalk
		{
			[HarmonyPrefix]
			private static void Prefix(NewAIController __instance, ConversationType convoType)
			{
				if (isRestoringSitting)
				{
					isRestoringSitting = false;
				}
				InteractionController instance = InteractionController.Instance;
				if (instance.lockedInInteraction != null && instance.lockedInInteraction.usagePoint != null)
				{
					PluginController<Plugin, IPluginBindings>.Log.LogInfo((object)"[SitAndTalk] Entering sit-and-talk mode");
					storedSittingInteractable = instance.lockedInInteraction;
					isSitAndTalkActive = true;
				}
			}

			[HarmonyPostfix]
			private static void Postfix(NewAIController __instance, ConversationType convoType)
			{
				if (!IsStoredChairValid())
				{
					ClearState();
				}
				else if (isSitAndTalkActive && storedSittingInteractable != null)
				{
					PluginController<Plugin, IPluginBindings>.Log.LogInfo((object)"[SitAndTalk] Restoring sitting state after TalkTo");
					((Actor)Player.Instance).SetInteracting(storedSittingInteractable);
					if (storedSittingInteractable.usagePoint != null)
					{
						storedSittingInteractable.usagePoint.TrySetUser((UsePointSlot)0, (Human)(object)Player.Instance, "");
					}
				}
			}
		}

		[HarmonyPatch(typeof(UsagePoint), "TrySetUser")]
		internal static class PreventUsagePointClear
		{
			[HarmonyPrefix]
			private static bool Prefix(UsagePoint __instance, UsePointSlot slot, Human newUser, string debug)
			{
				if (!IsStoredChairValid())
				{
					if (storedSittingInteractable != null)
					{
						ClearState();
					}
					return true;
				}
				if ((isSitAndTalkActive || isRestoringSitting || ((Object)(object)InteractionController.Instance != (Object)null && InteractionController.Instance.lockedInInteraction == storedSittingInteractable)) && (Object)(object)newUser == (Object)null && storedSittingInteractable != null && storedSittingInteractable.usagePoint == __instance)
				{
					PluginController<Plugin, IPluginBindings>.Log.LogInfo((object)"[SitAndTalk] Blocking usagePoint clear");
					return false;
				}
				return true;
			}
		}

		[HarmonyPatch(typeof(InteractionController), "SetLockedInInteractionMode")]
		internal static class PreventClearingSitting
		{
			[HarmonyPrefix]
			private static bool Prefix(Interactable val, InteractionController __instance)
			{
				if (!IsStoredChairValid())
				{
					if (storedSittingInteractable != null)
					{
						ClearState();
					}
					return true;
				}
				if (val != null && (Object)(object)val.isActor != (Object)null && isSitAndTalkActive && __instance.lockedInInteraction == storedSittingInteractable)
				{
					((Actor)Player.Instance).SetInteracting(storedSittingInteractable);
				}
				if (val == null && !isRestoringSitting && __instance.lockedInInteraction == storedSittingInteractable)
				{
					PluginController<Plugin, IPluginBindings>.Log.LogInfo((object)"[SitAndTalk] Unexpected Get Up detected - clearing state and allowing");
					ClearState();
					return true;
				}
				if (val == null && isRestoringSitting)
				{
					PluginController<Plugin, IPluginBindings>.Log.LogInfo((object)"[SitAndTalk] Blocking SetLockedIn(null) during restoration");
					return false;
				}
				return true;
			}

			[HarmonyPostfix]
			private static void Postfix(InteractionController __instance)
			{
				if (!IsStoredChairValid())
				{
					if (storedSittingInteractable != null)
					{
						ClearState();
					}
				}
				else if (isRestoringSitting && storedSittingInteractable != null && __instance.lockedInInteraction == null)
				{
					PluginController<Plugin, IPluginBindings>.Log.LogInfo((object)"[SitAndTalk] Re-applying restoration");
					__instance.lockedInInteraction = storedSittingInteractable;
					__instance.lockedInInteractionRef = 0;
					((Actor)Player.Instance).SetInteracting(storedSittingInteractable);
					if (storedSittingInteractable.usagePoint != null)
					{
						storedSittingInteractable.usagePoint.TrySetUser((UsePointSlot)0, (Human)(object)Player.Instance, "");
					}
					storedSittingInteractable.UpdateCurrentActions();
					__instance.InteractionRaycastCheck();
					__instance.UpdateInteractionText();
					((Actor)Player.Instance).UpdateIllegalStatus();
					PluginController<Plugin, IPluginBindings>.Log.LogInfo((object)"[SitAndTalk] Restoration complete - sitting state intact");
					ClearState();
				}
			}
		}

		[HarmonyPatch(typeof(Player), "TransformPlayerController")]
		internal static class SkipTransformWhileSitting
		{
			[HarmonyPrefix]
			private static bool Prefix(Player __instance, PlayerTransitionPreset newEnterTransition, Interactable newInteractable)
			{
				if (isSitAndTalkActive)
				{
					PluginController<Plugin, IPluginBindings>.Log.LogInfo((object)"[SitAndTalk] Skipping transform");
					return false;
				}
				return true;
			}
		}

		[HarmonyPatch(typeof(Player), "OnReturnFromHide")]
		internal static class BlockOnReturnFromHide
		{
			[HarmonyPrefix]
			private static bool Prefix()
			{
				if (isSitAndTalkActive || isRestoringSitting)
				{
					PluginController<Plugin, IPluginBindings>.Log.LogInfo((object)"[SitAndTalk] Blocking OnReturnFromHide");
					return false;
				}
				return true;
			}
		}

		[HarmonyPatch(typeof(Player), "ReturnFromTransform")]
		internal static class PreventReturnFromTransform
		{
			[HarmonyPrefix]
			private static bool Prefix(Player __instance)
			{
				if (!IsStoredChairValid())
				{
					if (storedSittingInteractable != null)
					{
						ClearState();
					}
					return true;
				}
				if (isSitAndTalkActive || isRestoringSitting)
				{
					PluginController<Plugin, IPluginBindings>.Log.LogInfo((object)"[SitAndTalk] Blocking ReturnFromTransform");
					return false;
				}
				return true;
			}
		}

		[HarmonyPatch(typeof(InteractionController), "SetDialog")]
		internal static class RestoreSittingAfterDialogue
		{
			[HarmonyPostfix]
			private static void Postfix(InteractionController __instance, bool val)
			{
				if (!IsStoredChairValid())
				{
					ClearState();
				}
				else if (!val && isSitAndTalkActive && storedSittingInteractable != null)
				{
					PluginController<Plugin, IPluginBindings>.Log.LogInfo((object)"[SitAndTalk] Dialogue ended, restoring chair");
					isSitAndTalkActive = false;
					isRestoringSitting = true;
					__instance.SetLockedInInteractionMode(storedSittingInteractable, 0, false);
				}
			}
		}

		private static bool isSitAndTalkActive;

		private static bool isRestoringSitting;

		private static Interactable storedSittingInteractable;

		private static bool IsStoredChairValid()
		{
			if (storedSittingInteractable == null)
			{
				return false;
			}
			if (storedSittingInteractable.usagePoint == null)
			{
				return false;
			}
			return true;
		}

		private static void ClearState()
		{
			storedSittingInteractable = null;
			isSitAndTalkActive = false;
			isRestoringSitting = false;
		}
	}
}
namespace OutOfThePast.Patches.BugFixPatches
{
	internal static class PassTimeImprovements
	{
		[HarmonyPatch(typeof(Player), "OnHide")]
		internal static class SuppressOnHide
		{
			[HarmonyPrefix]
			private static bool Prefix()
			{
				if (suppressOnHide)
				{
					return false;
				}
				return true;
			}
		}

		[HarmonyPatch(typeof(ActionController), "PassTime")]
		internal static class PassTimeNoJolt
		{
			[HarmonyPrefix]
			private static void Prefix()
			{
				InteractionController instance = InteractionController.Instance;
				Interactable val = ((instance != null) ? instance.lockedInInteraction : null);
				if (val != null)
				{
					suppressOnHide = true;
					pendingRef = 1;
				}
			}

			[HarmonyPostfix]
			private static void Postfix()
			{
				if (suppressOnHide)
				{
					ApplyPendingRef();
				}
			}
		}

		[HarmonyPatch(typeof(ActionController), "ActivateTimePass")]
		internal static class ActivateTimePassNoJolt
		{
			[HarmonyPrefix]
			private static void Prefix()
			{
				InteractionController instance = InteractionController.Instance;
				Interactable val = ((instance != null) ? instance.lockedInInteraction : null);
				if (val != null)
				{
					suppressOnHide = true;
					pendingRef = 0;
				}
			}

			[HarmonyPostfix]
			private static void Postfix()
			{
				if (suppressOnHide)
				{
					ApplyPendingRef();
				}
			}
		}

		[HarmonyPatch(typeof(ActionController), "CancelPassTime")]
		internal static class CancelPassTimeNoJolt
		{
			[HarmonyPrefix]
			private static void Prefix()
			{
				InteractionController instance = InteractionController.Instance;
				Interactable val = ((instance != null) ? instance.lockedInInteraction : null);
				if (val != null)
				{
					suppressOnHide = true;
					pendingRef = 0;
				}
			}

			[HarmonyPostfix]
			private static void Postfix()
			{
				if (suppressOnHide)
				{
					Player.Instance.SetSettingAlarmMode(false);
					Player.Instance.setAlarmModeAfterDelay = 0f;
					ApplyPendingRef();
				}
			}
		}

		[HarmonyPatch(typeof(BioScreenController), "SelectSlot")]
		internal static class CancelAlarmOnItemSwitch
		{
			[HarmonyPostfix]
			private static void Postfix()
			{
				//IL_001a: Unknown result type (might be due to invalid IL or missing references)
				//IL_0020: Invalid comparison between Unknown and I4
				InventorySlot selectedSlot = BioScreenController.Instance.selectedSlot;
				if (selectedSlot == null || (int)selectedSlot.isStatic == 2)
				{
					return;
				}
				Player instance = Player.Instance;
				if (instance.setAlarmMode || instance.setAlarmModeAfterDelay > 0f)
				{
					instance.SetSettingAlarmMode(false);
					instance.setAlarmModeAfterDelay = 0f;
					InteractionController instance2 = InteractionController.Instance;
					if (((instance2 != null) ? instance2.lockedInInteraction : null) != null)
					{
						instance2.lockedInInteractionRef = 0;
						instance.hideReference = 0;
						instance2.lockedInInteraction.UpdateCurrentActions();
						instance2.UpdateInteractionText();
					}
				}
			}
		}

		private static bool suppressOnHide = false;

		private static int pendingRef = -1;

		private static void ApplyPendingRef()
		{
			InteractionController instance = InteractionController.Instance;
			instance.lockedInInteractionRef = pendingRef;
			Player.Instance.hideReference = pendingRef;
			if (instance.lockedInInteraction != null)
			{
				instance.lockedInInteraction.UpdateCurrentActions();
				instance.UpdateInteractionText();
			}
			suppressOnHide = false;
			pendingRef = -1;
		}
	}
}