using System; using System.Collections.Generic; using System.Diagnostics; using System.IO; using System.Linq; using System.Reflection; using System.Runtime.CompilerServices; using System.Runtime.Versioning; using System.Security; using System.Security.Permissions; using BepInEx; using Cogwork_Waltz.Components; using HutongGames.PlayMaker; using HutongGames.PlayMaker.Actions; using Microsoft.CodeAnalysis; using UnityEngine; using UnityEngine.SceneManagement; using WavLib; [assembly: CompilationRelaxations(8)] [assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)] [assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)] [assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")] [assembly: AssemblyCompany("Cogwork Waltz")] [assembly: AssemblyConfiguration("Release")] [assembly: AssemblyFileVersion("1.0.1.0")] [assembly: AssemblyInformationalVersion("1.0.1+3d456a75c809fa6f2d3e37ead5d7c3a7cdb93744")] [assembly: AssemblyProduct("Cogwork Waltz")] [assembly: AssemblyTitle("Cogwork_Waltz")] [assembly: AssemblyMetadata("RepositoryUrl", "https://github.com/kaycodes13/Cogwork Waltz")] [assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)] [assembly: AssemblyVersion("1.0.1.0")] [module: UnverifiableCode] [module: RefSafetyRules(11)] namespace System.Runtime.CompilerServices { [CompilerGenerated] [Embedded] [AttributeUsage(AttributeTargets.Class | AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Event | AttributeTargets.Parameter | AttributeTargets.ReturnValue | AttributeTargets.GenericParameter, AllowMultiple = false, Inherited = false)] internal sealed class NullableAttribute : Attribute { public readonly byte[] NullableFlags; public NullableAttribute(byte P_0) { NullableFlags = new byte[1] { P_0 }; } public NullableAttribute(byte[] P_0) { NullableFlags = P_0; } } [CompilerGenerated] [Embedded] [AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Method | AttributeTargets.Interface | AttributeTargets.Delegate, AllowMultiple = false, Inherited = false)] internal sealed class NullableContextAttribute : Attribute { public readonly byte Flag; public NullableContextAttribute(byte P_0) { Flag = P_0; } } [CompilerGenerated] [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 BepInEx { [AttributeUsage(AttributeTargets.Class, Inherited = false, AllowMultiple = false)] [Conditional("CodeGeneration")] [Embedded] internal sealed class BepInAutoPluginAttribute : Attribute { public BepInAutoPluginAttribute(string? id = null, string? name = null, string? version = null) { } } } namespace BepInEx.Preloader.Core.Patching { [AttributeUsage(AttributeTargets.Class, Inherited = false, AllowMultiple = false)] [Conditional("CodeGeneration")] [Embedded] internal sealed class PatcherAutoPluginAttribute : Attribute { public PatcherAutoPluginAttribute(string? id = null, string? name = null, string? version = null) { } } } namespace Microsoft.CodeAnalysis { [Embedded] internal sealed class EmbeddedAttribute : Attribute { } } namespace Cogwork_Waltz.Components { [RequireComponent(typeof(AudioSource))] [RequireComponent(typeof(PlayMakerFSM))] internal class ResyncCogworkDancers : MonoBehaviour { private AudioSource music; private PlayMakerFSM dancerControl; private PlayMakerFSM beatControl; private int mult; private float prevMusicTime; private bool justLooped; private float CurrentBeatTiming => beatControl.FsmVariables.FloatVariables[0].Value; private void Awake() { music = ((Component)this).GetComponent(); dancerControl = ((Component)this).GetComponents().First((PlayMakerFSM x) => x.FsmName == "Control"); beatControl = ((Component)this).GetComponents().First((PlayMakerFSM x) => x.FsmName == "Beat Control"); mult = 1; prevMusicTime = -1f; justLooped = false; } private void OnDestroy() { RestartBeatFSM(); } private void Update() { if (!Object.op_Implicit((Object)(object)music.clip) || !music.loop || (!music.isPlaying && !HeroController.instance.IsPaused())) { if (!((Behaviour)beatControl).enabled) { mult = 1; prevMusicTime = -1f; justLooped = false; RestartBeatFSM(); } return; } ((Behaviour)beatControl).enabled = false; float currentBeatTiming = CurrentBeatTiming; if (prevMusicTime > music.time) { justLooped = true; } prevMusicTime = music.time; if ((float)mult * currentBeatTiming <= music.time) { mult++; SendBeatEvent(); } else if (justLooped && (float)mult * currentBeatTiming - music.clip.length <= music.time) { justLooped = false; mult = 1; SendBeatEvent(); } } private void SendBeatEvent() { dancerControl.SendEvent("BEAT"); EventRegister.SendEvent("BEAT", ((Component)this).gameObject); } private void RestartBeatFSM() { ((Behaviour)beatControl).enabled = true; beatControl.SendEvent("STOP"); beatControl.SendEvent("BEGIN"); } } } namespace CogworkWaltz { [BepInPlugin("io.github.kaycodes13.cogworkwaltz", "Cogwork_Waltz", "1.0.1")] public class CogworkWaltzPlugin : BaseUnityPlugin { private static List Phases = new List(); public const string Id = "io.github.kaycodes13.cogworkwaltz"; public static string Name => "Cogwork_Waltz"; public static string Version => "1.0.1"; private void Awake() { ((BaseUnityPlugin)this).Logger.LogInfo((object)("Plugin " + Name + " (io.github.kaycodes13.cogworkwaltz) has loaded!")); Assembly executingAssembly = Assembly.GetExecutingAssembly(); string[] manifestResourceNames = executingAssembly.GetManifestResourceNames(); Phases.Add(LoadEmbeddedWav(manifestResourceNames.First((string n) => n.EndsWith("sting.wav")), executingAssembly, "sting")); int i; for (i = 1; i <= 4; i++) { Phases.Add(LoadEmbeddedWav(manifestResourceNames.First((string n) => n.EndsWith($"phase_{i}.wav")), executingAssembly, $"phase_{i}")); } SceneManager.sceneLoaded += ReplaceMusic; } private void OnDestroy() { SceneManager.sceneLoaded -= ReplaceMusic; Phases.Clear(); } private void ReplaceMusic(Scene scene, LoadSceneMode _) { if (((Scene)(ref scene)).name != "Cog_Dancers_boss") { return; } GameObject obj = GameObject.Find("Dancer Control"); obj.AddComponent(); FsmState[] fsmStates = obj.GetComponents().First((PlayMakerFSM fsm) => fsm.FsmName == "Music Control").FsmStates; foreach (FsmState val in fsmStates) { if (val.Name == "Stop") { val.Actions.OfType().First().oneShotClip = FsmObject.op_Implicit((Object)(object)Phases[0]); continue; } for (int num2 = 1; num2 <= 4; num2++) { if (val.Name == $"P{num2} Music") { val.Actions.OfType().First().audioClip = FsmObject.op_Implicit((Object)(object)Phases[num2]); break; } } } } private static AudioClip LoadEmbeddedWav(string path, Assembly asm, string name) { //IL_0000: Unknown result type (might be due to invalid IL or missing references) //IL_0006: Expected O, but got Unknown WavData val = new WavData(); using (Stream stream = asm.GetManifestResourceStream(path)) { val.Parse(stream, (Action)null); } float[] samples = val.GetSamples(); AudioClip obj = AudioClip.Create(name, samples.Length / val.FormatChunk.NumChannels, (int)val.FormatChunk.NumChannels, (int)val.FormatChunk.SampleRate, false); obj.SetData(samples, 0); return obj; } } }