mirror of
https://github.com/NotAKidoS/NAK_CVR_Mods.git
synced 2025-09-02 06:19:22 +00:00
[KeepVelocityOnExitFlight] Initial release
This commit is contained in:
parent
c099d0b841
commit
f052ec7c8d
5 changed files with 112 additions and 0 deletions
36
KeepVelocityOnExitFlight/Main.cs
Normal file
36
KeepVelocityOnExitFlight/Main.cs
Normal file
|
@ -0,0 +1,36 @@
|
|||
using System.Reflection;
|
||||
using ABI_RC.Core.Util.AnimatorManager;
|
||||
using ABI_RC.Systems.Movement;
|
||||
using ABI.CCK.Scripts;
|
||||
using HarmonyLib;
|
||||
using MelonLoader;
|
||||
using UnityEngine;
|
||||
|
||||
namespace NAK.KeepVelocityOnExitFlight;
|
||||
|
||||
public class KeepVelocityOnExitFlightMod : MelonMod
|
||||
{
|
||||
public override void OnInitializeMelon()
|
||||
{
|
||||
HarmonyInstance.Patch(
|
||||
typeof(BetterBetterCharacterController).GetMethod(nameof(BetterBetterCharacterController.ChangeFlight),
|
||||
BindingFlags.Public | BindingFlags.Instance),
|
||||
prefix: new HarmonyMethod(typeof(KeepVelocityOnExitFlightMod).GetMethod(nameof(Prefix_OnChangeFlight),
|
||||
BindingFlags.NonPublic | BindingFlags.Static)),
|
||||
postfix: new HarmonyMethod(typeof(KeepVelocityOnExitFlightMod).GetMethod(nameof(Postfix_OnChangeFlight),
|
||||
BindingFlags.NonPublic | BindingFlags.Static))
|
||||
);
|
||||
}
|
||||
|
||||
// ReSharper disable once RedundantAssignment
|
||||
private static void Prefix_OnChangeFlight(ref BetterBetterCharacterController __instance, ref Vector3 __state)
|
||||
{
|
||||
__state = __instance.GetVelocity();
|
||||
}
|
||||
|
||||
private static void Postfix_OnChangeFlight(ref BetterBetterCharacterController __instance, ref Vector3 __state)
|
||||
{
|
||||
if (__instance.FlightAllowedInWorld && !__instance.IsFlying())
|
||||
__instance.SetVelocity(__state);
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue