Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Resonance] Improvements & Fixes (BETA 7) #2794

Merged
merged 5 commits into from
Oct 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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) == ''">9.0.0-beta.6</Version>
<Version Condition="$(Version) == ''">9.0.0-beta.7</Version>
<!-- Enables public beta warning via the PUBLIC_BETA constant -->
<PublicBeta>false</PublicBeta>

Expand Down
12 changes: 10 additions & 2 deletions Exiled.CustomModules/API/Features/CustomRoles/RoleBehaviour.cs
Original file line number Diff line number Diff line change
Expand Up @@ -479,6 +479,9 @@ protected override void SubscribeEvents()
Exiled.Events.Handlers.Player.Handcuffing += HandcuffingBehavior;
Exiled.Events.Handlers.Map.PlacingBlood += PlacingBloodBehavior;
Exiled.Events.Handlers.Player.ChangingNickname += OnInternalChangingNickname;
Exiled.Events.Handlers.Player.Spawning += OverrideSpawnPoint;
Exiled.Events.Handlers.Player.SpawningRagdoll += OnSpawningRagdoll;

EscapingEventDispatcher.Bind(this, OnEscaping);
EscapedEventDispatcher.Bind(this, OnEscaped);
}
Expand Down Expand Up @@ -509,6 +512,11 @@ protected override void UnsubscribeEvents()
Exiled.Events.Handlers.Player.Handcuffing -= HandcuffingBehavior;
Exiled.Events.Handlers.Map.PlacingBlood -= PlacingBloodBehavior;
Exiled.Events.Handlers.Player.ChangingNickname -= OnInternalChangingNickname;
Exiled.Events.Handlers.Player.Spawning -= OverrideSpawnPoint;
Exiled.Events.Handlers.Player.SpawningRagdoll -= OnSpawningRagdoll;

EscapingEventDispatcher.Unbind(this, OnEscaping);
EscapedEventDispatcher.Unbind(this, OnEscaped);
}

/// <summary>
Expand Down Expand Up @@ -661,8 +669,8 @@ protected virtual void PickingUpItemBehavior(SearchingPickupEventArgs ev)
ev.IsAllowed = false;
}

