Decompiled source of RainieLove v1.0.0

ror2RainieLove.dll

Decompiled 2 days ago
using System.Collections.ObjectModel;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using HG.Reflection;
using RoR2;
using UnityEngine;
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: OptIn]
[assembly: AssemblyTitle("ror2RainieLove")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("HP")]
[assembly: AssemblyProduct("ror2RainieLove")]
[assembly: AssemblyCopyright("Copyright © HP 2026")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("0b90c640-2c3f-4f7e-ac06-1345046ee2c4")]
[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 ror2RainieLove;

[BepInPlugin("com.rainie.love", "RainieLove", "1.0.0")]
public class RainieLovePlugin : BaseUnityPlugin
{
	internal static ManualLogSource Log;

	private static ConfigEntry<float> volumeConfig;

	private static bool isRunActive;

	private bool wasPlayingState = false;

	private bool isMusicPlaying = false;

	private float spawnGraceTimer = 0f;

	private float checkTimer = 0f;

	private const float checkInterval = 0.2f;

	private const string PlayEventName = "Play_RainieLove";

	private const string StopEventName = "Stop_RainieLove";

	public static RainieLovePlugin Instance { get; private set; }

	private void Awake()
	{
		Instance = this;
		Log = ((BaseUnityPlugin)this).Logger;
		volumeConfig = ((BaseUnityPlugin)this).Config.Bind<float>("Audio", "Volume", 0.5f, "音量 (注: 最终音量受游戏内设置影响)");
		Run.onRunStartGlobal += OnRunStart;
		Run.onRunDestroyGlobal += OnRunEnd;
		SceneManager.sceneLoaded += OnSceneLoaded;
		TeleporterInteraction.onTeleporterBeginChargingGlobal += OnTeleporterCharging;
		Log.LogInfo((object)"[RainieLove] 模组已加载!使用 Wwise SoundBank 播放。");
	}

	private void OnDestroy()
	{
		Run.onRunStartGlobal -= OnRunStart;
		Run.onRunDestroyGlobal -= OnRunEnd;
		SceneManager.sceneLoaded -= OnSceneLoaded;
		TeleporterInteraction.onTeleporterBeginChargingGlobal -= OnTeleporterCharging;
	}

	private void Update()
	{
		if (!isRunActive || (Object)(object)Run.instance == (Object)null || (Object)(object)Stage.instance == (Object)null)
		{
			return;
		}
		if (spawnGraceTimer > 0f)
		{
			spawnGraceTimer -= Time.deltaTime;
			return;
		}
		checkTimer += Time.deltaTime;
		if (!(checkTimer < 0.2f))
		{
			checkTimer = 0f;
			bool flag = CheckShouldPlay();
			if (flag && !wasPlayingState)
			{
				wasPlayingState = true;
				PlayMusic();
			}
			else if (!flag && wasPlayingState)
			{
				wasPlayingState = false;
				StopMusic("存活人数变化/结束");
			}
		}
	}

	private bool CheckShouldPlay()
	{
		ReadOnlyCollection<PlayerCharacterMasterController> instances = PlayerCharacterMasterController.instances;
		if (instances == null)
		{
			return false;
		}
		int num = 0;
		int num2 = 0;
		foreach (PlayerCharacterMasterController item in instances)
		{
			if ((Object)(object)item == (Object)null || (Object)(object)item.master == (Object)null)
			{
				continue;
			}
			num++;
			if ((Object)(object)item.master.inventory != (Object)null && item.master.inventory.GetItemCount(Items.ExtraLife) > 0)
			{
				num2++;
				continue;
			}
			CharacterBody body = item.master.GetBody();
			if ((Object)(object)body != (Object)null && (Object)(object)body.healthComponent != (Object)null && body.healthComponent.alive)
			{
				num2++;
			}
		}
		if (num2 == 0 || (num > 1 && num2 == 1))
		{
			return true;
		}
		return false;
	}

	private void PlayMusic()
	{
		if (!isMusicPlaying)
		{
			Util.PlaySound("Play_RainieLove", ((Component)this).gameObject);
			isMusicPlaying = true;
			Log.LogInfo((object)"[RainieLove] 队友全灭!触发 Wwise 事件:播放《雨爱》");
		}
	}

	private void StopMusic(string reason)
	{
		if (isMusicPlaying)
		{
			Util.PlaySound("Stop_RainieLove", ((Component)this).gameObject);
			isMusicPlaying = false;
			Log.LogInfo((object)("[RainieLove] 触发 Wwise 事件:停止播放 (" + reason + ")"));
		}
	}

	private void OnRunStart(Run run)
	{
		isRunActive = true;
		wasPlayingState = false;
		isMusicPlaying = false;
		spawnGraceTimer = 3f;
		Log.LogInfo((object)"[RainieLove] 游戏开始");
	}

	private void OnRunEnd(Run run)
	{
		isRunActive = false;
		StopMusic("游戏结束");
		wasPlayingState = false;
	}

	private void OnSceneLoaded(Scene scene, LoadSceneMode mode)
	{
		StopMusic("场景切换");
		wasPlayingState = false;
		spawnGraceTimer = 3f;
	}

	private void OnTeleporterCharging(TeleporterInteraction teleporter)
	{
		StopMusic("传送门充能完毕");
		wasPlayingState = false;
		spawnGraceTimer = 3f;
	}

	[ConCommand(/*Could not decode attribute arguments.*/)]
	private static void CCPlay(ConCommandArgs args)
	{
		if ((Object)(object)Instance != (Object)null)
		{
			Instance.PlayMusic();
		}
	}

	[ConCommand(/*Could not decode attribute arguments.*/)]
	private static void CCStop(ConCommandArgs args)
	{
		if ((Object)(object)Instance != (Object)null)
		{
			Instance.StopMusic("控制台强制停止");
		}
	}

	[ConCommand(/*Could not decode attribute arguments.*/)]
	private static void CCStatus(ConCommandArgs args)
	{
		if ((Object)(object)Instance == (Object)null)
		{
			return;
		}
		ReadOnlyCollection<PlayerCharacterMasterController> instances = PlayerCharacterMasterController.instances;
		int num = 0;
		int num2 = 0;
		if (instances != null)
		{
			foreach (PlayerCharacterMasterController item in instances)
			{
				if ((Object)(object)item == (Object)null || (Object)(object)item.master == (Object)null)
				{
					continue;
				}
				num++;
				if ((Object)(object)item.master.inventory != (Object)null && item.master.inventory.GetItemCount(Items.ExtraLife) > 0)
				{
					num2++;
					continue;
				}
				CharacterBody body = item.master.GetBody();
				if ((Object)(object)body != (Object)null && (Object)(object)body.healthComponent != (Object)null && body.healthComponent.alive)
				{
					num2++;
				}
			}
		}
		bool flag = num2 == 0 || (num > 1 && num2 == 1);
		Debug.Log((object)"====== RainieLove 状态 ======");
		Debug.Log((object)("播放状态: " + (Instance.isMusicPlaying ? "正在播放" : "未播放")));
		Debug.Log((object)("宽限倒计时: " + ((Instance.spawnGraceTimer > 0f) ? (Instance.spawnGraceTimer.ToString("F1") + "秒") : "已结束")));
		Debug.Log((object)$"房间总玩家: {num}");
		Debug.Log((object)$"当前存活人数: {num2}");
		Debug.Log((object)("是否满足播放条件: " + (flag ? "是" : "否")));
		Debug.Log((object)"==============================");
	}
}