using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using UnityEngine;
[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: AssemblyCompany("com.knotsora.queensoundslc")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("QueenSoundsLC")]
[assembly: AssemblyTitle("com.knotsora.queensoundslc")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
[module: UnverifiableCode]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
[CompilerGenerated]
[Microsoft.CodeAnalysis.Embedded]
internal sealed class EmbeddedAttribute : Attribute
{
}
}
namespace System.Runtime.CompilerServices
{
[CompilerGenerated]
[Microsoft.CodeAnalysis.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 QueenSoundsLCMod
{
[BepInPlugin("com.knotsora.queensoundslc", "QueenSoundsLC", "1.0.0")]
public class Plugin : BaseUnityPlugin
{
public static class WavManager
{
public static AudioClip LoadWav(string path)
{
byte[] array = File.ReadAllBytes(path);
int num = BitConverter.ToInt16(array, 22);
int num2 = BitConverter.ToInt32(array, 24);
int num3 = 44;
int num4 = (array.Length - num3) / 2;
float[] array2 = new float[num4];
int num5 = num3;
for (int i = 0; i < num4; i++)
{
short num6 = BitConverter.ToInt16(array, num5);
array2[i] = (float)num6 / 32768f;
num5 += 2;
}
AudioClip val = AudioClip.Create(Path.GetFileNameWithoutExtension(path), num4 / num, num, num2, false);
val.SetData(array2, 0);
float[] array3 = new float[val.samples * val.channels];
val.GetData(array3, 0);
for (int j = 0; j < array3.Length; j++)
{
array3[j] *= voiceLineVolume.Value;
}
val.SetData(array3, 0);
return val;
}
}
[HarmonyPatch(typeof(MaskedPlayerEnemy), "HitEnemy")]
public class MaskedPlayerEnemy_HitEnemy_Patch
{
private static void Prefix(MaskedPlayerEnemy __instance)
{
if ((Object)(object)__instance == (Object)null)
{
return;
}
EnemyType enemyType = ((EnemyAI)__instance).enemyType;
if ((Object)(object)enemyType == (Object)null)
{
return;
}
List<string> list = new List<string> { "hoot0", "hoot1", "hoot2" };
string key = list[Random.Range(0, list.Count)];
if (clips.TryGetValue(key, out var value))
{
if (replaceOriginalHitSounds.Value)
{
enemyType.hitBodySFX = value;
}
enemyType.hitEnemyVoiceSFX = value;
}
}
private static void Postfix(MaskedPlayerEnemy __instance)
{
if (!((Object)(object)__instance == (Object)null))
{
EnemyType enemyType = ((EnemyAI)__instance).enemyType;
if (!((Object)(object)enemyType == (Object)null) && ((EnemyAI)__instance).enemyHP == 0 && clips.TryGetValue("explosion", out var value))
{
((EnemyAI)__instance).creatureSFX.PlayOneShot(value);
WalkieTalkie.TransmitOneShotAudio(((EnemyAI)__instance).creatureSFX, value, 1f);
}
}
}
}
[HarmonyPatch(typeof(RandomPeriodicAudioPlayer), "PlayRandomAudioClientRpc")]
public class PatchMaskItem
{
private static void Prefix(RandomPeriodicAudioPlayer __instance)
{
MaskedPlayerEnemy componentInParent = ((Component)__instance).GetComponentInParent<MaskedPlayerEnemy>();
HauntedMaskItem componentInParent2 = ((Component)__instance).GetComponentInParent<HauntedMaskItem>();
Logger.LogMessage((object)componentInParent2.maskTypeId);
if ((Object)(object)componentInParent != (Object)null || ((Object)(object)__instance.attachedGrabbableObject != (Object)null && componentInParent2.maskTypeId != 5))
{
int num = Random.Range(0, __instance.randomClips.Length);
if (clips.TryGetValue("bitcrush", out var value))
{
__instance.randomClips[num % __instance.randomClips.Length] = value;
}
if (clips.TryGetValue("bitcrush_rev", out var value2))
{
__instance.randomClips[(num + 1) % __instance.randomClips.Length] = value2;
}
if (clips.TryGetValue("laugh0", out var value3))
{
__instance.randomClips[(num + 2) % __instance.randomClips.Length] = value3;
}
if (clips.TryGetValue("laugh1", out var value4))
{
__instance.randomClips[(num + 3) % __instance.randomClips.Length] = value4;
}
}
}
}
internal static ManualLogSource Logger;
public static Dictionary<string, AudioClip> clips = new Dictionary<string, AudioClip>();
public static ConfigEntry<float> voiceLineVolume;
public static ConfigEntry<bool> replaceOriginalHitSounds;
private void Awake()
{
//IL_00ed: Unknown result type (might be due to invalid IL or missing references)
//IL_00f3: Expected O, but got Unknown
Logger = ((BaseUnityPlugin)this).Logger;
Logger.LogInfo((object)"Plugin com.knotsora.queensoundslc is loaded!");
voiceLineVolume = ((BaseUnityPlugin)this).Config.Bind<float>("Volume", "VoiceLineVolume", 0.6f, "Volume for queen voice lines (0.0 = mute, 1.0 = loud, >1.0 very loud)");
replaceOriginalHitSounds = ((BaseUnityPlugin)this).Config.Bind<bool>("Replace", "ReplaceOriginalHitSounds", true, "Set whether the original masked hit sound effect should be played on hit");
LoadAudio("snd_queen_hoot_0.wav", "hoot0");
LoadAudio("snd_queen_hoot_1.wav", "hoot1");
LoadAudio("snd_queen_hoot_2.wav", "hoot2");
LoadAudio("snd_queen_bitcrushlaugh.wav", "bitcrush");
LoadAudio("snd_queen_bitcrushlaugh_reverse.wav", "bitcrush_rev");
LoadAudio("snd_queen_laugh_0.wav", "laugh0");
LoadAudio("snd_queen_laugh_1.wav", "laugh1");
LoadAudio("snd_badexplosion.wav", "explosion");
Harmony val = new Harmony("com.knotsora.queensoundslc");
val.PatchAll();
}
private void LoadAudio(string filename, string key)
{
string directoryName = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
string path = Path.Combine(directoryName, filename);
if (!File.Exists(path))
{
Logger.LogWarning((object)(filename + " missing"));
return;
}
AudioClip val = WavManager.LoadWav(path);
clips[key] = val;
Logger.LogInfo((object)$"Loaded sound: {key}, length {val.length}");
}
}
public static class MyPluginInfo
{
public const string PLUGIN_GUID = "com.knotsora.queensoundslc";
public const string PLUGIN_NAME = "QueenSoundsLC";
public const string PLUGIN_VERSION = "1.0.0";
}
}