Decompiled source of SilenceTameWolfCub v0.0.7

SilenceTameWolfCubMod.dll

Decompiled 5 months ago
using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Configuration;
using HarmonyLib;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: AssemblyTitle("SilenceTameWolfCubMod")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("SilenceTameWolfCubMod")]
[assembly: AssemblyCopyright("Copyright ©  2022")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("9e647534-f920-4303-98c2-9574a5845dee")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")]
[assembly: AssemblyVersion("1.0.0.0")]
namespace ValheimTameMods;

[BepInPlugin("afilbert.ValheimSilenceTameWolfCubMod", "Valheim - Silence Tame Wolf Cub Howls", "0.0.7")]
[BepInProcess("valheim.exe")]
public class SilenceTameWolfCubMod : BaseUnityPlugin
{
	[HarmonyPatch(typeof(ZSFX), "Play")]
	private class SilenceTheirYoungPatch
	{
		private static bool Prefix(ref ZSFX __instance)
		{
			//IL_002e: Unknown result type (might be due to invalid IL or missing references)
			bool result = true;
			if (((Object)__instance).name.Contains("sfx_wolf_haul") && EnableToggle.Value)
			{
				List<Character> list = new List<Character>();
				Character.GetCharactersInRange(((Component)__instance).transform.position, SilenceRange.Value, list);
				result = !list.Exists((Character c) => (c.IsTamed() || SilenceAdults.Value) && (((Object)c).name == "Wolf_cub(Clone)" || ((Object)c).name == "Wolf_cub" || (SilenceAdults.Value && (((Object)c).name == "Wolf(Clone)" || ((Object)c).name == "Wolf"))));
			}
			return result;
		}
	}

	private readonly Harmony harmony = new Harmony("afilbert.ValheimSilenceTameWolfCubMod");

	public static ConfigEntry<bool> EnableToggle;

	public static ConfigEntry<bool> SilenceAdults;

	public static ConfigEntry<float> SilenceRange;

	private void Awake()
	{
		harmony.PatchAll();
		EnableToggle = ((BaseUnityPlugin)this).Config.Bind<bool>("Mod", "EnableToggleFlag", true, "Enable this mod");
		SilenceAdults = ((BaseUnityPlugin)this).Config.Bind<bool>("Mod", "SilenceAdultsFlag", false, "Also silence adult wolves (tamed or otherwise)");
		SilenceRange = ((BaseUnityPlugin)this).Config.Bind<float>("Range", "SilenceRangeValue", 30f, "Radius in meters within which wolves are silenced");
	}
}