From 3f404c9807e6e32e2099534a8e5b81117d8c72e1 Mon Sep 17 00:00:00 2001 From: VALERA771 Date: Sat, 3 Aug 2024 14:21:19 +0300 Subject: [PATCH 1/6] new ev + previous role --- EXILED/Exiled.API/Features/Player.cs | 11 +++++- .../EventArgs/Player/EscapedEventArgs.cs | 38 +++++++++++++++++++ EXILED/Exiled.Events/Handlers/Player.cs | 11 ++++++ .../{Escaping.cs => EscapingAndEscaped.cs} | 28 ++++++++++++-- 4 files changed, 83 insertions(+), 5 deletions(-) create mode 100644 EXILED/Exiled.Events/EventArgs/Player/EscapedEventArgs.cs rename EXILED/Exiled.Events/Patches/Events/Player/{Escaping.cs => EscapingAndEscaped.cs} (82%) diff --git a/EXILED/Exiled.API/Features/Player.cs b/EXILED/Exiled.API/Features/Player.cs index ed937ead5d..9c96347deb 100644 --- a/EXILED/Exiled.API/Features/Player.cs +++ b/EXILED/Exiled.API/Features/Player.cs @@ -577,9 +577,18 @@ public PlayerPermissions RemoteAdminPermissions public Role Role { get => role ??= Role.Create(RoleManager.CurrentRole); - internal set => role = value; + internal set + { + PreviousRole = role; + role = value; + } } + /// + /// Gets the role that player had before changing role. + /// + public Role PreviousRole { get; private set; } + /// /// Gets or sets the player's SCP preferences. /// diff --git a/EXILED/Exiled.Events/EventArgs/Player/EscapedEventArgs.cs b/EXILED/Exiled.Events/EventArgs/Player/EscapedEventArgs.cs new file mode 100644 index 0000000000..aaaaf1ffb3 --- /dev/null +++ b/EXILED/Exiled.Events/EventArgs/Player/EscapedEventArgs.cs @@ -0,0 +1,38 @@ +// ----------------------------------------------------------------------- +// +// Copyright (c) Exiled Team. All rights reserved. +// Licensed under the CC BY-SA 3.0 license. +// +// ----------------------------------------------------------------------- + +namespace Exiled.Events.EventArgs.Player +{ + using Exiled.API.Enums; + using Exiled.API.Features; + using Exiled.Events.EventArgs.Interfaces; + + /// + /// Contains all information after player has escaped. + /// + public class EscapedEventArgs : IPlayerEvent + { + /// + /// Initializes a new instance of the class. + /// + /// + /// + public EscapedEventArgs(Player player, EscapeScenario escapeScenario) + { + Player = player; + EscapeScenario = escapeScenario; + } + + /// + public Player Player { get; } + + /// + /// Gets the type of escape. + /// + public EscapeScenario EscapeScenario { get; } + } +} \ No newline at end of file diff --git a/EXILED/Exiled.Events/Handlers/Player.cs b/EXILED/Exiled.Events/Handlers/Player.cs index aca07ce6e1..0da54bbb65 100644 --- a/EXILED/Exiled.Events/Handlers/Player.cs +++ b/EXILED/Exiled.Events/Handlers/Player.cs @@ -228,6 +228,11 @@ public class Player /// public static Event Escaping { get; set; } = new(); + /// + /// Invoked after a escapes. + /// + public static Event Escaped { get; set; } = new(); + /// /// Invoked before a begins speaking to the intercom. /// @@ -710,6 +715,12 @@ public class Player /// The instance. public static void OnEscaping(EscapingEventArgs ev) => Escaping.InvokeSafely(ev); + /// + /// Called after a escapes. + /// + /// The instance. + public static void OnEscaped(EscapedEventArgs ev) => Escaped.InvokeSafely(ev); + /// /// Called before a begins speaking to the intercom. /// diff --git a/EXILED/Exiled.Events/Patches/Events/Player/Escaping.cs b/EXILED/Exiled.Events/Patches/Events/Player/EscapingAndEscaped.cs similarity index 82% rename from EXILED/Exiled.Events/Patches/Events/Player/Escaping.cs rename to EXILED/Exiled.Events/Patches/Events/Player/EscapingAndEscaped.cs index 3ebf07eae3..019f20f457 100644 --- a/EXILED/Exiled.Events/Patches/Events/Player/Escaping.cs +++ b/EXILED/Exiled.Events/Patches/Events/Player/EscapingAndEscaped.cs @@ -1,5 +1,5 @@ // ----------------------------------------------------------------------- -// +// // Copyright (c) Exiled Team. All rights reserved. // Licensed under the CC BY-SA 3.0 license. // @@ -29,11 +29,12 @@ namespace Exiled.Events.Patches.Events.Player using static HarmonyLib.AccessTools; /// - /// Patches for . + /// Patches for and . /// [EventPatch(typeof(Handlers.Player), nameof(Handlers.Player.Escaping))] + [EventPatch(typeof(Handlers.Player), nameof(Handlers.Player.Escaped))] [HarmonyPatch(typeof(Escape), nameof(Escape.ServerHandlePlayer))] - internal static class Escaping + internal static class EscapingAndEscaped { private static IEnumerable Transpiler(IEnumerable instructions, ILGenerator generator) { @@ -98,9 +99,28 @@ private static IEnumerable Transpiler(IEnumerable Date: Sun, 11 Aug 2024 16:24:49 +0300 Subject: [PATCH 2/6] suggestions --- .../EventArgs/Player/EscapedEventArgs.cs | 28 +++++++++++++++++++ .../Events/Player/EscapingAndEscaped.cs | 7 ++--- 2 files changed, 30 insertions(+), 5 deletions(-) diff --git a/EXILED/Exiled.Events/EventArgs/Player/EscapedEventArgs.cs b/EXILED/Exiled.Events/EventArgs/Player/EscapedEventArgs.cs index aaaaf1ffb3..0dcecd1b83 100644 --- a/EXILED/Exiled.Events/EventArgs/Player/EscapedEventArgs.cs +++ b/EXILED/Exiled.Events/EventArgs/Player/EscapedEventArgs.cs @@ -7,9 +7,13 @@ namespace Exiled.Events.EventArgs.Player { + using System; + using Exiled.API.Enums; using Exiled.API.Features; using Exiled.Events.EventArgs.Interfaces; + using PlayerRoles; + using Respawning; /// /// Contains all information after player has escaped. @@ -25,6 +29,10 @@ public EscapedEventArgs(Player player, EscapeScenario escapeScenario) { Player = player; EscapeScenario = escapeScenario; + Team = EscapeScenario is EscapeScenario.Scientist or EscapeScenario.CuffedClassD ? SpawnableTeamType.NineTailedFox : SpawnableTeamType.ChaosInsurgency; + Tickets = Team == SpawnableTeamType.ChaosInsurgency ? 4 : 3; + OldRole = EscapeScenario is EscapeScenario.Scientist or EscapeScenario.CuffedScientist ? RoleTypeId.Scientist : RoleTypeId.ClassD; + EscapeTime = (int)Math.Ceiling(player.Role.ActiveTime.TotalSeconds); } /// @@ -34,5 +42,25 @@ public EscapedEventArgs(Player player, EscapeScenario escapeScenario) /// Gets the type of escape. /// public EscapeScenario EscapeScenario { get; } + + /// + /// Gets the that gained tickets for this escape. + /// + public SpawnableTeamType Team { get; } + + /// + /// Gets the amount of tickets gained for this escape. + /// + public int Tickets { get; } + + /// + /// Gets the previous role for this player. + /// + public RoleTypeId OldRole { get; } + + /// + /// Gets the time in seconds since round started. + /// + public int EscapeTime { get; } } } \ No newline at end of file diff --git a/EXILED/Exiled.Events/Patches/Events/Player/EscapingAndEscaped.cs b/EXILED/Exiled.Events/Patches/Events/Player/EscapingAndEscaped.cs index 019f20f457..80142a6397 100644 --- a/EXILED/Exiled.Events/Patches/Events/Player/EscapingAndEscaped.cs +++ b/EXILED/Exiled.Events/Patches/Events/Player/EscapingAndEscaped.cs @@ -104,15 +104,12 @@ private static IEnumerable Transpiler(IEnumerable Date: Mon, 12 Aug 2024 16:57:03 +0300 Subject: [PATCH 3/6] uwu --- .../EventArgs/Player/EscapedEventArgs.cs | 16 ++++++---- .../Events/Player/EscapingAndEscaped.cs | 31 +++++++++++++++---- 2 files changed, 35 insertions(+), 12 deletions(-) diff --git a/EXILED/Exiled.Events/EventArgs/Player/EscapedEventArgs.cs b/EXILED/Exiled.Events/EventArgs/Player/EscapedEventArgs.cs index 0dcecd1b83..d2d55bba33 100644 --- a/EXILED/Exiled.Events/EventArgs/Player/EscapedEventArgs.cs +++ b/EXILED/Exiled.Events/EventArgs/Player/EscapedEventArgs.cs @@ -8,9 +8,11 @@ namespace Exiled.Events.EventArgs.Player { using System; + using System.Collections.Generic; using Exiled.API.Enums; using Exiled.API.Features; + using Exiled.API.Features.Roles; using Exiled.Events.EventArgs.Interfaces; using PlayerRoles; using Respawning; @@ -25,14 +27,16 @@ public class EscapedEventArgs : IPlayerEvent /// /// /// - public EscapedEventArgs(Player player, EscapeScenario escapeScenario) + /// + /// , . + public EscapedEventArgs(Player player, EscapeScenario escapeScenario, Role role, KeyValuePair kvp) { Player = player; EscapeScenario = escapeScenario; - Team = EscapeScenario is EscapeScenario.Scientist or EscapeScenario.CuffedClassD ? SpawnableTeamType.NineTailedFox : SpawnableTeamType.ChaosInsurgency; - Tickets = Team == SpawnableTeamType.ChaosInsurgency ? 4 : 3; - OldRole = EscapeScenario is EscapeScenario.Scientist or EscapeScenario.CuffedScientist ? RoleTypeId.Scientist : RoleTypeId.ClassD; - EscapeTime = (int)Math.Ceiling(player.Role.ActiveTime.TotalSeconds); + Team = kvp.Key; + Tickets = kvp.Value; + OldRole = role.Type; + EscapeTime = (int)Math.Ceiling(role.ActiveTime.TotalSeconds); } /// @@ -51,7 +55,7 @@ public EscapedEventArgs(Player player, EscapeScenario escapeScenario) /// /// Gets the amount of tickets gained for this escape. /// - public int Tickets { get; } + public float Tickets { get; } /// /// Gets the previous role for this player. diff --git a/EXILED/Exiled.Events/Patches/Events/Player/EscapingAndEscaped.cs b/EXILED/Exiled.Events/Patches/Events/Player/EscapingAndEscaped.cs index 80142a6397..a05c12fece 100644 --- a/EXILED/Exiled.Events/Patches/Events/Player/EscapingAndEscaped.cs +++ b/EXILED/Exiled.Events/Patches/Events/Player/EscapingAndEscaped.cs @@ -9,7 +9,6 @@ namespace Exiled.Events.Patches.Events.Player { #pragma warning disable SA1402 // File may only contain a single type #pragma warning disable IDE0060 - using System; using System.Collections.Generic; using System.Linq; @@ -19,11 +18,10 @@ namespace Exiled.Events.Patches.Events.Player using API.Enums; using API.Features; using API.Features.Pools; - using EventArgs.Player; + using Exiled.API.Features.Roles; using Exiled.Events.Attributes; using HarmonyLib; - using Respawning; using static HarmonyLib.AccessTools; @@ -44,6 +42,7 @@ private static IEnumerable Transpiler(IEnumerable instruction.opcode == OpCodes.Newobj) + offset; @@ -102,16 +101,35 @@ private static IEnumerable Transpiler(IEnumerable x.Is(OpCodes.Stfld, Field(typeof(Escape.EscapeMessage), nameof(Escape.EscapeMessage.EscapeTime)))) + offset; + + newInstructions.InsertRange(index, new CodeInstruction[] + { + // role = ev.Player.Role + new(OpCodes.Ldloc_S, ev.LocalIndex), + new(OpCodes.Callvirt, PropertyGetter(typeof(EscapingEventArgs), nameof(EscapingEventArgs.Player))), + new(OpCodes.Callvirt, PropertyGetter(typeof(Player), nameof(Player.Role))), + new(OpCodes.Stloc_S, role.LocalIndex), + }); + newInstructions.InsertRange(newInstructions.Count - 1, new CodeInstruction[] { // ev.Player new(OpCodes.Ldloc_S, ev.LocalIndex), new(OpCodes.Callvirt, PropertyGetter(typeof(EscapingEventArgs), nameof(EscapingEventArgs.Player))), - // ev.EscapeScenario + // escapeScenario new(OpCodes.Ldloc_1), - // EscapedEventArgs ev2 = new(ev.Player, ev.EscapeScenario); + // role + new(OpCodes.Ldloc_S, role.LocalIndex), + + // ev.RespawnTickets.Key + new(OpCodes.Ldloc_S, ev.LocalIndex), + new(OpCodes.Callvirt, PropertyGetter(typeof(EscapingEventArgs), nameof(EscapingEventArgs.RespawnTickets))), + + // EscapedEventArgs ev2 = new(ev.Player, ev.EscapeScenario, role, float, SpawnableTeamType); new(OpCodes.Newobj, GetDeclaredConstructors(typeof(EscapedEventArgs))[0]), // Handlers.Player.OnEscaped(ev); @@ -138,6 +156,7 @@ private static void GrantAllTickets(EscapingEventArgs ev) /// Replaces last returned to . /// [EventPatch(typeof(Handlers.Player), nameof(Handlers.Player.Escaping))] + [EventPatch(typeof(Handlers.Player), nameof(Handlers.Player.Escaped))] [HarmonyPatch(typeof(Escape), nameof(Escape.ServerGetScenario))] internal static class GetScenario { @@ -165,4 +184,4 @@ private static IEnumerable Transpiler(IEnumerable.Pool.Return(newInstructions); } } -} +} \ No newline at end of file From bddd7d352087736049ff86d9ccddaf9a32ba4baa Mon Sep 17 00:00:00 2001 From: VALERA771 Date: Mon, 12 Aug 2024 17:39:52 +0300 Subject: [PATCH 4/6] suj --- EXILED/Exiled.Events/EventArgs/Player/EscapedEventArgs.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/EXILED/Exiled.Events/EventArgs/Player/EscapedEventArgs.cs b/EXILED/Exiled.Events/EventArgs/Player/EscapedEventArgs.cs index d2d55bba33..f185f78450 100644 --- a/EXILED/Exiled.Events/EventArgs/Player/EscapedEventArgs.cs +++ b/EXILED/Exiled.Events/EventArgs/Player/EscapedEventArgs.cs @@ -35,7 +35,7 @@ public EscapedEventArgs(Player player, EscapeScenario escapeScenario, Role role, EscapeScenario = escapeScenario; Team = kvp.Key; Tickets = kvp.Value; - OldRole = role.Type; + OldRole = role; EscapeTime = (int)Math.Ceiling(role.ActiveTime.TotalSeconds); } @@ -60,7 +60,7 @@ public EscapedEventArgs(Player player, EscapeScenario escapeScenario, Role role, /// /// Gets the previous role for this player. /// - public RoleTypeId OldRole { get; } + public Role OldRole { get; } /// /// Gets the time in seconds since round started. From 2147c9414112ccfa0ca95d5dc4421afba88b0a3d Mon Sep 17 00:00:00 2001 From: VALERA771 Date: Mon, 12 Aug 2024 18:09:44 +0300 Subject: [PATCH 5/6] fix --- .../Events/Player/EscapingAndEscaped.cs | 26 ++++++++++++------- 1 file changed, 16 insertions(+), 10 deletions(-) diff --git a/EXILED/Exiled.Events/Patches/Events/Player/EscapingAndEscaped.cs b/EXILED/Exiled.Events/Patches/Events/Player/EscapingAndEscaped.cs index a05c12fece..a48e531d96 100644 --- a/EXILED/Exiled.Events/Patches/Events/Player/EscapingAndEscaped.cs +++ b/EXILED/Exiled.Events/Patches/Events/Player/EscapingAndEscaped.cs @@ -9,6 +9,7 @@ namespace Exiled.Events.Patches.Events.Player { #pragma warning disable SA1402 // File may only contain a single type #pragma warning disable IDE0060 + using System; using System.Collections.Generic; using System.Linq; @@ -22,6 +23,7 @@ namespace Exiled.Events.Patches.Events.Player using Exiled.API.Features.Roles; using Exiled.Events.Attributes; using HarmonyLib; + using PlayerRoles.FirstPersonControl; using Respawning; using static HarmonyLib.AccessTools; @@ -164,18 +166,22 @@ private static IEnumerable Transpiler(IEnumerable newInstructions = ListPool.Pool.Get(instructions); - int e = 0; + LocalBuilder fpcRole = generator.DeclareLocal(typeof(FpcStandardRoleBase)); + + // replace HumanRole to FpcStandardRoleBase + newInstructions.Find(x => x.opcode == OpCodes.Isinst).operand = typeof(FpcStandardRoleBase); + + // after this index all invalid exit are considered Custom + int customExit = newInstructions.FindLastIndex(x => x.opcode == OpCodes.Ldarg_0); for (int i = 0; i < newInstructions.Count; i++) { - CodeInstruction codeInstruction = newInstructions[i]; - if (codeInstruction.opcode == OpCodes.Ldc_I4_0) - { - e++; - if (e > 3) - { - newInstructions[i].opcode = OpCodes.Ldc_I4_5; - } - } + OpCode opcode = newInstructions[i].opcode; + if (opcode == OpCodes.Stloc_0) + newInstructions[i] = new CodeInstruction(OpCodes.Stloc_S, fpcRole.LocalIndex).WithLabels(newInstructions[i].labels); + else if (opcode == OpCodes.Ldloc_0) + newInstructions[i] = new CodeInstruction(OpCodes.Ldloc_S, fpcRole.LocalIndex).WithLabels(newInstructions[i].labels); + else if (opcode == OpCodes.Ldc_I4_0 && i > customExit) + newInstructions[i].opcode = OpCodes.Ldc_I4_5; } for (int z = 0; z < newInstructions.Count; z++) From 8732744437f72e203405ef81317569f3693d9aba Mon Sep 17 00:00:00 2001 From: VALERA771 Date: Sat, 12 Oct 2024 01:10:09 +0300 Subject: [PATCH 6/6] uwu --- EXILED/Exiled.API/Features/Player.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/EXILED/Exiled.API/Features/Player.cs b/EXILED/Exiled.API/Features/Player.cs index 0ddbf631cd..fb3e564d5f 100644 --- a/EXILED/Exiled.API/Features/Player.cs +++ b/EXILED/Exiled.API/Features/Player.cs @@ -590,7 +590,7 @@ public Role Role get => role ??= Role.Create(RoleManager.CurrentRole); internal set { - PreviousRole = role; + PreviousRole = role.Type; role = value; } } @@ -598,7 +598,7 @@ internal set /// /// Gets the role that player had before changing role. /// - public Role PreviousRole { get; private set; } + public RoleTypeId PreviousRole { get; private set; } /// /// Gets or sets the player's SCP preferences.