Update 2.2.0

- Fixed: $1 coins should now work as expected outside of the newly added coin slots.
- Added: Currency symbols are now also applied to price tags where the price has never been set.
- Added: Currency Value Factor is now applied to Bank Loans.
- Added: Currency Value Factor is now applied to Store Sections.
- Added: Currency Value Factor is now applied to Storage Sections.
- Added: Currency Value Factor is now applied to Furniture Prices.
- Added: Currency Value Factor is now applied to the amount of money a new save game starts with.
- Added: Currency Value Factor is now applied to Restocker hiring & daily cost.
- Added: Currency Value Factor is now applied to Cashier hiring & daily cost.
- Added: Price Rounding, for when a currency doesn't support certain low denominations. You can now configure product prices as well as customer payments to not make you use 1 cent coins, or even coins below $1, if you wish.
- The new feature above has been preconfigured to 5 cents in the config file for the canadian dollar, making that currency's penny obsolete.
- Preconfigured config files have been updated to reflect changes made in this version.
This commit is contained in:
pan.codes 2024-05-05 21:57:31 +02:00
parent 0afdc1d02f
commit 6e2d2fac98
17 changed files with 324 additions and 4 deletions

View file

@ -4,7 +4,7 @@
<TargetFramework>netstandard2.1</TargetFramework>
<AssemblyName>ChangeCurrency</AssemblyName>
<Description>My first plugin</Description>
<Version>2.1.2</Version>
<Version>2.2.0</Version>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<LangVersion>latest</LangVersion>
</PropertyGroup>
@ -32,6 +32,9 @@
<Reference Include="MyBox" Publicize="true">
<HintPath>D:\SteamLibrary\steamapps\common\Supermarket Simulator\Supermarket Simulator_Data\Managed\MyBox.dll</HintPath>
</Reference>
<Reference Include="Unity.Localization">
<HintPath>D:\SteamLibrary\steamapps\common\Supermarket Simulator\Supermarket Simulator_Data\Managed\Unity.Localization.dll</HintPath>
</Reference>
<Reference Include="Unity.TextMeshPro">
<HintPath>D:\SteamLibrary\steamapps\common\Supermarket Simulator\Supermarket Simulator_Data\Managed\Unity.TextMeshPro.dll</HintPath>
</Reference>

View file

@ -0,0 +1,51 @@
using HarmonyLib;
using MyBox;
using System.Collections.Generic;
using System.Reflection;
namespace CurrencyChanger2.Patches
{
[HarmonyPatch(typeof(CashierItem), "Setup")]
public static class CashierItem_Setup_Patch
{
public static bool Done = false;
public static void Postfix(CashierItem __instance)
{
if (!Done)
{
Done = true;
Singleton<IDManager>.Instance.m_Cashiers.ForEach(x => { x.DailyWage *= Plugin.CurrencyValueFactor.Value; x.HiringCost *= Plugin.CurrencyValueFactor.Value; });
}
__instance.m_LocalizedDailyWageText.StringReference.Arguments = new object[]
{
__instance.m_CashierSetup.DailyWage.ToMoneyText(__instance.m_DailyWageText.fontSize)
};
__instance.m_LocalizedDailyWageText.RefreshString();
__instance.m_LocalizedHiringCostText.StringReference.Arguments = new object[]
{
__instance.m_CashierSetup.HiringCost.ToMoneyText(__instance.m_HiringCostText.fontSize)
};
__instance.m_LocalizedHiringCostText.RefreshString();
}
}
[HarmonyPatch(typeof(DayCycleManager), "StartNextDay")]
public static class DayCycleManager_StartNextDay_Patch
{
public static void Postfix() => UpdatePlayerPricing();
public static void UpdatePlayerPricing()
{
Singleton<PriceManager>.Instance.m_PricesSetByPlayer.ForEach(pricing =>
{
pricing.Price = Plugin.Rounder.Round(pricing.Price);
List<DisplaySlot> displaySlots = Singleton<DisplayManager>.Instance.GetDisplaySlots(pricing.ProductID, false);
if (displaySlots != null)
{
foreach (DisplaySlot obj in displaySlots)
{
obj.PricingChanged(pricing.ProductID);
}
}
});
}
}
}

