Bring back patch to impact audio

This commit is contained in:
xen-42 2025-02-10 16:12:02 -05:00
parent d5d9200331
commit 8a1fa3de97
2 changed files with 33 additions and 1 deletions

View File

@ -1,4 +1,3 @@
using HarmonyLib;
using NewHorizons.Utility.OWML; using NewHorizons.Utility.OWML;
using UnityEngine; using UnityEngine;
using UnityEngine.SceneManagement; using UnityEngine.SceneManagement;
@ -7,10 +6,16 @@ namespace NewHorizons.Handlers
{ {
internal class InvulnerabilityHandler internal class InvulnerabilityHandler
{ {
/// <summary>
/// Used in patches
/// </summary>
public static bool Invincible { get; private set; }
public static void MakeInvulnerable(bool invulnerable) public static void MakeInvulnerable(bool invulnerable)
{ {
NHLogger.Log($"Toggling immortality: {invulnerable}"); NHLogger.Log($"Toggling immortality: {invulnerable}");
Invincible = invulnerable;
var deathManager = GetDeathManager(); var deathManager = GetDeathManager();
var resources = GetPlayerResouces(); var resources = GetPlayerResouces();
@ -29,5 +34,11 @@ namespace NewHorizons.Handlers
private static DeathManager GetDeathManager() => GameObject.FindObjectOfType<DeathManager>(); private static DeathManager GetDeathManager() => GameObject.FindObjectOfType<DeathManager>();
private static PlayerResources GetPlayerResouces() => GameObject.FindObjectOfType<PlayerResources>(); private static PlayerResources GetPlayerResouces() => GameObject.FindObjectOfType<PlayerResources>();
static InvulnerabilityHandler()
{
// If the scene unloads when Invincible is on it might not get turned off
SceneManager.sceneUnloaded += (_) => Invincible = false;
}
} }
} }

View File

@ -0,0 +1,21 @@
using HarmonyLib;
using NewHorizons.Handlers;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace NewHorizons.Patches;
[HarmonyPatch]
public static class PlayerImpactAudioPatches
{
[HarmonyPrefix]
[HarmonyPatch(typeof(PlayerImpactAudio), nameof(PlayerImpactAudio.OnImpact))]
public static bool PlayerImpactAudio_OnImpact()
{
// DeathManager and PlayerResources _invincible stops player dying but you still hear the impact sounds which is annoying so we disable them
return !InvulnerabilityHandler.Invincible;
}
}