/// <inheritdoc cref="Exiled.Events.Handlers.Player.OnEscaping(Exiled.Events.EventArgs.Player.EscapingEventArgs)"/>
protected virtual void PreventPlayerFromEscaping(Exiled.Events.EventArgs.Player.EscapingEventArgs ev)
/// <inheritdoc cref="Exiled.Events.Handlers.Player.OnEscaping(EscapingEventArgs)"/>
protected virtual void PreventPlayerFromEscaping(EscapingEventArgs ev)
{
if (!Check(ev.Player) || useCustomEscape || wasEscaped || (EscapeSettings is not null && !EscapeSettings.IsEmpty()))
return;
Expand Down
5 changes: 5 additions & 0 deletions Exiled.Events/EventArgs/Player/BannedEventArgs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -57,5 +57,10 @@ public BannedEventArgs(Player target, Player issuer, BanDetails details, BanHand
/// Gets a value indicating whether the ban is forced or not.
/// </summary>
public bool IsForced { get; }

/// <summary>
/// Gets a value indicating whether the ban is an offline ban or not.
/// </summary>
public bool IsOffline => Details.OriginalName == "Unknown - offline ban";
}
}
4 changes: 2 additions & 2 deletions Exiled.Events/EventArgs/Player/PreAuthenticatingEventArgs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -94,9 +94,9 @@ public PreAuthenticatingEventArgs(
public ConnectionRequest Request { get; }

/// <summary>
/// Gets a value indicating whether the player can be authenticated or not.
/// Gets or sets a value indicating whether the player can be authenticated or not.
/// </summary>
public bool IsAllowed { get; private set; } = true;
public bool IsAllowed { get; set; } = true;

/// <summary>
/// Gets or sets the cached <see cref="CachedPreauthData"/> that is returned back to the NwPluginAPI.
Expand Down
59 changes: 59 additions & 0 deletions Exiled.Events/EventArgs/Player/SendingCommandEventArgs.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
// -----------------------------------------------------------------------
// <copyright file="SendingCommandEventArgs.cs" company="Exiled Team">
// Copyright (c) Exiled Team. All rights reserved.
// Licensed under the CC BY-SA 3.0 license.
// </copyright>
// -----------------------------------------------------------------------

namespace Exiled.Events.EventArgs.Player
{
using CommandSystem;

using Exiled.API.Features;
using Exiled.Events.EventArgs.Interfaces;

/// <summary>
/// Contains all information before a player sends a proper RA command.
/// </summary>
public class SendingCommandEventArgs : IPlayerEvent, IDeniableEvent
{
/// <summary>
/// Initializes a new instance of the <see cref="SendingCommandEventArgs" /> class.
/// </summary>
/// <param name="player">
/// <inheritdoc cref="Player" />
/// </param>
/// <param name="command">
/// <inheritdoc cref="Command" />
/// </param>
/// <param name="query">
/// <inheritdoc cref="Query" />
/// </param>
public SendingCommandEventArgs(Player player, ICommand command, string query)
{
Command = command;
Player = player;
Query = query;
}

/// <summary>
/// Gets or sets a value indicating whether the command can be executed.
/// </summary>
public bool IsAllowed { get; set; } = true;

/// <summary>
/// Gets the command that is being executed.
/// </summary>
public ICommand Command { get; }

/// <summary>
/// Gets the query of the command.
/// </summary>
public string Query { get; }

/// <summary>
/// Gets the player who's sending the command.
/// </summary>
public Player Player { get; }
}
}
43 changes: 13 additions & 30 deletions Exiled.Events/Handlers/Player.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@

namespace Exiled.Events.Handlers
{
using Exiled.API.Features.Pickups;
#pragma warning disable IDE0079
#pragma warning disable IDE0060
#pragma warning disable SA1623 // Property summary documentation should match accessors
Expand All @@ -16,10 +15,6 @@ namespace Exiled.Events.Handlers

using Exiled.Events.Features;

using PluginAPI.Core.Attributes;
using PluginAPI.Enums;
using PluginAPI.Events;

/// <summary>
/// Player related events.
/// </summary>
Expand Down Expand Up @@ -558,6 +553,11 @@ public class Player
/// </summary>
public static Event<ChangingNicknameEventArgs> ChangingNickname { get; set; } = new();

/// <summary>
/// Invoked before a <see cref="API.Features.Player"/>'s sends proper RA command.
/// </summary>
public static Event<SendingCommandEventArgs> SendingCommand { get; set; } = new();

/// <summary>
/// Invoked before displaying the hitmarker to the player.
/// </summary>
Expand Down Expand Up @@ -1203,6 +1203,12 @@ public static void OnItemRemoved(ReferenceHub referenceHub, InventorySystem.Item
/// <param name="ev">The <see cref="ChangingNicknameEventArgs"/> instance.</param>
public static void OnChangingNickname(ChangingNicknameEventArgs ev) => ChangingNickname.InvokeSafely(ev);

/// <summary>
/// Called before a <see cref="Player"/>'s sends propper RA command.
/// </summary>
/// <param name="ev">The <see cref="SendingCommandEventArgs"/> instance.</param>
public static void OnSendingCommand(SendingCommandEventArgs ev) => SendingCommand.InvokeSafely(ev);

/// <summary>
/// Called before displaying the hitmarker to the player.
/// </summary>
Expand All @@ -1218,30 +1224,7 @@ public static void OnItemRemoved(ReferenceHub referenceHub, InventorySystem.Item
/// <summary>
/// Called before pre-authenticating a <see cref="API.Features.Player"/>.
/// </summary>
/// <param name="userId"><inheritdoc cref="PreAuthenticatingEventArgs.UserId"/></param>
/// <param name="ipAddress"><inheritdoc cref="PreAuthenticatingEventArgs.IpAddress"/></param>
/// <param name="expiration"><inheritdoc cref="PreAuthenticatingEventArgs.Expiration"/></param>
/// <param name="flags"><inheritdoc cref="PreAuthenticatingEventArgs.Flags"/></param>
/// <param name="country"><inheritdoc cref="PreAuthenticatingEventArgs.Country"/></param>
/// <param name="signature"><inheritdoc cref="PreAuthenticatingEventArgs.Signature"/></param>
/// <param name="request"><inheritdoc cref="PreAuthenticatingEventArgs.Request"/></param>
/// <param name="readerStartPosition"><inheritdoc cref="PreAuthenticatingEventArgs.ReaderStartPosition"/></param>
/// <returns>Returns the <see cref="PreauthCancellationData"/> instance.</returns>
[PluginEvent(ServerEventType.PlayerPreauth)]
public PreauthCancellationData OnPreAuthenticating(
string userId,
string ipAddress,
long expiration,
CentralAuthPreauthFlags flags,
string country,
byte[] signature,
LiteNetLib.ConnectionRequest request,
int readerStartPosition)
{
PreAuthenticatingEventArgs ev = new(userId, ipAddress, expiration, flags, country, signature, request, readerStartPosition);
PreAuthenticating.InvokeSafely(ev);

return ev.CachedPreauthData;
}
/// <param name="ev"><The cref="PreAuthenticatingEventArgs"/> instance.</param>
public static void OnPreAuthenticating(PreAuthenticatingEventArgs ev) => PreAuthenticating.InvokeSafely(ev);
}
}
4 changes: 2 additions & 2 deletions Exiled.Events/Patches/Events/Player/Banned.cs
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,8 @@ private static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstructi
new(OpCodes.Call, Method(typeof(Handlers.Player), nameof(Handlers.Player.OnBanned))),
});

