using System;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Bootstrap;
using BepInEx.Configuration;
using BepInEx.Logging;
using HarmonyLib;
using LCSoundTool;
using UnityEngine;
using UnityEngine.Audio;
using UnityEngine.SceneManagement;
[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: AssemblyTitle("ShipMusic")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("ShipMusic")]
[assembly: AssemblyCopyright("Copyright © 2024")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("20ce88c8-f922-4500-b497-7ec06c9dcb99")]
[assembly: AssemblyFileVersion("1.0.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")]
[assembly: AssemblyVersion("1.0.0.0")]
namespace ShipMusic;
internal class MusicScript : MonoBehaviour
{
public static GameObject hangarShip;
public static GameObject musicObj;
private static AudioClip musicClip;
public static AudioSource shipMusicSource;
public static AudioMixerGroup gameMixerGroup;
private void Update()
{
//IL_010b: Unknown result type (might be due to invalid IL or missing references)
//IL_0115: Expected O, but got Unknown
//IL_013a: Unknown result type (might be due to invalid IL or missing references)
//IL_014f: Unknown result type (might be due to invalid IL or missing references)
//IL_0173: Unknown result type (might be due to invalid IL or missing references)
try
{
if ((Object)(object)hangarShip == (Object)null)
{
hangarShip = GameObject.Find("/Environment/HangarShip/");
gameMixerGroup = hangarShip.GetComponent<AudioSource>().outputAudioMixerGroup;
if ((Object)(object)musicClip == (Object)null)
{
try
{
Plugin.mls.LogWarning((object)"no file loaded, checking for files in the folder!");
musicClip = SoundTool.GetAudioClip("Command293-ShipMusic", "music.wav");
}
catch (Exception)
{
try
{
Plugin.mls.LogWarning((object)"no wav, trying ogg!");
musicClip = SoundTool.GetAudioClip("Command293-ShipMusic", "music.ogg");
}
catch (Exception)
{
try
{
Plugin.mls.LogWarning((object)"no wav, no ogg, trying mp3!");
musicClip = SoundTool.GetAudioClip("Command293-ShipMusic", "music.mp3");
goto end_IL_009d;
}
catch (Exception)
{
Plugin.mls.LogError((object)"No files found! have you checked the mod folder to see if the music file is there?");
goto end_IL_009d;
}
end_IL_009d:;
}
}
}
if ((Object)(object)hangarShip != (Object)null && (Object)(object)musicObj == (Object)null)
{
musicObj = new GameObject("ShipMusicSource");
musicObj.transform.SetParent(hangarShip.transform, false);
musicObj.transform.rotation = Quaternion.identity;
musicObj.transform.localScale = Vector3.one;
musicObj.transform.localPosition = new Vector3(2.2f, 0.5f, -6.7f);
musicObj.AddComponent<AudioSource>();
shipMusicSource = musicObj.GetComponent<AudioSource>();
if (Plugin.enableFilter.Value)
{
Plugin.mls.LogInfo((object)"filter config is enabled, adding filters...");
musicObj.AddComponent<AudioHighPassFilter>();
musicObj.AddComponent<AudioDistortionFilter>();
musicObj.AddComponent<AudioLowPassFilter>();
musicObj.GetComponent<AudioHighPassFilter>().cutoffFrequency = 4150f;
musicObj.GetComponent<AudioDistortionFilter>().distortionLevel = 0.92f;
musicObj.GetComponent<AudioLowPassFilter>().cutoffFrequency = 3064f;
Plugin.mls.LogInfo((object)"Added filters! unfortunately you can't remove them in-game yet, as that would need the mod to destroy this gameobject");
}
shipMusicSource.dopplerLevel = 0f;
shipMusicSource.spatialBlend = 1f;
shipMusicSource.volume = Plugin.musicVolume.Value;
shipMusicSource.loop = true;
shipMusicSource.priority = 0;
shipMusicSource.playOnAwake = false;
shipMusicSource.maxDistance = Plugin.maxMusicDistance.Value;
shipMusicSource.minDistance = 1f;
shipMusicSource.rolloffMode = (AudioRolloffMode)1;
shipMusicSource.clip = musicClip;
shipMusicSource.outputAudioMixerGroup = gameMixerGroup;
shipMusicSource.Play();
Plugin.mls.LogInfo((object)"made ship music gameobject!");
}
}
}
catch (Exception arg)
{
Plugin.mls.LogError((object)$"found error while making gameobject:\n{arg}");
}
shipMusicSource.maxDistance = Plugin.maxMusicDistance.Value;
shipMusicSource.volume = Plugin.musicVolume.Value;
}
}
[BepInPlugin("command293.ShipMusic", "ShipMusic", "1.0.0")]
[BepInDependency(/*Could not decode attribute arguments.*/)]
[BepInDependency(/*Could not decode attribute arguments.*/)]
public class Plugin : BaseUnityPlugin
{
public const string GUID = "command293.ShipMusic";
public const string NAME = "ShipMusic";
public const string VERSION = "1.0.0";
public static AudioClip selectedClip;
public static ConfigEntry<float> musicVolume;
public static ConfigEntry<float> maxMusicDistance;
public static ConfigEntry<bool> enableFilter;
public static ManualLogSource mls { get; private set; }
private void Awake()
{
//IL_003b: Unknown result type (might be due to invalid IL or missing references)
//IL_0045: Expected O, but got Unknown
mls = ((BaseUnityPlugin)this).Logger;
musicVolume = ((BaseUnityPlugin)this).Config.Bind<float>("General", "SoundVolume", 1f, new ConfigDescription("Volume of the music", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0f, 1f), Array.Empty<object>()));
maxMusicDistance = ((BaseUnityPlugin)this).Config.Bind<float>("General", "MaxDistance", 25f, "The maximum distance from which the music can reach the player listener");
enableFilter = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "SoundFilter", false, "When true, adds a filter that makes the music sound like it's heard from an actual old radio.");
SceneManager.sceneLoaded += OnSceneLoaded;
SetModCompatibility();
mls.LogInfo((object)"Plugin loaded, and the ship now has music constantly playing in it. how fun");
}
private void SetModCompatibility()
{
if (!Chainloader.PluginInfos.ContainsKey("BMX.LobbyCompatibility"))
{
mls.LogInfo((object)"BMX.LobbyCompatibility wasn't found, skipped checking everything else.");
return;
}
MethodInfo methodInfo = AccessTools.Method("LobbyCompatibility.Features.PluginHelper:RegisterPlugin", (Type[])null, (Type[])null);
if (methodInfo == null)
{
mls.LogError((object)"failed to get BMX.LobbyCompatibility RegisterPlugin method, as it is somehow null");
return;
}
mls.LogInfo((object)"Registering mod to BMX.LobbyCompatibility..");
try
{
methodInfo.Invoke(null, new object[4]
{
"command293.ShipMusic",
new Version("1.0.0"),
0,
0
});
}
catch
{
mls.LogError((object)"got an error while registering mod, so this mod probably isn't registered.");
return;
}
mls.LogInfo((object)"Registered mod with BMX.LobbyCompatibility");
}
private void OnSceneLoaded(Scene scene, LoadSceneMode loadMode)
{
//IL_001c: Unknown result type (might be due to invalid IL or missing references)
//IL_0022: Expected O, but got Unknown
if (((Scene)(ref scene)).name == "SampleSceneRelay")
{
GameObject val = new GameObject("ShipMusicController");
val.AddComponent<MusicScript>();
Object.DontDestroyOnLoad((Object)(object)val);
((Object)val).hideFlags = (HideFlags)61;
mls.LogInfo((object)"added the music to the ship!");
}
if (((Scene)(ref scene)).name == "MainMenu")
{
GameObject val2 = GameObject.Find("ShipMusicController");
Object.Destroy((Object)(object)val2);
mls.LogInfo((object)"in main menu, destroyed music object");
}
}
}