Decompiled source of PerfectSelfCheckout v1.0.0

BepInEx/plugins/PerfectSelfCheckout.dll

Decompiled a day ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Core.Logging.Interpolation;
using BepInEx.Logging;
using BepInEx.Unity.IL2CPP;
using HarmonyLib;
using IceBoxModLib.Config;
using IceBoxModLib.Localization;
using IceBoxModLib.UI;
using PerfectSelfCheckout.Configuration;
using PerfectSelfCheckout.Localization;
using Store.Cashregister;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: AssemblyTitle("PerfectSelfCheckout")]
[assembly: AssemblyDescription("Perfect Self Checkout mod for Roadside Research by Ice Box Studio")]
[assembly: AssemblyCompany("Ice Box Studio")]
[assembly: AssemblyProduct("PerfectSelfCheckout")]
[assembly: AssemblyCopyright("Copyright © 2026 Ice Box Studio All rights reserved.")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("9ee57946-f05a-486c-9331-95001b33a81f")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: TargetFramework(".NETCoreApp,Version=v6.0", FrameworkDisplayName = ".NET 6.0")]
[assembly: AssemblyVersion("1.0.0.0")]
namespace PerfectSelfCheckout
{
	[BepInPlugin("IceBoxStudio.RoadsideResearch.PerfectSelfCheckout", "PerfectSelfCheckout", "1.0.0")]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	public class PerfectSelfCheckout : BasePlugin
	{
		public static PerfectSelfCheckout _Instance;

		private Harmony _harmony;

		private bool patchesApplied;

		public static PerfectSelfCheckout Instance => _Instance;

		internal static ManualLogSource Log { get; private set; }

		public override void Load()
		{
			//IL_011b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0121: Expected O, but got Unknown
			//IL_0029: Unknown result type (might be due to invalid IL or missing references)
			//IL_002f: Expected O, but got Unknown
			//IL_0072: Unknown result type (might be due to invalid IL or missing references)
			//IL_0078: Expected O, but got Unknown
			//IL_00c0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c6: Expected O, but got Unknown
			_Instance = this;
			Log = ((BasePlugin)this).Log;
			bool flag = default(bool);
			try
			{
				Log.LogInfo((object)"=============================================");
				ManualLogSource log = Log;
				BepInExInfoLogInterpolatedStringHandler val = new BepInExInfoLogInterpolatedStringHandler(1, 2, ref flag);
				if (flag)
				{
					((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>("PerfectSelfCheckout");
					((BepInExLogInterpolatedStringHandler)val).AppendLiteral(" ");
					((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>(LocalizationManager.Instance.GetLocalizedText("plugin.initializing"));
				}
				log.LogInfo(val);
				ManualLogSource log2 = Log;
				val = new BepInExInfoLogInterpolatedStringHandler(54, 1, ref flag);
				if (flag)
				{
					((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>(LocalizationManager.Instance.GetLocalizedText("plugin.author_prefix"));
					((BepInExLogInterpolatedStringHandler)val).AppendLiteral("Ice Box Studio(https://steamcommunity.com/id/ibox666/)");
				}
				log2.LogInfo(val);
				ConfigManager.Initialize(((BasePlugin)this).Config);
				ApplyPatches();
				ManualLogSource log3 = Log;
				val = new BepInExInfoLogInterpolatedStringHandler(1, 2, ref flag);
				if (flag)
				{
					((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>("PerfectSelfCheckout");
					((BepInExLogInterpolatedStringHandler)val).AppendLiteral(" ");
					((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>(LocalizationManager.Instance.GetLocalizedText("plugin.initialized"));
				}
				log3.LogInfo(val);
				Log.LogInfo((object)"=============================================");
			}
			catch (Exception ex)
			{
				ManualLogSource log4 = Log;
				BepInExErrorLogInterpolatedStringHandler val2 = new BepInExErrorLogInterpolatedStringHandler(9, 3, ref flag);
				if (flag)
				{
					((BepInExLogInterpolatedStringHandler)val2).AppendFormatted<string>("PerfectSelfCheckout");
					((BepInExLogInterpolatedStringHandler)val2).AppendLiteral(" 初始化错误: ");
					((BepInExLogInterpolatedStringHandler)val2).AppendFormatted<string>(ex.Message);
					((BepInExLogInterpolatedStringHandler)val2).AppendLiteral("\n");
					((BepInExLogInterpolatedStringHandler)val2).AppendFormatted<string>(ex.StackTrace);
				}
				log4.LogError(val2);
			}
		}

		private void ApplyPatches()
		{
			//IL_0037: Unknown result type (might be due to invalid IL or missing references)
			//IL_003d: Expected O, but got Unknown
			//IL_000e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0018: Expected O, but got Unknown
			if (!patchesApplied)
			{
				try
				{
					_harmony = new Harmony("IceBoxStudio.RoadsideResearch.PerfectSelfCheckout");
					_harmony.PatchAll();
					patchesApplied = true;
					return;
				}
				catch (Exception ex)
				{
					ManualLogSource log = Log;
					bool flag = default(bool);
					BepInExErrorLogInterpolatedStringHandler val = new BepInExErrorLogInterpolatedStringHandler(10, 3, ref flag);
					if (flag)
					{
						((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>("PerfectSelfCheckout");
						((BepInExLogInterpolatedStringHandler)val).AppendLiteral(" 应用补丁错误: ");
						((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>(ex.Message);
						((BepInExLogInterpolatedStringHandler)val).AppendLiteral("\n");
						((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>(ex.StackTrace);
					}
					log.LogError(val);
					return;
				}
			}
			Log.LogInfo((object)LocalizationManager.Instance.GetLocalizedText("plugin.patches_skipped"));
		}
	}
	public static class PluginInfo
	{
		public const string PLUGIN_GUID = "IceBoxStudio.RoadsideResearch.PerfectSelfCheckout";

		public const string PLUGIN_NAME = "PerfectSelfCheckout";

		public const string PLUGIN_VERSION = "1.0.0";
	}
}
namespace PerfectSelfCheckout.Patches
{
	[HarmonyPatch(typeof(AutomatedCashRegister))]
	internal class AutomatedCashRegisterPatch
	{
		[HarmonyPatch("CheckIfItemMovementBreaks")]
		[HarmonyPrefix]
		private static bool PrefixCheckIfItemMovementBreaks(AutomatedCashRegister __instance)
		{
			if (!IsEnabled())
			{
				return true;
			}
			RestoreAutomation(__instance);
			return false;
		}

		[HarmonyPatch("FailNextAutoCheckout")]
		[HarmonyPrefix]
		private static bool PrefixFailNextAutoCheckout(AutomatedCashRegister __instance)
		{
			if (!IsEnabled())
			{
				return true;
			}
			return false;
		}

		[HarmonyPatch("OnAutomatedScanItems")]
		[HarmonyPrefix]
		private static void PrefixOnAutomatedScanItems(AutomatedCashRegister __instance)
		{
			if (IsEnabled())
			{
				RestoreAutomation(__instance);
			}
		}

		[HarmonyPatch("OnAutomatedScanItems")]
		[HarmonyPostfix]
		private static void PostfixOnAutomatedScanItems(AutomatedCashRegister __instance)
		{
			if (IsEnabled())
			{
				RestoreAutomation(__instance);
			}
		}

		[HarmonyPatch("FixedUpdateNetwork")]
		[HarmonyPostfix]
		private static void PostfixFixedUpdateNetwork(AutomatedCashRegister __instance)
		{
			if (IsEnabled())
			{
				RestoreAutomation(__instance);
			}
		}

		[HarmonyPatch("onAutomationInteruptedChanged")]
		[HarmonyPrefix]
		private static bool PrefixOnAutomationInteruptedChanged(AutomatedCashRegister __instance)
		{
			if (!IsEnabled())
			{
				return true;
			}
			RestoreAutomation(__instance);
			return false;
		}

		[HarmonyPatch(/*Could not decode attribute arguments.*/)]
		[HarmonyPrefix]
		private static bool PrefixIsAutomationInterupted(ref bool __result)
		{
			if (!IsEnabled())
			{
				return true;
			}
			__result = false;
			return false;
		}

		private static bool IsEnabled()
		{
			if (ConfigManager.Instance != null)
			{
				return ConfigManager.Instance.EnablePerfectSelfCheckout.Value;
			}
			return false;
		}

		private static void RestoreAutomation(AutomatedCashRegister register)
		{
			if (!((Object)(object)register == (Object)null))
			{
				bool num = register._isAutomationInterupted || register.__isAutomationInterupted || !register._isNpcAbleToAutomateItemMovement;
				register._isNpcAbleToAutomateItemMovement = true;
				register._isAutomationInterupted = false;
				register.__isAutomationInterupted = false;
				register.SetAutomationInteruptionVisuals(false);
				if (num)
				{
					ShowRescueNotification();
				}
			}
		}

		private static void ShowRescueNotification()
		{
			//IL_0046: Unknown result type (might be due to invalid IL or missing references)
			if (ConfigManager.Instance != null && ConfigManager.Instance.EnableRescueNotification.Value)
			{
				ModNotification.Show(LocalizationManager.Instance.GetLocalizedText("notification.customer_rescued"), 3.5f, (Color?)new Color(0.55f, 1f, 0.55f, 1f));
			}
		}
	}
}
namespace PerfectSelfCheckout.Localization
{
	public static class LocalizationHelper
	{
		public static Dictionary<string, string> GetDefaultTranslations(string language)
		{
			Dictionary<string, string> dictionary = new Dictionary<string, string>();
			switch (language)
			{
			case "简体中文":
				dictionary.Add("plugin.initializing", "开始初始化...");
				dictionary.Add("plugin.author_prefix", "作者:");
				dictionary.Add("plugin.initialized", "初始化成功!");
				dictionary.Add("plugin.patches_skipped", "补丁已应用,跳过...");
				dictionary.Add("config.enable_perfect_self_checkout.desc", "启用完美自助结账功能");
				dictionary.Add("config.enable_rescue_notification.desc", "启用挽救失能顾客通知");
				dictionary.Add("notification.customer_rescued", "已帮助顾客自助结账");
				break;
			case "繁體中文":
				dictionary.Add("plugin.initializing", "開始初始化...");
				dictionary.Add("plugin.author_prefix", "作者:");
				dictionary.Add("plugin.initialized", "初始化成功!");
				dictionary.Add("plugin.patches_skipped", "補丁已應用,跳過...");
				dictionary.Add("config.enable_perfect_self_checkout.desc", "啟用完美自助結帳功能");
				dictionary.Add("config.enable_rescue_notification.desc", "啟用挽救失能顧客通知");
				dictionary.Add("notification.customer_rescued", "已幫助顧客自助結帳");
				break;
			case "English":
				dictionary.Add("plugin.initializing", "Starting initialization...");
				dictionary.Add("plugin.author_prefix", "Author: ");
				dictionary.Add("plugin.initialized", "Initialization successful!");
				dictionary.Add("plugin.patches_skipped", "Patches already applied, skipping...");
				dictionary.Add("config.enable_perfect_self_checkout.desc", "Enable perfect self checkout feature");
				dictionary.Add("config.enable_rescue_notification.desc", "Enable rescued disabled customer notification");
				dictionary.Add("notification.customer_rescued", "Help customer self checkout");
				break;
			case "日本語":
				dictionary.Add("plugin.initializing", "初期化中...");
				dictionary.Add("plugin.author_prefix", "作者:");
				dictionary.Add("plugin.initialized", "初期化に成功しました!");
				dictionary.Add("plugin.patches_skipped", "パッチは既に適用されています。スキップします...");
				dictionary.Add("config.enable_perfect_self_checkout.desc", "完全セルフレジ機能を有効にする");
				dictionary.Add("config.enable_rescue_notification.desc", "救済通知を有効にする");
				dictionary.Add("notification.customer_rescued", "顧客を自セルしました");
				break;
			}
			return dictionary;
		}
	}
	public class LocalizationManager
	{
		private static LocalizationManager _instance;

		private readonly ModLocalizationService _service;

		public static readonly string[] SupportedLanguages = new string[4] { "简体中文", "繁體中文", "English", "日本語" };

		public static LocalizationManager Instance => _instance ?? (_instance = new LocalizationManager());

		private LocalizationManager()
		{
			//IL_0011: Unknown result type (might be due to invalid IL or missing references)
			//IL_001b: Expected O, but got Unknown
			_service = new ModLocalizationService((IEnumerable<string>)SupportedLanguages, "English");
			Initialize();
		}

		public void Initialize()
		{
			string[] supportedLanguages = SupportedLanguages;
			foreach (string text in supportedLanguages)
			{
				Dictionary<string, string> defaultTranslations = LocalizationHelper.GetDefaultTranslations(text);
				if (defaultTranslations != null && defaultTranslations.Count > 0)
				{
					_service.AddTranslations(text, defaultTranslations);
				}
			}
		}

		public string GetLocalizedText(string key, params object[] args)
		{
			return _service.GetText(key, args);
		}
	}
}
namespace PerfectSelfCheckout.Configuration
{
	public class ConfigManager : ModConfigBase
	{
		private static ConfigManager _instance;

		public ConfigEntry<bool> EnablePerfectSelfCheckout { get; private set; }

		public ConfigEntry<bool> EnableRescueNotification { get; private set; }

		public static ConfigManager Instance => _instance;

		private ConfigManager(ConfigFile configFile)
			: base(configFile)
		{
			InitializeDefaultConfigs();
		}

		public static void Initialize(ConfigFile configFile)
		{
			if (_instance == null)
			{
				_instance = new ConfigManager(configFile);
			}
		}

		private void InitializeDefaultConfigs()
		{
			EnablePerfectSelfCheckout = ((ModConfigBase)this).RegisterBool("General", "EnablePerfectSelfCheckout", GetLocalizedDescription("config.enable_perfect_self_checkout.desc"), true);
			EnableRescueNotification = ((ModConfigBase)this).RegisterBool("Notification", "EnableRescueNotification", GetLocalizedDescription("config.enable_rescue_notification.desc"), true);
		}

		private string GetLocalizedDescription(string key)
		{
			return LocalizationManager.Instance?.GetLocalizedText(key);
		}
	}
}