commit 96d67285ab7a50f031a6ac1a76c25602f6526291 Author: Marc Philipp Burgmann Date: Fri Jan 23 18:55:35 2026 +0100 Initial Commit diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..a4f5d33 --- /dev/null +++ b/.gitignore @@ -0,0 +1,5 @@ +.git/ +.vs/ +bin/ +obj/ +*.sln \ No newline at end of file diff --git a/AutoPriceUpdater.csproj b/AutoPriceUpdater.csproj new file mode 100644 index 0000000..1bd8a3e --- /dev/null +++ b/AutoPriceUpdater.csproj @@ -0,0 +1,39 @@ + + + + net6.0 + AutoPriceUpdater + Auto Price Updater + 1.0.0 + true + latest + + https://api.nuget.org/v3/index.json; + https://nuget.bepinex.dev/v3/index.json; + https://nuget.samboy.dev/v3/index.json + + AutoPriceUpdater + + + + + + + + + ..\lib\Assembly-CSharp.dll + + + ..\lib\MyBox.dll + + + ..\lib\Il2Cppmscorlib.dll + + + ..\lib\UnityEngine.CoreModule.dll + + + ..\lib\PhotonUnityNetworking.dll + + + diff --git a/Behaviour.cs b/Behaviour.cs new file mode 100644 index 0000000..751bac5 --- /dev/null +++ b/Behaviour.cs @@ -0,0 +1,34 @@ + +using BepInEx.Unity.IL2CPP.UnityEngine; +using MyBox; +using UnityEngine; + +namespace AutoPriceUpdater; +public class Behaviour : MonoBehaviour +{ + private static bool Once = false; + private void Start() + { + Plugin.Log.LogInfo("AutoPriceUpdater Behaviour started."); + int num = Singleton.Instance.Products.Count - Singleton.Instance.Price.PricesSetByPlayer.Count; + if (num > 0) + { + Plugin.Log.LogWarning($"There are {num} products without player-set prices. Updating prices..."); + Plugin.SetMissingPrices(); + } + Plugin.UpdatePrice(); + } + + private void Update() + { + if(Input.GetKeyInt(Plugin.UpdateKey.Value) && !Once) + { + Plugin.UpdatePrice(); + Once = true; + } + else if(!Input.GetKeyInt(Plugin.UpdateKey.Value) && Once) + { + Once = false; + } + } +} \ No newline at end of file diff --git a/Plugin.cs b/Plugin.cs new file mode 100644 index 0000000..3548f32 --- /dev/null +++ b/Plugin.cs @@ -0,0 +1,111 @@ +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.0.0"; + public static new ManualLogSource Log; + public static ConfigEntry UpdateKey; + private static List m_CachedDisplaySlots = new List(250); + + public override void Load() + { + Log = base.Log; + + Harmony harmony = new(PLUGIN_GUID); + harmony.PatchAll(); + + UpdateKey = Config.Bind("Settings", "UpdateKey", KeyCode.F9); + + SceneManager.sceneLoaded += (UnityAction) OnSceneLoaded; + + Log.LogInfo($"Plugin {PLUGIN_GUID} is loaded!"); + } + + public static void UpdatePrice() + { + List pricesSetByPlayer = Singleton.Instance.Price.PricesSetByPlayer; + foreach (Pricing pricing in pricesSetByPlayer) + { + pricing.Price = pricing.MarketPrice - 0.1f; + 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(); + } + } +} \ No newline at end of file