Skip to content

Commit

Permalink
Ending round event fix (Exiled-Team#2280)
Browse files Browse the repository at this point in the history
Co-authored-by: Yamato <[email protected]>
  • Loading branch information
Misaka-ZeroTwo and louis1706 authored Nov 20, 2023
1 parent cdc5e51 commit d17e1d4
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 4 deletions.
11 changes: 10 additions & 1 deletion Exiled.Events/EventArgs/Server/EndingRoundEventArgs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,15 @@ public class EndingRoundEventArgs : IDeniableEvent
/// <param name="isAllowed">
/// <inheritdoc cref="IsRoundEnded" />
/// </param>
public EndingRoundEventArgs(RoundSummary.LeadingTeam leadingTeam, RoundSummary.SumInfo_ClassList classList, bool isAllowed)
/// <param name="isForceEnded">
/// <inheritdoc cref="IsForceEnded" />
/// </param>
public EndingRoundEventArgs(RoundSummary.LeadingTeam leadingTeam, RoundSummary.SumInfo_ClassList classList, bool isAllowed, bool isForceEnded)
{
ClassList = classList;
LeadingTeam = (LeadingTeam)leadingTeam;
IsRoundEnded = isAllowed;
IsForceEnded = isForceEnded;
}

/// <summary>
Expand All @@ -51,6 +55,11 @@ public EndingRoundEventArgs(RoundSummary.LeadingTeam leadingTeam, RoundSummary.S
/// </summary>
public bool IsRoundEnded { get; set; } // TODO: Obsolete this in Exiled 10

/// <summary>
/// Gets or Sets a value indicating whether the round is ended by API call.
/// </summary>
public bool IsForceEnded { get; set; }

/// <summary>
/// Gets or sets a value indicating whether the event can be executed or not.
/// </summary>
Expand Down
15 changes: 12 additions & 3 deletions Exiled.Events/Patches/Events/Server/RoundEnd.cs
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,11 @@ private static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstructi
// shouldRoundEnd
new(OpCodes.Ldloc_S, 4),

// EndingRoundEventArgs evEndingRound = new(RoundSummary.LeadingTeam, RoundSummary.SumInfo_ClassList, bool);
// isForceEnd
new(OpCodes.Ldloc_1),
new(OpCodes.Ldfld, Field(typeof(RoundSummary), nameof(RoundSummary._roundEnded))),

// EndingRoundEventArgs evEndingRound = new(RoundSummary.LeadingTeam, RoundSummary.SumInfo_ClassList, bool, bool);
new(OpCodes.Newobj, GetDeclaredConstructors(typeof(EndingRoundEventArgs))[0]),
new(OpCodes.Dup),

Expand All @@ -94,11 +98,16 @@ private static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstructi
new(OpCodes.Callvirt, PropertyGetter(typeof(EndingRoundEventArgs), nameof(EndingRoundEventArgs.LeadingTeam))),
new(OpCodes.Stfld, Field(PrivateType, LeadingTeam)),

// this._roundEnded = ev.IsAllowed
// this._roundEnded = ev.IsForceEnded
new(OpCodes.Ldloc_1),
new(OpCodes.Ldloc_S, evEndingRound.LocalIndex),
new(OpCodes.Callvirt, PropertyGetter(typeof(EndingRoundEventArgs), nameof(EndingRoundEventArgs.IsAllowed))),
new(OpCodes.Callvirt, PropertyGetter(typeof(EndingRoundEventArgs), nameof(EndingRoundEventArgs.IsForceEnded))),
new(OpCodes.Stfld, Field(typeof(RoundSummary), nameof(RoundSummary._roundEnded))),

// flag = ev.IsAllowed
new(OpCodes.Ldloc_S, evEndingRound.LocalIndex),
new(OpCodes.Callvirt, PropertyGetter(typeof(EndingRoundEventArgs), nameof(EndingRoundEventArgs.IsAllowed))),
new(OpCodes.Stloc_S, 4),
});

offset = 7;
Expand Down

0 comments on commit d17e1d4

Please sign in to comment.