Decompiled source of ConfigurableProgressionMessages v2.1.0

plugins/ConfigurableProgressionMessages/ConfigurableProgressionMessages.dll

Decompiled 4 months 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.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;
using UnityEngine;

[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+5ee9888c976ab80749f4541c589f68a82af6ed9a")]
[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 IsMultiMsg(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 R2API.Utils
{
	[AttributeUsage(AttributeTargets.Assembly)]
	public class ManualNetworkRegistrationAttribute : Attribute
	{
	}
}
namespace ConfigurableProgressionMessages
{
	public static class Assets
	{
		public static AssetBundle ModIconAssetBundle;

		public const string BundleName = "modicon";

		public static string AssetBundlePath => Path.Combine(Path.GetDirectoryName(ConfigurableProgressionMessages.PInfo.Location), "modicon");

		public static void Init()
		{
			ModIconAssetBundle = AssetBundle.LoadFromFile(AssetBundlePath);
		}
	}
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	[BepInPlugin("LordVGames.ConfigurableProgressionMessages", "ConfigurableProgressionMessages", "2.1.0")]
	public class ConfigurableProgressionMessages : BaseUnityPlugin
	{
		public enum WhenToSendMsg
		{
			Never,
			OnFirstTime,
			OnEveryTime
		}

		public static class ModConfigEntries
		{
			public static ConfigEntry<bool> DebugLogging { get; set; }

			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 DebugLogging = "Enable debug logging";

			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 PluginName = "ConfigurableProgressionMessages";

		public const string PluginVersion = "2.1.0";

		public const string PluginAuthor = "LordVGames";

		public const string PluginGUID = "LordVGames.ConfigurableProgressionMessages";

		internal 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:\"";

		internal const int progMsgsCount = 8;

		internal 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 static PluginInfo PInfo { get; private set; }

		public void Awake()
		{
			//IL_0046: Unknown result type (might be due to invalid IL or missing references)
			//IL_0050: Expected O, but got Unknown
			//IL_0058: Unknown result type (might be due to invalid IL or missing references)
			//IL_0062: Expected O, but got Unknown
			PInfo = ((BaseUnityPlugin)this).Info;
			Log.Init(((BaseUnityPlugin)this).Logger);
			Assets.Init();
			ReadConfig();
			SetupSettingChangedEvents();
			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;
				bool flag2 = false;
				if (num > _previousStageNum)
				{
					flag = true;
					_previousStageNum = num;
				}
				if (Run.instance.loopClearCount > _previousLoopClearCount)
				{
					flag2 = true;
					_previousLoopClearCount = Run.instance.loopClearCount;
				}
				if (ModConfigEntries.DebugLogging.Value)
				{
					Log.Debug("Current scene name is \"" + _currentSceneName + "\". \"arena\" is the Void Fields, \"bazaar\" is the Bazaar");
					Log.Debug($"Did a loop start this stage? {flag2}");
					Log.Debug($"Current stage number is {num}");
					Log.Debug($"Did the stage number changes from last stage? {flag}");
				}
				for (int i = 0; i < 8; i++)
				{
					_wasChatMsgSent = false;
					if (flag && num == _tempSendOnStageXValues[i])
					{
						SendProgMsg(i);
						if (ModConfigEntries.SendAgainAfterXStages[i].Value > 0)
						{
							_tempSendOnStageXValues[i] += ModConfigEntries.SendAgainAfterXStages[i].Value;
							if (ModConfigEntries.DebugLogging.Value)
							{
								Log.Debug($"Message #{i + 1} will send again on stage {_tempSendOnStageXValues[i]}, {ModConfigEntries.SendAgainAfterXStages[i].Value} stages after the current one.");
							}
						}
					}
					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;
							}
						}
					}
				}
			};
		}

		private void ReadConfig()
		{
			ModConfigEntries.DebugLogging = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "Enable debug logging", false, "Only useful if you're trying to figure out a problem either with your messages or the mod itself.");
			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 ir = i;
				ModConfigEntries.Messages[ir].SettingChanged += delegate
				{
					SendChangedProgMsgToClientChat(ModConfigEntries.Messages[ir].Value, ir);
				};
			}
		}

		private void SendChangedProgMsgToClientChat(string progMsg, int progMsgIndex)
		{
			if (progMsg.IsMultiMsg())
			{
				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.IsMultiMsg())
			{
				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_0043: Unknown result type (might be due to invalid IL or missing references)
			//IL_0048: Unknown result type (might be due to invalid IL or missing references)
			//IL_004f: Unknown result type (might be due to invalid IL or missing references)
			//IL_005a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0077: Unknown result type (might be due to invalid IL or missing references)
			//IL_007e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0080: Unknown result type (might be due to invalid IL or missing references)
			//IL_0085: Unknown result type (might be due to invalid IL or missing references)
			//IL_0087: Unknown result type (might be due to invalid IL or missing references)
			//IL_0091: Expected O, but got Unknown
			//IL_008c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0096: Expected O, but got Unknown
			//IL_009e: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00aa: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cd: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d4: Expected O, but got Unknown
			//IL_00da: Expected O, but got Unknown
			//IL_00d5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00df: Expected O, but got Unknown
			//IL_00e7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ec: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fe: Unknown result type (might be due to invalid IL or missing references)
			//IL_0116: Unknown result type (might be due to invalid IL or missing references)
			//IL_011d: Expected O, but got Unknown
			//IL_0123: Expected O, but got Unknown
			//IL_011e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0128: Expected O, but got Unknown
			//IL_0130: Unknown result type (might be due to invalid IL or missing references)
			//IL_0135: Unknown result type (might be due to invalid IL or missing references)
			//IL_013c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0147: Unknown result type (might be due to invalid IL or missing references)
			//IL_0157: Expected O, but got Unknown
			//IL_0152: Unknown result type (might be due to invalid IL or missing references)
			//IL_015c: Expected O, but got Unknown
			//IL_0164: Unknown result type (might be due to invalid IL or missing references)
			//IL_0169: Unknown result type (might be due to invalid IL or missing references)
			//IL_0170: Unknown result type (might be due to invalid IL or missing references)
			//IL_017b: Unknown result type (might be due to invalid IL or missing references)
			//IL_018b: Expected O, but got Unknown
			//IL_0186: Unknown result type (might be due to invalid IL or missing references)
			//IL_0190: Expected O, but got Unknown
			//IL_0198: Unknown result type (might be due to invalid IL or missing references)
			//IL_019d: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a4: Unknown result type (might be due to invalid IL or missing references)
			//IL_01af: Unknown result type (might be due to invalid IL or missing references)
			//IL_01bf: Expected O, but got Unknown
			//IL_01ba: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c4: Expected O, but got Unknown
			ModSettingsManager.SetModIcon(Assets.ModIconAssetBundle.LoadAsset<Sprite>("icon.png"));
			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."
				}));
			}
		}
	}
}