View file

@ -35,7 +35,6 @@ namespace CurrencyChanger2.Patches
TextMeshProUGUI Coin6Text = null;
TextMeshProUGUI Coin7Text = null;
if (!Plugin.MoneyGeneratorDone)
{
Plugin.Bill1.Apply(Singleton<MoneyGenerator>.Instance.m_MoneyPrefabs[5]);

View file

@ -0,0 +1,17 @@
using HarmonyLib;
namespace CurrencyChanger2.Patches
{
[HarmonyPatch(typeof(CustomerPayment), "GenerateRandomPayment")]
public static class CustomerPayment_GenerateRandomPayment_Patch
{
public static void Postfix(ref float __result)
{
if(Plugin.Rounder == null)
{
return;
}
__result = Plugin.Rounder.Round(__result);
}
}
}

View file

@ -0,0 +1,16 @@
using HarmonyLib;
using TMPro;
namespace CurrencyChanger2.Patches
{
[HarmonyPatch(typeof(FurnitureSalesItem), "Setup")]
public static class FurnitureSalesItem_Setup_Patch
{
public static void Postfix(FurnitureSalesItem __instance)
{
__instance.transform.GetChild(2).GetChild(4).GetComponent<TextMeshProUGUI>().enableWordWrapping = false;
__instance.transform.GetChild(2).GetChild(4).gameObject.SetActive(false);
__instance.transform.GetChild(2).GetChild(4).gameObject.SetActive(true);
}
}
}

View file

@ -0,0 +1,16 @@
using HarmonyLib;
namespace CurrencyChanger2.Patches
{
[HarmonyPatch(typeof(IDManager), "BankCreditSO")]
public static class IDManager_BankCreditSO_Patch
{
public static bool Done = false;
public static void Prefix(IDManager __instance)
{
if (Done) return;
Done = true;
__instance.Loans.ForEach(x => x.Amount *= Plugin.CurrencyValueFactor.Value);
}
}
}

View file

@ -0,0 +1,16 @@
using HarmonyLib;
namespace CurrencyChanger2.Patches
{
[HarmonyPatch(typeof(IDManager), "FurnitureSO")]
public static class IDManager_FurnitureSO_Patch
{
public static bool Done = false;
public static void Prefix(IDManager __instance)
{
if (Done) return;
Done = true;
__instance.Furnitures.ForEach(x => x.Cost *= Plugin.CurrencyValueFactor.Value);
}
}
}

View file

@ -0,0 +1,16 @@
using HarmonyLib;
namespace CurrencyChanger2.Patches
{
[HarmonyPatch(typeof(IDManager), "ProductLicenseSO")]
public static class IDManager_ProductLicenseSO_Patch
{
public static bool Done = false;
public static void Prefix(IDManager __instance)
{
if (Done) return;
Done = true;
__instance.m_ProductLicenses.ForEach(x => x.PurchasingCost *= Plugin.CurrencyValueFactor.Value);
}
}
}

View file

@ -0,0 +1,17 @@
using HarmonyLib;
using UnityEngine.XR;
namespace CurrencyChanger2.Patches
{
[HarmonyPatch(typeof(IDManager), "SectionSO")]
public static class IDManager_SectionSO_Patch
{
public static bool Done = false;
public static void Prefix(IDManager __instance)
{
if (Done) return;
Done = true;
__instance.Sections.ForEach(x => x.Cost *= Plugin.CurrencyValueFactor.Value);
}
}
}

View file

@ -0,0 +1,16 @@
using HarmonyLib;
namespace CurrencyChanger2.Patches
{
[HarmonyPatch(typeof(IDManager), "StorageSO")]
public static class IDManager_StorageSO_Patch
{
public static bool Done = false;
public static void Prefix(IDManager __instance)
{
if (Done) return;
Done = true;
__instance.StorageSections.ForEach(x => x.Cost *= Plugin.CurrencyValueFactor.Value);
}
}
}

View file

@ -0,0 +1,16 @@
using HarmonyLib;
namespace CurrencyChanger2.Patches
{
[HarmonyPatch(typeof(PriceTag), "EnableTag")]
public static class PriceTag_EnableTag_Patch
{
public static void Postfix(PriceTag __instance)
{
if(__instance.m_PriceText.text == "$-")
{
__instance.m_PriceText.text = Plugin.CurrencyPrefix.Value + "-" + Plugin.CurrencySuffix.Value;
}
}
}
}

View file

@ -0,0 +1,10 @@
using HarmonyLib;
namespace CurrencyChanger2.Patches
{
[HarmonyPatch(typeof(PricingInteraction), "ClosePricingMenu")]
public static class PricingInteraction_ClosePricingMenu_Patch
{
public static void Postfix() => DayCycleManager_StartNextDay_Patch.UpdatePlayerPricing();
}
}

View file

@ -0,0 +1,29 @@
using HarmonyLib;
using MyBox;
namespace CurrencyChanger2.Patches
{
[HarmonyPatch(typeof(RestockerItem), "Setup")]
public static class RestockerItem_Setup_Patch
{
public static bool Done = false;
public static void Postfix(RestockerItem __instance)
{
if (!Done)
{
Done = true;
Singleton<IDManager>.Instance.m_Restockers.ForEach(x => { x.DailyWage *= Plugin.CurrencyValueFactor.Value; x.HiringCost *= Plugin.CurrencyValueFactor.Value; });
}
__instance.m_LocalizedDailyWageText.StringReference.Arguments = new object[]
{
__instance.m_RestockerSetup.DailyWage.ToMoneyText(__instance.m_DailyWageText.fontSize)
};
__instance.m_LocalizedDailyWageText.RefreshString();
__instance.m_LocalizedHiringCostText.StringReference.Arguments = new object[]
{
__instance.m_RestockerSetup.HiringCost.ToMoneyText(__instance.m_HiringCostText.fontSize)
};
__instance.m_LocalizedHiringCostText.RefreshString();
}
}
}

View file

@ -0,0 +1,13 @@
using HarmonyLib;
namespace CurrencyChanger2.Patches
{
[HarmonyPatch(typeof(SaveManager), "Clear")]
public static class SaveManager_Clear_Patch
{
public static void Postfix(SaveManager __instance)
{
__instance.Progression.Money *= Plugin.CurrencyValueFactor.Value;
}
}
}

View file

@ -0,0 +1,13 @@
using HarmonyLib;
namespace CurrencyChanger2.Patches
{
[HarmonyPatch(typeof(StorageTab), "Start")]
public static class StorageTab_Start_Patch
{
public static void Prefix(StorageTab __instance)
{
__instance.m_Cost *= Plugin.CurrencyValueFactor.Value;
}
}
}

View file

@ -9,6 +9,7 @@ using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Reflection;
using TMPro;
using UnityEngine;
using UnityEngine.SceneManagement;
@ -55,6 +56,8 @@ namespace CurrencyChanger2
public static ConfigComp<CoinTextureType> Coin5 { get; set; }
public static ConfigComp<CoinTextureType> Coin6 { get; set; }
public static ConfigComp<CoinTextureType> Coin7 { get; set; }
public static PriceRounder Rounder { get; set; }
private void Awake()
{
StaticLogger = Logger;
@ -78,6 +81,19 @@ namespace CurrencyChanger2
Harmony harmony = new Harmony(PluginInfo.PLUGIN_GUID);
harmony.PatchAll();
//HarmonyMethod eCommerce = new HarmonyMethod(typeof(Plugin).GetMethod("eCommercePatch"));
//if(Assembly.Load("eCommerce") is Assembly assembly)
//{
// if(assembly.GetType("eCommerce", false) is Type eCommerceType)
// {
// if(eCommerceType.GetMethod("OnLateUpdate") is MethodInfo method)
// {
// Logger.LogWarning("eCommerce is present - applying patch");
// harmony.Patch(method, postfix: eCommerce);
// }
// }
//}
SceneManager.sceneLoaded += (a, b) =>
{
if (SceneManager.GetActiveScene().name == "Main Menu")
@ -87,7 +103,33 @@ namespace CurrencyChanger2
MoneyGeneratorDone = false;
}
};
Rounder = new PriceRounder(Config);
}
//public static Dictionary<object, List<int>> updatedPrices = new();
//public void eCommercePatch(object __instance)
//{
// object order = __instance.GetType().GetField("currentOrder").GetValue(__instance);
// //Logger.LogInfo(order == null ? "Order is missing" : "Order was found");
// Dictionary<int, float> ProductsPrices = (Dictionary<int, float>)order.GetType().GetField("ProductsPrices").GetValue(order);
// //Logger.LogInfo(ProductsPrices == null ? "Dictionary is missing" : "Dictionary was found");
// foreach(var kvp in ProductsPrices)
// {
// if(updatedPrices.ContainsKey(order))
// {
// if (updatedPrices[order].Contains(kvp.Key))
// {
// continue;
// }
// } else
// {
// updatedPrices.Add(order, new());
// }
// ProductsPrices[kvp.Key] *= CurrencyValueFactor.Value;
// updatedPrices[order].Add(kvp.Key);
// }
//}
private void InitConfig()
{
EnableAdditionalCoinCompartments = Config.Bind("Currency Changer", "Enable Additional Coin Compartments", false, "Turns the $1 bill compartment into two coin compartments, 6 and 7, for additional coins.\nThis disables Bill Compartment 1 and enables Coin Compartments 6 and 7.");
@ -136,7 +178,7 @@ namespace CurrencyChanger2
Bill1.transform.localPosition = new Vector3(0, -10, 0);
CheckoutChangeManager ccm = __instance.transform.parent.parent.GetComponent<CheckoutChangeManager>();
List<MoneyPack> MoneyPacks = ccm.m_MoneyPacks == null ? new() : ccm.m_MoneyPacks.ToList();
MoneyPacks.RemoveAll(x => x && x.Value == 1f);
MoneyPacks.RemoveAll(x => x && x.gameObject.name == "1 Dollar Pack");
Bill1 = null;
Money prefab;
@ -181,7 +223,7 @@ namespace CurrencyChanger2
if (!MoneyGeneratorDone)
{
List<Money> MoneyPrefabs = Singleton<MoneyGenerator>.Instance.m_MoneyPrefabs == null ? new() : Singleton<MoneyGenerator>.Instance.m_MoneyPrefabs.ToList();
MoneyPrefabs.RemoveAll(x => x && x.Value == 1f);
MoneyPrefabs.RemoveAll(x => x && x.gameObject.name == "1 Dollar Variant");
Coin6Prefab = GameObject.Instantiate(Singleton<MoneyGenerator>.Instance.m_MoneyPrefabs[4].gameObject).GetComponent<Money>();
Coin7Prefab = GameObject.Instantiate(Singleton<MoneyGenerator>.Instance.m_MoneyPrefabs[4].gameObject).GetComponent<Money>();
ApplyNewRenderers(Coin6Prefab.GetComponent<MeshRenderer>());

30
PriceRounder.cs Normal file
View file

@ -0,0 +1,30 @@
using BepInEx.Configuration;
using System;
namespace CurrencyChanger2
{
public class PriceRounder
{
public enum RoundingModeType { ROUND_UP, ROUND_DOWN, AUTOMATIC }
public ConfigEntry<float> RoundingPoint { get;set; }
public ConfigEntry<RoundingModeType> RoundingMode { get;set; }
public PriceRounder(ConfigFile Config)
{
RoundingPoint = Config.Bind("Price Rounding", "Rounding Point", 0.01f, "Does your currency not have denominations for some small values?\nAdjust this to define the smallest possible denomination, and have all prices adjust to that.");
RoundingMode = Config.Bind("Price Rounding", "Rounding Mode", RoundingModeType.AUTOMATIC, "What should happen if a price does not match the indicated rounding point?");
}
public float Round(float price)
{
float value = price / RoundingPoint.Value;
switch(RoundingMode.Value)
{
default:
case RoundingModeType.AUTOMATIC: value = (float)Math.Round(value); break;
case RoundingModeType.ROUND_UP: value = (float)Math.Ceiling(value); break;
case RoundingModeType.ROUND_DOWN: value = (float)Math.Floor(value); break;
}
value *= RoundingPoint.Value;
return value;
}
}
}