Skip to content
11 changes: 6 additions & 5 deletions EXILED/Exiled.API/Features/Map.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

namespace Exiled.API.Features
{
#pragma warning disable SA1401
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
Expand Down Expand Up @@ -43,6 +44,11 @@ namespace Exiled.API.Features
/// </summary>
public static class Map
{
/// <summary>
/// Gets a list of <see cref="PocketDimensionTeleport"/>s on the map.
/// </summary>
internal static List<PocketDimensionTeleport> TeleportsValue = new();

private static AmbientSoundPlayer ambientSoundPlayer;

private static SqueakSpawner squeakSpawner;
Expand Down Expand Up @@ -114,11 +120,6 @@ public static bool IsDecontaminationEnabled
/// </summary>
public static SqueakSpawner SqueakSpawner => squeakSpawner ??= Object.FindObjectOfType<SqueakSpawner>();

/// <summary>
/// Gets a list of <see cref="PocketDimensionTeleport"/>s on the map.
/// </summary>
internal static List<PocketDimensionTeleport> TeleportsValue { get; } = new();

/// <summary>
/// Broadcasts a message to all <see cref="Player">players</see>.
/// </summary>
Expand Down
2 changes: 1 addition & 1 deletion EXILED/Exiled.API/Features/Roles/Scp106Role.cs
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ public bool IsSubmerged
public bool SinkholeState
{
get => StalkAbility.StalkActive;
set => StalkAbility.StalkActive = value;
set => StalkAbility.ServerSetStalk(value);
}

/// <summary>
Expand Down
4 changes: 3 additions & 1 deletion EXILED/Exiled.API/Features/Window.cs
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,9 @@ public void DamageWindow(float amount, DamageHandlerBase handler)
RoomType.LczGlassBox => GlassType.GR18,
RoomType.LczPlants => GlassType.Plants,
RoomType.Hcz049 => GlassType.Scp049,
RoomType.Hcz079 => Recontainer.Base._activatorGlass == Base ? GlassType.Scp079Trigger : GlassType.Scp079,

// TODO: Recontainer.Base._activatorGlass == Base ? GlassType.Scp079Trigger : GlassType.Scp079
RoomType.Hcz079 => GlassType.Scp079,
RoomType.HczHid => GlassType.MicroHid,
RoomType.HczTestRoom => GlassType.TestRoom,
RoomType.HczEzCheckpointA => GlassType.HczEzCheckpointA,
Expand Down
3 changes: 1 addition & 2 deletions EXILED/Exiled.Events/EventArgs/Player/SpawningEventArgs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
namespace Exiled.Events.EventArgs.Player
{
using System;
using System.Runtime.CompilerServices;

using Exiled.API.Features;
using Exiled.API.Features.Roles;
Expand Down Expand Up @@ -76,4 +75,4 @@ public SpawningEventArgs(Player player, Vector3 position, float rotation, Player
/// </summary>
public Role NewRole { get; }
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,16 +31,16 @@ public class UpgradingPlayerEventArgs : IPlayerEvent, IDeniableEvent
/// <param name="upgradeItems">
/// <inheritdoc cref="UpgradeItems" />
/// </param>
/// <param name="moveVector">
/// <inheritdoc cref="OutputPosition" />
/// <param name="outputPos">
/// <inheritdoc cref="OutputPosition"/>
/// </param>
public UpgradingPlayerEventArgs(Player player, bool upgradeItems, bool heldOnly, Scp914KnobSetting setting, Vector3 moveVector)
public UpgradingPlayerEventArgs(Player player, bool upgradeItems, bool heldOnly, Scp914KnobSetting setting, Vector3 outputPos)
{
Player = player;
UpgradeItems = upgradeItems;
HeldOnly = heldOnly;
KnobSetting = setting;
OutputPosition = player.Position + moveVector;
OutputPosition = outputPos;
}

/// <summary>
Expand Down
25 changes: 12 additions & 13 deletions EXILED/Exiled.Events/EventArgs/Server/RespawningTeamEventArgs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,25 +29,19 @@ public class RespawningTeamEventArgs : IDeniableEvent
/// <param name="players">
/// <inheritdoc cref="Players" />
/// </param>
/// <param name="queue">
/// <inheritdoc cref="SpawnQueue" />
/// </param>
/// <param name="maxRespawn">
/// <inheritdoc cref="MaximumRespawnAmount" />
/// </param>
/// <param name="nextKnownTeam">
/// <param name="wave">
/// <inheritdoc cref="NextKnownTeam" />
/// </param>
/// <param name="isAllowed">
/// <inheritdoc cref="IsAllowed" />
/// </param>
public RespawningTeamEventArgs(List<Player> players, Queue<RoleTypeId> queue, int maxRespawn, SpawnableWaveBase nextKnownTeam, bool isAllowed = true)
public RespawningTeamEventArgs(List<Player> players, int maxRespawn, SpawnableWaveBase wave)
{
Players = players;
MaximumRespawnAmount = maxRespawn;
SpawnQueue = queue;
NextKnownTeam = nextKnownTeam;
IsAllowed = isAllowed;
SpawnQueue = WaveSpawner.SpawnQueue;
Wave = wave;
IsAllowed = true;
}

/// <summary>
Expand All @@ -74,9 +68,14 @@ public int MaximumRespawnAmount
}

/// <summary>
/// Gets or sets a value indicating what the next respawnable team is.
/// Gets or sets a value indicating what the next wave is.
/// </summary>
public SpawnableWaveBase Wave { get; set; }

/// <summary>
/// Gets a value indicating what the next respawnable team is.
/// </summary>
public SpawnableWaveBase NextKnownTeam { get; set; }
public SpawnableTeamType NextKnownTeam => Wave.TargetFaction.GetSpawnableTeam();

/// <summary>
/// Gets or sets a value indicating whether the spawn can occur.
Expand Down
47 changes: 1 addition & 46 deletions EXILED/Exiled.Events/Handlers/Internal/MapGenerated.cs
Original file line number Diff line number Diff line change
Expand Up @@ -54,52 +54,7 @@ public static void OnMapGenerated()
PlayerRoles.RoleAssign.HumanSpawner.Handlers[PlayerRoles.Team.OtherAlive] = new PlayerRoles.RoleAssign.OneRoleHumanSpawner(PlayerRoles.RoleTypeId.Tutorial);
PlayerRoles.RoleAssign.HumanSpawner.Handlers[PlayerRoles.Team.Dead] = new PlayerRoles.RoleAssign.OneRoleHumanSpawner(PlayerRoles.RoleTypeId.Spectator);

GenerateAttachments();
Timing.CallDelayed(1, GenerateCache);
}

private static void GenerateCache()
{
Handlers.Map.OnGenerated();

Timing.CallDelayed(0.1f, Handlers.Server.OnWaitingForPlayers);
}

private static void GenerateAttachments()
{
foreach (FirearmType firearmType in EnumUtils<FirearmType>.Values)
{
if (firearmType == FirearmType.None)
continue;

if (Item.Create(firearmType.GetItemType()) is not Firearm firearm)
continue;

Firearm.ItemTypeToFirearmInstance.Add(firearmType, firearm);

List<AttachmentIdentifier> attachmentIdentifiers = ListPool<AttachmentIdentifier>.Pool.Get();
HashSet<AttachmentSlot> attachmentsSlots = HashSetPool<AttachmentSlot>.Pool.Get();

uint code = 1;

foreach (Attachment attachment in firearm.Attachments)
{
attachmentsSlots.Add(attachment.Slot);
attachmentIdentifiers.Add(new(code, attachment.Name, attachment.Slot));
code *= 2U;
}

uint baseCode = 0;
attachmentsSlots.ForEach(slot => baseCode += attachmentIdentifiers
.Where(attachment => attachment.Slot == slot)
.Min(slot => slot.Code));

Firearm.BaseCodesValue.Add(firearmType, baseCode);
Firearm.AvailableAttachmentsValue.Add(firearmType, attachmentIdentifiers.ToArray());

ListPool<AttachmentIdentifier>.Pool.Return(attachmentIdentifiers);
HashSetPool<AttachmentSlot>.Pool.Return(attachmentsSlots);
}
Timing.CallDelayed(1, Handlers.Map.OnGenerated);
}
}
}
51 changes: 51 additions & 0 deletions EXILED/Exiled.Events/Handlers/Internal/Round.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,21 +7,31 @@

