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.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETFramework,Version=v4.7.1", FrameworkDisplayName = ".NET Framework 4.7.1")]
[assembly: AssemblyCompany("WK_huoyan1231COMLib")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("WK_huoyan1231COMLib")]
[assembly: AssemblyTitle("WK_huoyan1231COMLib")]
[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;
}
}
}
internal static class MyPluginInfo
{
public const string PLUGIN_GUID = "huoyan1231.whiteknuckle.comlib";
public const string PLUGIN_NAME = "WK_huoyan1231COMLib";
public const string PLUGIN_VERSION = "1.0.0";
}
namespace WK_huoyan1231COMLib
{
[BepInPlugin("huoyan1231.whiteknuckle.comlib", "WK_huoyan1231COMLib", "1.0.0")]
public class Plugin : BaseUnityPlugin
{
internal static ManualLogSource Logger;
internal static ConfigEntry<bool> EnableLeaderboardManagement;
private void Awake()
{
//IL_003c: Unknown result type (might be due to invalid IL or missing references)
Logger = ((BaseUnityPlugin)this).Logger;
EnableLeaderboardManagement = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "EnableLeaderboardManagement", true, "When true, this library will automatically disable leaderboards when the Trinket budget is exceeded by any mod.");
if (EnableLeaderboardManagement.Value)
{
new Harmony("huoyan1231.whiteknuckle.comlib").PatchAll();
Logger.LogInfo((object)"[WK_huoyan1231COMLib] v1.0.0 loaded. Leaderboard management patches applied.");
}
else
{
Logger.LogInfo((object)"[WK_huoyan1231COMLib] v1.0.0 loaded but leaderboard management is disabled via config.");
}
}
}
public static class LeaderboardManager
{
private static readonly HashSet<string> _disabledBy = new HashSet<string>();
public static void DisableForThisRun(string requesterId)
{
if (_disabledBy.Add(requesterId))
{
WK_Leaderboard_Core.disableLeaderboards = true;
Plugin.Logger.LogInfo((object)("[COMLib] Leaderboards disabled by: " + requesterId));
}
}
public static void TryRestore(string requesterId)
{
_disabledBy.Remove(requesterId);
if (_disabledBy.Count == 0)
{
WK_Leaderboard_Core.disableLeaderboards = false;
Plugin.Logger.LogInfo((object)"[COMLib] Leaderboards re-enabled (all requesters cleared).");
}
else
{
Plugin.Logger.LogInfo((object)("[COMLib] " + requesterId + " cleared, but leaderboards still disabled by: " + string.Join(", ", _disabledBy)));
}
}
public static void ResetAll()
{
if (_disabledBy.Count > 0)
{
_disabledBy.Clear();
WK_Leaderboard_Core.disableLeaderboards = false;
Plugin.Logger.LogInfo((object)"[COMLib] Run ended — leaderboard disable state fully reset.");
}
}
public static bool IsTrinketBudgetExceeded(List<string> trinketNames)
{
int num = 0;
int num2 = 1;
foreach (string trinketName in trinketNames)
{
Trinket trinketAsset = CL_AssetManager.GetTrinketAsset(trinketName, "");
if (!((Object)(object)trinketAsset == (Object)null))
{
if (trinketAsset.isBinding)
{
num2 += trinketAsset.cost;
}
else
{
num += trinketAsset.cost;
}
}
}
return num > num2;
}
}
[HarmonyPatch(typeof(M_Gamemode), "StartFreshGamemode")]
internal static class Patch_StartFreshGamemode
{
private static void Postfix()
{
Plugin.Logger.LogInfo((object)"[COMLib] StartFreshGamemode called. External mods may now register leaderboard disable requests.");
}
}
[HarmonyPatch(typeof(M_Gamemode), "Finish")]
internal static class Patch_Finish
{
private static void Postfix()
{
LeaderboardManager.ResetAll();
}
}
}