The attack block patched Character.StartAttack, which Humanoid overrides without calling the base, so it never ran; and it covered the Fenring only. Every form swing also fired the hidden human's attack: stamina spent, regen held at zero while it played, and forward_speed dropped to 0. Patch Humanoid.StartAttack for all four forms, and clear m_blocking after SetControls so the pad's heavy attack stops raising the guard. Forms treat the player as airborne only after 0.25 s off the ground, so bumps no longer flicker run to idle. Melee reach ignores the target's own colliders and accepts a clear line from the eyes or the attack point, with an opt-in hit log. Sunrise names the key that still works by day.
129 lines
5.5 KiB
C#
129 lines
5.5 KiB
C#
using System.Collections;
|
|
using BepInEx;
|
|
using HarmonyLib;
|
|
using Jotunn.Configs;
|
|
using Jotunn.Entities;
|
|
using Jotunn.Managers;
|
|
using UnityEngine;
|
|
using UnityEngine.UI; // Added for UI
|
|
|
|
namespace RacesOfValheim
|
|
{
|
|
/// <summary>
|
|
/// The hidden human does not attack while a form does.
|
|
///
|
|
/// This patched Character.StartAttack, and it never ran once: Humanoid overrides StartAttack
|
|
/// without calling the base, and a player is a Humanoid. Skadi, the Aswid and the Sverm all
|
|
/// patch Humanoid, which is why their forms were clean and the Fenrir's were not. So every
|
|
/// claw and bite also fired the invisible human's own attack on the same button, and that
|
|
/// attack is what a player saw as three separate bugs:
|
|
/// - it spent stamina on every swing, and while its animation ran Player.UpdateStats held
|
|
/// stamina regen at zero (InAttack), so an empty bar did not come back mid-fight;
|
|
/// - a human mid-attack stands still, so the forward_speed the form copies dropped to 0 and
|
|
/// the creature fell back to idle in the middle of a fight;
|
|
/// - it did so with whatever weapon was in hand.
|
|
/// It also only ever looked at SE_FenrirForm, so even working it would have covered the Fenring
|
|
/// alone and left the Wolf, the Ulv and the Cultist out.
|
|
/// </summary>
|
|
[HarmonyPatch(typeof(Humanoid), nameof(Humanoid.StartAttack))]
|
|
public static class BlockPlayerLogicAttackPatch
|
|
{
|
|
public static bool Prefix(Humanoid __instance)
|
|
{
|
|
return !FenrirForms.LocalInForm(__instance);
|
|
}
|
|
}
|
|
|
|
// --- PATCH 2: BLOCCO ANIMAZIONI ED EFFETTI SONORI NATIVI ---
|
|
// Every form now, not the Fenring alone: see BlockPlayerLogicAttackPatch.
|
|
[HarmonyPatch(typeof(ZSyncAnimation), nameof(ZSyncAnimation.SetTrigger))]
|
|
public static class BlockPlayerAnimationsPatch
|
|
{
|
|
public static bool Prefix(ZSyncAnimation __instance, string name)
|
|
{
|
|
if (Player.m_localPlayer != null && __instance.gameObject == Player.m_localPlayer.gameObject)
|
|
{
|
|
if (FenrirForms.LocalInForm(Player.m_localPlayer))
|
|
{
|
|
string triggerName = name.ToLower();
|
|
if (triggerName.Contains("attack") || triggerName.Contains("swing") || triggerName.Contains("punch"))
|
|
{
|
|
return false;
|
|
}
|
|
}
|
|
}
|
|
return true;
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// The hidden human does not block while a form is up either. The forms put their heavy attack
|
|
/// on Right Mouse, and on a gamepad RaceInput maps that to JoyBlock, so every heavy bite also
|
|
/// raised the human's guard: it turned to face the camera and strafed (the form copies that
|
|
/// movement) and regenerated stamina at 80%. A wolf has no shield to raise.
|
|
///
|
|
/// Cleared after SetControls rather than by answering IsBlocking with false: Player also reads
|
|
/// the raw m_blocking flag for the strafe, and the block-and-jump dodge is worked out inside
|
|
/// SetControls before this runs, so the dodge still works.
|
|
/// </summary>
|
|
[HarmonyPatch(typeof(Player), nameof(Player.SetControls))]
|
|
public static class BlockPlayerGuardPatch
|
|
{
|
|
private static readonly AccessTools.FieldRef<Character, bool> Blocking =
|
|
AccessTools.FieldRefAccess<Character, bool>("m_blocking");
|
|
|
|
public static void Postfix(Player __instance)
|
|
{
|
|
if (FenrirForms.LocalInForm(__instance)) Blocking(__instance) = false;
|
|
}
|
|
}
|
|
|
|
[HarmonyPatch]
|
|
public static class FenrirDamagePatch
|
|
{
|
|
[HarmonyTargetMethod]
|
|
public static System.Reflection.MethodBase TargetMethod()
|
|
{
|
|
return System.Linq.Enumerable.FirstOrDefault(
|
|
HarmonyLib.AccessTools.GetDeclaredMethods(typeof(ItemDrop.ItemData)),
|
|
m => m.Name == "GetDamage" && m.ReturnType == typeof(HitData.DamageTypes)
|
|
);
|
|
}
|
|
public static void Postfix(ItemDrop.ItemData __instance, ref HitData.DamageTypes __result)
|
|
{
|
|
if (Player.m_localPlayer != null &&
|
|
Player.m_localPlayer.GetSEMan().HaveStatusEffect("SE_FenrirCurse".GetStableHashCode()) &&
|
|
Player.m_localPlayer.GetInventory().ContainsItem(__instance))
|
|
{
|
|
int state = BossProgressionManager.GetCurrentProgressionState();
|
|
if (state > 0)
|
|
{
|
|
float bonus = FenrirProgression.GetDamageBonus(state);
|
|
|
|
if (__result.m_slash > 0) __result.m_slash += bonus;
|
|
if (__result.m_blunt > 0) __result.m_blunt += bonus;
|
|
if (__result.m_pierce > 0) __result.m_pierce += bonus;
|
|
if (__result.m_chop > 0) __result.m_chop += bonus;
|
|
if (__result.m_pickaxe > 0) __result.m_pickaxe += bonus;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
[HarmonyPatch(typeof(Player), nameof(Player.GetBodyArmor))]
|
|
public static class FenrirArmorPatch
|
|
{
|
|
public static void Postfix(Player __instance, ref float __result)
|
|
{
|
|
if (__instance != null && __instance == Player.m_localPlayer)
|
|
{
|
|
if (__instance.GetSEMan().HaveStatusEffect("SE_FenrirCurse".GetStableHashCode()))
|
|
{
|
|
int state = BossProgressionManager.GetCurrentProgressionState();
|
|
__result += FenrirProgression.GetArmorBonus(state);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
}
|