Skip to content

Commit

Permalink
Merge branch 'dev' into changing-group
Browse files Browse the repository at this point in the history
  • Loading branch information
Misaka-ZeroTwo authored Nov 12, 2023
2 parents 17ea911 + 1cac8bb commit a8a151c
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 34 deletions.
2 changes: 1 addition & 1 deletion Exiled.API/Features/Map.cs
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ public static int Seed
/// <summary>
/// Gets the <see cref="global::AmbientSoundPlayer"/>.
/// </summary>
public static AmbientSoundPlayer AmbientSoundPlayer => ambientSoundPlayer != null ? ambientSoundPlayer : (ambientSoundPlayer = ReferenceHub.HostHub.GetComponent<AmbientSoundPlayer>());
public static AmbientSoundPlayer AmbientSoundPlayer => ambientSoundPlayer ??= ReferenceHub.HostHub.GetComponent<AmbientSoundPlayer>();

/// <summary>
/// Broadcasts a message to all <see cref="Player">players</see>.
Expand Down
36 changes: 3 additions & 33 deletions Exiled.Events/Patches/Generic/PickupControlPatch.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,8 @@ namespace Exiled.Events.Patches.Generic

using static HarmonyLib.AccessTools;

#pragma warning disable SA1402 /// File may only contain a single type.
/// <summary>
/// Patches <see cref="InventoryExtensions.ServerCreatePickup(ItemBase, PickupSyncInfo, Vector3, Quaternion, bool, Action{ItemPickupBase})"/> to save scale for pickups and control <see cref="Pickup.IsSpawned"/> property.
/// Patches <see cref="InventoryExtensions.ServerCreatePickup(ItemBase, PickupSyncInfo, Vector3, Quaternion, bool, Action{ItemPickupBase})"/> to save scale for pickups.
/// </summary>
[HarmonyPatch(typeof(InventoryExtensions), nameof(InventoryExtensions.ServerCreatePickup), typeof(ItemBase), typeof(PickupSyncInfo), typeof(Vector3), typeof(Quaternion), typeof(bool), typeof(Action<ItemPickupBase>))]
internal static class PickupControlPatch
Expand All @@ -44,9 +43,10 @@ private static IEnumerable<CodeInstruction> Transpiler(

newInstructions.InsertRange(index, new CodeInstruction[]
{
// pickup = Pickup.Get(pickupBase);
// Pickup.Get(pickupBase);
new(OpCodes.Ldloc_0),
new(OpCodes.Call, Method(typeof(Pickup), nameof(Pickup.Get), new[] { typeof(ItemPickupBase) })),
new(OpCodes.Pop),

/*
// Item.Get(itemBase);
Expand All @@ -55,36 +55,6 @@ private static IEnumerable<CodeInstruction> Transpiler(
// pickup.GetItemInfo(item);
new(OpCodes.Callvirt, Method(typeof(Pickup), nameof(Pickup.GetItemInfo))),*/

// pickup.IsSpawned = spawn
new(OpCodes.Ldarg_S, 4),
new(OpCodes.Callvirt, PropertySetter(typeof(Pickup), nameof(Pickup.IsSpawned))),
});

for (int z = 0; z < newInstructions.Count; z++)
yield return newInstructions[z];

ListPool<CodeInstruction>.Pool.Return(newInstructions);
}
}

/// <summary>
/// Patches <see cref="ItemDistributor.SpawnPickup"/> to control <see cref="Pickup.IsSpawned"/> property for delayed spawned pickup.
/// </summary>
[HarmonyPatch(typeof(ItemDistributor), nameof(ItemDistributor.SpawnPickup))]
internal static class TriggerPickupControlPatch
{
private static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstruction> instructions, ILGenerator generator)
{
List<CodeInstruction> newInstructions = ListPool<CodeInstruction>.Pool.Get(instructions);

newInstructions.InsertRange(newInstructions.Count - 1, new CodeInstruction[]
{
// Pickup.Get(pickupBase).IsSpawned = true
new(OpCodes.Ldarg_0),
new(OpCodes.Call, Method(typeof(Pickup), nameof(Pickup.Get), new[] { typeof(ItemPickupBase) })),
new(OpCodes.Ldc_I4_1),
new(OpCodes.Callvirt, PropertySetter(typeof(Pickup), nameof(Pickup.IsSpawned))),
});

for (int z = 0; z < newInstructions.Count; z++)
Expand Down

0 comments on commit a8a151c

Please sign in to comment.