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+46284b2485fee9c5e21b2c778fb2e8eb26de613c")]
[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]
[Embedded]
internal sealed class EmbeddedAttribute : Attribute
{
}
}
namespace System.Runtime.CompilerServices
{
[CompilerGenerated]
[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]
[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]
[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.1.0";
}
namespace WK_huoyan1231COMLib
{
[BepInPlugin("huoyan1231.whiteknuckle.comlib", "WK_huoyan1231COMLib", "1.1.0")]
public class Plugin : BaseUnityPlugin
{
internal static ManualLogSource Logger;
internal static ConfigEntry<bool> EnableLeaderboardManagement;
internal static ConfigEntry<bool> EnableAchievementManagement;
private void Awake()
{
//IL_0068: 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.");
EnableAchievementManagement = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "EnableAchievementManagement", true, "When true, this library will intercept Steam achievement unlocks so other mods can request disabling them.");
if (EnableLeaderboardManagement.Value || EnableAchievementManagement.Value)
{
new Harmony("huoyan1231.whiteknuckle.comlib").PatchAll();
Logger.LogInfo((object)("[WK_huoyan1231COMLib] v1.1.0 loaded. " + $"Patches applied (leaderboard={EnableLeaderboardManagement.Value}, achievements={EnableAchievementManagement.Value})."));
}
else
{
Logger.LogInfo((object)"[WK_huoyan1231COMLib] v1.1.0 loaded but all management patches are 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;
}
}
public static class AchievementManager
{
private static readonly HashSet<string> _disabledBy = new HashSet<string>();
private static bool _globalOverride = false;
public static void DisableForThisRun(string requesterId)
{
if (_disabledBy.Add(requesterId))
{
Plugin.Logger.LogInfo((object)("[COMLib] Steam achievements disabled this run by: " + requesterId));
}
}
public static void TryRestore(string requesterId)
{
_disabledBy.Remove(requesterId);
if (_disabledBy.Count == 0)
{
Plugin.Logger.LogInfo((object)"[COMLib] All per-run achievement-disable requests cleared; Steam achievements re-enabled.");
}
else
{
Plugin.Logger.LogInfo((object)("[COMLib] " + requesterId + " cleared, but Steam achievements still disabled by: " + string.Join(", ", _disabledBy)));
}
}
public static void SetSteamAchievementsDisabled(bool disabled)
{
_globalOverride = disabled;
Plugin.Logger.LogInfo((object)$"[COMLib] Steam achievements global override set to: {disabled}");
}
public static bool IsSteamAchievementsDisabled()
{
if (!_globalOverride)
{
return _disabledBy.Count > 0;
}
return true;
}
public static void ResetAll()
{
if (_disabledBy.Count > 0)
{
_disabledBy.Clear();
Plugin.Logger.LogInfo((object)"[COMLib] Run ended — per-run achievement-disable requests cleared.");
}
}
}
[HarmonyPatch(typeof(GameAchievement), "GetSteamAchievement")]
internal static class Patch_GetSteamAchievement
{
private static bool Prefix(GameAchievement __instance)
{
if (AchievementManager.IsSteamAchievementsDisabled())
{
Plugin.Logger.LogInfo((object)("[COMLib] Blocked Steam achievement upload: " + __instance.steamAchievementID));
return false;
}
return true;
}
}
[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();
AchievementManager.ResetAll();
}
}
}