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

Add round end feature #86

Open
wants to merge 6 commits into
base: dev
Choose a base branch
from
Open
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
7 changes: 7 additions & 0 deletions EXILED/Exiled.API/Features/Round.cs
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,12 @@ public static class Round
/// </summary>
public static bool IsLobby => !(IsEnded || IsStarted);

/// <summary>
/// Gets a value indicating the last ClassList.
/// </summary>
/// <remarks>this value is only updated when Round is <see cref="InProgress"/> and not <see cref="IsLocked"/>.</remarks>
public static RoundSummary.SumInfo_ClassList LastClassList { get; internal set; }

/// <summary>
/// Gets or sets a value indicating the amount of Chaos Targets remaining.
/// </summary>
Expand Down Expand Up @@ -121,6 +127,7 @@ public static int Kills
public static int SurvivingSCPs
{
get => RoundSummary.SurvivingSCPs;
[Obsolete("This value is rewritten by NW every time it's used", true)]
set => RoundSummary.SurvivingSCPs = value;
}

Expand Down
5 changes: 5 additions & 0 deletions EXILED/Exiled.Events/EventArgs/Server/RoundEndedEventArgs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,5 +49,10 @@ public RoundEndedEventArgs(LeadingTeam leadingTeam, RoundSummary.SumInfo_ClassLi
/// Gets or sets the time to restart the next round.
/// </summary>
public int TimeToRestart { get; set; }

/// <summary>
/// Gets or sets a value indicating whether Round Summary will be sent to all players.
/// </summary>
public bool ShowRoundSummary { get; set; } = true;
}
}
21 changes: 21 additions & 0 deletions EXILED/Exiled.Events/Patches/Events/Server/RoundEnd.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ namespace Exiled.Events.Patches.Events.Server
using PlayerRoles;

using static HarmonyLib.AccessTools;
using static RoundSummary;

/// <summary>
/// Patches <see cref="RoundSummary._ProcessServerSideCode()" />.
Expand Down Expand Up @@ -131,6 +132,17 @@ private static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstructi
new(OpCodes.Stloc_S, 4),
});

// Round.LastClassList = this.newList;
offset = 1;
index = newInstructions.FindIndex(x => x.opcode == OpCodes.Stfld && x.operand == (object)Field(typeof(SumInfo_ClassList), nameof(SumInfo_ClassList.warhead_kills))) + offset;
newInstructions.InsertRange(index, new CodeInstruction[]
{
new(OpCodes.Ldflda, Field(PrivateType, NewList)),
new(OpCodes.Call, PropertySetter(typeof(Round), nameof(Round.LastClassList))),
});

Label skip = generator.DefineLabel();

offset = 7;
index = newInstructions.FindLastIndex(x => x.opcode == OpCodes.Ldstr && x.operand == (object)"auto_round_restart_time") + offset;

Expand All @@ -153,15 +165,24 @@ private static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstructi
// RoundEndedEventArgs evEndedRound = new(RoundSummary.LeadingTeam, RoundSummary.SumInfo_ClassList, bool);
new(OpCodes.Newobj, GetDeclaredConstructors(typeof(RoundEndedEventArgs))[0]),
new(OpCodes.Dup),
new(OpCodes.Dup),

// Handlers.Server.OnRoundEnded(evEndedRound);
new(OpCodes.Call, Method(typeof(Handlers.Server), nameof(Handlers.Server.OnRoundEnded))),

// timeToRestart = ev.TimeToRestart
new(OpCodes.Callvirt, PropertyGetter(typeof(RoundEndedEventArgs), nameof(RoundEndedEventArgs.TimeToRestart))),
new(OpCodes.Stloc_S, timeToRestartIndex),

// if (!ShowRoundSummary) goto skip;
new(OpCodes.Callvirt, PropertyGetter(typeof(RoundEndedEventArgs), nameof(RoundEndedEventArgs.ShowRoundSummary))),
new(OpCodes.Brfalse_S, skip),
});

offset = 1;
index = newInstructions.FindLastIndex(x => x.opcode == OpCodes.Call && x.operand == (object)Method(typeof(RoundSummary), nameof(RoundSummary.RpcShowRoundSummary))) + offset;
newInstructions[index].labels.Add(skip);

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

Expand Down