Decompiled source of GoldRingScaling v0.1.0

plugins/StonewardsGoldRingScaling.dll

Decompiled 6 hours ago
using System;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Logging;
using HarmonyLib;
using Microsoft.CodeAnalysis;
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("StonewardsGoldRingScaling")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0+0abae0aa3498c21174642bcdb25218a2aadccb68")]
[assembly: AssemblyProduct("StonewardsGoldRingScaling")]
[assembly: AssemblyTitle("StonewardsGoldRingScaling")]
[assembly: AssemblyVersion("1.0.0.0")]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[Embedded]
	[AttributeUsage(AttributeTargets.Class | AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Event | AttributeTargets.Parameter | AttributeTargets.ReturnValue | AttributeTargets.GenericParameter, AllowMultiple = false, Inherited = false)]
	internal sealed class NullableAttribute : Attribute
	{
		public readonly byte[] NullableFlags;

		public NullableAttribute(byte P_0)
		{
			NullableFlags = new byte[1] { P_0 };
		}

		public NullableAttribute(byte[] P_0)
		{
			NullableFlags = P_0;
		}
	}
	[CompilerGenerated]
	[Embedded]
	[AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Method | AttributeTargets.Interface | AttributeTargets.Delegate, AllowMultiple = false, Inherited = false)]
	internal sealed class NullableContextAttribute : Attribute
	{
		public readonly byte Flag;

		public NullableContextAttribute(byte P_0)
		{
			Flag = P_0;
		}
	}
	[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 StonewardsGoldRingScaling
{
	[BepInPlugin("stonewards.goldringscaling", "Stonewards Gold Ring Scaling", "0.1.0")]
	public sealed class GoldRingScalingPlugin : BaseUnityPlugin
	{
		public const string PluginId = "stonewards.goldringscaling";

		public const string PluginName = "Stonewards Gold Ring Scaling";

		public const string PluginVersion = "0.1.0";

		private Harmony? _harmony;

		internal static ManualLogSource? Log { get; private set; }

		private void Awake()
		{
			//IL_0011: Unknown result type (might be due to invalid IL or missing references)
			//IL_001b: Expected O, but got Unknown
			Log = ((BaseUnityPlugin)this).Logger;
			_harmony = new Harmony("stonewards.goldringscaling");
			_harmony.PatchAll(typeof(GoldRingScalingPlugin).Assembly);
			((BaseUnityPlugin)this).Logger.LogInfo((object)"Gold Ring Scaling loaded. Leaderboard detection is NOT modified.");
		}

		private void OnDestroy()
		{
			Harmony? harmony = _harmony;
			if (harmony != null)
			{
				harmony.UnpatchSelf();
			}
		}
	}
	internal static class LegacyGoldRingScaling
	{
		private const float LegacyBonusPerUpgrade = 0.08f;

		private static bool _logged;

		internal static void Restore(AddMetaCurrencyMultiplierEffect effect)
		{
			//IL_000b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0011: Invalid comparison between Unknown and I4
			//IL_0015: Unknown result type (might be due to invalid IL or missing references)
			//IL_001b: Invalid comparison between Unknown and I4
			//IL_006f: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)effect == (Object)null || (int)((UpgradeEffect)effect).statType == 2)
			{
				return;
			}
			if ((int)((UpgradeEffect)effect).statType != 3)
			{
				if (!_logged)
				{
					ManualLogSource? log = GoldRingScalingPlugin.Log;
					if (log != null)
					{
						log.LogWarning((object)("Unexpected Gold Ring stat type: " + ((object)Unsafe.As<StatModType, StatModType>(ref ((UpgradeEffect)effect).statType)/*cast due to .constrained prefix*/).ToString() + ". The mod left it unchanged for safety."));
					}
					_logged = true;
				}
				return;
			}
			float baseValue = ((UpgradeEffect)effect).baseValue;
			((UpgradeEffect)effect).baseValue = 0.08f;
			((UpgradeEffect)effect).statType = (StatModType)2;
			if (!_logged)
			{
				ManualLogSource? log2 = GoldRingScalingPlugin.Log;
				if (log2 != null)
				{
					log2.LogInfo((object)("Gold Ring classic scaling restored: base bonus " + baseValue + " -> " + 0.08f + ", modifier LIMITED_TO_15 -> PERCENT_MULT. Final Gold multiplier cap: x200."));
				}
				_logged = true;
			}
		}
	}
	[HarmonyPatch(typeof(AddMetaCurrencyMultiplierEffect), "Apply")]
	internal static class GoldRingApplyPatch
	{
		[HarmonyPrefix]
		private static void Prefix(AddMetaCurrencyMultiplierEffect __instance)
		{
			LegacyGoldRingScaling.Restore(__instance);
		}
	}
	[HarmonyPatch(typeof(AddMetaCurrencyMultiplierEffect), "GetNextValue", new Type[] { typeof(float) })]
	internal static class GoldRingPreviewPatch
	{
		[HarmonyPrefix]
		private static void Prefix(AddMetaCurrencyMultiplierEffect __instance)
		{
			LegacyGoldRingScaling.Restore(__instance);
		}
	}
	internal static class LegacyGoldCap
	{
		internal const float MaxMultiplier = 200f;

		internal static void Clamp(CharacterStat stat, ref float value)
		{
			ResourceManager instance = ResourceManager.Instance;
			if (!((Object)(object)instance == (Object)null) && stat == instance.MetaCurrencyBonusMultiplier && value > 200f)
			{
				value = 200f;
			}
		}
	}
	[HarmonyPatch(typeof(CharacterStat), "get_Value")]
	internal static class GoldMultiplierCapPatch
	{
		[HarmonyPostfix]
		private static void Postfix(CharacterStat __instance, ref float __result)
		{
			LegacyGoldCap.Clamp(__instance, ref __result);
		}
	}
	[HarmonyPatch(typeof(CharacterStat), "GetValueWithModifierPreview")]
	internal static class GoldMultiplierPreviewCapPatch
	{
		[HarmonyPostfix]
		private static void Postfix(CharacterStat __instance, ref float __result)
		{
			LegacyGoldCap.Clamp(__instance, ref __result);
		}
	}
}