Ignore race ability input while a GUI has focus
UnityEngine.Input reads the device directly, so abilities bound to keys or mouse buttons kept firing with the map, the inventory, a chest, the chat or a menu open - clicking an item in a container also swung the transformed attack. Route that input through Player.TakeInput, which is what Valheim runs its own controls through and already reports false for those states (InventoryGui covers the backpack and chests alike). Aswid's transform keys were the only place already doing this; the shared helper replaces that one-off and covers Skadi's cold spell, form keys, flight toggle, form attacks and flight boost, Fenrir's form keys and the attacks of all four form behaviors, Trol's rock throw and true form, and Aswid's devour toggle. Cultist fire is a held button, so it is gated per read rather than around the block: opening a GUI mid-stream now falls through to StopFire() instead of leaving the flames running.
This commit is contained in:
parent
16275d6abc
commit
bca47beda6
9 changed files with 67 additions and 20 deletions
36
JotunnModStub/RaceInput.cs
Normal file
36
JotunnModStub/RaceInput.cs
Normal file
|
|
@ -0,0 +1,36 @@
|
|||
using System.Reflection;
|
||||
using HarmonyLib;
|
||||
|
||||
namespace RacesOfValheim
|
||||
{
|
||||
/// <summary>
|
||||
/// Gate for race ability input.
|
||||
///
|
||||
/// UnityEngine.Input reads the device directly, so abilities bound to keys or mouse buttons
|
||||
/// kept firing while the map, the inventory, a chest, the chat or a menu had focus - dragging
|
||||
/// an item inside a container also swung the transformed attack, for instance. Valheim runs
|
||||
/// its own controls through Player.TakeInput, which reports false for exactly those states
|
||||
/// (InventoryGui covers the backpack and chests alike), so mirror that instead of maintaining
|
||||
/// a parallel list of GUI checks that would drift as the game changes.
|
||||
/// </summary>
|
||||
public static class RaceInput
|
||||
{
|
||||
// Not public on Player, hence the reflection; resolved once rather than per frame.
|
||||
private static readonly MethodInfo TakeInputMethod = AccessTools.Method(typeof(Player), "TakeInput");
|
||||
|
||||
public static bool Allowed
|
||||
{
|
||||
get
|
||||
{
|
||||
Player player = Player.m_localPlayer;
|
||||
if (player == null) return false;
|
||||
|
||||
// Fail open: if a game update ever renames the method, abilities stay usable
|
||||
// rather than silently going dead.
|
||||
if (TakeInputMethod == null) return true;
|
||||
|
||||
return (bool)TakeInputMethod.Invoke(player, null);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue