Decompiled source of shermaInbellhome v1.0.1

shermaInBellhome.dll

Decompiled 2 months ago
using System;
using System.Collections;
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 BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using Microsoft.CodeAnalysis;
using UnityEngine;
using UnityEngine.AddressableAssets;
using UnityEngine.ResourceManagement.AsyncOperations;
using UnityEngine.ResourceManagement.ResourceProviders;
using UnityEngine.SceneManagement;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("shermaInBellhome")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.1.0")]
[assembly: AssemblyInformationalVersion("1.0.1+7db718fab2a5d4d87d0c36fddcf8af737df35644")]
[assembly: AssemblyProduct("shermaInBellhome")]
[assembly: AssemblyTitle("shermaInbellhome")]
[assembly: AssemblyMetadata("RepositoryUrl", "https://github.com/w-nityammm/shermaInBellhome")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.1.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.Class | AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Event | AttributeTargets.Parameter | AttributeTargets.ReturnValue | AttributeTargets.GenericParameter, AllowMultiple = false, Inherited = false)]
	internal sealed class NullableAttribute : Attribute
	{
		public readonly byte[] NullableFlags;

		public NullableAttribute(byte P_0)
		{
			NullableFlags = new byte[1] { P_0 };
		}

		public NullableAttribute(byte[] P_0)
		{
			NullableFlags = P_0;
		}
	}
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	[AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Method | AttributeTargets.Interface | AttributeTargets.Delegate, AllowMultiple = false, Inherited = false)]
	internal sealed class NullableContextAttribute : Attribute
	{
		public readonly byte Flag;

		public NullableContextAttribute(byte P_0)
		{
			Flag = P_0;
		}
	}
	[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 BepInEx
{
	[AttributeUsage(AttributeTargets.Class, Inherited = false, AllowMultiple = false)]
	[Conditional("CodeGeneration")]
	internal sealed class BepInAutoPluginAttribute : Attribute
	{
		public BepInAutoPluginAttribute(string? id = null, string? name = null, string? version = null)
		{
		}
	}
}
namespace BepInEx.Preloader.Core.Patching
{
	[AttributeUsage(AttributeTargets.Class, Inherited = false, AllowMultiple = false)]
	[Conditional("CodeGeneration")]
	internal sealed class PatcherAutoPluginAttribute : Attribute
	{
		public PatcherAutoPluginAttribute(string? id = null, string? name = null, string? version = null)
		{
		}
	}
}
namespace ShermaInBellHome
{
	[BepInPlugin("com.w-nityammm.ShermaInBellHome", "ShermaInBellHome", "1.0.1")]
	public class Plugin : BaseUnityPlugin
	{
		[CompilerGenerated]
		private sealed class <AddInspect>d__17 : IEnumerator<object>, IEnumerator, IDisposable
		{
			private int <>1__state;

			private object <>2__current;

			public Plugin <>4__this;

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

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

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

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

			private bool MoveNext()
			{
				//IL_0024: Unknown result type (might be due to invalid IL or missing references)
				//IL_002e: Expected O, but got Unknown
				//IL_0080: Unknown result type (might be due to invalid IL or missing references)
				//IL_008b: Unknown result type (might be due to invalid IL or missing references)
				//IL_0090: Unknown result type (might be due to invalid IL or missing references)
				//IL_009a: Expected O, but got Unknown
				//IL_00bb: Unknown result type (might be due to invalid IL or missing references)
				int num = <>1__state;
				Plugin CS$<>8__locals0 = <>4__this;
				switch (num)
				{
				default:
					return false;
				case 0:
					<>1__state = -1;
					<>2__current = (object)new WaitForSeconds(0.1f);
					<>1__state = 1;
					return true;
				case 1:
				{
					<>1__state = -1;
					string text = "Black Thread States/Black Thread World/Enclave Act 3/Sherma Caretaker";
					GameObject val = GameObject.Find(text);
					if ((Object)(object)val == (Object)null)
					{
						Log.LogError((object)("ShermaInBellHome: Could not find Sherma at path '" + text + "'"));
						return false;
					}
					Log.LogInfo((object)"ShermaInBellHome: Found Sherma");
					CS$<>8__locals0.inspect = Object.Instantiate<GameObject>(new GameObject(), val.transform.position, Quaternion.identity);
					BoxCollider2D obj = CS$<>8__locals0.inspect.AddComponent<BoxCollider2D>();
					((Collider2D)obj).isTrigger = true;
					obj.size = new Vector2(4f, 4f);
					InteractEvents obj2 = CS$<>8__locals0.inspect.AddComponent<InteractEvents>();
					((InteractableBase)obj2).InteractLabel = (PromptLabels)0;
					obj2.Interacted += delegate
					{
						if (!((Object)(object)CS$<>8__locals0.heroController == (Object)null))
						{
							CS$<>8__locals0.heroController.RelinquishControl();
							DialogueYesNoBox.Open((Action)delegate
							{
								CS$<>8__locals0.heroController.RegainControl();
								CS$<>8__locals0.InspectDialogue(answer: true);
							}, (Action)delegate
							{
								CS$<>8__locals0.heroController.RegainControl();
								CS$<>8__locals0.InspectDialogue(answer: false);
							}, true, "Take Sherma to Bellhome", (SavedItem)null);
						}
					};
					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();
			}
		}

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

			private object <>2__current;

			public Plugin <>4__this;

			private AsyncOperationHandle<SceneInstance> <handle>5__2;

			private Scene <shermaScene>5__3;

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

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

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

			[DebuggerHidden]
			void IDisposable.Dispose()
			{
				//IL_0006: Unknown result type (might be due to invalid IL or missing references)
				<handle>5__2 = default(AsyncOperationHandle<SceneInstance>);
				<>1__state = -2;
			}

			private bool MoveNext()
			{
				//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_0047: Unknown result type (might be due to invalid IL or missing references)
				//IL_006c: Unknown result type (might be due to invalid IL or missing references)
				//IL_0072: Invalid comparison between Unknown and I4
				//IL_007d: Unknown result type (might be due to invalid IL or missing references)
				//IL_0082: Unknown result type (might be due to invalid IL or missing references)
				//IL_0085: Unknown result type (might be due to invalid IL or missing references)
				//IL_008a: Unknown result type (might be due to invalid IL or missing references)
				//IL_0092: Unknown result type (might be due to invalid IL or missing references)
				//IL_0097: Unknown result type (might be due to invalid IL or missing references)
				//IL_0188: Unknown result type (might be due to invalid IL or missing references)
				//IL_016b: Unknown result type (might be due to invalid IL or missing references)
				int num = <>1__state;
				Plugin plugin = <>4__this;
				switch (num)
				{
				default:
					return false;
				case 0:
					<>1__state = -1;
					plugin.loadedInBellHome = true;
					<handle>5__2 = Addressables.LoadSceneAsync((object)"Scenes/Song_Enclave", (LoadSceneMode)1, true, 100, (SceneReleaseMode)0);
					<>2__current = <handle>5__2;
					<>1__state = 1;
					return true;
				case 1:
					<>1__state = -1;
					if ((int)<handle>5__2.Status == 1)
					{
						SceneInstance result = <handle>5__2.Result;
						plugin.shermaSceneLoadOp = <handle>5__2;
						<shermaScene>5__3 = ((SceneInstance)(ref result)).Scene;
						<>2__current = null;
						<>1__state = 2;
						return true;
					}
					break;
				case 2:
				{
					<>1__state = -1;
					plugin.shermaSceneLoaded = true;
					if (!((Scene)(ref <shermaScene>5__3)).IsValid() || !((Scene)(ref <shermaScene>5__3)).isLoaded)
					{
						break;
					}
					GameObject[] rootGameObjects = ((Scene)(ref <shermaScene>5__3)).GetRootGameObjects();
					foreach (GameObject val in rootGameObjects)
					{
						Transform val2 = plugin.FindChild(val.transform, "Sherma Caretaker");
						if ((Object)(object)val2 == (Object)null)
						{
							Object.Destroy((Object)(object)val.gameObject);
							continue;
						}
						val2.SetParent((Transform)null, true);
						Object.Destroy((Object)(object)val.gameObject);
						if ((Object)(object)plugin.heroController != (Object)null && plugin.heroController.playerData.GetBool("BelltownFurnishingSpa"))
						{
							val2.position = new Vector3(22.45f, 13.9f, 0.0051f);
						}
						else
						{
							val2.position = new Vector3(21f, 7.1f, 0.0051f);
						}
					}
					break;
				}
				}
				plugin.loadedInBellHome = false;
				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();
			}
		}

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

			private object <>2__current;

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

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

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

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

			private bool MoveNext()
			{
				//IL_001d: Unknown result type (might be due to invalid IL or missing references)
				//IL_0027: Expected O, but got Unknown
				switch (<>1__state)
				{
				default:
					return false;
				case 0:
					<>1__state = -1;
					<>2__current = (object)new WaitForSeconds(0.1f);
					<>1__state = 1;
					return true;
				case 1:
				{
					<>1__state = -1;
					string text = "Black Thread States/Black Thread World/Enclave Act 3/Sherma Caretaker";
					GameObject val = GameObject.Find(text);
					if ((Object)(object)val != (Object)null)
					{
						Object.Destroy((Object)(object)val);
						Log.LogInfo((object)"ShermaInBellHome: Removed Sherma from scene.");
					}
					else
					{
						Log.LogWarning((object)("ShermaInBellHome: Could not find Sherma at path '" + text + "' to remove!"));
					}
					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();
			}
		}

		internal static ManualLogSource Log;

		private HeroController heroController;

		private int saveFileIdx;

		private GameObject inspect;

		private List<ConfigEntry<bool>> shermaTakenConfigs = new List<ConfigEntry<bool>>();

		private List<ConfigEntry<bool>> shermaInBellHomeConfigs = new List<ConfigEntry<bool>>();

		private bool loadedInBellHome;

		private List<string> noNoSceneNames = new List<string> { "Pre_Menu_Loader", "Pre_Menu_Intro", "Menu_Title", "Song_Enclave" };

		private bool shermaSceneLoaded;

		private AsyncOperationHandle<SceneInstance> shermaSceneLoadOp;

		private void Awake()
		{
			Log = ((BaseUnityPlugin)this).Logger;
			SceneManager.sceneLoaded += OnSceneLoaded;
			for (int i = 0; i < 4; i++)
			{
				shermaTakenConfigs.Add(((BaseUnityPlugin)this).Config.Bind<bool>($"Save File {i}", "shermaTaken", false, ""));
				shermaInBellHomeConfigs.Add(((BaseUnityPlugin)this).Config.Bind<bool>($"Save File {i}", "shermaInBellHome", false, ""));
			}
		}

		private void Update()
		{
			if ((Object)(object)heroController == (Object)null)
			{
				heroController = HeroController.instance;
			}
		}

		private void OnDisable()
		{
			SceneManager.sceneLoaded -= OnSceneLoaded;
		}

		private void OnSceneLoaded(Scene scene, LoadSceneMode mode)
		{
			//IL_005e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0064: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)heroController != (Object)null)
			{
				try
				{
					saveFileIdx = heroController.playerData.profileID - 1;
				}
				catch (Exception)
				{
					Log.LogWarning((object)"Could not get saveFileIdx.");
				}
			}
			if (((Scene)(ref scene)).name != "Belltown_Room_Spare" && shermaSceneLoaded)
			{
				Addressables.UnloadSceneAsync(shermaSceneLoadOp.Result, true);
				shermaSceneLoaded = false;
			}
			if (saveFileIdx >= 0 && saveFileIdx < 4)
			{
				if (((Scene)(ref scene)).name == "Belltown_Room_Spare" && shermaInBellHomeConfigs[saveFileIdx].Value)
				{
					((MonoBehaviour)this).StartCoroutine(LoadSherma());
				}
				if (!noNoSceneNames.Contains(((Scene)(ref scene)).name) && shermaTakenConfigs[saveFileIdx].Value && !shermaInBellHomeConfigs[saveFileIdx].Value)
				{
					shermaInBellHomeConfigs[saveFileIdx].Value = true;
					((BaseUnityPlugin)this).Config.Save();
				}
			}
			if (((Scene)(ref scene)).name == "Song_Enclave" && (Object)(object)heroController != (Object)null && heroController.playerData.GetBool("shermaCaretakerConvo1") && saveFileIdx >= 0 && saveFileIdx < 4)
			{
				if (!shermaInBellHomeConfigs[saveFileIdx].Value)
				{
					((MonoBehaviour)this).StartCoroutine(AddInspect());
				}
				else
				{
					((MonoBehaviour)this).StartCoroutine(RemoveSherma());
				}
			}
		}

		[IteratorStateMachine(typeof(<LoadSherma>d__14))]
		private IEnumerator LoadSherma()
		{
			//yield-return decompiler failed: Unexpected instruction in Iterator.Dispose()
			return new <LoadSherma>d__14(0)
			{
				<>4__this = this
			};
		}

		private Transform FindChild(Transform parent, string name)
		{
			if (((Object)parent).name == name)
			{
				return parent;
			}
			for (int i = 0; i < parent.childCount; i++)
			{
				Transform child = parent.GetChild(i);
				Transform val = FindChild(child, name);
				if ((Object)(object)val != (Object)null)
				{
					return val;
				}
			}
			return null;
		}

		[IteratorStateMachine(typeof(<RemoveSherma>d__16))]
		private IEnumerator RemoveSherma()
		{
			//yield-return decompiler failed: Unexpected instruction in Iterator.Dispose()
			return new <RemoveSherma>d__16(0);
		}

		[IteratorStateMachine(typeof(<AddInspect>d__17))]
		private IEnumerator AddInspect()
		{
			//yield-return decompiler failed: Unexpected instruction in Iterator.Dispose()
			return new <AddInspect>d__17(0)
			{
				<>4__this = this
			};
		}

		private void InspectDialogue(bool answer)
		{
			if (answer)
			{
				if (saveFileIdx >= 0 && saveFileIdx < 4)
				{
					shermaTakenConfigs[saveFileIdx].Value = true;
					((BaseUnityPlugin)this).Config.Save();
				}
				Object.Destroy((Object)(object)inspect);
				((MonoBehaviour)this).StartCoroutine(RemoveSherma());
			}
		}
	}
}