From 211da3f1753a7c466329a8b91a2199ce2092e8ec Mon Sep 17 00:00:00 2001 From: Undid-Iridium <24619207+Undid-Iridium@users.noreply.github.com> Date: Sun, 17 Nov 2024 22:15:42 -0500 Subject: [PATCH 1/6] Scp330Fix --- .../Events/Scp330/InteractingScp330.cs | 80 +++++++++++++------ 1 file changed, 56 insertions(+), 24 deletions(-) diff --git a/EXILED/Exiled.Events/Patches/Events/Scp330/InteractingScp330.cs b/EXILED/Exiled.Events/Patches/Events/Scp330/InteractingScp330.cs index 7bc53aadec..7933fabbc2 100644 --- a/EXILED/Exiled.Events/Patches/Events/Scp330/InteractingScp330.cs +++ b/EXILED/Exiled.Events/Patches/Events/Scp330/InteractingScp330.cs @@ -5,6 +5,8 @@ // // ----------------------------------------------------------------------- +using InventorySystem; + namespace Exiled.Events.Patches.Events.Scp330 { #pragma warning disable SA1402 @@ -68,24 +70,44 @@ private static IEnumerable Transpiler(IEnumerable instruction.Calls(Method(typeof(Scp330Bag), nameof(Scp330Bag.ServerProcessPickup)))) + remove_offset; + // Remove original add candy logic + newInstructions.RemoveRange(remove_index, 4); + /* next code will used to override sound rpc check by EXILED * old: * if (args.PlaySound) * new: - * if (args.PlaySound && ev.PlaySound) + * if (args.PlaySound || ev.PlaySound) */ - + offset = 1; index = newInstructions.FindLastIndex( instruction => instruction.Calls(PropertyGetter(typeof(PlayerInteractScp330Event), nameof(PlayerInteractScp330Event.PlaySound)))) + offset; - + newInstructions.InsertRange( index, new[] @@ -93,30 +115,30 @@ private static IEnumerable Transpiler(IEnumerable= 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[] @@ -135,21 +157,31 @@ private static IEnumerable Transpiler(IEnumerable.Pool.Return(newInstructions); } - } - - /// - /// Replaces with . - /// - [EventPatch(typeof(Handlers.Scp330), nameof(Handlers.Scp330.InteractingScp330))] - [HarmonyPatch(typeof(Scp330Bag), nameof(Scp330Bag.TryAddSpecific))] - internal static class ReplaceCandy - { - private static void Prefix(Scp330Bag __instance, ref CandyKindID kind) + + private static bool ServerProcessPickup(ReferenceHub player, CandyKindID candy, out Scp330Bag bag) { - Scp330 scp330 = Item.Get(__instance); + if (!Scp330Bag.TryGetBag(player, out bag)) + { + player.inventory.ServerAddItem(ItemType.SCP330); - if (scp330.CandyToAdd != CandyKindID.None) - kind = scp330.CandyToAdd; + if (!Scp330Bag.TryGetBag(player, out bag)) + return false; + + bag.Candies = new List { candy }; + bag.ServerRefreshBag(); + + return true; + } + + bool result = bag.TryAddSpecific(candy); + + if (bag.AcquisitionAlreadyReceived) + bag.ServerRefreshBag(); + + return result; } } + + + } \ No newline at end of file From 8469949d7e106c39dc1c02b9f1e621534bc6dc67 Mon Sep 17 00:00:00 2001 From: Undid-Iridium <24619207+Undid-Iridium@users.noreply.github.com> Date: Sun, 17 Nov 2024 22:20:33 -0500 Subject: [PATCH 2/6] Sigh stylecop --- .../Events/Scp330/InteractingScp330.cs | 24 +++++++------------ 1 file changed, 9 insertions(+), 15 deletions(-) diff --git a/EXILED/Exiled.Events/Patches/Events/Scp330/InteractingScp330.cs b/EXILED/Exiled.Events/Patches/Events/Scp330/InteractingScp330.cs index 7933fabbc2..de5b953110 100644 --- a/EXILED/Exiled.Events/Patches/Events/Scp330/InteractingScp330.cs +++ b/EXILED/Exiled.Events/Patches/Events/Scp330/InteractingScp330.cs @@ -70,7 +70,7 @@ private static IEnumerable Transpiler(IEnumerable Transpiler(IEnumerable Transpiler(IEnumerable instruction.Calls(Method(typeof(Scp330Bag), nameof(Scp330Bag.ServerProcessPickup)))) + remove_offset; + // Remove original add candy logic newInstructions.RemoveRange(remove_index, 4); @@ -103,11 +103,9 @@ private static IEnumerable Transpiler(IEnumerable instruction.Calls(PropertyGetter(typeof(PlayerInteractScp330Event), nameof(PlayerInteractScp330Event.PlaySound)))) + offset; - newInstructions.InsertRange( index, new[] @@ -117,28 +115,27 @@ private static IEnumerable Transpiler(IEnumerable= 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[] @@ -157,7 +154,7 @@ private static IEnumerable Transpiler(IEnumerable.Pool.Return(newInstructions); } - + private static bool ServerProcessPickup(ReferenceHub player, CandyKindID candy, out Scp330Bag bag) { if (!Scp330Bag.TryGetBag(player, out bag)) @@ -181,7 +178,4 @@ private static bool ServerProcessPickup(ReferenceHub player, CandyKindID candy, return result; } } - - - } \ No newline at end of file From 1df63f28b4bf07b8d1a61fef3e846d154112b3fb Mon Sep 17 00:00:00 2001 From: Undid-Iridium <24619207+Undid-Iridium@users.noreply.github.com> Date: Sun, 17 Nov 2024 22:24:19 -0500 Subject: [PATCH 3/6] Sigh stylecop x2 --- .../Exiled.Events/Patches/Events/Scp330/InteractingScp330.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/EXILED/Exiled.Events/Patches/Events/Scp330/InteractingScp330.cs b/EXILED/Exiled.Events/Patches/Events/Scp330/InteractingScp330.cs index de5b953110..f944f3652c 100644 --- a/EXILED/Exiled.Events/Patches/Events/Scp330/InteractingScp330.cs +++ b/EXILED/Exiled.Events/Patches/Events/Scp330/InteractingScp330.cs @@ -5,12 +5,11 @@ // // ----------------------------------------------------------------------- -using InventorySystem; - namespace Exiled.Events.Patches.Events.Scp330 { #pragma warning disable SA1402 #pragma warning disable SA1313 + using System.Collections.Generic; using System.Reflection.Emit; @@ -20,6 +19,7 @@ namespace Exiled.Events.Patches.Events.Scp330 using Exiled.Events.EventArgs.Scp330; using HarmonyLib; using Interactables.Interobjects; + using InventorySystem; using InventorySystem.Items.Usables.Scp330; using PluginAPI.Events; From d99507cb75ef39503fcd4ad35466b47bd9750715 Mon Sep 17 00:00:00 2001 From: X <24619207+Undid-Iridium@users.noreply.github.com> Date: Mon, 18 Nov 2024 12:42:32 -0500 Subject: [PATCH 4/6] Update EXILED/Exiled.Events/Patches/Events/Scp330/InteractingScp330.cs Technically more accurate Co-authored-by: Yamato <66829532+louis1706@users.noreply.github.com> --- EXILED/Exiled.Events/Patches/Events/Scp330/InteractingScp330.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/EXILED/Exiled.Events/Patches/Events/Scp330/InteractingScp330.cs b/EXILED/Exiled.Events/Patches/Events/Scp330/InteractingScp330.cs index f944f3652c..c91a8b4ad8 100644 --- a/EXILED/Exiled.Events/Patches/Events/Scp330/InteractingScp330.cs +++ b/EXILED/Exiled.Events/Patches/Events/Scp330/InteractingScp330.cs @@ -101,7 +101,7 @@ private static IEnumerable Transpiler(IEnumerable Date: Wed, 20 Nov 2024 12:04:30 -0500 Subject: [PATCH 5/6] Amended changes --- EXILED/Exiled.API/Features/Items/Scp330.cs | 5 ----- .../EventArgs/Scp330/InteractingScp330EventArgs.cs | 11 ----------- 2 files changed, 16 deletions(-) diff --git a/EXILED/Exiled.API/Features/Items/Scp330.cs b/EXILED/Exiled.API/Features/Items/Scp330.cs index d0f902184a..689929f12b 100644 --- a/EXILED/Exiled.API/Features/Items/Scp330.cs +++ b/EXILED/Exiled.API/Features/Items/Scp330.cs @@ -87,11 +87,6 @@ internal Scp330() /// public CandyKindID ExposedType { get; set; } = CandyKindID.None; - /// - /// Gets or sets the candy that will be added to the bag. Used for events. - /// - internal CandyKindID CandyToAdd { get; set; } = CandyKindID.None; - /// /// Adds a specific candy to the bag. /// diff --git a/EXILED/Exiled.Events/EventArgs/Scp330/InteractingScp330EventArgs.cs b/EXILED/Exiled.Events/EventArgs/Scp330/InteractingScp330EventArgs.cs index cd4d4922fd..19fae1c8af 100644 --- a/EXILED/Exiled.Events/EventArgs/Scp330/InteractingScp330EventArgs.cs +++ b/EXILED/Exiled.Events/EventArgs/Scp330/InteractingScp330EventArgs.cs @@ -46,8 +46,6 @@ public InteractingScp330EventArgs(Player player, int usage) Scp330.RemoveAllCandy(); player.AddItem(Scp330); } - - Scp330.CandyToAdd = Scp330Candies.GetRandom(); } /// @@ -55,15 +53,6 @@ public InteractingScp330EventArgs(Player player, int usage) /// public int UsageCount { get; } - /// - /// Gets or sets a value indicating the type of candy that will be received from this interaction. - /// - public CandyKindID Candy - { - get => Scp330.CandyToAdd; - set => Scp330.CandyToAdd = value; - } - /// /// Gets or sets a value indicating whether the player's hands should get severed. /// From 08a5f5c494f3610704e34cee6a2e07cff24681ac Mon Sep 17 00:00:00 2001 From: Undid-Iridium <24619207+Undid-Iridium@users.noreply.github.com> Date: Wed, 20 Nov 2024 12:17:27 -0500 Subject: [PATCH 6/6] Missing candy item --- .../EventArgs/Scp330/InteractingScp330EventArgs.cs | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/EXILED/Exiled.Events/EventArgs/Scp330/InteractingScp330EventArgs.cs b/EXILED/Exiled.Events/EventArgs/Scp330/InteractingScp330EventArgs.cs index 19fae1c8af..bbe06102e4 100644 --- a/EXILED/Exiled.Events/EventArgs/Scp330/InteractingScp330EventArgs.cs +++ b/EXILED/Exiled.Events/EventArgs/Scp330/InteractingScp330EventArgs.cs @@ -64,6 +64,11 @@ public InteractingScp330EventArgs(Player player, int usage) /// It won't work if = . public bool ShouldPlaySound { get; set; } + /// + /// Gets or sets a value indicating the type of candy that will be received from this interaction. + /// + public CandyKindID Candy { get; set; } + /// /// Gets or sets a value indicating whether the player is allowed to interact with SCP-330. ///