using System;
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;
using UnityEngine.Networking;
using WhistleJesterExtension.Patches;
[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: AssemblyTitle("WhistleJesterExtension")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("WhistleJesterExtension")]
[assembly: AssemblyCopyright("Copyright © 2024")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("70a06817-3c3d-41e1-b6a9-f7c0532419c6")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")]
[assembly: AssemblyVersion("1.0.0.0")]
namespace WhistleJesterExtension
{
public class Config
{
public static ConfigEntry<float> volumePercentage;
public static ConfigEntry<bool> keepOriginalScream;
public Config(ConfigFile configFile)
{
volumePercentage = configFile.Bind<float>("General", "Volume", 100f, "Volume multiplier for the whistle music in %. Caution: Setting this value too high may damage your ears.");
keepOriginalScream = configFile.Bind<bool>("General", "KeepOriginalScream", true, "Determines whether the Jester's original scream sound will still be played or not.");
}
}
[BepInPlugin("KamenVacuumCleaner.WhistleJesterExtension", "WhistleJesterExtension", "1.0.0")]
public class Plugin : BaseUnityPlugin
{
private const string GUID = "KamenVacuumCleaner.WhistleJesterExtension";
private const string NAME = "WhistleJesterExtension";
private const string VERSION = "1.0.0";
internal ManualLogSource mls;
private Harmony harmony = new Harmony("WhistleJesterExtension");
private static Plugin instance;
public static AudioClip huntAudioClip;
private static bool loadingSuccess = true;
public static Config config { get; internal set; }
private void Awake()
{
if ((Object)(object)instance == (Object)null)
{
instance = this;
}
config = new Config(((BaseUnityPlugin)this).Config);
mls = Logger.CreateLogSource("WhistleJesterExtension");
mls.LogInfo((object)"Loading: WhistleJesterExtension v1.0.0...");
huntAudioClip = LoadAudio("JesterHunt.wav", (AudioType)20);
if (!loadingSuccess)
{
LogError("Unable to load plugin!");
return;
}
harmony.PatchAll(typeof(JesterPatch));
mls.LogInfo((object)"Plugin WhistleJesterExtension is loaded!");
}
private AudioClip LoadAudio(string path, AudioType type)
{
//IL_002a: Unknown result type (might be due to invalid IL or missing references)
//IL_004a: Unknown result type (might be due to invalid IL or missing references)
//IL_0050: Invalid comparison between Unknown and I4
AudioClip result = null;
string text = ((BaseUnityPlugin)this).Info.Location.TrimEnd("WhistleJesterExtension.dll".ToCharArray());
UnityWebRequest audioClip = UnityWebRequestMultimedia.GetAudioClip("File://" + text + path, type);
audioClip.SendWebRequest();
while (!audioClip.isDone)
{
}
if ((int)audioClip.result == 1)
{
result = DownloadHandlerAudioClip.GetContent(audioClip);
}
else
{
loadingSuccess = false;
mls.LogInfo((object)"Could not load audio file");
}
return result;
}
public static void Log(string message)
{
instance.mls.LogInfo((object)message);
}
public static void LogError(string message)
{
instance.mls.LogError((object)message);
}
}
}
namespace WhistleJesterExtension.Patches
{
[HarmonyPatch(typeof(JesterAI))]
internal class JesterPatch
{
private static AudioSource huntSource;
[HarmonyPatch("Start")]
[HarmonyPostfix]
public static void Initialization(JesterAI __instance)
{
if (!Config.keepOriginalScream.Value)
{
__instance.screamingSFX = null;
}
huntSource = ((Component)((EnemyAI)__instance).creatureVoice).gameObject.AddComponent<AudioSource>();
CopyAudioSourceValues(((EnemyAI)__instance).creatureVoice, ref huntSource);
AudioSource farAudio = __instance.farAudio;
farAudio.volume *= Config.volumePercentage.Value * 0.01f;
AudioSource obj = huntSource;
obj.volume *= Config.volumePercentage.Value * 0.01f;
}
[HarmonyPatch("SetJesterInitialValues")]
[HarmonyPostfix]
public static void Reset(JesterAI __instance)
{
if ((Object)(object)huntSource != (Object)null)
{
huntSource.Stop();
}
}
[HarmonyPatch("Update")]
[HarmonyPrefix]
public static void PlayHuntAudio(JesterAI __instance, ref int ___previousState)
{
if (((EnemyAI)__instance).currentBehaviourStateIndex == 2 && ___previousState != 2 && (Object)(object)huntSource != (Object)null)
{
huntSource.clip = Plugin.huntAudioClip;
huntSource.Play();
}
}
private static void CopyAudioSourceValues(AudioSource from, ref AudioSource to)
{
Type type = ((object)from).GetType();
BindingFlags bindingAttr = BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic;
PropertyInfo[] properties = type.GetProperties(bindingAttr);
PropertyInfo[] array = properties;
foreach (PropertyInfo propertyInfo in array)
{
if (propertyInfo.CanWrite)
{
propertyInfo.SetValue(to, propertyInfo.GetValue(from, null), null);
}
}
FieldInfo[] fields = type.GetFields(bindingAttr);
FieldInfo[] array2 = fields;
foreach (FieldInfo fieldInfo in array2)
{
fieldInfo.SetValue(to, fieldInfo.GetValue(from));
}
}
}
}