using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using AutoRestockFishFixed.Configuration;
using AutoRestockFishFixed.Localization;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using HarmonyLib;
using Newtonsoft.Json;
using Unity.Netcode;
using UnityEngine;
using UnityEngine.Localization;
using UnityEngine.Localization.Settings;
[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: AssemblyTitle("AutoRestockFishFixed")]
[assembly: AssemblyDescription("AutoRestockFishFixed mod for Old Market Simulator by Ice Box Studio")]
[assembly: AssemblyCompany("Ice Box Studio")]
[assembly: AssemblyProduct("AutoRestockFishFixed")]
[assembly: AssemblyCopyright("Copyright © 2025 Ice Box Studio All rights reserved.")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("D7F52A81-4B3C-48E9-9A5D-12C3F8E940B2")]
[assembly: AssemblyFileVersion("1.1.5.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")]
[assembly: AssemblyVersion("1.1.5.0")]
namespace AutoRestockFishFixed
{
[BepInPlugin("IceBoxStudio.AutoRestockFishFixed", "AutoRestockFishFixed", "1.1.5")]
[BepInIncompatibility("xuthics.autoFish")]
public class AutoRestockFishFixed : BaseUnityPlugin
{
private static AutoRestockFishFixed _instance;
private Harmony _harmony;
private bool patchesApplied;
public static AutoRestockFishFixed Instance => _instance;
internal static ManualLogSource Logger { get; private set; }
private void Awake()
{
_instance = this;
Logger = ((BaseUnityPlugin)this).Logger;
try
{
Logger.LogInfo((object)"=============================================");
Logger.LogInfo((object)("AutoRestockFishFixed " + LocalizationManager.Instance.GetLocalizedText("plugin.initializing")));
Logger.LogInfo((object)(LocalizationManager.Instance.GetLocalizedText("plugin.author_prefix") + "Ice Box Studio(https://steamcommunity.com/id/ibox666/)"));
ConfigManager.Initialize(((BaseUnityPlugin)this).Config);
ApplyPatches();
Logger.LogInfo((object)("AutoRestockFishFixed " + LocalizationManager.Instance.GetLocalizedText("plugin.initialized")));
Logger.LogInfo((object)"=============================================");
}
catch (Exception ex)
{
Logger.LogError((object)("AutoRestockFishFixed 初始化错误: " + ex.Message + "\n" + ex.StackTrace));
}
}
private void ApplyPatches()
{
//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.AutoRestockFishFixed");
_harmony.PatchAll();
patchesApplied = true;
return;
}
catch (Exception ex)
{
Logger.LogError((object)("AutoRestockFishFixed 应用补丁错误: " + ex.Message + "\n" + ex.StackTrace));
return;
}
}
Logger.LogInfo((object)LocalizationManager.Instance.GetLocalizedText("plugin.patches_skipped"));
}
}
public static class PluginInfo
{
public const string PLUGIN_GUID = "IceBoxStudio.AutoRestockFishFixed";
public const string PLUGIN_NAME = "AutoRestockFishFixed";
public const string PLUGIN_VERSION = "1.1.5";
public const string PLUGIN_AUTHOR = "Ice Box Studio";
public const string PLUGIN_DESCRIPTION = "自动补货鱼、肉类、药水、武器和雕像。";
}
}
namespace AutoRestockFishFixed.Patches
{
[HarmonyPatch(typeof(Item))]
public static class ItemPatches
{
[HarmonyPatch("BuyProductServer")]
[HarmonyPrefix]
public static bool BuyProductServer_Prefix(Item __instance, ref bool __result)
{
try
{
if (!ConfigManager.EnableMod.Value || (!ConfigManager.EnableAutoRestock.Value && !ConfigManager.EnableAutoRestockPotion.Value && !ConfigManager.EnableAutoRestockStatue.Value && !ConfigManager.EnableAutoRestockMeat.Value && !ConfigManager.EnableAutoRestockWeapon.Value))
{
return true;
}
if (!((NetworkBehaviour)__instance).IsServer)
{
__result = false;
return false;
}
NetworkVariable<int> amount = __instance.amount;
if (amount != null && amount.Value <= 0)
{
__result = false;
return false;
}
List<string> fishNames = ConfigManager.GetFishNames();
List<string> potionNames = ConfigManager.GetPotionNames();
List<string> statueNames = ConfigManager.GetStatueNames();
List<string> meatNames = ConfigManager.GetMeatNames();
List<string> weaponNames = ConfigManager.GetWeaponNames();
ItemSO itemSO = __instance.itemSO;
string text = ((itemSO != null) ? ((Object)itemSO).name : null);
ItemSO itemSO2 = __instance.itemSO;
string text2 = ((itemSO2 != null) ? itemSO2.GetLocalizedName() : null);
long itemID = __instance.itemSO?.id ?? 0;
bool flag = false;
bool flag2 = false;
bool flag3 = false;
bool flag4 = false;
bool flag5 = false;
if (!string.IsNullOrEmpty(text))
{
if (fishNames.Contains(text) || (text.StartsWith("R_") && fishNames.Contains(text.Substring(2))))
{
flag = true;
}
if (potionNames.Contains(text) || (text.StartsWith("R_") && potionNames.Contains(text.Substring(2))))
{
flag2 = true;
}
if (statueNames.Contains(text) || (text.StartsWith("R_") && statueNames.Contains(text.Substring(2))))
{
flag3 = true;
}
if (meatNames.Contains(text) || (text.StartsWith("R_") && meatNames.Contains(text.Substring(2))))
{
flag4 = true;
}
if (weaponNames.Contains(text) || (text.StartsWith("R_") && weaponNames.Contains(text.Substring(2))))
{
flag5 = true;
}
}
string key = null;
string key2 = null;
bool flag6 = false;
if (flag && ConfigManager.ShouldAutoRestock())
{
key = "restock.fish_restocked";
key2 = "restock.no_cellar_stock";
flag6 = true;
}
else if (flag2 && ConfigManager.ShouldAutoRestockPotion())
{
key = "restock.potion_restocked";
key2 = "restock.no_cellar_stock_potion";
flag6 = true;
}
else if (flag3 && ConfigManager.ShouldAutoRestockStatue())
{
key = "restock.statue_restocked";
key2 = "restock.no_cellar_stock_statue";
flag6 = true;
}
else if (flag4 && ConfigManager.ShouldAutoRestockMeat())
{
key = "restock.meat_restocked";
key2 = "restock.no_cellar_stock_meat";
flag6 = true;
}
else if (flag5 && ConfigManager.ShouldAutoRestockWeapon())
{
key = "restock.weapon_restocked";
key2 = "restock.no_cellar_stock_weapon";
flag6 = true;
}
if (flag6)
{
IEnumerable<Item> source = Object.FindObjectsOfType<Item>().Where(delegate(Item x)
{
if ((Object)(object)x != (Object)null && (Object)(object)x != (Object)(object)__instance)
{
NetworkVariable<int> amount4 = x.amount;
if (amount4 != null && amount4.Value > 0)
{
ItemSO itemSO3 = x.itemSO;
if (itemSO3 == null)
{
return false;
}
return itemSO3.id == itemID;
}
}
return false;
});
source = ((!(flag || flag4)) ? source.Where((Item x) => !x.onStand.Value) : source.Where((Item x) => x.IsInFreezer() && !x.IsExpired()));
List<Item> list = source.ToList();
if (list.Count > 0)
{
Item val = list.First();
if (((NetworkBehaviour)__instance).IsServer && (Object)(object)val != (Object)null && val.dayCounter != null)
{
__instance.dayCounter.Value = val.dayCounter.Value;
}
Object.Destroy((Object)(object)((Component)val).gameObject);
if (ConfigManager.ShowRestockNotifications.Value && !ConfigManager.OnlyShowFailedNotifications.Value)
{
string localizedText = LocalizationManager.Instance.GetLocalizedText(key, text2);
try
{
AccessTools.Method(typeof(GameManager), "ShowNotificationClientRpc", new Type[4]
{
typeof(string),
typeof(bool),
typeof(float),
typeof(bool)
}, (Type[])null)?.Invoke(GameManager.Instance, new object[4] { localizedText, false, 3f, false });
}
catch (Exception ex)
{
AutoRestockFishFixed.Logger.LogWarning((object)("无法显示游戏内通知: " + ex.Message));
}
}
}
else
{
if (__instance.amount != null)
{
NetworkVariable<int> amount2 = __instance.amount;
int value = amount2.Value;
amount2.Value = value - 1;
}
if (ConfigManager.ShowRestockNotifications.Value || ConfigManager.OnlyShowFailedNotifications.Value)
{
string localizedText2 = LocalizationManager.Instance.GetLocalizedText(key2, text2);
try
{
AccessTools.Method(typeof(GameManager), "ShowNotificationClientRpc", new Type[4]
{
typeof(string),
typeof(bool),
typeof(float),
typeof(bool)
}, (Type[])null)?.Invoke(GameManager.Instance, new object[4] { localizedText2, false, 3f, false });
}
catch (Exception ex2)
{
AutoRestockFishFixed.Logger.LogWarning((object)("无法显示游戏内通知: " + ex2.Message));
}
}
}
__result = true;
}
else
{
if (__instance.amount != null)
{
NetworkVariable<int> amount3 = __instance.amount;
int value = amount3.Value;
amount3.Value = value - 1;
}
__result = true;
}
return false;
}
catch (Exception ex3)
{
AutoRestockFishFixed.Logger.LogError((object)("BuyProductServer_Prefix 错误: " + ex3.Message + "\n" + ex3.StackTrace));
return true;
}
}
}
}
namespace AutoRestockFishFixed.Localization
{
public class LocalizationManager
{
private static LocalizationManager _instance;
private Dictionary<string, Dictionary<string, string>> _localizations = new Dictionary<string, Dictionary<string, string>>();
private string _currentLocale = "zh";
public static readonly string[] SupportedLanguages = new string[12]
{
"zh", "zh-Hant", "en", "fr", "de", "ja", "ko", "pt", "ru", "es",
"tr", "uk"
};
private static readonly string[] DefaultTranslationLanguages = new string[3] { "zh", "zh-Hant", "en" };
public static LocalizationManager Instance => _instance ?? (_instance = new LocalizationManager());
private LocalizationManager()
{
Initialize();
}
public void Initialize()
{
//IL_0013: Unknown result type (might be due to invalid IL or missing references)
//IL_0018: Unknown result type (might be due to invalid IL or missing references)
if ((Object)(object)LocalizationSettings.SelectedLocale != (Object)null)
{
LocaleIdentifier identifier = LocalizationSettings.SelectedLocale.Identifier;
_currentLocale = ((LocaleIdentifier)(ref identifier)).Code;
}
LocalizationHelper.InitializeLanguageFiles();
string path = Path.Combine(Paths.ConfigPath, "AutoRestockFishFixed", "Localization");
string[] supportedLanguages = SupportedLanguages;
foreach (string text in supportedLanguages)
{
string filePath = Path.Combine(path, text + ".json");
LoadLanguageFile(text, filePath);
}
LocalizationSettings.SelectedLocaleChanged += OnGameLanguageChanged;
}
private void OnGameLanguageChanged(Locale locale)
{
//IL_000a: Unknown result type (might be due to invalid IL or missing references)
//IL_000f: Unknown result type (might be due to invalid IL or missing references)
if ((Object)(object)locale != (Object)null)
{
LocaleIdentifier identifier = locale.Identifier;
string code = ((LocaleIdentifier)(ref identifier)).Code;
if (_localizations.ContainsKey(code))
{
_currentLocale = code;
return;
}
_currentLocale = "en";
AutoRestockFishFixed.Logger.LogInfo((object)GetLocalizedText("plugin.language_fallback", code));
}
}
private void LoadLanguageFile(string language, string filePath)
{
if (File.Exists(filePath))
{
try
{
Dictionary<string, string> value = JsonConvert.DeserializeObject<Dictionary<string, string>>(File.ReadAllText(filePath));
_localizations[language] = value;
return;
}
catch
{
if (Array.IndexOf(DefaultTranslationLanguages, language) >= 0)
{
_localizations[language] = GetDefaultTranslations(language);
}
return;
}
}
if (Array.IndexOf(DefaultTranslationLanguages, language) >= 0)
{
_localizations[language] = GetDefaultTranslations(language);
}
}
private Dictionary<string, string> GetDefaultTranslations(string language)
{
MethodInfo methodInfo = AccessTools.Method(typeof(LocalizationHelper), "GetDefaultTranslations", (Type[])null, (Type[])null);
if (methodInfo != null)
{
return methodInfo.Invoke(null, new object[1] { language }) as Dictionary<string, string>;
}
return new Dictionary<string, string>();
}
public string GetLocalizedText(string key, params object[] args)
{
if (string.IsNullOrEmpty(_currentLocale) || !_localizations.ContainsKey(_currentLocale))
{
_currentLocale = "en";
}
if (_localizations.ContainsKey(_currentLocale) && _localizations[_currentLocale].TryGetValue(key, out var value))
{
if (args.Length == 0)
{
return value;
}
return string.Format(value, args);
}
if (_currentLocale != "en" && _localizations.ContainsKey("en") && _localizations["en"].TryGetValue(key, out var value2))
{
if (args.Length == 0)
{
return value2;
}
return string.Format(value2, args);
}
if (_localizations.ContainsKey("zh") && _localizations["zh"].TryGetValue(key, out var value3))
{
if (args.Length == 0)
{
return value3;
}
return string.Format(value3, args);
}
return key;
}
}
public static class LocalizationHelper
{
private static readonly string[] DefaultTranslationLanguages = new string[3] { "zh", "zh-Hant", "en" };
public static void InitializeLanguageFiles()
{
string text = Path.Combine(Paths.ConfigPath, "AutoRestockFishFixed", "Localization");
if (!Directory.Exists(text))
{
Directory.CreateDirectory(text);
}
string[] defaultTranslationLanguages = DefaultTranslationLanguages;
foreach (string text2 in defaultTranslationLanguages)
{
string filePath = Path.Combine(text, text2 + ".json");
EnsureLanguageFile(text2, filePath);
}
}
private static void EnsureLanguageFile(string language, string filePath)
{
Dictionary<string, string> defaultTranslations = GetDefaultTranslations(language);
if (File.Exists(filePath))
{
try
{
Dictionary<string, string> dictionary = JsonConvert.DeserializeObject<Dictionary<string, string>>(File.ReadAllText(filePath)) ?? new Dictionary<string, string>();
bool flag = false;
foreach (KeyValuePair<string, string> item in defaultTranslations)
{
if (!dictionary.ContainsKey(item.Key))
{
dictionary[item.Key] = item.Value;
flag = true;
}
else if (dictionary[item.Key] != item.Value)
{
dictionary[item.Key] = item.Value;
flag = true;
}
}
foreach (string item2 in new List<string>(dictionary.Keys))
{
if (!defaultTranslations.ContainsKey(item2))
{
dictionary.Remove(item2);
flag = true;
}
}
if (flag)
{
string contents = JsonConvert.SerializeObject((object)dictionary, (Formatting)1);
File.WriteAllText(filePath, contents);
}
return;
}
catch
{
CreateLanguageFile(filePath, defaultTranslations);
return;
}
}
CreateLanguageFile(filePath, defaultTranslations);
}
private static void CreateLanguageFile(string filePath, Dictionary<string, string> translations)
{
string contents = JsonConvert.SerializeObject((object)translations, (Formatting)1);
File.WriteAllText(filePath, contents);
}
public static Dictionary<string, string> GetDefaultTranslations(string language)
{
Dictionary<string, string> dictionary = new Dictionary<string, string>();
switch (language)
{
case "zh":
dictionary.Add("plugin.initializing", "开始初始化...");
dictionary.Add("plugin.author_prefix", "作者:");
dictionary.Add("plugin.initialized", "初始化成功!");
dictionary.Add("plugin.patches_skipped", "补丁已应用,跳过...");
dictionary.Add("plugin.language_fallback", "不支持的语言 {0},使用英语作为备用。");
dictionary.Add("config.enable_mod_desc", "是否启用模组");
dictionary.Add("config.show_restock_notifications_desc", "是否显示补货成功的提示信息");
dictionary.Add("config.only_show_failed_notifications_desc", "仅显示无法补货的提示信息");
dictionary.Add("config.enable_auto_restock_desc", "是否启用鱼类自动补货功能");
dictionary.Add("config.fish_item_names_desc", "鱼类物品名称列表");
dictionary.Add("config.enable_auto_restock_meat_desc", "是否启用肉类自动补货功能");
dictionary.Add("config.meat_item_names_desc", "肉类物品名称列表");
dictionary.Add("config.enable_auto_restock_potion_desc", "是否启用药水自动补货功能");
dictionary.Add("config.potion_item_names_desc", "药水物品名称列表");
dictionary.Add("config.enable_auto_restock_statue_desc", "是否启用雕像自动补货功能");
dictionary.Add("config.statue_item_names_desc", "雕像物品名称列表");
dictionary.Add("config.enable_auto_restock_weapon_desc", "是否启用武器自动补货功能");
dictionary.Add("config.weapon_item_names_desc", "武器物品名称列表");
dictionary.Add("restock.fish_restocked", "从地窖补充了鱼:{0}。");
dictionary.Add("restock.no_cellar_stock", "地窖中没有鱼 {0} 的库存,无法补充。");
dictionary.Add("restock.meat_restocked", "从地窖补充了肉:{0}。");
dictionary.Add("restock.no_cellar_stock_meat", "地窖中没有肉 {0} 的库存,无法补充。");
dictionary.Add("restock.potion_restocked", "已补充药水:{0}。");
dictionary.Add("restock.no_cellar_stock_potion", "没有药水 {0} 的库存,无法补充。");
dictionary.Add("restock.statue_restocked", "已补充雕像:{0}。");
dictionary.Add("restock.no_cellar_stock_statue", "没有雕像 {0} 的库存,无法补充。");
dictionary.Add("restock.weapon_restocked", "已补充武器:{0}。");
dictionary.Add("restock.no_cellar_stock_weapon", "没有武器 {0} 的库存,无法补充。");
break;
case "zh-Hant":
dictionary.Add("plugin.initializing", "開始初始化...");
dictionary.Add("plugin.author_prefix", "作者:");
dictionary.Add("plugin.initialized", "初始化成功!");
dictionary.Add("plugin.patches_skipped", "補丁已應用,跳過...");
dictionary.Add("plugin.language_fallback", "不支持的語言 {0},使用英語作為備用。");
dictionary.Add("config.enable_mod_desc", "是否啟用模組");
dictionary.Add("config.show_restock_notifications_desc", "是否顯示補貨成功的提示信息");
dictionary.Add("config.only_show_failed_notifications_desc", "僅顯示無法補貨的提示資訊");
dictionary.Add("config.enable_auto_restock_desc", "是否啟用魚類自動補貨功能");
dictionary.Add("config.fish_item_names_desc", "魚類物品名稱列表");
dictionary.Add("config.enable_auto_restock_meat_desc", "是否啟用肉類自動補貨功能");
dictionary.Add("config.meat_item_names_desc", "肉類物品名稱列表");
dictionary.Add("config.enable_auto_restock_potion_desc", "是否啟用藥水自動補貨功能");
dictionary.Add("config.potion_item_names_desc", "藥水物品名稱列表");
dictionary.Add("config.enable_auto_restock_statue_desc", "是否啟用雕像自動補貨功能");
dictionary.Add("config.statue_item_names_desc", "雕像物品名稱列表");
dictionary.Add("config.enable_auto_restock_weapon_desc", "是否啟用武器自動補貨功能");
dictionary.Add("config.weapon_item_names_desc", "武器物品名稱列表");
dictionary.Add("restock.fish_restocked", "從地窖補充了魚:{0}。");
dictionary.Add("restock.no_cellar_stock", "地窖中沒有魚 {0} 的庫存,無法補充。");
dictionary.Add("restock.meat_restocked", "從地窖補充了肉:{0}。");
dictionary.Add("restock.no_cellar_stock_meat", "地窖中沒有肉 {0} 的庫存,無法補充。");
dictionary.Add("restock.potion_restocked", "已補充藥水:{0}。");
dictionary.Add("restock.no_cellar_stock_potion", "沒有藥水 {0} 的庫存,無法補充。");
dictionary.Add("restock.statue_restocked", "已補充雕像:{0}。");
dictionary.Add("restock.no_cellar_stock_statue", "沒有雕像 {0} 的庫存,無法補充。");
dictionary.Add("restock.weapon_restocked", "已補充武器:{0}。");
dictionary.Add("restock.no_cellar_stock_weapon", "沒有武器 {0} 的庫存,無法補充。");
break;
case "en":
dictionary.Add("plugin.initializing", "is initializing...");
dictionary.Add("plugin.author_prefix", "Author: ");
dictionary.Add("plugin.initialized", "initialized successfully!");
dictionary.Add("plugin.patches_skipped", "Patches already applied, skipping...");
dictionary.Add("plugin.language_fallback", "Unsupported language {0}, using English as fallback.");
dictionary.Add("config.enable_mod_desc", "Whether to enable mod");
dictionary.Add("config.show_restock_notifications_desc", "Whether to show restock success notifications");
dictionary.Add("config.only_show_failed_notifications_desc", "Only show failed restock notifications");
dictionary.Add("config.enable_auto_restock_desc", "Whether to enable automatic fish restocking");
dictionary.Add("config.fish_item_names_desc", "List of fish item names");
dictionary.Add("config.enable_auto_restock_meat_desc", "Whether to enable automatic meat restocking");
dictionary.Add("config.meat_item_names_desc", "List of meat item names");
dictionary.Add("config.enable_auto_restock_potion_desc", "Whether to enable automatic potion restocking");
dictionary.Add("config.potion_item_names_desc", "List of potion item names");
dictionary.Add("config.enable_auto_restock_statue_desc", "Whether to enable automatic statue restocking");
dictionary.Add("config.statue_item_names_desc", "List of statue item names");
dictionary.Add("config.enable_auto_restock_weapon_desc", "Whether to enable automatic weapon restocking");
dictionary.Add("config.weapon_item_names_desc", "List of weapon item names");
dictionary.Add("restock.fish_restocked", "Restocked fish from cellar: {0}.");
dictionary.Add("restock.no_cellar_stock", "No stock of fish {0} in cellar, unable to restock.");
dictionary.Add("restock.meat_restocked", "Restocked meat from cellar: {0}.");
dictionary.Add("restock.no_cellar_stock_meat", "No stock of meat {0} in cellar, unable to restock.");
dictionary.Add("restock.potion_restocked", "Restocked potion: {0}.");
dictionary.Add("restock.no_cellar_stock_potion", "No stock of potion {0}, unable to restock.");
dictionary.Add("restock.statue_restocked", "Restocked statue: {0}.");
dictionary.Add("restock.no_cellar_stock_statue", "No stock of statue {0}, unable to restock.");
dictionary.Add("restock.weapon_restocked", "Restocked weapon: {0}.");
dictionary.Add("restock.no_cellar_stock_weapon", "No stock of weapon {0}, unable to restock.");
break;
}
return dictionary;
}
}
}
namespace AutoRestockFishFixed.Configuration
{
public static class ConfigManager
{
public static ConfigEntry<bool> EnableMod { get; private set; }
public static ConfigEntry<bool> EnableAutoRestock { get; private set; }
public static ConfigEntry<string> FishItemNames { get; private set; }
public static ConfigEntry<bool> ShowRestockNotifications { get; private set; }
public static ConfigEntry<bool> OnlyShowFailedNotifications { get; private set; }
public static ConfigEntry<bool> EnableAutoRestockPotion { get; private set; }
public static ConfigEntry<bool> EnableAutoRestockStatue { get; private set; }
public static ConfigEntry<bool> EnableAutoRestockMeat { get; private set; }
public static ConfigEntry<string> PotionItemNames { get; private set; }
public static ConfigEntry<string> StatueItemNames { get; private set; }
public static ConfigEntry<string> MeatItemNames { get; private set; }
public static ConfigEntry<bool> EnableAutoRestockWeapon { get; private set; }
public static ConfigEntry<string> WeaponItemNames { get; private set; }
public static List<string> GetFishNames()
{
if (string.IsNullOrEmpty(FishItemNames.Value))
{
return new List<string>();
}
return (from name in FishItemNames.Value.Split(new char[1] { ',' })
select name.Trim() into name
where !string.IsNullOrEmpty(name)
select name).ToList();
}
public static List<string> GetPotionNames()
{
if (string.IsNullOrEmpty(PotionItemNames.Value))
{
return new List<string>();
}
return (from name in PotionItemNames.Value.Split(new char[1] { ',' })
select name.Trim() into name
where !string.IsNullOrEmpty(name)
select name).ToList();
}
public static List<string> GetStatueNames()
{
if (string.IsNullOrEmpty(StatueItemNames.Value))
{
return new List<string>();
}
return (from name in StatueItemNames.Value.Split(new char[1] { ',' })
select name.Trim() into name
where !string.IsNullOrEmpty(name)
select name).ToList();
}
public static List<string> GetMeatNames()
{
if (string.IsNullOrEmpty(MeatItemNames.Value))
{
return new List<string>();
}
return (from name in MeatItemNames.Value.Split(new char[1] { ',' })
select name.Trim() into name
where !string.IsNullOrEmpty(name)
select name).ToList();
}
public static List<string> GetWeaponNames()
{
if (string.IsNullOrEmpty(WeaponItemNames.Value))
{
return new List<string>();
}
return (from name in WeaponItemNames.Value.Split(new char[1] { ',' })
select name.Trim() into name
where !string.IsNullOrEmpty(name)
select name).ToList();
}
public static void Initialize(ConfigFile config)
{
EnableMod = config.Bind<bool>("General", "EnableMod", true, LocalizationManager.Instance.GetLocalizedText("config.enable_mod_desc"));
ShowRestockNotifications = config.Bind<bool>("General", "ShowRestockNotifications", true, LocalizationManager.Instance.GetLocalizedText("config.show_restock_notifications_desc"));
OnlyShowFailedNotifications = config.Bind<bool>("General", "OnlyShowFailedNotifications", false, LocalizationManager.Instance.GetLocalizedText("config.only_show_failed_notifications_desc"));
EnableAutoRestock = config.Bind<bool>("General", "EnableAutoRestock", true, LocalizationManager.Instance.GetLocalizedText("config.enable_auto_restock_desc"));
string text = "Regular Fish,Brown Fish,Grey Fish,Green Fish,Orange Roughy,Carp,Swordfish,Octopus,Baby Shark,Trout,Lobster,Tuna,Ray,Goby";
FishItemNames = config.Bind<string>("General", "FishItemNames", text, LocalizationManager.Instance.GetLocalizedText("config.fish_item_names_desc"));
EnsureDefaultsIncluded(FishItemNames, text);
EnableAutoRestockMeat = config.Bind<bool>("Meat", "EnableAutoRestockMeat", true, LocalizationManager.Instance.GetLocalizedText("config.enable_auto_restock_meat_desc"));
string text2 = "Meat";
MeatItemNames = config.Bind<string>("Meat", "MeatItemNames", text2, LocalizationManager.Instance.GetLocalizedText("config.meat_item_names_desc"));
EnsureDefaultsIncluded(MeatItemNames, text2);
EnableAutoRestockPotion = config.Bind<bool>("Potion", "EnableAutoRestockPotion", true, LocalizationManager.Instance.GetLocalizedText("config.enable_auto_restock_potion_desc"));
string text3 = "Health Potion,Love Potion,Pleasure Potion,Stamina Potion";
PotionItemNames = config.Bind<string>("Potion", "PotionItemNames", text3, LocalizationManager.Instance.GetLocalizedText("config.potion_item_names_desc"));
EnsureDefaultsIncluded(PotionItemNames, text3);
EnableAutoRestockStatue = config.Bind<bool>("Statue", "EnableAutoRestockStatue", true, LocalizationManager.Instance.GetLocalizedText("config.enable_auto_restock_statue_desc"));
string text4 = "Man Statue,Senator Statue,Soldier Statue,Woman Statue";
StatueItemNames = config.Bind<string>("Statue", "StatueItemNames", text4, LocalizationManager.Instance.GetLocalizedText("config.statue_item_names_desc"));
EnsureDefaultsIncluded(StatueItemNames, text4);
EnableAutoRestockWeapon = config.Bind<bool>("Weapon", "EnableAutoRestockWeapon", true, LocalizationManager.Instance.GetLocalizedText("config.enable_auto_restock_weapon_desc"));
string text5 = "Short Sword,Falchion,Knight Sword,Commander Sword,Ornate Sword,Nomad Bow,Short Bow,Red Bow,Amazon Bow";
WeaponItemNames = config.Bind<string>("Weapon", "WeaponItemNames", text5, LocalizationManager.Instance.GetLocalizedText("config.weapon_item_names_desc"));
EnsureDefaultsIncluded(WeaponItemNames, text5);
}
public static bool ShouldAutoRestock()
{
if (EnableMod.Value)
{
return EnableAutoRestock.Value;
}
return false;
}
public static bool ShouldAutoRestockPotion()
{
if (EnableMod.Value)
{
return EnableAutoRestockPotion.Value;
}
return false;
}
public static bool ShouldAutoRestockStatue()
{
if (EnableMod.Value)
{
return EnableAutoRestockStatue.Value;
}
return false;
}
public static bool ShouldAutoRestockMeat()
{
if (EnableMod.Value)
{
return EnableAutoRestockMeat.Value;
}
return false;
}
public static bool ShouldAutoRestockWeapon()
{
if (EnableMod.Value)
{
return EnableAutoRestockWeapon.Value;
}
return false;
}
private static void EnsureDefaultsIncluded(ConfigEntry<string> entry, string defaultNames)
{
if (entry == null || string.IsNullOrWhiteSpace(defaultNames))
{
return;
}
List<string> list = (from n in defaultNames.Split(new char[1] { ',' })
select n.Trim() into n
where n.Length > 0
select n).ToList();
if (list.Count == 0)
{
return;
}
List<string> list2 = (string.IsNullOrWhiteSpace(entry.Value) ? new List<string>() : (from n in entry.Value.Split(new char[1] { ',' })
select n.Trim() into n
where n.Length > 0
select n).ToList());
HashSet<string> hashSet = new HashSet<string>(list2, StringComparer.OrdinalIgnoreCase);
bool flag = false;
foreach (string item in list)
{
if (!hashSet.Contains(item))
{
list2.Add(item);
hashSet.Add(item);
flag = true;
}
}
if (flag || string.IsNullOrWhiteSpace(entry.Value))
{
entry.Value = string.Join(",", list2);
}
}
}
}