Skip to content

Commit 841a5ce

Browse files
committed
Fixed Error & InteractingScp330 IL Code
1 parent 586d1f0 commit 841a5ce

File tree

12 files changed

+72
-143
lines changed

12 files changed

+72
-143
lines changed

EXILED/Exiled.API/Features/Lockers/Chamber.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -245,6 +245,6 @@ public Vector3 GetRandomSpawnPoint()
245245
/// </summary>
246246
/// <param name="chamber"><see cref="LockerChamber"/>.</param>
247247
/// <returns><see cref="Chamber"/>.</returns>
248-
internal static Chamber Get(LockerChamber chamber) => Chambers.TryGetValue(chamber, out Chamber chmb) ? chmb : new(chamber, Locker.Get(x => x.Chambers.Any(x => x.Base == chamber)).FirstOrDefault());
248+
internal static Chamber Get(LockerChamber chamber) => chamber == null ? null : Chambers.TryGetValue(chamber, out Chamber chmb) ? chmb : new(chamber, Locker.Get(x => x.Chambers.Any(x => x.Base == chamber)).FirstOrDefault());
249249
}
250250
}

EXILED/Exiled.API/Features/Pickups/ExplosiveGrenadePickup.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,8 +96,8 @@ protected override void InitializeProperties(ItemBase itemBase)
9696
base.InitializeProperties(itemBase);
9797
if (itemBase is ThrowableItem throwable && throwable.Projectile is ExplosionGrenade explosiveGrenade)
9898
{
99-
MaxRadius = explosiveGrenade._maxRadius;
100-
ScpDamageMultiplier = explosiveGrenade._scpDamageMultiplier;
99+
MaxRadius = explosiveGrenade.MaxRadius;
100+
ScpDamageMultiplier = explosiveGrenade.ScpDamageMultiplier;
101101
BurnDuration = explosiveGrenade._burnedDuration;
102102
DeafenDuration = explosiveGrenade._deafenedDuration;
103103
ConcussDuration = explosiveGrenade._concussedDuration;

EXILED/Exiled.API/Features/Pickups/Projectiles/ExplosionGrenadeProjectile.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,8 @@ internal ExplosionGrenadeProjectile(ItemType type)
4949
/// </summary>
5050
public float MaxRadius
5151
{
52-
get => Base._maxRadius;
53-
set => Base._maxRadius = value;
52+
get => Base.MaxRadius;
53+
set => Base.MaxRadius = value;
5454
}
5555

5656
/// <summary>
@@ -94,8 +94,8 @@ public float ConcussDuration
9494
/// </summary>
9595
public float ScpDamageMultiplier
9696
{
97-
get => Base._scpDamageMultiplier;
98-
set => Base._scpDamageMultiplier = value;
97+
get => Base.ScpDamageMultiplier;
98+
set => Base.ScpDamageMultiplier = value;
9999
}
100100

101101
/// <summary>

EXILED/Exiled.API/Features/Roles/Scp079Role.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -593,7 +593,7 @@ public void ActivateTesla(bool consumeEnergy = true)
593593
Scp079Camera cam = CurrentCameraSync.CurrentCamera;
594594
RewardManager.MarkRoom(cam.Room);
595595

596-
if (!global::TeslaGate.AllGates.TryGetFirst(x => RoomIdUtils.IsTheSameRoom(cam.Position, x.transform.position), out global::TeslaGate teslaGate))
596+
if (!global::TeslaGate.AllGates.TryGetFirst(x => RoomUtils.IsTheSameRoom(cam.Position, x.transform.position), out global::TeslaGate teslaGate))
597597
return;
598598

599599
if (consumeEnergy)

EXILED/Exiled.API/Features/Room.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -246,7 +246,7 @@ public static Room Get(RoomIdentifier roomIdentifier) => roomIdentifier == null
246246
/// </summary>
247247
/// <param name="position">The <see cref="Vector3"/> to search for.</param>
248248
/// <returns>The <see cref="Room"/> with the given <see cref="Vector3"/> or <see langword="null"/> if not found.</returns>
249-
public static Room Get(Vector3 position) => RoomIdUtils.RoomAtPositionRaycasts(position, false) is RoomIdentifier identifier ? Get(identifier) : null;
249+
public static Room Get(Vector3 position) => RoomUtils.RoomAtPositionRaycasts(position, false) is RoomIdentifier identifier ? Get(identifier) : null;
250250

251251
/// <summary>
252252
/// Gets a <see cref="Room"/> given the specified <see cref="RelativePosition"/>.

EXILED/Exiled.Events/EventArgs/Map/FillingLockerEventArgs.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ public FillingLockerEventArgs(ItemPickupBase pickupBase, LockerChamber lockerCha
4141
/// <summary>
4242
/// Gets a locker which is containing <see cref="Chamber"/>.
4343
/// </summary>
44-
public API.Features.Lockers.Locker Locker => Chamber.Locker;
44+
public API.Features.Lockers.Locker Locker => Chamber?.Locker;
4545

4646
/// <summary>
4747
/// Gets a chamber which is filling.

EXILED/Exiled.Events/EventArgs/Scp330/InteractingScp330EventArgs.cs

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -21,31 +21,29 @@ public class InteractingScp330EventArgs : IPlayerEvent, IScp330Event, IDeniableE
2121
/// <summary>
2222
/// Initializes a new instance of the <see cref="InteractingScp330EventArgs" /> class.
2323
/// </summary>
24-
/// <param name="player">
24+
/// <param name="referenceHub">
2525
/// <inheritdoc cref="Player" />
2626
/// </param>
2727
/// <param name="usage">
2828
/// <inheritdoc cref="UsageCount" />
2929
/// </param>
30-
public InteractingScp330EventArgs(Player player, int usage)
30+
/// <param name="shouldPlaySound">
31+
/// <inheritdoc cref="ShouldPlaySound" />
32+
/// </param>
33+
/// <param name="shouldSever">
34+
/// <inheritdoc cref="ShouldSever" />
35+
/// </param>
36+
/// <param name="candy">
37+
/// <inheritdoc cref="Candy" />
38+
/// </param>
39+
public InteractingScp330EventArgs(ReferenceHub referenceHub, int usage, bool shouldPlaySound, bool shouldSever, CandyKindID candy)
3140
{
32-
Player = player;
41+
Player = Player.Get(referenceHub);
3342
UsageCount = usage;
3443
ShouldSever = usage >= 2;
35-
ShouldPlaySound = true;
44+
ShouldPlaySound = shouldPlaySound;
3645
IsAllowed = Player.IsHuman;
3746
Candy = Scp330Candies.GetRandom();
38-
39-
if (Scp330Bag.TryGetBag(player.ReferenceHub, out Scp330Bag scp330Bag))
40-
{
41-
Scp330 = (Scp330)Item.Get(scp330Bag);
42-
}
43-
else
44-
{
45-
Scp330 = (Scp330)Item.Create(ItemType.SCP330, player);
46-
Scp330.RemoveAllCandy();
47-
player.AddItem(Scp330);
48-
}
4947
}
5048

5149
/// <summary>

EXILED/Exiled.Events/Patches/Events/Map/ExplodingFlashGrenade.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ private static void ProcessEvent(FlashbangGrenade instance, float distance)
7373
continue;
7474
if (!IndividualFriendlyFire.CheckFriendlyFirePlayer(instance.PreviousOwner, player.ReferenceHub) && !instance.PreviousOwner.CompareLife(player.ReferenceHub))
7575
continue;
76-
if (Physics.Linecast(instance.transform.position, player.CameraTransform.position, instance._blindingMask))
76+
if (Physics.Linecast(instance.transform.position, player.CameraTransform.position, instance.BlindingMask))
7777
continue;
7878

7979
targetToAffect.Add(player);

EXILED/Exiled.Events/Patches/Events/Scp0492/Consumed.cs

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -38,35 +38,32 @@ private static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstructi
3838

3939
LocalBuilder ev = generator.DeclareLocal(typeof(ConsumedCorpseEventArgs));
4040

41-
int offset = 1;
42-
int index = newInstructions.FindIndex(instruction => instruction.opcode == OpCodes.Ret) + offset;
43-
4441
Label returnLabel = generator.DefineLabel();
4542

4643
newInstructions.InsertRange(
47-
index,
44+
0,
4845
new[]
4946
{
50-
// Player.Get(base.Owner)
51-
new CodeInstruction(OpCodes.Ldarg_0).MoveLabelsFrom(newInstructions[index]),
47+
// base.Owner
48+
new CodeInstruction(OpCodes.Ldarg_0),
5249
new(OpCodes.Call, PropertyGetter(typeof(StandardSubroutine<ZombieRole>), nameof(StandardSubroutine<ZombieRole>.Owner))),
5350

5451
// base.CurRagdoll
5552
new CodeInstruction(OpCodes.Ldarg_0),
5653
new(OpCodes.Call, PropertyGetter(typeof(RagdollAbilityBase<ZombieRole>), nameof(RagdollAbilityBase<ZombieRole>.CurRagdoll))),
5754

58-
// ConsumingCorpseEventArgs ev = new(Player, Ragdoll, bool)
55+
// ConsumingCorpseEventArgs ev = new(ReferenceHub, Ragdoll, bool)
5956
new(OpCodes.Newobj, GetDeclaredConstructors(typeof(ConsumedCorpseEventArgs))[0]),
6057
new(OpCodes.Dup),
6158
new(OpCodes.Stloc_S, ev.LocalIndex),
6259

63-
// Handlers.Scp049.OnSendingCall(ev)
60+
// Handlers.Scp049.OnConsumedCorpse(ev)
6461
new(OpCodes.Call, Method(typeof(Handlers.Scp0492), nameof(Handlers.Scp0492.OnConsumedCorpse))),
6562
});
6663

67-
// replace "base.Owner.playerStats.GetModule<HealthStat>().ServerHeal(100f)" with "base.Owner.playerStats.GetModule<HealthStat>().ServerHeal(ev.ConsumeHeal)"
68-
offset = -1;
69-
index = newInstructions.FindIndex(instruction => instruction.operand == (object)Method(typeof(HealthStat), nameof(HealthStat.ServerHeal))) + offset;
64+
// replace "Scp0492ConsumingCorpseEventArgs(base.Owner, base.CurRagdoll, 100f);" with "Scp0492ConsumingCorpseEventArgs(base.Owner, base.CurRagdoll, ev.ConsumeHeal);"
65+
int offset = -1;
66+
int index = newInstructions.FindIndex(x => x.opcode == OpCodes.Ldc_R4 && (float)x.operand == ZombieConsumeAbility.ConsumeHeal) + offset;
7067
newInstructions.RemoveAt(index);
7168

7269
newInstructions.InsertRange(

EXILED/Exiled.Events/Patches/Events/Scp330/InteractingScp330.cs

Lines changed: 30 additions & 101 deletions
Original file line numberDiff line numberDiff line change
@@ -46,105 +46,57 @@ private static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstructi
4646
// Remove original "No scp can touch" logic.
4747
newInstructions.RemoveRange(0, 3);
4848

49-
// Find ServerProcessPickup, insert before it.
50-
int offset = -3;
49+
int offset = 2;
5150
int index = newInstructions.FindLastIndex(
52-
instruction => instruction.Calls(Method(typeof(Scp330Bag), nameof(Scp330Bag.ServerProcessPickup)))) + offset;
51+
instruction => instruction.Calls(Method(typeof(Scp330Candies), nameof(Scp330Candies.GetRandom)))) + offset;
5352

5453
newInstructions.InsertRange(
5554
index,
5655
new[]
5756
{
58-
// Player.Get(ply)
59-
new CodeInstruction(OpCodes.Ldarg_1).MoveLabelsFrom(newInstructions[index]),
60-
new(OpCodes.Call, Method(typeof(Player), nameof(Player.Get), new[] { typeof(ReferenceHub) })),
57+
// ply
58+
new CodeInstruction(OpCodes.Ldarg_1),
6159

62-
// num2
60+
// usage
6361
new(OpCodes.Ldloc_1),
6462

65-
// InteractingScp330EventArgs ev = new(Player, int)
63+
// shouldPlaySound
64+
new(OpCodes.Ldloc_2),
65+
66+
// shouldSever
67+
new(OpCodes.Ldloc_3),
68+
69+
// candyKindID
70+
new(OpCodes.Ldloc_S, 4),
71+
72+
// InteractingScp330EventArgs ev = new(ReferenceHub, int, bool, bool, CandyKindID)
6673
new(OpCodes.Newobj, GetDeclaredConstructors(typeof(InteractingScp330EventArgs))[0]),
6774
new(OpCodes.Dup),
6875
new(OpCodes.Dup),
6976
new(OpCodes.Stloc, ev.LocalIndex),
7077

7178
// Scp330.OnInteractingScp330(ev)
7279
new(OpCodes.Call, Method(typeof(Handlers.Scp330), nameof(Handlers.Scp330.OnInteractingScp330))),
80+
new(OpCodes.Dup),
81+
new(OpCodes.Dup),
82+
new(OpCodes.Dup),
7383

74-
// if (!ev.IsAllowed)
75-
// return;
76-
new(OpCodes.Callvirt, PropertyGetter(typeof(InteractingScp330EventArgs), nameof(InteractingScp330EventArgs.IsAllowed))),
77-
new(OpCodes.Brfalse, returnLabel),
78-
79-
// ldarg.1 to player
80-
new(OpCodes.Ldarg_1),
81-
82-
// ev.Candy
83-
new(OpCodes.Ldloc, ev.LocalIndex),
84-
new(OpCodes.Callvirt, PropertyGetter(typeof(InteractingScp330EventArgs), nameof(InteractingScp330EventArgs.Candy))),
85-
86-
// bag
87-
new(OpCodes.Ldloca_S, 2),
88-
89-
// ServerProcessPickup(ReferenceHub, CandyKindID, Scp330Bag)
90-
new CodeInstruction(OpCodes.Call, Method(typeof(InteractingScp330), nameof(ServerProcessPickup), new[] { typeof(ReferenceHub), typeof(CandyKindID), typeof(Scp330Bag).MakeByRefType() })),
91-
});
92-
93-
int remove_offset = -3;
94-
int remove_index = newInstructions.FindLastIndex(
95-
instruction => instruction.Calls(Method(typeof(Scp330Bag), nameof(Scp330Bag.ServerProcessPickup)))) + remove_offset;
96-
97-
// Remove original add candy logic
98-
newInstructions.RemoveRange(remove_index, 4);
99-
100-
/* next code will used to override sound rpc check by EXILED
101-
* old:
102-
* if (args.PlaySound)
103-
* new:
104-
* if (args.PlaySound | ev.PlaySound)
105-
*/
106-
offset = 1;
107-
index = newInstructions.FindLastIndex(
108-
instruction => instruction.Calls(PropertyGetter(typeof(LabApi.Events.Arguments.PlayerEvents.PlayerInteractingScp330EventArgs), nameof(LabApi.Events.Arguments.PlayerEvents.PlayerInteractingScp330EventArgs.PlaySound)))) + offset;
109-
newInstructions.InsertRange(
110-
index,
111-
new[]
112-
{
113-
// load ev.ShouldPlaySound and or operation with nw property.
114-
new CodeInstruction(OpCodes.Ldloc_S, ev.LocalIndex),
84+
// shouldPlaySound = ev.ShouldPlaySound
11585
new(OpCodes.Callvirt, PropertyGetter(typeof(InteractingScp330EventArgs), nameof(InteractingScp330EventArgs.ShouldPlaySound))),
116-
new(OpCodes.Or),
117-
});
118-
/* next code will used to override Sever check by EXILED
119-
* old:
120-
* if (args.AllowPunishment && uses >= 2)
121-
* new:
122-
* if (args.AllowPunishment && ev.ShouldSever)
123-
*/
86+
new(OpCodes.Stloc, 2),
12487

125-
// set `notSeverLabel`
126-
offset = -1;
127-
index = newInstructions.FindLastIndex(
128-
instruction => instruction.LoadsField(Field(typeof(Scp330Interobject), nameof(Scp330Interobject._previousUses)))) + offset;
129-
130-
Label notSeverLabel = newInstructions[index].labels[0];
131-
132-
offset = 2;
133-
index = newInstructions.FindLastIndex(
134-
instruction => instruction.Calls(PropertyGetter(typeof(LabApi.Events.Arguments.PlayerEvents.PlayerInteractingScp330EventArgs), nameof(LabApi.Events.Arguments.PlayerEvents.PlayerInteractingScp330EventArgs.AllowPunishment)))) + offset;
88+
// shouldSever = ev.ShouldSever
89+
new(OpCodes.Callvirt, PropertyGetter(typeof(InteractingScp330EventArgs), nameof(InteractingScp330EventArgs.ShouldSever))),
90+
new(OpCodes.Stloc, 3),
13591

136-
// remove `uses >= 2` check, to override that by ev.ShouldSever
137-
newInstructions.RemoveRange(index, 3);
92+
// candyKindID = ev.Candy
93+
new(OpCodes.Callvirt, PropertyGetter(typeof(InteractingScp330EventArgs), nameof(InteractingScp330EventArgs.Candy))),
94+
new(OpCodes.Stloc_S, 4),
13895

139-
newInstructions.InsertRange(
140-
index,
141-
new[]
142-
{
143-
// if (!ev.ShouldSever)
144-
// goto shouldNotSever;
145-
new CodeInstruction(OpCodes.Ldloc_S, ev.LocalIndex),
146-
new(OpCodes.Callvirt, PropertyGetter(typeof(InteractingScp330EventArgs), nameof(InteractingScp330EventArgs.ShouldSever))),
147-
new(OpCodes.Brfalse_S, notSeverLabel),
96+
// if (!ev.IsAllowed)
97+
// return;
98+
new(OpCodes.Callvirt, PropertyGetter(typeof(InteractingScp330EventArgs), nameof(InteractingScp330EventArgs.IsAllowed))),
99+
new(OpCodes.Brfalse, returnLabel),
148100
});
149101

150102
newInstructions[newInstructions.Count - 1].labels.Add(returnLabel);
@@ -154,28 +106,5 @@ private static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstructi
154106

155107
ListPool<CodeInstruction>.Pool.Return(newInstructions);
156108
}
157-
158-
private static bool ServerProcessPickup(ReferenceHub player, CandyKindID candy, out Scp330Bag bag)
159-
{
160-
if (!Scp330Bag.TryGetBag(player, out bag))
161-
{
162-
player.inventory.ServerAddItem(ItemType.SCP330, ItemAddReason.AdminCommand);
163-
164-
if (!Scp330Bag.TryGetBag(player, out bag))
165-
return false;
166-
167-
bag.Candies = new List<CandyKindID> { candy };
168-
bag.ServerRefreshBag();
169-
170-
return true;
171-
}
172-
173-
bool result = bag.TryAddSpecific(candy);
174-
175-
if (bag.AcquisitionAlreadyReceived)
176-
bag.ServerRefreshBag();
177-
178-
return result;
179-
}
180109
}
181110
}

0 commit comments

Comments
 (0)