using System;
using System.Diagnostics;
using System.IO;
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.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("Sparroh")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.2.0.0")]
[assembly: AssemblyInformationalVersion("1.2.0")]
[assembly: AssemblyProduct("AtmosphericEnergizersRework")]
[assembly: AssemblyTitle("AtmosphericEnergizersRework")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.2.0.0")]
[module: UnverifiableCode]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
[CompilerGenerated]
[Embedded]
internal sealed class EmbeddedAttribute : Attribute
{
}
}
namespace System.Runtime.CompilerServices
{
[CompilerGenerated]
[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 AtmosphericEnergizersRework
{
public static class ConfigManager
{
public const string CapModeAmmoCapacity = "AmmoCapacity";
public const string CapModeCustom = "Custom";
private const float DebounceSeconds = 0.25f;
private static ConfigFile config;
private static ManualLogSource logger;
private static FileSystemWatcher configWatcher;
private static volatile bool reloadPending;
private static float lastReloadTime;
public static ConfigEntry<bool> Enabled { get; private set; }
public static ConfigEntry<float> FireDelay { get; private set; }
public static ConfigEntry<int> AmmoPerTick { get; private set; }
public static ConfigEntry<float> IntervalMultiplier { get; private set; }
public static ConfigEntry<string> CapMode { get; private set; }
public static ConfigEntry<int> CustomCap { get; private set; }
public static void Initialize(ConfigFile configFile, ManualLogSource log)
{
config = configFile;
logger = log;
Enabled = config.Bind<bool>("General", "Enabled", true, "Master toggle for the Atmospheric Energizers rework. When disabled, vanilla SwarmGun ammo regen runs unchanged.");
FireDelay = config.Bind<float>("General", "Fire Delay", 1f, "Seconds after last fire before auto ammo regen can start. Vanilla uses 1 second.");
AmmoPerTick = config.Bind<int>("General", "Ammo Per Tick", 1, "Stored ammo restored each regen tick (minimum 1).");
IntervalMultiplier = config.Bind<float>("General", "Interval Multiplier", 1f, "Multiplies the weapon's autoAmmoRegenInterval. Values below 1 regen faster; above 1 slower. Must be greater than 0.");
CapMode = config.Bind<string>("General", "Cap Mode", "AmmoCapacity", "How StoredAmmo is capped on regen. 'AmmoCapacity' uses GunData.ammoCapacity. 'Custom' uses Custom Cap.");
CustomCap = config.Bind<int>("General", "Custom Cap", 999, "Maximum StoredAmmo when Cap Mode is 'Custom'. Ignored for 'AmmoCapacity'.");
try
{
SetupFileWatcher();
}
catch (Exception ex)
{
logger.LogError((object)("Error setting up config file watcher: " + ex.Message));
}
}
public static void Tick()
{
if (!reloadPending || Time.unscaledTime - lastReloadTime < 0.25f)
{
return;
}
reloadPending = false;
lastReloadTime = Time.unscaledTime;
try
{
config.Reload();
logger.LogInfo((object)"Config reloaded from disk.");
}
catch (Exception ex)
{
logger.LogError((object)("Error reloading config: " + ex.Message));
}
}
public static void Dispose()
{
if (configWatcher != null)
{
configWatcher.EnableRaisingEvents = false;
configWatcher.Changed -= OnConfigFileChanged;
configWatcher.Created -= OnConfigFileChanged;
configWatcher.Renamed -= OnConfigFileChanged;
configWatcher.Dispose();
configWatcher = null;
}
}
public static int GetAmmoPerTick()
{
return Mathf.Max(1, AmmoPerTick.Value);
}
public static float GetFireDelay()
{
return Mathf.Max(0f, FireDelay.Value);
}
public static float GetIntervalMultiplier()
{
float value = IntervalMultiplier.Value;
if (!(value > 0f))
{
return 1f;
}
return value;
}
public static int GetCap(int ammoCapacity)
{
if (IsCustomCapMode())
{
return Mathf.Max(0, CustomCap.Value);
}
return ammoCapacity;
}
public static bool IsCustomCapMode()
{
string text = CapMode?.Value;
if (!string.IsNullOrEmpty(text))
{
return text.Equals("Custom", StringComparison.OrdinalIgnoreCase);
}
return false;
}
private static void SetupFileWatcher()
{
configWatcher = new FileSystemWatcher(Paths.ConfigPath, "sparroh.atmosphericenergizersrework.cfg");
configWatcher.NotifyFilter = NotifyFilters.FileName | NotifyFilters.Size | NotifyFilters.LastWrite;
configWatcher.Changed += OnConfigFileChanged;
configWatcher.Created += OnConfigFileChanged;
configWatcher.Renamed += OnConfigFileChanged;
configWatcher.EnableRaisingEvents = true;
}
private static void OnConfigFileChanged(object sender, FileSystemEventArgs e)
{
reloadPending = true;
}
}
[BepInPlugin("sparroh.atmosphericenergizersrework", "AtmosphericEnergizersRework", "1.2.0")]
[MycoMod(/*Could not decode attribute arguments.*/)]
public class AtmosphericEnergizersReworkPlugin : BaseUnityPlugin
{
public const string PluginGUID = "sparroh.atmosphericenergizersrework";
public const string PluginName = "AtmosphericEnergizersRework";
public const string PluginVersion = "1.2.0";
internal static ManualLogSource Logger;
private Harmony harmony;
private void Awake()
{
//IL_0021: Unknown result type (might be due to invalid IL or missing references)
//IL_002b: Expected O, but got Unknown
Logger = ((BaseUnityPlugin)this).Logger;
ConfigManager.Initialize(((BaseUnityPlugin)this).Config, Logger);
harmony = new Harmony("sparroh.atmosphericenergizersrework");
try
{
harmony.PatchAll(typeof(SwarmGun_OnActiveUpdate_Patch));
Logger.LogInfo((object)"Harmony patches applied.");
}
catch (Exception ex)
{
Logger.LogError((object)("Error applying patches: " + ex.Message));
}
Logger.LogInfo((object)"AtmosphericEnergizersRework v1.2.0 loaded successfully.");
}
private void Update()
{
ConfigManager.Tick();
}
private void OnDestroy()
{
ConfigManager.Dispose();
Harmony obj = harmony;
if (obj != null)
{
obj.UnpatchSelf();
}
}
}
[HarmonyPatch(typeof(SwarmGun), "OnActiveUpdate")]
public class SwarmGun_OnActiveUpdate_Patch
{
private static void Prefix(SwarmGun __instance, ref float ___lastAutoRegenAmmoTime)
{
//IL_0023: Unknown result type (might be due to invalid IL or missing references)
//IL_0028: Unknown result type (might be due to invalid IL or missing references)
//IL_0029: Unknown result type (might be due to invalid IL or missing references)
//IL_0043: Unknown result type (might be due to invalid IL or missing references)
if (ConfigManager.Enabled == null || !ConfigManager.Enabled.Value || ((Gun)__instance).Reloading)
{
return;
}
Data swarmData = __instance.SwarmData;
if (!(swarmData.autoAmmoRegenInterval <= 0f))
{
float time = Time.time;
float fireDelay = ConfigManager.GetFireDelay();
float num = swarmData.autoAmmoRegenInterval * ConfigManager.GetIntervalMultiplier();
if (!(time - ((Gun)__instance).LastFireTime < fireDelay) && __instance.HoveringBullets.Count > 0 && !(time - ___lastAutoRegenAmmoTime <= num))
{
___lastAutoRegenAmmoTime = time;
int cap = ConfigManager.GetCap(((Gun)__instance).GunData.ammoCapacity);
((Gun)__instance).StoredAmmo = Mathf.Min(((Gun)__instance).StoredAmmo + (float)ConfigManager.GetAmmoPerTick(), (float)cap);
}
}
}
}
public static class MyPluginInfo
{
public const string PLUGIN_GUID = "AtmosphericEnergizersRework";
public const string PLUGIN_NAME = "AtmosphericEnergizersRework";
public const string PLUGIN_VERSION = "1.2.0";
}
}
namespace System.Runtime.CompilerServices
{
[AttributeUsage(AttributeTargets.Assembly, AllowMultiple = true)]
internal sealed class IgnoresAccessChecksToAttribute : Attribute
{
public IgnoresAccessChecksToAttribute(string assemblyName)
{
}
}
}