Decompiled source of CoronerCustomMessages v1.1.0

BepInEx\plugins\CoronerCustomMessages\CoronerCustomMessages.dll

Decompiled 7 hours ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Xml.Linq;
using BepInEx;
using BepInEx.Configuration;
using Coroner;
using Microsoft.CodeAnalysis;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETFramework,Version=v4.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")]
[assembly: AssemblyCompany("CoronerCustomMessages")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("CoronerCustomMessages")]
[assembly: AssemblyTitle("CoronerCustomMessages")]
[assembly: AssemblyVersion("1.0.0.0")]
[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 CoronerCustomMessages
{
	[BepInPlugin("dowompi.coronercustommessages", "Coroner Custom Messages", "1.1.0")]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	public sealed class Plugin : BaseUnityPlugin
	{
		public const string PluginGuid = "dowompi.coronercustommessages";

		public const string PluginName = "Coroner Custom Messages";

		public const string PluginVersion = "1.1.0";

		private const string LanguageCode = "en-us";

		private const string OutputFileName = "Strings_en-us_custom.xml";

		private const string Separator = "||";

		private ConfigEntry<bool> pluginEnabled;

		private ConfigEntry<string> brackenMessages;

		private ConfigEntry<string> coilHeadMessages;

		private ConfigEntry<string> jesterMessages;

		private ConfigEntry<string> landmineMessages;

		private ConfigEntry<string> jetpackBlastMessages;

		private ConfigEntry<string> cruiserRanOverMessages;

		private ConfigEntry<string> spikeTrapMessages;

		private ConfigEntry<string> unknownMessages;

		private void Awake()
		{
			BindConfig();
			WriteLanguageFile();
			ReloadCoronerLanguage();
			((BaseUnityPlugin)this).Logger.LogInfo((object)"Coroner Custom Messages loaded.");
		}

		private void BindConfig()
		{
			pluginEnabled = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "Enabled", true, "Enable writing the custom Coroner language file.");
			brackenMessages = BindMessageList("DeathEnemyBracken", "Was folded into a portable shape by a Bracken.||Learned too late that the Bracken wanted privacy.");
			coilHeadMessages = BindMessageList("DeathEnemyCoilHead", "Lost a staring contest with a Coil-Head.||Blinking was the last mistake they made.");
			jesterMessages = BindMessageList("DeathEnemyJester", "Stayed for the punchline. There was no survival after it.||Heard the music and still did not leave.");
			landmineMessages = BindMessageList("DeathOtherLandmine", "Conducted an unscheduled landmine inspection.||Proved the mine was active.");
			jetpackBlastMessages = BindMessageList("DeathPlayerJetpackBlast", "Turned the jetpack into a very brief career.||Misunderstood which end of the jetpack was the dangerous one.");
			cruiserRanOverMessages = BindMessageList("DeathPlayerCruiserRanOver", "Became a speed bump for company transport.||Lost an argument with several tons of cruiser.");
			spikeTrapMessages = BindMessageList("DeathOtherSpikeTrap", "Tested the spike trap so the team would not have to.||Found the trap the fast way.");
			unknownMessages = BindMessageList("DeathUnknown", "Died under unclear but probably embarrassing circumstances.");
		}

		private ConfigEntry<string> BindMessageList(string tag, string defaultValue)
		{
			return ((BaseUnityPlugin)this).Config.Bind<string>("Messages", tag, defaultValue, "Messages for " + tag + ". Separate multiple variants with '||'.");
		}

		private void WriteLanguageFile()
		{
			//IL_013f: Unknown result type (might be due to invalid IL or missing references)
			//IL_016d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0173: Expected O, but got Unknown
			//IL_0198: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a2: Expected O, but got Unknown
			//IL_019d: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a7: Expected O, but got Unknown
			//IL_01a2: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a8: Expected O, but got Unknown
			//IL_01d5: Unknown result type (might be due to invalid IL or missing references)
			//IL_01db: Expected O, but got Unknown
			//IL_01db: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e1: Expected O, but got Unknown
			//IL_01e6: Expected O, but got Unknown
			//IL_01e1: Unknown result type (might be due to invalid IL or missing references)
			string text = Path.Combine(Paths.ConfigPath, "EliteMasterEric-Coroner");
			Directory.CreateDirectory(text);
			string text2 = Path.Combine(text, "Strings_en-us_custom.xml");
			if (!pluginEnabled.Value)
			{
				if (File.Exists(text2))
				{
					File.Delete(text2);
					((BaseUnityPlugin)this).Logger.LogInfo((object)"Deleted Strings_en-us_custom.xml because the plugin is disabled.");
				}
				return;
			}
			KeyValuePair<string, string>[] source = new KeyValuePair<string, string>[8]
			{
				CreateEntry("DeathEnemyBracken", brackenMessages.Value),
				CreateEntry("DeathEnemyCoilHead", coilHeadMessages.Value),
				CreateEntry("DeathEnemyJester", jesterMessages.Value),
				CreateEntry("DeathOtherLandmine", landmineMessages.Value),
				CreateEntry("DeathPlayerJetpackBlast", jetpackBlastMessages.Value),
				CreateEntry("DeathPlayerCruiserRanOver", cruiserRanOverMessages.Value),
				CreateEntry("DeathOtherSpikeTrap", spikeTrapMessages.Value),
				CreateEntry("DeathUnknown", unknownMessages.Value)
			};
			new XDocument(new XDeclaration("1.0", "utf-8", (string)null), new object[1] { (object)new XElement(XName.op_Implicit("base"), new object[3]
			{
				(object)new XAttribute(XName.op_Implicit("type"), (object)"string"),
				(object)new XElement(XName.op_Implicit("tags"), (object)new XElement(XName.op_Implicit("tag"), (object)new XAttribute(XName.op_Implicit("language"), (object)"en-us"))),
				(object)new XElement(XName.op_Implicit("strings"), (object)source.SelectMany(BuildElementsForEntry))
			}) }).Save(text2);
			((BaseUnityPlugin)this).Logger.LogInfo((object)("Wrote " + text2));
		}

		private static KeyValuePair<string, string> CreateEntry(string tag, string rawValue)
		{
			return new KeyValuePair<string, string>(tag, rawValue ?? string.Empty);
		}

		private static IEnumerable<XElement> BuildElementsForEntry(KeyValuePair<string, string> entry)
		{
			foreach (string item in SplitMessages(entry.Value))
			{
				yield return new XElement(XName.op_Implicit(entry.Key), (object)new XAttribute(XName.op_Implicit("text"), (object)item));
			}
		}

		private static IEnumerable<string> SplitMessages(string rawValue)
		{
			return (from message in (rawValue ?? string.Empty).Split(new string[1] { "||" }, StringSplitOptions.None)
				select message.Trim() into message
				where !string.IsNullOrWhiteSpace(message)
				select message).Distinct<string>(StringComparer.Ordinal);
		}

		private void ReloadCoronerLanguage()
		{
			try
			{
				if ((Object)(object)Plugin.Instance == (Object)null)
				{
					((BaseUnityPlugin)this).Logger.LogWarning((object)"Coroner instance was not available; custom messages will apply next launch.");
					return;
				}
				Plugin.Instance.LoadLanguageHandlers();
				((BaseUnityPlugin)this).Logger.LogInfo((object)"Reloaded Coroner language handlers.");
			}
			catch (Exception ex) when (ex is IOException || ex is UnauthorizedAccessException || ex is SecurityException)
			{
				((BaseUnityPlugin)this).Logger.LogError((object)$"Failed to reload Coroner language handlers: {ex}");
			}
		}
	}
}