Skip to content

Commit f67ab6a

Browse files
committed
Removed unusued utilities (including the entire Generation namespace - replaced by UniqueList<T>), added docs to I think every method + general code cleanup.
1 parent 70ca6fd commit f67ab6a

58 files changed

Lines changed: 3225 additions & 2665 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.editorconfig

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
[*.cs]
2+
3+
# CS8618: Non-nullable field must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring as nullable.
4+
dotnet_diagnostic.CS8618.severity = none

LabExtended.sln

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11

22
Microsoft Visual Studio Solution File, Format Version 12.00
3+
# Visual Studio Version 18
4+
VisualStudioVersion = 18.0.11012.119 d18.0
5+
MinimumVisualStudioVersion = 10.0.40219.1
36
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "LabExtended", "LabExtended\LabExtended.csproj", "{2B2B3DCB-2B69-488F-8D9F-ACC001F4E9E2}"
47
EndProject
58
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "LabExtended.ImageConvertor", "LabExtended.ImageConvertor\LabExtended.ImageConvertor.csproj", "{01637DCD-155C-4458-BEE8-1B3C1BF8149F}"
@@ -10,13 +13,19 @@ Global
1013
Release|Any CPU = Release|Any CPU
1114
EndGlobalSection
1215
GlobalSection(ProjectConfigurationPlatforms) = postSolution
13-
{2B2B3DCB-2B69-488F-8D9F-ACC001F4E9E2}.Release|Any CPU.ActiveCfg = Release|Any CPU
14-
{2B2B3DCB-2B69-488F-8D9F-ACC001F4E9E2}.Release|Any CPU.Build.0 = Release|Any CPU
1516
{2B2B3DCB-2B69-488F-8D9F-ACC001F4E9E2}.Debug|Any CPU.ActiveCfg = Release|Any CPU
1617
{2B2B3DCB-2B69-488F-8D9F-ACC001F4E9E2}.Debug|Any CPU.Build.0 = Release|Any CPU
18+
{2B2B3DCB-2B69-488F-8D9F-ACC001F4E9E2}.Release|Any CPU.ActiveCfg = Release|Any CPU
19+
{2B2B3DCB-2B69-488F-8D9F-ACC001F4E9E2}.Release|Any CPU.Build.0 = Release|Any CPU
1720
{01637DCD-155C-4458-BEE8-1B3C1BF8149F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
1821
{01637DCD-155C-4458-BEE8-1B3C1BF8149F}.Debug|Any CPU.Build.0 = Debug|Any CPU
1922
{01637DCD-155C-4458-BEE8-1B3C1BF8149F}.Release|Any CPU.ActiveCfg = Release|Any CPU
2023
{01637DCD-155C-4458-BEE8-1B3C1BF8149F}.Release|Any CPU.Build.0 = Release|Any CPU
2124
EndGlobalSection
25+
GlobalSection(SolutionProperties) = preSolution
26+
HideSolutionNode = FALSE
27+
EndGlobalSection
28+
GlobalSection(ExtensibilityGlobals) = postSolution
29+
SolutionGuid = {CAA4E5D4-59F5-4A6A-AD9E-580E9CC46365}
30+
EndGlobalSection
2231
EndGlobal

LabExtended/.idea/.idea.LabExtended.dir/.idea/.gitignore

Lines changed: 0 additions & 13 deletions
This file was deleted.

LabExtended/API/Collections/Unsafe/UnsafeEnumerator.cs

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,13 @@
22

33
namespace LabExtended.API.Collections.Unsafe;
44

5+
/// <summary>
6+
/// Provides an enumerator for iterating over the elements of an UnsafeList{T} without thread safety guarantees.
7+
/// </summary>
8+
/// <remarks>This enumerator does not provide thread safety. Modifying the underlying UnsafeList{T} during
9+
/// enumeration may result in undefined behavior. The enumerator is intended for performance-critical scenarios where
10+
/// thread safety is managed externally or is not required.</remarks>
11+
/// <typeparam name="T">The type of elements in the collection to enumerate.</typeparam>
512
public struct UnsafeEnumerator<T> : IEnumerator<T>, IEnumerator
613
{
714
internal static volatile IEnumerator<T> emptyEnumerator = new UnsafeEnumerator<T>();
@@ -10,6 +17,11 @@ public struct UnsafeEnumerator<T> : IEnumerator<T>, IEnumerator
1017
private volatile int index;
1118
private T? current;
1219

20+
/// <summary>
21+
/// Initializes a new instance of the UnsafeEnumerator{T} class for the specified list.
22+
/// </summary>
23+
/// <param name="list">The UnsafeList{T} to enumerate. Cannot be null.</param>
24+
/// <exception cref="ArgumentNullException">Thrown if the list parameter is null.</exception>
1325
public UnsafeEnumerator(UnsafeList<T> list)
1426
{
1527
if (list is null)
@@ -38,7 +50,7 @@ public UnsafeEnumerator(UnsafeList<T> list)
3850
/// <inheritdoc cref="IDisposable.Dispose"/>
3951
public void Dispose() { }
4052

41-
/// <inheritdoc cref="IEnumerator{T}.MoveNext"/>
53+
/// <inheritdoc cref="IEnumerator.MoveNext"/>
4254
public bool MoveNext()
4355
{
4456
if (((uint)index < (uint)list.size))

LabExtended/API/Collections/Unsafe/UnsafeList.cs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,16 @@
44
namespace LabExtended.API.Collections.Unsafe;
55

66
/// <summary>
7-
/// An unsafe version of <see cref="List{T}"/> which ignores modifications made during enumeration. As an addition, volatile operations are allowed.
7+
/// Represents a high-performance, array-backed list of elements that provides fast, low-level access and manipulation
8+
/// without built-in thread safety or bounds checking. Intended for scenarios where maximum performance is required and
9+
/// the caller is responsible for ensuring correct usage.
810
/// </summary>
9-
/// <typeparam name="T">The type of the list's object.</typeparam>
11+
/// <remarks>UnsafeList{T} is similar to List{T} but omits certain safety checks and thread synchronization to
12+
/// maximize performance. It is not thread-safe and does not perform bounds checking on all operations; callers must
13+
/// ensure that indices and capacities are valid. This type is suitable for advanced scenarios where the overhead of
14+
/// additional safety is undesirable and the caller can guarantee correct usage. Modifying the collection while
15+
/// enumerating it is not supported and may result in undefined behavior.</remarks>
16+
/// <typeparam name="T">The type of elements stored in the list.</typeparam>
1017
public class UnsafeList<T> : IList<T>, IList, IReadOnlyList<T>
1118
{
1219
/// <summary>

LabExtended/API/Collections/Updateable/UpdateableList.cs

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,21 @@
1-
using LabExtended.API.Collections.Unsafe;
21
using LabExtended.Core;
32
using LabExtended.Extensions;
43
using LabExtended.Utilities.Update;
4+
using LabExtended.API.Collections.Unsafe;
55

66
using UnityEngine;
77

88
namespace LabExtended.API.Collections.Updateable;
99

1010
/// <summary>
11-
/// Represents a list of updateable elements. Wraps around <see cref="UnsafeList{T}"/>.
11+
/// Represents a list of elements that can be updated at a specified interval and provides events for element and list
12+
/// updates.
1213
/// </summary>
13-
/// <typeparam name="T">The element type.</typeparam>
14+
/// <remarks>The update loop is managed automatically after calling <see cref="Initialize"/>, which subscribes the
15+
/// list to periodic updates. The <see cref="Updated"/> event is raised after each update cycle, and the <see
16+
/// cref="ElementUpdated"/> event is raised for each element as it is updated. Call <see cref="Dispose"/> to unsubscribe
17+
/// the list from updates and release resources. This class is not thread-safe.</remarks>
18+
/// <typeparam name="T">The type of elements in the list. Must implement <see cref="IUpdateableElement"/>.</typeparam>
1419
public class UpdateableList<T> : UnsafeList<T>, IDisposable
1520
where T : IUpdateableElement
1621
{

LabExtended/API/Containers/InventoryContainer.cs

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66
using InventorySystem.Items.Keycards;
77
using InventorySystem.Items.Pickups;
88

9-
using LabExtended.Utilities.Keycards;
109
using LabExtended.Extensions;
10+
using LabExtended.API.CustomAmmo;
1111

1212
using UnityEngine;
1313

@@ -16,10 +16,8 @@
1616
using PlayerRoles.FirstPersonControl;
1717

1818
using InventorySystem.Items.Usables;
19-
using LabExtended.API.CustomAmmo;
2019

2120
#pragma warning disable CS8603 // Possible null reference return.
22-
2321
#pragma warning disable CS8625 // Cannot convert null literal to non-nullable reference type.
2422

2523
namespace LabExtended.API.Containers;
@@ -153,7 +151,7 @@ public ItemBase? this[ushort itemSerial]
153151
/// Gets permissions of the currently held keycard. <i>(<see cref="DoorPermissionFlags.None"/> if the player isn't holding a keycard)</i>.
154152
/// </summary>
155153
public DoorPermissionFlags HeldKeycardPermissions =>
156-
CurrentItem is KeycardItem keycardItem && keycardItem.TryGetDetail<PredefinedPermsDetail>(out var perms)
154+
CurrentItem is KeycardItem keycardItem && keycardItem.Details.TryGetFirst<PredefinedPermsDetail>(out var perms)
157155
? perms.Levels.Permissions
158156
: DoorPermissionFlags.None;
159157

@@ -228,7 +226,7 @@ public DoorPermissionFlags AllKeycardPermissions
228226

229227
foreach (var keycard in Keycards)
230228
{
231-
if (!keycard.TryGetDetail<PredefinedPermsDetail>(out var cardPerms))
229+
if (!keycard.Details.TryGetFirst<PredefinedPermsDetail>(out var cardPerms))
232230
continue;
233231

234232
perms |= cardPerms.Levels.Permissions;
@@ -399,7 +397,7 @@ public bool HasItems(ItemType type, int count)
399397
public bool HasKeycardPermission(DoorPermissionFlags keycardPermissions, bool anyPermission = false)
400398
=> Keycards.Any(card =>
401399
{
402-
if (!card.TryGetDetail<PredefinedPermsDetail>(out var cardPerms))
400+
if (!card.Details.TryGetFirst<PredefinedPermsDetail>(out var cardPerms))
403401
return false;
404402

405403
return anyPermission

LabExtended/API/CustomItems/CustomItemRegistry.cs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,24 @@
11
using System.Reflection;
2+
23
using HarmonyLib;
4+
35
using InventorySystem;
46
using InventorySystem.Items;
57
using InventorySystem.Items.Armor;
8+
69
using LabApi.Events.Arguments.PlayerEvents;
710
using LabApi.Events.Arguments.Scp914Events;
811

912
using LabApi.Events.Handlers;
10-
using LabApi.Features.Wrappers;
1113
using LabExtended.API.CustomItems.Behaviours;
1214

1315
using LabExtended.Core;
1416
using LabExtended.Events;
1517
using LabExtended.Attributes;
1618
using LabExtended.Events.Map;
1719
using LabExtended.Extensions;
20+
1821
using LabExtended.Utilities;
19-
using LabExtended.Utilities.Testing.CustomItems;
2022
using LabExtended.Utilities.Update;
2123

2224
using NorthwoodLib.Pools;
@@ -564,9 +566,6 @@ private static void OnDiscovered(Type type)
564566
if (type.GetCustomAttribute<LoaderIgnoreAttribute>() != null)
565567
return;
566568

567-
if (type == typeof(TestCustomItemHandler) && !TestCustomItemHandler.IsEnabled)
568-
return;
569-
570569
var constructor = AccessTools.DeclaredConstructor(type);
571570

572571
if (constructor is null)

LabExtended/API/FileStorage/FileStorageManager.cs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
using LabExtended.Events.Player;
99

1010
using LabExtended.Utilities;
11-
using LabExtended.Utilities.Testing.FileStorage;
1211

1312
namespace LabExtended.API.FileStorage;
1413

@@ -403,9 +402,6 @@ private static void OnDiscovered(Type type)
403402

404403
if (type.HasAttribute<LoaderIgnoreAttribute>())
405404
return;
406-
407-
if (type == typeof(TestFileStorageComponent) && !TestFileStorageComponent.IsEnabled)
408-
return;
409405

410406
Components.Add(type);
411407

LabExtended/API/RemoteAdmin/RemoteAdminController.cs

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -9,22 +9,21 @@
99
using LabExtended.API.RemoteAdmin.Interfaces;
1010

1111
using LabExtended.Events;
12+
using LabExtended.Attributes;
1213
using LabExtended.Extensions;
1314

1415
using LabExtended.Utilities.Update;
15-
using LabExtended.Utilities.Generation;
16-
17-
using NorthwoodLib.Pools;
1816

1917
using LabExtended.API.RemoteAdmin.Actions;
2018
using LabExtended.API.RemoteAdmin.Buttons;
2119

22-
using LabExtended.Attributes;
23-
2420
using NetworkManagerUtils.Dummies;
2521

2622
using RemoteAdmin.Communication;
2723

24+
using LabExtended.Utilities;
25+
using NorthwoodLib.Pools;
26+
2827
#pragma warning disable CS8601 // Possible null reference assignment.
2928
#pragma warning disable CS8625 // Cannot convert null literal to non-nullable reference type.
3029

@@ -50,8 +49,8 @@ public class RemoteAdminController : IDisposable
5049
/// </summary>
5150
public const string OverwatchIconPrefix = "<link=RA_OverwatchEnabled><color=white>[</color><color=#03f8fc>\uf06e</color><color=white>]</color></link> ";
5251

53-
private static readonly UniqueStringGenerator objectIdGenerator = new(10, false);
54-
private static readonly UniqueInt32Generator listIdGenerator = new(6000, 11000);
52+
private static readonly UniqueList objectIdGenerator = new();
53+
private static readonly UniqueList listIdGenerator = new();
5554

5655
// ReSharper disable once CollectionNeverUpdated.Local
5756
private static readonly HashSet<Type> globalObjects = new();
@@ -174,8 +173,8 @@ public void Dispose()
174173
obj.OnDisabled();
175174
}
176175

177-
objectIdGenerator.Free(obj.Id);
178-
listIdGenerator.Free(obj.ListId);
176+
listIdGenerator.Generated.Remove(obj.Id);
177+
objectIdGenerator.Generated.Remove(obj.Id);
179178
}
180179

181180
ListPool<IRemoteAdminObject>.Shared.Return(Objects);
@@ -209,8 +208,8 @@ public IRemoteAdminObject AddObject(Type objectType, string? customId = null)
209208

210209
raObject.CustomId = customId;
211210

212-
raObject.Id = objectIdGenerator.Next();
213-
raObject.ListId = listIdGenerator.Next();
211+
raObject.Id = objectIdGenerator.GetString(10);
212+
raObject.ListId = listIdGenerator.Get(() => UnityEngine.Random.Range(6000, 11000));
214213

215214
raObject.IsActive = true;
216215
raObject.OnEnabled();
@@ -256,9 +255,9 @@ public void AddObject(IRemoteAdminObject remoteAdminObject)
256255
}
257256

258257
if (string.IsNullOrWhiteSpace(remoteAdminObject.Id))
259-
remoteAdminObject.Id = objectIdGenerator.Next();
258+
remoteAdminObject.Id = objectIdGenerator.GetString(10);
260259

261-
remoteAdminObject.ListId = listIdGenerator.Next();
260+
remoteAdminObject.ListId = listIdGenerator.Get(() => UnityEngine.Random.Range(6000, 11000));
262261

263262
Objects.Add(remoteAdminObject);
264263
}
@@ -280,8 +279,8 @@ public bool RemoveObject(IRemoteAdminObject remoteAdminObject)
280279
remoteAdminObject.OnDisabled();
281280
}
282281

283-
objectIdGenerator.Free(remoteAdminObject.Id);
284-
listIdGenerator.Free(remoteAdminObject.ListId);
282+
objectIdGenerator.Generated.Remove(remoteAdminObject.Id);
283+
listIdGenerator.Generated.Remove(remoteAdminObject.ListId);
285284

286285
return Objects.Remove(remoteAdminObject);
287286
}

0 commit comments

Comments
 (0)