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(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")]
[assembly: AssemblyCompany("PopupReducer")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("PopupReducer")]
[assembly: AssemblyTitle("PopupReducer")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.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;
}
}
}
[BepInPlugin("sparroh.popupreducer", "PopupReducer", "1.1.0")]
[MycoMod(/*Could not decode attribute arguments.*/)]
public class SparrohPlugin : BaseUnityPlugin
{
public const string PluginGUID = "sparroh.popupreducer";
public const string PluginName = "PopupReducer";
public const string PluginVersion = "1.1.0";
internal static ManualLogSource Logger;
internal static ConfigEntry<bool> resizePopups;
private Harmony harmony;
private FileSystemWatcher configWatcher;
private volatile bool configReloadPending;
private float lastReloadTime;
internal static SparrohPlugin Instance { get; set; }
private void Awake()
{
//IL_0054: Unknown result type (might be due to invalid IL or missing references)
//IL_005e: Expected O, but got Unknown
Instance = this;
Logger = ((BaseUnityPlugin)this).Logger;
resizePopups = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "Resize Item Popups", true, "If true, reduces the size of item upgrade popups and repositions them.");
((BaseUnityPlugin)this).Config.ConfigReloaded += OnConfigReloaded;
SetupConfigWatcher();
try
{
harmony = new Harmony("sparroh.popupreducer");
harmony.PatchAll(typeof(ResizePopupPatches));
}
catch (Exception ex)
{
Logger.LogError((object)("Failed to apply Harmony patches: " + ex.Message));
}
Logger.LogInfo((object)"PopupReducer loaded successfully.");
}
private void Update()
{
if (!configReloadPending || Time.unscaledTime - lastReloadTime < 0.25f)
{
return;
}
configReloadPending = false;
lastReloadTime = Time.unscaledTime;
try
{
((BaseUnityPlugin)this).Config.Reload();
}
catch (Exception ex)
{
Logger.LogWarning((object)("Failed to reload config: " + ex.Message));
}
}
private void OnConfigReloaded(object sender, EventArgs e)
{
Logger.LogInfo((object)$"Config reloaded. Resize Item Popups = {resizePopups.Value}");
}
private void SetupConfigWatcher()
{
try
{
string configFilePath = ((BaseUnityPlugin)this).Config.ConfigFilePath;
string directoryName = Path.GetDirectoryName(configFilePath);
string fileName = Path.GetFileName(configFilePath);
if (string.IsNullOrEmpty(directoryName) || string.IsNullOrEmpty(fileName))
{
Logger.LogWarning((object)"Could not set up config file watcher: invalid config path.");
return;
}
configWatcher = new FileSystemWatcher(directoryName, fileName)
{
NotifyFilter = (NotifyFilters.Size | NotifyFilters.LastWrite),
EnableRaisingEvents = true
};
configWatcher.Changed += OnConfigFileChanged;
configWatcher.Created += OnConfigFileChanged;
configWatcher.Renamed += OnConfigFileChanged;
Logger.LogInfo((object)("Watching config file for changes: " + configFilePath));
}
catch (Exception ex)
{
Logger.LogWarning((object)("Could not set up config file watcher: " + ex.Message));
}
}
private void OnConfigFileChanged(object sender, FileSystemEventArgs e)
{
configReloadPending = true;
}
private void OnDestroy()
{
((BaseUnityPlugin)this).Config.ConfigReloaded -= OnConfigReloaded;
if (configWatcher != null)
{
configWatcher.EnableRaisingEvents = false;
configWatcher.Changed -= OnConfigFileChanged;
configWatcher.Created -= OnConfigFileChanged;
configWatcher.Renamed -= OnConfigFileChanged;
configWatcher.Dispose();
configWatcher = null;
}
try
{
Harmony obj = harmony;
if (obj != null)
{
obj.UnpatchSelf();
}
}
catch (Exception ex)
{
Logger.LogError((object)("Error unpatching Harmony: " + ex.Message));
}
}
}
[HarmonyPatch]
public static class ResizePopupPatches
{
private const float Scale = 0.5f;
private const float RightShift = 200f;
private const float SpawnXThreshold = -200f;
[HarmonyPatch(typeof(UpgradePopup), "Update")]
[HarmonyPostfix]
private static void UpgradePopup_Update_Postfix(UpgradePopup __instance)
{
//IL_0046: Unknown result type (might be due to invalid IL or missing references)
//IL_0058: Unknown result type (might be due to invalid IL or missing references)
//IL_005d: Unknown result type (might be due to invalid IL or missing references)
//IL_005e: Unknown result type (might be due to invalid IL or missing references)
//IL_0026: Unknown result type (might be due to invalid IL or missing references)
//IL_006c: Unknown result type (might be due to invalid IL or missing references)
//IL_0078: Unknown result type (might be due to invalid IL or missing references)
//IL_007e: Unknown result type (might be due to invalid IL or missing references)
if ((Object)(object)__instance == (Object)null)
{
return;
}
if (SparrohPlugin.resizePopups == null || !SparrohPlugin.resizePopups.Value)
{
((Component)__instance).transform.localScale = Vector3.one;
return;
}
((Component)__instance).transform.localScale = new Vector3(0.5f, 0.5f, 1f);
RectTransform rectTransform = __instance.RectTransform;
Vector2 anchoredPosition = rectTransform.anchoredPosition;
if (anchoredPosition.x < -200f)
{
rectTransform.anchoredPosition = new Vector2(anchoredPosition.x + 200f, anchoredPosition.y);
}
}
}
namespace PopupReducer
{
public static class MyPluginInfo
{
public const string PLUGIN_GUID = "PopupReducer";
public const string PLUGIN_NAME = "PopupReducer";
public const string PLUGIN_VERSION = "1.0.0";
}
}
namespace System.Runtime.CompilerServices
{
[AttributeUsage(AttributeTargets.Assembly, AllowMultiple = true)]
internal sealed class IgnoresAccessChecksToAttribute : Attribute
{
public IgnoresAccessChecksToAttribute(string assemblyName)
{
}
}
}