diff --git a/EXILED/Exiled.Events/Patches/Fixes/Fix106ItemManager.cs b/EXILED/Exiled.Events/Patches/Fixes/Fix106ItemManager.cs new file mode 100644 index 000000000..c082edbed --- /dev/null +++ b/EXILED/Exiled.Events/Patches/Fixes/Fix106ItemManager.cs @@ -0,0 +1,45 @@ +// ----------------------------------------------------------------------- +// +// 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 PlayerRoles.PlayableScps.Scp106; + + /// + /// Patches the method. + /// Fixes an error caused by this method cuz NW doesn't know how to do array indexing. + /// + [HarmonyPatch(typeof(Scp106PocketItemManager), nameof(Scp106PocketItemManager.GetRandomValidSpawnPosition))] + public class Fix106ItemManager + { + private static IEnumerable Transpiler(IEnumerable instructions) + { + List newInstructions = ListPool.Pool.Get(instructions); + + int offset = 1; + int index = newInstructions.FindIndex(x => x.LoadsConstant(64)) + offset; + + newInstructions[index].opcode = OpCodes.Blt_S; + + index = newInstructions.FindLastIndex(x => x.LoadsConstant(64)) + offset; + + newInstructions[index].opcode = OpCodes.Blt_S; + + for (int z = 0; z < newInstructions.Count; z++) + yield return newInstructions[z]; + + ListPool.Pool.Return(newInstructions); + } + } +} \ No newline at end of file