Decompiled source of UnstableJester v1.1.0

UnstableJester.dll

Decompiled 11 months ago
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Reflection;
using System.Reflection.Emit;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using HarmonyLib;
using UnstableJester.Patches;

[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.1", FrameworkDisplayName = "")]
[assembly: AssemblyCompany("UnstableJester")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyDescription("Gives the jester a 5 second safe period when winding but after that, it can go at any time!")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("UnstableJester")]
[assembly: AssemblyTitle("UnstableJester")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
[module: UnverifiableCode]
namespace UnstableJester
{
	[BepInPlugin("UnstableJester", "UnstableJester", "1.0.0")]
	public class Plugin : BaseUnityPlugin
	{
		private bool _patched;

		public static ConfigEntry<float> popMin;

		public static ConfigEntry<float> popMax;

		public static ManualLogSource Log { get; set; }

		private void Awake()
		{
			if (_patched)
			{
				Log.LogWarning((object)"Already Patched");
				return;
			}
			popMin = ((BaseUnityPlugin)this).Config.Bind<float>("General", "popMin", 5f, "The minimum time it takes for the jester to pop");
			popMax = ((BaseUnityPlugin)this).Config.Bind<float>("General", "popMax", 10f, "The maximum time it takes for the jester to pop (Must be above min, going above 40s may cause audio issues)");
			Log = ((BaseUnityPlugin)this).Logger;
			Harmony.CreateAndPatchAll(typeof(JesterPatch), "UnstableJester");
			((BaseUnityPlugin)this).Logger.LogInfo((object)"Plugin UnstableJester is loaded!");
			_patched = true;
		}
	}
	public static class PluginInfo
	{
		public const string PLUGIN_GUID = "UnstableJester";

		public const string PLUGIN_NAME = "UnstableJester";

		public const string PLUGIN_VERSION = "1.0.0";
	}
}
namespace UnstableJester.Patches
{
	internal class JesterPatch
	{
		[HarmonyPatch(typeof(JesterAI), "SetJesterInitialValues")]
		[HarmonyTranspiler]
		private static IEnumerable<CodeInstruction> UnstablePatch(IEnumerable<CodeInstruction> instructions)
		{
			//IL_00a0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00aa: Expected O, but got Unknown
			//IL_00c3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cd: Expected O, but got Unknown
			List<CodeInstruction> list = instructions.ToList();
			for (int i = 0; i < list.Count - 1; i++)
			{
				if (list[i].opcode == OpCodes.Ldc_R4 && (float)list[i].operand == 35f)
				{
					Plugin.Log.LogInfo((object)"Patching Jester's values...");
					if (Plugin.popMin.Value >= 0f && Plugin.popMin.Value < Plugin.popMax.Value)
					{
						list[i] = new CodeInstruction(OpCodes.Ldc_R4, (object)Plugin.popMin.Value);
						list[i + 1] = new CodeInstruction(OpCodes.Ldc_R4, (object)Plugin.popMax.Value);
						Plugin.Log.LogInfo((object)"Patched!");
						break;
					}
					Plugin.Log.LogError((object)"Unable to patch, values are incorrect!");
				}
			}
			return list;
		}
	}
}