Code updates

This commit is contained in:
pan.codes 2025-06-08 21:38:33 +02:00
parent 6e2d2fac98
commit eefc098b20
6 changed files with 109 additions and 8 deletions

View file

@ -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;
}
}
}

View file

@ -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<IDManager>.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<PriceManager>.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;
// }
//}
}