Skip to content
This repository has been archived by the owner on Jan 19, 2025. It is now read-only.

Commit

Permalink
Merge remote-tracking branch 'origin/apis-rework' into apis-rework
Browse files Browse the repository at this point in the history
  • Loading branch information
NaoUnderscore committed May 24, 2024
2 parents 772dee4 + e1ec158 commit 528e6c1
Show file tree
Hide file tree
Showing 35 changed files with 1,648 additions and 155 deletions.
2 changes: 1 addition & 1 deletion EXILED.props
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

<PropertyGroup>
<!-- This is the global version and is used for all projects that don't have a version -->
<Version Condition="$(Version) == ''">8.8.2</Version>
<Version Condition="$(Version) == ''">8.9.2</Version>
<!-- Enables public beta warning via the PUBLIC_BETA constant -->
<PublicBeta>false</PublicBeta>

Expand Down
6 changes: 6 additions & 0 deletions Exiled.API/Enums/EffectType.cs
Original file line number Diff line number Diff line change
Expand Up @@ -228,5 +228,11 @@ public enum EffectType
/// Makes the player nearly invisible, and allows them to pass through doors.
/// </summary>
Ghostly,

/// <summary>
/// Manipulate wish Fog player will have.
/// <remarks>You can choose fog with <see cref="CustomRendering.FogType"/> and putting it on intensity.</remarks>
/// </summary>
FogControl,
}
}
9 changes: 9 additions & 0 deletions Exiled.API/Extensions/EffectTypeExtension.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ namespace Exiled.API.Extensions
using System.Linq;

using CustomPlayerEffects;
using CustomRendering;
using Enums;
using InventorySystem.Items.MarshmallowMan;
using InventorySystem.Items.Usables.Scp244.Hypothermia;
Expand Down Expand Up @@ -71,6 +72,7 @@ public static class EffectTypeExtension
#pragma warning restore CS0618
{ EffectType.Strangled, typeof(Strangled) },
{ EffectType.Ghostly, typeof(Ghostly) },
{ EffectType.FogControl, typeof(FogControl) },
});

/// <summary>
Expand Down Expand Up @@ -120,6 +122,13 @@ public static bool TryGetEffectType(this StatusEffectBase statusEffectBase, out
return true;
}

/// <summary>
/// Sets the <see cref="FogType"/> of the specified <see cref="FogControl"/>.
/// </summary>
/// <param name="fogControl">The <see cref="FogControl"/> effect.</param>
/// <param name="fogType">The <see cref="FogType"/> applied.</param>
public static void SetFogType(this FogControl fogControl, FogType fogType) => fogControl.Intensity = (byte)(fogType + 1);

/// <summary>
/// Returns whether or not the provided <paramref name="effect"/> drains health over time.
/// </summary>
Expand Down
45 changes: 45 additions & 0 deletions Exiled.API/Features/Attributes/Validators/GreaterThanAttribute.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
// -----------------------------------------------------------------------
// <copyright file="GreaterThanAttribute.cs" company="Exiled Team">
// Copyright (c) Exiled Team. All rights reserved.
// Licensed under the CC BY-SA 3.0 license.
// </copyright>
// -----------------------------------------------------------------------

namespace Exiled.API.Features.Attributes.Validators
{
using System;

using Exiled.API.Interfaces;

/// <summary>
/// An attribute that validates if the value of the marked property is greater than a specified number.
/// </summary>
[AttributeUsage(AttributeTargets.Property)]
public sealed class GreaterThanAttribute : Attribute, IValidator
{
/// <summary>
/// Initializes a new instance of the <see cref="GreaterThanAttribute"/> class.
/// </summary>
/// <param name="number">The number the marked property should be greater than.</param>
/// <param name="isIncluded">Whether or not the comparison in inclusive (includes <see cref="Number"/> as a valid value for the marked property).</param>
public GreaterThanAttribute(object number, bool isIncluded = false)
{
Number = (IComparable)number;
IsIncluded = isIncluded;
}

/// <summary>
/// Gets the number that the value of the marked property should be greater than.
/// </summary>
public IComparable Number { get; }

/// <summary>
/// Gets a value indicating whether or not the comparison is inclusive.
/// <remarks>If this returns true, <see cref="Number"/> is a valid value for the marked property.</remarks>
/// </summary>
public bool IsIncluded { get; }

/// <inheritdoc/>
public bool Validate(object value) => Number.CompareTo(value) is -1 || (IsIncluded && Number.CompareTo(value) is 0);
}
}
45 changes: 45 additions & 0 deletions Exiled.API/Features/Attributes/Validators/LessThanAttribute.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
// -----------------------------------------------------------------------
// <copyright file="LessThanAttribute.cs" company="Exiled Team">
// Copyright (c) Exiled Team. All rights reserved.
// Licensed under the CC BY-SA 3.0 license.
// </copyright>
// -----------------------------------------------------------------------

