Skip to content

Commit

Permalink
Merge branch 'dev' into sendingcommandevent
Browse files Browse the repository at this point in the history
  • Loading branch information
Mar1ki authored Jan 4, 2025
2 parents 06a15c0 + 111a848 commit e5d45bb
Show file tree
Hide file tree
Showing 68 changed files with 1,053 additions and 549 deletions.
2 changes: 1 addition & 1 deletion .github/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ Localized READMEs
<div>
<img src="https://flagsapi.com/DE/flat/64.png" height=30>
<br>
<a href="documentation/localization/README-DE.md">German</a>
<a href="documentation/localization/README-DE.md">Deutsch</a>
</div>
<br>
<div>
Expand Down
12 changes: 6 additions & 6 deletions EXILED/Exiled.API/Enums/SpawnLocationType.cs
Original file line number Diff line number Diff line change
Expand Up @@ -124,19 +124,19 @@ public enum SpawnLocationType
InsideHczArmory,

/// <summary>
/// Inside the Micro-HID room.
/// Inside the chamber that contains the Micro-HID in Micro-HID room.
/// </summary>
InsideHid,
InsideHidChamber,

/// <summary>
/// Just inside the left door next to Micro-HID room.
/// Inside the lower door that leads to the stairs in Micro-HID room.
/// </summary>
InsideHidLeft,
InsideHidLower,

/// <summary>
/// Just inside the right door next to Micro-HID room.
/// Inside the upper door that leads into the Micro-HID room just after the stairs.
/// </summary>
InsideHidRight,
InsideHidUpper,

/// <summary>
/// Just inside the LCZ WC door.
Expand Down
1 change: 1 addition & 0 deletions EXILED/Exiled.API/Exiled.API.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
<Reference Include="UnityEngine.CoreModule" HintPath="$(EXILED_REFERENCES)\UnityEngine.CoreModule.dll" Private="false" />
<Reference Include="UnityEngine.ParticleSystemModule" HintPath="$(EXILED_REFERENCES)\UnityEngine.ParticleSystemModule.dll" Private="false" />
<Reference Include="UnityEngine.PhysicsModule" HintPath="$(EXILED_REFERENCES)\UnityEngine.PhysicsModule.dll" Private="false" />
<Reference Include="UnityEngine.AudioModule" HintPath="$(EXILED_REFERENCES)\UnityEngine.AudioModule.dll" Private="false" />
<Reference Include="YamlDotNet" HintPath="$(EXILED_REFERENCES)\YamlDotNet.dll" Private="false" />
</ItemGroup>

Expand Down
11 changes: 5 additions & 6 deletions EXILED/Exiled.API/Extensions/SpawnExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,16 +25,15 @@ public static class SpawnExtensions
{
SpawnLocationType.InsideHczArmory,
SpawnLocationType.Inside079First,
SpawnLocationType.InsideHidRight,
SpawnLocationType.InsideHidUpper,
SpawnLocationType.Inside173Gate,
SpawnLocationType.InsideHidLeft,
SpawnLocationType.InsideGateA,
SpawnLocationType.InsideGateB,
SpawnLocationType.InsideLczWc,
SpawnLocationType.InsideGr18,
SpawnLocationType.Inside914,
SpawnLocationType.InsideHid,
SpawnLocationType.Inside049Armory,
SpawnLocationType.InsideLczCafe,
};

