Merge pull request 'rework-skadi-flight' (#11) from rework-skadi-flight into main

Reviewed-on: #11
This commit is contained in:
kanym 2026-08-05 11:24:21 +02:00
commit a5a64b3c6b
8 changed files with 225 additions and 39 deletions

3
.gitignore vendored
View file

@ -16,6 +16,9 @@ temp_test_zip/
test_extract/
*.dll
# Release packaging output - a Release build drops the Thunderstore and Nexus zips here.
/dist/
# OS generated files
.DS_Store
Thumbs.db

View file

@ -329,7 +329,12 @@ namespace RacesOfValheim {
if (prefab != null && playerVisual != null)
{
playerVisual.localScale = Vector3.one * 0.001f;
// Shrinking the Visual to nothing was how this hid the human body, and it stopped
// working: the scale reset that keeps a non-Trol player at normal size runs from a
// postfix on this same update and puts it straight back to 1, so the man reappeared
// standing inside his own wolf. Hide the renderers instead - that is what Skadi and
// the Aswid already do, and nothing resets it.
PlayerVisualHider.Hide(playerVisual, "fenrir-local-form");
Transform visual = prefab.transform.Find("Visual");
if (visual != null)
@ -409,11 +414,9 @@ namespace RacesOfValheim {
nview.GetZDO().Set("RacesOfValheim_FenrirForm", "");
}
if (playerVisual != null)
{
playerVisual.localScale = Vector3.one;
playerVisual.gameObject.SetActive(true);
}
// Show undoes the scale and the SetActive of the older hiding paths as well, so a form
// entered before this change still reverts cleanly.
PlayerVisualHider.Show(playerVisual, "fenrir-local-revert");
Player.m_localPlayer.GetSEMan().RemoveStatusEffect("SE_FenrirForm".GetStableHashCode());
Player.m_localPlayer.GetSEMan().RemoveStatusEffect("SE_CultistForm".GetStableHashCode());

View file

@ -257,7 +257,7 @@ namespace RacesOfValheim
if (state >= 3)
{
sb.AppendLine("[The Elder Unlock] Drake Form ('G' Key):");
sb.AppendLine("Take the shape of a frost drake. Right Mouse lifts you into flight: you glide wherever you aim, hold W to climb and gather speed, and release to hold level a moment before settling into a slow descent. In this shape you cannot yet strike.\n");
sb.AppendLine("Take the shape of a frost drake. Right Mouse lifts you into flight: you glide wherever you aim, hold W to climb and gather speed, hold Shift with it to spend stamina on a burst of speed, and press S to beat backwards along your aim while your gaze stays where it was. Release everything and you hold level for five seconds before settling into a slow descent. Water cannot hold you - your wings drag you free of the sea as readily as they lift you from the shore. In this shape you cannot yet strike.\n");
}
if (state >= 4)

View file

@ -34,6 +34,9 @@
<Reference Include="assembly_valheim">
<HintPath>..\..\..\..\..\..\Program Files (x86)\Steam\steamapps\common\Valheim\valheim_Data\Managed\assembly_valheim.dll</HintPath>
</Reference>
<!-- Jotunn 2.29.2 references a Unity module this build of Valheim no longer ships, and the
unresolvable reference warned on every build. Nothing here uses it. -->
<Reference Remove="UnityEngine.ProfilerModule" />
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Xml.Linq" />
@ -52,15 +55,40 @@
<ItemGroup>
<PackageReference Include="BepInEx.Core" Version="5.4.21" />
<PackageReference Include="JotunnLib" Version="2.29.2" />
<!-- net48 reference assemblies as a NuGet package, so the plain .NET SDK can build this
without a Visual Studio install supplying the targeting pack. Build-time only: it
contributes nothing to the shipped DLL. -->
<PackageReference Include="Microsoft.NETFramework.ReferenceAssemblies" Version="1.0.3" PrivateAssets="all" />
</ItemGroup>
<PropertyGroup>
<!-- Both of these came from machine-level environment variables, which a fresh clone (or a
fresh PC) does not have: VALHEIM_INSTALL expanded to nothing, so every path built from
it started at the drive root and the build died on the first Copy. Default them to the
standard Steam install, and leave the environment variables able to override for anyone
who keeps Valheim somewhere else. -->
<VALHEIM_INSTALL Condition="'$(VALHEIM_INSTALL)' == ''">C:\Program Files (x86)\Steam\steamapps\common\Valheim</VALHEIM_INSTALL>
<BEPINEX_PATH Condition="'$(BEPINEX_PATH)' == ''">$(VALHEIM_INSTALL)\BepInEx</BEPINEX_PATH>
<VALHEIM_MANAGED>$(VALHEIM_INSTALL)/valheim_Data/Managed</VALHEIM_MANAGED>
<!-- Jotunn publicizes the game assemblies into valheim_Data\Managed\publicized_assemblies and
then references them. It reads this flag out of DoPrebuild.props, which its Paths.props
imports through $(SolutionDir) - undefined on a plain `dotnet build` of this project, so
the flag never arrived, the publicizer never ran, and every build warned about ten
references it could not resolve. Run it exactly when its output is missing: once on a
fresh machine, never again, and -p:ExecutePrebuild=true still forces it after a game
update. -->
<ExecutePrebuild Condition="!Exists('$(VALHEIM_MANAGED)/publicized_assemblies/assembly_valheim_publicized.dll')">true</ExecutePrebuild>
<!-- The one place the built mod is deployed. -->
<PLUGINS_PATH>$(BEPINEX_PATH)\plugins</PLUGINS_PATH>
<!-- SolutionDir is only defined when msbuild is handed a .sln, so it expanded to
"*Undefined*" and broke the packaging target on a plain `dotnet build` of this
project. The repo root is always one level above the project. -->
<REPO_ROOT>$(ProjectDir)..\</REPO_ROOT>
<UNITY_FOLDER>$(REPO_ROOT)JotunnModStubUnity</UNITY_FOLDER>
<!-- The Unity stub project only matters when authoring assets in the editor, and its copy
step rewrites a folder full of game assemblies on every single build. Opt in with
-p:CopyAssembliesToUnity=true when you actually need it. -->
<CopyAssembliesToUnity Condition="'$(CopyAssembliesToUnity)' == ''">false</CopyAssembliesToUnity>
</PropertyGroup>
<Target Name="CopyToUnity">
@ -94,7 +122,15 @@
</Target>
<Target Name="JotunnPostBuildTask" AfterTargets="Build">
<CallTarget Targets="CopyToUnity" Condition="Exists('$(UNITY_FOLDER)')" />
<CallTarget Targets="CopyToUnity" Condition="'$(CopyAssembliesToUnity)' == 'true' And Exists('$(UNITY_FOLDER)')" />
</Target>
<!-- The mod's only deployment target: BepInEx\plugins. Runs for Debug as well as Release, so
the build-and-launch loop needs no second step. -->
<Target Name="DeployToValheim" AfterTargets="Build">
<Warning Text="BepInEx plugins folder not found at $(PLUGINS_PATH) - the DLL was built but not deployed." Condition="!Exists('$(PLUGINS_PATH)')" />
<Message Text="Deploying $(TargetName).dll to $(PLUGINS_PATH)" Importance="high" Condition="Exists('$(PLUGINS_PATH)')" />
<Copy SourceFiles="$(TargetDir)$(TargetName).dll" DestinationFolder="$(PLUGINS_PATH)\" Condition="Exists('$(PLUGINS_PATH)')" />
</Target>
<Target Name="PackageThunderstore" AfterTargets="Build" Condition="'$(Configuration)'=='Release'">
@ -102,13 +138,11 @@
<PackageOutputDir>$(REPO_ROOT)dist\</PackageOutputDir>
</PropertyGroup>
<MakeDir Directories="$(PackageOutputDir)" Condition="!Exists('$(PackageOutputDir)')" />
<Message Text="Packaging Thunderstore and Nexus Zips..." Importance="high" />
<Message Text="Packaging Thunderstore and Nexus zips into $(PackageOutputDir)" Importance="high" />
<!-- The version is read back out of manifest.json rather than duplicated here, so
manifest.json stays the single place a release is numbered. Written with string
concatenation because MSBuild would eat a PowerShell $(...) subexpression. -->
<Exec Command="powershell -NoProfile -Command &quot;$v = (Get-Content '$(ProjectDir)..\manifest.json' -Raw | ConvertFrom-Json).version_number; Compress-Archive -Path '$(TargetDir)$(TargetName).dll', '$(ProjectDir)..\manifest.json', '$(ProjectDir)..\README.md', '$(ProjectDir)Package\icon.png' -DestinationPath ('$(PackageOutputDir)RacesOfValheim_Thunderstore_' + $v + '.zip') -Force; Compress-Archive -Path '$(TargetDir)$(TargetName).dll' -DestinationPath ('$(PackageOutputDir)RacesOfValheim_Nexus_' + $v + '.zip') -Force&quot;" />
<Message Text="Copying DLL to Valheim BepInEx plugins..." Importance="high" Condition="Exists('$(VALHEIM_INSTALL)\BepInEx\plugins')" />
<Copy SourceFiles="$(TargetDir)$(TargetName).dll" DestinationFolder="$(VALHEIM_INSTALL)\BepInEx\plugins\" Condition="Exists('$(VALHEIM_INSTALL)\BepInEx\plugins')" />
</Target>

View file

@ -1,3 +1,4 @@
using System.Reflection;
using HarmonyLib;
using UnityEngine;
@ -244,32 +245,64 @@ namespace RacesOfValheim
// move direction. Character.UpdateFlying normally reads whatever m_moveDir the vanilla input
// pipeline last wrote (ground-plane WASD relative to camera yaw only); this patch overwrites
// it every frame with the camera's actual look direction (pitch included) so the player always
// glides toward wherever the mouse is aiming, with W adding a speed boost (m_run) on top of the
// base glide speed instead of being required just to move.
// glides toward wherever the mouse is aiming, with W powering forward, Shift spending stamina
// for a burst of speed, and S beating backwards away from whatever you are looking at.
[HarmonyPatch(typeof(Character), "UpdateFlying")]
public static class SkadiDirectedFlightPatch
{
private const float TURN_SPEED = 120f;
private const float GLIDE_SPEED = 5f;
private const float BOOST_SPEED = 12f;
private const float HOVER_SECONDS = 2f;
private const float SPRINT_SPEED = 22f;
private const float REVERSE_SPEED = 7f;
// Climbing out of water is deliberately slower than a powered climb in open air - the
// wings are dragging themselves free, not racing.
private const float LIFTOFF_SPEED = 9f;
private const float HOVER_SECONDS = 5f;
// Per second, drained only while the sprint is actually being granted.
private const float SPRINT_STAMINA_PER_SECOND = 15f;
// Tangent of the unpowered descent angle: 0.4 sinks at roughly 22 degrees below level.
private const float DESCENT_SLOPE = 0.4f;
// How much of the aim heading survives the climb out of water. Mostly up, with enough
// forward in it that the player still chooses which shore they surface towards.
private const float LIFTOFF_HEADING_BLEND = 0.35f;
public static void Prefix(Character __instance)
/// <summary>
/// True while the local player is beating backwards this frame. Read by
/// SkadiReverseFacingPatch, which keeps the body pointed at the camera while it happens.
/// </summary>
public static bool Reversing { get; private set; }
public static void Prefix(Character __instance, float dt)
{
if (__instance != Player.m_localPlayer) return;
DrakeFormBehavior form = DrakeFormBehavior.Active;
if (form == null || !form.IsFlying) return;
if (form == null || !form.IsFlying)
{
Reversing = false;
return;
}
var traverse = Traverse.Create(__instance);
Vector3 lookDir = Player.m_localPlayer.GetLookDir();
bool boost = RaceInput.Allowed && Input.GetKey(KeyCode.W);
bool input = RaceInput.Allowed;
bool forward = input && Input.GetKey(KeyCode.W);
// Forward wins a W+S mash rather than the two cancelling into a dead hover.
bool backward = input && !forward && Input.GetKey(KeyCode.S);
bool sprintKey = input && (Input.GetKey(KeyCode.LeftShift) || Input.GetKey(KeyCode.RightShift));
bool onGround = __instance.IsOnGround();
// IsSwimming is the exact test UpdateMotion uses to hand the frame to UpdateSwimming
// instead of UpdateFlying, so it is also the one condition SkadiWaterFlightPatch has
// to take back. Its half-second tail past leaving the water is welcome here - it
// keeps the climb going just long enough to clear the surface properly.
bool inWater = __instance.IsSwimming();
traverse.Field("m_run").SetValue(boost);
traverse.Field("m_flyFastSpeed").SetValue(BOOST_SPEED);
Reversing = backward;
// m_run only picks between the two fly speeds. Every mode now has its own speed, so
// leave it off and drive all of them through m_flySlowSpeed.
traverse.Field("m_run").SetValue(false);
// UpdateFlying rotates the body toward m_moveDir on its own, but at m_flyTurnSpeed,
// which sits at Character's 12 deg/s default because the Player prefab was never set
@ -277,38 +310,145 @@ namespace RacesOfValheim
// model reads as not turning at all. Give it a speed that suits a flying mount.
traverse.Field("m_flyTurnSpeed").SetValue(TURN_SPEED);
// Powered flight and ground contact both refresh the hover window.
if (boost || onGround) form.LastPoweredTime = Time.time;
// Powered flight, ground contact and clawing out of water all refresh the hover
// window, so none of them can be followed by an immediate sink.
if (forward || backward || onGround || inWater) form.LastPoweredTime = Time.time;
Vector3 moveDir = lookDir;
float coastSpeed;
float speed;
if (onGround || Time.time - form.LastPoweredTime < HOVER_SECONDS)
if (inWater)
{
// Wet wings still beat. Water used to be a trap: UpdateMotion hands a swimming
// character to UpdateSwimming before it ever looks at m_flying, so a dragon that
// touched the sea was stuck paddling with the flight controls doing nothing.
// SkadiWaterFlightPatch gives the frame back to flight, and this branch spends it
// climbing regardless of where the camera points, so the surface is always
// something you break out of rather than something you sit in.
moveDir = (Vector3.up + FlatHeading(__instance, lookDir) * LIFTOFF_HEADING_BLEND).normalized;
speed = LIFTOFF_SPEED;
}
else if (backward)
{
// Straight reverse thrust along the aim, pitch included: look down and beat back
// and you rise away from what you are looking at, which is the whole point of
// having a reverse - you can retreat without taking your eyes (or your breath
// attack, which fires along the same vector) off the target.
moveDir = -lookDir;
speed = REVERSE_SPEED;
}
else if (forward)
{
speed = BOOST_SPEED;
// The sprint is the only part of flight that costs anything. Base flight stays
// free on purpose - the drake arrives at the Elder, long before the player has
// the stamina pool to pay for simply staying airborne.
if (sprintKey && TrySpendSprintStamina(dt)) speed = SPRINT_SPEED;
}
else if (onGround || Time.time - form.LastPoweredTime < HOVER_SECONDS)
{
// Holding station: on the ground this keeps a touchdown from sliding the player
// forward forever, and in the air it gives the beat of level flight before the
// forward forever, and in the air it gives the beats of level flight before the
// form starts to sink. m_moveDir stays full length so the body still turns to
// face the camera, and zeroing the speed (rather than the rigidbody velocity)
// avoids fighting the AddForce UpdateFlying queues, which caused visible jitter.
coastSpeed = 0f;
speed = 0f;
}
else
{
// Unpowered flight is a glide, not a hover with a joystick: drift along the
// heading the camera faces while losing height, so aiming at the sky without
// holding W no longer climbs.
Vector3 heading = new Vector3(lookDir.x, 0f, lookDir.z);
if (heading.sqrMagnitude < 0.0001f)
{
heading = __instance.transform.forward;
heading.y = 0f;
}
moveDir = (heading.normalized + Vector3.down * DESCENT_SLOPE).normalized;
coastSpeed = GLIDE_SPEED;
moveDir = (FlatHeading(__instance, lookDir) + Vector3.down * DESCENT_SLOPE).normalized;
speed = GLIDE_SPEED;
}
traverse.Field("m_moveDir").SetValue(moveDir);
traverse.Field("m_flySlowSpeed").SetValue(coastSpeed);
traverse.Field("m_flySlowSpeed").SetValue(speed);
}
/// <summary>Aim flattened onto the ground plane, falling back to the body's own facing
/// when the player is looking straight up or down.</summary>
private static Vector3 FlatHeading(Character character, Vector3 lookDir)
{
Vector3 heading = new Vector3(lookDir.x, 0f, lookDir.z);
if (heading.sqrMagnitude < 0.0001f)
{
heading = character.transform.forward;
heading.y = 0f;
}
return heading.normalized;
}
/// <summary>
/// Charges this frame of sprint. Returns false when the player cannot pay, which drops
/// them back to the free boost speed rather than out of the sky.
/// </summary>
private static bool TrySpendSprintStamina(float dt)
{
Player player = Player.m_localPlayer;
if (player == null) return false;
float cost = SPRINT_STAMINA_PER_SECOND * dt;
if (!player.HaveStamina(cost)) return false;
player.UseStamina(cost);
return true;
}
}
/// <summary>
/// Character.UpdateMotion asks IsSwimming before it asks m_flying, so a flying dragon that
/// touched water was handed to UpdateSwimming every frame: the flight patch above never ran,
/// the form paddled on the surface, and there was no way back into the air short of finding
/// land. (The Aswid's bat escapes this because debug-fly is checked at the very top of
/// UpdateMotion, before water is considered at all - which is exactly why it can take off
/// from the sea.) Hand those frames back to UpdateFlying, which is the only motion path the
/// two methods contend over: nothing else calls either of them, and everything that merely
/// asks IsSwimming - the Wet status, the animator, stamina - is left alone.
/// </summary>
[HarmonyPatch(typeof(Character), "UpdateSwimming")]
public static class SkadiWaterFlightPatch
{
private static readonly MethodInfo UpdateFlyingMethod = AccessTools.Method(typeof(Character), "UpdateFlying");
public static bool Prefix(Character __instance, float dt)
{
if (__instance != Player.m_localPlayer) return true;
DrakeFormBehavior form = DrakeFormBehavior.Active;
if (form == null || !form.IsFlying) return true;
// Fail open: if a game update ever renames the method, swim normally rather than
// freezing the player in place with no motion update at all.
if (UpdateFlyingMethod == null) return true;
UpdateFlyingMethod.Invoke(__instance, new object[] { dt });
return false;
}
}
/// <summary>
/// UpdateFlying turns the body to face m_moveDir, which is right for every direction of
/// travel except backwards - reverse thrust would spin the dragon around to fly nose-first
/// away from the camera, putting its tail where its breath comes out. Claiming
/// AlwaysRotateCamera for the duration switches UpdateRotation over to the camera's yaw
/// instead, so the form keeps facing whatever it is retreating from. Scoped to the frames
/// the reverse is actually held.
/// </summary>
[HarmonyPatch(typeof(Player), "AlwaysRotateCamera")]
public static class SkadiReverseFacingPatch
{
public static bool Prefix(Player __instance, ref bool __result)
{
if (__instance != Player.m_localPlayer) return true;
if (!SkadiDirectedFlightPatch.Reversing) return true;
DrakeFormBehavior form = DrakeFormBehavior.Active;
if (form == null || !form.IsFlying) return true;
__result = true;
return false;
}
}

View file

@ -182,11 +182,14 @@ namespace RacesOfValheim
{
if (string.IsNullOrEmpty(currentForm))
{
playerVisual.localScale = Vector3.one;
PlayerVisualHider.Show(playerVisual, "fenrir-remote-revert");
}
else
{
playerVisual.localScale = Vector3.one * 0.001f;
// Same story as the local form: the scale trick this used to hide the body
// is undone every frame by the reset that keeps non-Trol players at normal
// size, so other players saw the man standing in his own wolf too.
PlayerVisualHider.Hide(playerVisual, "fenrir-remote-form");
GameObject prefab = Jotunn.Managers.PrefabManager.Cache.GetPrefab<GameObject>(currentForm);
if (prefab != null)
{

View file

@ -125,9 +125,12 @@ This mod currently introduces 8 custom races:
- **Fader**: Skeleton Dragon Form ('J' Key).
While transformed, Right Mouse toggles flight. You glide toward wherever you are aiming; hold W
to power forward and climb. Let go and the form holds level for a couple of seconds before
settling into a gentle descent. Timed forms show their remaining seconds, and their cooldown,
as a Moder trophy icon beside the minimap.
to power forward and climb, and add Shift to spend stamina on a burst of speed. S beats backwards
along your aim - look down and press it to rise away from whatever you are watching, without
turning to face away from it. Let go of everything and the form holds level for five seconds
before settling into a gentle descent. Water is no obstacle: a flying form beats its way back
out of the sea instead of being stuck paddling on the surface. Timed forms show their remaining
seconds, and their cooldown, as a Moder trophy icon beside the minimap.
### Skeleton Progression
- **Base (No Bosses)**: +50 Max Health. Undead Diet (Cannot eat mortal food, no stamina bar).

BIN
dist/icon.png vendored

Binary file not shown.

Before

Width:  |  Height:  |  Size: 72 KiB