Skip to content
This repository has been archived by the owner on Jan 13, 2023. It is now read-only.

Commit

Permalink
Fixes
Browse files Browse the repository at this point in the history
+ Fixed ChangingMoveState patch.
+ Removed OverwatchSkipFix.
  • Loading branch information
iopietro committed Dec 23, 2022
1 parent a592e80 commit 1ab7087
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 108 deletions.
10 changes: 5 additions & 5 deletions Exiled.Events/EventArgs/Player/ChangingMoveStateEventArgs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,11 @@ public ChangingMoveStateEventArgs(Player player, PlayerMovementState oldState, P
IsAllowed = isAllowed;
}

/// <summary>
/// Gets the player who's changing the movement state.
/// </summary>
public Player Player { get; }

/// <summary>
/// Gets the old state.
/// </summary>
Expand All @@ -53,10 +58,5 @@ public ChangingMoveStateEventArgs(Player player, PlayerMovementState oldState, P
/// Gets or sets a value indicating whether the player can change the movement state.
/// </summary>
public bool IsAllowed { get; set; }

/// <summary>
/// Gets the player who's changing the movement state.
/// </summary>
public Player Player { get; }
}
}
40 changes: 28 additions & 12 deletions Exiled.Events/Patches/Events/Player/ChangingMoveState.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
namespace Exiled.Events.Patches.Events.Player
{
using System.Collections.Generic;
using System.Reflection;
using System.Reflection.Emit;

using Exiled.Events.EventArgs.Player;
Expand All @@ -21,10 +22,10 @@ namespace Exiled.Events.Patches.Events.Player
using static HarmonyLib.AccessTools;

/// <summary>
/// Patches <see cref="FpcStateProcessor.UpdateMovementState(PlayerMovementState)" />.
/// Patches <see cref="FirstPersonMovementModule.SyncMovementState" /> setter.
/// Adds the <see cref="Player.ChangingMoveState" /> event.
/// </summary>
[HarmonyPatch(typeof(FpcStateProcessor), nameof(FpcStateProcessor.UpdateMovementState))]
[HarmonyPatch(typeof(FirstPersonMovementModule), nameof(FirstPersonMovementModule.SyncMovementState), MethodType.Setter)]
internal static class ChangingMoveState
{
private static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstruction> instructions, ILGenerator generator)
Expand All @@ -33,33 +34,48 @@ private static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstructi

LocalBuilder ev = generator.DeclareLocal(typeof(ChangingMoveStateEventArgs));

Label continueLabel = generator.DefineLabel();
Label returnLabel = generator.DefineLabel();

const int index = 0;

newInstructions[index].WithLabels(continueLabel);

newInstructions.InsertRange(
0,
index,
new CodeInstruction[]
{
// Player.Get(this._hub)
// Player.Get(this.Hub)
new(OpCodes.Ldarg_0),
new(OpCodes.Ldfld, Field(typeof(FpcStateProcessor), nameof(FpcStateProcessor._hub))),
new(OpCodes.Call, PropertyGetter(typeof(FirstPersonMovementModule), nameof(FirstPersonMovementModule.Hub))),
new(OpCodes.Call, Method(typeof(API.Features.Player), nameof(API.Features.Player.Get), new[] { typeof(ReferenceHub) })),
new(OpCodes.Dup),

// player.MoveState
new(OpCodes.Callvirt, PropertyGetter(typeof(API.Features.Player), nameof(API.Features.Player.MoveState))),
// oldState
new(OpCodes.Ldarg_0),
new(OpCodes.Call, PropertyGetter(typeof(FirstPersonMovementModule), nameof(FirstPersonMovementModule.SyncMovementState))),

// newState
// value
new(OpCodes.Ldarg_1),

// true
new(OpCodes.Ldc_I4_1),

// ChangingMoveStateEventArgs ev = new(Player, PlayerMovementState, PlayerMovementState, bool)
new(OpCodes.Newobj, GetDeclaredConstructors(typeof(ChangingMoveStateEventArgs))[0]),
new(OpCodes.Dup),
new(OpCodes.Dup),
new(OpCodes.Dup, ev.LocalIndex),
new(OpCodes.Stloc_S, ev.LocalIndex),

// if (ev.OldState == ev.NewState)
// goto continueLabel;
new(OpCodes.Callvirt, PropertyGetter(typeof(ChangingMoveStateEventArgs), nameof(ChangingMoveStateEventArgs.OldState))),
new(OpCodes.Ldloc_S, ev.LocalIndex),
new(OpCodes.Callvirt, PropertyGetter(typeof(ChangingMoveStateEventArgs), nameof(ChangingMoveStateEventArgs.NewState))),
new(OpCodes.Beq_S, continueLabel),

// load ev twice
new(OpCodes.Ldloc_S, ev.LocalIndex),
new(OpCodes.Dup),

// Player.OnChangingMoveState(ev)
new(OpCodes.Call, Method(typeof(Player), nameof(Player.OnChangingMoveState))),

Expand All @@ -68,7 +84,7 @@ private static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstructi
new(OpCodes.Callvirt, PropertyGetter(typeof(ChangingMoveStateEventArgs), nameof(ChangingMoveStateEventArgs.IsAllowed))),
new(OpCodes.Brfalse_S, returnLabel),

// newState = ev.NewState
// value = ev.NewState
new(OpCodes.Ldloc_S, ev.LocalIndex),
new(OpCodes.Call, PropertyGetter(typeof(ChangingMoveStateEventArgs), nameof(ChangingMoveStateEventArgs.NewState))),
new(OpCodes.Starg_S, 1),
Expand Down
91 changes: 0 additions & 91 deletions Exiled.Events/Patches/Fixes/OverwatchSkipFix.cs

This file was deleted.

0 comments on commit 1ab7087

Please sign in to comment.