Decompiled source of SilenceTameWolfCub v0.1.0

SilenceTameWolfCubMod.dll

Decompiled 6 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 BepInEx.Logging;
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.1.0")]
[BepInProcess("valheim.exe")]
public class SilenceTameWolfCubMod : BaseUnityPlugin
{
	[HarmonyPatch(typeof(ZSFX), "Play")]
	private class SilenceTheirYoungPatch
	{
		private static bool Prefix(ref ZSFX __instance)
		{
			//IL_0030: Unknown result type (might be due to invalid IL or missing references)
			if (!EnableToggle.Value)
			{
				return true;
			}
			bool result = true;
			if (((Object)__instance).name.Contains("sfx_wolf_haul"))
			{
				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"))));
			}
			if (SilenceChickens.Value && ((Object)__instance).name.Contains("sfx_love"))
			{
				result = false;
			}
			return result;
		}
	}

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

	public static ManualLogSource logger;

	public static ConfigEntry<bool> EnableToggle;

	public static ConfigEntry<bool> SilenceAdults;

	public static ConfigEntry<bool> SilenceChickens;

	public static ConfigEntry<float> SilenceRange;

	private void Awake()
	{
		harmony.PatchAll();
		logger = ((BaseUnityPlugin)this).Logger;
		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)");
		SilenceChickens = ((BaseUnityPlugin)this).Config.Bind<bool>("Mod", "SilenceChickens", false, "Also silence chicken crowing");
		SilenceRange = ((BaseUnityPlugin)this).Config.Bind<float>("Range", "SilenceRangeValue", 30f, "Radius in meters within which wolves are silenced");
	}
}