From f4abc04b64cac69b4c57680553859e776a3a3a7d Mon Sep 17 00:00:00 2001
From: Misaka-ZeroTwo <45165615+Misaka-ZeroTwo@users.noreply.github.com>
Date: Tue, 13 Aug 2024 01:17:11 +0800
Subject: [PATCH] v8.12.0-rc.2 (#57)
* `[Exiled::API]` Removing breaking changes (#54)
Co-authored-by: VALERA771 <72030575+VALERA771@users.noreply.github.com>
Co-authored-by: Nameless <85962933+Misfiy@users.noreply.github.com>
* `Scp330` sound fix (#55)
Co-authored-by: IRacle <79921583+IRacle1@users.noreply.github.com>
Co-authored-by: Misaka-ZeroTwo <45165615+Misaka-ZeroTwo@users.noreply.github.com>
---
EXILED/Exiled.API/Features/Player.cs | 11 +++
.../Scp330/InteractingScp330EventArgs.cs | 9 ++-
.../Events/Scp330/InteractingScp330.cs | 67 +++++++++++++------
3 files changed, 65 insertions(+), 22 deletions(-)
diff --git a/EXILED/Exiled.API/Features/Player.cs b/EXILED/Exiled.API/Features/Player.cs
index 0885000f7..314817264 100644
--- a/EXILED/Exiled.API/Features/Player.cs
+++ b/EXILED/Exiled.API/Features/Player.cs
@@ -2411,6 +2411,17 @@ public ushort GetAmmoLimit(AmmoType type, bool ignoreArmor = false)
return InventorySystem.Configs.InventoryLimits.GetAmmoLimit(type.GetItemType(), referenceHub);
}
+ ///
+ /// Gets the maximum amount of ammo the player can hold, given the ammo .
+ ///
+ /// The of the ammo to check.
+ /// The maximum amount of ammo this player can carry.
+ [Obsolete("Use Player::GetAmmoLimit(AmmoType, bool) instead.")]
+ public int GetAmmoLimit(AmmoType type)
+ {
+ return (int)InventorySystem.Configs.InventoryLimits.GetAmmoLimit(type.GetItemType(), referenceHub);
+ }
+
///
/// Gets the maximum amount of ammo the player can hold, given the ammo .
/// This limit will scale with the armor the player is wearing.
diff --git a/EXILED/Exiled.Events/EventArgs/Scp330/InteractingScp330EventArgs.cs b/EXILED/Exiled.Events/EventArgs/Scp330/InteractingScp330EventArgs.cs
index b87238842..45a587755 100644
--- a/EXILED/Exiled.Events/EventArgs/Scp330/InteractingScp330EventArgs.cs
+++ b/EXILED/Exiled.Events/EventArgs/Scp330/InteractingScp330EventArgs.cs
@@ -35,6 +35,7 @@ public InteractingScp330EventArgs(Player player, int usage)
Candy = Scp330Candies.GetRandom();
UsageCount = usage;
ShouldSever = usage >= 2;
+ ShouldPlaySound = true;
IsAllowed = Player.IsHuman;
}
@@ -53,10 +54,16 @@ public InteractingScp330EventArgs(Player player, int usage)
///
public bool ShouldSever { get; set; }
+ ///
+ /// Gets or sets a value indicating whether the sound should be played.
+ ///
+ /// It won't work if = .
+ public bool ShouldPlaySound { get; set; }
+
///
/// Gets or sets a value indicating whether the player is allowed to interact with SCP-330.
///
- public bool IsAllowed { get; set; } = true;
+ public bool IsAllowed { get; set; }
///
/// Gets the triggering the event.
diff --git a/EXILED/Exiled.Events/Patches/Events/Scp330/InteractingScp330.cs b/EXILED/Exiled.Events/Patches/Events/Scp330/InteractingScp330.cs
index c8ff97d32..bcb4f5308 100644
--- a/EXILED/Exiled.Events/Patches/Events/Scp330/InteractingScp330.cs
+++ b/EXILED/Exiled.Events/Patches/Events/Scp330/InteractingScp330.cs
@@ -10,6 +10,7 @@ namespace Exiled.Events.Patches.Events.Scp330
using System.Collections.Generic;
using System.Reflection.Emit;
+ using Exiled.API.Features;
using Exiled.API.Features.Pools;
using Exiled.Events.Attributes;
using Exiled.Events.EventArgs.Scp330;
@@ -17,6 +18,7 @@ namespace Exiled.Events.Patches.Events.Scp330
using HarmonyLib;
using Interactables.Interobjects;
using InventorySystem.Items.Usables.Scp330;
+ using PluginAPI.Events;
using static HarmonyLib.AccessTools;
@@ -34,9 +36,7 @@ private static IEnumerable Transpiler(IEnumerable newInstructions = ListPool.Pool.Get(instructions);
- Label shouldNotSever = generator.DefineLabel();
Label returnLabel = generator.DefineLabel();
- Label enableEffectLabel = generator.DefineLabel();
LocalBuilder ev = generator.DeclareLocal(typeof(InteractingScp330EventArgs));
@@ -74,35 +74,60 @@ private static IEnumerable Transpiler(IEnumerable instruction.Calls(Method(typeof(Scp330Interobject), nameof(Scp330Interobject.RpcMakeSound)))) + addShouldSeverOffset;
+ /* next code will used to override sound rpc check by EXILED
+ * old:
+ * if (args.PlaySound)
+ * new:
+ * if (args.PlaySound && ev.PlaySound)
+ */
- int serverEffectLocationStart = -1;
- int enableEffect = newInstructions.FindLastIndex(
- instruction => instruction.LoadsField(Field(typeof(ReferenceHub), nameof(ReferenceHub.playerEffectsController)))) + serverEffectLocationStart;
+ offset = 1;
+ index = newInstructions.FindLastIndex(
+ instruction => instruction.Calls(PropertyGetter(typeof(PlayerInteractScp330Event), nameof(PlayerInteractScp330Event.PlaySound)))) + offset;
- newInstructions[enableEffect].WithLabels(enableEffectLabel);
newInstructions.InsertRange(
- addShouldSeverIndex,
+ index,
+ new[]
+ {
+ // load ev.ShouldPlaySound and or operation with nw property.
+ new CodeInstruction(OpCodes.Ldloc_S, ev.LocalIndex),
+ new(OpCodes.Callvirt, PropertyGetter(typeof(InteractingScp330EventArgs), nameof(InteractingScp330EventArgs.ShouldPlaySound))),
+ new(OpCodes.And),
+ });
+
+ /* next code will used to override Sever check by EXILED
+ * old:
+ * if (args.AllowPunishment && uses >= 2)
+ * new:
+ * if (args.AllowPunishment && ev.ShouldSever)
+ */
+
+ // set `notSeverLabel`
+ offset = -1;
+ index = newInstructions.FindLastIndex(
+ instruction => instruction.LoadsField(Field(typeof(Scp330Interobject), nameof(Scp330Interobject._takenCandies)))) + offset;
+
+ Label notSeverLabel = newInstructions[index].labels[0];
+
+ offset = 2;
+ index = newInstructions.FindLastIndex(
+ instruction => instruction.Calls(PropertyGetter(typeof(PlayerInteractScp330Event), nameof(PlayerInteractScp330Event.AllowPunishment)))) + offset;
+
+ // remove `uses >= 2` check, to override that by ev.ShouldSever
+ newInstructions.RemoveRange(index, 3);
+
+ newInstructions.InsertRange(
+ index,
new[]
{
// if (!ev.ShouldSever)
// goto shouldNotSever;
- new CodeInstruction(OpCodes.Ldloc, ev.LocalIndex),
+ new CodeInstruction(OpCodes.Ldloc_S, ev.LocalIndex),
new(OpCodes.Callvirt, PropertyGetter(typeof(InteractingScp330EventArgs), nameof(InteractingScp330EventArgs.ShouldSever))),
- new(OpCodes.Brfalse, shouldNotSever),
- new(OpCodes.Br, enableEffectLabel),
+ new(OpCodes.Brfalse_S, notSeverLabel),
});
- // This will let us jump to the taken candies code and lock until ldarg_0, meaning we allow base game logic handle candy adding.
- int addTakenCandiesOffset = -1;
- int addTakenCandiesIndex = newInstructions.FindLastIndex(
- instruction => instruction.LoadsField(Field(typeof(Scp330Interobject), nameof(Scp330Interobject._takenCandies)))) + addTakenCandiesOffset;
-
- newInstructions[addTakenCandiesIndex].WithLabels(shouldNotSever);
- newInstructions[newInstructions.Count - 1].WithLabels(returnLabel);
+ newInstructions[newInstructions.Count - 1].labels.Add(returnLabel);
for (int z = 0; z < newInstructions.Count; z++)
yield return newInstructions[z];