Decompiled source of Bad to the Bone v1.0.1

BadToTheBone.dll

Decompiled a week ago
using System;
using System.Collections;
using System.Diagnostics;
using System.IO;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using BepInEx;
using HarmonyLib;
using UnityEngine;
using UnityEngine.Networking;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: TargetFramework(".NETFramework,Version=v4.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")]
[assembly: AssemblyVersion("0.0.0.0")]
namespace ValheimSkeletonSoundMod;

[BepInPlugin("com.xAlphaSapphire.badtothebone", "Bad to the Bone", "1.0.1")]
public class SkeletonSoundMod : BaseUnityPlugin
{
	private const string ModGUID = "com.xAlphaSapphire.badtothebone";

	private const string ModName = "Bad to the Bone";

	private const string ModVersion = "1.0.1";

	public static AudioClip CustomSound;

	public static SkeletonSoundMod Instance;

	private static string ModPath = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);

	private void Awake()
	{
		//IL_0051: Unknown result type (might be due to invalid IL or missing references)
		//IL_0057: Expected O, but got Unknown
		Instance = this;
		string text = Path.Combine(ModPath, "badtothebone.ogg");
		if (File.Exists(text))
		{
			((MonoBehaviour)this).StartCoroutine(LoadAudio(text));
		}
		else
		{
			((BaseUnityPlugin)this).Logger.LogError((object)("Sound file not found at: " + text));
		}
		Harmony val = new Harmony("com.xAlphaSapphire.badtothebone");
		val.PatchAll();
	}

	private IEnumerator LoadAudio(string filePath)
	{
		UnityWebRequest www = UnityWebRequestMultimedia.GetAudioClip("file:///" + filePath, (AudioType)14);
		try
		{
			yield return www.SendWebRequest();
			if ((int)www.result == 1)
			{
				CustomSound = DownloadHandlerAudioClip.GetContent(www);
				((BaseUnityPlugin)this).Logger.LogInfo((object)"Custom skeleton sound 'badtothebone.wav' loaded successfully!");
			}
			else
			{
				((BaseUnityPlugin)this).Logger.LogError((object)("Failed to load audio: " + www.error));
			}
		}
		finally
		{
			((IDisposable)www)?.Dispose();
		}
	}
}
[HarmonyPatch(typeof(Character), "Awake")]
public static class CharacterAwakePatch
{
	private static void Postfix(Character __instance)
	{
		//IL_0041: Unknown result type (might be due to invalid IL or missing references)
		//IL_0047: Expected O, but got Unknown
		//IL_0053: Unknown result type (might be due to invalid IL or missing references)
		if (!((Object)(object)__instance == (Object)null) && ((Object)__instance).name.StartsWith("Skeleton_Friendly") && (Object)(object)SkeletonSoundMod.CustomSound != (Object)null)
		{
			GameObject val = new GameObject("TempSkeletonAudio");
			val.transform.position = ((Component)__instance).transform.position;
			AudioSource val2 = val.AddComponent<AudioSource>();
			val2.clip = SkeletonSoundMod.CustomSound;
			val2.spatialBlend = 1f;
			val2.minDistance = 5f;
			val2.maxDistance = 40f;
			val2.volume = 1f;
			val2.Play();
			Object.Destroy((Object)(object)val, SkeletonSoundMod.CustomSound.length);
		}
	}
}