Decompiled source of BetterSprayPaint v80Fix v1.0.0

BSPv80Fix.dll

Decompiled 3 hours ago
using System;
using System.Diagnostics;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Logging;
using BetterSprayPaint;
using BetterSprayPaint.Ngo;
using GameNetcodeStuff;
using HarmonyLib;
using Microsoft.CodeAnalysis;
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(".NETFramework,Version=v4.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")]
[assembly: AssemblyCompany("BSPv80Fix")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("BSPv80Fix")]
[assembly: AssemblyTitle("BSPv80Fix")]
[assembly: AssemblyVersion("1.0.0.0")]
[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 BSPv80Fix
{
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	[BepInPlugin("aspect.BSPv80Fix", "BetterSprayPaint v80 Fix", "1.0.0")]
	public class BSPv80Fix : BaseUnityPlugin
	{
		private static ManualLogSource Log;

		private static Harmony harmony;

		private void Awake()
		{
			//IL_0021: Unknown result type (might be due to invalid IL or missing references)
			//IL_002b: Expected O, but got Unknown
			Log = ((BaseUnityPlugin)this).Logger;
			Log.LogInfo((object)"BetterSprayPaint v80 Fix loaded");
			harmony = new Harmony("aspect.BSPv80Fix");
			harmony.PatchAll();
		}
	}
}
namespace BSPv80Fix.Patches
{
	[HarmonyPatch(typeof(SprayPaintItemNetExt), "get_HeldByLocalPlayer")]
	internal class HeldByLocalPlayerPatch
	{
		private static bool Prefix(SprayPaintItemNetExt __instance, ref bool __result)
		{
			SprayPaintItem item = ((Component)__instance).GetComponent<SprayPaintItem>();
			PlayerControllerB val = ((GrabbableObject)(item?)).playerHeldBy;
			if ((Object)(object)val == (Object)null || !Utils.IsLocalPlayer(val))
			{
				__result = false;
				return false;
			}
			if (val.ItemSlots != null && val.ItemSlots.Any((GrabbableObject slot) => (Object)(object)slot == (Object)(object)item))
			{
				__result = true;
				return false;
			}
			if (val.currentItemSlot == 50 && (Object)(object)val.currentlyHeldObjectServer == (Object)(object)item)
			{
				__result = true;
				return false;
			}
			__result = false;
			return false;
		}
	}
	[HarmonyPatch(typeof(SprayPaintItemNetExt), "get_InActiveSlot")]
	internal class SafeInActiveSlotPatch
	{
		private static bool Prefix(SprayPaintItemNetExt __instance, ref bool __result)
		{
			SprayPaintItem component = ((Component)__instance).GetComponent<SprayPaintItem>();
			PlayerControllerB val = ((GrabbableObject)(component?)).playerHeldBy;
			if ((Object)(object)val == (Object)null || !Utils.IsLocalPlayer(val))
			{
				__result = false;
				return false;
			}
			int currentItemSlot = val.currentItemSlot;
			if (currentItemSlot < 0 || currentItemSlot >= val.ItemSlots.Length)
			{
				__result = false;
				return false;
			}
			__result = (Object)(object)val.ItemSlots[currentItemSlot] == (Object)(object)component;
			return false;
		}
	}
	[HarmonyPatch(typeof(SprayPaintItemExt), "ItemActive")]
	internal class ItemActivePatch
	{
		private static bool Prefix(SprayPaintItemExt __instance, ref bool __result)
		{
			GrabbableObject instance = (GrabbableObject)(object)__instance.instance;
			PlayerControllerB playerHeldBy = instance.playerHeldBy;
			if ((Object)(object)playerHeldBy == (Object)null || !Utils.IsLocalPlayer(playerHeldBy))
			{
				__result = false;
				return false;
			}
			if (playerHeldBy.currentItemSlot == 50 && (Object)(object)playerHeldBy.currentlyHeldObjectServer == (Object)(object)instance)
			{
				__result = true;
				return false;
			}
			if (playerHeldBy.currentItemSlot >= 0 && playerHeldBy.currentItemSlot < playerHeldBy.ItemSlots.Length && (Object)(object)playerHeldBy.ItemSlots[playerHeldBy.currentItemSlot] == (Object)(object)instance)
			{
				__result = true;
				return false;
			}
			__result = false;
			return false;
		}
	}
	[HarmonyPatch(typeof(SprayPaintItemNetExt), "Update")]
	internal class NetUpdatePatch
	{
		private static void Postfix(SprayPaintItemNetExt __instance)
		{
			SprayPaintItem component = ((Component)__instance).GetComponent<SprayPaintItem>();
			PlayerControllerB val = ((GrabbableObject)(component?)).playerHeldBy;
			if (!((Object)(object)val == (Object)null) && Utils.IsLocalPlayer(val))
			{
				bool flag = val.currentItemSlot == 50 && (Object)(object)val.currentlyHeldObjectServer == (Object)(object)component;
				bool flag2 = val.currentItemSlot >= 0 && val.currentItemSlot < val.ItemSlots.Length && (Object)(object)val.ItemSlots[val.currentItemSlot] == (Object)(object)component;
				if (!flag && !flag2)
				{
					SprayPaintItemNetExt val2 = Utils.NetExt(component);
					val2.IsErasing = false;
				}
			}
		}
	}
	[HarmonyPatch(typeof(SprayPaintItemNetExt), "get_InActiveSlot")]
	internal class InActiveSlotPatch
	{
		private static bool Prefix(SprayPaintItemNetExt __instance, ref bool __result)
		{
			SprayPaintItem component = ((Component)__instance).GetComponent<SprayPaintItem>();
			PlayerControllerB val = ((GrabbableObject)(component?)).playerHeldBy;
			if ((Object)(object)val == (Object)null || !Utils.IsLocalPlayer(val))
			{
				__result = false;
				return false;
			}
			if (val.currentItemSlot == 50 && (Object)(object)val.currentlyHeldObjectServer == (Object)(object)component)
			{
				__result = true;
				return false;
			}
			int currentItemSlot = val.currentItemSlot;
			if (currentItemSlot < 0 || currentItemSlot >= val.ItemSlots.Length)
			{
				__result = false;
				return false;
			}
			__result = (Object)(object)val.ItemSlots[currentItemSlot] == (Object)(object)component;
			return false;
		}
	}
	[HarmonyPatch(typeof(PlayerControllerB), "UseUtilitySlot_performed")]
	internal class UtilitySlotPatch
	{
		private static void Postfix(PlayerControllerB __instance)
		{
			GrabbableObject currentlyHeldObjectServer = __instance.currentlyHeldObjectServer;
			if (!((Object)(object)currentlyHeldObjectServer == (Object)null))
			{
				((Component)currentlyHeldObjectServer).SendMessage("ItemActive", (SendMessageOptions)1);
			}
		}
	}
}