Decompiled source of double shards v1.4.0

BepInEx/plugins/com.blueraja.double_shards.dll

Decompiled 4 days ago
using System;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Configuration;
using GlobalSettings;
using HarmonyLib;
using Microsoft.CodeAnalysis;

[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("com.blueraja.double_shards")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.4.0.0")]
[assembly: AssemblyInformationalVersion("1.4.0+84a26c3021aa06e4b9456f855d6177aef2c1d522")]
[assembly: AssemblyProduct("Double Shards")]
[assembly: AssemblyTitle("com.blueraja.double_shards")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.4.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.Module, AllowMultiple = false, Inherited = false)]
	internal sealed class RefSafetyRulesAttribute : Attribute
	{
		public readonly int Version;

		public RefSafetyRulesAttribute(int P_0)
		{
			Version = P_0;
		}
	}
}
namespace double_shards
{
	[BepInPlugin("com.blueraja.double_shards", "Double Shards", "1.4.0")]
	[BepInProcess("Hollow Knight Silksong.exe")]
	public class Plugin : BaseUnityPlugin
	{
		private static ConfigEntry<float> _shardsMultiplier;

		private static ConfigEntry<float> _maxShardsMultiplier;

		private static readonly Random Random = new Random();

		private void Awake()
		{
			Harmony.CreateAndPatchAll(typeof(Plugin), (string)null);
			_shardsMultiplier = ((BaseUnityPlugin)this).Config.Bind<float>("Cheats", "ShardsMultiplier", 2f, "The multiplier for collecting shards. Fractional values work by randomly rounding up/down to get the desired multiplier on average.");
			_maxShardsMultiplier = ((BaseUnityPlugin)this).Config.Bind<float>("Cheats", "MaxShardsMultiplier", 1f, "The multiplier for increasing the max shards. A value of 1.0 means the max shards are not changed.");
			((BaseUnityPlugin)this).Logger.LogInfo((object)"Plugin com.blueraja.double_shards is loaded!");
		}

		[HarmonyPatch(typeof(PlayerData), "AddShards")]
		[HarmonyPrefix]
		private static void AddShardsPrefix(PlayerData __instance, ref int amount)
		{
			amount = RoundRandomly((float)amount * _shardsMultiplier.Value);
		}

		[HarmonyPatch(typeof(Gameplay), "GetCurrencyCap")]
		[HarmonyPostfix]
		private static void GetCurrencyCapPostfix(ref int __result, CurrencyType type)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0002: Invalid comparison between Unknown and I4
			if ((int)type == 1)
			{
				__result = (int)Math.Round((float)__result * _maxShardsMultiplier.Value);
			}
		}

		private static int RoundRandomly(float roundMe)
		{
			int num = (int)Math.Floor(roundMe);
			float num2 = roundMe - (float)num;
			if (!(num2 > 0f) || !((double)num2 > Random.NextDouble()))
			{
				return num;
			}
			return num + 1;
		}
	}
	public static class MyPluginInfo
	{
		public const string PLUGIN_GUID = "com.blueraja.double_shards";

		public const string PLUGIN_NAME = "Double Shards";

		public const string PLUGIN_VERSION = "1.4.0";
	}
}