diff --git a/EXILED/Exiled.Events/EventArgs/Player/JumpingEventArgs.cs b/EXILED/Exiled.Events/EventArgs/Player/JumpingEventArgs.cs index 0a1c34b634..410897b531 100644 --- a/EXILED/Exiled.Events/EventArgs/Player/JumpingEventArgs.cs +++ b/EXILED/Exiled.Events/EventArgs/Player/JumpingEventArgs.cs @@ -57,7 +57,7 @@ public float Speed } /// - /// Gets or sets a value indicating whether the client data can be synchronized with the server. + /// Gets or sets a value indicating whether or not the player can jump. /// public bool IsAllowed { get; set; } } diff --git a/EXILED/Exiled.Events/Patches/Events/Item/ReceivingPreference.cs b/EXILED/Exiled.Events/Patches/Events/Item/ReceivingPreference.cs index 96b9907b3a..324c8cb6d4 100644 --- a/EXILED/Exiled.Events/Patches/Events/Item/ReceivingPreference.cs +++ b/EXILED/Exiled.Events/Patches/Events/Item/ReceivingPreference.cs @@ -40,10 +40,9 @@ private static IEnumerable Transpiler(IEnumerable newInstructions = ListPool.Pool.Get(instructions); int offset = 1; - int index = newInstructions.FindIndex(instruction => instruction.opcode == OpCodes.Ret) + offset; + int index = newInstructions.FindIndex(instruction => instruction.opcode == OpCodes.Stloc_2) + offset; LocalBuilder ev = generator.DeclareLocal(typeof(ReceivingPreferenceEventArgs)); - LocalBuilder curCode = generator.DeclareLocal(typeof(uint)); Label cdc = generator.DefineLabel(); Label ret = generator.DefineLabel(); @@ -54,14 +53,6 @@ private static IEnumerable Transpiler(IEnumerable), nameof(Dictionary.TryGetValue))), - new(OpCodes.Brfalse_S, cdc), - // API::Features::Player::Get(referenceHub) new(OpCodes.Ldloc_0), new(OpCodes.Call, Method(typeof(Player), nameof(Player.Get), new[] { typeof(ReferenceHub) })), @@ -70,12 +61,11 @@ private static IEnumerable Transpiler(IEnumerable Transpiler(IEnumerable Transpiler(IEnumerable i.opcode == OpCodes.Newobj && (ConstructorInfo)i.operand == GetDeclaredConstructors(typeof(LabApi.Events.Arguments.ServerEvents.CassieQueuingScpTerminationEventArgs))[0]) + offset; newInstructions.InsertRange( diff --git a/EXILED/Exiled.Events/Patches/Events/Player/ChangedRoom.cs b/EXILED/Exiled.Events/Patches/Events/Player/ChangedRoom.cs index 5a74d90b86..376587b14e 100644 --- a/EXILED/Exiled.Events/Patches/Events/Player/ChangedRoom.cs +++ b/EXILED/Exiled.Events/Patches/Events/Player/ChangedRoom.cs @@ -15,8 +15,8 @@ namespace Exiled.Events.Patches.Events.Player using Exiled.Events.EventArgs.Player; using Exiled.Events.Handlers; using HarmonyLib; - using LabApi.Events.Handlers; using MapGeneration; + using PlayerRoles; using UnityEngine; using static HarmonyLib.AccessTools; @@ -34,12 +34,17 @@ private static IEnumerable Transpiler(IEnumerable x == (object)Method(typeof(Object), "op_Inequality", new[] { typeof(Object), typeof(Object) })) + offset; + int index = newInstructions.FindIndex(x => x.Calls(Method(typeof(Object), "op_Inequality", new[] { typeof(Object), typeof(Object) }))) + offset; newInstructions[index].labels.Add(jump); newInstructions.InsertRange(index, new CodeInstruction[] { + // referenceHub + new(OpCodes.Ldarg_0), + new(OpCodes.Ldfld, Field(typeof(CurrentRoomPlayerCache), nameof(CurrentRoomPlayerCache._roleManager))), + new(OpCodes.Callvirt, PropertyGetter(typeof(PlayerRoleManager), nameof(PlayerRoleManager.Hub))), + // oldRoom new(OpCodes.Ldloc_2), diff --git a/EXILED/Exiled.Events/Patches/Events/Player/ChangingRadioPreset.cs b/EXILED/Exiled.Events/Patches/Events/Player/ChangingRadioPreset.cs index 4c4b27c4a3..ad77fa94ba 100644 --- a/EXILED/Exiled.Events/Patches/Events/Player/ChangingRadioPreset.cs +++ b/EXILED/Exiled.Events/Patches/Events/Player/ChangingRadioPreset.cs @@ -21,6 +21,8 @@ namespace Exiled.Events.Patches.Events.Player using InventorySystem.Items; using InventorySystem.Items.Radio; + using LabApi.Events.Arguments.PlayerEvents; + using static HarmonyLib.AccessTools; /// @@ -40,7 +42,7 @@ private static IEnumerable Transpiler(IEnumerable instruction.opcode == OpCodes.Newobj) + offset; + int index = newInstructions.FindIndex(instruction => instruction.operand == (object)Constructor(typeof(PlayerChangingRadioRangeEventArgs), new[] { typeof(ReferenceHub), typeof(RadioItem), typeof(RadioMessages.RadioRangeLevel) })) + offset; newInstructions.InsertRange( index, diff --git a/EXILED/Exiled.Events/Patches/Events/Player/Jumping.cs b/EXILED/Exiled.Events/Patches/Events/Player/Jumping.cs index c7840c950a..435bcb7eca 100644 --- a/EXILED/Exiled.Events/Patches/Events/Player/Jumping.cs +++ b/EXILED/Exiled.Events/Patches/Events/Player/Jumping.cs @@ -34,18 +34,41 @@ private static IEnumerable Transpiler(IEnumerable newInstructions = ListPool.Pool.Get(instructions); LocalBuilder ev = generator.DeclareLocal(typeof(JumpingEventArgs)); + LocalBuilder jumping = generator.DeclareLocal(typeof(bool)); - Label ret = generator.DefineLabel(); + Label cont = generator.DefineLabel(); + Label cancel = generator.DefineLabel(); - const int offset = 1; - int index = newInstructions.FindIndex(instruction => instruction.opcode == OpCodes.Stfld) + offset; + // fun fact, the "int num = ProcessJump() ? 1 : 0;" in target method doesn't actually store anything, the bool result from ProcessJump is simply kept on stack. + // our patch needs to know when player is jumping so we modify method to store that. + int offset = 1; + int index = newInstructions.FindIndex(instruction => instruction.Calls(Method(typeof(FpcJumpController), nameof(FpcJumpController.ProcessJump)))) + offset; + + // after ProcessJump, store its result + newInstructions.Insert(index, new CodeInstruction(OpCodes.Stloc, jumping)); + + // offset here is 0 + index = newInstructions.FindIndex(instruction => instruction.opcode == OpCodes.Brfalse_S); + + // make br_false use stored value + newInstructions.Insert(index, new CodeInstruction(OpCodes.Ldloc, jumping)); + + // The FindIndex finds when storing the field inside the moveDirection vector, so our patch occurs right before "this.MoveDirection = moveDirection;" + offset = 1; + index = newInstructions.FindIndex(instruction => instruction.opcode == OpCodes.Stfld) + offset; + + newInstructions[index].WithLabels(cont); newInstructions.InsertRange( index, new[] { + // if not jumping, skip Jumping event + new(OpCodes.Ldloc, jumping), + new(OpCodes.Brfalse, cont), + // Player.Get(this.Hub) - new CodeInstruction(OpCodes.Ldarg_0).MoveLabelsFrom(newInstructions[index]), + new(OpCodes.Ldarg_0), new(OpCodes.Ldfld, Field(typeof(FpcMotor), nameof(FpcMotor.Hub))), new(OpCodes.Call, Method(typeof(API.Features.Player), nameof(API.Features.Player.Get), new[] { typeof(ReferenceHub) })), @@ -59,7 +82,7 @@ private static IEnumerable Transpiler(IEnumerable Transpiler(IEnumerable