Decompiled source of The CampFire Song SongKR v1.0.1

Peak_CampfireMusic.dll

Decompiled 5 days ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Configuration;
using HarmonyLib;
using UnityEngine;
using UnityEngine.Networking;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: AssemblyTitle("Peak_CampfireMusic")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("Peak_CampfireMusic")]
[assembly: AssemblyCopyright("Copyright ©  2025")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("b1cc2659-bcdb-48ae-8ee1-4160b3d80502")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
[module: UnverifiableCode]
namespace Peak_CampfireMusic;

[BepInPlugin("Xiaohai.Peak.CampfireMusic", "CampfireMusic", "1.0.1")]
public class Plugin : BaseUnityPlugin
{
	[CompilerGenerated]
	private sealed class <LoadAndPlayCampfireMusic>d__9 : IEnumerator<object>, IDisposable, IEnumerator
	{
		private int <>1__state;

		private object <>2__current;

		public Plugin <>4__this;

		object IEnumerator<object>.Current
		{
			[DebuggerHidden]
			get
			{
				return <>2__current;
			}
		}

		object IEnumerator.Current
		{
			[DebuggerHidden]
			get
			{
				return <>2__current;
			}
		}

		[DebuggerHidden]
		public <LoadAndPlayCampfireMusic>d__9(int <>1__state)
		{
			this.<>1__state = <>1__state;
		}

		[DebuggerHidden]
		void IDisposable.Dispose()
		{
			<>1__state = -2;
		}

		private bool MoveNext()
		{
			switch (<>1__state)
			{
			default:
				return false;
			case 0:
				<>1__state = -1;
				<>2__current = <>4__this.LoadCampfireMusic(delegate(AudioClip clip)
				{
					<>4__this.campfireMusic = clip;
				});
				<>1__state = 1;
				return true;
			case 1:
				<>1__state = -1;
				if ((Object)(object)<>4__this.campfireMusic == (Object)null)
				{
					Debug.LogError((object)"无法加载篝火音乐");
					return false;
				}
				return false;
			}
		}

		bool IEnumerator.MoveNext()
		{
			//ILSpy generated this explicit interface implementation from .override directive in MoveNext
			return this.MoveNext();
		}

		[DebuggerHidden]
		void IEnumerator.Reset()
		{
			throw new NotSupportedException();
		}
	}

	[CompilerGenerated]
	private sealed class <LoadCampfireMusic>d__10 : IEnumerator<object>, IDisposable, IEnumerator
	{
		private int <>1__state;

		private object <>2__current;

		public Action<AudioClip> onLoaded;

		public Plugin <>4__this;

		private string <assemblyLocation>5__1;

		private string <filePath>5__2;

		private string <url>5__3;

		private UnityWebRequest <www>5__4;

		private AudioClip <clip>5__5;

		object IEnumerator<object>.Current
		{
			[DebuggerHidden]
			get
			{
				return <>2__current;
			}
		}

		object IEnumerator.Current
		{
			[DebuggerHidden]
			get
			{
				return <>2__current;
			}
		}

		[DebuggerHidden]
		public <LoadCampfireMusic>d__10(int <>1__state)
		{
			this.<>1__state = <>1__state;
		}

		[DebuggerHidden]
		void IDisposable.Dispose()
		{
			int num = <>1__state;
			if (num == -3 || num == 1)
			{
				try
				{
				}
				finally
				{
					<>m__Finally1();
				}
			}
			<assemblyLocation>5__1 = null;
			<filePath>5__2 = null;
			<url>5__3 = null;
			<www>5__4 = null;
			<clip>5__5 = null;
			<>1__state = -2;
		}

		private bool MoveNext()
		{
			//IL_010b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0111: Invalid comparison between Unknown and I4
			try
			{
				switch (<>1__state)
				{
				default:
					return false;
				case 0:
					<>1__state = -1;
					<assemblyLocation>5__1 = Assembly.GetExecutingAssembly().Location;
					<assemblyLocation>5__1 = Path.GetDirectoryName(<assemblyLocation>5__1);
					<filePath>5__2 = Path.Combine(<assemblyLocation>5__1, <>4__this.musicFileName.Value);
					if (!File.Exists(<filePath>5__2))
					{
						Debug.LogError((object)("未找到音乐文件 No found: " + <filePath>5__2));
						onLoaded?.Invoke(null);
						return false;
					}
					<url>5__3 = "file://" + <filePath>5__2;
					<www>5__4 = UnityWebRequestMultimedia.GetAudioClip(<url>5__3, (AudioType)0);
					<>1__state = -3;
					<>2__current = <www>5__4.SendWebRequest();
					<>1__state = 1;
					return true;
				case 1:
					<>1__state = -3;
					if ((int)<www>5__4.result != 1)
					{
						Debug.LogError((object)("music file error: " + <www>5__4.error));
						onLoaded?.Invoke(null);
					}
					else
					{
						<clip>5__5 = DownloadHandlerAudioClip.GetContent(<www>5__4);
						if ((Object)(object)<clip>5__5 != (Object)null)
						{
							((Object)<clip>5__5).name = "campfire_music";
							Debug.Log((object)$"Loaded music file: {((Object)<clip>5__5).name} ({<clip>5__5.length}s)");
							onLoaded?.Invoke(<clip>5__5);
						}
						else
						{
							Debug.LogError((object)"MP3加载成功但未获取到AudioClip");
							onLoaded?.Invoke(null);
						}
						<clip>5__5 = null;
					}
					<>m__Finally1();
					<www>5__4 = null;
					return false;
				}
			}
			catch
			{
				//try-fault
				((IDisposable)this).Dispose();
				throw;
			}
		}

		bool IEnumerator.MoveNext()
		{
			//ILSpy generated this explicit interface implementation from .override directive in MoveNext
			return this.MoveNext();
		}

		private void <>m__Finally1()
		{
			<>1__state = -1;
			if (<www>5__4 != null)
			{
				((IDisposable)<www>5__4).Dispose();
			}
		}

		[DebuggerHidden]
		void IEnumerator.Reset()
		{
			throw new NotSupportedException();
		}
	}

	public AudioClip campfireMusic;

	public static Plugin Instance;

	private const string PLUGIN_GUID = "Xiaohai.Peak.CampfireMusic";

	private const string PLUGIN_NAME = "CampfireMusic";

	private const string PLUGIN_VERSION = "1.0.1";

	public ConfigEntry<string> musicFileName;

	public ConfigEntry<float> musicVolume;

	public ConfigEntry<bool> musicLoop;

	private void Awake()
	{
		//IL_0077: Unknown result type (might be due to invalid IL or missing references)
		Instance = this;
		musicFileName = ((BaseUnityPlugin)this).Config.Bind<string>("Settings", "MusicFileName", "campfire_music.mp3", "Campfire music file name, placed in the plugin directory");
		musicVolume = ((BaseUnityPlugin)this).Config.Bind<float>("Settings", "MusicVolume", 0.85f, "Volume of the campfire music (0.0 to 1.0)");
		musicLoop = ((BaseUnityPlugin)this).Config.Bind<bool>("Settings", "MusicLoop", true, "Whether the campfire music should loop");
		new Harmony("Xiaohai.Peak.CampfireMusic").PatchAll();
		((MonoBehaviour)this).StartCoroutine(LoadAndPlayCampfireMusic());
	}

	[IteratorStateMachine(typeof(<LoadAndPlayCampfireMusic>d__9))]
	private IEnumerator LoadAndPlayCampfireMusic()
	{
		//yield-return decompiler failed: Unexpected instruction in Iterator.Dispose()
		return new <LoadAndPlayCampfireMusic>d__9(0)
		{
			<>4__this = this
		};
	}

	[IteratorStateMachine(typeof(<LoadCampfireMusic>d__10))]
	public IEnumerator LoadCampfireMusic(Action<AudioClip> onLoaded)
	{
		//yield-return decompiler failed: Unexpected instruction in Iterator.Dispose()
		return new <LoadCampfireMusic>d__10(0)
		{
			<>4__this = this,
			onLoaded = onLoaded
		};
	}
}
[HarmonyPatch]
internal static class CampfireMusicPatch
{
	[HarmonyPatch(typeof(Campfire), "Awake")]
	[HarmonyPostfix]
	public static void Postfix(Campfire __instance)
	{
		if ((Object)(object)Plugin.Instance.campfireMusic != (Object)null)
		{
			AudioSource val = ((Component)__instance.loop).gameObject.AddComponent<AudioSource>();
			if ((Object)(object)val != (Object)null)
			{
				val = __instance.loop;
				float num = (__instance.Lit ? Plugin.Instance.musicVolume.Value : 0f);
				val.volume = Mathf.Lerp(val.volume, num, Time.deltaTime * 5f);
				val.clip = Plugin.Instance.campfireMusic;
				val.loop = Plugin.Instance.musicLoop.Value;
				val.Play();
				Debug.Log((object)"Campfire Music OK!");
			}
			else
			{
				Debug.LogError((object)"未找到Campfire的AudioSource组件");
			}
		}
	}
}
[HarmonyPatch(typeof(MapHandler))]
internal static class PatchMapHandler
{
	[HarmonyPatch("GoToSegment")]
	public static void Postfix(MapHandler __instance, ref Segment s)
	{
		//IL_0018: Unknown result type (might be due to invalid IL or missing references)
		//IL_001d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0033: Expected O, but got Unknown
		//IL_006b: Unknown result type (might be due to invalid IL or missing references)
		GameObject val = GameObject.Find("Flag_planted_seagull");
		if ((Object)(object)val != (Object)null)
		{
			SFX_Settings settings = new SFX_Settings
			{
				volume = Plugin.Instance.musicVolume.Value
			};
			SFX_Instance val2 = ScriptableObject.CreateInstance<SFX_Instance>();
			val2.clips = (AudioClip[])(object)new AudioClip[1];
			val2.settings = settings;
			val2.clips[0] = Plugin.Instance.campfireMusic;
			SFX_Player.instance.PlaySFX(val2, val.transform.position, val.transform, (SFX_Settings)null, 1f, Plugin.Instance.musicLoop.Value);
		}
	}
}