Skip to content
This repository was archived by the owner on Jan 19, 2025. It is now read-only.

Commit 00a919e

Browse files
committed
Stalk events fix & PlaceBulletHole decal fix
1 parent 0475412 commit 00a919e

File tree

5 files changed

+39
-69
lines changed

5 files changed

+39
-69
lines changed

Exiled.Events/EventArgs/Map/PlacingBulletHoleEventArgs.cs

+11-3
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,8 @@
88
namespace Exiled.Events.EventArgs.Map
99
{
1010
using API.Features;
11-
11+
using Exiled.API.Features.Items;
1212
using Interfaces;
13-
1413
using UnityEngine;
1514

1615
/// <summary>
@@ -27,11 +26,15 @@ public class PlacingBulletHoleEventArgs : IPlayerEvent, IDeniableEvent
2726
/// <param name="hit">
2827
/// <inheritdoc cref="RaycastHit" />
2928
/// </param>
30-
public PlacingBulletHoleEventArgs(Player owner, RaycastHit hit)
29+
/// <param name="firearm">
30+
/// <inheritdoc cref="Firearm" />
31+
/// </param>
32+
public PlacingBulletHoleEventArgs(Player owner, RaycastHit hit, InventorySystem.Items.Firearms.Firearm firearm)
3133
{
3234
Player = owner;
3335
Position = hit.point;
3436
Rotation = Quaternion.LookRotation(hit.normal);
37+
Firearm = Item.Get(firearm).As<Firearm>();
3538
}
3639

3740
/// <summary>
@@ -53,5 +56,10 @@ public PlacingBulletHoleEventArgs(Player owner, RaycastHit hit)
5356
/// Gets the decal owner.
5457
/// </summary>
5558
public Player Player { get; }
59+
60+
/// <summary>
61+
/// Gets the firearm that triggered the event.
62+
/// </summary>
63+
public Firearm Firearm { get; }
5664
}
5765
}

Exiled.Events/Patches/Events/Map/ExplodingFragGrenade.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ namespace Exiled.Events.Patches.Events.Map
2626
using static HarmonyLib.AccessTools;
2727

2828
/// <summary>
29-
/// Patches <see cref="ExplosionGrenade.Explode(Footprint, Vector3, ExplosionGrenade)"/>.
29+
/// Patches <see cref="ExplosionGrenade.Explode(Footprint, Vector3, ExplosionGrenade, ExplosionType)"/>.
3030
/// Adds the <see cref="Handlers.Map.ExplodingGrenade"/> event.
3131
/// </summary>
3232
[EventPatch(typeof(Handlers.Map), nameof(Handlers.Map.ExplodingGrenade))]

Exiled.Events/Patches/Events/Map/PlacingBulletHole.cs

+10-9
Original file line numberDiff line numberDiff line change
@@ -11,28 +11,24 @@ namespace Exiled.Events.Patches.Events.Map
1111
using System.Reflection.Emit;
1212

1313
using API.Features.Core.Generic.Pools;
14-
1514
using Exiled.Events.Attributes;
1615
using Exiled.Events.EventArgs.Map;
17-
1816
using Handlers;
19-
2017
using HarmonyLib;
21-
18+
using InventorySystem.Items.Firearms;
2219
using InventorySystem.Items.Firearms.Modules;
23-
2420
using UnityEngine;
2521

2622
using static HarmonyLib.AccessTools;
2723

2824
using Player = API.Features.Player;
2925

