Decompiled source of DestructionTextReplacer v1.0.0

oknorton.DestructTextReplacer.dll

Decompiled 6 hours 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 BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using UnityEngine;
using UnityEngine.Events;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("oknorton.DestructTextReplacer")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("DestructTextReplacer")]
[assembly: AssemblyTitle("oknorton.DestructTextReplacer")]
[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 DestructTextReplacer
{
	public static class ConfigManager
	{
		private static ConfigEntry<string> customWordsConfig;

		private static ConfigEntry<string> leftBehindWordsConfig;

		private static ConfigEntry<string> cancelSelfDestructWordsConfig;

		public static void Initialize(ConfigFile config)
		{
			customWordsConfig = config.Bind<string>("SelfDestruct", "Words", "i'm out,Farewell,Adieu,sayonara,Auf Wiedersehen,adios,ciao,Au Revoir,hasta la vista,see You Later,later,peace OUT,catch you later,later gator,toodles,bye bye,bye,AAAAAAAAAAAAH!,AAAAAAAAAAAAAAAAAAAAAAAH!,bye... ... oh?,this will hurt,it's over for me,why me?,I'm sorry,i see the light,sad but necessary,HEJ DÅ!", "Comma-separated list of self-destruct words");
			leftBehindWordsConfig = config.Bind<string>("LeftBehind", "Words", "I'm sorry,Goodbye,see you later,hope this works out,good luck,peace out,I'm out of here", "Comma-separated list of words for left behind message");
			cancelSelfDestructWordsConfig = config.Bind<string>("SelfDestructCancel", "Words", "Self-destruct sequence aborted!,Phew, that was close!,Canceling self-destruct...,Stand down, crisis averted,False alarm, standing by,Guess I’ll live for now", "Comma-separated list of cancel self-destruct messages");
		}

		public static List<string> GetCancelSelfDestructWords()
		{
			((BaseUnityPlugin)Plugin.Instance).Config.Reload();
			if (cancelSelfDestructWordsConfig == null)
			{
				Debug.LogError((object)"ConfigManager not initialized!");
				return new List<string> { "Error: Config not loaded!" };
			}
			string value = cancelSelfDestructWordsConfig.Value;
			List<string> list = new List<string>(value.Split(','));
			return (list.Count > 0) ? list : new List<string> { "Default cancel message missing!" };
		}

		public static List<string> GetSelfDestructWords()
		{
			((BaseUnityPlugin)Plugin.Instance).Config.Reload();
			if (customWordsConfig == null)
			{
				Debug.LogError((object)"ConfigManager not initialized!");
				return new List<string> { "Error: Config not loaded!" };
			}
			string value = customWordsConfig.Value;
			List<string> list = new List<string>(value.Split(','));
			return (list.Count > 0) ? list : new List<string> { "Default wordlist missing!" };
		}

		public static List<string> GetLeftBehindWords()
		{
			((BaseUnityPlugin)Plugin.Instance).Config.Reload();
			if (leftBehindWordsConfig == null)
			{
				Debug.LogError((object)"ConfigManager not initialized!");
				return new List<string> { "Error: Config not loaded!" };
			}
			string value = leftBehindWordsConfig.Value;
			List<string> list = new List<string>(value.Split(','));
			return (list.Count > 0) ? list : new List<string> { "Default left behind wordlist missing!" };
		}
	}
	[BepInPlugin("oknorton.DestructTextReplacer", "DestructTextReplacer", "1.0.0")]
	[BepInProcess("REPO.exe")]
	public class Plugin : BaseUnityPlugin
	{
		internal static ManualLogSource Logger;

		private static Harmony _harmony;

		public static Plugin Instance { get; private set; }

		private void Awake()
		{
			//IL_0034: Unknown result type (might be due to invalid IL or missing references)
			//IL_003e: Expected O, but got Unknown
			Instance = this;
			ConfigManager.Initialize(((BaseUnityPlugin)this).Config);
			Logger = ((BaseUnityPlugin)this).Logger;
			Logger.LogInfo((object)"Plugin oknorton.DestructTextReplacer is loaded!");
			_harmony = new Harmony("oknorton.DestructTextReplacer");
			_harmony.PatchAll();
		}
	}
	public static class MyPluginInfo
	{
		public const string PLUGIN_GUID = "oknorton.DestructTextReplacer";

		public const string PLUGIN_NAME = "DestructTextReplacer";

		public const string PLUGIN_VERSION = "1.0.0";
	}
}
namespace DestructTextReplacer.Patches
{
	[HarmonyPatch(typeof(ChatManager))]
	public class ChatManagerPatch
	{
		[HarmonyPostfix]
		[HarmonyPatch(typeof(ChatManager), "Awake")]
		private static void AwakePostFix()
		{
			Debug.Log((object)"Starting the patch: Postfix for awake");
		}

		[HarmonyPrefix]
		[HarmonyPatch("PossessSelfDestruction")]
		private static bool PossessSelfDestructionPreFix(ChatManager __instance)
		{
			//IL_0090: Unknown result type (might be due to invalid IL or missing references)
			//IL_0097: Expected O, but got Unknown
			//IL_00c1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c8: Expected O, but got Unknown
			//IL_012d: Unknown result type (might be due to invalid IL or missing references)
			try
			{
				FieldInfo fieldInfo = AccessTools.Field(typeof(ChatManager), "playerAvatar");
				object value = fieldInfo.GetValue(__instance);
				if (value == null)
				{
					return false;
				}
				FieldInfo fieldInfo2 = AccessTools.Field(value.GetType(), "isDisabled");
				if ((bool)fieldInfo2.GetValue(value))
				{
					return false;
				}
				MethodInfo methodInfo = AccessTools.Method(typeof(ChatManager), "PossessChatScheduleStart", (Type[])null, (Type[])null);
				methodInfo.Invoke(__instance, new object[1] { -1 });
				UnityEvent val = new UnityEvent();
				MethodInfo method = AccessTools.Method(typeof(ChatManager), "SelfDestruct", (Type[])null, (Type[])null);
				UnityAction val2 = (UnityAction)Delegate.CreateDelegate(typeof(UnityAction), __instance, method);
				val.AddListener(val2);
				List<string> selfDestructWords = ConfigManager.GetSelfDestructWords();
				string text = selfDestructWords[Random.Range(0, selfDestructWords.Count)];
				MethodInfo methodInfo2 = AccessTools.Method(typeof(ChatManager), "PossessChat", (Type[])null, (Type[])null);
				methodInfo2.Invoke(__instance, new object[8]
				{
					(object)(PossessChatID)3,
					text,
					2f,
					Color.red,
					0f,
					true,
					2,
					val
				});
				MethodInfo methodInfo3 = AccessTools.Method(typeof(ChatManager), "PossessChatScheduleEnd", (Type[])null, (Type[])null);
				methodInfo3.Invoke(__instance, null);
				return false;
			}
			catch (Exception ex)
			{
				Debug.LogError((object)("Error in SelfDestruct patch: " + ex.Message + "\n" + ex.StackTrace));
				return true;
			}
		}

		[HarmonyPrefix]
		[HarmonyPatch("PossessLeftBehind")]
		private static bool PossessLeftBehindPreFix(ChatManager __instance)
		{
			//IL_014a: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a3: Unknown result type (might be due to invalid IL or missing references)
			//IL_01fc: Unknown result type (might be due to invalid IL or missing references)
			//IL_0255: Unknown result type (might be due to invalid IL or missing references)
			//IL_02ae: Unknown result type (might be due to invalid IL or missing references)
			//IL_0307: Unknown result type (might be due to invalid IL or missing references)
			//IL_0360: Unknown result type (might be due to invalid IL or missing references)
			//IL_03b9: Unknown result type (might be due to invalid IL or missing references)
			//IL_0412: Unknown result type (might be due to invalid IL or missing references)
			//IL_046b: Unknown result type (might be due to invalid IL or missing references)
			//IL_04c4: Unknown result type (might be due to invalid IL or missing references)
			//IL_051d: Unknown result type (might be due to invalid IL or missing references)
			//IL_054d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0554: Expected O, but got Unknown
			//IL_057e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0585: Expected O, but got Unknown
			//IL_05d2: Unknown result type (might be due to invalid IL or missing references)
			try
			{
				FieldInfo fieldInfo = AccessTools.Field(typeof(ChatManager), "playerAvatar");
				object value = fieldInfo.GetValue(__instance);
				if (value == null)
				{
					return false;
				}
				FieldInfo fieldInfo2 = AccessTools.Field(value.GetType(), "isDisabled");
				if ((bool)fieldInfo2.GetValue(value))
				{
					return false;
				}
				FieldInfo fieldInfo3 = AccessTools.Field(value.GetType(), "RoomVolumeCheck");
				object value2 = fieldInfo3.GetValue(value);
				FieldInfo fieldInfo4 = AccessTools.Field(value2.GetType(), "inTruck");
				if ((bool)fieldInfo4.GetValue(value2))
				{
					return false;
				}
				FieldInfo fieldInfo5 = AccessTools.Field(typeof(ChatManager), "betrayalActive");
				fieldInfo5.SetValue(__instance, true);
				MethodInfo methodInfo = AccessTools.Method(typeof(ChatManager), "PossessChatScheduleStart", (Type[])null, (Type[])null);
				methodInfo.Invoke(__instance, new object[1] { 2 });
				string text = SemiFunc.MessageGeneratedGetLeftBehind();
				MethodInfo methodInfo2 = AccessTools.Method(typeof(ChatManager), "PossessChat", (Type[])null, (Type[])null);
				methodInfo2.Invoke(__instance, new object[8]
				{
					(object)(PossessChatID)4,
					text,
					0.5f,
					Color.red,
					0f,
					true,
					2,
					null
				});
				methodInfo2.Invoke(__instance, new object[8]
				{
					(object)(PossessChatID)4,
					"I need to get to the truck in...",
					0.4f,
					Color.red,
					0f,
					true,
					2,
					null
				});
				methodInfo2.Invoke(__instance, new object[8]
				{
					(object)(PossessChatID)4,
					"10...",
					0.25f,
					Color.red,
					0f,
					true,
					2,
					null
				});
				methodInfo2.Invoke(__instance, new object[8]
				{
					(object)(PossessChatID)4,
					"9...",
					0.25f,
					Color.red,
					0.3f,
					true,
					2,
					null
				});
				methodInfo2.Invoke(__instance, new object[8]
				{
					(object)(PossessChatID)4,
					"8...",
					0.25f,
					Color.red,
					0.3f,
					true,
					2,
					null
				});
				methodInfo2.Invoke(__instance, new object[8]
				{
					(object)(PossessChatID)4,
					"7...",
					0.25f,
					Color.red,
					0.3f,
					true,
					2,
					null
				});
				methodInfo2.Invoke(__instance, new object[8]
				{
					(object)(PossessChatID)4,
					"6...",
					0.25f,
					Color.red,
					0.3f,
					true,
					2,
					null
				});
				methodInfo2.Invoke(__instance, new object[8]
				{
					(object)(PossessChatID)4,
					"5...",
					0.25f,
					Color.red,
					0.3f,
					true,
					2,
					null
				});
				methodInfo2.Invoke(__instance, new object[8]
				{
					(object)(PossessChatID)4,
					"4...",
					0.25f,
					Color.red,
					0.3f,
					true,
					2,
					null
				});
				methodInfo2.Invoke(__instance, new object[8]
				{
					(object)(PossessChatID)4,
					"3...",
					0.25f,
					Color.red,
					0.3f,
					true,
					2,
					null
				});
				methodInfo2.Invoke(__instance, new object[8]
				{
					(object)(PossessChatID)4,
					"2...",
					0.25f,
					Color.red,
					0.3f,
					true,
					2,
					null
				});
				methodInfo2.Invoke(__instance, new object[8]
				{
					(object)(PossessChatID)4,
					"1...",
					0.5f,
					Color.red,
					0.3f,
					true,
					2,
					null
				});
				UnityEvent val = new UnityEvent();
				MethodInfo method = AccessTools.Method(typeof(ChatManager), "BetrayalSelfDestruct", (Type[])null, (Type[])null);
				UnityAction val2 = (UnityAction)Delegate.CreateDelegate(typeof(UnityAction), __instance, method);
				val.AddListener(val2);
				List<string> leftBehindWords = ConfigManager.GetLeftBehindWords();
				string text2 = leftBehindWords[Random.Range(0, leftBehindWords.Count)];
				methodInfo2.Invoke(__instance, new object[8]
				{
					(object)(PossessChatID)3,
					text2,
					2f,
					Color.red,
					0f,
					true,
					2,
					val
				});
				MethodInfo methodInfo3 = AccessTools.Method(typeof(ChatManager), "PossessChatScheduleEnd", (Type[])null, (Type[])null);
				methodInfo3.Invoke(__instance, null);
				return false;
			}
			catch (Exception ex)
			{
				Debug.LogError((object)("Error in LeftBehind patch: " + ex.Message + "\n" + ex.StackTrace));
				return true;
			}
		}

		[HarmonyPrefix]
		[HarmonyPatch("PossessCancelSelfDestruction")]
		private static bool PossessCancelSelfDestructionPreFix(ChatManager __instance)
		{
			//IL_00eb: Unknown result type (might be due to invalid IL or missing references)
			try
			{
				FieldInfo fieldInfo = AccessTools.Field(typeof(ChatManager), "playerAvatar");
				object value = fieldInfo.GetValue(__instance);
				if (value == null)
				{
					return false;
				}
				FieldInfo fieldInfo2 = AccessTools.Field(value.GetType(), "isDisabled");
				if ((bool)fieldInfo2.GetValue(value))
				{
					return false;
				}
				MethodInfo methodInfo = AccessTools.Method(typeof(ChatManager), "PossessChatScheduleStart", (Type[])null, (Type[])null);
				methodInfo.Invoke(__instance, new object[1] { 1 });
				List<string> cancelSelfDestructWords = ConfigManager.GetCancelSelfDestructWords();
				string text = cancelSelfDestructWords[Random.Range(0, cancelSelfDestructWords.Count)];
				MethodInfo methodInfo2 = AccessTools.Method(typeof(ChatManager), "PossessChat", (Type[])null, (Type[])null);
				methodInfo2.Invoke(__instance, new object[8]
				{
					(object)(PossessChatID)5,
					text,
					2f,
					Color.green,
					0f,
					false,
					0,
					null
				});
				MethodInfo methodInfo3 = AccessTools.Method(typeof(ChatManager), "PossessChatScheduleEnd", (Type[])null, (Type[])null);
				methodInfo3.Invoke(__instance, null);
				return false;
			}
			catch (Exception ex)
			{
				Debug.LogError((object)("Error in CancelSelfDestruct patch: " + ex.Message + "\n" + ex.StackTrace));
				return true;
			}
		}
	}
}