Decompiled source of Simple ValuableScaler v1.0.0

Simple_ValuableScaler.dll

Decompiled a day ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
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 Microsoft.CodeAnalysis;
using UnityEngine;

[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 = ".NET Standard 2.1")]
[assembly: IgnoresAccessChecksTo("")]
[assembly: AssemblyCompany("zabu")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("zabumod")]
[assembly: AssemblyTitle("zabumod")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
[module: UnverifiableCode]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.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]
	[Microsoft.CodeAnalysis.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]
	[Microsoft.CodeAnalysis.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 REPOJP.Simple_ValuableScaler
{
	[BepInPlugin("REPOJP.Simple_ValuableScaler", "Simple_ValuableScaler", "1.0.0")]
	public sealed class Simple_ValuableScalerPlugin : BaseUnityPlugin
	{
		public const string PluginGuid = "REPOJP.Simple_ValuableScaler";

		public const string PluginName = "Simple_ValuableScaler";

		public const string PluginVersion = "1.0.0";

		internal static ManualLogSource Log;

		internal static ConfigEntry<float> CfgAmountMultiplier;

		internal static ConfigEntry<bool> CfgIgnoreLevelSizeRestrictions;

		internal static ConfigEntry<float> CfgTinySizeMultiplier;

		internal static ConfigEntry<float> CfgSmallSizeMultiplier;

		internal static ConfigEntry<float> CfgMediumSizeMultiplier;

		internal static ConfigEntry<float> CfgBigSizeMultiplier;

		internal static ConfigEntry<float> CfgWideSizeMultiplier;

		internal static ConfigEntry<float> CfgTallSizeMultiplier;

		internal static ConfigEntry<float> CfgVeryTallSizeMultiplier;

		private void Awake()
		{
			//IL_003a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0044: Expected O, but got Unknown
			//IL_0065: Unknown result type (might be due to invalid IL or missing references)
			//IL_006f: Expected O, but got Unknown
			//IL_00e9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ef: Expected O, but got Unknown
			Log = ((BaseUnityPlugin)this).Logger;
			CfgAmountMultiplier = ((BaseUnityPlugin)this).Config.Bind<float>("General", "AmountMultiplier", 1.5f, new ConfigDescription("Valuables spawn amount multiplier (0.0 - 10.0). Multiplies total valuables spawned.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0f, 10f), Array.Empty<object>()));
			CfgIgnoreLevelSizeRestrictions = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "IgnoreLevelSizeRestrictions", false, new ConfigDescription("Allow valuables normally locked to higher levels to spawn on any level.", (AcceptableValueBase)null, Array.Empty<object>()));
			CfgTinySizeMultiplier = BindSizeMultiplier("TinySizeMultiplier");
			CfgSmallSizeMultiplier = BindSizeMultiplier("SmallSizeMultiplier");
			CfgMediumSizeMultiplier = BindSizeMultiplier("MediumSizeMultiplier");
			CfgBigSizeMultiplier = BindSizeMultiplier("BigSizeMultiplier");
			CfgWideSizeMultiplier = BindSizeMultiplier("WideSizeMultiplier");
			CfgTallSizeMultiplier = BindSizeMultiplier("TallSizeMultiplier");
			CfgVeryTallSizeMultiplier = BindSizeMultiplier("VeryTallSizeMultiplier");
			Harmony val = new Harmony("REPOJP.Simple_ValuableScaler");
			val.PatchAll();
			((BaseUnityPlugin)this).Logger.LogInfo((object)"Simple_ValuableScaler 1.0.0 loaded");
		}

		private ConfigEntry<float> BindSizeMultiplier(string key)
		{
			//IL_002b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0035: Expected O, but got Unknown
			return ((BaseUnityPlugin)this).Config.Bind<float>("SizeMultiplier", key, 1f, new ConfigDescription("Multiplier affecting spawn ratio weight for this size (0.0 - 10.0). 1.0 keeps vanilla ratio.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0f, 10f), Array.Empty<object>()));
		}
	}
	[HarmonyPatch(typeof(ValuableDirector), "SetupHost")]
	[HarmonyPatch(/*Could not decode attribute arguments.*/)]
	internal static class ValuableDirectorSetupHostEnumeratorPatch
	{
		private sealed class OriginalState
		{
			public int TotalMaxAmount;

			public float TotalMaxValue;

			public int TinyMaxAmount;

			public int SmallMaxAmount;

			public int MediumMaxAmount;

			public int BigMaxAmount;

			public int WideMaxAmount;

			public int TallMaxAmount;

			public int VeryTallMaxAmount;

			public int TinyChance;

			public int SmallChance;

			public int MediumChance;

			public int BigChance;

			public int WideChance;

			public int TallChance;

			public int VeryTallChance;

			public bool Logged;
		}

		private static readonly FieldRef<ValuableDirector, int> Ref_totalMaxAmount = AccessTools.FieldRefAccess<ValuableDirector, int>("totalMaxAmount");

		private static readonly FieldRef<ValuableDirector, float> Ref_totalMaxValue = AccessTools.FieldRefAccess<ValuableDirector, float>("totalMaxValue");

		private static readonly FieldRef<ValuableDirector, int> Ref_tinyMaxAmount = AccessTools.FieldRefAccess<ValuableDirector, int>("tinyMaxAmount");

		private static readonly FieldRef<ValuableDirector, int> Ref_smallMaxAmount = AccessTools.FieldRefAccess<ValuableDirector, int>("smallMaxAmount");

		private static readonly FieldRef<ValuableDirector, int> Ref_mediumMaxAmount = AccessTools.FieldRefAccess<ValuableDirector, int>("mediumMaxAmount");

		private static readonly FieldRef<ValuableDirector, int> Ref_bigMaxAmount = AccessTools.FieldRefAccess<ValuableDirector, int>("bigMaxAmount");

		private static readonly FieldRef<ValuableDirector, int> Ref_wideMaxAmount = AccessTools.FieldRefAccess<ValuableDirector, int>("wideMaxAmount");

		private static readonly FieldRef<ValuableDirector, int> Ref_tallMaxAmount = AccessTools.FieldRefAccess<ValuableDirector, int>("tallMaxAmount");

		private static readonly FieldRef<ValuableDirector, int> Ref_veryTallMaxAmount = AccessTools.FieldRefAccess<ValuableDirector, int>("veryTallMaxAmount");

		private static readonly ConditionalWeakTable<ValuableDirector, OriginalState> States = new ConditionalWeakTable<ValuableDirector, OriginalState>();

		[HarmonyTranspiler]
		private static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstruction> instructions, MethodBase __originalMethod)
		{
			//IL_005a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0060: Expected O, but got Unknown
			//IL_0076: Unknown result type (might be due to invalid IL or missing references)
			//IL_007c: Expected O, but got Unknown
			//IL_00ad: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b3: 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_00de: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e4: Expected O, but got Unknown
			List<CodeInstruction> list = new List<CodeInstruction>(instructions);
			FieldInfo fieldInfo = AccessTools.Field(typeof(ValuableDirector), "valuableTargetAmount");
			if (fieldInfo == null)
			{
				return list;
			}
			FieldInfo fieldInfo2 = AccessTools.Field(__originalMethod.DeclaringType, "<>4__this");
			if (fieldInfo2 == null)
			{
				return list;
			}
			CodeMatcher val = new CodeMatcher((IEnumerable<CodeInstruction>)list, (ILGenerator)null);
			val.MatchForward(false, (CodeMatch[])(object)new CodeMatch[1]
			{
				new CodeMatch((OpCode?)OpCodes.Stfld, (object)fieldInfo, (string)null)
			});
			if (!val.IsValid)
			{
				return list;
			}
			val.Advance(1);
			val.Insert((CodeInstruction[])(object)new CodeInstruction[3]
			{
				new CodeInstruction(OpCodes.Ldarg_0, (object)null),
				new CodeInstruction(OpCodes.Ldfld, (object)fieldInfo2),
				new CodeInstruction(OpCodes.Call, (object)AccessTools.Method(typeof(ValuableDirectorSetupHostEnumeratorPatch), "ApplySettings", (Type[])null, (Type[])null))
			});
			return val.InstructionEnumeration();
		}

		public static void ApplySettings(ValuableDirector inst)
		{
			if (!((Object)(object)inst == (Object)null))
			{
				if (!States.TryGetValue(inst, out OriginalState value))
				{
					value = new OriginalState
					{
						TotalMaxAmount = Ref_totalMaxAmount.Invoke(inst),
						TotalMaxValue = Ref_totalMaxValue.Invoke(inst),
						TinyMaxAmount = Ref_tinyMaxAmount.Invoke(inst),
						SmallMaxAmount = Ref_smallMaxAmount.Invoke(inst),
						MediumMaxAmount = Ref_mediumMaxAmount.Invoke(inst),
						BigMaxAmount = Ref_bigMaxAmount.Invoke(inst),
						WideMaxAmount = Ref_wideMaxAmount.Invoke(inst),
						TallMaxAmount = Ref_tallMaxAmount.Invoke(inst),
						VeryTallMaxAmount = Ref_veryTallMaxAmount.Invoke(inst),
						TinyChance = inst.tinyChance,
						SmallChance = inst.smallChance,
						MediumChance = inst.mediumChance,
						BigChance = inst.bigChance,
						WideChance = inst.wideChance,
						TallChance = inst.tallChance,
						VeryTallChance = inst.veryTallChance
					};
					States.Add(inst, value);
				}
				Ref_totalMaxAmount.Invoke(inst) = value.TotalMaxAmount;
				Ref_totalMaxValue.Invoke(inst) = value.TotalMaxValue;
				Ref_tinyMaxAmount.Invoke(inst) = value.TinyMaxAmount;
				Ref_smallMaxAmount.Invoke(inst) = value.SmallMaxAmount;
				Ref_mediumMaxAmount.Invoke(inst) = value.MediumMaxAmount;
				Ref_bigMaxAmount.Invoke(inst) = value.BigMaxAmount;
				Ref_wideMaxAmount.Invoke(inst) = value.WideMaxAmount;
				Ref_tallMaxAmount.Invoke(inst) = value.TallMaxAmount;
				Ref_veryTallMaxAmount.Invoke(inst) = value.VeryTallMaxAmount;
				inst.tinyChance = value.TinyChance;
				inst.smallChance = value.SmallChance;
				inst.mediumChance = value.MediumChance;
				inst.bigChance = value.BigChance;
				inst.wideChance = value.WideChance;
				inst.tallChance = value.TallChance;
				inst.veryTallChance = value.VeryTallChance;
				float value2 = Simple_ValuableScalerPlugin.CfgAmountMultiplier.Value;
				value2 = Mathf.Clamp(value2, 0f, 10f);
				int num = Mathf.Max(0, Mathf.RoundToInt((float)value.TotalMaxAmount * value2));
				Ref_totalMaxAmount.Invoke(inst) = num;
				float num2 = value.TotalMaxValue * value2;
				Ref_totalMaxValue.Invoke(inst) = Mathf.Max(num2, 100000000f);
				if (!value.Logged)
				{
					value.Logged = true;
					Simple_ValuableScalerPlugin.Log.LogInfo((object)$"Simple_ValuableScaler applied | AmountMultiplier={value2} | TotalMaxAmount={num}");
				}
			}
		}
	}
}