Skip to content

Commit 30b607b

Browse files
authored
fix: Fix 3114 Dancing + minor docs fix (#601)
Fix 3114 Dancing + minor docs fix
1 parent 597cef6 commit 30b607b

2 files changed

Lines changed: 12 additions & 38 deletions

File tree

EXILED/Exiled.API/Features/Player.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -608,7 +608,7 @@ public ScpSpawnPreferences.SpawnPreferences ScpPreferences
608608
public bool HasFlashlightModuleEnabled => CurrentItem is Firearm firearm && firearm.FlashlightEnabled;
609609

610610
/// <summary>
611-
/// Gets a value indicating whether the player is jumping.
611+
/// Gets or sets a value indicating whether the player is jumping.
612612
/// </summary>
613613
public bool IsJumping
614614
{

EXILED/Exiled.Events/Patches/Events/Scp3114/Dancing.cs

Lines changed: 11 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,6 @@
77

88
namespace Exiled.Events.Patches.Events.Scp3114
99
{
10-
#pragma warning disable SA1402 // File may only contain a single type
11-
1210
using System.Collections.Generic;
1311
using System.Linq;
1412
using System.Reflection.Emit;
@@ -35,7 +33,7 @@ private static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstructi
3533
{
3634
List<CodeInstruction> newInstructions = ListPool<CodeInstruction>.Pool.Get(instructions);
3735

38-
int index = newInstructions.FindIndex(x => x.opcode == OpCodes.Brfalse_S);
36+
int index = newInstructions.FindIndex(x => x.opcode == OpCodes.Brfalse);
3937

4038
Label continueLabel = generator.DefineLabel();
4139

@@ -58,64 +56,40 @@ private static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstructi
5856
new(OpCodes.Newobj, GetDeclaredConstructors(typeof(DancingEventArgs))[0]),
5957
new(OpCodes.Dup),
6058
new(OpCodes.Dup),
61-
new(OpCodes.Stloc_S, ev.LocalIndex),
59+
new(OpCodes.Stloc, ev),
6260

6361
// Handlers.Scp3114.OnDancing(ev);
6462
new(OpCodes.Call, Method(typeof(Handlers.Scp3114), nameof(Handlers.Scp3114.OnDancing))),
6563

6664
// if (ev.IsAllowed)
6765
// goto continueLabel;
6866
new(OpCodes.Callvirt, PropertyGetter(typeof(DancingEventArgs), nameof(DancingEventArgs.IsAllowed))),
69-
new(OpCodes.Brtrue_S, continueLabel),
67+
new(OpCodes.Brtrue, continueLabel),
7068

7169
// return
7270
new(OpCodes.Ret),
7371

7472
// ev.NewState
75-
new CodeInstruction(OpCodes.Ldloc_S, ev.LocalIndex).WithLabels(continueLabel),
73+
new CodeInstruction(OpCodes.Ldloc, ev).WithLabels(continueLabel),
7674
new(OpCodes.Callvirt, PropertyGetter(typeof(DancingEventArgs), nameof(DancingEventArgs.IsDancing))),
7775
});
7876

79-
for (int z = 0; z < newInstructions.Count; z++)
80-
yield return newInstructions[z];
77+
index = newInstructions.FindIndex(x => x.opcode == OpCodes.Ldc_I4_0);
8178

82-
ListPool<CodeInstruction>.Pool.Return(newInstructions);
83-
}
84-
}
79+
newInstructions.RemoveRange(index, 3);
8580

86-
/// <summary>
87-
/// Patches <see cref="Scp3114Dance.ServerProcessCmd"/>
88-
/// to add <see cref="Handlers.Scp3114.Dancing"/> event.
89-
/// </summary>
90-
[HarmonyPatch(typeof(Scp3114Dance), nameof(Scp3114Dance.ServerWriteRpc))]
91-
internal class ChooseDanceType
92-
{
93-
private static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstruction> instructions, ILGenerator generator)
94-
{
95-
List<CodeInstruction> newInstructions = ListPool<CodeInstruction>.Pool.Get(instructions);
96-
97-
int offset = -4;
98-
int index = newInstructions.FindIndex(x => x.operand == (object)Method(typeof(NetworkWriter), nameof(NetworkWriter.WriteByte))) + offset;
99-
100-
newInstructions.RemoveRange(index, 4);
101-
102-
// replace "writer.WriteByte((byte)UnityEngine.Random.Range(0, 255))"
103-
// with "writer.WriteByte(ChooseDanceType.DanceType)"
104-
newInstructions.InsertRange(index, new CodeInstruction[]
81+
newInstructions.InsertRange(
82+
index,
83+
new[]
10584
{
106-
// Handle(Player.Get(this.Owner));
107-
new(OpCodes.Ldarg_0),
108-
109-
new(OpCodes.Call, Method(typeof(ChooseDanceType), nameof(Handle))),
85+
new CodeInstruction(OpCodes.Ldloc, ev),
86+
new(OpCodes.Call, PropertyGetter(typeof(DancingEventArgs), nameof(DancingEventArgs.DanceType))),
11087
});
11188

11289
for (int z = 0; z < newInstructions.Count; z++)
11390
yield return newInstructions[z];
11491

11592
ListPool<CodeInstruction>.Pool.Return(newInstructions);
11693
}
117-
118-
private static byte Handle(Scp3114Dance scp3114Dance)
119-
=> (byte)Player.Get(scp3114Dance.Owner).Role.As<API.Features.Roles.Scp3114Role>().DanceType;
12094
}
12195
}

0 commit comments

Comments
 (0)