Decompiled source of Readable Numbers for CloverPit v1.0.1

plugins/CloverPitBetterNumbers.dll

Decompiled 2 months ago
using System;
using System.Diagnostics;
using System.Numerics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using BepInEx;
using HarmonyLib;
using Microsoft.CodeAnalysis;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")]
[assembly: AssemblyCompany("CloverPitBetterNumbers")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("CloverPitBetterNumbers")]
[assembly: AssemblyTitle("CloverPitBetterNumbers")]
[assembly: AssemblyVersion("1.0.0.0")]
[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 CloverPitBetterNumbers
{
	[BepInPlugin("Pxntxrez.cloverpitbetternumbers", "CloverPit Better Numbers", "1.0.0")]
	public class Plugin : BaseUnityPlugin
	{
		public const string PluginGUID = "Pxntxrez.cloverpitbetternumbers";

		public const string PluginName = "CloverPit Better Numbers";

		public const string PluginVersion = "1.0.0";

		private void Awake()
		{
			//IL_0015: Unknown result type (might be due to invalid IL or missing references)
			((BaseUnityPlugin)this).Logger.LogInfo((object)"Plugin CloverPit Better Numbers loaded!");
			new Harmony("Pxntxrez.cloverpitbetternumbers").PatchAll();
			((BaseUnityPlugin)this).Logger.LogInfo((object)"Patches applied! Now the numbers will be beautiful :)");
		}
	}
	[HarmonyPatch(typeof(ClassExtensions), "ToStringSmart", new Type[] { typeof(BigInteger) })]
	public class BigIntegerFormatPatch
	{
		private static bool Prefix(BigInteger n, ref string __result)
		{
			__result = NumberFormatter.FormatBigInteger(n);
			return false;
		}
	}
	[HarmonyPatch(typeof(ClassExtensions), "ToStringSmart", new Type[]
	{
		typeof(double),
		typeof(string),
		typeof(IFormatProvider)
	})]
	public class DoubleFormatPatch
	{
		private static bool Prefix(double n, ref string __result)
		{
			__result = NumberFormatter.FormatDouble(n);
			return false;
		}
	}
	public static class NumberFormatter
	{
		private static readonly string[] suffixes = new string[52]
		{
			"", "K", "M", "B", "T", "Qa", "Qi", "Sx", "Sp", "Oc",
			"No", "Dc", "UDc", "DDc", "TDc", "QaDc", "QiDc", "SxDc", "SpDc", "OcDc",
			"NoDc", "Vg", "UVg", "DVg", "TVg", "QaVg", "QiVg", "SxVg", "SpVg", "OcVg",
			"NoVg", "Tg", "UTg", "DTg", "TTg", "QaTg", "QiTg", "SxTg", "SpTg", "OcTg",
			"NoTg", "Qd", "UQd", "DQd", "TQd", "QaQd", "QiQd", "SxQd", "SpQd", "OcQd",
			"NoQd", "Qq"
		};

		public static string FormatBigInteger(BigInteger number)
		{
			bool flag = number < 0L;
			if (flag)
			{
				number = BigInteger.Abs(number);
			}
			if (number < 1000L)
			{
				return (flag ? "-" : "") + number.ToString("N0");
			}
			double num = (double)number;
			int num2 = 0;
			while (num >= 1000.0 && num2 < suffixes.Length - 1)
			{
				num /= 1000.0;
				num2++;
			}
			return string.Concat(str1: (num >= 100.0) ? num.ToString("F1") : ((!(num >= 10.0)) ? num.ToString("F2") : num.ToString("F2")), str0: flag ? "-" : "", str2: suffixes[num2]);
		}

		public static string FormatDouble(double number)
		{
			bool flag = number < 0.0;
			if (flag)
			{
				number = Math.Abs(number);
			}
			if (number < 1000.0)
			{
				return (flag ? "-" : "") + number.ToString("F0");
			}
			int num = 0;
			while (number >= 1000.0 && num < suffixes.Length - 1)
			{
				number /= 1000.0;
				num++;
			}
			return string.Concat(str1: (number >= 100.0) ? number.ToString("F1") : ((!(number >= 10.0)) ? number.ToString("F2") : number.ToString("F2")), str0: flag ? "-" : "", str2: suffixes[num]);
		}
	}
}