using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Cryptography;
using System.Security.Permissions;
using BepInEx;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using UnityEngine;
using UnityEngine.Networking;
[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: IgnoresAccessChecksTo("Assembly-CSharp")]
[assembly: IgnoresAccessChecksTo("Unity.Netcode.Runtime")]
[assembly: AssemblyCompany("MuzikaGromche")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyDescription("Opa che tut u nas")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0+9ffa5dd761cead4a7640940a725ed2838a8ab566")]
[assembly: AssemblyProduct("MuzikaGromche")]
[assembly: AssemblyTitle("MuzikaGromche")]
[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 MuzikaGromche
{
[BepInPlugin("MuzikaGromche", "MuzikaGromche", "1.0.0")]
public class Plugin : BaseUnityPlugin
{
public static Track[] Tracks = new Track[6]
{
new Track
{
Name = "MuzikaGromche",
WindUpTimer = 46.3f,
Bpm = 130f
},
new Track
{
Name = "VseVZale",
WindUpTimer = 39f,
Bpm = 138f
},
new Track
{
Name = "DeployDestroy",
WindUpTimer = 40.7f,
Bpm = 130f
},
new Track
{
Name = "MoyaZhittya",
WindUpTimer = 34.5f,
Bpm = 120f
},
new Track
{
Name = "Gorgorod",
WindUpTimer = 43.2f,
Bpm = 180f
},
new Track
{
Name = "Durochka",
WindUpTimer = 37f,
Bpm = 130f
}
};
public static Coroutine JesterLightSwitching;
public static Track CurrentTrack;
private void Awake()
{
//IL_013d: Unknown result type (might be due to invalid IL or missing references)
string text = ((BaseUnityPlugin)this).Info.Location.TrimEnd("MuzikaGromche.dll".ToCharArray());
UnityWebRequest[] array = (UnityWebRequest[])(object)new UnityWebRequest[Tracks.Length * 2];
for (int i = 0; i < Tracks.Length; i++)
{
Track track = Tracks[i];
array[i * 2] = UnityWebRequestMultimedia.GetAudioClip("File://" + text + track.Name + "Start.mp3", (AudioType)13);
array[i * 2 + 1] = UnityWebRequestMultimedia.GetAudioClip("File://" + text + track.Name + "Loop.mp3", (AudioType)13);
array[i * 2].SendWebRequest();
array[i * 2 + 1].SendWebRequest();
}
while (!array.All((UnityWebRequest request) => request.isDone))
{
}
if (array.All((UnityWebRequest request) => (int)request.result == 1))
{
for (int j = 0; j < Tracks.Length; j++)
{
Tracks[j].LoadedStart = DownloadHandlerAudioClip.GetContent(array[j * 2]);
Tracks[j].LoadedLoop = DownloadHandlerAudioClip.GetContent(array[j * 2 + 1]);
}
new Harmony("MuzikaGromche").PatchAll(typeof(JesterPatch));
}
else
{
((BaseUnityPlugin)this).Logger.LogError((object)"Could not load audio file");
}
}
}
public class Track
{
public string Name;
public float WindUpTimer;
public float Bpm;
public AudioClip LoadedStart;
public AudioClip LoadedLoop;
}
[HarmonyPatch(typeof(JesterAI))]
internal class JesterPatch
{
private static List<Color> colors = new List<Color>(4)
{
Color.magenta,
Color.cyan,
Color.green,
Color.yellow
};
[HarmonyPatch("Update")]
[HarmonyPrefix]
public static void DoNotStopTheMusicPrefix(JesterAI __instance, out State __state)
{
__state = new State();
__state.prevStateindex = __instance.previousState;
if (((EnemyAI)__instance).currentBehaviourStateIndex == 2 && ((EnemyAI)__instance).previousBehaviourStateIndex != 2)
{
__state.farAudio = __instance.farAudio;
__instance.farAudio = ((EnemyAI)__instance).creatureVoice;
}
}
public static IEnumerator rotateColors()
{
Debug.Log((object)"Starting color rotation");
int i = 0;
while (true)
{
Color val = colors[i];
Color val2 = val;
Debug.Log((object)("Chose color " + ((object)(Color)(ref val2)).ToString()));
foreach (Light allPoweredLight in RoundManager.Instance.allPoweredLights)
{
allPoweredLight.color = val;
}
i++;
if (i >= colors.Count)
{
i = 0;
}
yield return (object)new WaitForSeconds(60f / Plugin.CurrentTrack.Bpm);
}
}
[HarmonyPatch("Update")]
[HarmonyPostfix]
public static void DoNotStopTheMusic(JesterAI __instance, State __state)
{
//IL_021d: Unknown result type (might be due to invalid IL or missing references)
if ((Object)(object)__state.farAudio != (Object)null)
{
__instance.farAudio = __state.farAudio;
}
if (((EnemyAI)__instance).currentBehaviourStateIndex == 1 && __state.prevStateindex != 1)
{
__instance.farAudio.Stop();
((EnemyAI)__instance).creatureVoice.Stop();
int chosenSeed = RoundManager.Instance.dungeonGenerator.Generator.ChosenSeed;
byte[] array = SHA256.Create().ComputeHash(BitConverter.GetBytes(chosenSeed));
int num = 0;
byte[] array2 = array;
foreach (byte b in array2)
{
num *= 256 % Plugin.Tracks.Length;
num %= Plugin.Tracks.Length;
num += b % Plugin.Tracks.Length;
num %= Plugin.Tracks.Length;
}
Debug.Log((object)$"Seed is {chosenSeed}, chosen track is {num} out of {Plugin.Tracks.Length} tracks");
Plugin.CurrentTrack = Plugin.Tracks[num];
__instance.popUpTimer = Plugin.CurrentTrack.WindUpTimer;
__instance.farAudio.maxDistance = 150f;
__instance.farAudio.clip = Plugin.CurrentTrack.LoadedStart;
__instance.farAudio.loop = false;
Debug.Log((object)$"Playing start music: maxDistance: {__instance.farAudio.maxDistance}, minDistance: {__instance.farAudio.minDistance}, volume: {__instance.farAudio.volume}, spread: {__instance.farAudio.spread}");
__instance.farAudio.Play();
}
if (((EnemyAI)__instance).currentBehaviourStateIndex == 2 && __state.prevStateindex != 2)
{
((EnemyAI)__instance).creatureVoice.Stop();
if (Plugin.JesterLightSwitching != null)
{
((MonoBehaviour)__instance).StopCoroutine(Plugin.JesterLightSwitching);
Plugin.JesterLightSwitching = null;
}
Plugin.JesterLightSwitching = ((MonoBehaviour)__instance).StartCoroutine(rotateColors());
}
if (((EnemyAI)__instance).currentBehaviourStateIndex != 2 && __state.prevStateindex == 2)
{
if (Plugin.JesterLightSwitching != null)
{
((MonoBehaviour)__instance).StopCoroutine(Plugin.JesterLightSwitching);
Plugin.JesterLightSwitching = null;
}
foreach (Light allPoweredLight in RoundManager.Instance.allPoweredLights)
{
allPoweredLight.color = Color.white;
}
}
if (((EnemyAI)__instance).currentBehaviourStateIndex == 2 && !((EnemyAI)__instance).creatureVoice.isPlaying)
{
((EnemyAI)__instance).creatureVoice.maxDistance = 150f;
((EnemyAI)__instance).creatureVoice.clip = Plugin.CurrentTrack.LoadedLoop;
float time = __instance.farAudio.time;
float num2 = Plugin.CurrentTrack.LoadedStart.length - time;
Debug.Log((object)$"Start length: {Plugin.CurrentTrack.LoadedStart.length}; played time: {time}");
Debug.Log((object)$"Playing loop music: maxDistance: {((EnemyAI)__instance).creatureVoice.maxDistance}, minDistance: {((EnemyAI)__instance).creatureVoice.minDistance}, volume: {((EnemyAI)__instance).creatureVoice.volume}, spread: {((EnemyAI)__instance).creatureVoice.spread}, in seconds: {num2}");
((EnemyAI)__instance).creatureVoice.PlayDelayed(num2);
}
}
}
internal class State
{
public AudioSource farAudio;
public int prevStateindex;
}
public static class PluginInfo
{
public const string PLUGIN_GUID = "MuzikaGromche";
public const string PLUGIN_NAME = "MuzikaGromche";
public const string PLUGIN_VERSION = "1.0.0";
}
}
namespace System.Runtime.CompilerServices
{
[AttributeUsage(AttributeTargets.Assembly, AllowMultiple = true)]
internal sealed class IgnoresAccessChecksToAttribute : Attribute
{
public IgnoresAccessChecksToAttribute(string assemblyName)
{
}
}
}