namespace Exiled.API.Features.Attributes.Validators
{
using System;

using Exiled.API.Interfaces;

/// <summary>
/// An attribute that validates if the value of the marked property is less than a specified number.
/// </summary>
[AttributeUsage(AttributeTargets.Property)]
public sealed class LessThanAttribute : Attribute, IValidator
{
/// <summary>
/// Initializes a new instance of the <see cref="LessThanAttribute"/> class.
/// </summary>
/// <param name="number">The number the marked property should be less than.</param>
/// <param name="isIncluded">Whether or not the comparison in inclusive (includes <see cref="Number"/> as a valid value for the marked property).</param>
public LessThanAttribute(object number, bool isIncluded = false)
{
Number = (IComparable)number;
IsIncluded = isIncluded;
}

/// <summary>
/// Gets the number that the value of the marked property should be less than.
/// </summary>
public IComparable Number { get; }

/// <summary>
/// Gets a value indicating whether or not the comparison is inclusive.
/// <remarks>If this returns true, <see cref="Number"/> is a valid value for the marked property.</remarks>
/// </summary>
public bool IsIncluded { get; }

/// <inheritdoc/>
public bool Validate(object value) => Number.CompareTo(value) is 1 || (IsIncluded && Number.CompareTo(value) is 0);
}
}
23 changes: 23 additions & 0 deletions Exiled.API/Features/Attributes/Validators/NonNegativeAttribute.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
// -----------------------------------------------------------------------
// <copyright file="NonNegativeAttribute.cs" company="Exiled Team">
// Copyright (c) Exiled Team. All rights reserved.
// Licensed under the CC BY-SA 3.0 license.
// </copyright>
// -----------------------------------------------------------------------

namespace Exiled.API.Features.Attributes.Validators
{
using System;

using Exiled.API.Interfaces;

/// <summary>
/// An attribute that validates if the value of the marked property is non-negative.
/// </summary>
[AttributeUsage(AttributeTargets.Property)]
public sealed class NonNegativeAttribute : Attribute, IValidator
{
/// <inheritdoc/>
public bool Validate(object value) => value is >= 0;
}
}
23 changes: 23 additions & 0 deletions Exiled.API/Features/Attributes/Validators/NonPositiveAttribute.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
// -----------------------------------------------------------------------
// <copyright file="NonPositiveAttribute.cs" company="Exiled Team">
// Copyright (c) Exiled Team. All rights reserved.
// Licensed under the CC BY-SA 3.0 license.
// </copyright>
// -----------------------------------------------------------------------

