Decompiled source of MarkAllSeen v1.0.0

MarkAllSeen.dll

Decompiled 9 hours ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using BepInEx;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using RiskOfOptions;
using RiskOfOptions.Options;
using RoR2;
using RoR2.UI;
using UnityEngine.Events;

[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("MarkAllSeen")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("MarkAllSeen")]
[assembly: AssemblyTitle("MarkAllSeen")]
[assembly: AssemblyVersion("1.0.0.0")]
[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;
		}
	}
}
namespace MarkAllSeen
{
	[BepInPlugin("revor.MarkAllSeen", "MarkAllSeen", "1.0.0")]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	public class MarkAllSeenPlugin : BaseUnityPlugin
	{
		public const string PluginGUID = "revor.MarkAllSeen";

		private static readonly FieldRef<Dictionary<string, Node>> allNodes = AccessTools.StaticFieldRefAccess<Dictionary<string, Node>>(AccessTools.Field(typeof(ViewablesCatalog), "fullNameToNodeMap"));

		private static readonly FieldRef<UserProfile, List<string>> viewedViewables = AccessTools.FieldRefAccess<UserProfile, List<string>>("viewedViewables");

		private void Awake()
		{
			//IL_0025: Unknown result type (might be due to invalid IL or missing references)
			//IL_002f: Expected O, but got Unknown
			//IL_002a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0034: Expected O, but got Unknown
			ModSettingsManager.SetModDescription("Clear every \"New!\" marker on your profile with one button.");
			ModSettingsManager.AddOption((BaseOption)new GenericButtonOption("Mark all as seen", "General", "Marks everything currently showing \"New!\" as seen: logbook entries, items, skills, skins and survivors. Things you unlock later still show as new.", "Mark all", new UnityAction(MarkAll)));
		}

		private void MarkAll()
		{
			//IL_0072: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ac: Unknown result type (might be due to invalid IL or missing references)
			int num = 0;
			foreach (LocalUser readOnlyLocalUsers in LocalUserManager.readOnlyLocalUsersList)
			{
				if (((readOnlyLocalUsers != null) ? readOnlyLocalUsers.userProfile : null) != null)
				{
					num += MarkAll(readOnlyLocalUsers.userProfile);
				}
			}
			((BaseUnityPlugin)this).Logger.LogInfo((object)$"Marked {num} viewables as seen.");
			SimpleDialogBox obj = SimpleDialogBox.Create((MPEventSystem)null);
			obj.headerToken = new TokenParamsPair("Mark all as seen", Array.Empty<object>());
			obj.descriptionToken = new TokenParamsPair((num == 0) ? "Nothing to mark: you've already seen everything." : string.Format("Marked {0} {1} as seen.", num, (num == 1) ? "entry" : "entries"), Array.Empty<object>());
			obj.AddCancelButton("OK", Array.Empty<object>());
		}

		private static int MarkAll(UserProfile profile)
		{
			List<string> list = new List<string>();
			foreach (Node value in allNodes.Invoke().Values)
			{
				if (value != null && !value.isFolder && value.shouldShowUnviewed != null && value.shouldShowUnviewed(profile))
				{
					list.Add(value.fullName);
				}
			}
			if (list.Count == 0)
			{
				return 0;
			}
			List<string> list2 = viewedViewables.Invoke(profile);
			for (int i = 0; i < list.Count - 1; i++)
			{
				if (!list2.Contains(list[i]))
				{
					list2.Add(list[i]);
				}
			}
			profile.MarkViewableAsViewed(list[list.Count - 1]);
			return list.Count;
		}
	}
}