3026
/// <summary>
31-
/// Patches <see cref="StandardHitregBase.PlaceBulletholeDecal" />.
27+
/// Patches <see cref="ImpactEffectsModule.ServerSendImpactDecal" />.
3228
/// Adds the <see cref="Map.PlacingBulletHole" /> event.
3329
/// </summary>
3430
[EventPatch(typeof(Map), nameof(Map.PlacingBulletHole))]
35-
[HarmonyPatch(typeof(StandardHitregBase), nameof(StandardHitregBase.PlaceBulletholeDecal))]
31+
[HarmonyPatch(typeof(ImpactEffectsModule), nameof(ImpactEffectsModule.ServerSendImpactDecal))]
3632
internal static class PlacingBulletHole
3733
{
3834
private static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstruction> instructions, ILGenerator generator)
@@ -50,11 +46,16 @@ private static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstructi
5046
{
5147
// Player.Get(this.Hub)
5248
new(OpCodes.Ldarg_0),
53-
new(OpCodes.Callvirt, PropertyGetter(typeof(SingleBulletHitreg), nameof(SingleBulletHitreg.Hub))),
49+
new(OpCodes.Callvirt, PropertyGetter(typeof(ImpactEffectsModule), nameof(ImpactEffectsModule.Firearm))),
50+
new(OpCodes.Callvirt, PropertyGetter(typeof(Firearm), nameof(Firearm.Owner))),
5451
new(OpCodes.Call, Method(typeof(Player), nameof(Player.Get), new[] { typeof(ReferenceHub) })),
5552

5653
// hit
57-
new(OpCodes.Ldarg_2),
54+
new(OpCodes.Ldarg_1),
55+
56+
// this.Firearm
57+
new(OpCodes.Ldarg_0),
58+
new(OpCodes.Callvirt, PropertyGetter(typeof(ImpactEffectsModule), nameof(ImpactEffectsModule.Firearm))),
5859

5960
// PlacingBulletHole ev = new(Player, RaycastHit)
6061
new(OpCodes.Newobj, GetDeclaredConstructors(typeof(PlacingBulletHoleEventArgs))[0]),

Exiled.Events/Patches/Events/Scp106/ExitStalking.cs

+10-19
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,11 @@ namespace Exiled.Events.Patches.Events.Scp106
2121
using static HarmonyLib.AccessTools;
2222

2323
/// <summary>
24-
/// Patches <see cref="Scp106StalkAbility.ServerProcessCmd"/>.
24+
/// Patches <see cref="Scp106StalkAbility.UpdateServerside"/>.
2525
/// To add the <see cref="Handlers.Scp106.ExitStalking"/> event.
2626
/// </summary>
2727
[EventPatch(typeof(Handlers.Scp106), nameof(Handlers.Scp106.ExitStalking))]
28-
[HarmonyPatch(typeof(Scp106StalkAbility), nameof(Scp106StalkAbility.IsActive), MethodType.Setter)]
28+
[HarmonyPatch(typeof(Scp106StalkAbility), nameof(Scp106StalkAbility.UpdateServerside))]
2929
public class ExitStalking
3030
{
3131
private static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstruction> instructions, ILGenerator generator)
@@ -34,22 +34,17 @@ private static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstructi
3434

3535
LocalBuilder ev = generator.DeclareLocal(typeof(ExitStalkingEventArgs));
3636

37-
Label continueLabel = generator.DefineLabel();
3837
Label returnLabel = generator.DefineLabel();
39-
int offset = -3;
40-
int index = newInstructions.FindIndex(instruction => instruction.opcode == OpCodes.Newobj) + offset;
38+
39+
const int offset = -2;
40+
int index = newInstructions.FindIndex(instruction => instruction.OperandIs(Method(typeof(Scp106StalkAbility), nameof(Scp106StalkAbility.ServerSetStalk), new[] { typeof(bool) }))) + offset;
4141
newInstructions.InsertRange(
4242
index,
43-
new CodeInstruction[]
43+
new[]
4444
{
45-
// if (value is false) continue;
46-
new CodeInstruction(OpCodes.Ldarg_1).MoveLabelsFrom(newInstructions[index]),
47-
new(OpCodes.Ldc_I4_0),
48-
new(OpCodes.Beq_S, continueLabel),
49-
5045
// Player.Get(this.Owner);
51-
new(OpCodes.Ldarg_0),
52-
new(OpCodes.Callvirt, PropertyGetter(typeof(Scp106HuntersAtlasAbility), nameof(Scp106HuntersAtlasAbility.Owner))),
46+
new CodeInstruction(OpCodes.Ldarg_0).MoveLabelsFrom(newInstructions[index]),
47+
new(OpCodes.Callvirt, PropertyGetter(typeof(Scp106StalkAbility), nameof(Scp106StalkAbility.Owner))),
5348
new(OpCodes.Call, Method(typeof(Player), nameof(Player.Get), new[] { typeof(ReferenceHub) })),
5449

5550
// true
@@ -70,14 +65,10 @@ private static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstructi
7065
new(OpCodes.Brfalse_S, returnLabel),
7166
});
7267

73-
offset = -3;
74-
index = newInstructions.FindIndex(instruction => instruction.opcode == OpCodes.Newobj) + offset;
75-
newInstructions[index].labels.Add(continueLabel);
76-
7768
newInstructions[newInstructions.Count - 1].labels.Add(returnLabel);
7869

79-
for (int z = 0; z < newInstructions.Count; z++)
80-
yield return newInstructions[z];
70+
foreach (CodeInstruction instruction in newInstructions)
71+
yield return instruction;
8172

8273
ListPool<CodeInstruction>.Pool.Return(newInstructions);
8374
}

