using BepInEx; using BepInEx.Configuration; using BepInEx.Logging; using BepInEx.Unity.IL2CPP; using HarmonyLib; using Il2CppInterop.Runtime.Injection; using Il2CppSystem.Collections.Generic; using MyBox; using UnityEngine; using UnityEngine.Events; using UnityEngine.SceneManagement; using KeyCode = BepInEx.Unity.IL2CPP.UnityEngine.KeyCode; namespace AutoPriceUpdater; [BepInPlugin(PLUGIN_GUID, PLUGIN_NAME, PLUGIN_VERSION)] public class Plugin : BasePlugin { public const string PLUGIN_GUID = "de.mpburgmann.AutoPriceUpdater"; public const string PLUGIN_NAME = "Auto Price Updater"; public const string PLUGIN_VERSION = "1.1.0"; public static new ManualLogSource Log; private static ConfigEntry EnableAutoUpdate; private static ConfigEntry AmountToAdd; public static ConfigEntry UpdateKey; private static List m_CachedDisplaySlots = new List(250); public override void Load() { Log = base.Log; Log.LogInfo($"Loading {PLUGIN_NAME} v{PLUGIN_VERSION}"); Harmony harmony = new(PLUGIN_GUID); harmony.PatchAll(); EnableAutoUpdate = Config.Bind("Settings", "Enabled", true, "If enabled, prices will be automatically updated at the start of each day."); UpdateKey = Config.Bind("Settings", "UpdateKey", KeyCode.F9, "Key to manually update prices. Not working when Enabled is false."); AmountToAdd = Config.Bind("Price Settings", "Amount To Add", 0.1f, "Amount to add to market price. Can be negative."); SceneManager.sceneLoaded += (UnityAction) OnSceneLoaded; Log.LogInfo($"{PLUGIN_NAME} loaded successfully"); } public static void UpdatePrice() { if(!EnableAutoUpdate.Value) return; List pricesSetByPlayer = Singleton.Instance.Price.PricesSetByPlayer; foreach (Pricing pricing in pricesSetByPlayer) { pricing.Price = pricing.MarketPrice + AmountToAdd.Value; Log.LogInfo($"Updated price for product ID {pricing.ProductID} to {pricing.Price}"); if(Singleton.Instance.GetDisplaySlots(pricing.ProductID, false, m_CachedDisplaySlots) > 0) { foreach (DisplaySlot slot in m_CachedDisplaySlots) { slot.PricingChanged(pricing.ProductID); } } } Singleton.Instance.PlayCheckoutWarningSFX(Singleton.Instance.transform.position); } public static void SetMissingPrices() { List products = Singleton.Instance.Products; List pricesSetByPlayer = Singleton.Instance.Price.PricesSetByPlayer; foreach (ProductSO product in products) { bool priceExists = false; foreach (Pricing pricing in pricesSetByPlayer) { if (pricing.ProductID == product.ID) { priceExists = true; break; } } if (!priceExists) { pricesSetByPlayer.Add(new Pricing(product.ID, product.BasePrice)); Log.LogInfo($"Set missing price for product ID {product.ID} to base price {product.BasePrice}"); } } } private static void OnSceneLoaded(Scene scene, LoadSceneMode mode) { if (scene.name == "Main Scene") { ClassInjector.RegisterTypeInIl2Cpp(); GameObject gameObject = new("AutoPriceUpdaterBehaviour"); Object.DontDestroyOnLoad(gameObject); gameObject.AddComponent(); } if(scene.name == "Main Menu") { Object gameObject = GameObject.Find("AutoPriceUpdaterBehaviour"); if(gameObject != null) { Object.Destroy(gameObject); } } } [HarmonyPatch(typeof(DayCycleManager), "StartNextDay")] private static class DayCycleManager_StartNextDay_Patch { [HarmonyPostfix] private static void Postfix() { Log.LogInfo("StartNextDay triggered"); UpdatePrice(); } } }