Decompiled source of AverageTierGabriel v1.0.0

plugins/AverageTierGabriel/AverageTierGabriel.dll

Decompiled 2 months ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using System.Threading;
using System.Threading.Tasks;
using BepInEx;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using UnityEngine;
using UnityEngine.SceneManagement;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETStandard,Version=v2.0", FrameworkDisplayName = ".NET Standard 2.0")]
[assembly: AssemblyCompany("AverageTierGabriel")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyDescription("yeae")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0+0cf93a53ad8ef37019ccab94c858dda4fdb8eefa")]
[assembly: AssemblyProduct("AverageTierGabriel")]
[assembly: AssemblyTitle("AverageTierGabriel")]
[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;
		}
	}
}
public class DisableIt : MonoBehaviour
{
	[SerializeField]
	private string ToFindAndDisable;

	private void OnTriggerEnter(Collider other)
	{
		//IL_0001: Unknown result type (might be due to invalid IL or missing references)
		if (((Component)other).gameObject.CompareTag("Player"))
		{
			Object.Destroy((Object)(object)GameObject.Find(ToFindAndDisable));
		}
	}
}
namespace LowTierSisy
{
	[BepInPlugin("ImNotSimon.AverageTierGabriel", "AverageTierGabriel", "1.0.0")]
	public class Plugin : BaseUnityPlugin
	{
		public class UnityMainThreadDispatcher : MonoBehaviour
		{
			private static UnityMainThreadDispatcher _instance;

			private readonly Queue<Action> _executionQueue = new Queue<Action>();

			public static UnityMainThreadDispatcher Instance()
			{
				//IL_0012: Unknown result type (might be due to invalid IL or missing references)
				//IL_0017: Unknown result type (might be due to invalid IL or missing references)
				//IL_0027: Expected O, but got Unknown
				if ((Object)(object)_instance == (Object)null)
				{
					GameObject val = new GameObject("UnityMainThreadDispatcher");
					_instance = val.AddComponent<UnityMainThreadDispatcher>();
					Object.DontDestroyOnLoad((Object)val);
				}
				return _instance;
			}

			public void Update()
			{
				while (_executionQueue.Count > 0)
				{
					_executionQueue.Dequeue()();
				}
			}

			public void Enqueue(Action action)
			{
				lock (_executionQueue)
				{
					_executionQueue.Enqueue(action);
				}
			}
		}

		[HarmonyPatch(typeof(StockMapInfo), "Awake")]
		internal class Patch00
		{
			private static void Postfix(StockMapInfo __instance)
			{
				//IL_00ce: Unknown result type (might be due to invalid IL or missing references)
				//IL_00d5: Expected O, but got Unknown
				//IL_014e: Unknown result type (might be due to invalid IL or missing references)
				//IL_0153: Unknown result type (might be due to invalid IL or missing references)
				AudioSource[] array = Resources.FindObjectsOfTypeAll<AudioSource>();
				foreach (AudioSource val in array)
				{
					if (!Object.op_Implicit((Object)(object)val.clip))
					{
						continue;
					}
					bool flag = false;
					new List<SubtitleDataLine>();
					if (((Object)val.clip).name == "gab_Behold")
					{
						Debug.Log((object)"Replacing gabe behold");
						AudioClip val2 = (((Object)(object)GabBundle != (Object)null) ? GabBundle.LoadAsset<AudioClip>("gab_gtfo.mp3") : null);
						if ((Object)(object)val2 != (Object)null)
						{
							val.clip = val2;
							flag = true;
							Debug.Log((object)"Audio clip 'gab_gtfo.mp3' loaded and replaced successfully.");
						}
						else
						{
							Debug.LogError((object)"Failed to load audio clip 'gab_gtfo.mp3' from AssetBundle.");
						}
					}
					if (!flag)
					{
						continue;
					}
					SubtitledAudioSource val3 = ((Component)val).GetComponent<SubtitledAudioSource>();
					if ((Object)(object)val3 == (Object)null)
					{
						val3 = ((Component)val).gameObject.AddComponent<SubtitledAudioSource>();
						Debug.Log((object)"SubtitledAudioSource component was missing and has been added.");
					}
					if ((Object)(object)val3 != (Object)null)
					{
						SubtitleData val4 = new SubtitleData();
						val4.lines = (SubtitleDataLine[])(object)new SubtitleDataLine[1] { MakeLine("Get the FUCK out of my palace!", 2f) };
						SubtitleData value = val4;
						Traverse obj = Traverse.Create((object)val3).Field("subtitles");
						obj.SetValue((object)value);
						object value2 = obj.GetValue();
						SubtitleData val5 = (SubtitleData)((value2 is SubtitleData) ? value2 : null);
						if (val5 != null && val5.lines.Length != 0)
						{
							Debug.Log((object)"Subtitles updated successfully.");
						}
						else
						{
							Debug.LogError((object)"Failed to update subtitles. SubtitleData is null or empty.");
						}
					}
					else
					{
						Debug.LogError((object)"Failed to add or find SubtitledAudioSource component.");
					}
					Scene activeScene = SceneManager.GetActiveScene();
					if (((Scene)(ref activeScene)).name == "f1aa2efdf8dccae45b1396aef397ed79")
					{
						WatchForGameObjectActivation("gab_Intro1");
					}
				}
			}
		}

