Decompiled source of BloodVFXTweaks Updated v1.0.1

BloodVFXTweaks.dll

Decompiled 2 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;
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.5.0")]
	[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 readonly HashSet<Material> TrackedBloodMaterials = new HashSet<Material>();

		private static readonly string[] AnimKeywords = new string[18]
		{
			"speed", "scroll", "pan", "flow", "wave", "ripple", "wobble", "turbulence", "distort", "warp",
			"displace", "sway", "pulse", "shimmer", "anim", "freq", "rate", "time"
		};

		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(StartOfRound), "Start")]
		[HarmonyPostfix]
		private static void ApplyConfigOnce()
		{
			TrackedBloodMaterials.Clear();
			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();
				break;
			}
		}

		[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);
			}
		}

		[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)
			{
				((Behaviour)StartOfRound.Instance.spectateCamera).enabled = true;
			}
		}

		[HarmonyPatch(typeof(DecalProjector), "OnEnable")]
		[HarmonyPostfix]
		private static void TuneDecalOnSpawn(DecalProjector __instance)
		{
			//IL_01bf: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c4: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c6: Unknown result type (might be due to invalid IL or missing references)
			//IL_01dc: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e9: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f6: Unknown result type (might be due to invalid IL or missing references)
			//IL_01fd: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)__instance == (Object)null || (Object)(object)__instance.material == (Object)null)
			{
				return;
			}
			string text = ((Object)__instance.material).name.ToLower();
			string text2 = ((Object)((Component)__instance).gameObject).name.ToLower();
			string text3 = (((Object)(object)__instance.material.shader != (Object)null) ? ((Object)__instance.material.shader).name.ToLower() : "");
			if (!text.Contains("blood") && !text2.Contains("blood") && !text3.Contains("blood") && !text.Contains("splat") && !text2.Contains("splat") && !text.Contains("puddle") && !text2.Contains("puddle") && !text.Contains("stain") && !text2.Contains("stain") && !text.Contains("drip") && !text2.Contains("drip") && !text.Contains("wound") && !text2.Contains("wound") && !text.Contains("footprint") && !text2.Contains("footprint") && !text2.Contains("boot"))
			{
				return;
			}
			TrackedBloodMaterials.Add(__instance.material);
			FreezeBloodMaterial(__instance.material);
			if (text.Contains("footprint") || text2.Contains("footprint") || text2.Contains("boot") || text2.Contains("step"))
			{
				Vector3 size = __instance.size;
				if (size.x < 0.45f)
				{
					__instance.size = new Vector3(size.x * 1.45f, size.y * 1.45f, size.z);
				}
			}
		}

		[HarmonyPatch(typeof(RoundManager), "Update")]
		[HarmonyPostfix]
		private static void KeepBloodStatic()
		{
			if (TrackedBloodMaterials.Count == 0)
			{
				return;
			}
			foreach (Material trackedBloodMaterial in TrackedBloodMaterials)
			{
				if ((Object)(object)trackedBloodMaterial != (Object)null)
				{
					FreezeBloodMaterial(trackedBloodMaterial);
				}
			}
		}

		private static void FreezeBloodMaterial(Material mat)
		{
			//IL_0042: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ad: Unknown result type (might be due to invalid IL or missing references)
			//IL_00af: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b2: Invalid comparison between Unknown and I4
			//IL_00b4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b7: Invalid comparison between Unknown and I4
			//IL_00d2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d5: Invalid comparison between Unknown and I4
			//IL_00e0: Unknown result type (might be due to invalid IL or missing references)
			if (mat.HasProperty("_Smoothness"))
			{
				mat.SetFloat("_Smoothness", 0.35f);
			}
			if (mat.HasProperty("_Metallic"))
			{
				mat.SetFloat("_Metallic", 0f);
			}
			mat.mainTextureOffset = Vector2.zero;
			Shader shader = mat.shader;
			if ((Object)(object)shader == (Object)null)
			{
				return;
			}
			int propertyCount = shader.GetPropertyCount();
			for (int i = 0; i < propertyCount; i++)
			{
				string propertyName = shader.GetPropertyName(i);
				string text = propertyName.ToLower();
				for (int j = 0; j < AnimKeywords.Length; j++)
				{
					if (text.Contains(AnimKeywords[j]))
					{
						ShaderPropertyType propertyType = shader.GetPropertyType(i);
						if ((int)propertyType == 2 || (int)propertyType == 3)
						{
							mat.SetFloat(propertyName, 0f);
						}
						else if ((int)propertyType == 1)
						{
							mat.SetVector(propertyName, Vector4.zero);
						}
						break;
					}
				}
			}
		}
	}
}