/// <summary>
Expand Down Expand Up @@ -81,16 +80,16 @@ public static Vector3 GetPosition(this SpawnLocationType location)
SpawnLocationType.Inside330 => "330",
SpawnLocationType.Inside096 => "096",
SpawnLocationType.Inside914 => "914",
SpawnLocationType.InsideHid => "HID",
SpawnLocationType.InsideHidChamber => "HID_CHAMBER",
SpawnLocationType.InsideGr18 => "GR18",
SpawnLocationType.InsideGateA => "GATE_A",
SpawnLocationType.InsideGateB => "GATE_B",
SpawnLocationType.InsideLczWc => "LCZ_WC",
SpawnLocationType.InsideHidLeft => "HID_LEFT",
SpawnLocationType.InsideHidLower => "HID_LOWER",
SpawnLocationType.InsideLczCafe => "LCZ_CAFE",
SpawnLocationType.Inside173Gate => "173_GATE",
SpawnLocationType.InsideIntercom => "INTERCOM",
SpawnLocationType.InsideHidRight => "HID_RIGHT",
SpawnLocationType.InsideHidUpper => "HID_UPPER",
SpawnLocationType.Inside079First => "079_FIRST",
SpawnLocationType.Inside330Chamber => "330_CHAMBER",
SpawnLocationType.Inside049Armory => "049_ARMORY",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ internal ButtonSetting(SSButton settingBase)
{
Base = settingBase;

if (OriginalDefinition.Is(out ButtonSetting setting))
if (OriginalDefinition != null && OriginalDefinition.Is(out ButtonSetting setting))
{
Text = setting.Text;
HoldTime = setting.HoldTime;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ internal DropdownSetting(SSDropdownSetting settingBase)
{
Base = settingBase;

if (OriginalDefinition.Is(out DropdownSetting dropdown))
if (OriginalDefinition != null && OriginalDefinition.Is(out DropdownSetting dropdown))
{
Options = dropdown.Options;
}
Expand Down
41 changes: 16 additions & 25 deletions EXILED/Exiled.API/Features/Core/UserSettings/SettingBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -225,39 +225,28 @@ public static void SendToAll(Func<Player, bool> predicate)
/// <remarks>This method is used to sync new settings with players.</remarks>
public static IEnumerable<SettingBase> Register(IEnumerable<SettingBase> settings, Func<Player, bool> predicate = null)
{
List<SettingBase> list = ListPool<SettingBase>.Pool.Get(settings);
List<SettingBase> list2 = new(list.Count);
IEnumerable<IGrouping<HeaderSetting, SettingBase>> grouped = settings.Where(s => s != null).GroupBy(s => s.Header);

while (list.Exists(x => x.Header != null))
{
SettingBase setting = list.Find(x => x.Header != null);
SettingBase header = list.Find(x => x == setting.Header);
List<SettingBase> range = list.FindAll(x => x.Header?.Id == setting.Header.Id);
List<SettingBase> result = new();

list2.Add(header);
list2.AddRange(range);
// Group settings by headers
foreach (IGrouping<HeaderSetting, SettingBase> grouping in grouped)
{
if (grouping.Key != null)
result.Add(grouping.Key);

list.Remove(header);
list.RemoveAll(x => x.Header?.Id == setting.Header.Id);
result.AddRange(grouping);
}

list2.AddRange(list);

List<ServerSpecificSettingBase> list3 = ListPool<ServerSpecificSettingBase>.Pool.Get(ServerSpecificSettingsSync.DefinedSettings ?? Array.Empty<ServerSpecificSettingBase>());
list3.AddRange(list2.Select(x => x.Base));

ServerSpecificSettingsSync.DefinedSettings = list3.ToArray();
Settings.AddRange(list2);
ServerSpecificSettingsSync.DefinedSettings = (ServerSpecificSettingsSync.DefinedSettings ?? Array.Empty<ServerSpecificSettingBase>()).Concat(result.Select(s => s.Base)).ToArray();
Settings.AddRange(result);

if (predicate == null)
SendToAll();
else
SendToAll(predicate);

ListPool<ServerSpecificSettingBase>.Pool.Return(list3);
ListPool<SettingBase>.Pool.Return(list);

return list2;
return result;
}

/// <summary>
Expand Down Expand Up @@ -311,7 +300,7 @@ internal static void OnSettingUpdated(ReferenceHub hub, ServerSpecificSettingBas
ReceivedSettings.Add(player, new() { setting });

if (setting.Is(out ButtonSetting _))
setting.OriginalDefinition.OnChanged?.Invoke(player, setting);
goto invoke;

return;
}
Expand All @@ -322,13 +311,15 @@ internal static void OnSettingUpdated(ReferenceHub hub, ServerSpecificSettingBas
list.Add(setting);

if (setting.Is(out ButtonSetting _))
setting.OriginalDefinition.OnChanged?.Invoke(player, setting);
goto invoke;

return;
}

setting = list.Find(x => x.Id == settingBase.SettingId);

invoke:

if (setting.OriginalDefinition == null)
{
Settings.Add(Create(settingBase.OriginalDefinition));
Expand All @@ -337,4 +328,4 @@ internal static void OnSettingUpdated(ReferenceHub hub, ServerSpecificSettingBas
setting.OriginalDefinition?.OnChanged?.Invoke(player, setting);
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ internal TwoButtonsSetting(SSTwoButtonsSetting settingBase)
{
Base = settingBase;

if (OriginalDefinition.Is(out TwoButtonsSetting setting))
if (OriginalDefinition != null && OriginalDefinition.Is(out TwoButtonsSetting setting))
{
FirstOption = setting.FirstOption;
SecondOption = setting.SecondOption;
Expand Down
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
6 changes: 4 additions & 2 deletions EXILED/Exiled.API/Features/Items/Firearm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ namespace Exiled.API.Features.Items
using Extensions;
using InventorySystem;
using InventorySystem.Items;
using InventorySystem.Items.Autosync;
using InventorySystem.Items.Firearms;
using InventorySystem.Items.Firearms.Attachments;
using InventorySystem.Items.Firearms.Attachments.Components;
Expand Down Expand Up @@ -690,6 +691,7 @@ public override Item Clone()
/// <param name="newOwner">new <see cref="Firearm"/> owner.</param>
internal override void ChangeOwner(Player oldOwner, Player newOwner)
{
Base.InstantiationStatus = newOwner == Server.Host ? AutosyncInstantiationStatus.SimulatedInstance : AutosyncInstantiationStatus.InventoryInstance;
Base.Owner = newOwner.ReferenceHub;
Base._footprintCacheSet = false;
foreach (ModuleBase module in Base.Modules)
Expand All @@ -699,9 +701,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
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ public override bool IsCocked

set
{
PumpBarrel.SyncCocked = MaxAmmo;
PumpBarrel.SyncCocked = value ? MaxAmmo : 0;
Resync();
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,16 @@ public override int MaxAmmo
set => MagazineModule._defaultCapacity = value;
}

/// <inheritdoc/>
public override int Ammo
{
set
{
MagazineModule.SyncData[MagazineModule.ItemSerial] = Math.Max(value, 0) + 1;
Resync();
}
}

/// <inheritdoc/>
public override int ConstantMaxAmmo => MagazineModule._defaultCapacity;

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
70 changes: 48 additions & 22 deletions EXILED/Exiled.API/Features/Items/Item.cs
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@ public Item(ItemBase itemBase)
ushort serial = ItemSerialGenerator.GenerateNext();
Serial = serial;
itemBase.OnAdded(null);
if (Base is ModularAutosyncItem syncItem)
syncItem.InstantiationStatus = AutosyncInstantiationStatus.SimulatedInstance;
#if DEBUG
Log.Debug($"{nameof(Item)}.ctor: Generating new serial number. Serial should now be: {serial}. // {Serial}");
#endif
Expand Down Expand Up @@ -293,28 +295,34 @@ public static T Get<T>(ushort serial)
/// <param name="type">The <see cref="ItemType"/> of the item to create.</param>
/// <param name="owner">The <see cref="Player"/> who owns the item by default.</param>
/// <returns>The <see cref="Item"/> created. This can be cast as a subclass.</returns>
public static Item Create(ItemType type, Player owner = null) => type switch
public static Item Create(ItemType type, Player owner = null) => type.GetTemplate() switch
{
ItemType.SCP268 => new Usable(type),
ItemType.Adrenaline or ItemType.Medkit or ItemType.Painkillers or ItemType.SCP500 or ItemType.SCP207 or ItemType.SCP1853 or ItemType.AntiSCP207 => new Consumable(type),
ItemType.SCP244a or ItemType.SCP244b => new Scp244(type),
ItemType.Ammo9x19 or ItemType.Ammo12gauge or ItemType.Ammo44cal or ItemType.Ammo556x45 or ItemType.Ammo762x39 => new Ammo(type),
ItemType.Flashlight or ItemType.Lantern => new Flashlight(type),
ItemType.Radio => new Radio(),
ItemType.MicroHID => new MicroHid(),
ItemType.GrenadeFlash => new FlashGrenade(owner),
ItemType.GrenadeHE => new ExplosiveGrenade(type, owner),
ItemType.SCP018 => new Scp018(type, owner),
ItemType.GunCrossvec or ItemType.GunLogicer or ItemType.GunRevolver or ItemType.GunShotgun or ItemType.GunAK or ItemType.GunCOM15 or ItemType.GunCOM18 or ItemType.GunCom45 or ItemType.GunE11SR or ItemType.GunFSP9 or ItemType.ParticleDisruptor or ItemType.GunA7 or ItemType.GunFRMG0 => new Firearm(type),
ItemType.KeycardGuard or ItemType.KeycardJanitor or ItemType.KeycardO5 or ItemType.KeycardScientist or ItemType.KeycardChaosInsurgency or ItemType.KeycardContainmentEngineer or ItemType.KeycardFacilityManager or ItemType.KeycardResearchCoordinator or ItemType.KeycardZoneManager or ItemType.KeycardMTFPrivate or ItemType.KeycardMTFOperative or
ItemType.KeycardMTFCaptain => new Keycard(type),
ItemType.ArmorLight or ItemType.ArmorCombat or ItemType.ArmorHeavy => new Armor(type),
ItemType.SCP330 => new Scp330(),
ItemType.SCP2176 => new Scp2176(owner),
ItemType.SCP1576 => new Scp1576(),
ItemType.SCP1344 => new Scp1344(),
ItemType.Jailbird => new Jailbird(),
_ => new Item(type),
InventorySystem.Items.Firearms.Firearm => new Firearm(type),
KeycardItem => new Keycard(type),
UsableItem usable => usable switch
{
Scp330Bag => new Scp330(),
Scp244Item => new Scp244(type),
Scp1576Item => new Scp1576(),
Scp1344Item => new Scp1344(),
BaseConsumable => new Consumable(type),
_ => new Usable(type),
},
RadioItem => new Radio(),
MicroHIDItem => new MicroHid(),
BodyArmor => new Armor(type),
AmmoItem => new Ammo(type),
ToggleableLightItemBase => new Flashlight(type),
JailbirdItem => new Jailbird(),
ThrowableItem throwable => throwable.Projectile switch
{
FlashbangGrenade => new FlashGrenade(owner),
ExplosionGrenade => new ExplosiveGrenade(type, owner),
Scp2176Projectile => new Scp2176(owner),
Scp018Projectile => new Scp018(type, owner),
_ => new Throwable(type, owner),
},
_ => new(type),
};

/// <summary>
Expand Down Expand Up @@ -429,12 +437,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)
{
}
}
}
Loading

0 comments on commit e5d45bb

Please sign in to comment.