Decompiled source of LessLogs v1.0.1

patchers/LessLogs/LessLogs.dll

Decompiled a year ago
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.Security;
using System.Security.Permissions;
using System.Text.RegularExpressions;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using HarmonyLib;
using JetBrains.Annotations;
using Microsoft.CodeAnalysis;
using Mono.Cecil;
using UnityEngine;

[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("LessLogs")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyDescription("Prevents mods from spamming the BepInEx log.")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("LessLogs")]
[assembly: AssemblyTitle("LessLogs")]
[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.Module, AllowMultiple = false, Inherited = false)]
	internal sealed class RefSafetyRulesAttribute : Attribute
	{
		public readonly int Version;

		public RefSafetyRulesAttribute(int P_0)
		{
			Version = P_0;
		}
	}
}
namespace LessLogs
{
	public static class LessLogs
	{
		[HarmonyPatch(typeof(ManualLogSource), "Log")]
		private static class Patch_ManualLogSource_Log
		{
			private static bool Prefix(LogLevel level)
			{
				//IL_0024: Unknown result type (might be due to invalid IL or missing references)
				//IL_0029: Unknown result type (might be due to invalid IL or missing references)
				//IL_002a: Unknown result type (might be due to invalid IL or missing references)
				//IL_002c: Invalid comparison between Unknown and I4
				if (logLevel.TryGetValue(new StackFrame(3).GetMethod().DeclaringType.Assembly, out var value))
				{
					return (value.Value & level) > 0;
				}
				return true;
			}
		}

		[HarmonyPatch(typeof(Logger), "InitializeInternalLoggers")]
		private static class Patch_Preloader_PatchEntrypoint
		{
			[HarmonyPatch(typeof(UnityLogSource), "OnUnityLogMessageReceived")]
			private static class Patch_UnityLogSource_OnUnityLogMessageReceived
			{
				private static bool Prefix(LogType type)
				{
					//IL_0000: Unknown result type (might be due to invalid IL or missing references)
					//IL_001a: Expected I4, but got Unknown
					//IL_001d: Unknown result type (might be due to invalid IL or missing references)
					//IL_0021: 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_0066: Unknown result type (might be due to invalid IL or missing references)
					//IL_006b: 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_006e: Invalid comparison between Unknown and I4
					LogLevel val;
					switch ((int)type)
					{
					case 0:
					case 1:
					case 4:
						val = (LogLevel)2;
						break;
					case 2:
						val = (LogLevel)4;
						break;
					default:
						val = (LogLevel)16;
						break;
					}
					MethodBase method = new StackFrame(8).GetMethod();
					if (method == null || method.DeclaringType == null)
					{
						return true;
					}
					if (logLevel.TryGetValue(method.DeclaringType.Assembly, out var value))
					{
						return (value.Value & val) > 0;
					}
					return true;
				}
			}

			[HarmonyPatch(/*Could not decode attribute arguments.*/)]
			private static class Patch_BaseUnityPlugin
			{
				private static void Postfix(BaseUnityPlugin __instance)
				{
					Regex regex = new Regex("['[\"\\]]");
					logLevel[((object)__instance).GetType().Assembly] = Config.Bind<LogLevel>("General", regex.Replace(__instance.Info.Metadata.Name, ""), (LogLevel)7, (ConfigDescription)null);
				}
			}

			private static void Prefix()
			{
				//IL_0005: 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)
				Harmony val = new Harmony("org.bepinex.patchers.lesslogs.inner");
				val.PatchAll(typeof(Patch_UnityLogSource_OnUnityLogMessageReceived));
				val.PatchAll(typeof(Patch_BaseUnityPlugin));
			}
		}

		private static readonly ConfigFile Config = new ConfigFile(Path.Combine(Paths.ConfigPath, "LessLogs.cfg"), true);

		private static readonly Dictionary<Assembly, ConfigEntry<LogLevel>> logLevel = new Dictionary<Assembly, ConfigEntry<LogLevel>>();

		public static IEnumerable<string> TargetDLLs { get; } = Array.Empty<string>();


		public static void Patch(AssemblyDefinition assembly)
		{
		}

		[UsedImplicitly]
		public static void Initialize()
		{
			//IL_0005: 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)
			Harmony val = new Harmony("org.bepinex.patchers.lesslogs");
			val.PatchAll(typeof(Patch_ManualLogSource_Log));
			val.PatchAll(typeof(Patch_Preloader_PatchEntrypoint));
		}
	}
	public static class MyPluginInfo
	{
		public const string PLUGIN_GUID = "LessLogs";

		public const string PLUGIN_NAME = "LessLogs";

		public const string PLUGIN_VERSION = "1.0.0";
	}
}