		public class GameObjectWatcher : MonoBehaviour
		{
			private static GameObjectWatcher _instance;

			public static GameObjectWatcher Instance
			{
				get
				{
					//IL_0029: Unknown result type (might be due to invalid IL or missing references)
					if ((Object)(object)_instance == (Object)null)
					{
						_instance = Object.FindObjectOfType<GameObjectWatcher>();
						if ((Object)(object)_instance == (Object)null)
						{
							_instance = new GameObject("GameObjectWatcher").AddComponent<GameObjectWatcher>();
						}
					}
					return _instance;
				}
			}

			public static IEnumerator WaitForActivation(string gameObjectName)
			{
				GameObject targetGameObject = GameObject.Find(gameObjectName);
				if ((Object)(object)targetGameObject == (Object)null)
				{
					Debug.LogError((object)("GameObject with the name '" + gameObjectName + "' not found in the scene."));
					yield break;
				}
				while (!targetGameObject.activeInHierarchy)
				{
					yield return null;
				}
				Debug.Log((object)("GameObject '" + gameObjectName + "' is now active."));
			}
		}

		private static Harmony harmony;

		internal static AssetBundle GabBundle;

		private static bool prefabInstantiated;

		private void Awake()
		{
			//IL_006f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0079: Expected O, but got Unknown
			//IL_0088: Unknown result type (might be due to invalid IL or missing references)
			Debug.Log((object)"MACHINE! (simon's gabriel mod starting)");
			Assembly.GetExecutingAssembly();
			string path = "averagetiergabriel";
			string text = Path.Combine(ModPath(), path);
			if (File.Exists(text))
			{
				GabBundle = AssetBundle.LoadFromFile(text);
				if ((Object)(object)GabBundle == (Object)null)
				{
					Debug.LogError((object)"Failed to load AssetBundle. The bundle is null.");
				}
				else
				{
					Debug.Log((object)"AssetBundle loaded successfully.");
				}
			}
			else
			{
				Debug.LogError((object)("AssetBundle file not found at path: " + text));
			}
			harmony = new Harmony("simon.Gabriel");
			harmony.PatchAll();
			new GameObject("GameObjectWatcher").AddComponent<GameObjectWatcher>();
			SceneManager.sceneLoaded += OnSceneLoaded;
		}

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

		private void OnSceneLoaded(Scene scene, LoadSceneMode mode)
		{
			prefabInstantiated = false;
			Debug.Log((object)"Scene loaded. Prefab instantiation flag reset.");
		}

		public static async void WatchForGameObjectActivation(string gameObjectName)
		{
			await Task.Run(delegate
			{
				CheckForGameObjectActivation(gameObjectName);
			});
		}

		private static void CheckForGameObjectActivation(string gameObjectName)
		{
			bool found = false;
			while (!found)
			{
				UnityMainThreadDispatcher.Instance().Enqueue(delegate
				{
					GameObject val = GameObject.Find(gameObjectName);
					if ((Object)(object)val != (Object)null && val.activeInHierarchy)
					{
						Debug.Log((object)("GameObject '" + gameObjectName + "' is now active."));
						LoadAndInstantiatePrefab();
						found = true;
					}
				});
				Thread.Sleep(50);
			}
		}

		private static void LoadAndInstantiatePrefab()
		{
			//IL_002a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0035: Unknown result type (might be due to invalid IL or missing references)
			//IL_004c: Unknown result type (might be due to invalid IL or missing references)
			if (!prefabInstantiated)
			{
				string text = "cowardice";
				GameObject val = GabBundle.LoadAsset<GameObject>(text);
				if ((Object)(object)val != (Object)null)
				{
					Object.Instantiate<GameObject>(val, val.transform.position, val.transform.rotation);
					Debug.Log((object)$"{text} prefab instantiated successfully at {val.transform.position}.");
					prefabInstantiated = true;
				}
				else
				{
					Debug.LogError((object)("Failed to load prefab '" + text + "' from AssetBundle."));
				}
			}
		}

		public static string ModPath()
		{
			return Assembly.GetExecutingAssembly().Location.Substring(0, Assembly.GetExecutingAssembly().Location.LastIndexOf(Path.DirectorySeparatorChar));
		}

		private static SubtitleDataLine MakeLine(string subtitle, float time)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0005: Unknown result type (might be due to invalid IL or missing references)
			//IL_000c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0014: Expected O, but got Unknown
			return new SubtitleDataLine
			{
				subtitle = subtitle,
				time = time
			};
		}
	}
}