using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
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 Microsoft.CodeAnalysis;
using Sparroh.UI;
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.1.0.0")]
[assembly: AssemblyInformationalVersion("1.1.0")]
[assembly: AssemblyProduct("GridClear")]
[assembly: AssemblyTitle("GridClear")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.1.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;
}
}
}
public static class ConfigManager
{
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> EnableClearGrid { get; private set; }
public static void Initialize(ConfigFile configFile, ManualLogSource log)
{
config = configFile;
logger = log;
EnableClearGrid = config.Bind<bool>("General", "Enable Clear Grid", true, "Show the Clear Grid button on the gear action bar.");
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;
}
}
private static void SetupFileWatcher()
{
configWatcher = new FileSystemWatcher(Paths.ConfigPath, "sparroh.gridclear.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;
}
}
public static class GridClearLogic
{
private static readonly PropertyInfo _upgradablePrefabProperty = typeof(GearDetailsWindow).GetProperty("UpgradablePrefab", BindingFlags.Instance | BindingFlags.Public);
private static readonly FieldInfo _selectedGearField = typeof(OuroGearWindow).GetField("selectedGear", BindingFlags.Instance | BindingFlags.NonPublic);
public static void TryClearFromOpenWindow()
{
if ((Object)(object)Menu.Instance == (Object)null || !Menu.Instance.IsOpen || (Object)(object)Menu.Instance.WindowSystem == (Object)null)
{
return;
}
Window top = Menu.Instance.WindowSystem.GetTop();
IUpgradeWindow val = (IUpgradeWindow)(object)((top is GearDetailsWindow) ? top : null);
IUpgradable val2 = null;
if (val != null)
{
object? obj = _upgradablePrefabProperty?.GetValue(val);
val2 = (IUpgradable)((obj is IUpgradable) ? obj : null);
}
else
{
val = (IUpgradeWindow)(object)((top is OuroGearWindow) ? top : null);
if (val != null)
{
object? obj2 = _selectedGearField?.GetValue(val);
val2 = (IUpgradable)((obj2 is IUpgradable) ? obj2 : null);
}
}
if (val != null && val2 != null)
{
ClearAllUpgrades(val, val2);
}
}
private static void ClearAllUpgrades(IUpgradeWindow window, IUpgradable gear)
{
//IL_0030: Unknown result type (might be due to invalid IL or missing references)
//IL_0035: Unknown result type (might be due to invalid IL or missing references)
//IL_0037: Unknown result type (might be due to invalid IL or missing references)
//IL_0041: Unknown result type (might be due to invalid IL or missing references)
ModuleEquipSlots equipSlots = GetEquipSlots(window);
if ((Object)(object)equipSlots == (Object)null)
{
return;
}
HexMap hexMap = equipSlots.HexMap;
List<UpgradeInstance> list = new List<UpgradeInstance>();
for (int i = 0; i < hexMap.Height; i++)
{
for (int j = 0; j < hexMap.Width; j++)
{
Node val = hexMap[j, i];
if (val.upgrade != null)
{
list.Add(val.upgrade);
}
}
}
foreach (UpgradeInstance item in list.OrderBy((UpgradeInstance u) => (u.Upgrade.Name == "Boundary Incursion") ? 1 : 0).ToList())
{
equipSlots.Unequip(gear, item);
}
}
private static ModuleEquipSlots GetEquipSlots(IUpgradeWindow window)
{
//IL_001f: Unknown result type (might be due to invalid IL or missing references)
//IL_0025: Expected O, but got Unknown
return (ModuleEquipSlots)(((object)window).GetType().GetField("equipSlots", BindingFlags.Instance | BindingFlags.NonPublic)?.GetValue(window));
}
}
public static class GridClearUI
{
private static bool _registered;
public static void UpdateUI()
{
GearActionBar.Tick();
if (!GearActionBar.IsGearMenuOpen())
{
return;
}
if (ConfigManager.EnableClearGrid == null || !ConfigManager.EnableClearGrid.Value)
{
if (_registered)
{
GearActionBar.Unregister("clear_grid");
_registered = false;
}
}
else if (!_registered)
{
GearActionBar.Register("clear_grid", "Clear Grid", 10, (Action)delegate
{
UIDialog.Confirm("Clear Grid", "Unequip all upgrades from this gear grid?", (Action)GridClearLogic.TryClearFromOpenWindow, (Action)null, "Confirm", "Cancel");
}, (UIButtonStyle)2);
_registered = true;
}
}
public static void Cleanup()
{
GearActionBar.Unregister("clear_grid");
_registered = false;
}
}
[BepInPlugin("sparroh.gridclear", "GridClear", "1.1.0")]
[BepInDependency(/*Could not decode attribute arguments.*/)]
[MycoMod(/*Could not decode attribute arguments.*/)]
public class GridClearPlugin : BaseUnityPlugin
{
public const string PluginGUID = "sparroh.gridclear";
public const string PluginName = "GridClear";
public const string PluginVersion = "1.1.0";
internal static ManualLogSource Logger;
public static GridClearPlugin Instance;
private void Awake()
{
Logger = ((BaseUnityPlugin)this).Logger;
Instance = this;
ConfigManager.Initialize(((BaseUnityPlugin)this).Config, Logger);
Logger.LogInfo((object)"GridClear v1.1.0 loaded successfully.");
}
private void Update()
{
ConfigManager.Tick();
GridClearUI.UpdateUI();
}
private void OnDestroy()
{
GridClearUI.Cleanup();
ConfigManager.Dispose();
}
}
namespace GridClear
{
public static class MyPluginInfo
{
public const string PLUGIN_GUID = "GridClear";
public const string PLUGIN_NAME = "GridClear";
public const string PLUGIN_VERSION = "1.1.0";
}
}
namespace System.Runtime.CompilerServices
{
[AttributeUsage(AttributeTargets.Assembly, AllowMultiple = true)]
internal sealed class IgnoresAccessChecksToAttribute : Attribute
{
public IgnoresAccessChecksToAttribute(string assemblyName)
{
}
}
}