namespace Exiled.API.Features.Attributes.Validators
{
using System;

using Exiled.API.Interfaces;

/// <summary>
/// An attribute that validates if the value of the marked property is non-positive.
/// </summary>
[AttributeUsage(AttributeTargets.Property)]
public sealed class NonPositiveAttribute : Attribute, IValidator
{
/// <inheritdoc/>
public bool Validate(object value) => value is <= 0;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
// -----------------------------------------------------------------------
// <copyright file="PossibleValuesAttribute.cs" company="Exiled Team">
// Copyright (c) Exiled Team. All rights reserved.
// Licensed under the CC BY-SA 3.0 license.
// </copyright>
// -----------------------------------------------------------------------

namespace Exiled.API.Features.Attributes.Validators
{
using System;

using Exiled.API.Interfaces;

/// <summary>
/// An attribute that validates if the value of the marked property included in the specified values.
/// </summary>
[AttributeUsage(AttributeTargets.Property)]
public sealed class PossibleValuesAttribute : Attribute, IValidator
{
/// <summary>
/// Initializes a new instance of the <see cref="PossibleValuesAttribute"/> class.
/// </summary>
/// <param name="values">The values the marked property can have that should be considered valid.</param>
public PossibleValuesAttribute(params object[] values)
{
Values = values;
}

/// <summary>
/// Gets the values the marked property can have that should be considered valid.
/// </summary>
public object[] Values { get; }

/// <inheritdoc/>
public bool Validate(object value) => Values.Contains(value);
}
}
15 changes: 13 additions & 2 deletions Exiled.API/Features/Player.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ namespace Exiled.API.Features

using Core;
using CustomPlayerEffects;
using CustomPlayerEffects.Danger;
using DamageHandlers;
using Enums;
using Exiled.API.Features.Attributes;
Expand Down Expand Up @@ -348,7 +349,7 @@ public string CustomInfo
set
{
// NW Client check.
if (value.Contains('<'))
if (value is not null && value.Contains('<'))
{
foreach (string token in value.Split('<'))
{
Expand Down Expand Up @@ -725,7 +726,7 @@ public Vector3 Scale
ReferenceHub.transform.localScale = value;

foreach (Player target in List)
Server.SendSpawnMessage?.Invoke(null, new object[] { NetworkIdentity, target.Connection });
MirrorExtensions.SendSpawnMessageMethodInfo?.Invoke(null, new object[] { NetworkIdentity, target.Connection });
}
catch (Exception exception)
{
Expand All @@ -734,6 +735,16 @@ public Vector3 Scale
}
}

/// <summary>
/// Gets an array of <see cref="DangerStackBase"/>.
/// </summary>
public DangerStackBase[] Dangers => (GetEffect(EffectType.Scp1853) as Scp1853)?.Dangers;

/// <summary>
/// Gets a list of current <see cref="DangerStackBase"/> the player has.
/// </summary>
public IEnumerable<DangerStackBase> ActiveDangers => Dangers.Where(d => d.IsActive);

/// <summary>
/// Gets or sets a value indicating whether or not the player's bypass mode is enabled.
/// </summary>
Expand Down
57 changes: 50 additions & 7 deletions Exiled.API/Features/Server.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,6 @@ namespace Exiled.API.Features
/// </summary>
public static class Server
{
private static MethodInfo sendSpawnMessage;

/// <summary>
/// Gets a dictionary that pairs assemblies with their associated plugins.
/// </summary>
Expand All @@ -48,11 +46,6 @@ public static class Server
/// </summary>
public static global::Broadcast Broadcast => global::Broadcast.Singleton;

/// <summary>
/// Gets the cached <see cref="SendSpawnMessage"/> <see cref="MethodInfo"/>.
/// </summary>
public static MethodInfo SendSpawnMessage => sendSpawnMessage ??= typeof(NetworkServer).GetMethod("SendSpawnMessage", BindingFlags.NonPublic | BindingFlags.Static);

/// <summary>
/// Gets or sets the name of the server.
/// </summary>
Expand Down Expand Up @@ -212,6 +205,56 @@ public static bool IsIdleModeEnabled
/// </summary>
public static Dictionary<string, object> SessionVariables { get; } = new();

/// <summary>
/// Gets or sets a list with all fake SyncVar that will be applied to player ass soon as he connects.
/// <para>
/// As string argument use a full name of Network property ('full type name'.'property name').
/// As object argument use value that will be used instead of a current value.
/// </para>
/// </summary>
public static Dictionary<string, object> FakeSyncVars { get; set; } = new();

/// <summary>
/// Adds a new value to <see cref="FakeSyncVars"/>.
/// </summary>
/// <param name="propertyInfo">A property of a sync var (starts with "Network").</param>
/// <param name="newValue">The value that will replace actual one.</param>
public static void AddFakeSyncVar(PropertyInfo propertyInfo, object newValue)
{
if (propertyInfo.PropertyType != newValue.GetType())
{
Log.Error($"Type mismatch between property info type ({propertyInfo.PropertyType}) and new value type ({newValue.GetType()})");
return;
}

string fullName = propertyInfo.DeclaringType!.FullName + '.' + propertyInfo.Name;

if (FakeSyncVars.ContainsKey(fullName))
FakeSyncVars.Remove(fullName);

FakeSyncVars.Add(fullName, newValue);
}

/// <summary>
/// Adds a new value to <see cref="FakeSyncVars"/>.
/// </summary>
/// <param name="fieldInfo">The sync var field.</param>
/// <param name="newValue">The new value that will replace actual one.</param>
public static void AddFakeSyncVar(FieldInfo fieldInfo, object newValue) =>
AddFakeSyncVar(fieldInfo.DeclaringType!.GetProperty("Network" + fieldInfo.Name), newValue);

/// <summary>
/// Adds a new value to <see cref="FakeSyncVars"/>.
/// </summary>
/// <param name="type">Type where sync var is declared.</param>
/// <param name="name">Name of sync var field or property.</param>
/// <param name="newValue">The new value that will replace actual one.</param>
public static void AddFakeSyncVar(Type type, string name, object newValue)
{
name = name.Replace(type.Name, string.Empty);
AddFakeSyncVar(name.StartsWith("Network") ? type.GetProperty(name) : type.GetProperty("Network" + name), newValue);
}

/// <summary>
/// Restarts the server, reconnects all players.
/// </summary>
Expand Down
Loading

0 comments on commit 528e6c1

Please sign in to comment.