-
Notifications
You must be signed in to change notification settings - Fork 178
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Resonance] Improvements & Fixes (BETA 7) (#2794)
* Ban event improvements & Port TPS Fix to Dev * PreAuth patch port * Version bump * Sending command port * Fix Role Behavior Custom Spawnpoint
- Loading branch information
Showing
10 changed files
with
309 additions
and
37 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} | ||
} |
Oops, something went wrong.