namespace Exiled.Events.Handlers.Internal
{
using System.Collections.Generic;
using System.Linq;

using CentralAuth;

using Exiled.API.Enums;
using Exiled.API.Extensions;
using Exiled.API.Features;
using Exiled.API.Features.Items;
using Exiled.API.Features.Pools;
using Exiled.API.Features.Roles;
using Exiled.API.Structs;
using Exiled.Events.EventArgs.Player;
using Exiled.Events.EventArgs.Scp049;
using Exiled.Loader;
using Exiled.Loader.Features;
using InventorySystem;
using InventorySystem.Items.Firearms.Attachments;
using InventorySystem.Items.Firearms.Attachments.Components;
using InventorySystem.Items.Usables;
using PlayerRoles;
using PlayerRoles.RoleAssign;

using Utils.NonAllocLINQ;

/// <summary>
/// Handles some round clean-up events and some others related to players.
/// </summary>
Expand All @@ -33,6 +43,7 @@ internal static class Round
/// <inheritdoc cref="Handlers.Server.OnWaitingForPlayers" />
public static void OnWaitingForPlayers()
{
GenerateAttachments();
MultiAdminFeatures.CallEvent(MultiAdminFeatures.EventType.WAITING_FOR_PLAYERS);

if (Events.Instance.Config.ShouldReloadConfigsAtRoundRestart)
Expand Down Expand Up @@ -93,5 +104,45 @@ public static void OnVerified(VerifiedEventArgs ev)
ev.Player.SendFakeSyncVar(room.RoomLightControllerNetIdentity, typeof(RoomLightController), nameof(RoomLightController.NetworkLightsEnabled), false);
}
}

