Code updates
This commit is contained in:
parent
6e2d2fac98
commit
eefc098b20
6 changed files with 109 additions and 8 deletions
|
|
@ -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<MeshRenderer>().sharedMaterials)
|
||||
foreach (var item1 in pack.GetComponentInChildren<MeshRenderer>().sharedMaterials)
|
||||
{
|
||||
item1.mainTexture = texture;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@
|
|||
<TargetFramework>netstandard2.1</TargetFramework>
|
||||
<AssemblyName>ChangeCurrency</AssemblyName>
|
||||
<Description>My first plugin</Description>
|
||||
<Version>2.2.0</Version>
|
||||
<Version>2.4.0</Version>
|
||||
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
|
||||
<LangVersion>latest</LangVersion>
|
||||
</PropertyGroup>
|
||||
|
|
@ -26,19 +26,34 @@
|
|||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Reference Include="Accessibility">
|
||||
<HintPath>D:\SteamLibrary\steamapps\common\Supermarket Simulator\Supermarket Simulator_Data\Managed\Accessibility.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="Assembly-CSharp" Publicize="true">
|
||||
<HintPath>D:\SteamLibrary\steamapps\common\Supermarket Simulator\Supermarket Simulator_Data\Managed\Assembly-CSharp.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="Assembly-CSharp-firstpass" Publicize="true">
|
||||
<HintPath>D:\SteamLibrary\steamapps\common\Supermarket Simulator\Supermarket Simulator_Data\Managed\Assembly-CSharp-firstpass.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="AYellowpaper.SerializedCollections" Publicize="true">
|
||||
<HintPath>D:\SteamLibrary\steamapps\common\Supermarket Simulator\Supermarket Simulator_Data\Managed\AYellowpaper.SerializedCollections.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="LeanCommon" Publicize="true">
|
||||
<HintPath>D:\SteamLibrary\steamapps\common\Supermarket Simulator\Supermarket Simulator_Data\Managed\LeanCommon.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="LeanPool" Publicize="true">
|
||||
<HintPath>D:\SteamLibrary\steamapps\common\Supermarket Simulator\Supermarket Simulator_Data\Managed\LeanPool.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="MyBox" Publicize="true">
|
||||
<HintPath>D:\SteamLibrary\steamapps\common\Supermarket Simulator\Supermarket Simulator_Data\Managed\MyBox.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="Unity.Localization">
|
||||
<Reference Include="Unity.Localization" Publicize="true">
|
||||
<HintPath>D:\SteamLibrary\steamapps\common\Supermarket Simulator\Supermarket Simulator_Data\Managed\Unity.Localization.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="Unity.TextMeshPro">
|
||||
<Reference Include="Unity.TextMeshPro" Publicize="true">
|
||||
<HintPath>D:\SteamLibrary\steamapps\common\Supermarket Simulator\Supermarket Simulator_Data\Managed\Unity.TextMeshPro.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="UnityEngine.UI">
|
||||
<Reference Include="UnityEngine.UI" Publicize="true">
|
||||
<HintPath>D:\SteamLibrary\steamapps\common\Supermarket Simulator\Supermarket Simulator_Data\Managed\UnityEngine.UI.dll</HintPath>
|
||||
</Reference>
|
||||
</ItemGroup>
|
||||
|
|
|
|||
14
Patches/PriceManager_ChangeCurrentCost_Patch.cs
Normal file
14
Patches/PriceManager_ChangeCurrentCost_Patch.cs
Normal 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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -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;
|
||||
// }
|
||||
//}
|
||||
}
|
||||
|
|
@ -36,6 +36,7 @@ namespace CurrencyChanger2
|
|||
public static ConfigEntry<string> CurrencySuffix { get; set; }
|
||||
public static ConfigEntry<string> CurrencyDecimalSeperator { get; set; }
|
||||
public static ConfigEntry<float> CurrencyValueFactor { get; set; }
|
||||
public static ConfigEntry<bool> ApplyValueFactorRetroactively { get; set; }
|
||||
|
||||
|
||||
public static ConfigEntry<CardTextureType> 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.");
|
||||
|
||||
|
|
|
|||
30
PriceChanger.cs
Normal file
30
PriceChanger.cs
Normal file
|
|
@ -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<int, ConfigEntry<float>> ConfigEntries;
|
||||
public static ConfigEntry<bool> 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;
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue