using System;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using BepInEx;
using BepInEx.Configuration;
using RTM.UISystem;
using UnityEngine;
using Voxels.TowerDefense;
using Voxels.TowerDefense.ProfileInternals;
using Voxels.TowerDefense.UI;
using Voxels.TowerDefense.UI.UpgradeScreen;
[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: AssemblyCompany("BadNorth.CampaignGold")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("BadNorth.CampaignGold")]
[assembly: AssemblyTitle("BadNorth.CampaignGold")]
[assembly: AssemblyVersion("1.0.0.0")]
namespace BadNorth.CampaignGold;
[BepInPlugin("local.badnorth.campaign-gold", "Bad North Campaign Gold", "1.0.0")]
public sealed class CampaignGoldPlugin : BaseUnityPlugin
{
private const int MaximumBalance = 999999;
private ConfigEntry<KeyboardShortcut> addShortcut;
private ConfigEntry<KeyboardShortcut> setShortcut;
private ConfigEntry<int> addAmount;
private ConfigEntry<int> targetBalance;
private void Awake()
{
//IL_001c: Unknown result type (might be due to invalid IL or missing references)
//IL_004c: Unknown result type (might be due to invalid IL or missing references)
addShortcut = ((BaseUnityPlugin)this).Config.Bind<KeyboardShortcut>("Gold", "AddShortcut", new KeyboardShortcut((KeyCode)287, (KeyCode[])(object)new KeyCode[0]), "Adds AddAmount on the campaign map.");
setShortcut = ((BaseUnityPlugin)this).Config.Bind<KeyboardShortcut>("Gold", "SetShortcut", new KeyboardShortcut((KeyCode)288, (KeyCode[])(object)new KeyCode[0]), "Sets the balance to TargetBalance on the campaign map.");
addAmount = ((BaseUnityPlugin)this).Config.Bind<int>("Gold", "AddAmount", 100, "Amount added per press. A negative amount removes gold.");
targetBalance = ((BaseUnityPlugin)this).Config.Bind<int>("Gold", "TargetBalance", 999, "Balance to set. The resulting balance is limited to 0 through " + 999999 + ".");
}
private void Update()
{
//IL_0006: Unknown result type (might be due to invalid IL or missing references)
//IL_000b: Unknown result type (might be due to invalid IL or missing references)
//IL_001e: Unknown result type (might be due to invalid IL or missing references)
//IL_0023: Unknown result type (might be due to invalid IL or missing references)
KeyboardShortcut value = setShortcut.Value;
bool flag = ((KeyboardShortcut)(ref value)).IsDown();
if (!flag)
{
value = addShortcut.Value;
if (!((KeyboardShortcut)(ref value)).IsDown())
{
return;
}
}
UIManager instance = Singleton<UIManager>.instance;
if (!Object.op_Implicit((Object)(object)instance))
{
return;
}
UIMenu activeMenu = instance.activeMenu;
CampaignMapUI val = (CampaignMapUI)(object)((activeMenu is CampaignMapUI) ? activeMenu : null);
if (val == null || ((UIMenu)val).blockingInput || Profile.Loading)
{
return;
}
CampaignSave campaign = Profile.campaign;
SuperUpgradeMenu instance2 = SuperUpgradeMenu.instance;
if (campaign != null && !campaign.gameOver && Profile.activeCampaignMeta != null && Object.op_Implicit((Object)(object)instance2))
{
int coinBank = campaign.coinBank;
if (ChangeBalance(campaign, flag ? targetBalance.Value : addAmount.Value, flag))
{
instance2.UpdateCoinBank();
Profile.SaveCampaign(false);
((BaseUnityPlugin)this).Logger.LogInfo((object)("Campaign gold changed from " + coinBank + " to " + campaign.coinBank + "."));
}
}
}
private static bool ChangeBalance(CampaignSave save, int amount, bool replace)
{
long val = (replace ? amount : ((long)save.coinBank + (long)amount));
int num = (int)Math.Min(999999L, Math.Max(0L, val));
if (num == save.coinBank)
{
return false;
}
save.coinBank = num;
return true;
}
}