Initial Commit
This commit is contained in:
5
.gitignore
vendored
Normal file
5
.gitignore
vendored
Normal file
@@ -0,0 +1,5 @@
|
||||
.git/
|
||||
.vs/
|
||||
bin/
|
||||
obj/
|
||||
*.sln
|
||||
39
AutoPriceUpdater.csproj
Normal file
39
AutoPriceUpdater.csproj
Normal file
@@ -0,0 +1,39 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net6.0</TargetFramework>
|
||||
<AssemblyName>AutoPriceUpdater</AssemblyName>
|
||||
<Product>Auto Price Updater</Product>
|
||||
<Version>1.0.0</Version>
|
||||
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
|
||||
<LangVersion>latest</LangVersion>
|
||||
<RestoreAdditionalProjectSources>
|
||||
https://api.nuget.org/v3/index.json;
|
||||
https://nuget.bepinex.dev/v3/index.json;
|
||||
https://nuget.samboy.dev/v3/index.json
|
||||
</RestoreAdditionalProjectSources>
|
||||
<RootNamespace>AutoPriceUpdater</RootNamespace>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="BepInEx.Unity.IL2CPP" Version="6.0.0-be.*" IncludeAssets="compile" />
|
||||
<PackageReference Include="BepInEx.PluginInfoProps" Version="2.*" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Reference Include="Assembly-CSharp" Publicize="true">
|
||||
<HintPath>..\lib\Assembly-CSharp.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="MyBox" Publicize="true">
|
||||
<HintPath>..\lib\MyBox.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="Il2Cppmscorlib" Publicize="true">
|
||||
<HintPath>..\lib\Il2Cppmscorlib.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="UnityEngine.CoreModule" Publicize="true">
|
||||
<HintPath>..\lib\UnityEngine.CoreModule.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="PhotonUnityNetworking" Publicize="true">
|
||||
<HintPath>..\lib\PhotonUnityNetworking.dll</HintPath>
|
||||
</Reference>
|
||||
</ItemGroup>
|
||||
</Project>
|
||||
34
Behaviour.cs
Normal file
34
Behaviour.cs
Normal file
@@ -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<IDManager>.Instance.Products.Count - Singleton<SaveManager>.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;
|
||||
}
|
||||
}
|
||||
}
|
||||
111
Plugin.cs
Normal file
111
Plugin.cs
Normal file
@@ -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<KeyCode> UpdateKey;
|
||||
private static List<DisplaySlot> m_CachedDisplaySlots = new List<DisplaySlot>(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<Scene, LoadSceneMode>) OnSceneLoaded;
|
||||
|
||||
Log.LogInfo($"Plugin {PLUGIN_GUID} is loaded!");
|
||||
}
|
||||
|
||||
public static void UpdatePrice()
|
||||
{
|
||||
List<Pricing> pricesSetByPlayer = Singleton<SaveManager>.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<DisplayManager>.Instance.GetDisplaySlots(pricing.ProductID, false, m_CachedDisplaySlots) > 0)
|
||||
{
|
||||
foreach (DisplaySlot slot in m_CachedDisplaySlots)
|
||||
{
|
||||
slot.PricingChanged(pricing.ProductID);
|
||||
}
|
||||
}
|
||||
}
|
||||
Singleton<SFXManager>.Instance.PlayCheckoutWarningSFX(Singleton<PlayerInstance>.Instance.transform.position);
|
||||
}
|
||||
|
||||
public static void SetMissingPrices()
|
||||
{
|
||||
List<ProductSO> products = Singleton<IDManager>.Instance.Products;
|
||||
List<Pricing> pricesSetByPlayer = Singleton<SaveManager>.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<Behaviour>();
|
||||
GameObject gameObject = new("AutoPriceUpdaterBehaviour");
|
||||
Object.DontDestroyOnLoad(gameObject);
|
||||
gameObject.AddComponent<Behaviour>();
|
||||
}
|
||||
|
||||
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();
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user