Decompiled source of MO Manager v1.1.0

MOManager.dll

Decompiled a month ago
using System;
using System.Diagnostics;
using System.Globalization;
using System.IO;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Core.Logging.Interpolation;
using BepInEx.Logging;
using BepInEx.Unity.IL2CPP;
using HarmonyLib;
using Il2CppInterop.Runtime;
using Il2CppSystem.Collections.Generic;
using Microsoft.CodeAnalysis;
using UnityEngine;
using UniverseLib;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: TargetFramework(".NETCoreApp,Version=v6.0", FrameworkDisplayName = ".NET 6.0")]
[assembly: AssemblyCompany("MOManager")]
[assembly: AssemblyConfiguration("IL2CPP")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0+bd715abf0d69684914fc5d422cef3e39ca0c63bc")]
[assembly: AssemblyProduct("MOManager")]
[assembly: AssemblyTitle("MOManager")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
[module: UnverifiableCode]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[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 MOManager
{
	[BepInPlugin("MOManager", "MOManager", "1.0.0")]
	public class MOManagerPlugin : BasePlugin
	{
		[HarmonyPatch(typeof(Toolbox), "Start")]
		public class Toolbox_Start
		{
			public static void Postfix()
			{
				//IL_0159: Unknown result type (might be due to invalid IL or missing references)
				//IL_0165: 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_01b0: Unknown result type (might be due to invalid IL or missing references)
				Enumerator<string, ScriptableObject> enumerator = Toolbox.Instance.resourcesCache[Il2CppType.Of<MurderPreset>()].Values.GetEnumerator();
				while (enumerator.MoveNext())
				{
					ScriptableObject current = enumerator.Current;
					MurderPreset val = ReflectionExtensions.TryCast<MurderPreset>((object)current);
					if (!string.IsNullOrEmpty(((SoCustomComparison)val).presetName) && !(((SoCustomComparison)val).presetName == "Hitman"))
					{
						int value = ConfigFile.Bind<int>("MurderPreset", "Frequency " + ((SoCustomComparison)val).presetName.Trim() + ".", val.frequency, PresetDescription(val.frequency)).Value;
						if (value <= 0)
						{
							val.disabled = true;
						}
						else
						{
							val.frequency = value;
						}
					}
				}
				Enumerator<string, ScriptableObject> enumerator2 = Toolbox.Instance.resourcesCache[Il2CppType.Of<MurderMO>()].Values.GetEnumerator();
				while (enumerator2.MoveNext())
				{
					ScriptableObject current2 = enumerator2.Current;
					MurderMO val2 = ReflectionExtensions.TryCast<MurderMO>((object)current2);
					if (!string.IsNullOrEmpty(((SoCustomComparison)val2).presetName) && !(((SoCustomComparison)val2).presetName == "Hitman"))
					{
						float value2 = ConfigFile.Bind<float>("MurderMO", "Maximum base score for " + ((SoCustomComparison)val2).presetName.Trim() + ".", val2.pickRandomScoreRange.y, MODescription(val2.pickRandomScoreRange.y)).Value;
						if (value2 <= 0f)
						{
							val2.disabled = true;
						}
						else
						{
							val2.pickRandomScoreRange = new Vector2(val2.pickRandomScoreRange.x, value2);
						}
					}
				}
			}
		}

		public static ConfigEntry<bool> Enabled;

		public static ManualLogSource PluginLogger;

		public static ConfigFile ConfigFile;

		public override void Load()
		{
			//IL_0080: Unknown result type (might be due to invalid IL or missing references)
			//IL_0086: Expected O, but got Unknown
			//IL_00bb: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c1: Expected O, but got Unknown
			//IL_00d4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00da: Expected O, but got Unknown
			PluginLogger = ((BasePlugin)this).Log;
			ConfigFile = ((BasePlugin)this).Config;
			((BasePlugin)this).Config.SaveOnConfigSet = false;
			Enabled = ((BasePlugin)this).Config.Bind<bool>("General", "Enabled", true, "Is the mod enabled at all? (Game restart required after changing any settings at all)");
			PreBindSavedEntries();
			((BasePlugin)this).Config.SaveOnConfigSet = true;
			((BasePlugin)this).Config.Save();
			if (Enabled.Value)
			{
				ManualLogSource pluginLogger = PluginLogger;
				bool flag = default(bool);
				BepInExInfoLogInterpolatedStringHandler val = new BepInExInfoLogInterpolatedStringHandler(18, 1, ref flag);
				if (flag)
				{
					((BepInExLogInterpolatedStringHandler)val).AppendLiteral("Plugin ");
					((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>("MOManager");
					((BepInExLogInterpolatedStringHandler)val).AppendLiteral(" is loaded!");
				}
				pluginLogger.LogInfo(val);
				Harmony val2 = new Harmony("MOManager");
				val2.PatchAll();
				ManualLogSource pluginLogger2 = PluginLogger;
				val = new BepInExInfoLogInterpolatedStringHandler(19, 1, ref flag);
				if (flag)
				{
					((BepInExLogInterpolatedStringHandler)val).AppendLiteral("Plugin ");
					((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>("MOManager");
					((BepInExLogInterpolatedStringHandler)val).AppendLiteral(" is patched!");
				}
				pluginLogger2.LogInfo(val);
			}
		}

		private static string PresetDescription(int defaultFrequency)
		{
			return $"The frequency for this Preset. This preset is added to the pool this many times, and then a preset is selected from the pool at random. Default is {defaultFrequency}, -1 to disable outright.";
		}

		private static string MODescription(float defaultScore)
		{
			return $"The maximum base score for this MO. The higher, the more likely this MO is to be picked. Default is {defaultScore}, -1 to disable outright.";
		}

		private static void PreBindSavedEntries()
		{
			if (!File.Exists(ConfigFile.ConfigFilePath))
			{
				return;
			}
			string text = null;
			string s = null;
			foreach (string item in File.ReadLines(ConfigFile.ConfigFilePath))
			{
				if (item.StartsWith("["))
				{
					text = item.Trim('[', ']');
				}
				else if (item.StartsWith("# Default value: "))
				{
					s = item.Substring("# Default value: ".Length);
				}
				else if (!item.StartsWith("#") && item.Contains('='))
				{
					string text2 = item.Substring(0, item.IndexOf('=')).Trim();
					float result2;
					if (text == "MurderPreset" && int.TryParse(s, NumberStyles.Integer, CultureInfo.InvariantCulture, out var result))
					{
						ConfigFile.Bind<int>(text, text2, result, PresetDescription(result));
					}
					else if (text == "MurderMO" && float.TryParse(s, NumberStyles.Float, CultureInfo.InvariantCulture, out result2))
					{
						ConfigFile.Bind<float>(text, text2, result2, MODescription(result2));
					}
					s = null;
				}
			}
		}
	}
	public static class MyPluginInfo
	{
		public const string PLUGIN_GUID = "MOManager";

		public const string PLUGIN_NAME = "MOManager";

		public const string PLUGIN_VERSION = "1.0.0";
	}
}