From eefc098b20ff852a441e558f3d169b9df5681762 Mon Sep 17 00:00:00 2001 From: Jonathan Riedel Date: Sun, 8 Jun 2025 21:38:33 +0200 Subject: [PATCH] Code updates --- Config/Plugin.ConfigComp.cs | 2 +- CurrencyChanger2.csproj | 23 ++++++++-- .../PriceManager_ChangeCurrentCost_Patch.cs | 14 ++++++ Patches/PriceManager_CurrentCost_Patch.cs | 46 +++++++++++++++++-- Plugin.cs | 2 + PriceChanger.cs | 30 ++++++++++++ 6 files changed, 109 insertions(+), 8 deletions(-) create mode 100644 Patches/PriceManager_ChangeCurrentCost_Patch.cs create mode 100644 PriceChanger.cs diff --git a/Config/Plugin.ConfigComp.cs b/Config/Plugin.ConfigComp.cs index d40f536..8cbed50 100644 --- a/Config/Plugin.ConfigComp.cs +++ b/Config/Plugin.ConfigComp.cs @@ -54,7 +54,7 @@ namespace CurrencyChanger2 var texture = GetTexture(); if (texture == null) return this; Plugin.StaticLogger.LogWarning("Applying " + Enum.GetName(typeof(TTexture), Texture.Value) + " texture to " + pack.gameObject.name + " (Money)"); - foreach (var item1 in pack.GetComponent().sharedMaterials) + foreach (var item1 in pack.GetComponentInChildren().sharedMaterials) { item1.mainTexture = texture; } diff --git a/CurrencyChanger2.csproj b/CurrencyChanger2.csproj index e3c94fa..06a43a5 100644 --- a/CurrencyChanger2.csproj +++ b/CurrencyChanger2.csproj @@ -4,7 +4,7 @@ netstandard2.1 ChangeCurrency My first plugin - 2.2.0 + 2.4.0 true latest @@ -26,19 +26,34 @@ + + D:\SteamLibrary\steamapps\common\Supermarket Simulator\Supermarket Simulator_Data\Managed\Accessibility.dll + D:\SteamLibrary\steamapps\common\Supermarket Simulator\Supermarket Simulator_Data\Managed\Assembly-CSharp.dll + + D:\SteamLibrary\steamapps\common\Supermarket Simulator\Supermarket Simulator_Data\Managed\Assembly-CSharp-firstpass.dll + + + D:\SteamLibrary\steamapps\common\Supermarket Simulator\Supermarket Simulator_Data\Managed\AYellowpaper.SerializedCollections.dll + + + D:\SteamLibrary\steamapps\common\Supermarket Simulator\Supermarket Simulator_Data\Managed\LeanCommon.dll + + + D:\SteamLibrary\steamapps\common\Supermarket Simulator\Supermarket Simulator_Data\Managed\LeanPool.dll + D:\SteamLibrary\steamapps\common\Supermarket Simulator\Supermarket Simulator_Data\Managed\MyBox.dll - + D:\SteamLibrary\steamapps\common\Supermarket Simulator\Supermarket Simulator_Data\Managed\Unity.Localization.dll - + D:\SteamLibrary\steamapps\common\Supermarket Simulator\Supermarket Simulator_Data\Managed\Unity.TextMeshPro.dll - + D:\SteamLibrary\steamapps\common\Supermarket Simulator\Supermarket Simulator_Data\Managed\UnityEngine.UI.dll diff --git a/Patches/PriceManager_ChangeCurrentCost_Patch.cs b/Patches/PriceManager_ChangeCurrentCost_Patch.cs new file mode 100644 index 0000000..a69238f --- /dev/null +++ b/Patches/PriceManager_ChangeCurrentCost_Patch.cs @@ -0,0 +1,14 @@ +using HarmonyLib; +using System.Linq; + +namespace CurrencyChanger2.Patches +{ + [HarmonyPatch(typeof(PriceManager), "ChangeCurrentCost")] + public static class PriceManager_ChangeCurrentCost_Patch + { + public static void Postfix(int productID, PriceManager __instance) + { + if(PriceChanger.Override.Value) PriceChanger.ConfigEntries[productID].Value = __instance.m_CurrentCosts.FirstOrDefault((Pricing i) => i.ProductID == productID).Price; + } + } +} diff --git a/Patches/PriceManager_CurrentCost_Patch.cs b/Patches/PriceManager_CurrentCost_Patch.cs index ac9a40e..8588c12 100644 --- a/Patches/PriceManager_CurrentCost_Patch.cs +++ b/Patches/PriceManager_CurrentCost_Patch.cs @@ -1,13 +1,53 @@ -using HarmonyLib; +using BepInEx.Configuration; +using HarmonyLib; +using MyBox; +using System.Collections.Generic; +using UnityEngine; namespace CurrencyChanger2.Patches { [HarmonyPatch(typeof(PriceManager), "CurrentCost")] public static class PriceManager_CurrentCost_Patch { - public static void Postfix(ref float __result) + public static void Postfix(int productID, ref float __result) { + if (PriceChanger.ConfigEntries == null) + { + PriceChanger.ConfigEntries = new(); + Singleton.Instance.Products.ForEach(product => + { + PriceChanger.Log.LogInfo("Registering Config Entry for " + product.ProductBrand + " " + product.ProductName); + PriceChanger.ConfigEntries[product.ID] = PriceChanger.Config.Bind("Product Base Prices", "Product " + product.ID, product.BasePrice, "The base price of " + product.ProductBrand + " " + product.ProductName + " (ID: " + product.ID + ")"); + }); + } + __result = PriceChanger.ConfigEntries[productID].Value; __result *= Plugin.CurrencyValueFactor.Value; } } -} + [HarmonyPatch(typeof(PriceManager), "PreviousCost")] + public static class PriceManager_PreviousCost_Patch + { + public static void Postfix(int productID, ref float __result) + { + if (Plugin.ApplyValueFactorRetroactively.Value && !Mathf.Approximately(__result, -1f)) + __result *= Plugin.CurrencyValueFactor.Value; + } + } + [HarmonyPatch(typeof(PricingItem), "Setup")] + public static class PricingItem_Setup_Patch + { + public static void Prefix(Pricing data) + { + data.Price = Singleton.Instance.CurrentCost(data.ProductID); + } + } + //[HarmonyPatch(typeof(PriceManager), "AverageCost")] + //public static class PriceManager_AverageCost_Patch + //{ + // public static void Postfix(int productID, ref float __result) + // { + // if (Plugin.ApplyValueFactorRetroactively.Value) + // __result *= Plugin.CurrencyValueFactor.Value; + // } + //} +} \ No newline at end of file diff --git a/Plugin.cs b/Plugin.cs index 6d6190f..ef737a6 100644 --- a/Plugin.cs +++ b/Plugin.cs @@ -36,6 +36,7 @@ namespace CurrencyChanger2 public static ConfigEntry CurrencySuffix { get; set; } public static ConfigEntry CurrencyDecimalSeperator { get; set; } public static ConfigEntry CurrencyValueFactor { get; set; } + public static ConfigEntry ApplyValueFactorRetroactively { get; set; } public static ConfigEntry CreditCardFront { get; set; } @@ -140,6 +141,7 @@ namespace CurrencyChanger2 CurrencySuffix = Config.Bind("Currency Settings", "Suffix", "", "The currency symbol (or arbitrary string) to use after the value, where a euro sign might for example be."); CurrencyDecimalSeperator = Config.Bind("Currency Settings", "Decimal Seperator", ".", "What symbol to use to seperate the whole number part from the fractional part."); CurrencyValueFactor = Config.Bind("Currency Settings", "Value Factor", 1f, "Multiplies all product costs and market prices by the defined number."); + ApplyValueFactorRetroactively = Config.Bind("Currency Settings", "Apply Value Factor Retroactively", true, "Whether or not the Value Factor setting should be applied to \"Previous Cost\" in the pricing manager."); VersionNumber = Config.Bind("Info", "Version", "2.0.0", "What version of the plugin this config file was created under.\nDo NOT change this value, or stuff WILL break.\nIf this value is missing, v1.2.1 will be assumed."); diff --git a/PriceChanger.cs b/PriceChanger.cs new file mode 100644 index 0000000..02faf72 --- /dev/null +++ b/PriceChanger.cs @@ -0,0 +1,30 @@ +using BepInEx; +using BepInEx.Configuration; +using BepInEx.Logging; +using MyBox; +using System.Collections.Generic; +using UnityEngine.SceneManagement; + +namespace CurrencyChanger2 +{ + [BepInPlugin(PLUGIN_GUID, PLUGIN_NAME, PLUGIN_VERSION), BepInDependency("ChangeCurrency")] + public class PriceChanger : BaseUnityPlugin + { + public static Dictionary> ConfigEntries; + public static ConfigEntry Override; + public const string PLUGIN_GUID = PluginInfo.PLUGIN_GUID + ".ProductPrices"; + public const string PLUGIN_NAME = PluginInfo.PLUGIN_NAME + " Product Price Changer"; + public const string PLUGIN_VERSION = PluginInfo.PLUGIN_VERSION; + public static new ConfigFile Config { get; set; } + public static ManualLogSource Log { get; set; } + public void Awake() + { + Config = base.Config; + Config.Bind("Info", ".", ".", "This config file allows you to independently define the base prices of every product.\nThis price will be what you end up buying them from the market for,\nbut it will also be what the market value (the recommended selling price) will be calculated based on.\nIf both are configured, the \"Value Factor\" multiplier from the main config will still be applied to these prices."); + Override = Config.Bind("Info", "Allow Ingame Price Changes to override config", true, "By default, the in-game prices will change by up to 20% in either direction on a few randomly selected products every day.\nSince this feature overrides product prices, it causes that to stop working.\nBy setting this to true, the in-game price changes will instead override the ones in this config file.\nThis is irreversible, so make sure to backup the config file if you've put a lot of work into editing it."); + Log = Logger; + + SceneManager.sceneLoaded += (a, b) => ConfigEntries = null; + } + } +}