using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Core.Logging.Interpolation;
using BepInEx.Logging;
using BepInEx.Unity.IL2CPP;
using HarmonyLib;
using Store.Pump;
using Store.Pump.UI;
using UnityEngine;
using UpgradeLib;
[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETCoreApp,Version=v6.0", FrameworkDisplayName = "")]
[assembly: AssemblyCompany("FuelCapacityUpgrade")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("FuelCapacityUpgrade")]
[assembly: AssemblyTitle("FuelCapacityUpgrade")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
[module: UnverifiableCode]
namespace FuelCapacityUpgrade;
[BepInPlugin("com.fuelcapacity.roadsideresearch", "FuelCapacityUpgrade", "2.0.0")]
[BepInDependency(/*Could not decode attribute arguments.*/)]
public class Plugin : BasePlugin
{
public const string GUID = "com.fuelcapacity.roadsideresearch";
public const string Name = "FuelCapacityUpgrade";
public const string Version = "2.0.0";
internal static ManualLogSource Log;
internal static ConfigEntry<float> PercentPerLevel;
internal static ConfigEntry<int> MaxLevel;
internal static ConfigEntry<float> BaseCost;
internal static ConfigEntry<float> CostMultiplier;
internal static readonly List<string> FuelNodeIds = new List<string>();
private static readonly string[] RomanNumerals = new string[20]
{
"I", "II", "III", "IV", "V", "VI", "VII", "VIII", "IX", "X",
"XI", "XII", "XIII", "XIV", "XV", "XVI", "XVII", "XVIII", "XIX", "XX"
};
public override void Load()
{
//IL_0052: Unknown result type (might be due to invalid IL or missing references)
//IL_005c: Expected O, but got Unknown
//IL_00b9: Unknown result type (might be due to invalid IL or missing references)
//IL_00d7: Unknown result type (might be due to invalid IL or missing references)
//IL_00dd: Expected O, but got Unknown
Log = ((BasePlugin)this).Log;
PercentPerLevel = ((BasePlugin)this).Config.Bind<float>("Fuel", "PercentPerLevel", 25f, "Percent increase in max fuel per upgrade tier");
MaxLevel = ((BasePlugin)this).Config.Bind<int>("Fuel", "MaxLevel", 5, new ConfigDescription("Number of upgrade tiers", (AcceptableValueBase)(object)new AcceptableValueRange<int>(1, 20), Array.Empty<object>()));
BaseCost = ((BasePlugin)this).Config.Bind<float>("Fuel", "BaseCost", 500f, "Cost for the first fuel upgrade tier");
CostMultiplier = ((BasePlugin)this).Config.Bind<float>("Fuel", "CostMultiplier", 1.5f, "Cost multiplier per tier");
UpgradeAPI.RegisterTree(BuildFuelTree());
new Harmony("com.fuelcapacity.roadsideresearch").PatchAll(typeof(FuelPatches));
ManualLogSource log = Log;
bool flag = default(bool);
BepInExInfoLogInterpolatedStringHandler val = new BepInExInfoLogInterpolatedStringHandler(44, 2, ref flag);
if (flag)
{
((BepInExLogInterpolatedStringHandler)val).AppendLiteral("FuelCapacityUpgrade loaded! ");
((BepInExLogInterpolatedStringHandler)val).AppendFormatted<int>(MaxLevel.Value);
((BepInExLogInterpolatedStringHandler)val).AppendLiteral(" tiers, +");
((BepInExLogInterpolatedStringHandler)val).AppendFormatted<float>(PercentPerLevel.Value);
((BepInExLogInterpolatedStringHandler)val).AppendLiteral("% each.");
}
log.LogInfo(val);
}
private UpgradeDefinition BuildFuelTree()
{
//IL_009d: Unknown result type (might be due to invalid IL or missing references)
//IL_00a2: Unknown result type (might be due to invalid IL or missing references)
//IL_00aa: Unknown result type (might be due to invalid IL or missing references)
//IL_00bc: Unknown result type (might be due to invalid IL or missing references)
//IL_00f4: Unknown result type (might be due to invalid IL or missing references)
//IL_00f6: Unknown result type (might be due to invalid IL or missing references)
//IL_00fb: Unknown result type (might be due to invalid IL or missing references)
//IL_010e: Unknown result type (might be due to invalid IL or missing references)
//IL_0119: Unknown result type (might be due to invalid IL or missing references)
//IL_0124: Unknown result type (might be due to invalid IL or missing references)
//IL_0138: Expected O, but got Unknown
int value = MaxLevel.Value;
float value2 = BaseCost.Value;
float value3 = CostMultiplier.Value;
float value4 = PercentPerLevel.Value;
UpgradeDefinition val = null;
UpgradeDefinition val2 = null;
for (int i = 0; i < value; i++)
{
string text = $"fuel_capacity_{i + 1}";
FuelNodeIds.Add(text);
int num = i + 1;
string text2 = ((num <= RomanNumerals.Length) ? RomanNumerals[num - 1] : num.ToString());
float value5 = value4 * (float)num;
UpgradeDefinition val3 = new UpgradeDefinition
{
Id = text,
Name = "Fuel Tank " + text2,
Description = $"Increases max fuel storage by {value5}%.",
CostType = (CostType)0,
Cost = value2 * (float)Math.Pow(value3, i),
Category = "Station",
VanillaIconMatch = "gas-pump",
OnPurchased = RefreshFuelBarUI
};
if (val == null)
{
val3.Title = "Fuel Upgrades";
val = val3;
}
else
{
val2.Children.Add(val3);
}
val2 = val3;
}
return val;
}
private static void RefreshFuelBarUI()
{
FuelInventory val = Object.FindObjectOfType<FuelInventory>();
if (!((Object)(object)val == (Object)null))
{
Traverse.Create((object)val).Method("UpdateVisuals", Array.Empty<object>()).GetValue();
}
}
}
[HarmonyPatch]
internal static class FuelPatches
{
[HarmonyPatch(typeof(FuelInventory), "MaxFuel")]
[HarmonyPostfix]
public static void IncreaseMaxFuel(ref float __result)
{
int num = 0;
foreach (string fuelNodeId in Plugin.FuelNodeIds)
{
if (UpgradeAPI.IsPurchased(fuelNodeId))
{
num++;
}
}
if (num > 0)
{
float num2 = 1f + Plugin.PercentPerLevel.Value / 100f * (float)num;
__result *= num2;
}
}
[HarmonyPatch(typeof(DataDisplayPumpFuelStorageBar), "HandleNewData")]
[HarmonyPostfix]
public static void FixFuelStorageBarFill(DataDisplayPumpFuelStorageBar __instance, FuelInventory newData)
{
//IL_001a: Unknown result type (might be due to invalid IL or missing references)
//IL_0027: Unknown result type (might be due to invalid IL or missing references)
if (!((Object)(object)newData == (Object)null) && !((Object)(object)__instance.FillBar == (Object)null))
{
float num = newData.MaxFuel(__instance.TypeToDisplay);
float value = newData.CurrentFuel(__instance.TypeToDisplay, true);
if (num > 0f)
{
__instance.FillBar.maxValue = num;
__instance.FillBar.value = value;
}
}
}
}