diff --git a/SecretAPI.Examples/SecretAPI.Examples.csproj b/SecretAPI.Examples/SecretAPI.Examples.csproj
index a2aeb98..076e87e 100644
--- a/SecretAPI.Examples/SecretAPI.Examples.csproj
+++ b/SecretAPI.Examples/SecretAPI.Examples.csproj
@@ -9,7 +9,7 @@
-
+
diff --git a/SecretAPI/Attribute/CallOnLoadAttribute.cs b/SecretAPI/Attribute/CallOnLoadAttribute.cs
index 7c02d9a..cb55356 100644
--- a/SecretAPI/Attribute/CallOnLoadAttribute.cs
+++ b/SecretAPI/Attribute/CallOnLoadAttribute.cs
@@ -4,12 +4,13 @@
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
+ using SecretAPI.Features;
///
/// Defines the attribute for methods to call on load.
///
[AttributeUsage(AttributeTargets.Method)]
- public class CallOnLoadAttribute : Attribute
+ public class CallOnLoadAttribute : Attribute, IPriority
{
///
/// Initializes a new instance of the class.
@@ -32,9 +33,25 @@ public CallOnLoadAttribute(int priority = 0)
public static void Load(Assembly? assembly = null)
{
assembly ??= Assembly.GetCallingAssembly();
+ CallAttributeMethodPriority(assembly);
+ }
+
+ ///
+ public override bool Equals(object? obj) => obj == this;
+ ///
+ public override int GetHashCode() => base.GetHashCode();
+
+ ///
+ /// Calls the method associated with a Attribute implementing .
+ ///
+ /// The assembly to handle calls from.
+ /// The attribute required for this to be called.
+ internal static void CallAttributeMethodPriority(Assembly assembly)
+ where TAttribute : Attribute, IPriority
+ {
const BindingFlags methodFlags = BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic;
- Dictionary methods = new();
+ Dictionary methods = new();
// get all types
foreach (Type type in assembly.GetTypes())
@@ -42,7 +59,7 @@ public static void Load(Assembly? assembly = null)
// get all static methods
foreach (MethodInfo method in type.GetMethods(methodFlags))
{
- CallOnLoadAttribute? attribute = method.GetCustomAttribute();
+ TAttribute? attribute = method.GetCustomAttribute();
if (attribute == null)
continue;
@@ -50,14 +67,8 @@ public static void Load(Assembly? assembly = null)
}
}
- foreach (KeyValuePair method in methods.OrderBy(static v => v.Key.Priority))
+ foreach (KeyValuePair method in methods.OrderBy(static v => v.Key.Priority))
method.Value.Invoke(null, null);
}
-
- ///
- public override bool Equals(object? obj) => obj == this;
-
- ///
- public override int GetHashCode() => base.GetHashCode();
}
}
\ No newline at end of file
diff --git a/SecretAPI/Attribute/CallOnUnloadAttribute.cs b/SecretAPI/Attribute/CallOnUnloadAttribute.cs
index 2303047..b886d55 100644
--- a/SecretAPI/Attribute/CallOnUnloadAttribute.cs
+++ b/SecretAPI/Attribute/CallOnUnloadAttribute.cs
@@ -1,15 +1,14 @@
namespace SecretAPI.Attribute
{
using System;
- using System.Collections.Generic;
- using System.Linq;
using System.Reflection;
+ using SecretAPI.Features;
///
/// Defines the attribute for methods to call on unload.
///
[AttributeUsage(AttributeTargets.Method)]
- public class CallOnUnloadAttribute : Attribute
+ public class CallOnUnloadAttribute : Attribute, IPriority
{
///
/// Initializes a new instance of the class.
@@ -32,26 +31,7 @@ public CallOnUnloadAttribute(int priority = 0)
public static void Unload(Assembly? assembly = null)
{
assembly ??= Assembly.GetCallingAssembly();
-
- const BindingFlags methodFlags = BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic;
- Dictionary methods = new();
-
- // get all types
- foreach (Type type in assembly.GetTypes())
- {
- // get all static methods
- foreach (MethodInfo method in type.GetMethods(methodFlags))
- {
- CallOnUnloadAttribute? attribute = method.GetCustomAttribute();
- if (attribute == null)
- continue;
-
- methods.Add(attribute, method);
- }
- }
-
- foreach (KeyValuePair method in methods.OrderBy(static v => v.Key.Priority))
- method.Value.Invoke(null, null);
+ CallOnLoadAttribute.CallAttributeMethodPriority(assembly);
}
///
diff --git a/SecretAPI/Extensions/CollectionExtensions.cs b/SecretAPI/Extensions/CollectionExtensions.cs
index b52b2ce..28e1887 100644
--- a/SecretAPI/Extensions/CollectionExtensions.cs
+++ b/SecretAPI/Extensions/CollectionExtensions.cs
@@ -1,5 +1,6 @@
namespace SecretAPI.Extensions
{
+ using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
@@ -16,6 +17,7 @@ public static class CollectionExtensions
/// The collection to pull from.
/// The Type contained by the collection.
/// A random value, default value when empty collection.
+ /// Will occur if the collection is empty.
public static T GetRandomValue(this IEnumerable collection)
{
TryGetRandomValue(collection, out T? value);
diff --git a/SecretAPI/Extensions/RoleExtensions.cs b/SecretAPI/Extensions/RoleExtensions.cs
index 2d8bd28..e436281 100644
--- a/SecretAPI/Extensions/RoleExtensions.cs
+++ b/SecretAPI/Extensions/RoleExtensions.cs
@@ -1,15 +1,17 @@
namespace SecretAPI.Extensions
{
+ using System;
using System.Diagnostics.CodeAnalysis;
using InventorySystem;
- using InventorySystem.Configs;
+ using LabApi.Features.Extensions;
using PlayerRoles;
- using PlayerRoles.FirstPersonControl;
+ using Respawning.Objectives;
using UnityEngine;
///
/// Extensions related to .
///
+ [Obsolete("This no longer provides anything that basegame/LabAPI does not")]
public static class RoleExtensions
{
///
@@ -19,16 +21,18 @@ public static class RoleExtensions
/// The found.
/// The .
/// The role base found, else null.
+ [Obsolete("Use LabApi.Features.Extensions.RoleExtensions.TryGetRoleBase")]
public static bool TryGetRoleBase(this RoleTypeId roleTypeId, [NotNullWhen(true)] out T? role)
- => PlayerRoleLoader.TryGetRoleTemplate(roleTypeId, out role);
+ => LabApi.Features.Extensions.RoleExtensions.TryGetRoleBase(roleTypeId, out role);
///
/// Gets the color of a .
///
/// The role to get color of.
/// The color found, if not found then white.
+ [Obsolete("Use Respawning.Objectives.GetRoleColor")]
public static Color GetColor(this RoleTypeId roleTypeId)
- => TryGetRoleBase(roleTypeId, out PlayerRoleBase? role) ? role.RoleColor : Color.white;
+ => roleTypeId.GetRoleColor();
///
/// Tries to get a random spawn point from a .
@@ -37,24 +41,17 @@ public static Color GetColor(this RoleTypeId roleTypeId)
/// The position found.
/// The rotation found.
/// Whether a spawnpoint was found.
+ [Obsolete("Use LabApi.Features.Extensions.RoleExtensions.TryGetRandomSpawnPoint")]
public static bool GetRandomSpawnPosition(this RoleTypeId role, out Vector3 position, out float horizontalRot)
- {
- if (TryGetRoleBase(role, out IFpcRole? fpc))
- return fpc.SpawnpointHandler.TryGetSpawnpoint(out position, out horizontalRot);
-
- position = Vector3.zero;
- horizontalRot = 0f;
- return false;
- }
+ => role.TryGetRandomSpawnPoint(out position, out horizontalRot);
///
/// Gets the inventory of the specified .
///
/// The .
/// The found.
+ [Obsolete("Use LabApi.Features.Extensions.RoleExtensions.GetInventory")]
public static InventoryRoleInfo GetInventory(this RoleTypeId role)
- => StartingInventories.DefinedInventories.TryGetValue(role, out InventoryRoleInfo info)
- ? info
- : new InventoryRoleInfo([], []);
+ => LabApi.Features.Extensions.RoleExtensions.GetInventory(role);
}
}
\ No newline at end of file
diff --git a/SecretAPI/Extensions/RoomExtensions.cs b/SecretAPI/Extensions/RoomExtensions.cs
index 8ffe917..41629af 100644
--- a/SecretAPI/Extensions/RoomExtensions.cs
+++ b/SecretAPI/Extensions/RoomExtensions.cs
@@ -14,7 +14,9 @@ public static class RoomExtensions
[
RoomName.HczTesla, // Instant death
RoomName.EzEvacShelter, // Stuck permanently
- RoomName.EzCollapsedTunnel // Stuck permanently
+ RoomName.EzCollapsedTunnel, // Stuck permanently
+ RoomName.HczWaysideIncinerator, // Death
+ RoomName.Hcz096, // Void
];
///
diff --git a/SecretAPI/Features/IPriority.cs b/SecretAPI/Features/IPriority.cs
new file mode 100644
index 0000000..f337724
--- /dev/null
+++ b/SecretAPI/Features/IPriority.cs
@@ -0,0 +1,13 @@
+namespace SecretAPI.Features
+{
+ ///
+ /// Handles IPriority.
+ ///
+ public interface IPriority
+ {
+ ///
+ /// Gets the current priority.
+ ///
+ public int Priority { get; }
+ }
+}
\ No newline at end of file
diff --git a/SecretAPI/SecretAPI.csproj b/SecretAPI/SecretAPI.csproj
index 26e8dd1..bfa4f3b 100644
--- a/SecretAPI/SecretAPI.csproj
+++ b/SecretAPI/SecretAPI.csproj
@@ -4,7 +4,7 @@
net48
latest
enable
- 2.0.1
+ 2.0.2
true
@@ -29,7 +29,7 @@
-
+
diff --git a/SecretAPI/SecretApi.cs b/SecretAPI/SecretApi.cs
index 4c12582..6272099 100644
--- a/SecretAPI/SecretApi.cs
+++ b/SecretAPI/SecretApi.cs
@@ -3,6 +3,7 @@
using System;
using System.Reflection;
using HarmonyLib;
+ using LabApi.Features;
using LabApi.Loader.Features.Plugins;
using LabApi.Loader.Features.Plugins.Enums;
using SecretAPI.Attribute;
@@ -28,10 +29,11 @@ public class SecretApi : Plugin
public override Version Version { get; } = Assembly.GetName().Version;
///
- public override Version RequiredApiVersion { get; } = new(LabApi.Features.LabApiProperties.CompiledVersion);
+ public override Version RequiredApiVersion => LabApiProperties.CurrentVersion;
- /*///
- public override bool IsTransparent => true;*/
+ ///
+ /// We use transparent here because this is an API and should not interfere by itself with game logic.
+ public override bool IsTransparent => true;
///
/// Gets the harmony to use for the API.