Decompiled source of CorrectifLampes v1.0.0

CorrectifLampes.dll

Decompiled a week ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Logging;
using HarmonyLib;
using Microsoft.CodeAnalysis;
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("CorrectifLampes")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("CorrectifLampes")]
[assembly: AssemblyTitle("CorrectifLampes")]
[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 CorrectifLampes
{
	[BepInPlugin("ak.correctiflampes", "CorrectifLampes", "1.0.0")]
	public class CorrectifLampesPlugin : BaseUnityPlugin
	{
		internal static ManualLogSource Log;

		private void Awake()
		{
			//IL_0010: Unknown result type (might be due to invalid IL or missing references)
			//IL_0016: Expected O, but got Unknown
			//IL_002c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0032: Expected O, but got Unknown
			Log = ((BaseUnityPlugin)this).Logger;
			Harmony val = new Harmony("ak.correctiflampes");
			HarmonyMethod val2 = new HarmonyMethod(typeof(CorrectifLampesPlugin).GetMethod("Nettoyer", BindingFlags.Static | BindingFlags.NonPublic));
			int num = 0;
			foreach (Type item in from t in typeof(RoundManager).GetNestedTypes(BindingFlags.Public | BindingFlags.NonPublic)
				where t.Name.Contains("turnOnLights") || t.Name.Contains("FlickerPoweredLights")
				select t)
			{
				MethodInfo methodInfo = AccessTools.Method(item, "MoveNext", (Type[])null, (Type[])null);
				if (!(methodInfo == null))
				{
					val.Patch((MethodBase)methodInfo, val2, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
					num++;
				}
			}
			MethodInfo methodInfo2 = AccessTools.Method(typeof(RoundManager), "UpdateIndirectLightMode", (Type[])null, (Type[])null);
			if (methodInfo2 != null)
			{
				val.Patch((MethodBase)methodInfo2, val2, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
				num++;
			}
			Log.LogInfo((object)((num == 3) ? "CorrectifLampes actif" : $"CorrectifLampes actif sur {num}/3 fonctions du jeu (version du jeu différente ?)"));
		}

		private static void Nettoyer()
		{
			RoundManager instance = RoundManager.Instance;
			if ((Object)(object)instance == (Object)null)
			{
				return;
			}
			try
			{
				int num = Retirer(instance.allPoweredLightsAnimators, Valide);
				int num2 = Retirer(instance.allPoweredLights, (Light l) => (Object)(object)l != (Object)null);
				if (num + num2 > 0)
				{
					Log.LogWarning((object)$"{num} lampe(s) fantôme(s) et {num2} lumière(s) fantôme(s) retirée(s) de la liste des lumières (objet détruit après l'inscription de ses lampes)");
				}
			}
			catch (Exception arg)
			{
				Log.LogError((object)$"nettoyage des lampes impossible : {arg}");
			}
		}

		private static int Retirer<T>(List<T> liste, Func<T, bool> garder) where T : class
		{
			if (liste == null)
			{
				return 0;
			}
			int count = liste.Count;
			liste.RemoveAll((T x) => !garder(x));
			return count - liste.Count;
		}

		private static bool Valide(Animator a)
		{
			if ((Object)(object)a == (Object)null)
			{
				return false;
			}
			try
			{
				_ = ((Component)a).gameObject;
				_ = a.runtimeAnimatorController;
				return true;
			}
			catch (Exception ex)
			{
				Log.LogWarning((object)("lampe illisible retirée (" + ex.GetType().Name + ")"));
				return false;
			}
		}
	}
}