Decompiled source of RandomDeathMessages v1.0.0

RandomDeathMessages.dll

Decompiled 4 months ago
using System;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using GameNetcodeStuff;
using HarmonyLib;
using TMPro;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: AssemblyTitle("RandomDeathMessages")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("RandomDeathMessages")]
[assembly: AssemblyCopyright("Copyright ©  2024")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("90054e45-91ad-49c8-ae72-8d699a919566")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")]
[assembly: AssemblyVersion("1.0.0.0")]
namespace RandomDeathMessages;

[BepInPlugin("ironbean.RandomizedDeathMessages", "RandomizedDeathMessages", "1.0.0")]
public class DeathMessageMod : BaseUnityPlugin
{
	[HarmonyPatch(typeof(PlayerControllerB))]
	internal class MessageReplacePatch
	{
		[HarmonyPatch("KillPlayer")]
		[HarmonyPrefix]
		private static void CreatePatch()
		{
			GameObject val = GameObject.Find("Systems/UI/Canvas/DeathScreen/GameOverText");
			TextMeshProUGUI component = val.GetComponent<TextMeshProUGUI>();
			string[] array = configMessages.Value.Split(new char[1] { ';' });
			if ((Object)(object)val != (Object)null)
			{
				((TMP_Text)component).text = array[rand.Next(0, array.Length)];
			}
		}
	}

	private const string modGUID = "ironbean.RandomizedDeathMessages";

	private const string modName = "RandomizedDeathMessages";

	private const string modVersion = "1.0.0";

	private readonly Harmony harmony = new Harmony("ironbean.RandomizedDeathMessages");

	private static DeathMessageMod Instance;

	private static ConfigEntry<string> configMessages;

	internal static ManualLogSource mls;

	private static Random rand = new Random();

	private void Awake()
	{
		if ((Object)(object)Instance == (Object)null)
		{
			Instance = this;
		}
		mls = Logger.CreateLogSource("ironbean.RandomizedDeathMessages");
		configMessages = ((BaseUnityPlugin)this).Config.Bind<string>("General", "DeathMessages", "[LIFE SUPPORT: OFFLINE]", "List of custom death messages. Separate the different messages with the ; character.");
		mls.LogInfo((object)("Loaded " + configMessages.Value.Split(new char[1] { ';' }).Length + " death messages!"));
		if (configMessages.Value == "")
		{
			configMessages.Value = "[LIFE SUPPORT: OFFLINE]";
		}
		harmony.PatchAll(typeof(DeathMessageMod));
		harmony.PatchAll(typeof(MessageReplacePatch));
	}
}