Decompiled source of Merchant Altar Minimum Payout v1.0.0

BepInEx/plugins/GatekeeperMerchantAltarMinimumPayout/GatekeeperMerchantAltarMinimumPayout.dll

Decompiled 4 days ago
using System;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Core.Logging.Interpolation;
using BepInEx.Logging;
using BepInEx.Unity.IL2CPP;
using Gatekeeper.EnvironmentStuff;
using Gatekeeper.EnvironmentStuff.TradersAltar;
using HarmonyLib;
using MerchantAltarMinimumPayout.Core;
using Microsoft.CodeAnalysis;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: AssemblyCompany("prom")]
[assembly: AssemblyProduct("Merchant Altar Minimum Payout")]
[assembly: AssemblyTitle("GatekeeperMerchantAltarMinimumPayout")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: TargetFramework(".NETCoreApp,Version=v6.0", FrameworkDisplayName = ".NET 6.0")]
[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 MerchantAltarMinimumPayout
{
	[BepInPlugin("com.prom.gatekeeper.merchantaltarminimum", "Merchant Altar Minimum Payout", "1.0.0")]
	[BepInProcess("Gatekeeper.exe")]
	public sealed class Plugin : BasePlugin
	{
		internal const string PluginGuid = "com.prom.gatekeeper.merchantaltarminimum";

		internal const string PluginName = "Merchant Altar Minimum Payout";

		internal const string PluginVersion = "1.0.0";

		private static ConfigEntry<uint>? _minimumPayout;

		private static ManualLogSource? _log;

		private Harmony? _harmony;

		public override void Load()
		{
			//IL_0180: Unknown result type (might be due to invalid IL or missing references)
			//IL_0187: Expected O, but got Unknown
			//IL_00ca: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d4: Expected O, but got Unknown
			//IL_00dd: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ea: Expected O, but got Unknown
			//IL_00f7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fe: Expected O, but got Unknown
			_log = ((BasePlugin)this).Log;
			_minimumPayout = ((BasePlugin)this).Config.Bind<uint>("General", "MerchantAltarMinimumPayout", 100u, "Absolute minimum Prism payout from the Merchant's Altar. Restart the game after changing this value.");
			bool flag = default(bool);
			try
			{
				MethodInfo methodInfo = typeof(TradersAltarRepaired).GetMethod("Awake", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic, null, Type.EmptyTypes, null) ?? throw new MissingMethodException(typeof(TradersAltarRepaired).FullName, "Awake()");
				if (methodInfo.DeclaringType != typeof(TradersAltarRepaired))
				{
					throw new InvalidOperationException("Resolved Awake() was not declared by TradersAltarRepaired; refusing to patch a broader type.");
				}
				MethodInfo methodInfo2 = typeof(Plugin).GetMethod("TradersAltarRepairedAwakePostfix", BindingFlags.Static | BindingFlags.NonPublic) ?? throw new MissingMethodException(typeof(Plugin).FullName, "TradersAltarRepairedAwakePostfix");
				_harmony = new Harmony("com.prom.gatekeeper.merchantaltarminimum");
				_harmony.Patch((MethodBase)methodInfo, (HarmonyMethod)null, new HarmonyMethod(methodInfo2), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
				ManualLogSource log = ((BasePlugin)this).Log;
				BepInExInfoLogInterpolatedStringHandler val = new BepInExInfoLogInterpolatedStringHandler(62, 2, ref flag);
				if (flag)
				{
					((BepInExLogInterpolatedStringHandler)val).AppendLiteral("Patched only ");
					((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>(typeof(TradersAltarRepaired).FullName);
					((BepInExLogInterpolatedStringHandler)val).AppendLiteral(".Awake(); configured MerchantAltarMinimumPayout=");
					((BepInExLogInterpolatedStringHandler)val).AppendFormatted<uint>(_minimumPayout.Value);
					((BepInExLogInterpolatedStringHandler)val).AppendLiteral(".");
				}
				log.LogInfo(val);
			}
			catch (Exception ex)
			{
				Harmony? harmony = _harmony;
				if (harmony != null)
				{
					harmony.UnpatchSelf();
				}
				ManualLogSource log2 = ((BasePlugin)this).Log;
				BepInExErrorLogInterpolatedStringHandler val2 = new BepInExErrorLogInterpolatedStringHandler(52, 1, ref flag);
				if (flag)
				{
					((BepInExLogInterpolatedStringHandler)val2).AppendLiteral("Failed closed; no Merchant's Altar patch is active: ");
					((BepInExLogInterpolatedStringHandler)val2).AppendFormatted<Exception>(ex);
				}
				log2.LogError(val2);
			}
		}

		private static void TradersAltarRepairedAwakePostfix(TradersAltarRepaired __instance)
		{
			//IL_0180: Unknown result type (might be due to invalid IL or missing references)
			//IL_0187: Expected O, but got Unknown
			//IL_0030: Unknown result type (might be due to invalid IL or missing references)
			//IL_0052: Expected I4, but got Unknown
			//IL_0084: Unknown result type (might be due to invalid IL or missing references)
			//IL_008b: Expected O, but got Unknown
			bool flag = default(bool);
			try
			{
				TradersAltarRepairedInfo interactableObjectInfo = ((NetworkInteractable<TradersAltarMaterialController, TradersAltarRepairedInfo>)(object)__instance).InteractableObjectInfo;
				if (interactableObjectInfo == null)
				{
					ManualLogSource? log = _log;
					if (log != null)
					{
						log.LogError((object)"TradersAltarRepaired has no TradersAltarRepairedInfo; MinPrice was not changed.");
					}
					return;
				}
				AltarInfoSnapshot original = new AltarInfoSnapshot((int)interactableObjectInfo.ItemReferencePrice, interactableObjectInfo.OmniCost, interactableObjectInfo.MinPrice, interactableObjectInfo.Multiplier, interactableObjectInfo.DeprecationStep);
				interactableObjectInfo.MinPrice = MinimumPayoutPolicy.WithMinimumPayout(original, _minimumPayout.Value).MinPrice;
				ManualLogSource log2 = _log;
				if (log2 != null)
				{
					BepInExInfoLogInterpolatedStringHandler val = new BepInExInfoLogInterpolatedStringHandler(104, 6, ref flag);
					if (flag)
					{
						((BepInExLogInterpolatedStringHandler)val).AppendLiteral("Merchant's Altar MinPrice ");
						((BepInExLogInterpolatedStringHandler)val).AppendFormatted<uint>(original.MinPrice);
						((BepInExLogInterpolatedStringHandler)val).AppendLiteral(" -> ");
						((BepInExLogInterpolatedStringHandler)val).AppendFormatted<uint>(interactableObjectInfo.MinPrice);
						((BepInExLogInterpolatedStringHandler)val).AppendLiteral("; ");
						((BepInExLogInterpolatedStringHandler)val).AppendLiteral("preserved ItemReferencePrice=");
						((BepInExLogInterpolatedStringHandler)val).AppendFormatted<int>(original.ItemReferencePrice);
						((BepInExLogInterpolatedStringHandler)val).AppendLiteral(", OmniCost=");
						((BepInExLogInterpolatedStringHandler)val).AppendFormatted<uint>(original.OmniCost);
						((BepInExLogInterpolatedStringHandler)val).AppendLiteral(", ");
						((BepInExLogInterpolatedStringHandler)val).AppendLiteral("Multiplier=");
						((BepInExLogInterpolatedStringHandler)val).AppendFormatted<float>(original.Multiplier);
						((BepInExLogInterpolatedStringHandler)val).AppendLiteral(", DeprecationStep=");
						((BepInExLogInterpolatedStringHandler)val).AppendFormatted<float>(original.DeprecationStep);
						((BepInExLogInterpolatedStringHandler)val).AppendLiteral(".");
					}
					log2.LogInfo(val);
				}
			}
			catch (Exception ex)
			{
				ManualLogSource log3 = _log;
				if (log3 != null)
				{
					BepInExErrorLogInterpolatedStringHandler val2 = new BepInExErrorLogInterpolatedStringHandler(43, 1, ref flag);
					if (flag)
					{
						((BepInExLogInterpolatedStringHandler)val2).AppendLiteral("Merchant's Altar MinPrice was not changed: ");
						((BepInExLogInterpolatedStringHandler)val2).AppendFormatted<Exception>(ex);
					}
					log3.LogError(val2);
				}
			}
		}
	}
}
namespace MerchantAltarMinimumPayout.Core
{
	internal readonly record struct AltarInfoSnapshot(int ItemReferencePrice, uint OmniCost, uint MinPrice, float Multiplier, float DeprecationStep);
	internal static class MinimumPayoutPolicy
	{
		internal static AltarInfoSnapshot WithMinimumPayout(AltarInfoSnapshot original, uint minimumPayout)
		{
			return original with
			{
				MinPrice = minimumPayout
			};
		}
	}
}