Please disclose if your mod was created primarily using AI tools by adding the 'AI Generated' category. Failing to do so may result in the mod being removed from Thunderstore.
Decompiled source of YakkityFast v0.1.1
plugins/YakkityFast.dll
Decompiled 5 months agousing System; using System.Collections; using System.Diagnostics; using System.IO; using System.Reflection; using System.Runtime.CompilerServices; using System.Runtime.InteropServices; using System.Runtime.Versioning; using BepInEx; using BepInEx.Configuration; using HarmonyLib; using UnityEngine; using UnityEngine.Networking; [assembly: CompilationRelaxations(8)] [assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)] [assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)] [assembly: AssemblyTitle("YakkityFast")] [assembly: AssemblyDescription("")] [assembly: AssemblyConfiguration("")] [assembly: AssemblyCompany("")] [assembly: AssemblyProduct("YakkityFast")] [assembly: AssemblyCopyright("Copyright © 2024")] [assembly: AssemblyTrademark("")] [assembly: ComVisible(false)] [assembly: Guid("ea282da8-693d-4cf1-bf7a-8ecac0827eaa")] [assembly: AssemblyFileVersion("1.0.0.0")] [assembly: TargetFramework(".NETFramework,Version=v4.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")] [assembly: AssemblyVersion("1.0.0.0")] namespace YakkityFast; [BepInPlugin("com.oathorse.Yakkity", "Yakkity Fast", "0.1.1")] public class YakkityFast : BaseUnityPlugin { public const string PluginGUID = "com.oathorse.Yakkity"; public const string PluginName = "Yakkity Fast"; public const string PluginVersion = "0.1.1"; private readonly Harmony harmony = new Harmony("com.oathorse.Yakkity"); private ConfigEntry<float> m_minSpeed; private ConfigEntry<float> m_maxSeconds; private ConfigEntry<float> m_fadeDelay; private ConfigEntry<float> m_fadeRate; private ConfigEntry<float> m_startGracePeriod; private ConfigEntry<float> m_stopGracePeriod; private AudioSource m_audioSource; private AudioClip m_sound; private bool m_isPlaying; private float m_elapsedSeconds; private float m_gracePeriodTimer; private bool m_disabled; private const float DEFAULT_FADE_DELAY = 60f; private const float DEFAULT_MAX_SECONDS = 120f; private IEnumerator LoadAudio(string filePath) { string text = "file://" + filePath; UnityWebRequest www = UnityWebRequestMultimedia.GetAudioClip(text, (AudioType)14); try { DebugLog("Loading: '" + www.url + "'"); yield return www.SendWebRequest(); if ((int)www.result == 2 || (int)www.result == 3) { Result result = www.result; Debug.LogError((object)("Error loading OGG file: result: " + ((object)(Result)(ref result)).ToString() + " error: " + www.error)); } else { m_sound = DownloadHandlerAudioClip.GetContent(www); m_audioSource = ((Component)this).gameObject.AddComponent<AudioSource>(); m_audioSource.clip = m_sound; } } finally { ((IDisposable)www)?.Dispose(); } } private void DebugLog(string message) { } private void AddConsoleCommands() { //IL_0011: Unknown result type (might be due to invalid IL or missing references) //IL_0024: Expected O, but got Unknown //IL_001f: Unknown result type (might be due to invalid IL or missing references) new ConsoleCommand("yakkity", "Controls Yakkity Fast", (ConsoleEventFailable)delegate(ConsoleEventArgs args) { if (!Object.op_Implicit((Object)(object)Game.instance)) { return true; } if (args.Length > 1) { switch (args[1]) { case "unleashed": m_fadeDelay.Value = 0f; m_maxSeconds.Value = 0f; m_disabled = false; ((BaseUnityPlugin)this).Config.Save(); break; case "default": m_fadeDelay.Value = 60f; m_maxSeconds.Value = 120f; m_disabled = false; ((BaseUnityPlugin)this).Config.Save(); break; case "off": m_disabled = true; break; case "on": m_disabled = false; break; } } return true; }, false, false, false, false, false, (ConsoleOptionsFetcher)null, false, false, false); } private void Awake() { string filePath = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location) + "\\YakkitySax.ogg"; ((MonoBehaviour)this).StartCoroutine(LoadAudio(filePath)); harmony.PatchAll(); AddConsoleCommands(); m_minSpeed = ((BaseUnityPlugin)this).Config.Bind<float>("General", "Minimum Speed", 10.5f, "The minimum velocity where the audio will start playing"); m_maxSeconds = ((BaseUnityPlugin)this).Config.Bind<float>("General", "Maximum Seconds", 0f, "The maximum number of seconds of audio that will ever play, 0 for no limit"); m_fadeDelay = ((BaseUnityPlugin)this).Config.Bind<float>("General", "Fade Delay", 0f, "The number of seconds before audio fades"); m_fadeRate = ((BaseUnityPlugin)this).Config.Bind<float>("General", "Fade Rate", 0.1f, "The rate at which audio will fade once playing"); m_startGracePeriod = ((BaseUnityPlugin)this).Config.Bind<float>("General", "Start Grace Period", 1f, "Number of seconds velocity must be below Minimum Speed for music to Start"); m_stopGracePeriod = ((BaseUnityPlugin)this).Config.Bind<float>("General", "Stop Grace Period", 3f, "Number of seconds velocity must be below Minimum Speed for music to Stop"); } private void Update() { //IL_0042: Unknown result type (might be due to invalid IL or missing references) //IL_0047: Unknown result type (might be due to invalid IL or missing references) Player localPlayer = Player.m_localPlayer; if ((Object)(object)localPlayer == (Object)null || !Object.op_Implicit((Object)(object)m_audioSource)) { return; } if (m_disabled) { if (m_isPlaying) { m_audioSource.Stop(); m_isPlaying = false; } return; } Vector3 velocity = ((Character)localPlayer).GetVelocity(); velocity.y = 0f; if (((Vector3)(ref velocity)).magnitude > m_minSpeed.Value) { if (!m_isPlaying) { m_gracePeriodTimer -= Time.deltaTime; if (m_gracePeriodTimer <= 0f) { Debug.LogWarning((object)"YF: Starting music"); m_audioSource.Play(); m_isPlaying = true; m_elapsedSeconds = 0f; m_gracePeriodTimer = m_stopGracePeriod.Value; m_audioSource.volume = 1f; } else { DebugLog($"YF: Start Audio m_gracePeriodTimer: {m_gracePeriodTimer}"); } return; } m_elapsedSeconds += Time.deltaTime; if (m_fadeDelay.Value > 0f && m_elapsedSeconds > m_fadeDelay.Value) { DebugLog("YF: Fading, volume =" + m_audioSource.volume); float num = m_fadeRate.Value * Time.deltaTime; AudioSource audioSource = m_audioSource; audioSource.volume -= num; m_audioSource.volume = Mathf.Clamp(m_audioSource.volume, 0f, 1f); } if (m_maxSeconds.Value > 0f && m_elapsedSeconds > m_maxSeconds.Value) { DebugLog("YF: MaxSeconds Elapsed, Stopping"); m_audioSource.Stop(); m_isPlaying = false; } m_gracePeriodTimer = m_stopGracePeriod.Value; } else if (m_isPlaying) { m_gracePeriodTimer -= Time.deltaTime; if (m_gracePeriodTimer <= 0f) { DebugLog("YF: Grace Period elapsed, Stopping"); m_audioSource.Stop(); m_isPlaying = false; m_gracePeriodTimer = m_startGracePeriod.Value; } else { DebugLog($"YF: Stop Audio m_gracePeriodTimer: {m_gracePeriodTimer}"); m_audioSource.volume = m_gracePeriodTimer / m_stopGracePeriod.Value; } } else { m_gracePeriodTimer = m_startGracePeriod.Value; } } }