Decompiled source of Shanty4Heim v1.0.1

plugins/SeaShanty4Heim.dll

Decompiled a day ago
using 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.Logging;
using HarmonyLib;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: AssemblyTitle("SeaShanty4Heim")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("SeaShanty4Heim")]
[assembly: AssemblyCopyright("Copyright ©  2025")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("82659a80-5ea4-4861-89b2-1482c7681b90")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")]
[assembly: AssemblyVersion("1.0.0.0")]
namespace SeaShantyMod;

[BepInPlugin("com.yourname.seashantymod", "Sea Shanty 2 Dance Mod", "1.0.0")]
public class SeaShantyPlugin : BaseUnityPlugin
{
	private const string pluginGUID = "com.yourname.seashantymod";

	private const string pluginName = "Sea Shanty 2 Dance Mod";

	private const string pluginVersion = "1.0.0";

	private readonly Harmony harmony = new Harmony("com.yourname.seashantymod");

	public static ManualLogSource logger;

	public static AudioClip seaShanty2Clip;

	private static AudioSource musicSource;

	public void Awake()
	{
		logger = ((BaseUnityPlugin)this).Logger;
		logger.LogInfo((object)"Sea Shanty 2 Mod loaded!");
		LoadAudioClip();
		harmony.PatchAll(Assembly.GetExecutingAssembly());
	}

	private void LoadAudioClip()
	{
		try
		{
			string text = "SeaShanty4Heim.Assets.Sea_Shanty_2.wav";
			using Stream stream = Assembly.GetExecutingAssembly().GetManifestResourceStream(text);
			if (stream == null)
			{
				logger.LogError((object)("Could not find embedded resource: " + text));
				logger.LogInfo((object)"Available resources:");
				string[] manifestResourceNames = Assembly.GetExecutingAssembly().GetManifestResourceNames();
				foreach (string text2 in manifestResourceNames)
				{
					logger.LogInfo((object)("  - " + text2));
				}
			}
			else
			{
				byte[] array = new byte[stream.Length];
				stream.Read(array, 0, array.Length);
				string path = Path.Combine(Path.GetTempPath(), "seashanty2.wav");
				File.WriteAllBytes(path, array);
				((MonoBehaviour)this).StartCoroutine(LoadAudioFromFile(path));
			}
		}
		catch (Exception arg)
		{
			logger.LogError((object)$"Error loading audio: {arg}");
		}
	}

	private IEnumerator LoadAudioFromFile(string path)
	{
		WWW www = new WWW("file:///" + path);
		try
		{
			yield return www;
			if (string.IsNullOrEmpty(www.error))
			{
				seaShanty2Clip = www.GetAudioClip(false, false, (AudioType)20);
				logger.LogInfo((object)"Sea Shanty 2 audio loaded successfully!");
			}
			else
			{
				logger.LogError((object)("Failed to load audio: " + www.error));
			}
		}
		finally
		{
			((IDisposable)www)?.Dispose();
		}
	}

	public static void PlaySeaShanty(Player player)
	{
		//IL_003b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0041: Expected O, but got Unknown
		if ((Object)(object)seaShanty2Clip == (Object)null)
		{
			logger.LogWarning((object)"Audio clip not loaded yet!");
			return;
		}
		if ((Object)(object)musicSource == (Object)null)
		{
			GameObject val = new GameObject("SeaShantyAudioSource");
			musicSource = val.AddComponent<AudioSource>();
			musicSource.spatialBlend = 0f;
			musicSource.volume = 0.3f;
			musicSource.loop = true;
			Object.DontDestroyOnLoad((Object)(object)val);
		}
		if (!musicSource.isPlaying)
		{
			musicSource.clip = seaShanty2Clip;
			musicSource.Play();
		}
	}

	public static void StopSeaShanty()
	{
		if ((Object)(object)musicSource != (Object)null && musicSource.isPlaying)
		{
			musicSource.Stop();
		}
	}
}
[HarmonyPatch(typeof(Player), "UpdateEmote")]
public static class Patch_Player_UpdateEmote
{
	private static bool wasPlayingOnBoat;

	private static void Postfix(Player __instance)
	{
		bool flag = ((Character)__instance).InEmote();
		Ship standingOnShip = ((Character)__instance).GetStandingOnShip();
		bool flag2 = (Object)(object)standingOnShip != (Object)null;
		bool flag3 = flag && flag2;
		if (flag3 && !wasPlayingOnBoat)
		{
			SeaShantyPlugin.PlaySeaShanty(__instance);
			wasPlayingOnBoat = true;
		}
		else if (!flag3 && wasPlayingOnBoat)
		{
			SeaShantyPlugin.StopSeaShanty();
			wasPlayingOnBoat = false;
		}
	}
}