Exiled.Events/Patches/Events/Scp106/Stalking.cs

+7-37
Original file line numberDiff line numberDiff line change
@@ -35,15 +35,15 @@ private static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstructi
3535
LocalBuilder ev = generator.DeclareLocal(typeof(StalkingEventArgs));
3636

3737
Label returnLabel = generator.DefineLabel();
38-
int offset = 2;
39-
int index = newInstructions.FindIndex(instruction => instruction.operand == (object)PropertyGetter(typeof(Scp106StalkAbility), nameof(Scp106StalkAbility.IsActive))) + offset;
38+
const int offset = -1;
39+
int index = newInstructions.FindIndex(instruction => instruction.Calls(PropertyGetter(typeof(Scp106VigorAbilityBase), nameof(Scp106VigorAbilityBase.VigorAmount)))) + offset;
4040
newInstructions.InsertRange(
4141
index,
42-
new CodeInstruction[]
42+
new[]
4343
{
4444
// Player.Get(this.Owner);
4545
new CodeInstruction(OpCodes.Ldarg_0).MoveLabelsFrom(newInstructions[index]),
46-
new(OpCodes.Callvirt, PropertyGetter(typeof(Scp106HuntersAtlasAbility), nameof(Scp106HuntersAtlasAbility.Owner))),
46+
new(OpCodes.Callvirt, PropertyGetter(typeof(Scp106StalkAbility), nameof(Scp106StalkAbility.Owner))),
4747
new(OpCodes.Call, Method(typeof(Player), nameof(Player.Get), new[] { typeof(ReferenceHub) })),
4848

4949
// true
@@ -64,38 +64,8 @@ private static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstructi
6464
new(OpCodes.Brfalse_S, returnLabel),
6565
});
6666

67-
offset = 2;
68-
index = newInstructions.FindIndex(instruction => instruction.operand == (object)PropertySetter(typeof(Scp106StalkAbility), nameof(Scp106StalkAbility.IsActive))) + offset;
69-
newInstructions.InsertRange(
70-
index,
71-
new CodeInstruction[]
72-
{
73-
// Player.Get(this.Owner);
74-
new CodeInstruction(OpCodes.Ldarg_0).MoveLabelsFrom(newInstructions[index]),
75-
new(OpCodes.Callvirt, PropertyGetter(typeof(Scp106HuntersAtlasAbility), nameof(Scp106HuntersAtlasAbility.Owner))),
76-
new(OpCodes.Call, Method(typeof(Player), nameof(Player.Get), new[] { typeof(ReferenceHub) })),
77-
78-
// true
79-
new(OpCodes.Ldc_I4_1),
80-
81-
// StalkingEventArgs ev = new(Player, isAllowed)
82-
new(OpCodes.Newobj, GetDeclaredConstructors(typeof(StalkingEventArgs))[0]),
83-
new(OpCodes.Dup),
84-
new(OpCodes.Dup),
85-
new(OpCodes.Stloc_S, ev.LocalIndex),
86-
87-
// Handlers.Scp106.OnStalking(ev)
88-
new(OpCodes.Call, Method(typeof(Handlers.Scp106), nameof(Handlers.Scp106.OnStalking))),
89-
90-
// if (!ev.IsAllowed)
91-
// return;
92-
new(OpCodes.Callvirt, PropertyGetter(typeof(StalkingEventArgs), nameof(StalkingEventArgs.IsAllowed))),
93-
new(OpCodes.Brfalse_S, returnLabel),
94-
});
95-
9667
// replace "base.Vigor.VigorAmount < 0.25f" with "base.Vigor.VigorAmount < ev.MinimumVigor"
97-
offset = 0;
98-
index = newInstructions.FindIndex(instruction => instruction.opcode == OpCodes.Ldc_R4) + offset;
68+
index = newInstructions.FindIndex(instruction => instruction.opcode == OpCodes.Ldc_R4);
9969
newInstructions.RemoveAt(index);
10070

10171
newInstructions.InsertRange(
@@ -109,8 +79,8 @@ private static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstructi
10979

11080
newInstructions[newInstructions.Count - 1].WithLabels(returnLabel);
11181

112-
for (int z = 0; z < newInstructions.Count; z++)
113-
yield return newInstructions[z];
82+
foreach (CodeInstruction instruction in newInstructions)
83+
yield return instruction;
11484

11585
ListPool<CodeInstruction>.Pool.Return(newInstructions);
11686
}

0 commit comments

Comments
 (0)