Skip to content

Commit

Permalink
uwu
Browse files Browse the repository at this point in the history
  • Loading branch information
VALERA771 committed Aug 12, 2024
1 parent c40c52f commit cac9a15
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 12 deletions.
16 changes: 10 additions & 6 deletions EXILED/Exiled.Events/EventArgs/Player/EscapedEventArgs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -25,14 +27,16 @@ public class EscapedEventArgs : IPlayerEvent
/// </summary>
/// <param name="player"><inheritdoc cref="Player"/></param>
/// <param name="escapeScenario"><inheritdoc cref="EscapeScenario"/></param>
public EscapedEventArgs(Player player, EscapeScenario escapeScenario)
/// <param name="role"><inheritdoc cref="Role"/></param>
/// <param name="kvp"><inheritdoc cref="Tickets"/>, <inheritdoc cref="Team"/>.</param>
public EscapedEventArgs(Player player, EscapeScenario escapeScenario, Role role, KeyValuePair<SpawnableTeamType, float> 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);
}

/// <inheritdoc/>
Expand All @@ -51,7 +55,7 @@ public EscapedEventArgs(Player player, EscapeScenario escapeScenario)
/// <summary>
/// Gets the amount of tickets gained for this escape.
/// </summary>
public int Tickets { get; }
public float Tickets { get; }

/// <summary>
/// Gets the previous role for this player.
Expand Down
31 changes: 25 additions & 6 deletions EXILED/Exiled.Events/Patches/Events/Player/EscapingAndEscaped.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -44,6 +42,7 @@ private static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstructi
Label returnLabel = generator.DefineLabel();

LocalBuilder ev = generator.DeclareLocal(typeof(EscapingEventArgs));
LocalBuilder role = generator.DeclareLocal(typeof(Role));

int offset = -2;
int index = newInstructions.FindIndex(instruction => instruction.opcode == OpCodes.Newobj) + offset;
Expand Down Expand Up @@ -102,16 +101,35 @@ private static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstructi
new(OpCodes.Call, Method(typeof(EscapingAndEscaped), nameof(GrantAllTickets))),
});

offset = 4;
index = newInstructions.FindIndex(x => 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);
Expand All @@ -138,6 +156,7 @@ private static void GrantAllTickets(EscapingEventArgs ev)
/// Replaces last returned <see cref="EscapeScenario.None"/> to <see cref="EscapeScenario.CustomEscape"/>.
/// </summary>
[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
{
Expand Down Expand Up @@ -165,4 +184,4 @@ private static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstructi
ListPool<CodeInstruction>.Pool.Return(newInstructions);
}
}
}
}

0 comments on commit cac9a15

Please sign in to comment.