using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using System.Threading;
using BepInEx;
using BepInEx.Logging;
using HarmonyLib;
using TheDownTheamSoundPack.Pathces;
using UnityEngine;
using UnityEngine.Networking;
[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = "")]
[assembly: AssemblyCompany("TheDownTheamSoundPack")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyDescription("Sound pack for my frends from tg:Тима даунов")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("TheDownTheamSoundPack")]
[assembly: AssemblyTitle("TheDownTheamSoundPack")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
[module: UnverifiableCode]
namespace TheDownTheamSoundPack
{
[BepInPlugin("quant86.TheDownTheamSoundPack", "The Down Theam Sound Pack", "0.1")]
public class Plugin : BaseUnityPlugin
{
private delegate AudioClip checkedFunc();
private const string modGUID = "quant86.TheDownTheamSoundPack";
private const string modName = "The Down Theam Sound Pack";
private const string modVersion = "0.1";
private readonly Harmony harmony = new Harmony("quant86.TheDownTheamSoundPack");
private static Plugin Instance;
internal static AudioClip nutcrackerStartSearch;
internal static AudioClip nutcrackerFindPlayer;
internal static AudioClip nutcrackerRage;
internal static AudioClip[] hoardingBugRage = (AudioClip[])(object)new AudioClip[3];
internal static AudioClip CrawlerRage;
internal static AudioClip[] ForestGiantRage = (AudioClip[])(object)new AudioClip[3];
internal static AudioClip GhostGirlSound;
internal ManualLogSource mls = Logger.CreateLogSource("quant86.TheDownTheamSoundPack");
private void Awake()
{
((BaseUnityPlugin)this).Logger.LogInfo((object)"Plugin quant86.TheDownTheamSoundPack is loading!");
if ((Object)(object)Instance == (Object)null)
{
Instance = this;
}
string location = ((BaseUnityPlugin)Instance).Info.Location;
string text3 = "TheDownTheamSoundPack.dll";
string text2 = location.TrimEnd(text3.ToCharArray());
try
{
nutcrackerStartSearch = exec_checked(() => LoadAudio(text2, "nutcrackerStartSearch.mp3"));
nutcrackerFindPlayer = exec_checked(() => LoadAudio(text2, "nutcrackerFindPlayer.mp3"));
nutcrackerRage = exec_checked(() => LoadAudio(text2, "nutcracker_rage.mp3"));
hoardingBugRage[0] = exec_checked(() => LoadAudio(text2, "hoardingbug_rage1.mp3"));
hoardingBugRage[1] = exec_checked(() => LoadAudio(text2, "hoardingbug_rage2.mp3"));
hoardingBugRage[2] = exec_checked(() => LoadAudio(text2, "hoardingbug_rage3.mp3"));
CrawlerRage = exec_checked(() => LoadAudio(text2, "crawler_rage.mp3"));
ForestGiantRage[0] = exec_checked(() => LoadAudio(text2, "ForestGiantRage1.mp3"));
ForestGiantRage[1] = exec_checked(() => LoadAudio(text2, "ForestGiantRage2.mp3"));
ForestGiantRage[2] = exec_checked(() => LoadAudio(text2, "ForestGiantRage3.mp3"));
GhostGirlSound = exec_checked(() => LoadAudio(text2, "GhostGirlSound.mp3"));
}
catch (Exception ex)
{
mls.LogError((object)("<quant86.TheDownTheamSoundPack ERROR!> " + ex.Message));
return;
}
harmony.PatchAll(typeof(NutckrackerPatch));
harmony.PatchAll(typeof(HoarderBugPatch));
harmony.PatchAll(typeof(CrawlerPatch));
harmony.PatchAll(typeof(ForestGiantPatch));
harmony.PatchAll(typeof(GhostGirlPatch));
mls.LogInfo((object)"Plugin quant86.TheDownTheamSoundPack is loaded!");
}
private static AudioClip LoadAudio(string path_prefix, string name)
{
//IL_0024: Unknown result type (might be due to invalid IL or missing references)
//IL_002a: Expected O, but got Unknown
//IL_0043: Unknown result type (might be due to invalid IL or missing references)
//IL_0049: Expected O, but got Unknown
string text = string.Format(path_prefix + "\\" + name);
DownloadHandlerAudioClip val = new DownloadHandlerAudioClip("file://" + text, (AudioType)13);
val.compressed = true;
UnityWebRequest val2 = new UnityWebRequest("file://" + text, "GET", (DownloadHandler)(object)val, (UploadHandler)null);
try
{
UnityWebRequestAsyncOperation val3 = val2.SendWebRequest();
while (!((AsyncOperation)val3).isDone)
{
Thread.Sleep(10);
}
if (val2.responseCode == 200)
{
return val.audioClip;
}
throw new Exception("Can't load audio assets, path " + text + "!");
}
finally
{
((IDisposable)val2)?.Dispose();
}
}
private static AudioClip exec_checked(checkedFunc func)
{
AudioClip obj = func();
if ((Object)(object)obj == (Object)null)
{
throw new Exception("Can't load audio assets!");
}
return obj;
}
}
public static class PluginInfo
{
public const string PLUGIN_GUID = "TheDownTheamSoundPack";
public const string PLUGIN_NAME = "TheDownTheamSoundPack";
public const string PLUGIN_VERSION = "1.0.0";
}
}
namespace TheDownTheamSoundPack.Pathces
{
[HarmonyPatch(typeof(CrawlerAI))]
internal class CrawlerPatch
{
private static Dictionary<CrawlerAI, int> BehaviourState_prev = new Dictionary<CrawlerAI, int>();
[HarmonyPatch("Start")]
[HarmonyPostfix]
private static void InitPatch(CrawlerAI __instance)
{
BehaviourState_prev[__instance] = 0;
}
[HarmonyPatch("KillEnemy")]
[HarmonyPostfix]
private static void StopSounds(ref AudioSource ___creatureVoice)
{
___creatureVoice.Stop();
}
[HarmonyPatch("Update")]
[HarmonyPostfix]
private static void addSoundOnChangeState(CrawlerAI __instance, ref int ___currentBehaviourStateIndex, ref AudioSource ___creatureVoice)
{
switch (___currentBehaviourStateIndex)
{
case 0:
if (BehaviourState_prev[__instance] != ___currentBehaviourStateIndex)
{
___creatureVoice.Stop();
BehaviourState_prev[__instance] = ___currentBehaviourStateIndex;
}
break;
case 1:
if (BehaviourState_prev[__instance] != ___currentBehaviourStateIndex)
{
___creatureVoice.PlayOneShot(Plugin.CrawlerRage);
BehaviourState_prev[__instance] = ___currentBehaviourStateIndex;
}
break;
}
}
}
[HarmonyPatch(typeof(ForestGiantAI))]
internal class ForestGiantPatch
{
private static Dictionary<ForestGiantAI, int> BehaviourState_prev = new Dictionary<ForestGiantAI, int>();
[HarmonyPatch("Start")]
[HarmonyPostfix]
private static void InitPatch(ForestGiantAI __instance)
{
BehaviourState_prev[__instance] = 0;
}
[HarmonyPatch("KillEnemy")]
[HarmonyPostfix]
private static void StopSounds(ref AudioSource ___creatureVoice)
{
___creatureVoice.Stop();
}
[HarmonyPatch("Update")]
[HarmonyPostfix]
private static void addSoundOnChangeState(ForestGiantAI __instance, ref int ___currentBehaviourStateIndex, ref AudioSource ___creatureVoice)
{
switch (___currentBehaviourStateIndex)
{
case 0:
if (BehaviourState_prev[__instance] != ___currentBehaviourStateIndex)
{
BehaviourState_prev[__instance] = ___currentBehaviourStateIndex;
}
break;
case 1:
if (BehaviourState_prev[__instance] != ___currentBehaviourStateIndex)
{
Random random = new Random();
___creatureVoice.PlayOneShot(Plugin.ForestGiantRage[random.Next(Plugin.hoardingBugRage.Length)]);
BehaviourState_prev[__instance] = ___currentBehaviourStateIndex;
}
break;
}
}
}
[HarmonyPatch(typeof(DressGirlAI))]
internal class GhostGirlPatch
{
[HarmonyPatch("SetHauntStarePosition")]
[HarmonyPostfix]
private static void StartMusic(AudioSource ___creatureVoice)
{
___creatureVoice.PlayOneShot(Plugin.GhostGirlSound);
}
}
[HarmonyPatch(typeof(HoarderBugAI))]
internal class HoarderBugPatch
{
[HarmonyPatch("Update")]
[HarmonyPrefix]
private static void addSoundsOnChangeState(ref AudioSource ___creatureSFX, ref bool ___inChase, ref int ___currentBehaviourStateIndex)
{
if (___currentBehaviourStateIndex == 2 && !___inChase)
{
Random random = new Random();
___creatureSFX.PlayOneShot(Plugin.hoardingBugRage[random.Next(Plugin.hoardingBugRage.Length)]);
}
}
}
[HarmonyPatch(typeof(NutcrackerEnemyAI))]
internal class NutckrackerPatch
{
private static Dictionary<NutcrackerEnemyAI, bool> play_rage = new Dictionary<NutcrackerEnemyAI, bool>();
private static Dictionary<NutcrackerEnemyAI, bool> play_rage_prev = new Dictionary<NutcrackerEnemyAI, bool>();
[HarmonyPatch("AimGun")]
[HarmonyPostfix]
private static void PlayRage(NutcrackerEnemyAI __instance, ref AudioSource ___longRangeAudio)
{
if (play_rage[__instance] && play_rage[__instance] != play_rage_prev[__instance])
{
___longRangeAudio.clip = Plugin.nutcrackerRage;
___longRangeAudio.PlayDelayed(2f);
play_rage_prev[__instance] = play_rage[__instance];
}
}
[HarmonyPatch("KillEnemy")]
[HarmonyPostfix]
private static void StopSounds(ref AudioSource ___longRangeAudio)
{
___longRangeAudio.Stop();
}
[HarmonyPatch("Update")]
[HarmonyPrefix]
private static void addSoundsOnChangeState(NutcrackerEnemyAI __instance, ref AudioSource ___longRangeAudio, ref int ___previousBehaviourState, ref int ___currentBehaviourStateIndex)
{
switch (___currentBehaviourStateIndex)
{
case 0:
if (___previousBehaviourState != ___currentBehaviourStateIndex)
{
___longRangeAudio.Stop();
play_rage[__instance] = false;
play_rage_prev[__instance] = true;
}
break;
case 1:
if (___previousBehaviourState != ___currentBehaviourStateIndex)
{
___longRangeAudio.Stop();
___longRangeAudio.PlayOneShot(Plugin.nutcrackerStartSearch);
play_rage[__instance] = false;
play_rage_prev[__instance] = true;
}
break;
case 2:
if (___previousBehaviourState != ___currentBehaviourStateIndex)
{
if (___previousBehaviourState == 1)
{
___longRangeAudio.PlayOneShot(Plugin.nutcrackerFindPlayer);
}
play_rage[__instance] = true;
play_rage_prev[__instance] = false;
}
break;
}
}
}
}