Decompiled source of AutoPriceAdjust v1.0.0

BepInEx/plugins/OldMarket.AutoPriceAdjust.dll

Decompiled a month ago
using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using BepInEx;
using HarmonyLib;
using Unity.Netcode;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: AssemblyTitle("OldMarket.AutoPriceMod")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("OldMarket.AutoPriceMod")]
[assembly: AssemblyCopyright("Copyright ©  2025")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("dca4e67f-7575-4393-910c-497bf8376d06")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")]
[assembly: AssemblyVersion("1.0.0.0")]
namespace OldMarketSimulatorMods;

[BepInPlugin("yourname.oldmarketsim.autoprice", "Old Market Simulator Auto Price", "1.0.0")]
public class AutoPricePlugin : BaseUnityPlugin
{
	public const string PluginGuid = "yourname.oldmarketsim.autoprice";

	public const string PluginName = "Old Market Simulator Auto Price";

	public const string PluginVersion = "1.0.0";

	private Harmony _harmony;

	private void Awake()
	{
		//IL_0006: Unknown result type (might be due to invalid IL or missing references)
		//IL_0010: Expected O, but got Unknown
		_harmony = new Harmony("yourname.oldmarketsim.autoprice");
		_harmony.PatchAll();
	}
}
internal static class AutoPriceHelper
{
	public static void AdjustAllPrices(GameManager gameManager, string reason)
	{
		if ((Object)(object)gameManager == (Object)null || !((NetworkBehaviour)gameManager).IsServer || !gameManager.IsWorldLoaded())
		{
			return;
		}
		Dictionary<long, int> productPricesServer = gameManager.GetProductPricesServer();
		if (productPricesServer == null || productPricesServer.Count == 0)
		{
			return;
		}
		foreach (long item in new List<long>(productPricesServer.Keys))
		{
			ItemSO itemById = gameManager.GetItemById(item);
			ProductSO val = (ProductSO)(object)((itemById is ProductSO) ? itemById : null);
			if (!((Object)(object)val == (Object)null))
			{
				int recommendedPrice = gameManager.GetRecommendedPrice(val);
				if (recommendedPrice >= 0)
				{
					productPricesServer[item] = recommendedPrice;
				}
			}
		}
		Item[] array = Object.FindObjectsOfType<Item>();
		foreach (Item val2 in array)
		{
			if (!((Object)(object)val2 == (Object)null) && !((Object)(object)val2.itemSO == (Object)null) && productPricesServer.TryGetValue(val2.itemSO.id, out var value))
			{
				val2.sellingPriceForTag.Value = value;
			}
		}
	}
}
[HarmonyPatch(typeof(GameManager), "OnDayChanged")]
internal static class GameManager_OnDayChanged_AutoPricePatch
{
	private static void Postfix(GameManager __instance, int previous, int current)
	{
		AutoPriceHelper.AdjustAllPrices(__instance, "OnDayChanged");
	}
}
[HarmonyPatch(typeof(GameManager), "CheckDay")]
internal static class GameManager_CheckDay_AutoPricePatch
{
	private static bool _alreadyAdjustedOnLoad;

	private static void Postfix(GameManager __instance)
	{
		if (!_alreadyAdjustedOnLoad)
		{
			AutoPriceHelper.AdjustAllPrices(__instance, "CheckDayInitial");
			_alreadyAdjustedOnLoad = true;
		}
	}
}