using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Threading.Tasks;
using BepInEx;
using BepInEx.Logging;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using PluginConfig.API;
using PluginConfig.API.Decorators;
using PluginConfig.API.Fields;
using Steamworks;
using Steamworks.Data;
using UnityEngine;
[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("UltrakillDifficultyLeaderboard")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("UltrakillDifficultyLeaderboard")]
[assembly: AssemblyTitle("UltrakillDifficultyLeaderboard")]
[assembly: AssemblyVersion("1.0.0.0")]
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;
}
}
}
namespace UltrakillDifficultyLeaderboard
{
[BepInPlugin("net.zephyr.ultrakill.DifficultyLeaderboards", "Difficulty Leaderboards", "0.1.0")]
public class LeaderboardPlugin : BaseUnityPlugin
{
public class DifficultyOption
{
[Serializable]
[CompilerGenerated]
private sealed class <>c
{
public static readonly <>c <>9 = new <>c();
public static BoolValueChangeEventDelegate <>9__11_0;
internal void <.ctor>b__11_0(BoolValueChangeEvent e)
{
}
}
public GameDifficulty Difficulty { get; }
public BoolField VisibilityField { get; set; }
public BoolField RecordSetField { get; set; }
public unsafe DifficultyOption(GameDifficulty difficulty, ConfigPanel panel)
{
//IL_0009: Unknown result type (might be due to invalid IL or missing references)
//IL_000a: Unknown result type (might be due to invalid IL or missing references)
//IL_0042: Unknown result type (might be due to invalid IL or missing references)
//IL_0048: Expected O, but got Unknown
//IL_0066: Unknown result type (might be due to invalid IL or missing references)
//IL_0070: Expected O, but got Unknown
//IL_008f: Unknown result type (might be due to invalid IL or missing references)
//IL_0099: Expected O, but got Unknown
//IL_00f0: Unknown result type (might be due to invalid IL or missing references)
//IL_00f5: Unknown result type (might be due to invalid IL or missing references)
//IL_00fb: Expected O, but got Unknown
Difficulty = difficulty;
string text = ((object)(*(GameDifficulty*)(&difficulty))/*cast due to .constrained prefix*/).ToString().ToUpper();
string text2 = ((object)(*(GameDifficulty*)(&difficulty))/*cast due to .constrained prefix*/).ToString().ToLower();
ConfigPanel val = new ConfigPanel(panel, text, text2 + "_panel");
VisibilityField = new BoolField(val, "Show " + text + " Times\non Leaderboards", text2 + "_vis_toggle", true);
RecordSetField = new BoolField(val, "Allow new " + text + "\nRecords", text2 + "_time_toggle", true);
((ConfigField)VisibilityField).interactable = !Instance.DiffVis.value;
((ConfigField)RecordSetField).interactable = !Instance.BlockAllRecords.value;
BoolField visibilityField = VisibilityField;
object obj = <>c.<>9__11_0;
if (obj == null)
{
BoolValueChangeEventDelegate val2 = delegate
{
};
<>c.<>9__11_0 = val2;
obj = (object)val2;
}
visibilityField.onValueChange += (BoolValueChangeEventDelegate)obj;
}
public static DifficultyOption Create(GameDifficulty difficulty, ConfigPanel panel)
{
//IL_0001: Unknown result type (might be due to invalid IL or missing references)
//IL_000e: Unknown result type (might be due to invalid IL or missing references)
DifficultyOption difficultyOption = new DifficultyOption(difficulty, panel);
DifficultyVisibility.Add(difficulty, difficultyOption);
return difficultyOption;
}
}
internal static ManualLogSource? Log;
private PluginConfigurator config;
public static Dictionary<GameDifficulty, DifficultyOption> DifficultyVisibility = new Dictionary<GameDifficulty, DifficultyOption>();
private const string ModName = "Zephyr's Leaderboard Manager";
private const string ActiveDiffName = "Show Active Difficulty Times";
private const string ActiveDiffOnlyName = "Hide Other Difficulty Times";
private const string HideOthersName = "Hide Other Players";
private const string BlockAllRecordName = "Block All New Records";
private const string DiffPanelName = "Config Difficulties";
private const string DiffCatecoryName1 = "ACCESSIBLE";
private const string DiffCatecoryName2 = "HARD";
private const string DiffCatecoryName3 = "VERY HARD";
public BoolField ActiveDiffVis { get; private set; }
public BoolField DiffVis { get; private set; }
public BoolField BlockAllRecords { get; private set; }
public BoolField HideOthers { get; private set; }
public static LeaderboardPlugin Instance { get; private set; }
public LeaderboardPlugin()
{
Instance = this;
CreateConfig();
}
private void Awake()
{
//IL_0006: Unknown result type (might be due to invalid IL or missing references)
//IL_000c: Expected O, but got Unknown
Harmony val = new Harmony("net.zephyr.ultrakill.DifficultyLeaderboards");
val.PatchAll();
Log = ((BaseUnityPlugin)this).Logger;
Log.LogInfo((object)"Difficulty Leaderboards loaded!");
}
private void CreateConfig()
{
//IL_003d: Unknown result type (might be due to invalid IL or missing references)
//IL_0043: Expected O, but got Unknown
//IL_0064: Unknown result type (might be due to invalid IL or missing references)
//IL_0073: Unknown result type (might be due to invalid IL or missing references)
//IL_00ab: Unknown result type (might be due to invalid IL or missing references)
//IL_00b5: Expected O, but got Unknown
config = PluginConfigurator.Create("Zephyr's Leaderboard Manager", "net.zephyr.ultrakill.DifficultyLeaderboards");
string directoryName = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
string path = Path.Combine(directoryName, "icon.png");
byte[] array = File.ReadAllBytes(path);
Texture2D val = new Texture2D(2, 2, (TextureFormat)4, false);
ImageConversion.LoadImage(val, array);
Sprite icon = Sprite.Create(val, new Rect(0f, 0f, (float)((Texture)val).width, (float)((Texture)val).height), new Vector2(0.5f, 0.5f));
config.icon = icon;
CreateConfigDifficulties();
HideOthers = new BoolField(config.rootPanel, "Hide Other Players", "others_vis", false);
}
private void CreateConfigDifficulties()
{
//IL_0025: Unknown result type (might be due to invalid IL or missing references)
//IL_002f: Expected O, but got Unknown
//IL_0047: Unknown result type (might be due to invalid IL or missing references)
//IL_0051: Expected O, but got Unknown
//IL_0069: Unknown result type (might be due to invalid IL or missing references)
//IL_0073: Expected O, but got Unknown
//IL_008a: Unknown result type (might be due to invalid IL or missing references)
//IL_0094: Expected O, but got Unknown
//IL_00cb: Unknown result type (might be due to invalid IL or missing references)
//IL_00d5: Expected O, but got Unknown
//IL_00e3: Unknown result type (might be due to invalid IL or missing references)
//IL_00e9: Expected O, but got Unknown
//IL_00ea: Unknown result type (might be due to invalid IL or missing references)
//IL_011c: Unknown result type (might be due to invalid IL or missing references)
//IL_0123: Expected O, but got Unknown
//IL_0130: Unknown result type (might be due to invalid IL or missing references)
//IL_0137: Expected O, but got Unknown
//IL_014d: Unknown result type (might be due to invalid IL or missing references)
//IL_0181: Unknown result type (might be due to invalid IL or missing references)
//IL_0188: Expected O, but got Unknown
//IL_0195: Unknown result type (might be due to invalid IL or missing references)
//IL_019c: Expected O, but got Unknown
//IL_019e: Unknown result type (might be due to invalid IL or missing references)
//IL_01d2: Unknown result type (might be due to invalid IL or missing references)
//IL_01dc: Expected O, but got Unknown
//IL_01ea: Unknown result type (might be due to invalid IL or missing references)
//IL_01f4: Expected O, but got Unknown
ActiveDiffVis = new BoolField(config.rootPanel, "Show Active Difficulty Times", "active_diff_vis", true);
DiffVis = new BoolField(config.rootPanel, "Hide Other Difficulty Times", "diff_vis", false);
BlockAllRecords = new BoolField(config.rootPanel, "Block All New Records", "records_lock", false);
ConfigPanel diffPanel = new ConfigPanel(config.rootPanel, "Config Difficulties", "diff_panel");
((ConfigField)diffPanel).interactable = !DiffVis.value || !BlockAllRecords.value;
ActiveDiffVis.onValueChange += (BoolValueChangeEventDelegate)delegate(BoolValueChangeEvent e)
{
DiffVis.value = DiffVis.value && e.value;
((ConfigField)DiffVis).interactable = e.value;
DiffVis.TriggerValueChangeEvent();
};
ConfigHeader val = new ConfigHeader(diffPanel, "ACCESSIBLE", 24);
val.textColor = Color.yellow;
DifficultyOption difficultyOption = DifficultyOption.Create((GameDifficulty)0, diffPanel);
DifficultyOption difficultyOption2 = DifficultyOption.Create((GameDifficulty)1, diffPanel);
ConfigHeader val2 = new ConfigHeader(diffPanel, "", 24);
ConfigHeader val3 = new ConfigHeader(diffPanel, "HARD", 24);
val3.textColor = new Color(1f, 0.5f, 0f, 1f);
DifficultyOption difficultyOption3 = DifficultyOption.Create((GameDifficulty)2, diffPanel);
DifficultyOption difficultyOption4 = DifficultyOption.Create((GameDifficulty)3, diffPanel);
ConfigHeader val4 = new ConfigHeader(diffPanel, "", 24);
ConfigHeader val5 = new ConfigHeader(diffPanel, "VERY HARD", 24);
val5.textColor = Color.red;
DifficultyOption difficultyOption5 = DifficultyOption.Create((GameDifficulty)4, diffPanel);
DifficultyOption difficultyOption6 = DifficultyOption.Create((GameDifficulty)5, diffPanel);
DiffVis.onValueChange += (BoolValueChangeEventDelegate)delegate(BoolValueChangeEvent e)
{
foreach (DifficultyOption value in DifficultyVisibility.Values)
{
((ConfigField)value.VisibilityField).interactable = !e.value;
}
((ConfigField)diffPanel).interactable = !e.value || !BlockAllRecords.value;
};
BlockAllRecords.onValueChange += (BoolValueChangeEventDelegate)delegate(BoolValueChangeEvent e)
{
foreach (DifficultyOption value2 in DifficultyVisibility.Values)
{
((ConfigField)value2.RecordSetField).interactable = !e.value;
}
((ConfigField)diffPanel).interactable = !DiffVis.value || !e.value;
};
}
}
[HarmonyPatch(typeof(GameProgressSaver))]
public class GameProgressSaverPatch
{
[HarmonyPrefix]
[HarmonyPatch("SetBestCyber")]
private static bool SetBestCyberPrefix(ref FinalCyberRank fcr)
{
int num = MonoSingleton<PrefsManager>.Instance.GetInt("difficulty", 0);
if (LeaderboardPlugin.DifficultyVisibility.ContainsKey((GameDifficulty)num) && !LeaderboardPlugin.DifficultyVisibility[(GameDifficulty)num].RecordSetField.value)
{
return false;
}
return true;
}
}
[HarmonyPatch(typeof(LeaderboardController))]
public class LeaderboardControllerPatch
{
[HarmonyPostfix]
[HarmonyPatch("FetchLeaderboardEntries")]
private static void FetchLeaderboardEntriesPostfix(ref Task<LeaderboardEntry[]> __result)
{
__result = ModifyLeaderboardEntries(__result);
}
[HarmonyPrefix]
[HarmonyPatch("SubmitCyberGrindScore")]
private static bool SubmitCyberGrindScorePrefix(ref int difficulty, ref float wave, ref int kills, ref int style, ref float seconds)
{
if (LeaderboardPlugin.DifficultyVisibility.ContainsKey((GameDifficulty)difficulty) && !LeaderboardPlugin.DifficultyVisibility[(GameDifficulty)difficulty].RecordSetField.value)
{
return false;
}
return true;
}
[HarmonyPrefix]
[HarmonyPatch("SubmitLevelScore")]
private static bool SubmitScoreAsyncPrefix(ref string levelName, ref int difficulty, ref float seconds, ref int kills, ref int style, ref int restartCount, ref bool pRank)
{
if (LeaderboardPlugin.DifficultyVisibility.ContainsKey((GameDifficulty)difficulty) && !LeaderboardPlugin.DifficultyVisibility[(GameDifficulty)difficulty].RecordSetField.value)
{
return false;
}
return true;
}
private static async Task<LeaderboardEntry[]> ModifyLeaderboardEntries(Task<LeaderboardEntry[]> original)
{
LeaderboardEntry[] entries = await original;
if (entries == null)
{
return (LeaderboardEntry[])(object)new LeaderboardEntry[0];
}
List<LeaderboardEntry> modifiedEntries = new List<LeaderboardEntry>();
LeaderboardEntry[] array = entries;
for (int i = 0; i < array.Length; i++)
{
LeaderboardEntry entry = array[i];
bool showOnlyActive = LeaderboardPlugin.Instance.DiffVis.value;
bool showActive = LeaderboardPlugin.Instance.ActiveDiffVis.value || showOnlyActive;
int num;
if (LeaderboardPlugin.Instance.HideOthers.value)
{
Friend user = entry.User;
num = ((!((Friend)(ref user)).IsMe) ? 1 : 0);
}
else
{
num = 0;
}
bool isOtherAndHidden = (byte)num != 0;
if (showActive && entry.Details[0] == MonoSingleton<PrefsManager>.Instance.GetInt("difficulty", 0) && !isOtherAndHidden)
{
modifiedEntries.Add(entry);
}
else if (!showOnlyActive && LeaderboardPlugin.DifficultyVisibility.ContainsKey((GameDifficulty)entry.Details[0]) && LeaderboardPlugin.DifficultyVisibility[(GameDifficulty)entry.Details[0]].VisibilityField.value && !isOtherAndHidden)
{
modifiedEntries.Add(entry);
}
}
return modifiedEntries.ToArray();
}
}
}