Decompiled source of BloodVFXTweaks v1.0.0

BloodVFXTweaks.dll

Decompiled 6 hours ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Configuration;
using GameNetcodeStuff;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using Unity.Netcode;
using UnityEngine;
using UnityEngine.Rendering.HighDefinition;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("BloodVFXTweaks")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("BloodVFXTweaks")]
[assembly: AssemblyTitle("BloodVFXTweaks")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
[module: UnverifiableCode]
[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 BloodVFXTweaks
{
	[BepInPlugin("com.mavka.bloodvfxtweaks", "BloodVFX Tweaks", "2.2.3")]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	public class Plugin : BaseUnityPlugin
	{
		public static CauseOfDeath LastDeathCause;

		public static bool WasSinking;

		private void Awake()
		{
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_000c: Expected O, but got Unknown
			//IL_010c: Unknown result type (might be due to invalid IL or missing references)
			//IL_011a: Expected O, but got Unknown
			Harmony val = new Harmony("com.mavka.bloodvfxtweaks");
			val.PatchAll(typeof(Patches));
			Assembly[] assemblies = AppDomain.CurrentDomain.GetAssemblies();
			foreach (Assembly assembly in assemblies)
			{
				if (!assembly.GetName().Name.ToLower().Contains("blood"))
				{
					continue;
				}
				Type[] types = assembly.GetTypes();
				foreach (Type type in types)
				{
					MethodInfo[] methods = type.GetMethods(BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic);
					foreach (MethodInfo methodInfo in methods)
					{
						string text = methodInfo.Name.ToLower();
						if ((text.Contains("spawngib") || text.Contains("triggergib") || text.Contains("burstbody") || text.Contains("tearlimb")) && methodInfo.ReturnType == typeof(void))
						{
							try
							{
								val.Patch((MethodBase)methodInfo, new HarmonyMethod(typeof(Patches), "OnlyOnBlast", (Type[])null), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
							}
							catch
							{
							}
						}
					}
				}
			}
		}
	}
	public class Patches
	{
		private static bool cfgDone;

		private static float nextBloodCheck;

		[HarmonyPatch(typeof(PlayerControllerB), "KillPlayer")]
		[HarmonyPrefix]
		private static void SaveDeathInfo(PlayerControllerB __instance, CauseOfDeath causeOfDeath)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			Plugin.LastDeathCause = causeOfDeath;
			Plugin.WasSinking = __instance.sinkingValue > 0.25f || __instance.isSinking;
		}

		[HarmonyPatch(typeof(DeadBodyInfo), "Start")]
		[HarmonyPostfix]
		private static void RemoveSunkenBody(DeadBodyInfo __instance)
		{
			//IL_0008: Unknown result type (might be due to invalid IL or missing references)
			//IL_000f: Invalid comparison between Unknown and I4
			//IL_0011: Unknown result type (might be due to invalid IL or missing references)
			//IL_0017: Invalid comparison between Unknown and I4
			if ((Plugin.WasSinking || (int)Plugin.LastDeathCause == 9 || (int)Plugin.LastDeathCause == 5) && (Object)(object)__instance.playerScript != (Object)null && (__instance.playerScript.sinkingValue > 0.25f || Plugin.WasSinking))
			{
				((Component)__instance).gameObject.SetActive(false);
				Object.Destroy((Object)(object)((Component)__instance).gameObject);
			}
		}

		public static bool OnlyOnBlast()
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0006: Invalid comparison between Unknown and I4
			return (int)Plugin.LastDeathCause == 3;
		}

		[HarmonyPatch(typeof(GrabbableObject), "Start")]
		[HarmonyPostfix]
		private static void NoHeadGrab(GrabbableObject __instance)
		{
			string text = ((Object)((Component)__instance).gameObject).name.ToLower();
			if (text.Contains("gib") || text.Contains("severed") || (text.Contains("head") && !text.Contains("headlamp") && !text.Contains("bobblehead")))
			{
				__instance.grabbable = false;
				((Behaviour)__instance).enabled = false;
			}
		}

		[HarmonyPatch(typeof(PlayerControllerB), "LateUpdate")]
		[HarmonyPostfix]
		private static void FixCam(PlayerControllerB __instance)
		{
			if (((NetworkBehaviour)__instance).IsOwner && __instance.isPlayerDead && (Object)(object)StartOfRound.Instance?.spectateCamera != (Object)null)
			{
				((Behaviour)StartOfRound.Instance.spectateCamera).enabled = true;
			}
		}

		[HarmonyPatch(typeof(RoundManager), "Update")]
		[HarmonyPostfix]
		private static void UpdateConfigAndColor()
		{
			if (!cfgDone)
			{
				BaseUnityPlugin[] array = Object.FindObjectsOfType<BaseUnityPlugin>();
				foreach (BaseUnityPlugin val in array)
				{
					object obj;
					if (val == null)
					{
						obj = null;
					}
					else
					{
						PluginInfo info = val.Info;
						obj = ((info != null) ? info.Metadata.GUID : null);
					}
					if ((string?)obj != "com.y4ngz.bloodfx")
					{
						continue;
					}
					foreach (KeyValuePair<ConfigDefinition, ConfigEntryBase> item in val.Config)
					{
						string key = item.Key.Key;
						if (key == "Gib Death Causes" && item.Value is ConfigEntry<string> val2)
						{
							val2.Value = "Blast";
						}
						switch (key)
						{
						case "Gib Full Velocity":
						case "Gib Partial Velocity":
						case "Gib Impact Velocity":
							if (item.Value is ConfigEntry<float> val3)
							{
								val3.Value = 0f;
							}
							break;
						}
						if (key.StartsWith("Gib Source") && item.Value is ConfigEntry<string> val4)
						{
							val4.Value = "Off";
						}
						if (key == "Gib Partial Chance" && item.Value is ConfigEntry<int> val5)
						{
							val5.Value = 0;
						}
					}
					val.Config.Save();
					cfgDone = true;
				}
			}
			if (Time.time < nextBloodCheck)
			{
				return;
			}
			nextBloodCheck = Time.time + 0.4f;
			DecalProjector[] array2 = Object.FindObjectsOfType<DecalProjector>();
			foreach (DecalProjector val6 in array2)
			{
				if (!((Object)(object)((val6 != null) ? val6.material : null) == (Object)null) && (((Object)val6.material).name.ToLower().Contains("blood") || ((Object)((Component)val6).gameObject).name.ToLower().Contains("blood")))
				{
					if (val6.material.HasProperty("_Smoothness"))
					{
						val6.material.SetFloat("_Smoothness", 0.35f);
					}
					if (val6.material.HasProperty("_Metallic"))
					{
						val6.material.SetFloat("_Metallic", 0f);
					}
				}
			}
		}
	}
}