Decompiled source of LCSprayFix v1.0.4

LCSprayFix.dll

Decompiled 10 months ago
using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using HarmonyLib;
using LCSprayFix.Patches;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: AssemblyTitle("LCSprayFix")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("LCSprayFix")]
[assembly: AssemblyCopyright("Copyright ©  2024")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("4E067BF4-EF57-413C-9834-A61AA01E5CEF")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.8.1", FrameworkDisplayName = ".NET Framework 4.8.1")]
[assembly: AssemblyVersion("1.0.0.0")]
namespace LCSprayFix
{
	[BepInPlugin("Spltiface.LCSprayFix", "LCSprayFix", "1.0.4")]
	public class LCSprayFix : BaseUnityPlugin
	{
		private readonly Harmony harmony = new Harmony("Spltiface.LCSprayFix");

		public static LCSprayFix Instance { get; private set; }

		public ManualLogSource Logger { get; private set; }

		public PluginConfig Config { get; private set; }

		private void Awake()
		{
			if ((Object)(object)Instance == (Object)null)
			{
				Instance = this;
			}
			Logger = ((BaseUnityPlugin)this).Logger;
			Config = new PluginConfig(((BaseUnityPlugin)this).Config);
			harmony.PatchAll(typeof(LCSprayFix));
			harmony.PatchAll(typeof(StartMatchLeverPatch));
			harmony.PatchAll(typeof(StartOfRoundPatch));
			harmony.PatchAll(typeof(SprayPaintItemPatch));
			harmony.PatchAll(typeof(GameNetworkManagerPatch));
			Logger.LogInfo((object)"I have loaded.");
		}
	}
	public class PluginConfig
	{
		public bool DEV_MODE { get; private set; }

		public ConfigFile Config { get; private set; }

		public PluginConfig(ConfigFile cfg)
		{
			Config = cfg;
			InitConfig();
		}

		private T ConfigEntry<T>(string section, string key, T defaultVal, string description)
		{
			return Config.Bind<T>(section, key, defaultVal, description).Value;
		}

		private void InitConfig()
		{
			DEV_MODE = ConfigEntry("Other", "Dev Mode", defaultVal: false, "Enable this for some extra logging.");
		}
	}
	public class PluginData
	{
		public const string Guid = "Spltiface.LCSprayFix";

		public const string Name = "LCSprayFix";

		public const string Version = "1.0.4";
	}
}
namespace LCSprayFix.Patches
{
	[HarmonyPatch(typeof(StartMatchLever))]
	public class StartMatchLeverPatch
	{
		[HarmonyPostfix]
		[HarmonyPatch("EndGame")]
		private static void SprayPaintPatch()
		{
			SprayCanFix.RemoveAllPaint();
		}
	}
	[HarmonyPatch(typeof(StartOfRound))]
	public class StartOfRoundPatch
	{
		[HarmonyPostfix]
		[HarmonyPatch("ShipLeaveAutomatically")]
		private static void ShipLeaveAutomaticallyPatch()
		{
			SprayCanFix.RemoveAllPaint();
		}
	}
	[HarmonyPatch(typeof(SprayPaintItem))]
	public class SprayPaintItemPatch
	{
		[HarmonyPostfix]
		[HarmonyPatch("AddSprayPaintLocal")]
		private static void AddSprayPaintLocalPatch()
		{
			SprayCanFix.UpdatePaintToRemove();
		}
	}
	[HarmonyPatch(typeof(GameNetworkManager))]
	public class GameNetworkManagerPatch
	{
		[HarmonyPostfix]
		[HarmonyPatch("Disconnect")]
		private static void DisconnectPatch()
		{
			SprayCanFix.ClearPaintToRemove();
		}
	}
	public class SprayCanFix
	{
		private static readonly HashSet<GameObject> allSprayDecals = new HashSet<GameObject>();

		public static void UpdatePaintToRemove()
		{
			if (SprayPaintItem.sprayPaintDecals.Count > 0)
			{
				allSprayDecals.Add(SprayPaintItem.sprayPaintDecals[SprayPaintItem.sprayPaintDecalsIndex]);
			}
		}

		public static void ClearPaintToRemove()
		{
			allSprayDecals.Clear();
		}

		public static void RemoveAllPaint()
		{
			if (LCSprayFix.Instance.Config.DEV_MODE)
			{
				LCSprayFix.Instance.Logger.LogInfo((object)"Removing all spray");
			}
			int num = 0;
			int num2 = 0;
			int num3 = 0;
			foreach (GameObject allSprayDecal in allSprayDecals)
			{
				if ((Object)(object)allSprayDecal == (Object)null)
				{
					num++;
					continue;
				}
				if (allSprayDecal.activeSelf)
				{
					num3++;
					allSprayDecal.SetActive(false);
				}
				num2++;
				Object.Destroy((Object)(object)allSprayDecal);
			}
			if (LCSprayFix.Instance.Config.DEV_MODE)
			{
				LCSprayFix.Instance.Logger.LogInfo((object)$"Total spray to delete: {allSprayDecals.Count}");
				LCSprayFix.Instance.Logger.LogInfo((object)$"Total spray removed: {num2}");
				LCSprayFix.Instance.Logger.LogInfo((object)$"Total null spray skipped: {num}");
				LCSprayFix.Instance.Logger.LogInfo((object)$"Total spray was active: {num3}");
			}
		}
	}
}