Decompiled source of TributeMultiplier v1.0.2

BepInEx\plugins\TributeMultiplier\TributeMultiplier.dll

Decompiled 2 weeks ago
using System;
using System.Diagnostics;
using System.IO;
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.NET.Common;
using HarmonyLib;
using ModSettingsMenu.Api;
using RomesteadLocalizationAPI.Api;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETCoreApp,Version=v8.0", FrameworkDisplayName = ".NET 8.0")]
[assembly: AssemblyCompany("TributeMultiplier")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("TributeMultiplier")]
[assembly: AssemblyTitle("TributeMultiplier")]
[assembly: AssemblyVersion("1.0.0.0")]
[module: RefSafetyRules(11)]
namespace TributeMultiplier;

internal static class I18n
{
	public static readonly RomesteadLocalizer L = RomesteadLocalization.For("local.romestead.tribute-multiplier");
}
internal static class AddGodProgressPatch
{
	public static void Prefix(ref float __1)
	{
		float num = Plugin.MultiplierEntry?.Value ?? 2f;
		if (!(num <= 1f))
		{
			__1 *= num;
		}
	}
}
[BepInPlugin("local.romestead.tribute-multiplier", "Tribute Multiplier", "1.0.2")]
[BepInDependency(/*Could not decode attribute arguments.*/)]
[BepInDependency(/*Could not decode attribute arguments.*/)]
public class Plugin : BasePlugin
{
	public const string PluginGuid = "local.romestead.tribute-multiplier";

	public const string PluginName = "Tribute Multiplier";

	public const string PluginVersion = "1.0.2";

	public static ManualLogSource Logger;

	public static ConfigEntry<float>? MultiplierEntry;

	private Harmony _harmony;

	private bool _settingsRegistered;