for (int z = 0; z < newInstructions.Count; z++)
yield return newInstructions[z];
foreach (CodeInstruction instruction in newInstructions)
yield return instruction;

ListPool<CodeInstruction>.Pool.Return(newInstructions);
}
Expand Down
91 changes: 91 additions & 0 deletions Exiled.Events/Patches/Events/Player/PreAuthenticating.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
// -----------------------------------------------------------------------
// <copyright file="PreAuthenticating.cs" company="Exiled Team">
// Copyright (c) Exiled Team. All rights reserved.
// Licensed under the CC BY-SA 3.0 license.
// </copyright>
// -----------------------------------------------------------------------

namespace Exiled.Events.Patches.Events.Player
{
using System.Collections.Generic;
using System.Reflection.Emit;

using API.Features.Core.Generic.Pools;
using Exiled.Events.Attributes;
using Exiled.Events.EventArgs.Player;

using HarmonyLib;

using LiteNetLib;

using static HarmonyLib.AccessTools;

/// <summary>
/// Patches <see cref="CustomLiteNetLib4MirrorTransport.ProcessConnectionRequest(ConnectionRequest)" />.
/// Adds the <see cref="Handlers.Player.PreAuthenticating" /> event.
/// </summary>
[EventPatch(typeof(Handlers.Player), nameof(Handlers.Player.PreAuthenticating))]
[HarmonyPatch(typeof(CustomLiteNetLib4MirrorTransport), nameof(CustomLiteNetLib4MirrorTransport.ProcessConnectionRequest))]
internal static class PreAuthenticating
{
private static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstruction> instructions, ILGenerator generator)
{
List<CodeInstruction> newInstructions = ListPool<CodeInstruction>.Pool.Get(instructions);

Label ret = generator.DefineLabel();
newInstructions[newInstructions.Count - 1].labels.Add(ret);

LocalBuilder ev = generator.DeclareLocal(typeof(PreAuthenticatingEventArgs));
int index = newInstructions.FindIndex(instruction => instruction.opcode == OpCodes.Ldstr && (string)instruction.operand == "{0};{1};{2};{3}");

newInstructions.InsertRange(
index,
new[]
{
// userid
new CodeInstruction(OpCodes.Ldloc_S, 10),

// ipaddress
new (OpCodes.Ldloc_S, 15),

// expiration
new (OpCodes.Ldloc_S, 11),

// flags
new (OpCodes.Ldloc_S, 12),

// country
new (OpCodes.Ldloc_S, 13),

// signature
new (OpCodes.Ldloc_S, 14),

// request
new (OpCodes.Ldarg_1),

// position
new (OpCodes.Ldloc_S, 9),

// PreAuthenticatingEventArgs ev = new (userid, ipaddress, expiration, flags, country, signature, request, position)
new (OpCodes.Newobj, GetDeclaredConstructors(typeof(PreAuthenticatingEventArgs))[0]),
new (OpCodes.Dup),
new (OpCodes.Stloc_S, ev.LocalIndex),

// OnPreAuthenticating(ev)
new (OpCodes.Call, Method(typeof(Handlers.Player), nameof(Handlers.Player.OnPreAuthenticating))),
new (OpCodes.Ldloc_S, ev.LocalIndex),

// ev.isallowed
new (OpCodes.Callvirt, PropertyGetter(typeof(PreAuthenticatingEventArgs), nameof(PreAuthenticatingEventArgs.IsAllowed))),

// ret
new (OpCodes.Brfalse_S, ret),
});

foreach (CodeInstruction instruction in newInstructions)
yield return instruction;

ListPool<CodeInstruction>.Pool.Return(newInstructions);
}
}
}
85 changes: 85 additions & 0 deletions Exiled.Events/Patches/Events/Player/SendingCommand.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
// -----------------------------------------------------------------------
// <copyright file="SendingCommand.cs" company="Exiled Team">
// Copyright (c) Exiled Team. All rights reserved.
// Licensed under the CC BY-SA 3.0 license.
// </copyright>
// -----------------------------------------------------------------------

