Decompiled source of Custom Death Messages v1.0.1

CustomDeathMessages.dll

Decompiled a week ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Logging;
using Events;
using Events.ClientToAllClients;
using Events.Local;
using HarmonyLib;
using JsonFx.Json;
using JsonFx.Model;
using JsonFx.Serialization;
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("CustomDeathMessages")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("CustomDeathMessages")]
[assembly: AssemblyCopyright("Copyright ©  2025")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("abecaea3-a747-4065-b6b0-f25a870e0e58")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
[module: UnverifiableCode]
public static class ClientPlayerInfoExtensions
{
	public static string GetChatName(this ClientPlayerInfo playerInfo, bool closeColorTag)
	{
		return ClientPlayerInfo.GetColorPrefix(playerInfo.index_) + playerInfo.username_ + (closeColorTag ? "[-]" : string.Empty);
	}
}
namespace CustomDeathMessages
{
	public static class Message
	{
		internal const string ResetFormatting = "[-][-][-][-][-]";

		internal static readonly List<KeyValuePair<string, MessageType>> MessageDictionary = new List<KeyValuePair<string, MessageType>>
		{
			new KeyValuePair<string, MessageType>("was terminated by the laser grid", MessageType.KillGrid),
			new KeyValuePair<string, MessageType>("reset", MessageType.SelfTermination),
			new KeyValuePair<string, MessageType>("was wrecked after getting split", MessageType.LaserOverheated),
			new KeyValuePair<string, MessageType>("got wrecked?", MessageType.AntiTunnelSquish),
			new KeyValuePair<string, MessageType>("got wrecked", MessageType.Impact),
			new KeyValuePair<string, MessageType>("exploded from overheating", MessageType.Overheated),
			new KeyValuePair<string, MessageType>("multiplier!", MessageType.KillGrid),
			new KeyValuePair<string, MessageType>("was kicked due to not having this level", MessageType.KickNoLevel),
			new KeyValuePair<string, MessageType>("finished", MessageType.Finished),
			new KeyValuePair<string, MessageType>("is not ready", MessageType.NotReady),
			new KeyValuePair<string, MessageType>("left the match to spectate", MessageType.Spectate),
			new KeyValuePair<string, MessageType>("has taken the lead!", MessageType.TagPointsLead)
		};

		public static MessageType GetMessageType(string message)
		{
			foreach (KeyValuePair<string, MessageType> item in MessageDictionary)
			{
				if (message.IndexOf(item.Key, StringComparison.InvariantCultureIgnoreCase) >= 0)
				{
					return item.Value;
				}
			}
			return MessageType.None;
		}

		public static int GetStuntMultiplier(string message)
		{
			int.TryParse(message.Substring(14), out var result);
			return result;
		}

		public static string GetMessage(string message, string username, string formattedName)
		{
			//IL_0070: Unknown result type (might be due to invalid IL or missing references)
			MessageType messageType = GetMessageType(message);
			int num = 0;
			if (messageType == MessageType.StuntCollect)
			{
				num = GetStuntMultiplier(message);
			}
			Mod.Instance.MessagesDictionary.TryGetValue(messageType.ToString(), out var value);
			if (messageType == MessageType.None || ArrayEx.IsNullOrEmpty<string>(value))
			{
				return username + " " + message;
			}
			return NGUIEx.Colorize(string.Format(ArrayEx.RandomElement<string>(value), formattedName, num, username), Colors.tan);
		}

		public static void Send(string message)
		{
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			StaticTransceivedEvent<Data>.Broadcast(new Data(message));
		}
	}
	[Flags]
	public enum MessageType : uint
	{
		None = 0u,
		KillGrid = 1u,
		SelfTermination = 2u,
		LaserOverheated = 3u,
		Impact = 4u,
		Overheated = 5u,
		AntiTunnelSquish = 6u,
		StuntCollect = 7u,
		KickNoLevel = 8u,
		Finished = 9u,
		NotReady = 0xAu,
		Spectate = 0xBu,
		TagPointsLead = 0xCu
	}
	[BepInPlugin("Distance.CustomDeathMessages", "Custom Death Messages", "1.0.1")]
	public sealed class Mod : BaseUnityPlugin
	{
		private const string modGUID = "Distance.CustomDeathMessages";

		private const string modName = "Custom Death Messages";

		private const string modVersion = "1.0.1";

		public Dictionary<string, string[]> MessagesDictionary = new Dictionary<string, string[]>();

		private static readonly Harmony harmony = new Harmony("Distance.CustomDeathMessages");

		public static ManualLogSource Log = new ManualLogSource("Custom Death Messages");

		public static Mod Instance;

		private void Awake()
		{
			if ((Object)(object)Instance == (Object)null)
			{
				Instance = this;
			}
			Log = Logger.CreateLogSource("Distance.CustomDeathMessages");
			((BaseUnityPlugin)this).Logger.LogInfo((object)"Thanks for using Custom Death Messages");
			LoadMessages();
			((BaseUnityPlugin)this).Logger.LogInfo((object)"Loading...");
			harmony.PatchAll();
			((BaseUnityPlugin)this).Logger.LogInfo((object)"Loaded!");
		}

		private void SaveMessages()
		{
			//IL_0017: Unknown result type (might be due to invalid IL or missing references)
			//IL_001c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0025: Expected O, but got Unknown
			//IL_0026: Unknown result type (might be due to invalid IL or missing references)
			//IL_002c: Expected O, but got Unknown
			string path = "CustomDeathMessages.json";
			string directoryName = Path.GetDirectoryName(Assembly.GetCallingAssembly().Location);
			DataWriterSettings val = new DataWriterSettings
			{
				PrettyPrint = true
			};
			JsonWriter val2 = new JsonWriter(val);
			try
			{
				using StreamWriter streamWriter = new StreamWriter(Path.Combine(directoryName, path), append: false);
				streamWriter.WriteLine(((DataWriter<ModelTokenType>)(object)val2).Write((object)MessagesDictionary));
			}
			catch (Exception ex)
			{
				Log.LogWarning((object)ex);
			}
		}

		private void LoadMessages()
		{
			//IL_0039: Unknown result type (might be due to invalid IL or missing references)
			//IL_0040: Expected O, but got Unknown
			string directoryName = Path.GetDirectoryName(Assembly.GetCallingAssembly().Location);
			string path = Path.Combine(directoryName, "CustomDeathMessages.json");
			if (File.Exists(path))
			{
				try
				{
					using StreamReader streamReader = new StreamReader(path);
					string text = streamReader.ReadToEnd();
					JsonReader val = new JsonReader();
					Dictionary<string, string[]> messagesDictionary = ((DataReader<ModelTokenType>)(object)val).Read<Dictionary<string, string[]>>(text);
					MessagesDictionary = messagesDictionary;
					return;
				}
				catch (Exception ex)
				{
					Log.LogWarning((object)"Failed to load custom death messages. Using Defaults");
					Log.LogWarning((object)ex);
					MessagesDictionary.Clear();
					AddDefaultsToDicationary();
					return;
				}
			}
			Log.LogWarning((object)"CustomDeathMessages.json doesn't exist. Using Defaults, generating a new file");
			AddDefaultsToDicationary();
			SaveMessages();
		}

		private void AddDefaultsToDicationary()
		{
			string[] value = new string[2] { "The laser grid was not cool with {0}", "{0} have touched the forbiden grid" };
			MessagesDictionary.Add("KillGrid", value);
			string[] value2 = new string[2] { "{0} pressed the reset button", "{0} commited sudoku" };
			MessagesDictionary.Add("SelfTermination", value2);
			string[] value3 = new string[2] { "{0} don't know how to drive without wheels", "{0} was too hot" };
			MessagesDictionary.Add("LaserOverheated", value3);
			string[] value4 = new string[2] { "{0} kissed a wall", "The ground facepalmed {0}" };
			MessagesDictionary.Add("Impact", value4);
			string[] value5 = new string[1] { "{0} needs to stop boosting sometimes" };
			MessagesDictionary.Add("Overheated", value5);
			string[] value6 = new string[1] { "{0} got unitied" };
			MessagesDictionary.Add("AntiTunnelSquish", value6);
			string[] value7 = new string[1] { "{0} looted a x{1} multiplier!" };
			MessagesDictionary.Add("StuntCollect", value7);
			string[] value8 = new string[2] { "{0} is too poor to have this level", "[FF0000]{0} is sad because he can't load the level[-]" };
			MessagesDictionary.Add("KickNoLevel", value8);
			string[] value9 = new string[1] { "[FFFFFF]{0}[-] [00FF00]f[-][00FFFF]i[-][0000FF]n[-][FF00FF]i[-][FF0000]s[-][FFFF00]h[-][00FF00]e[-][00FFFF]d[-]" };
			MessagesDictionary.Add("Finished", value9);
			string[] value10 = new string[1] { "{0} is a little busy, try again later" };
			MessagesDictionary.Add("NotReady", value10);
			string[] value11 = new string[1] { "[-]This map is too hard, {0} gave up" };
			MessagesDictionary.Add("Spectate", value11);
			string[] value12 = new string[1] { "[FFFFFF]{0}[-] is [00FF00]f[-][00FFFF]a[-][0000FF]b[-][FF00FF]u[-][FF0000]l[-][FFFF00]o[-][00FF00]u[-][00FFFF]s[-]!" };
			MessagesDictionary.Add("TagPointsLead", value12);
		}
	}
}
namespace CustomDeathMessages.Patches
{
	[HarmonyPatch(typeof(ClientLogic), "OnEventPlayerActionMessage")]
	internal static class ClientLogic__OnEventPlayerActionMessage
	{
		[HarmonyPrefix]
		internal static bool Prefix(ClientLogic __instance, Data data)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			string message_ = data.message_;
			string username_ = __instance.GetLocalPlayerInfo().username_;
			string chatName = __instance.GetLocalPlayerInfo().GetChatName(closeColorTag: true);
			string message = Message.GetMessage(message_, username_, chatName);
			Message.Send(message);
			return false;
		}
	}
	[HarmonyPatch(typeof(ClientLogic), "OnEventToAllClientsRemotePlayerActionMessage")]
	internal static class ClientLogic__OnEventToAllClientsRemotePlayerActionMessage
	{
		[HarmonyPrefix]
		internal static bool Prefix(ClientLogic __instance, Data data)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_000e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0025: Unknown result type (might be due to invalid IL or missing references)
			string message_ = data.message_;
			string username_ = __instance.ClientPlayerList_[data.index_].username_;
			string chatName = __instance.ClientPlayerList_[data.index_].GetChatName(closeColorTag: true);
			string message = Message.GetMessage(message_, username_, chatName);
			Message.Send(message);
			return false;
		}
	}
}