Decompiled source of Dull Arrows v0.1.0

FrizzQOL.DullArrows.dll

Decompiled 2 weeks ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using BepInEx;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")]
[assembly: AssemblyCompany("FrizzQOL.DullArrows")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0+7c34f229472a147d660bf41a4a7fed36251c9290")]
[assembly: AssemblyProduct("FrizzQOL.DullArrows")]
[assembly: AssemblyTitle("FrizzQOL.DullArrows")]
[assembly: AssemblyVersion("1.0.0.0")]
[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 DullArrows
{
	[HarmonyPatch(typeof(ObjectDB), "Awake")]
	internal static class ObjectDBAwakePatch
	{
		private static void Postfix(ObjectDB __instance)
		{
			//IL_0079: Unknown result type (might be due to invalid IL or missing references)
			//IL_0080: Invalid comparison between Unknown and I4
			//IL_0084: Unknown result type (might be due to invalid IL or missing references)
			//IL_008b: Invalid comparison between Unknown and I4
			if ((Object)(object)__instance == (Object)null || __instance.m_items == null)
			{
				Plugin.LogWarning("ObjectDB item list missing.");
				return;
			}
			HashSet<int> seen = new HashSet<int>();
			int num = 0;
			foreach (GameObject item in __instance.m_items)
			{
				if ((Object)(object)item == (Object)null)
				{
					continue;
				}
				ItemDrop component = item.GetComponent<ItemDrop>();
				SharedData val = ((!((Object)(object)component != (Object)null)) ? null : component.m_itemData?.m_shared);
				if (val != null && ((int)val.m_itemType == 9 || (int)val.m_itemType == 23))
				{
					if (ArrowGlow.Dull(item, seen))
					{
						num++;
						Plugin.LogInfo("Removed tip glow from " + ((Object)item).name);
					}
					GameObject val2 = ((val.m_attack != null) ? val.m_attack.m_attackProjectile : null);
					if ((Object)(object)val2 != (Object)null && ArrowGlow.Dull(val2, seen))
					{
						Plugin.LogInfo("Removed tip glow from projectile " + ((Object)val2).name);
					}
				}
			}
			Plugin.LogInfo("Dulled " + num + " ammo prefabs.");
		}
	}
	internal static class ArrowGlow
	{
		public static bool Dull(GameObject prefab, HashSet<int> seen)
		{
			//IL_00aa: 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)
			if ((Object)(object)prefab == (Object)null || !seen.Add(((Object)prefab).GetInstanceID()))
			{
				return false;
			}
			bool result = false;
			Renderer[] componentsInChildren = prefab.GetComponentsInChildren<Renderer>(true);
			for (int i = 0; i < componentsInChildren.Length; i++)
			{
				Material[] sharedMaterials = componentsInChildren[i].sharedMaterials;
				for (int j = 0; j < sharedMaterials.Length; j++)
				{
					if (TurnOffEmission(sharedMaterials[j]))
					{
						result = true;
					}
				}
			}
			Light[] componentsInChildren2 = prefab.GetComponentsInChildren<Light>(true);
			for (int k = 0; k < componentsInChildren2.Length; k++)
			{
				componentsInChildren2[k].intensity = 0f;
				((Behaviour)componentsInChildren2[k]).enabled = false;
				result = true;
			}
			ParticleSystem[] componentsInChildren3 = prefab.GetComponentsInChildren<ParticleSystem>(true);
			foreach (ParticleSystem val in componentsInChildren3)
			{
				EmissionModule emission = val.emission;
				((EmissionModule)(ref emission)).enabled = false;
				val.Stop(true, (ParticleSystemStopBehavior)0);
				ParticleSystemRenderer component = ((Component)val).GetComponent<ParticleSystemRenderer>();
				if ((Object)(object)component != (Object)null)
				{
					((Renderer)component).enabled = false;
				}
				if ((Object)(object)((Component)val).gameObject != (Object)(object)prefab)
				{
					((Component)val).gameObject.SetActive(false);
				}
				result = true;
			}
			Transform[] componentsInChildren4 = prefab.GetComponentsInChildren<Transform>(true);
			foreach (Transform val2 in componentsInChildren4)
			{
				if (!((Object)(object)val2 == (Object)null) && !(((Object)val2).name != "equiped"))
				{
					((Component)val2).gameObject.SetActive(false);
					((Object)val2).name = "equiped_off";
					result = true;
				}
			}
			return result;
		}

		private static bool TurnOffEmission(Material mat)
		{
			//IL_0036: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)mat == (Object)null || !mat.IsKeywordEnabled("_EMISSION"))
			{
				return false;
			}
			mat.DisableKeyword("_EMISSION");
			if (mat.HasProperty("_EmissionColor"))
			{
				mat.SetColor("_EmissionColor", Color.black);
			}
			mat.globalIlluminationFlags = (MaterialGlobalIlluminationFlags)4;
			return true;
		}
	}
	[BepInPlugin("com.frizzqol.dullarrows", "FrizzQOL Dull Arrows", "0.1.0")]
	public class Plugin : BaseUnityPlugin
	{
		public const string PluginGuid = "com.frizzqol.dullarrows";

		public const string PluginName = "FrizzQOL Dull Arrows";

		public const string PluginVersion = "0.1.0";

		internal static Plugin Instance { get; private set; }

		private void Awake()
		{
			//IL_000b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0011: Expected O, but got Unknown
			Instance = this;
			Harmony val = new Harmony("com.frizzqol.dullarrows");
			try
			{
				val.PatchAll();
				((BaseUnityPlugin)this).Logger.LogInfo((object)"FrizzQOL Dull Arrows 0.1.0 loaded");
			}
			catch (Exception ex)
			{
				((BaseUnityPlugin)this).Logger.LogError((object)("Harmony patch failed: " + ex.Message));
			}
		}

		internal static void LogInfo(string message)
		{
			if ((Object)(object)Instance != (Object)null)
			{
				((BaseUnityPlugin)Instance).Logger.LogInfo((object)message);
			}
		}

		internal static void LogWarning(string message)
		{
			if ((Object)(object)Instance != (Object)null)
			{
				((BaseUnityPlugin)Instance).Logger.LogWarning((object)message);
			}
		}
	}
}