Decompiled source of ConfigurableProgressionMessages v2.0.0

plugins/ConfigurableProgressionMessages/ConfigurableProgressionMessages.dll

Decompiled 2 weeks ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using System.Text.RegularExpressions;
using BepInEx;
using BepInEx.Bootstrap;
using BepInEx.Configuration;
using BepInEx.Logging;
using CustomStringExtensions;
using Microsoft.CodeAnalysis;
using On.RoR2;
using RiskOfOptions;
using RiskOfOptions.OptionConfigs;
using RiskOfOptions.Options;
using RoR2;
using TMPro;

[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.0", FrameworkDisplayName = ".NET Standard 2.0")]
[assembly: AssemblyCompany("ConfigurableProgressionMessages")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0+b12bf494ef761e57638569d39397b602cb5b18e6")]
[assembly: AssemblyProduct("ConfigurableProgressionMessages")]
[assembly: AssemblyTitle("ConfigurableProgressionMessages")]
[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 CustomStringExtensions
{
	public static class CustomStringExtensions
	{
		public static bool ProgMsgIsMultiMsg(this string ProgMsg)
		{
			return Regex.Match(ProgMsg, "(?<!/)(EXTRAMSG:)").Success;
		}

		public static string CleanUpProgMsg(this string Msg)
		{
			Msg = Msg.Replace("/EXTRAMSG:", "EXTRAMSG:");
			Msg = Msg.Trim();
			return Msg;
		}
	}
}
namespace ConfigurableProgressionMessages
{
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	[BepInPlugin("LordVGames.ConfigurableProgressionMessages", "ConfigurableProgressionMessages", "1.1.0")]
	public class ConfigurableProgressionMessages : BaseUnityPlugin
	{
		public enum WhenToSendMsg
		{
			Never,
			OnFirstTime,
			OnEveryTime
		}

		public static class ModConfigEntries
		{
			public static ConfigEntry<string>[] Messages { get; set; } = new ConfigEntry<string>[8];


			public static ConfigEntry<int>[] SendOnStageX { get; set; } = new ConfigEntry<int>[8];


			public static ConfigEntry<int>[] SendAgainAfterXStages { get; set; } = new ConfigEntry<int>[8];


			public static ConfigEntry<WhenToSendMsg>[] SendOnLoopStart { get; set; } = new ConfigEntry<WhenToSendMsg>[8];


			public static ConfigEntry<WhenToSendMsg>[] SendOnBazaarVisit { get; set; } = new ConfigEntry<WhenToSendMsg>[8];


			public static ConfigEntry<WhenToSendMsg>[] SendOnVoidFieldsVisit { get; set; } = new ConfigEntry<WhenToSendMsg>[8];

		}

		public class ConfigEntryNames
		{
			public const string Message = "Message to send";

			public const string SendOnStageX = "Send On Stage X";

			public const string SendAgainAfterXStages = "Send Again After X Stages";

			public const string SendOnLoopStart = "Send On Loop Start";

			public const string SendOnBazaarVisit = "Send On Bazaar Visit";

			public const string SendOnVoidFieldsVisit = "Send On Void Fields Visit";
		}

		public const string DetailedMessageConfigDesc = "Leave blank for no message. If you want to include extra messages for the mod to randomly pick from put \"EXTRAMSG:\" before every message past the first one. If you really want to use \"EXTRAMSG:\" in a message, put a forward slash right before it.\nExample: \"my 1st message  EXTRAMSG: my 2nd message EXTRAMSG: my 3rd message with /EXTRAMSG:\"";

		public const string PluginName = "ConfigurableProgressionMessages";

		public const string PluginVersion = "1.1.0";

		public const string PluginAuthor = "LordVGames";

		public const string PluginGUID = "LordVGames.ConfigurableProgressionMessages";

		public const int ProgMsgsCount = 8;

		public const string MultiMsgRegex = "(?<!/)(EXTRAMSG:)";

		private string CurrentSceneName;

		private int PreviousLoopClearCount = 0;

		private int PreviousStageNum = 0;

		private bool HasVoidFieldsBeenVisited = false;

		private bool HasBazaarBeenVisited = false;

		private bool WasChatMsgSent = false;

		private int[] TempSendOnStageXValues = new int[8];

		public void Awake()
		{
			//IL_002d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0037: Expected O, but got Unknown
			//IL_003f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0049: Expected O, but got Unknown
			Log.Init(((BaseUnityPlugin)this).Logger);
			ReadConfig();
			Run.onRunStartGlobal += delegate
			{
				HasBazaarBeenVisited = false;
				HasVoidFieldsBeenVisited = false;
				PreviousStageNum = 0;
				PreviousLoopClearCount = 0;
				for (int j = 0; j < 8; j++)
				{
					TempSendOnStageXValues[j] = ModConfigEntries.SendOnStageX[j].Value;
				}
			};
			Run.OnServerSceneChanged += (hook_OnServerSceneChanged)delegate(orig_OnServerSceneChanged orig, Run self, string sceneName)
			{
				orig.Invoke(self, sceneName);
				CurrentSceneName = sceneName;
			};
			Stage.BeginServer += (hook_BeginServer)delegate(orig_BeginServer orig, Stage self)
			{
				orig.Invoke(self);
				int num = Run.instance.stageClearCount + 1;
				bool flag = false;
				if (num > PreviousStageNum)
				{
					flag = true;
					PreviousStageNum = num;
				}
				bool flag2 = false;
				if (Run.instance.loopClearCount > PreviousLoopClearCount)
				{
					flag2 = true;
					PreviousLoopClearCount = Run.instance.loopClearCount;
				}
				for (int i = 0; i < 8; i++)
				{
					WasChatMsgSent = false;
					if (flag && num == ModConfigEntries.SendOnStageX[i].Value)
					{
						SendProgMsg(i);
						ConfigEntry<int> obj = ModConfigEntries.SendOnStageX[i];
						obj.Value += ModConfigEntries.SendAgainAfterXStages[i].Value;
					}
					else
					{
						if (flag2)
						{
							switch (ModConfigEntries.SendOnLoopStart[i].Value)
							{
							case WhenToSendMsg.OnFirstTime:
								if (Run.instance.loopClearCount == 1)
								{
									SendProgMsg(i);
								}
								break;
							case WhenToSendMsg.OnEveryTime:
								SendProgMsg(i);
								break;
							}
							if (WasChatMsgSent)
							{
								continue;
							}
						}
						if (CurrentSceneName == "arena")
						{
							switch (ModConfigEntries.SendOnVoidFieldsVisit[i].Value)
							{
							case WhenToSendMsg.OnFirstTime:
								if (!HasVoidFieldsBeenVisited)
								{
									SendProgMsg(i);
									HasVoidFieldsBeenVisited = true;
								}
								break;
							case WhenToSendMsg.OnEveryTime:
								SendProgMsg(i);
								break;
							}
							if (!WasChatMsgSent)
							{
							}
						}
						else if (CurrentSceneName == "bazaar")
						{
							switch (ModConfigEntries.SendOnBazaarVisit[i].Value)
							{
							case WhenToSendMsg.OnFirstTime:
								if (!HasBazaarBeenVisited)
								{
									SendProgMsg(i);
									HasBazaarBeenVisited = true;
								}
								break;
							case WhenToSendMsg.OnEveryTime:
								SendProgMsg(i);
								break;
							}
						}
					}
				}
			};
			SetupSettingChangedEvents();
		}

		private void ReadConfig()
		{
			for (int i = 0; i < 8; i++)
			{
				string text = $"Progression Message #{i + 1}";
				string text2 = "";
				string text3 = "The message(s) that will be sent when the conditions are met. You can have no message or add extra messages in the same ways as the first message.";
				WhenToSendMsg whenToSendMsg = WhenToSendMsg.Never;
				if (i == 0)
				{
					text2 = "<size=125%><color=#005500>The planet is growing restless from your presence...</color></size>";
					text3 = "The message(s) that will be sent when the conditions are met. Leave blank for no message. If you want to include extra messages for the mod to randomly pick from put \"EXTRAMSG:\" before every message past the first one. If you really want to use \"EXTRAMSG:\" in a message, put a forward slash right before it.\nExample: \"my 1st message  EXTRAMSG: my 2nd message EXTRAMSG: my 3rd message with /EXTRAMSG:\"";
					whenToSendMsg = WhenToSendMsg.OnFirstTime;
				}
				ModConfigEntries.Messages[i] = ((BaseUnityPlugin)this).Config.Bind<string>(text, "Message to send", text2, text3);
				ModConfigEntries.SendOnStageX[i] = ((BaseUnityPlugin)this).Config.Bind<int>(text, "Send On Stage X", -1, "At the start of what stage should the message be sent? Set to -1 for no stage.");
				ModConfigEntries.SendAgainAfterXStages[i] = ((BaseUnityPlugin)this).Config.Bind<int>(text, "Send Again After X Stages", -1, "After how many stages should the message be sent again? Set to -1 to not send again. Does nothing if \"Send On Stage X\" is -1.");
				ModConfigEntries.SendOnLoopStart[i] = ((BaseUnityPlugin)this).Config.Bind<WhenToSendMsg>(text, "Send On Loop Start", whenToSendMsg, "Should the message be sent when a loop is started?");
				ModConfigEntries.SendOnBazaarVisit[i] = ((BaseUnityPlugin)this).Config.Bind<WhenToSendMsg>(text, "Send On Bazaar Visit", WhenToSendMsg.Never, "Should the message be sent when you visit the bazaar?");
				ModConfigEntries.SendOnVoidFieldsVisit[i] = ((BaseUnityPlugin)this).Config.Bind<WhenToSendMsg>(text, "Send On Void Fields Visit", WhenToSendMsg.Never, "Should the message be sent when you visit the void fields?");
			}
			if (RiskOfOptionsCompat.ModIsRunning)
			{
				RiskOfOptionsCompat.AddProgMsgsToRiskOfOptions();
			}
		}

		private void SetupSettingChangedEvents()
		{
			for (int i = 0; i < 8; i++)
			{
				int ic = i;
				ModConfigEntries.Messages[ic].SettingChanged += delegate
				{
					SendChangedProgMsgToClientChat(ModConfigEntries.Messages[ic].Value, ic);
				};
			}
		}

		private void SendChangedProgMsgToClientChat(string ProgMsg, int ProgMsgIndex)
		{
			if (ProgMsg.ProgMsgIsMultiMsg())
			{
				SendChatMsg($"<color=yellow>Progression Message #{ProgMsgIndex + 1} will randomly pick from these messages when it's sent:</color>", BroadcastToAll: false);
				{
					foreach (string item in GetMsgListFromMultiMsg(ProgMsg))
					{
						SendChatMsg(item.CleanUpProgMsg(), BroadcastToAll: false);
					}
					return;
				}
			}
			if (Utility.IsNullOrWhiteSpace(ProgMsg))
			{
				SendChatMsg($"<color=yellow>Progression Message #{ProgMsgIndex + 1} will not send any message.\nIt's best to set the message to never send instead.", BroadcastToAll: false);
				return;
			}
			SendChatMsg($"<color=yellow>Progression Message #{ProgMsgIndex + 1} is now:</color>", BroadcastToAll: false);
			SendChatMsg(ProgMsg.CleanUpProgMsg(), BroadcastToAll: false);
		}

		private void SendProgMsg(int ArrayNum)
		{
			WasChatMsgSent = true;
			string value = ModConfigEntries.Messages[ArrayNum].Value;
			string msgToSend;
			if (value.ProgMsgIsMultiMsg())
			{
				List<string> msgListFromMultiMsg = GetMsgListFromMultiMsg(value);
				Random random = new Random();
				int index = random.Next(0, msgListFromMultiMsg.Count - 1);
				msgToSend = msgListFromMultiMsg[index].CleanUpProgMsg();
			}
			else
			{
				msgToSend = value.CleanUpProgMsg();
			}
			SendChatMsg(msgToSend);
		}

		private List<string> GetMsgListFromMultiMsg(string MultiMsg)
		{
			List<string> list = Regex.Split(MultiMsg, "(?<!/)(EXTRAMSG:)").ToList();
			for (int num = list.Count - 1; num >= 0; num--)
			{
				if (list[num] == "EXTRAMSG:")
				{
					list.RemoveAt(num);
				}
			}
			return list;
		}

		private void SendChatMsg(string MsgToSend, bool BroadcastToAll = true)
		{
			//IL_0007: 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
			if (BroadcastToAll)
			{
				SimpleChatMessage val = new SimpleChatMessage
				{
					baseToken = MsgToSend
				};
				Chat.SendBroadcastChat((ChatMessageBase)(object)val);
			}
			else
			{
				Chat.AddMessage(MsgToSend);
			}
		}
	}
	internal static class Log
	{
		private static ManualLogSource _logSource;

		internal static void Init(ManualLogSource logSource)
		{
			_logSource = logSource;
		}

		internal static void Debug(object data)
		{
			_logSource.LogDebug(data);
		}

		internal static void Error(object data)
		{
			_logSource.LogError(data);
		}

		internal static void Fatal(object data)
		{
			_logSource.LogFatal(data);
		}

		internal static void Info(object data)
		{
			_logSource.LogInfo(data);
		}

		internal static void Message(object data)
		{
			_logSource.LogMessage(data);
		}

		internal static void Warning(object data)
		{
			_logSource.LogWarning(data);
		}
	}
	public static class RiskOfOptionsCompat
	{
		public const string PluginName = "com.rune580.riskofoptions";

		private static bool? _modexists;

		public static bool ModIsRunning
		{
			get
			{
				if (!_modexists.HasValue)
				{
					_modexists = Chainloader.PluginInfos.ContainsKey("com.rune580.riskofoptions");
				}
				return _modexists.Value;
			}
		}

		public static void AddProgMsgsToRiskOfOptions()
		{
			//IL_002e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0033: Unknown result type (might be due to invalid IL or missing references)
			//IL_003a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0045: Unknown result type (might be due to invalid IL or missing references)
			//IL_0062: Unknown result type (might be due to invalid IL or missing references)
			//IL_0069: Unknown result type (might be due to invalid IL or missing references)
			//IL_006b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0070: Unknown result type (might be due to invalid IL or missing references)
			//IL_0072: Unknown result type (might be due to invalid IL or missing references)
			//IL_007c: Expected O, but got Unknown
			//IL_0077: Unknown result type (might be due to invalid IL or missing references)
			//IL_0081: Expected O, but got Unknown
			//IL_0089: Unknown result type (might be due to invalid IL or missing references)
			//IL_008e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0095: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bf: Expected O, but got Unknown
			//IL_00c5: Expected O, but got Unknown
			//IL_00c0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ca: Expected O, but got Unknown
			//IL_00d2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00de: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e9: Unknown result type (might be due to invalid IL or missing references)
			//IL_0101: Unknown result type (might be due to invalid IL or missing references)
			//IL_0108: Expected O, but got Unknown
			//IL_010e: Expected O, but got Unknown
			//IL_0109: Unknown result type (might be due to invalid IL or missing references)
			//IL_0113: Expected O, but got Unknown
			//IL_011b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0120: Unknown result type (might be due to invalid IL or missing references)
			//IL_0127: Unknown result type (might be due to invalid IL or missing references)
			//IL_0132: Unknown result type (might be due to invalid IL or missing references)
			//IL_0142: Expected O, but got Unknown
			//IL_013d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0147: Expected O, but got Unknown
			//IL_014f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0154: Unknown result type (might be due to invalid IL or missing references)
			//IL_015b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0166: Unknown result type (might be due to invalid IL or missing references)
			//IL_0176: Expected O, but got Unknown
			//IL_0171: Unknown result type (might be due to invalid IL or missing references)
			//IL_017b: Expected O, but got Unknown
			//IL_0183: Unknown result type (might be due to invalid IL or missing references)
			//IL_0188: Unknown result type (might be due to invalid IL or missing references)
			//IL_018f: Unknown result type (might be due to invalid IL or missing references)
			//IL_019a: Unknown result type (might be due to invalid IL or missing references)
			//IL_01aa: Expected O, but got Unknown
			//IL_01a5: Unknown result type (might be due to invalid IL or missing references)
			//IL_01af: Expected O, but got Unknown
			ModSettingsManager.SetModDescription("Adds some chat messages that you can configure the contents of, along with when they appear in your runs.");
			for (int i = 0; i < 8; i++)
			{
				string category = $"Message #{i + 1}";
				ModSettingsManager.AddOption((BaseOption)new StringInputFieldOption(ConfigurableProgressionMessages.ModConfigEntries.Messages[i], new InputFieldConfig
				{
					category = category,
					name = "Message to send",
					description = string.Format("The message(s) for Progression Message #{0}.\n{1}", i + 1, "Leave blank for no message. If you want to include extra messages for the mod to randomly pick from put \"EXTRAMSG:\" before every message past the first one. If you really want to use \"EXTRAMSG:\" in a message, put a forward slash right before it.\nExample: \"my 1st message  EXTRAMSG: my 2nd message EXTRAMSG: my 3rd message with /EXTRAMSG:\""),
					richText = false,
					lineType = (LineType)2,
					submitOn = (SubmitEnum)4
				}));
				ConfigEntry<int> obj = ConfigurableProgressionMessages.ModConfigEntries.SendOnStageX[i];
				IntFieldConfig val = new IntFieldConfig
				{
					category = category,
					name = "Send On Stage X",
					description = $"The stage number that Progression Message #{i + 1} will be sent at the start of. Set to -1 for no stage."
				};
				((NumericFieldConfig<int>)val).Min = -1;
				ModSettingsManager.AddOption((BaseOption)new IntFieldOption(obj, val));
				ConfigEntry<int> obj2 = ConfigurableProgressionMessages.ModConfigEntries.SendAgainAfterXStages[i];
				IntFieldConfig val2 = new IntFieldConfig
				{
					category = category,
					name = "Send Again After X Stages",
					description = $"The amount of stages to wait before Progression Message #{i + 1} will be sent again. Set to -1 for no stage."
				};
				((NumericFieldConfig<int>)val2).Min = -1;
				ModSettingsManager.AddOption((BaseOption)new IntFieldOption(obj2, val2));
				ModSettingsManager.AddOption((BaseOption)new ChoiceOption((ConfigEntryBase)(object)ConfigurableProgressionMessages.ModConfigEntries.SendOnLoopStart[i], new ChoiceConfig
				{
					category = category,
					name = "Send On Loop Start",
					description = "Whether to send the message at the start of your first loop, at the start of every loop, or never."
				}));
				ModSettingsManager.AddOption((BaseOption)new ChoiceOption((ConfigEntryBase)(object)ConfigurableProgressionMessages.ModConfigEntries.SendOnBazaarVisit[i], new ChoiceConfig
				{
					category = category,
					name = "Send On Bazaar Visit",
					description = "Whether to send the message on your first visit to the Bazaar, on every visit, or never."
				}));
				ModSettingsManager.AddOption((BaseOption)new ChoiceOption((ConfigEntryBase)(object)ConfigurableProgressionMessages.ModConfigEntries.SendOnVoidFieldsVisit[i], new ChoiceConfig
				{
					category = category,
					name = "Send On Void Fields Visit",
					description = "Whether to send the message on your first visit to the Void Fields, on every visit, or never."
				}));
			}
		}
	}
}
namespace R2API.Utils
{
	[AttributeUsage(AttributeTargets.Assembly)]
	public class ManualNetworkRegistrationAttribute : Attribute
	{
	}
}