using System;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using HarmonyLib;
using Random_Sell_Prices.Patches;
using UnityEngine;
[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")]
[assembly: AssemblyVersion("0.0.0.0")]
namespace Random_Sell_Prices
{
[BepInPlugin("BigDaddy.RandomSellPrices", "Random Sell Prices", "1.0.1")]
public class RandomSellPrices : BaseUnityPlugin
{
private const string modGUID = "BigDaddy.RandomSellPrices";
private const string modName = "Random Sell Prices";
private const string modVersion = "1.0.1";
public static ConfigEntry<float> minPercentage;
public static ConfigEntry<float> maxPercentage;
public static ConfigEntry<float> pityPercentage;
public static ConfigEntry<bool> pityEnabled;
private readonly Harmony harmony = new Harmony("BigDaddy.RandomSellPrices");
private static RandomSellPrices Instance;
public static ManualLogSource mls;
private void Awake()
{
if ((Object)(object)Instance == (Object)null)
{
Instance = this;
}
minPercentage = ((BaseUnityPlugin)this).Config.Bind<float>("General", "Minimum Selling Percentage", 0.1f, "Minimum random selling price (NOTE: This value is the decimal form of a percentage i.e. 0.1f = 10%.)");
maxPercentage = ((BaseUnityPlugin)this).Config.Bind<float>("General", "Maximum Selling Percentage", 1.2f, "Maximum random selling price (NOTE: This value is the decimal form of a percentage i.e. 1.2f = 120%.)");
pityEnabled = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "Pity Day Enabled", true, "Whether or not to allow for one pity day, where the sell percentage is at leasr the amount shown below.");
pityPercentage = ((BaseUnityPlugin)this).Config.Bind<float>("General", "Pity Selling Percentage", 0.8f, "At least one day per quota period is guaranteed to be at least this price (NOTE: This value is the decimal form of a percentage i.e. 0.8f = 80%.)");
mls = Logger.CreateLogSource("BigDaddy.RandomSellPrices");
mls.LogInfo((object)"The Random Price Mod has awoken. Patching...");
harmony.PatchAll(typeof(RandomSellPrices));
harmony.PatchAll(typeof(TimeOfDayPatch));
mls.LogInfo((object)"Patching complete!");
}
}
}
namespace Random_Sell_Prices.Patches
{
[HarmonyPatch(typeof(StartOfRound))]
public class TimeOfDayPatch
{
private static bool hadPityDay;
[HarmonyPatch(typeof(TimeOfDay), "SetBuyingRateForDay")]
[HarmonyPostfix]
private static void setBuyingRateForDayPatch()
{
float value = RandomSellPrices.minPercentage.Value;
float value2 = RandomSellPrices.maxPercentage.Value;
bool value3 = RandomSellPrices.pityEnabled.Value;
float num = (((Object)(object)TimeOfDay.Instance != (Object)null) ? TimeOfDay.Instance.daysUntilDeadline : 3);
if (value3 && num <= 1f && !hadPityDay)
{
value = RandomSellPrices.pityPercentage.Value;
}
if (num <= 1f && StartOfRound.Instance.companyBuyingRate >= RandomSellPrices.pityPercentage.Value)
{
hadPityDay = true;
}
Random random = new Random(StartOfRound.Instance.randomMapSeed);
float companyBuyingRate = (float)random.NextDouble() * (value2 - value) + value;
RandomSellPrices.mls.LogInfo((object)("Set daily price to: " + companyBuyingRate));
StartOfRound.Instance.companyBuyingRate = companyBuyingRate;
}
[HarmonyPatch(typeof(TimeOfDay), "SetNewProfitQuota")]
[HarmonyPostfix]
private static void setNewProfitQuotaPatch()
{
hadPityDay = false;
}
[HarmonyPatch(typeof(StartOfRound), "ResetShip")]
[HarmonyPostfix]
private static void resetShipPatch()
{
hadPityDay = false;
}
}
}