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 BlindingLights.Patches;
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: AssemblyTitle("BlindingLights")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("BlindingLights")]
[assembly: AssemblyCopyright("Copyright © 2024")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("0a6763fc-1d9f-411b-a929-4c8aacb117ef")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")]
[assembly: AssemblyVersion("1.0.0.0")]
namespace BlindingLights
{
public class Config
{
public static ConfigEntry<float> volumePercentage;
public Config(ConfigFile configFile)
{
volumePercentage = configFile.Bind<float>("General", "Volume", 100f, "Volume multiplier for the music in %. Caution: Setting this value too high may damage your ears.");
}
}
[BepInPlugin("KamenVacuumCleaner.BlindingLights", "BlindingLights", "1.0.0")]
internal class Plugin : BaseUnityPlugin
{
private const string GUID = "KamenVacuumCleaner.BlindingLights";
private const string NAME = "BlindingLights";
private const string VERSION = "1.0.0";
internal ManualLogSource mls;
private Harmony harmony = new Harmony("BlindingLights");
private static Plugin instance;
public static AudioClip blindingLightsClip;
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("BlindingLights");
mls.LogInfo((object)"Loading: BlindingLights v1.0.0...");
blindingLightsClip = LoadAudio("BlindingLights.wav", (AudioType)20);
if (!loadingSuccess)
{
LogError("Unable to load plugin!");
return;
}
harmony.PatchAll(typeof(EnemyAIPatch));
mls.LogInfo((object)"Plugin BlindingLights 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("BlindingLights.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 BlindingLights.Patches
{
[HarmonyPatch(typeof(EnemyAI))]
internal class EnemyAIPatch
{
private static float startTime = -1f;
private static Dictionary<EnemyAI, AudioSource> stunAudioSources = new Dictionary<EnemyAI, AudioSource>();
private const float SONG_OFFSET = 118.48f;
public static AudioSource CreateAudioSource(EnemyAI __instance)
{
AudioSource val = ((Component)__instance.creatureVoice).gameObject.AddComponent<AudioSource>();
if ((Object)(object)val == (Object)null)
{
Plugin.LogError("Failed to create audio source on " + ((Object)__instance.enemyType).name);
return null;
}
val.volume *= Config.volumePercentage.Value * 0.01f;
val.clip = Plugin.blindingLightsClip;
val.loop = true;
val.spatialBlend = 1f;
val.dopplerLevel = 0.8f;
val.spread = 50f;
val.minDistance = 3f;
val.maxDistance = 30f;
val.rolloffMode = (AudioRolloffMode)2;
return val;
}
[HarmonyPatch("SetEnemyStunned")]
[HarmonyPostfix]
public static void SetEnemyStunnedPatch(EnemyAI __instance)
{
if (!stunAudioSources.ContainsKey(__instance))
{
PlayStunAudio(__instance);
}
}
[HarmonyPatch("Update")]
[HarmonyPrefix]
public static void UpdatePatch(EnemyAI __instance)
{
if (!stunAudioSources.ContainsKey(__instance) || __instance.stunnedIndefinitely > 0 || !(__instance.stunNormalizedTimer <= 0f))
{
return;
}
AudioSource val = stunAudioSources[__instance];
if (!((Object)(object)val == (Object)null))
{
val.Stop();
Object.Destroy((Object)(object)val);
stunAudioSources.Remove(__instance);
if (stunAudioSources.Count <= 0)
{
startTime = -1f;
}
}
}
private static void PlayStunAudio(EnemyAI __instance)
{
AudioSource val = CreateAudioSource(__instance);
if (!((Object)(object)val == (Object)null))
{
if (startTime > 0f)
{
val.time = Time.time - startTime;
}
else
{
startTime = Time.time;
}
val.time += 118.48f;
stunAudioSources.Add(__instance, val);
val.Play();
}
}
}
}