diff --git a/EXILED/Exiled.API/Features/Pickups/FirearmPickup.cs b/EXILED/Exiled.API/Features/Pickups/FirearmPickup.cs
index 66ad5633db..72af44d11b 100644
--- a/EXILED/Exiled.API/Features/Pickups/FirearmPickup.cs
+++ b/EXILED/Exiled.API/Features/Pickups/FirearmPickup.cs
@@ -9,6 +9,8 @@ namespace Exiled.API.Features.Pickups
{
using System;
+ using Exiled.API.Features.Items.FirearmModules;
+ using Exiled.API.Features.Items.FirearmModules.Primary;
using Exiled.API.Interfaces;
using InventorySystem.Items;
using InventorySystem.Items.Firearms;
@@ -168,13 +170,28 @@ internal override void ReadItemInfo(Items.Item item)
protected override void InitializeProperties(ItemBase itemBase)
{
base.InitializeProperties(itemBase);
- if (!(itemBase as Firearm).TryGetModule(out IPrimaryAmmoContainerModule magazine))
+ if (itemBase is not Firearm firearm)
{
- Log.Error($"firearm prefab {itemBase.ItemTypeId} doesnt have an primary magazine module(unexpected)");
+ Log.Error("FirearmPickup::InitializeProperties called with a non-firearm item!");
return;
}
- MaxAmmo = magazine.AmmoMax;
+ foreach (ModuleBase module in firearm.Modules)
+ {
+ switch (module)
+ {
+ case IPrimaryAmmoContainerModule primaryAmmoModule:
+ MaxAmmo = primaryAmmoModule.AmmoMax;
+ break;
+
+ case HitscanHitregModuleBase hitregModule:
+ Damage = hitregModule.BaseDamage;
+ Inaccuracy = hitregModule.BaseBulletInaccuracy;
+ Penetration = hitregModule.BasePenetration;
+ DamageFalloffDistance = hitregModule.DamageFalloffDistance;
+ break;
+ }
+ }
}
}
}
diff --git a/EXILED/Exiled.Events/Patches/Fixes/Scp127TryGetCurPairFix.cs b/EXILED/Exiled.Events/Patches/Fixes/Scp127TryGetCurPairFix.cs
new file mode 100644
index 0000000000..abece231de
--- /dev/null
+++ b/EXILED/Exiled.Events/Patches/Fixes/Scp127TryGetCurPairFix.cs
@@ -0,0 +1,49 @@
+// -----------------------------------------------------------------------
+//
+// Copyright (c) ExMod Team. All rights reserved.
+// Licensed under the CC BY-SA 3.0 license.
+//
+// -----------------------------------------------------------------------
+
+namespace Exiled.Events.Patches.Fixes
+{
+ using System.Collections.Generic;
+ using System.Reflection.Emit;
+
+ using Exiled.API.Features.Pools;
+ using HarmonyLib;
+ using InventorySystem.Items.Firearms.Modules.Scp127;
+ using UnityEngine;
+
+ using static HarmonyLib.AccessTools;
+
+ ///
+ /// Patches to work and return false when the module has no owner.
+ ///
+ [HarmonyPatch(typeof(Scp127Hitscan), nameof(Scp127Hitscan.TryGetCurPair))]
+ public class Scp127TryGetCurPairFix
+ {
+ private static IEnumerable Transpiler(IEnumerable instructions, ILGenerator generator)
+ {
+ List newInstructions = ListPool.Pool.Get(instructions);
+
+ Label retLabel = generator.DefineLabel();
+
+ newInstructions.FindLast(x => x.opcode == OpCodes.Ldarg_1).labels.Add(retLabel);
+
+ newInstructions.InsertRange(0, new CodeInstruction[]
+ {
+ // check if owner is null, if so, jump to last 2 lines of method, else, run the method.
+ new(OpCodes.Ldarg_0),
+ new(OpCodes.Callvirt, PropertyGetter(typeof(Scp127Hitscan), nameof(Scp127Hitscan.Owner))),
+ new(OpCodes.Call, Method(typeof(Object), "op_Implicit")),
+ new(OpCodes.Brfalse_S, retLabel),
+ });
+
+ for (int z = 0; z < newInstructions.Count; z++)
+ yield return newInstructions[z];
+
+ ListPool.Pool.Return(newInstructions);
+ }
+ }
+}
\ No newline at end of file