Decompiled source of FlametalOreVeinWontSink v1.1.0

plugins/FlametalOreVeinWontSink.dll

Decompiled a month ago
using System;
using System.Diagnostics;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Configuration;
using HarmonyLib;
using Jotunn.Utils;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: AssemblyTitle("FlametalOreVeinWontSink")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("FlametalOreVeinWontSink")]
[assembly: AssemblyCopyright("Copyright \ufffd  2021")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("e3243d22-4307-4008-ba36-9f326008cde5")]
[assembly: AssemblyFileVersion("1.1.0.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.1.0.0")]
namespace FlametalOreVeinWontSink;

public class Configs
{
	public static ConfigEntry<bool> AffectFlametalOreVeins;

	public static ConfigEntry<bool> AffectLeviathans;

	public static ConfigEntry<float> FlametalOreVeinSinkChance;

	public static ConfigEntry<float> LeviathanSinkChance;

	public static ConfigurationManagerAttributes IsAdminOnly = new ConfigurationManagerAttributes
	{
		IsAdminOnly = true
	};

	public static void SetupConfigs(ConfigFile config)
	{
		//IL_0025: Unknown result type (might be due to invalid IL or missing references)
		//IL_002f: Expected O, but got Unknown
		//IL_0059: Unknown result type (might be due to invalid IL or missing references)
		//IL_0063: Expected O, but got Unknown
		//IL_00a4: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ae: Expected O, but got Unknown
		//IL_00ef: Unknown result type (might be due to invalid IL or missing references)
		//IL_00f9: Expected O, but got Unknown
		AffectFlametalOreVeins = config.Bind<bool>("General", GenerateConfigKey("AffectFlametalOreVeins"), true, new ConfigDescription("Prevent flametal ore veins from sinking.", (AcceptableValueBase)null, new object[1] { IsAdminOnly }));
		AffectLeviathans = config.Bind<bool>("General", GenerateConfigKey("AffectLeviathans"), false, new ConfigDescription("Prevent leviathans from sinking.", (AcceptableValueBase)null, new object[1] { IsAdminOnly }));
		FlametalOreVeinSinkChance = config.Bind<float>("General", GenerateConfigKey("FlametalOreVeinSinkChance", "%"), 0f, new ConfigDescription("Chance per hit to trigger sinking when Affect Flametal Ore Veins is enabled.\n0% prevents sinking; 100% triggers sinking on every hit.\nVanilla default: 1%.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0f, 100f), new object[1] { IsAdminOnly }));
		LeviathanSinkChance = config.Bind<float>("General", GenerateConfigKey("LeviathanSinkChance", "%"), 0f, new ConfigDescription("Chance per hit to trigger sinking when Affect Leviathans is enabled.\n0% prevents sinking; 100% triggers sinking on every hit.\nVanilla default: 10%.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0f, 100f), new object[1] { IsAdminOnly }));
	}

	public static string GenerateConfigKey(string key)
	{
		return GenerateConfigKey(key, null);
	}

	public static string GenerateConfigKey(string key, string unit)
	{
		key = string.Concat(key.Select((char x) => (!char.IsUpper(x)) ? x.ToString() : (" " + x))).TrimStart(new char[1] { ' ' });
		if (!string.IsNullOrEmpty(unit))
		{
			key += $" ({unit})";
		}
		return key;
	}
}
[BepInPlugin("FlametalOreVeinWontSink", "FlametalOreVeinWontSink", "1.1.0")]
[BepInDependency(/*Could not decode attribute arguments.*/)]
[NetworkCompatibility(/*Could not decode attribute arguments.*/)]
internal class FlametalOreVeinWontSink : BaseUnityPlugin
{
	[HarmonyPatch(typeof(Leviathan), "Awake")]
	public static class Leviathan_Awake_Patch
	{
		public static void Postfix(Leviathan __instance, ref float ___m_hitReactionChance)
		{
			if (Configs.AffectFlametalOreVeins.Value && ((Object)((Component)__instance).gameObject).name.StartsWith("LeviathanLava", StringComparison.Ordinal))
			{
				___m_hitReactionChance = Configs.FlametalOreVeinSinkChance.Value / 100f;
			}
			if (Configs.AffectLeviathans.Value && ((Object)((Component)__instance).gameObject).name.StartsWith("Leviathan", StringComparison.Ordinal) && !((Object)((Component)__instance).gameObject).name.StartsWith("LeviathanLava", StringComparison.Ordinal))
			{
				___m_hitReactionChance = Configs.LeviathanSinkChance.Value / 100f;
			}
		}
	}

	public const string PluginGUID = "FlametalOreVeinWontSink";

	public const string PluginName = "FlametalOreVeinWontSink";

	public const string PluginVersion = "1.1.0";

	private static Harmony harmony;

	private void Awake()
	{
		Configs.SetupConfigs(((BaseUnityPlugin)this).Config);
		harmony = Harmony.CreateAndPatchAll(Assembly.GetExecutingAssembly(), "FlametalOreVeinWontSink");
	}

	private void OnDestroy()
	{
		Harmony obj = harmony;
		if (obj != null)
		{
			obj.UnpatchSelf();
		}
	}
}