private static void GenerateAttachments()
{
foreach (FirearmType firearmType in EnumUtils<FirearmType>.Values)
{
if (firearmType == FirearmType.None)
continue;

Log.Warn(firearmType.GetItemType());
Log.Warn(Server.Host == null);

if (Item.Create(firearmType.GetItemType()) is not Firearm firearm)
continue;

Firearm.ItemTypeToFirearmInstance.Add(firearmType, firearm);

List<AttachmentIdentifier> attachmentIdentifiers = ListPool<AttachmentIdentifier>.Pool.Get();
HashSet<AttachmentSlot> attachmentsSlots = HashSetPool<AttachmentSlot>.Pool.Get();

uint code = 1;

foreach (Attachment attachment in firearm.Attachments)
{
attachmentsSlots.Add(attachment.Slot);
attachmentIdentifiers.Add(new(code, attachment.Name, attachment.Slot));
code *= 2U;
}

uint baseCode = 0;
attachmentsSlots.ForEach(slot => baseCode += attachmentIdentifiers
.Where(attachment => attachment.Slot == slot)
.Min(slot => slot.Code));

Firearm.BaseCodesValue.Add(firearmType, baseCode);
Firearm.AvailableAttachmentsValue.Add(firearmType, attachmentIdentifiers.ToArray());

ListPool<AttachmentIdentifier>.Pool.Return(attachmentIdentifiers);
HashSetPool<AttachmentSlot>.Pool.Return(attachmentsSlots);
}
}
}
}
2 changes: 1 addition & 1 deletion EXILED/Exiled.Events/Patches/Events/Map/FillingLocker.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ private static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstructi
new[]
{
// FillingLockerEventArgs ev = new(ItemPickupBase, loockerChamber)
new(OpCodes.Ldloc_S, 4),
new(OpCodes.Ldloc_S, 5),
new(OpCodes.Ldarg_0),
new CodeInstruction(OpCodes.Newobj, GetDeclaredConstructors(typeof(FillingLockerEventArgs))[0]),
new(OpCodes.Dup),
Expand Down
16 changes: 4 additions & 12 deletions EXILED/Exiled.Events/Patches/Events/Map/SpawningTeamVehicle.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ private static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstructi
Label retLabel = generator.DefineLabel();
Label continueLabel = generator.DefineLabel();

LocalBuilder ev = generator.DeclareLocal(typeof(SpawningTeamVehicleEventArgs));
LocalBuilder msg = generator.DeclareLocal(typeof(WaveUpdateMessage));

int offset = 1;
Expand All @@ -47,21 +46,19 @@ private static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstructi

// if (type != RespawnEffectsController.EffectType.Selection)
// goto continueLabel;
new(OpCodes.Ldloc_S, msg.LocalIndex),
new(OpCodes.Ldloca_S, msg.LocalIndex),
new(OpCodes.Callvirt, PropertyGetter(typeof(WaveUpdateMessage), nameof(WaveUpdateMessage.IsTrigger))),
new(OpCodes.Brfalse_S, continueLabel),

// team
new(OpCodes.Ldarg_1),
// wave
new(OpCodes.Ldarg_0),

// true
new(OpCodes.Ldc_I4_1),

// SpawningTeamVehicleEventArgs ev = new(SpawnableTeamType, bool);
// SpawningTeamVehicleEventArgs ev = new(SpawnableWaveBase, bool);
new(OpCodes.Newobj, GetDeclaredConstructors(typeof(SpawningTeamVehicleEventArgs))[0]),
new(OpCodes.Dup),
new(OpCodes.Dup),
new(OpCodes.Stloc_S, ev.LocalIndex),

// Handlers.Map.OnSpawningTeamVehicle(ev);
new(OpCodes.Call, Method(typeof(Handlers.Map), nameof(Handlers.Map.OnSpawningTeamVehicle))),
Expand All @@ -71,11 +68,6 @@ private static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstructi
new(OpCodes.Callvirt, PropertyGetter(typeof(SpawningTeamVehicleEventArgs), nameof(SpawningTeamVehicleEventArgs.IsAllowed))),
new(OpCodes.Brfalse_S, retLabel),

// team = ev.Team
new(OpCodes.Ldloc_S, ev),
new(OpCodes.Callvirt, PropertyGetter(typeof(SpawningTeamVehicleEventArgs), nameof(SpawningTeamVehicleEventArgs.Team))),
new(OpCodes.Starg_S, 1),

new CodeInstruction(OpCodes.Ldloc_S, msg.LocalIndex).WithLabels(continueLabel),
});

Expand Down
Loading