	public override void Load()
	{
		//IL_0035: Unknown result type (might be due to invalid IL or missing references)
		//IL_003f: Expected O, but got Unknown
		//IL_0060: Unknown result type (might be due to invalid IL or missing references)
		//IL_0066: Expected O, but got Unknown
		Logger = ((BasePlugin)this).Log;
		I18n.L.RegisterJson(Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "localization.json"));
		_harmony = new Harmony("local.romestead.tribute-multiplier");
		ApplyPatches();
		RomesteadLocalization.LocalizationApplied += OnLocalizationApplied;
		ManualLogSource logger = Logger;
		bool flag = default(bool);
		BepInExInfoLogInterpolatedStringHandler val = new BepInExInfoLogInterpolatedStringHandler(9, 2, ref flag);
		if (flag)
		{
			((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>("Tribute Multiplier");
			((BepInExLogInterpolatedStringHandler)val).AppendLiteral(" ");
			((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>("1.0.2");
			((BepInExLogInterpolatedStringHandler)val).AppendLiteral(" loaded.");
		}
		logger.LogInfo(val);
	}

	private ConfigDescription BuildDescription()
	{
		//IL_00a4: Unknown result type (might be due to invalid IL or missing references)
		//IL_00aa: Expected O, but got Unknown
		return new ConfigDescription(I18n.L.Text("config.multiplier.description", Array.Empty<object>()), (AcceptableValueBase)(object)new AcceptableValueRange<float>(1f, 100f), new object[2]
		{
			ModSettingsTags.Section("General", I18n.L.Text("section.general", Array.Empty<object>()), (int?)10, (bool?)null),
			ModSettingsTags.Entry(I18n.L.Text("entry.multiplier", Array.Empty<object>()), I18n.L.Text("config.multiplier.description", Array.Empty<object>()), (int?)1, (double?)1.0, (bool?)null)
		});
	}

	private void OnLocalizationApplied(string locale)
	{
		//IL_0081: Unknown result type (might be due to invalid IL or missing references)
		//IL_0086: Unknown result type (might be due to invalid IL or missing references)
		//IL_0091: Unknown result type (might be due to invalid IL or missing references)
		//IL_009c: Unknown result type (might be due to invalid IL or missing references)
		//IL_00a7: Unknown result type (might be due to invalid IL or missing references)
		//IL_00c1: Unknown result type (might be due to invalid IL or missing references)
		//IL_00d3: 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
		if (_settingsRegistered)
		{
			typeof(ConfigEntryBase).GetField("<Description>k__BackingField", BindingFlags.Instance | BindingFlags.NonPublic)?.SetValue(MultiplierEntry, BuildDescription());
		}
		else
		{
			_settingsRegistered = true;
			MultiplierEntry = ((BasePlugin)this).Config.Bind<float>("General", "Multiplier", 2f, BuildDescription());
		}
		ModSettingsRegistry.Register("local.romestead.tribute-multiplier", I18n.L.Text("mod.name", Array.Empty<object>()), ((BasePlugin)this).Config, new ModSettingsModOptions
		{
			Icon = "cog",
			Version = "1.0.2",
			Author = "wwwshe",
			Description = I18n.L.Text("mod.description", Array.Empty<object>()),
			Order = 50
		});
		ManualLogSource logger = Logger;
		bool flag = default(bool);
		BepInExInfoLogInterpolatedStringHandler val = new BepInExInfoLogInterpolatedStringHandler(62, 2, ref flag);
		if (flag)
		{
			((BepInExLogInterpolatedStringHandler)val).AppendLiteral("[TributeMultiplier] Settings registered (locale: ");
			((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>(RomesteadLocalization.CurrentLocale);
			((BepInExLogInterpolatedStringHandler)val).AppendLiteral(") — ");
			((BepInExLogInterpolatedStringHandler)val).AppendFormatted<float>(MultiplierEntry.Value);
			((BepInExLogInterpolatedStringHandler)val).AppendLiteral("x active.");
		}
		logger.LogInfo(val);
	}

	private void ApplyPatches()
	{
		//IL_008a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0091: Expected O, but got Unknown
		//IL_013b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0149: Expected O, but got Unknown
		MethodInfo methodInfo = null;
		Type type = null;
		Assembly[] assemblies = AppDomain.CurrentDomain.GetAssemblies();
		foreach (Assembly assembly in assemblies)
		{
			Type[] types;
			try
			{
				types = assembly.GetTypes();
			}
			catch
			{
				continue;
			}
			Type[] array = types;
			foreach (Type type2 in array)
			{
				MethodInfo method = type2.GetMethod("AddGodProgress", BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic);
				if ((object)method != null)
				{
					methodInfo = method;
					type = type2;
					break;
				}
			}
			if ((object)methodInfo != null)
			{
				break;
			}
		}
		if ((object)methodInfo == null)
		{
			Logger.LogWarning((object)"[TributeMultiplier] AddGodProgress not found — patch skipped.");
			return;
		}
		ManualLogSource logger = Logger;
		bool flag = default(bool);
		BepInExInfoLogInterpolatedStringHandler val = new BepInExInfoLogInterpolatedStringHandler(32, 3, ref flag);
		if (flag)
		{
			((BepInExLogInterpolatedStringHandler)val).AppendLiteral("[TributeMultiplier] Patching ");
			((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>(type.FullName);
			((BepInExLogInterpolatedStringHandler)val).AppendLiteral(".");
			((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>(methodInfo.Name);
			((BepInExLogInterpolatedStringHandler)val).AppendLiteral("(");
			((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>(string.Join(", ", Array.ConvertAll(methodInfo.GetParameters(), (ParameterInfo p) => p.ParameterType.Name + " " + p.Name)));
			((BepInExLogInterpolatedStringHandler)val).AppendLiteral(")");
		}
		logger.LogInfo(val);
		_harmony.Patch((MethodBase)methodInfo, new HarmonyMethod(typeof(AddGodProgressPatch), "Prefix", (Type[])null), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
	}

	public override bool Unload()
	{
		RomesteadLocalization.LocalizationApplied -= OnLocalizationApplied;
		_harmony.UnpatchSelf();
		return true;
	}
}