Decompiled source of ScoutGemPetrifyConfig v1.1.4

ScoutGemPetrifyConfig.dll

Decompiled 2 months ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
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.Logging;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using Peak;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("ScoutGemPetrifyConfig")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyDescription("Configurable scout gem petrify penalties for PEAK")]
[assembly: AssemblyFileVersion("1.1.0.0")]
[assembly: AssemblyInformationalVersion("1.1.0")]
[assembly: AssemblyProduct("ScoutGemPetrifyConfig")]
[assembly: AssemblyTitle("ScoutGemPetrifyConfig")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.1.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 PeakNoPetrifyMod
{
	[BepInPlugin("com.modder.peak.scoutgempetrifyconfig", "ScoutGemPetrifyConfig", "2.0.0")]
	[BepInProcess("PEAK.exe")]
	public class NoPetrifyGemsPlugin : BaseUnityPlugin
	{
		public const string PLUGIN_GUID = "com.modder.peak.scoutgempetrifyconfig";

		public const string PLUGIN_NAME = "ScoutGemPetrifyConfig";

		public const string PLUGIN_VERSION = "2.0.0";

		internal static ManualLogSource LogSource;

		private Harmony _harmony;

		public static ConfigEntry<bool> ModEnabled;

		public static ConfigEntry<bool> UseCustomFlatValues;

		public static ConfigEntry<float> GlobalPetrifyMultiplier;

		public static ConfigEntry<int> GenerosityStandardCost;

		public static ConfigEntry<int> GenerosityMysticalCost;

		public static ConfigEntry<int> DoubleJumpCost;

		public static ConfigEntry<int> HealingCost;

		public static ConfigEntry<int> InfiniteStamCost;

		private void Awake()
		{
			//IL_0079: Unknown result type (might be due to invalid IL or missing references)
			//IL_0083: Expected O, but got Unknown
			//IL_00ab: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b5: Expected O, but got Unknown
			//IL_00dd: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e7: Expected O, but got Unknown
			//IL_010f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0119: Expected O, but got Unknown
			//IL_0141: Unknown result type (might be due to invalid IL or missing references)
			//IL_014b: Expected O, but got Unknown
			//IL_0173: Unknown result type (might be due to invalid IL or missing references)
			//IL_017d: Expected O, but got Unknown
			//IL_0188: Unknown result type (might be due to invalid IL or missing references)
			//IL_0192: Expected O, but got Unknown
			LogSource = ((BaseUnityPlugin)this).Logger;
			ModEnabled = ((BaseUnityPlugin)this).Config.Bind<bool>("1. General", "ModEnabled", true, "Enable or disable custom Scout Gem/Amulet petrify configuration.");
			UseCustomFlatValues = ((BaseUnityPlugin)this).Config.Bind<bool>("1. General", "UseCustomFlatValues", false, "If true, uses the exact flat petrify values configured below. If false, applies the Global Multiplier to default values.");
			GlobalPetrifyMultiplier = ((BaseUnityPlugin)this).Config.Bind<float>("1. General", "GlobalPetrifyMultiplier", 0.5f, new ConfigDescription("Global multiplier applied to petrify costs when 'UseCustomFlatValues' is false (0.0 = 0%, 0.5 = 50%, 1.0 = 100%).", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0f, 2f), Array.Empty<object>()));
			GenerosityStandardCost = ((BaseUnityPlugin)this).Config.Bind<int>("2. Generosity Values", "GenerosityStandardCost", 0, new ConfigDescription("Flat petrify cost for duplicating normal items.", (AcceptableValueBase)(object)new AcceptableValueRange<int>(0, 100), Array.Empty<object>()));
			GenerosityMysticalCost = ((BaseUnityPlugin)this).Config.Bind<int>("2. Generosity Values", "GenerosityMysticalCost", 0, new ConfigDescription("Flat petrify cost for duplicating Mystical items.", (AcceptableValueBase)(object)new AcceptableValueRange<int>(0, 100), Array.Empty<object>()));
			DoubleJumpCost = ((BaseUnityPlugin)this).Config.Bind<int>("3. Other Amulet Values", "DoubleJumpCost", 0, new ConfigDescription("Petrify cost per double jump.", (AcceptableValueBase)(object)new AcceptableValueRange<int>(0, 100), Array.Empty<object>()));
			HealingCost = ((BaseUnityPlugin)this).Config.Bind<int>("3. Other Amulet Values", "HealingCost", 0, new ConfigDescription("Petrify cost when healing.", (AcceptableValueBase)(object)new AcceptableValueRange<int>(0, 100), Array.Empty<object>()));
			InfiniteStamCost = ((BaseUnityPlugin)this).Config.Bind<int>("3. Other Amulet Values", "InfiniteStamCost", 0, new ConfigDescription("Petrify cost for Infinite Stamina.", (AcceptableValueBase)(object)new AcceptableValueRange<int>(0, 100), Array.Empty<object>()));
			try
			{
				_harmony = new Harmony("com.modder.peak.scoutgempetrifyconfig");
				_harmony.PatchAll(Assembly.GetExecutingAssembly());
				LogSource.LogInfo((object)"ScoutGemPetrifyConfig successfully patched!");
			}
			catch (Exception arg)
			{
				LogSource.LogError((object)string.Format("Failed to patch methods in {0}: {1}", "ScoutGemPetrifyConfig", arg));
			}
		}

		public static int CalculateCost(int originalValue, int customValue)
		{
			if (!ModEnabled.Value)
			{
				return originalValue;
			}
			if (UseCustomFlatValues.Value)
			{
				return customValue;
			}
			float num = Mathf.Clamp(GlobalPetrifyMultiplier.Value, 0f, 2f);
			if (num <= 0f)
			{
				return 0;
			}
			return Mathf.Max(1, Mathf.RoundToInt((float)originalValue * num));
		}

		private void OnDestroy()
		{
			Harmony harmony = _harmony;
			if (harmony != null)
			{
				harmony.UnpatchSelf();
			}
		}
	}
	[HarmonyPatch(typeof(Action_CloneSelectedItem), "RunAction")]
	public static class Patch_Generosity_Direct
	{
		private static int _defaultPetrify = -1;

		private static int _defaultPetrifyMystical = -1;

		[HarmonyPrefix]
		public static void Prefix(Action_CloneSelectedItem __instance)
		{
			if (NoPetrifyGemsPlugin.ModEnabled.Value)
			{
				if (_defaultPetrify == -1)
				{
					_defaultPetrify = __instance.petrify;
				}
				if (_defaultPetrifyMystical == -1)
				{
					_defaultPetrifyMystical = __instance.petrifyMystical;
				}
				__instance.petrify = NoPetrifyGemsPlugin.CalculateCost(_defaultPetrify, NoPetrifyGemsPlugin.GenerosityStandardCost.Value);
				__instance.petrifyMystical = NoPetrifyGemsPlugin.CalculateCost(_defaultPetrifyMystical, NoPetrifyGemsPlugin.GenerosityMysticalCost.Value);
			}
		}
	}
	[HarmonyPatch]
	public static class Patch_InfiniteStam_OnUpdate
	{
		private static int _defaultPetrifyPerSecond = -1;

		[HarmonyTargetMethod]
		public static MethodBase TargetMethod()
		{
			return AccessTools.Method(AccessTools.TypeByName("Peak.InfiniteStamAmulet+DoubleJumpAmuletBehaviorInstance") ?? AccessTools.TypeByName("InfiniteStamAmulet+DoubleJumpAmuletBehaviorInstance"), "OnUpdate", (Type[])null, (Type[])null);
		}

		[HarmonyPrefix]
		public static void Prefix(object __instance)
		{
			if (!NoPetrifyGemsPlugin.ModEnabled.Value || __instance == null)
			{
				return;
			}
			FieldInfo fieldInfo = AccessTools.Field(__instance.GetType(), "petrifyPerSecond");
			if (!(fieldInfo == null))
			{
				int defaultPetrifyPerSecond = Convert.ToInt32(fieldInfo.GetValue(__instance));
				if (_defaultPetrifyPerSecond == -1)
				{
					_defaultPetrifyPerSecond = defaultPetrifyPerSecond;
				}
				int num = NoPetrifyGemsPlugin.CalculateCost(_defaultPetrifyPerSecond, NoPetrifyGemsPlugin.InfiniteStamCost.Value);
				fieldInfo.SetValue(__instance, num);
			}
		}
	}
	[HarmonyPatch]
	public static class Patch_OtherAmulets
	{
		[HarmonyTargetMethods]
		public static IEnumerable<MethodBase> TargetGetters()
		{
			Assembly[] assemblies = AppDomain.CurrentDomain.GetAssemblies();
			foreach (Assembly assembly in assemblies)
			{
				string name = assembly.GetName().Name;
				if (!name.StartsWith("Assembly-CSharp") && !name.StartsWith("Peak"))
				{
					continue;
				}
				Type[] types;
				try
				{
					types = assembly.GetTypes();
				}
				catch (ReflectionTypeLoadException ex)
				{
					types = ex.Types;
				}
				Type[] array = types;
				foreach (Type type in array)
				{
					if (!(type == null))
					{
						PropertyInfo property = type.GetProperty("petrifyAmount", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
						if (property?.GetGetMethod(nonPublic: true) != null)
						{
							yield return property.GetGetMethod(nonPublic: true);
						}
					}
				}
			}
		}

		[HarmonyPostfix]
		public static void Postfix(MethodBase __originalMethod, ref int __result)
		{
			if (NoPetrifyGemsPlugin.ModEnabled.Value)
			{
				string text = __originalMethod.DeclaringType?.FullName ?? "";
				if (text.Contains("DoubleJumpAmulet"))
				{
					__result = NoPetrifyGemsPlugin.CalculateCost(__result, NoPetrifyGemsPlugin.DoubleJumpCost.Value);
				}
				else if (text.Contains("HealingAmulet"))
				{
					__result = NoPetrifyGemsPlugin.CalculateCost(__result, NoPetrifyGemsPlugin.HealingCost.Value);
				}
			}
		}
	}
}