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.Logging;
using HarmonyLib;
using Microsoft.CodeAnalysis;
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(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("Omniscye")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("Overdraft")]
[assembly: AssemblyTitle("Overdraft")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
[module: UnverifiableCode]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
[CompilerGenerated]
[Microsoft.CodeAnalysis.Embedded]
internal sealed class EmbeddedAttribute : Attribute
{
}
}
namespace System.Runtime.CompilerServices
{
[CompilerGenerated]
[Microsoft.CodeAnalysis.Embedded]
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Event | AttributeTargets.Parameter | AttributeTargets.ReturnValue | AttributeTargets.GenericParameter, AllowMultiple = false, Inherited = false)]
internal sealed class NullableAttribute : Attribute
{
public readonly byte[] NullableFlags;
public NullableAttribute(byte P_0)
{
NullableFlags = new byte[1] { P_0 };
}
public NullableAttribute(byte[] P_0)
{
NullableFlags = P_0;
}
}
[CompilerGenerated]
[Microsoft.CodeAnalysis.Embedded]
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Method | AttributeTargets.Interface | AttributeTargets.Delegate, AllowMultiple = false, Inherited = false)]
internal sealed class NullableContextAttribute : Attribute
{
public readonly byte Flag;
public NullableContextAttribute(byte P_0)
{
Flag = P_0;
}
}
[CompilerGenerated]
[Microsoft.CodeAnalysis.Embedded]
[AttributeUsage(AttributeTargets.Module, AllowMultiple = false, Inherited = false)]
internal sealed class RefSafetyRulesAttribute : Attribute
{
public readonly int Version;
public RefSafetyRulesAttribute(int P_0)
{
Version = P_0;
}
}
}
namespace RepoDebt
{
[BepInPlugin("Omniscye.RepoDebt", "RepoDebt", "1.0")]
public class RepoDebt : BaseUnityPlugin
{
internal static RepoDebt Instance { get; private set; }
internal static ManualLogSource Logger => Instance._logger;
private ManualLogSource _logger => ((BaseUnityPlugin)this).Logger;
internal Harmony? Harmony { get; set; }
private void Awake()
{
Instance = this;
((Component)this).gameObject.transform.parent = null;
((Object)((Component)this).gameObject).hideFlags = (HideFlags)61;
Patch();
Logger.LogInfo((object)$"{((BaseUnityPlugin)this).Info.Metadata.GUID} v{((BaseUnityPlugin)this).Info.Metadata.Version} has loaded!");
}
internal void Patch()
{
//IL_001a: Unknown result type (might be due to invalid IL or missing references)
//IL_001f: Unknown result type (might be due to invalid IL or missing references)
//IL_0021: Expected O, but got Unknown
//IL_0026: Expected O, but got Unknown
if (Harmony == null)
{
Harmony val = new Harmony(((BaseUnityPlugin)this).Info.Metadata.GUID);
Harmony val2 = val;
Harmony = val;
}
Harmony.PatchAll();
}
internal void Unpatch()
{
Harmony? harmony = Harmony;
if (harmony != null)
{
harmony.UnpatchSelf();
}
}
private void Update()
{
}
}
}
namespace Empress.RepoMods.OverdraftShop
{
[BepInPlugin("empress.repo.overdraftshop", "Overdraft Shop & Debt Spawn Scaling", "1.0.1")]
public class OverdraftShopPlugin : BaseUnityPlugin
{
public const string ModGuid = "empress.repo.overdraftshop";
public const string ModName = "Overdraft Shop & Debt Spawn Scaling";
public const string ModVersion = "1.0.1";
internal static ConfigEntry<bool> CfgEnableOverdraft;
internal static ConfigEntry<bool> CfgEnableDebtSpawnScaling;
internal static ConfigEntry<int> CfgDebtBracket;
internal static ConfigEntry<int> CfgMaxMultiplier;
internal static ConfigEntry<int> CfgMinDebtForScaling;
private Harmony _harmony;
private void Awake()
{
//IL_00ab: Unknown result type (might be due to invalid IL or missing references)
//IL_00b5: Expected O, but got Unknown
CfgEnableOverdraft = ((BaseUnityPlugin)this).Config.Bind<bool>("Overdraft", "EnableOverdraft", true, "Allow shop purchases to push currency below zero.");
CfgEnableDebtSpawnScaling = ((BaseUnityPlugin)this).Config.Bind<bool>("Spawns", "EnableDebtSpawnScaling", true, "Increase enemy spawns while in debt.");
CfgDebtBracket = ((BaseUnityPlugin)this).Config.Bind<int>("Spawns", "DebtBracket", 20000, "Debt per +1 spawn multiplier tier (e.g., 20000 => 1–20k = x2, 21–40k = x3, etc.).");
CfgMaxMultiplier = ((BaseUnityPlugin)this).Config.Bind<int>("Spawns", "MaxMultiplier", 4, "Maximum total multiplier (x1..this).");
CfgMinDebtForScaling = ((BaseUnityPlugin)this).Config.Bind<int>("Spawns", "MinDebtForScaling", 1, "Minimum absolute debt required to trigger scaling.");
_harmony = new Harmony("empress.repo.overdraftshop");
_harmony.PatchAll(typeof(OverdraftShopPlugin).Assembly);
((BaseUnityPlugin)this).Logger.LogInfo((object)"Overdraft Shop & Debt Spawn Scaling 1.0.1 loaded.");
}
private void OnDestroy()
{
try
{
Harmony harmony = _harmony;
if (harmony != null)
{
harmony.UnpatchSelf();
}
}
catch
{
}
}
internal static int GetDebt()
{
try
{
int num = SemiFunc.StatGetRunCurrency();
return (num < 0) ? (-num) : 0;
}
catch
{
return 0;
}
}
internal static int ComputeSpawnMultiplier()
{
if (!CfgEnableDebtSpawnScaling.Value)
{
return 1;
}
int debt = GetDebt();
if (debt < CfgMinDebtForScaling.Value)
{
return 1;
}
int num = Math.Max(1, CfgDebtBracket.Value);
int num2 = Mathf.CeilToInt((float)debt / (float)num);
int num3 = 1 + num2;
return Mathf.Clamp(num3, 1, Math.Max(1, CfgMaxMultiplier.Value));
}
}
[HarmonyPatch(typeof(ExtractionPoint), "DestroyTheFirstPhysObjectsInShopList")]
internal static class Patch_ExtractionPoint_DestroyFirst
{
[HarmonyPrefix]
private static bool Prefix()
{
//IL_00f5: Unknown result type (might be due to invalid IL or missing references)
//IL_00fb: Invalid comparison between Unknown and I4
//IL_0121: Unknown result type (might be due to invalid IL or missing references)
//IL_0127: Invalid comparison between Unknown and I4
if (!OverdraftShopPlugin.CfgEnableOverdraft.Value)
{
return true;
}
try
{
if (!SemiFunc.IsMasterClientOrSingleplayer())
{
return false;
}
if ((Object)(object)ShopManager.instance == (Object)null || ShopManager.instance.shoppingList == null || ShopManager.instance.shoppingList.Count == 0)
{
return false;
}
ItemAttributes val = ShopManager.instance.shoppingList[0];
if ((Object)(object)val == (Object)null)
{
return false;
}
PhysGrabObject component = ((Component)val).GetComponent<PhysGrabObject>();
if ((Object)(object)component == (Object)null)
{
return false;
}
int num = (OverdraftRuntime.SpoofActive ? OverdraftRuntime.PrevCurrency : SemiFunc.StatGetRunCurrency());
int value = val.value;
SemiFunc.StatSetRunCurrency(num - value);
OverdraftRuntime.SpoofActive = false;
StatsManager.instance.ItemPurchase(((Object)val.item).name);
if ((int)val.item.itemType == 3)
{
StatsManager.instance.AddItemsUpgradesPurchased(((Object)val.item).name);
}
if ((int)val.item.itemType == 5)
{
StatsManager.instance.runStats["chargingStationChargeTotal"] += 17;
if (StatsManager.instance.runStats["chargingStationChargeTotal"] > 100)
{
StatsManager.instance.runStats["chargingStationChargeTotal"] = 100;
}
}
component.DestroyPhysGrabObject();
ShopManager.instance.shoppingList.RemoveAt(0);
SemiFunc.ShopUpdateCost();
return false;
}
catch (Exception arg)
{
Debug.LogError((object)string.Format("[{0}] Error in overdraft purchase (first): {1}", "Overdraft Shop & Debt Spawn Scaling", arg));
return true;
}
}
}
[HarmonyPatch(typeof(ExtractionPoint), "DestroyAllPhysObjectsInShoppingList")]
internal static class Patch_ExtractionPoint_DestroyAll
{
[HarmonyPrefix]
private static bool Prefix()
{
//IL_00f0: Unknown result type (might be due to invalid IL or missing references)
//IL_00f6: Invalid comparison between Unknown and I4
//IL_011e: Unknown result type (might be due to invalid IL or missing references)
//IL_0124: Invalid comparison between Unknown and I4
if (!OverdraftShopPlugin.CfgEnableOverdraft.Value)
{
return true;
}
try
{
if (!SemiFunc.IsMasterClientOrSingleplayer())
{
return false;
}
if ((Object)(object)ShopManager.instance == (Object)null || ShopManager.instance.shoppingList == null)
{
return false;
}
List<ItemAttributes> list = new List<ItemAttributes>();
int num = (OverdraftRuntime.SpoofActive ? OverdraftRuntime.PrevCurrency : SemiFunc.StatGetRunCurrency());
foreach (ItemAttributes shopping in ShopManager.instance.shoppingList)
{
if ((Object)(object)shopping == (Object)null)
{
continue;
}
PhysGrabObject component = ((Component)shopping).GetComponent<PhysGrabObject>();
if ((Object)(object)component == (Object)null)
{
continue;
}
int value = shopping.value;
num -= value;
StatsManager.instance.ItemPurchase(((Object)shopping.item).name);
if ((int)shopping.item.itemType == 3)
{
StatsManager.instance.AddItemsUpgradesPurchased(((Object)shopping.item).name);
}
if ((int)shopping.item.itemType == 5)
{
StatsManager.instance.runStats["chargingStationChargeTotal"] += 17;
if (StatsManager.instance.runStats["chargingStationChargeTotal"] > 100)
{
StatsManager.instance.runStats["chargingStationChargeTotal"] = 100;
}
}
component.DestroyPhysGrabObject();
list.Add(shopping);
}
OverdraftRuntime.SpoofActive = false;
SemiFunc.StatSetRunCurrency(num);
foreach (ItemAttributes item in list)
{
ShopManager.instance.shoppingList.Remove(item);
}
SemiFunc.ShopUpdateCost();
return false;
}
catch (Exception arg)
{
Debug.LogError((object)string.Format("[{0}] Error in overdraft purchase (all): {1}", "Overdraft Shop & Debt Spawn Scaling", arg));
return true;
}
}
}
[HarmonyPatch(typeof(LevelGenerator), "EnemySpawn")]
internal static class Patch_LevelGenerator_EnemySpawn
{
private static bool _dupeGuard;
[HarmonyPostfix]
private static void Postfix(LevelGenerator __instance, EnemySetup enemySetup, Vector3 position)
{
//IL_0068: Unknown result type (might be due to invalid IL or missing references)
if (!OverdraftShopPlugin.CfgEnableDebtSpawnScaling.Value || _dupeGuard)
{
return;
}
try
{
if (!SemiFunc.IsMasterClientOrSingleplayer() || !SemiFunc.RunIsLevel())
{
return;
}
int num = OverdraftShopPlugin.ComputeSpawnMultiplier();
if (num > 1)
{
_dupeGuard = true;
for (int i = 0; i < num - 1; i++)
{
__instance.EnemySpawn(enemySetup, position);
}
}
}
catch (Exception arg)
{
Debug.LogError((object)string.Format("[{0}] Enemy spawn scaling failed: {1}", "Overdraft Shop & Debt Spawn Scaling", arg));
}
finally
{
_dupeGuard = false;
}
}
}
internal static class OverdraftRuntime
{
internal static bool SpoofActive;
internal static int PrevCurrency;
}
[HarmonyPatch(typeof(ExtractionPoint), "OnShopClick")]
internal static class Patch_ExtractionPoint_OnShopClick
{
private static FieldInfo _fiIsShop;
private static MethodInfo _miHaulInternalStatsUpdate;
[HarmonyPrefix]
private static bool Prefix(ExtractionPoint __instance)
{
if (!OverdraftShopPlugin.CfgEnableOverdraft.Value)
{
return true;
}
if (!SemiFunc.IsMasterClientOrSingleplayer())
{
return true;
}
try
{
if ((object)_fiIsShop == null)
{
_fiIsShop = AccessTools.Field(typeof(ExtractionPoint), "isShop");
}
if ((object)_miHaulInternalStatsUpdate == null)
{
_miHaulInternalStatsUpdate = AccessTools.Method(typeof(ExtractionPoint), "HaulInternalStatsUpdate", Type.EmptyTypes, (Type[])null);
}
if (!(_fiIsShop != null) || !(bool)_fiIsShop.GetValue(__instance))
{
return true;
}
int num = SemiFunc.StatGetRunCurrency();
int num2 = SemiFunc.ShopGetTotalCost();
if (num < num2)
{
OverdraftRuntime.PrevCurrency = num;
OverdraftRuntime.SpoofActive = true;
SemiFunc.StatSetRunCurrency(num2);
Debug.Log((object)$"[OverdraftShop] Spoofing currency for afford check (K): {num} -> {num2}");
_miHaulInternalStatsUpdate?.Invoke(__instance, null);
}
return true;
}
catch (Exception arg)
{
Debug.LogError((object)$"[OverdraftShop] OnShopClick prefix failed: {arg}");
return true;
}
}
}
}