namespace Exiled.Events.Patches.Events.Player
{
using System;
using System.Collections.Generic;
using System.Reflection.Emit;

using API.Features;
using API.Features.Core.Generic.Pools;

using CommandSystem;

using Exiled.Events.Attributes;
using Exiled.Events.EventArgs.Player;

using HarmonyLib;

using RemoteAdmin;

using static HarmonyLib.AccessTools;

/// <summary>
/// Patches <see cref="CommandProcessor.ProcessQuery(string, CommandSender)" />.
/// Adds the <see cref="Handlers.Player.SendingCommand" /> event.
/// </summary>
[EventPatch(typeof(Handlers.Player), nameof(Handlers.Player.SendingCommand))]
[HarmonyPatch(typeof(CommandProcessor), nameof(CommandProcessor.ProcessQuery))]
internal static class SendingCommand
{
private static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstruction> instructions, ILGenerator generator)
{
List<CodeInstruction> newInstructions = ListPool<CodeInstruction>.Pool.Get(instructions);

Label ret = generator.DefineLabel();

newInstructions[newInstructions.Count - 1].labels.Add(ret);
LocalBuilder ev = generator.DeclareLocal(typeof(SendingCommandEventArgs));
const int offset = 2;
int index = newInstructions.FindIndex(instruction => instruction.Calls(Method(typeof(CommandHandler), nameof(CommandHandler.TryGetCommand)))) + offset;

newInstructions.InsertRange(
index,
new[]
{
// Sender
new CodeInstruction(OpCodes.Ldarg_1),

// Player.Get(CommandSender)
new CodeInstruction(OpCodes.Call, Method(typeof(Player), nameof(Player.Get), new[] { typeof(CommandSender) })),

// command
new CodeInstruction(OpCodes.Ldloc_1),

// query
new CodeInstruction(OpCodes.Ldarg_0),

// SendingCommandEventArgs ev = new SendingCommandEventArgs(Player, ICommand, Query)
new CodeInstruction(OpCodes.Newobj, GetDeclaredConstructors(typeof(SendingCommandEventArgs))[0]),
new CodeInstruction(OpCodes.Dup),
new CodeInstruction(OpCodes.Stloc_S, ev.LocalIndex),

// Handlers.Player.OnSendingCommand(ev)
new CodeInstruction(OpCodes.Call, Method(typeof(Handlers.Player), nameof(Handlers.Player.OnSendingCommand))),

// isallowed == false
new CodeInstruction(OpCodes.Ldloc_S, ev.LocalIndex),
new CodeInstruction(OpCodes.Callvirt, PropertyGetter(typeof(SendingCommandEventArgs), nameof(SendingCommandEventArgs.IsAllowed))),

// ret
new CodeInstruction(OpCodes.Brfalse_S, ret),
});

foreach (CodeInstruction instruction in newInstructions)
yield return instruction;

ListPool<CodeInstruction>.Pool.Return(newInstructions);
}
}
}
Loading
Loading