Decompiled source of PriceDotFormatter v1.2.0

PriceDotFormatter.dll

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

[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("PriceDotFormatter")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("PriceDotFormatter")]
[assembly: AssemblyTitle("PriceDotFormatter")]
[assembly: AssemblyVersion("1.0.0.0")]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[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 PriceDotFormatter
{
	[BepInPlugin("acesgaminguk.supermarkettogether.pricedotformatter", "Price Dot Formatter", "1.2.0")]
	public class Plugin : BaseUnityPlugin
	{
		private void Awake()
		{
			Harmony.CreateAndPatchAll(typeof(Plugin), (string)null);
			((BaseUnityPlugin)this).Logger.LogInfo((object)"Price Dot Formatter 1.2.0 loaded.");
		}

		[HarmonyPatch(typeof(ProductListing), "ConvertFloatToTextPrice")]
		[HarmonyPostfix]
		private static void ConvertFloatToTextPrice_Postfix(ref string __result)
		{
			FixText(ref __result);
		}

		[HarmonyPatch(typeof(TMP_Text), "set_text")]
		[HarmonyPrefix]
		private static void TMPText_SetText_Prefix(ref string value)
		{
			FixText(ref value);
		}

		private static void FixText(ref string text)
		{
			if (!string.IsNullOrEmpty(text) && (text.Contains("$") || text.Contains("€") || text.Contains("£") || text.Contains("Price") || text.Contains("price") || LooksLikeDecimalPrice(text)))
			{
				text = text.Replace(",", ".");
			}
		}

		private static bool LooksLikeDecimalPrice(string text)
		{
			for (int i = 1; i < text.Length - 2; i++)
			{
				if (text[i] == ',' && char.IsDigit(text[i - 1]) && char.IsDigit(text[i + 1]) && char.IsDigit(text[i + 2]))
				{
					return true;
				}
			}
			return false;
		}
	}
}