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("me.loaforc.soundapi")]
[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+8518e0f62d7923e906393adf3f2c4a34563bbcd8")]
[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 Track[] KerstTracks = new Track[3]
{
new Track
{
Name = "Paarden",
WindUpTimer = 36.6f,
Bpm = 178f
},
new Track
{
Name = "IkWilJe",
WindUpTimer = 43.8f,
Bpm = 164f
},
new Track
{
Name = "DiscoKapot",
WindUpTimer = 30.4f,
Bpm = 134f
}
};
public static Coroutine JesterLightSwitching;
public static List<Color> colorsNormal = new List<Color>(4)
{
Color.magenta,
Color.cyan,
Color.green,
Color.yellow
};
public static List<Color> colorsKerst = new List<Color>(4)
{
Color.red,
Color.blue,
Color.green,
Color.yellow
};
public static List<Color> selectedColors = colorsNormal;
public static Track CurrentTrack;
private void Awake()
{
//IL_022d: 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 + KerstTracks.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();
}
for (int j = 0; j < KerstTracks.Length; j++)
{
Track track2 = KerstTracks[j];
int num = Tracks.Length * 2 + j * 2;
array[num] = UnityWebRequestMultimedia.GetAudioClip("File://" + text + track2.Name + "Start.mp3", (AudioType)13);
array[num + 1] = UnityWebRequestMultimedia.GetAudioClip("File://" + text + track2.Name + "Loop.mp3", (AudioType)13);
array[num].SendWebRequest();
array[num + 1].SendWebRequest();
}
while (!array.All((UnityWebRequest request) => request.isDone))
{
}
if (array.All((UnityWebRequest request) => (int)request.result == 1))
{
for (int k = 0; k < Tracks.Length; k++)
{
Tracks[k].LoadedStart = DownloadHandlerAudioClip.GetContent(array[k * 2]);
Tracks[k].LoadedLoop = DownloadHandlerAudioClip.GetContent(array[k * 2 + 1]);
}
for (int l = 0; l < KerstTracks.Length; l++)
{
int num2 = Tracks.Length * 2 + l * 2;
KerstTracks[l].LoadedStart = DownloadHandlerAudioClip.GetContent(array[num2]);
KerstTracks[l].LoadedLoop = DownloadHandlerAudioClip.GetContent(array[num2 + 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
{
[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(List<Color> colors)
{
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_0291: 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();
DateTime utcNow = DateTime.UtcNow;
Debug.Log((object)$"Month: {utcNow.Month} day: {utcNow.Day}");
Track[] array = Plugin.Tracks;
if (utcNow.Month == 12 && utcNow.Day > 10)
{
array = Plugin.KerstTracks;
Plugin.selectedColors = Plugin.colorsKerst;
}
else if (utcNow.Month == 1 && utcNow.Day < 3)
{
array = Plugin.KerstTracks;
Plugin.selectedColors = Plugin.colorsKerst;
}
int chosenSeed = RoundManager.Instance.dungeonGenerator.Generator.ChosenSeed;
byte[] array2 = SHA256.Create().ComputeHash(BitConverter.GetBytes(chosenSeed));
int num = 0;
byte[] array3 = array2;
foreach (byte b in array3)
{
num *= 256 % array.Length;
num %= array.Length;
num += b % array.Length;
num %= array.Length;
}
Debug.Log((object)$"Seed is {chosenSeed}, chosen track is {num} out of {array.Length} tracks");
Plugin.CurrentTrack = array[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(Plugin.selectedColors));
}
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)
{
}
}
}