Decompiled source of AutoPriceManager v1.0.0

BepInEx/plugins/AutoPriceManager.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 AutoPriceManager.Configuration;
using AutoPriceManager.Localization;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Core.Logging.Interpolation;
using BepInEx.Logging;
using BepInEx.Unity.IL2CPP;
using Fusion;
using HarmonyLib;
using IceBoxModLib.Config;
using IceBoxModLib.Localization;
using IceBoxModLib.UI;
using Il2CppSystem.Collections.Generic;
using NPC.Customer;
using Store;
using UnityEngine;
using WallyBox;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: AssemblyTitle("AutoPriceManager")]
[assembly: AssemblyDescription("Auto Price Manager mod for Roadside Research by Ice Box Studio")]
[assembly: AssemblyCompany("Ice Box Studio")]
[assembly: AssemblyProduct("AutoPriceManager")]
[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 AutoPriceManager
{
	[BepInPlugin("IceBoxStudio.RoadsideResearch.AutoPriceManager", "AutoPriceManager", "1.0.0")]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	public class AutoPriceManager : BasePlugin
	{
		public static AutoPriceManager _Instance;

		private Harmony _harmony;

		private bool patchesApplied;

		public static AutoPriceManager 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>("AutoPriceManager");
					((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>("AutoPriceManager");
					((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>("AutoPriceManager");
					((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.AutoPriceManager");
					_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>("AutoPriceManager");
						((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.AutoPriceManager";

		public const string PLUGIN_NAME = "AutoPriceManager";

		public const string PLUGIN_VERSION = "1.0.0";
	}
}
namespace AutoPriceManager.Patches
{
	[HarmonyPatch(typeof(PriceManager))]
	public class PriceManagerPatch
	{
		private static int _lastAdjustFrame = -1;

		private static int _lastAdjustedStoreOpenDay = -1;

		[HarmonyPatch(typeof(StoreManager), "OnChangeStoreIsOpened")]
		[HarmonyPostfix]
		public static void OnChangeStoreIsOpened_Postfix(StoreManager __instance)
		{
			if (ConfigManager.Instance.EnableAutoPrice.Value && StoreManager.StoreIsOpened)
			{
				int currentDay = DaytimeManager.GetCurrentDay();
				if (_lastAdjustedStoreOpenDay != currentDay && !((Object)(object)SingletonNetworkBehaviour<PriceManager>.Instance == (Object)null))
				{
					AutoAdjustPrices(SingletonNetworkBehaviour<PriceManager>.Instance);
					_lastAdjustedStoreOpenDay = currentDay;
				}
			}
		}

		[HarmonyPatch(typeof(SatisfactionManager), "OnSatisfactionUpdated")]
		[HarmonyPostfix]
		public static void OnSatisfactionUpdated_Postfix()
		{
			if (ConfigManager.Instance.EnableAutoPrice.Value && ConfigManager.Instance.EnableAutoPriceOnSatisfactionChange.Value && (Object)(object)SingletonNetworkBehaviour<PriceManager>.Instance != (Object)null)
			{
				AutoAdjustPrices(SingletonNetworkBehaviour<PriceManager>.Instance, showNotification: false);
			}
		}

		private static void AutoAdjustPrices(PriceManager priceManager, bool showNotification = true)
		{
			int frameCount = Time.frameCount;
			if (frameCount == _lastAdjustFrame)
			{
				if (showNotification && ConfigManager.Instance.EnableShowNotification.Value)
				{
					ModNotification.Show(LocalizationManager.Instance.GetLocalizedText("notification.auto_price_done"), 5f, (Color?)null);
				}
				return;
			}
			_lastAdjustFrame = frameCount;
			if ((Object)(object)((SimulationBehaviour)priceManager).Object == (Object)null || !((SimulationBehaviour)priceManager).Object.HasStateAuthority)
			{
				if (showNotification && ConfigManager.Instance.EnableShowNotification.Value)
				{
					ModNotification.Show(LocalizationManager.Instance.GetLocalizedText("notification.auto_price_done"), 5f, (Color?)null);
				}
				return;
			}
			float value = ConfigManager.Instance.PriceMultiplier.Value;
			bool value2 = ConfigManager.Instance.EnableAutoRoundPrice.Value;
			SatisfactionManager.GetSatisfaction();
			float num = 1f;
			if ((Object)(object)SingletonNetworkBehaviour<SatisfactionManager>.Instance != (Object)null)
			{
				num = SingletonNetworkBehaviour<SatisfactionManager>.Instance.GetShoppingLimitMultiplier();
			}
			float priceToleranceMultiplier = DifficultyManager.PriceToleranceMultiplier;
			float num2 = 1f;
			num2 = StatImprovementManager.MultiplyByStat((StatImprovementType)6, 1f);
			float num3 = num * priceToleranceMultiplier * value * num2;
			List<Item> availableItems = StoreManager.AvailableItems;
			if (availableItems == null)
			{
				return;
			}
			int num4 = 0;
			int num5 = 0;
			Enumerator<Item> enumerator = availableItems.GetEnumerator();
			while (enumerator.MoveNext())
			{
				Item current = enumerator.Current;
				float price = PriceManager.GetPrice(current, (PriceType)2, 1);
				float price2 = PriceManager.GetPrice(current, (PriceType)1, 1);
				float num6 = price * num3;
				if (value2)
				{
					num6 = AutoRoundPrice(num6);
				}
				num6 = PriceManager.ClampedPrice(num6);
				if (Mathf.Abs(price2 - num6) > 0.001f)
				{
					num5++;
				}
				PriceManager.SetPrice(current, num6);
				num4++;
			}
			if (showNotification && ConfigManager.Instance.EnableShowNotification.Value)
			{
				ModNotification.Show(LocalizationManager.Instance.GetLocalizedText("notification.auto_price_done"), 5f, (Color?)null);
			}
		}

		private static float AutoRoundPrice(float price)
		{
			return PriceManager.RoundToNearest(price, 0.5f);
		}
	}
}
namespace AutoPriceManager.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_auto_price.desc", "启用自动修改价格功能");
				dictionary.Add("config.enable_auto_price_on_satisfaction_change.desc", "启用顾客满意度发生变更后自动调价");
				dictionary.Add("config.price_multiplier.desc", "价格接受度乘数,1.0 为最高可接受价格\n默认 = 1.0");
				dictionary.Add("config.enable_show_notification.desc", "启用通知显示");
				dictionary.Add("config.enable_auto_round_price.desc", "启用自动抹零价格");
				dictionary.Add("notification.auto_price_done", "商品价格已根据当前顾客最大接受度自动调整完毕");
				break;
			case "繁體中文":
				dictionary.Add("plugin.initializing", "開始初始化...");
				dictionary.Add("plugin.author_prefix", "作者:");
				dictionary.Add("plugin.initialized", "初始化成功!");
				dictionary.Add("plugin.patches_skipped", "補丁已應用,跳過...");
				dictionary.Add("config.enable_auto_price.desc", "啟用自動修改價格功能");
				dictionary.Add("config.enable_auto_price_on_satisfaction_change.desc", "啟用顧客滿意度發生變更後自動調價");
				dictionary.Add("config.price_multiplier.desc", "價格接受度乘數,1.0 為最高可接受價格\n預設 = 1.0");
				dictionary.Add("config.enable_show_notification.desc", "啟用通知顯示");
				dictionary.Add("config.enable_auto_round_price.desc", "啟用自動抹零價格");
				dictionary.Add("notification.auto_price_done", "商品價格已根據當前顧客最大接受度自動調整完畢");
				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_auto_price.desc", "Enable automatic price adjustment feature");
				dictionary.Add("config.enable_auto_price_on_satisfaction_change.desc", "Enable automatic price adjustment when customer satisfaction changes");
				dictionary.Add("config.price_multiplier.desc", "Price acceptance multiplier, 1.0 is the highest acceptable price\nDefault = 1.0");
				dictionary.Add("config.enable_show_notification.desc", "Enable notification display");
				dictionary.Add("config.enable_auto_round_price.desc", "Enable automatic price rounding");
				dictionary.Add("notification.auto_price_done", "Product prices have been automatically adjusted based on current maximum customer acceptance");
				break;
			case "日本語":
				dictionary.Add("plugin.initializing", "初期化中...");
				dictionary.Add("plugin.author_prefix", "作者:");
				dictionary.Add("plugin.initialized", "初期化に成功しました!");
				dictionary.Add("plugin.patches_skipped", "パッチは既に適用されています。スキップします...");
				dictionary.Add("config.enable_auto_price.desc", "価格自動変更機能を有効にする");
				dictionary.Add("config.enable_auto_price_on_satisfaction_change.desc", "顧客の満足度が変わった時に自動で価格を調整する機能を有効にする");
				dictionary.Add("config.price_multiplier.desc", "価格許容度乗数、1.0は最高許容価格\nデフォルト = 1.0");
				dictionary.Add("config.enable_show_notification.desc", "通知表示を有効にする");
				dictionary.Add("config.enable_auto_round_price.desc", "自動価格端数処理を有効にする");
				dictionary.Add("notification.auto_price_done", "商品価格は現在の顧客の最大許容度に基づいて自動調整されました");
				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 AutoPriceManager.Configuration
{
	public class ConfigManager : ModConfigBase
	{
		private static ConfigManager _instance;

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

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

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

		public ConfigEntry<float> PriceMultiplier { get; private set; }

		public ConfigEntry<bool> EnableAutoRoundPrice { 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()
		{
			EnableAutoPrice = ((ModConfigBase)this).RegisterBool("General", "EnableAutoPrice", GetLocalizedDescription("config.enable_auto_price.desc"), true);
			EnableAutoPriceOnSatisfactionChange = ((ModConfigBase)this).RegisterBool("General", "EnableAutoPriceOnSatisfactionChange", GetLocalizedDescription("config.enable_auto_price_on_satisfaction_change.desc"), false);
			PriceMultiplier = ((ModConfigBase)this).RegisterFloat("Settings", "PriceMultiplier", GetLocalizedDescription("config.price_multiplier.desc"), 1f);
			EnableAutoRoundPrice = ((ModConfigBase)this).RegisterBool("Settings", "EnableAutoRoundPrice", GetLocalizedDescription("config.enable_auto_round_price.desc"), true);
			EnableShowNotification = ((ModConfigBase)this).RegisterBool("Settings", "EnableShowNotification", GetLocalizedDescription("config.enable_show_notification.desc"), true);
		}

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