Skip to content

Commit

Permalink
Merge branch 'dev' into dev
Browse files Browse the repository at this point in the history
  • Loading branch information
louis1706 authored Dec 26, 2024
2 parents 094aeb4 + f7aa841 commit 021f6cc
Show file tree
Hide file tree
Showing 26 changed files with 295 additions and 91 deletions.
6 changes: 2 additions & 4 deletions EXILED/Exiled.API/Features/Items/Armor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,6 @@ public IEnumerable<BodyArmor.ArmorCategoryLimitModifier> CategoryLimits
{
Weight = Weight,
StaminaUseMultiplier = StaminaUseMultiplier,
RemoveExcessOnDrop = RemoveExcessOnDrop,
CategoryLimits = CategoryLimits,
StaminaRegenMultiplier = StaminaRegenMultiplier,
AmmoLimits = AmmoLimits,
Expand All @@ -159,14 +158,13 @@ public IEnumerable<BodyArmor.ArmorCategoryLimitModifier> CategoryLimits
};

/// <inheritdoc/>
internal override void ReadPickupInfo(Pickup pickup)
internal override void ReadPickupInfoBefore(Pickup pickup)
{
base.ReadPickupInfo(pickup);
base.ReadPickupInfoBefore(pickup);
if (pickup is Pickups.BodyArmorPickup armorPickup)
{
HelmetEfficacy = armorPickup.HelmetEfficacy;
VestEfficacy = armorPickup.VestEfficacy;
RemoveExcessOnDrop = armorPickup.RemoveExcessOnDrop;
StaminaUseMultiplier = armorPickup.StaminaUseMultiplier;
StaminaRegenMultiplier = armorPickup.StaminaRegenMultiplier;
AmmoLimits = armorPickup.AmmoLimits;
Expand Down
4 changes: 2 additions & 2 deletions EXILED/Exiled.API/Features/Items/ExplosiveGrenade.cs
Original file line number Diff line number Diff line change
Expand Up @@ -162,9 +162,9 @@ public ExplosionGrenadeProjectile SpawnActive(Vector3 position, Player owner = n
};

/// <inheritdoc/>
internal override void ReadPickupInfo(Pickup pickup)
internal override void ReadPickupInfoBefore(Pickup pickup)
{
base.ReadPickupInfo(pickup);
base.ReadPickupInfoBefore(pickup);
if (pickup is ExplosiveGrenadePickup explosiveGrenadePickup)
{
MaxRadius = explosiveGrenadePickup.MaxRadius;
Expand Down
4 changes: 2 additions & 2 deletions EXILED/Exiled.API/Features/Items/Firearm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -699,9 +699,9 @@ internal override void ChangeOwner(Player oldOwner, Player newOwner)
}

/// <inheritdoc/>
internal override void ReadPickupInfo(Pickup pickup)
internal override void ReadPickupInfoBefore(Pickup pickup)
{
base.ReadPickupInfo(pickup);
base.ReadPickupInfoBefore(pickup);

if (pickup is FirearmPickup firearmPickup)
{
Expand Down
4 changes: 2 additions & 2 deletions EXILED/Exiled.API/Features/Items/FlashGrenade.cs
Original file line number Diff line number Diff line change
Expand Up @@ -139,9 +139,9 @@ public FlashbangProjectile SpawnActive(Vector3 position, Player owner = null)
public override string ToString() => $"{Type} ({Serial}) [{Weight}] *{Scale}* |{FuseTime}|";

/// <inheritdoc/>
internal override void ReadPickupInfo(Pickup pickup)
internal override void ReadPickupInfoBefore(Pickup pickup)
{
base.ReadPickupInfo(pickup);
base.ReadPickupInfoBefore(pickup);
if (pickup is FlashGrenadePickup flashGrenadePickup)
{
MinimalDurationEffect = flashGrenadePickup.MinimalDurationEffect;
Expand Down
20 changes: 19 additions & 1 deletion EXILED/Exiled.API/Features/Items/Item.cs
Original file line number Diff line number Diff line change
Expand Up @@ -429,12 +429,30 @@ internal virtual void ChangeOwner(Player oldOwner, Player newOwner)
/// Helper method for saving data between items and pickups.
/// </summary>
/// <param name="pickup"><see cref="Pickup"/>-related data to give to the <see cref="Item"/>.</param>
internal virtual void ReadPickupInfo(Pickup pickup)
/// <remarks>
/// Analog to <see cref="ReadPickupInfoAfter(Pickup)"/>, but it is called before item initialization.
/// <see cref="ItemBase.OnAdded(ItemPickupBase)"/>.
/// </remarks>
/// <see cref="ReadPickupInfoAfter"/>
internal virtual void ReadPickupInfoBefore(Pickup pickup)
{
if (pickup is not null)
{
Scale = pickup.Scale;
}
}

/// <summary>
/// Helper method for saving data between items and pickups.
/// </summary>
/// <param name="pickup"><see cref="Pickup"/>-related data to give to the <see cref="Item"/>.</param>
/// <remarks>
/// Analog to <see cref="ReadPickupInfoAfter(Pickup)"/>, but it is called after item initialization.
/// <see cref="ItemBase.OnAdded(ItemPickupBase)"/>.
/// </remarks>
/// <see cref="ReadPickupInfoBefore"/>
internal virtual void ReadPickupInfoAfter(Pickup pickup)
{
}
}
}
4 changes: 2 additions & 2 deletions EXILED/Exiled.API/Features/Items/Jailbird.cs
Original file line number Diff line number Diff line change
Expand Up @@ -185,9 +185,9 @@ public void Break()
public override string ToString() => $"{Type} ({Serial}) [{Weight}] *{Scale}*";

/// <inheritdoc/>
internal override void ReadPickupInfo(Pickup pickup)
internal override void ReadPickupInfoBefore(Pickup pickup)
{
base.ReadPickupInfo(pickup);
base.ReadPickupInfoBefore(pickup);
if (pickup is JailbirdPickup jailbirdPickup)
{
MeleeDamage = jailbirdPickup.MeleeDamage;
Expand Down
4 changes: 2 additions & 2 deletions EXILED/Exiled.API/Features/Items/Keycard.cs
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,9 @@ public KeycardPermissions Permissions
public override string ToString() => $"{Type} ({Serial}) [{Weight}] *{Scale}* |{Permissions}|";

/// <inheritdoc/>
internal override void ReadPickupInfo(Pickup pickup)
internal override void ReadPickupInfoBefore(Pickup pickup)
{
base.ReadPickupInfo(pickup);
base.ReadPickupInfoBefore(pickup);
if (pickup is KeycardPickup keycardPickup)
{
Permissions = keycardPickup.Permissions;
Expand Down
4 changes: 2 additions & 2 deletions EXILED/Exiled.API/Features/Items/Scp244.cs
Original file line number Diff line number Diff line change
Expand Up @@ -119,9 +119,9 @@ public override Pickup CreatePickup(Vector3 position, Quaternion? rotation = nul
public override string ToString() => $"{Type} ({Serial}) [{Weight}] *{Scale}* -{Primed}-";

/// <inheritdoc/>
internal override void ReadPickupInfo(Pickup pickup)
internal override void ReadPickupInfoBefore(Pickup pickup)
{
base.ReadPickupInfo(pickup);
base.ReadPickupInfoBefore(pickup);
if (pickup is Scp244Pickup scp244)
{
Health = scp244.Health;
Expand Down
4 changes: 2 additions & 2 deletions EXILED/Exiled.API/Features/Items/Usable.cs
Original file line number Diff line number Diff line change
Expand Up @@ -136,9 +136,9 @@ public virtual void Use()
}

/// <inheritdoc/>
internal override void ReadPickupInfo(Pickup pickup)
internal override void ReadPickupInfoBefore(Pickup pickup)
{
base.ReadPickupInfo(pickup);
base.ReadPickupInfoBefore(pickup);
if (pickup is UsablePickup usablePickup)
{
UseTime = usablePickup.UseTime;
Expand Down
3 changes: 1 addition & 2 deletions EXILED/Exiled.API/Features/Pickups/BodyArmorPickup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ internal BodyArmorPickup(ItemType type)
/// <summary>
/// Gets or sets a value indicating whether excess ammo should be removed when the armor is dropped.
/// </summary>
[Obsolete("Propetry is internal, and controls armor remove logic for clearing inventory")]
public bool RemoveExcessOnDrop { get; set; }

/// <summary>
Expand Down Expand Up @@ -132,7 +133,6 @@ internal override void ReadItemInfo(Item item)
{
helmetEfficacy = armoritem.HelmetEfficacy;
vestEfficacy = armoritem.VestEfficacy;
RemoveExcessOnDrop = armoritem.RemoveExcessOnDrop;
StaminaUseMultiplier = armoritem.StaminaUseMultiplier;
StaminaRegenMultiplier = armoritem.StaminaRegenMultiplier;
AmmoLimits = armoritem.AmmoLimits;
Expand All @@ -148,7 +148,6 @@ protected override void InitializeProperties(ItemBase itemBase)
{
helmetEfficacy = armoritem.HelmetEfficacy;
vestEfficacy = armoritem.VestEfficacy;
RemoveExcessOnDrop = !armoritem.DontRemoveExcessOnDrop;
StaminaUseMultiplier = armoritem._staminaUseMultiplier;
StaminaRegenMultiplier = armoritem.StaminaRegenMultiplier;
AmmoLimits = armoritem.AmmoLimits.Select(limit => (ArmorAmmoLimit)limit);
Expand Down
9 changes: 6 additions & 3 deletions EXILED/Exiled.API/Features/Pickups/FirearmPickup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -138,9 +138,12 @@ public override void Spawn()
/// <inheritdoc/>
internal override void ReadItemInfo(Items.Item item)
{
Items.Firearm firearm = (Items.Firearm)item;
MaxAmmo = firearm.PrimaryMagazine.ConstantMaxAmmo;
AmmoDrain = firearm.AmmoDrain;
if (item is Items.Firearm firearm)
{
MaxAmmo = firearm.PrimaryMagazine.ConstantMaxAmmo;
AmmoDrain = firearm.AmmoDrain;
}

base.ReadItemInfo(item);
}

Expand Down
6 changes: 3 additions & 3 deletions EXILED/Exiled.API/Features/Player.cs
Original file line number Diff line number Diff line change
Expand Up @@ -794,7 +794,7 @@ public bool IsIntercomMuted
/// <summary>
/// Gets a value indicating whether the player is speaking.
/// </summary>
public bool IsSpeaking => Role is Roles.IVoiceRole voiceRole && voiceRole.VoiceModule.IsSpeaking;
public bool IsSpeaking => Role is Roles.IVoiceRole voiceRole && voiceRole.VoiceModule.ServerIsSending;

/// <summary>
/// Gets the player's voice color.
Expand Down Expand Up @@ -2813,7 +2813,7 @@ public void AddItem(Firearm item, IEnumerable<AttachmentIdentifier> identifiers)
/// <param name="pickup">The <see cref="Pickup"/> of the item to be added.</param>
/// <param name="addReason">The reason the item was added.</param>
/// <returns>The <see cref="Item"/> that was added.</returns>
public Item AddItem(Pickup pickup, ItemAddReason addReason = ItemAddReason.Undefined) => Item.Get(Inventory.ServerAddItem(pickup.Type, addReason, pickup.Serial, pickup.Base));
public Item AddItem(Pickup pickup, ItemAddReason addReason = ItemAddReason.AdminCommand) => Item.Get(Inventory.ServerAddItem(pickup.Type, addReason, pickup.Serial, pickup.Base));

/// <summary>
/// Adds an item to the player's inventory.
Expand All @@ -2823,7 +2823,7 @@ public void AddItem(Firearm item, IEnumerable<AttachmentIdentifier> identifiers)
/// <returns>The <see cref="Item"/> that was added.</returns>
public Item AddItem(FirearmPickup pickup, IEnumerable<AttachmentIdentifier> identifiers)
{
Firearm firearm = Item.Get<Firearm>(Inventory.ServerAddItem(pickup.Type, ItemAddReason.Undefined, pickup.Serial, pickup.Base));
Firearm firearm = Item.Get<Firearm>(Inventory.ServerAddItem(pickup.Type, ItemAddReason.AdminCommand, pickup.Serial, pickup.Base));

if (identifiers is not null)
firearm.AddAttachment(identifiers);
Expand Down
2 changes: 0 additions & 2 deletions EXILED/Exiled.API/Features/Room.cs
Original file line number Diff line number Diff line change
Expand Up @@ -517,8 +517,6 @@ private void InternalCreate()
Log.Error($"[ROOMTYPE UNKNOWN] {this} Name : {gameObject?.name} Shape : {Identifier?.Shape}");
#endif

RoomLightControllersValue.AddRange(gameObject.GetComponentsInChildren<RoomLightController>());

RoomLightControllers = RoomLightControllersValue.AsReadOnly();

GetComponentsInChildren<BreakableWindow>().ForEach(component =>
Expand Down
2 changes: 1 addition & 1 deletion EXILED/Exiled.API/Features/TeslaGate.cs
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,7 @@ public void ForceTrigger()
/// </summary>
/// <param name="player">The <see cref="Player"/> to check.</param>
/// <returns><see langword="true"/> if the given <see cref="Player"/> is in the hurt range of the tesla gate; otherwise, <see langword="false"/>.</returns>
public bool IsPlayerInHurtRange(Player player) => player is not null && Vector3.Distance(Position, player.Position) <= Base.sizeOfTrigger * 2.2f;
public bool IsPlayerInHurtRange(Player player) => player is not null && Base.killers.Any(x => new Bounds(x.transform.position, Base.sizeOfKiller).Contains(player.Position));

/// <summary>
/// Gets a value indicating whether the <see cref="Player"/> is in the idle range of a specific tesla gate.
Expand Down
15 changes: 4 additions & 11 deletions EXILED/Exiled.Events/EventArgs/Player/ReloadingWeaponEventArgs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,26 +20,19 @@ public class ReloadingWeaponEventArgs : IPlayerEvent, IFirearmEvent, IDeniableEv
/// <summary>
/// Initializes a new instance of the <see cref="ReloadingWeaponEventArgs" /> class.
/// </summary>
/// <param name="player">
/// <inheritdoc cref="Player" />
/// </param>
/// <param name="firearm">
/// <inheritdoc cref="Firearm" />
/// </param>
/// <param name="isAllowed">
/// <inheritdoc cref="IsAllowed" />
/// </param>
public ReloadingWeaponEventArgs(Player player, Firearm firearm, bool isAllowed = true)
public ReloadingWeaponEventArgs(InventorySystem.Items.Firearms.Firearm firearm)
{
Firearm = firearm;
Player = player;
IsAllowed = isAllowed;
Firearm = Item.Get<Firearm>(firearm);
Player = Firearm.Owner;
}

/// <summary>
/// Gets or sets a value indicating whether the weapon can be reloaded.
/// </summary>
public bool IsAllowed { get; set; }
public bool IsAllowed { get; set; } = true;

/// <summary>
/// Gets the <see cref="API.Features.Items.Firearm" /> being reloaded.
Expand Down
13 changes: 3 additions & 10 deletions EXILED/Exiled.Events/EventArgs/Player/UnloadingWeaponEventArgs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,26 +20,19 @@ public class UnloadingWeaponEventArgs : IPlayerEvent, IFirearmEvent, IDeniableEv
/// <summary>
/// Initializes a new instance of the <see cref="UnloadingWeaponEventArgs" /> class.
/// </summary>
/// <param name="player">
/// <inheritdoc cref="Player" />
/// </param>
/// <param name="firearm">
/// <inheritdoc cref="Firearm" />
/// </param>
/// <param name="isAllowed">
/// <inheritdoc cref="IsAllowed" />
/// </param>
public UnloadingWeaponEventArgs(Player player, Firearm firearm, bool isAllowed = true)
public UnloadingWeaponEventArgs(Firearm firearm)
{
Firearm = firearm;
Player = player;
IsAllowed = isAllowed;
Player = firearm.Owner;
}

/// <summary>
/// Gets or sets a value indicating whether the weapon can be unloaded.
/// </summary>
public bool IsAllowed { get; set; }
public bool IsAllowed { get; set; } = true;

/// <summary>
/// Gets the <see cref="API.Features.Items.Firearm" /> being unloaded.
Expand Down
2 changes: 1 addition & 1 deletion EXILED/Exiled.Events/Handlers/Player.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1024,7 +1024,7 @@ public static void OnItemAdded(ReferenceHub referenceHub, InventorySystem.Items.
{
ItemAddedEventArgs ev = new(referenceHub, itemBase, pickupBase);

ev.Item.ReadPickupInfo(ev.Pickup);
ev.Item.ReadPickupInfoAfter(ev.Pickup);

ev.Player.ItemsValue.Add(ev.Item);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -220,16 +220,13 @@ private static void ChangeInventory(ChangingRoleEventArgs ev)
inventory.SendAmmoNextFrame = true;
}

if (!StartingInventories.DefinedInventories.TryGetValue(ev.NewRole, out InventoryRoleInfo value))
return;

foreach (KeyValuePair<ItemType, ushort> item in value.Ammo)
inventory.ServerAddAmmo(item.Key, item.Value);
foreach (KeyValuePair<ItemType, ushort> ammo in ev.Ammo)
inventory.ServerAddAmmo(ammo.Key, ammo.Value);

for (int i = 0; i < value.Items.Length; i++)
foreach (ItemType item in ev.Items)
{
ItemBase arg = inventory.ServerAddItem(value.Items[i], ItemAddReason.StartingItem, 0);
InventoryItemProvider.OnItemProvided?.Invoke(ev.Player.ReferenceHub, arg);
ItemBase itemBase = inventory.ServerAddItem(item, ItemAddReason.StartingItem);
InventoryItemProvider.OnItemProvided?.Invoke(ev.Player.ReferenceHub, itemBase);
}

InventoryItemProvider.InventoriesToReplenish.Enqueue(ev.Player.ReferenceHub);
Expand Down
2 changes: 1 addition & 1 deletion EXILED/Exiled.Events/Patches/Events/Player/DryFire.cs
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ private static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstructi
Label ret = newInstructions[newInstructions.Count - 1 + offset].labels[0];

offset = -2;
int index = newInstructions.FindIndex(x => x.Calls(PropertyGetter(typeof(AutomaticActionModule), nameof(AutomaticActionModule.Cocked)))) + offset;
int index = newInstructions.FindLastIndex(x => x.Calls(PropertyGetter(typeof(AutomaticActionModule), nameof(AutomaticActionModule.Cocked)))) + offset;

newInstructions.InsertRange(index, GetInstructions(newInstructions[index], ret));

Expand Down
66 changes: 66 additions & 0 deletions EXILED/Exiled.Events/Patches/Events/Player/ReloadingWeapon.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
// -----------------------------------------------------------------------
// <copyright file="ReloadingWeapon.cs" company="ExMod Team">
// Copyright (c) ExMod Team. All rights reserved.
// Licensed under the CC BY-SA 3.0 license.
// </copyright>
// -----------------------------------------------------------------------

namespace Exiled.Events.Patches.Events.Player
{
using System.Collections.Generic;
using System.Reflection.Emit;

using API.Features.Pools;

using Exiled.API.Extensions;
using Exiled.Events.Attributes;
using Exiled.Events.EventArgs.Player;
using HarmonyLib;
using InventorySystem.Items.Firearms.Modules;

using static HarmonyLib.AccessTools;

/// <summary>
/// Patches <see cref="AnimatorReloaderModuleBase.ServerProcessCmd" />.
/// Adds the <see cref="Handlers.Player.ReloadingWeapon" /> event.
/// </summary>
[EventPatch(typeof(Handlers.Player), nameof(Handlers.Player.ReloadingWeapon))]
[HarmonyPatch(typeof(AnimatorReloaderModuleBase), nameof(AnimatorReloaderModuleBase.ServerProcessCmd))]
internal static class ReloadingWeapon
{
private static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstruction> instructions, ILGenerator generator)
{
List<CodeInstruction> newInstructions = ListPool<CodeInstruction>.Pool.Get(instructions);

int offset = 2;
int index = newInstructions.FindIndex(x => x.Calls(Method(typeof(IReloadUnloadValidatorModule), nameof(IReloadUnloadValidatorModule.ValidateReload)))) + offset;

Label skip = (Label)newInstructions[index - 1].operand;
newInstructions.InsertRange(
index,
new[]
{
// player
new CodeInstruction(OpCodes.Ldarg_0),
new(OpCodes.Callvirt, PropertyGetter(typeof(AnimatorReloaderModuleBase), nameof(AnimatorReloaderModuleBase.Firearm))),

// ReloadingWeaponEventArgs ev = new(firearm)
new(OpCodes.Newobj, GetDeclaredConstructors(typeof(ReloadingWeaponEventArgs))[0]),
new(OpCodes.Dup),

// Player.OnReloadingWeapon(ev)
new(OpCodes.Call, Method(typeof(Handlers.Player), nameof(Handlers.Player.OnReloadingWeapon))),

// if (!ev.IsAllowed)
// goto skip;
new(OpCodes.Callvirt, PropertyGetter(typeof(ReloadingWeaponEventArgs), nameof(ReloadingWeaponEventArgs.IsAllowed))),
new(OpCodes.Brfalse, skip),
});

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

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

0 comments on commit 021f6cc

Please sign in to comment.