Decompiled source of EOSExt SecDoor v1.0.0

plugins/Inas07.EOSExt.SecDoor.dll

Decompiled 2 months ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using System.Text;
using BepInEx;
using BepInEx.Unity.IL2CPP;
using EOSExt.SecDoor.Definition;
using ExtraObjectiveSetup.BaseClasses;
using ExtraObjectiveSetup.Utils;
using GTFO.API;
using GameData;
using HarmonyLib;
using Il2CppInterop.Runtime.Injection;
using Il2CppInterop.Runtime.InteropTypes;
using Il2CppSystem;
using Il2CppSystem.Text;
using LevelGeneration;
using Localization;
using Microsoft.CodeAnalysis;
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("Inas07.EOSExt.SecDoor")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("Inas07.EOSExt.SecDoor")]
[assembly: AssemblyTitle("Inas07.EOSExt.SecDoor")]
[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 EOSExt.SecDoor
{
	public class InteractGlitchManager : MonoBehaviour
	{
		private const string HEX_CHARPOOL = "0123456789ABCDEF";

		private const string ERR_CHARPOOL = "$#/-01";

		private Random Random = new Random();

		private float _Timer;

		private uint START_SECURITY_SCAN_SEQUENCE_TEXT_ID;

		private uint HOLD_TEXT_ID;

		private uint SCAN_UNKNOWN_TEXT_DB;

		public static InteractGlitchManager Current { get; }

		internal bool Enabled { get; set; }

		internal bool CanInteract { get; set; }

		private StringBuilder _StrBuilder { get; } = new StringBuilder();


		internal GlitchMode Mode { get; set; }

		private Dictionary<IntPtr, LG_SecurityDoor> DoorLocks { get; } = new Dictionary<IntPtr, LG_SecurityDoor>();


		private void Update()
		{
			if (Enabled && !(_Timer > Clock.Time) && GuiManager.InteractionLayer != null && Mode != 0)
			{
				switch (Mode)
				{
				case GlitchMode.Style1:
					GuiManager.InteractionLayer.SetInteractPrompt(GetFormat1(), CanInteract ? Text.Format(HOLD_TEXT_ID, (Object[])(object)new Object[1] { Object.op_Implicit(InputMapper.GetBindingName((InputAction)6)) }) : string.Empty, (ePUIMessageStyle)0);
					GuiManager.InteractionLayer.InteractPromptVisible = true;
					_Timer = Clock.Time + 0.05f;
					break;
				case GlitchMode.Style2:
				{
					string format = GetFormat2(Text.Get(START_SECURITY_SCAN_SEQUENCE_TEXT_ID));
					string format2 = GetFormat2(Text.Get(SCAN_UNKNOWN_TEXT_DB));
					GuiManager.InteractionLayer.SetInteractPrompt(format + "<color=red>" + format2 + "</color>", CanInteract ? Text.Format(HOLD_TEXT_ID, (Object[])(object)new Object[1] { Object.op_Implicit(InputMapper.GetBindingName((InputAction)6)) }) : string.Empty, (ePUIMessageStyle)0);
					GuiManager.InteractionLayer.InteractPromptVisible = true;
					_Timer = Clock.Time + 0.075f;
					break;
				}
				}
			}
		}

		private string GetFormat1()
		{
			return "<color=red>://Decryption E_RR at: [" + GetRandomHex() + GetRandomHex() + "-" + GetRandomHex() + GetRandomHex() + "-" + GetRandomHex() + GetRandomHex() + "-" + GetRandomHex() + GetRandomHex() + "]</color>";
		}

		private string GetFormat2(string baseMessage)
		{
			_StrBuilder.Clear();
			foreach (char c in baseMessage)
			{
				if (Random.NextDouble() > 0.009999999776482582 || c == ':')
				{
					_StrBuilder.Append(c);
				}
				else
				{
					_StrBuilder.Append("$#/-01"[Random.Next(0, "$#/-01".Length)]);
				}
			}
			return _StrBuilder.ToString();
		}

		private string GetRandomHex()
		{
			return string.Format("{0}{1}", "0123456789ABCDEF"[Random.Next(0, "0123456789ABCDEF".Length)], "0123456789ABCDEF"[Random.Next(0, "0123456789ABCDEF".Length)]);
		}

		internal void RegisterDoorLocks(LG_SecurityDoor_Locks locks)
		{
			DoorLocks[((Il2CppObjectBase)locks.m_intCustomMessage).Pointer] = locks.m_door;
			DoorLocks[((Il2CppObjectBase)locks.m_intOpenDoor).Pointer] = locks.m_door;
		}

		public GlitchMode GetGlitchMode(Interact_Base interact)
		{
			//IL_0028: Unknown result type (might be due to invalid IL or missing references)
			//IL_002d: Unknown result type (might be due to invalid IL or missing references)
			//IL_002f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0034: Unknown result type (might be due to invalid IL or missing references)
			//IL_003b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0040: Unknown result type (might be due to invalid IL or missing references)
			//IL_0046: Unknown result type (might be due to invalid IL or missing references)
			//IL_0047: Unknown result type (might be due to invalid IL or missing references)
			//IL_0048: Unknown result type (might be due to invalid IL or missing references)
			if (!DoorLocks.TryGetValue(((Il2CppObjectBase)interact).Pointer, out var value))
			{
				return GlitchMode.None;
			}
			eDimensionIndex dimensionIndex = value.Gate.DimensionIndex;
			LG_LayerType linksToLayerType = value.LinksToLayerType;
			eLocalZoneIndex localIndex = value.LinkedToZoneData.LocalIndex;
			return ((ZoneDefinitionManager<SecDoorIntTextOverride>)SecDoorIntTextOverrideManager.Current).GetDefinition(dimensionIndex, linksToLayerType, localIndex)?.GlitchMode ?? GlitchMode.None;
		}

		private void Clear()
		{
			DoorLocks.Clear();
		}

		private InteractGlitchManager()
		{
			START_SECURITY_SCAN_SEQUENCE_TEXT_ID = ((GameDataBlockBase<TextDataBlock>)(object)GameDataBlockBase<TextDataBlock>.GetBlock("InGame.InteractionPrompt.SecurityDoor.StartSecurityScanSequence"))?.persistentID ?? 0;
			HOLD_TEXT_ID = ((GameDataBlockBase<TextDataBlock>)(object)GameDataBlockBase<TextDataBlock>.GetBlock("InGame.InteractionPrompt.Hold_X"))?.persistentID ?? 0;
			SCAN_UNKNOWN_TEXT_DB = ((GameDataBlockBase<TextDataBlock>)(object)GameDataBlockBase<TextDataBlock>.GetBlock("InGame.InteractionPrompt.SecurityDoor.StartSecurityScanSequence_ScanUnknown"))?.persistentID ?? 0;
			LevelAPI.OnBuildStart += Clear;
			LevelAPI.OnLevelCleanup += Clear;
		}

		static InteractGlitchManager()
		{
			//IL_000c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0012: Expected O, but got Unknown
			ClassInjector.RegisterTypeInIl2Cpp<InteractGlitchManager>();
			GameObject val = new GameObject("CONST_InteractGlitchManager");
			Object.DontDestroyOnLoad((Object)(object)val);
			Current = val.AddComponent<InteractGlitchManager>();
		}
	}
	public class SecDoorIntTextOverrideManager : ZoneDefinitionManager<SecDoorIntTextOverride>
	{
		public static SecDoorIntTextOverrideManager Current { get; }

		protected override string DEFINITION_NAME => "SecDoorIntText";

		private SecDoorIntTextOverrideManager()
		{
		}

		static SecDoorIntTextOverrideManager()
		{
			Current = new SecDoorIntTextOverrideManager();
		}
	}
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	[BepInPlugin("Inas.EOSExt.SecDoor", "EOSExt.SecDoor", "1.0.0")]
	public class EntryPoint : BasePlugin
	{
		public const string AUTHOR = "Inas";

		public const string PLUGIN_NAME = "EOSExt.SecDoor";

		public const string VERSION = "1.0.0";

		private Harmony m_Harmony;

		public override void Load()
		{
			//IL_000e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0018: Expected O, but got Unknown
			SetupManagers();
			m_Harmony = new Harmony("EOSExt.SecDoor");
			m_Harmony.PatchAll();
			EOSLogger.Log("ExtraObjectiveSetup.SecDoor loaded.");
		}

		private void SetupManagers()
		{
			((ZoneDefinitionManager<SecDoorIntTextOverride>)SecDoorIntTextOverrideManager.Current).Init();
		}
	}
}
namespace EOSExt.SecDoor.Patches
{
	[HarmonyPatch]
	internal class CustomizeSecDoorInteractionText
	{
		[HarmonyPostfix]
		[HarmonyPatch(typeof(LG_SecurityDoor), "Setup")]
		private static void Post_Customize_SecDoor_Interaction_Text(LG_SecurityDoor __instance)
		{
			//IL_000f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0014: Unknown result type (might be due to invalid IL or missing references)
			//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)
			//IL_0022: Unknown result type (might be due to invalid IL or missing references)
			//IL_0027: Unknown result type (might be due to invalid IL or missing references)
			//IL_002f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0030: Unknown result type (might be due to invalid IL or missing references)
			//IL_0031: Unknown result type (might be due to invalid IL or missing references)
			eDimensionIndex dimensionIndex = __instance.Gate.DimensionIndex;
			LG_LayerType linksToLayerType = __instance.LinksToLayerType;
			eLocalZoneIndex localIndex = __instance.LinkedToZoneData.LocalIndex;
			SecDoorIntTextOverride def = ((ZoneDefinitionManager<SecDoorIntTextOverride>)SecDoorIntTextOverrideManager.Current).GetDefinition(dimensionIndex, linksToLayerType, localIndex);
			LG_SecurityDoor_Locks obj = ((Il2CppObjectBase)__instance.m_locks).Cast<LG_SecurityDoor_Locks>();
			Interact_Timed intOpenDoor = ((obj != null) ? obj.m_intOpenDoor : null);
			if ((Object)(object)intOpenDoor == (Object)null || def == null || def.GlitchMode != 0)
			{
				return;
			}
			__instance.m_sync.OnDoorStateChange += Action<pDoorState, bool>.op_Implicit((Action<pDoorState, bool>)delegate
			{
				//IL_0037: Unknown result type (might be due to invalid IL or missing references)
				//IL_003d: Expected O, but got Unknown
				//IL_00ea: 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_012a: Unknown result type (might be due to invalid IL or missing references)
				string text = (string.IsNullOrEmpty(LocalizedText.op_Implicit(def.TextToReplace)) ? intOpenDoor.InteractionMessage : LocalizedText.op_Implicit(def.TextToReplace));
				StringBuilder val = new StringBuilder();
				if (!string.IsNullOrEmpty(LocalizedText.op_Implicit(def.Prefix)))
				{
					val.Append(LocalizedText.op_Implicit(def.Prefix)).AppendLine();
				}
				val.Append(text);
				if (!string.IsNullOrEmpty(LocalizedText.op_Implicit(def.Postfix)))
				{
					val.AppendLine().Append(LocalizedText.op_Implicit(def.Postfix));
				}
				intOpenDoor.InteractionMessage = ((Object)val).ToString();
				EOSLogger.Debug($"SecDoorIntTextOverride: Override IntText. {((GlobalZoneIndex)def).LocalIndex}, {((GlobalZoneIndex)def).LayerType}, {((GlobalZoneIndex)def).DimensionIndex}");
			});
		}
	}
	[HarmonyPatch]
	internal class InteractGlitch
	{
		[HarmonyPostfix]
		[HarmonyPatch(typeof(Interact_Timed), "OnSelectedChange")]
		private static void Post_Interact_Timed_OnSelectedChange(Interact_Timed __instance, bool selected)
		{
			Handle((Interact_Base)(object)__instance, selected, canInteract: true);
		}

		[HarmonyPostfix]
		[HarmonyPatch(typeof(Interact_MessageOnScreen), "OnSelectedChange")]
		private static void Post_Interact_MessageOnScreen_OnSelectedChange(Interact_MessageOnScreen __instance, bool selected)
		{
			Handle((Interact_Base)(object)__instance, selected, canInteract: false);
		}

		[HarmonyPostfix]
		[HarmonyPatch(typeof(LG_SecurityDoor_Locks), "Setup", new Type[] { typeof(LG_SecurityDoor) })]
		private static void Post_LG_SecurityDoor_Locks_Setup(LG_SecurityDoor_Locks __instance, LG_SecurityDoor door)
		{
			InteractGlitchManager.Current.RegisterDoorLocks(__instance);
		}

		private static void Handle(Interact_Base interact, bool selected, bool canInteract)
		{
			if (selected)
			{
				if (!((Object)(object)interact == (Object)null))
				{
					switch (InteractGlitchManager.Current.GetGlitchMode(interact))
					{
					case GlitchMode.Style1:
						InteractGlitchManager.Current.Enabled = true;
						InteractGlitchManager.Current.CanInteract = canInteract;
						InteractGlitchManager.Current.Mode = GlitchMode.Style1;
						GuiManager.InteractionLayer.InteractPromptVisible = false;
						break;
					case GlitchMode.Style2:
						InteractGlitchManager.Current.Enabled = true;
						InteractGlitchManager.Current.CanInteract = canInteract;
						InteractGlitchManager.Current.Mode = GlitchMode.Style2;
						GuiManager.InteractionLayer.InteractPromptVisible = false;
						break;
					}
				}
			}
			else
			{
				InteractGlitchManager.Current.Enabled = false;
			}
		}
	}
}
namespace EOSExt.SecDoor.Definition
{
	public enum GlitchMode
	{
		None,
		Style1,
		Style2
	}
	public class SecDoorIntTextOverride : GlobalZoneIndex
	{
		public LocalizedText Prefix { get; set; } = null;


		public LocalizedText Postfix { get; set; } = null;


		public LocalizedText TextToReplace { get; set; } = null;


		public GlitchMode GlitchMode { get; set; } = GlitchMode.None;

	}
}