Decompiled source of NoMineDust v1.0.0

NoMineDust.dll

Decompiled 20 hours ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using BepInEx;
using HarmonyLib;
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("NoPicaxeDust")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("NoPicaxeDust")]
[assembly: AssemblyCopyright("Copyright ©  2026")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("ba8a8ced-044a-4da9-b4b1-d44713a235e7")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.6.2", FrameworkDisplayName = ".NET Framework 4.6.2")]
[assembly: AssemblyVersion("1.0.0.0")]
namespace NoMineDust;

[BepInPlugin("zhaila0.NoMineDust", "No Mine Dust", "1.0.0")]
public class Plugin : BaseUnityPlugin
{
	internal static readonly HashSet<string> BlockedEffects = new HashSet<string>(StringComparer.OrdinalIgnoreCase) { "vfx_RockDestroyed", "vfx_RockDestroyed_large", "vfx_MudDestroyed", "vfx_CoalDestroyed", "fx_flametalnode_destruction", "vfx_RockHit", "vfx_MudHit", "vfx_CoalHit" };

	private void Awake()
	{
		//IL_0006: Unknown result type (might be due to invalid IL or missing references)
		new Harmony("zhaila0.NoMineDust").PatchAll();
	}
}
[HarmonyPatch(typeof(ZNetScene), "Awake")]
internal static class ZNetScene_Awake_Patch
{
	private static void Postfix(ZNetScene __instance)
	{
		HashSet<GameObject> hashSet = new HashSet<GameObject>();
		foreach (GameObject prefab in __instance.m_prefabs)
		{
			if ((Object)(object)prefab == (Object)null || !hashSet.Add(prefab))
			{
				continue;
			}
			foreach (Component targetComponent in GetTargetComponents(prefab))
			{
				StripDestroyEffects(targetComponent);
			}
		}
	}

	private static IEnumerable<Component> GetTargetComponents(GameObject prefab)
	{
		MineRock[] components = prefab.GetComponents<MineRock>();
		for (int i = 0; i < components.Length; i++)
		{
			yield return (Component)(object)components[i];
		}
		MineRock5[] components2 = prefab.GetComponents<MineRock5>();
		for (int j = 0; j < components2.Length; j++)
		{
			yield return (Component)(object)components2[j];
		}
		if (((Object)prefab).name.StartsWith("Rock_", StringComparison.Ordinal) || ((Object)prefab).name.StartsWith("MineRock_", StringComparison.Ordinal) || ((Object)prefab).name.StartsWith("mudpile", StringComparison.Ordinal))
		{
			Destructible[] components3 = prefab.GetComponents<Destructible>();
			for (int k = 0; k < components3.Length; k++)
			{
				yield return (Component)(object)components3[k];
			}
		}
	}

	private static void StripDestroyEffects(Component comp)
	{
		IEnumerable<FieldInfo> enumerable = from f in ((object)comp).GetType().GetFields(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic)
			where f.FieldType == typeof(EffectList) && (f.Name.IndexOf("destroy", StringComparison.OrdinalIgnoreCase) >= 0 || f.Name.IndexOf("hit", StringComparison.OrdinalIgnoreCase) >= 0)
			select f;
		foreach (FieldInfo item in enumerable)
		{
			object? value = item.GetValue(comp);
			EffectList val = (EffectList)((value is EffectList) ? value : null);
			if (val?.m_effectPrefabs != null)
			{
				EffectData[] array = val.m_effectPrefabs.Where((EffectData e) => (Object)(object)e?.m_prefab == (Object)null || !Plugin.BlockedEffects.Contains(((Object)e.m_prefab).name)).ToArray();
				if (array.Length != val.m_effectPrefabs.Length)
				{
					val.m_effectPrefabs = array;
				}
			}
		}
	}
}