diff --git a/EXILED/Exiled.Events/EventArgs/Server/EndingRoundEventArgs.cs b/EXILED/Exiled.Events/EventArgs/Server/EndingRoundEventArgs.cs index 5c72d299be..bbdce5c087 100644 --- a/EXILED/Exiled.Events/EventArgs/Server/EndingRoundEventArgs.cs +++ b/EXILED/Exiled.Events/EventArgs/Server/EndingRoundEventArgs.cs @@ -7,8 +7,6 @@ namespace Exiled.Events.EventArgs.Server { - using System; - using API.Enums; using Interfaces; @@ -23,21 +21,18 @@ public class EndingRoundEventArgs : IDeniableEvent /// /// /// - /// - /// - /// - /// - /// - /// /// /// /// - public EndingRoundEventArgs(RoundSummary.LeadingTeam leadingTeam, RoundSummary.SumInfo_ClassList classList, bool isAllowed, bool isForceEnded) + /// + /// + /// + public EndingRoundEventArgs(RoundSummary.SumInfo_ClassList classList, bool isForceEnded, bool isAllowed) { ClassList = classList; - LeadingTeam = (LeadingTeam)leadingTeam; - IsRoundEnded = isAllowed; + LeadingTeam = GetLeadingTeam(classList); IsForceEnded = isForceEnded; + IsAllowed = isAllowed; } /// @@ -51,22 +46,33 @@ public EndingRoundEventArgs(RoundSummary.LeadingTeam leadingTeam, RoundSummary.S public LeadingTeam LeadingTeam { get; set; } /// - /// Gets or sets a value indicating whether the round is going to finish. - /// - public bool IsRoundEnded { get; set; } // TODO: Obsolete this in Exiled 10 - - /// - /// Gets or Sets a value indicating whether the round is ended by API call. + /// Gets or sets a value indicating whether the round is ended by API call. /// public bool IsForceEnded { get; set; } /// - /// Gets or sets a value indicating whether the event can be executed. + /// Gets or sets a value indicating whether the round is going to finish or not. /// - public bool IsAllowed + public bool IsAllowed { get; set; } + + private LeadingTeam GetLeadingTeam(RoundSummary.SumInfo_ClassList classList) { - get => IsRoundEnded; - set => IsRoundEnded = value; + // NW logic + int facilityForces = classList.mtf_and_guards + classList.scientists; + int chaosInsurgency = classList.chaos_insurgents + classList.class_ds; + int anomalies = classList.scps_except_zombies + classList.zombies; + int num4 = facilityForces > 0 ? 1 : 0; + bool flag1 = chaosInsurgency > 0; + bool flag2 = anomalies > 0; + RoundSummary.LeadingTeam leadingTeam = RoundSummary.LeadingTeam.Draw; + if (num4 != 0) + leadingTeam = RoundSummary.EscapedScientists >= RoundSummary.EscapedClassD ? RoundSummary.LeadingTeam.FacilityForces : RoundSummary.LeadingTeam.Draw; + else if (flag2 || flag2 & flag1) + leadingTeam = RoundSummary.EscapedClassD > RoundSummary.SurvivingSCPs ? RoundSummary.LeadingTeam.ChaosInsurgency : (RoundSummary.SurvivingSCPs > RoundSummary.EscapedScientists ? RoundSummary.LeadingTeam.Anomalies : RoundSummary.LeadingTeam.Draw); + else if (flag1) + leadingTeam = RoundSummary.EscapedClassD >= RoundSummary.EscapedScientists ? RoundSummary.LeadingTeam.ChaosInsurgency : RoundSummary.LeadingTeam.Draw; + + return (LeadingTeam)leadingTeam; } -} + } } \ No newline at end of file diff --git a/EXILED/Exiled.Events/Patches/Events/Server/RoundEnd.cs b/EXILED/Exiled.Events/Patches/Events/Server/RoundEnd.cs index 9088c7ed35..489e015a19 100644 --- a/EXILED/Exiled.Events/Patches/Events/Server/RoundEnd.cs +++ b/EXILED/Exiled.Events/Patches/Events/Server/RoundEnd.cs @@ -78,29 +78,25 @@ private static IEnumerable Transpiler(IEnumerable x.opcode == OpCodes.Ldfld && x.operand == (object)Field(typeof(RoundSummary), nameof(RoundSummary._roundEnded))) + offset; + index = newInstructions.FindIndex(x => x.LoadsField(Field(typeof(RoundSummary), nameof(RoundSummary._roundEnded)))) + offset; LocalBuilder evEndingRound = generator.DeclareLocal(typeof(EndingRoundEventArgs)); newInstructions.InsertRange( index, - new CodeInstruction[] + new[] { - // this.leadingTeam - new CodeInstruction(OpCodes.Ldarg_0).MoveLabelsFrom(newInstructions[index]), - new(OpCodes.Ldfld, Field(PrivateType, LeadingTeam)), - // this.newList - new(OpCodes.Ldarg_0), + new CodeInstruction(OpCodes.Ldarg_0).MoveLabelsFrom(newInstructions[index]), new(OpCodes.Ldfld, Field(PrivateType, NewList)), - // shouldRoundEnd - new(OpCodes.Ldloc_S, 4), - // isForceEnd new(OpCodes.Ldloc_1), new(OpCodes.Ldfld, Field(typeof(RoundSummary), nameof(RoundSummary._roundEnded))), - // EndingRoundEventArgs evEndingRound = new(RoundSummary.LeadingTeam, RoundSummary.SumInfo_ClassList, bool, bool); + // baseGameConditionsSatisfied + new(OpCodes.Ldloc_S, 5), + + // EndingRoundEventArgs evEndingRound = new(RoundSummary.SumInfo_ClassList, bool, bool); new(OpCodes.Newobj, GetDeclaredConstructors(typeof(EndingRoundEventArgs))[0]), new(OpCodes.Dup), @@ -108,12 +104,6 @@ private static IEnumerable Transpiler(IEnumerable Transpiler(IEnumerable x.LoadsField(Field(typeof(RoundSummary), nameof(RoundSummary._roundEnded)))) + offset; + int offset2 = 1; + int index2 = newInstructions.FindLastIndex(x => x.opcode == OpCodes.Stloc_S && x.operand is LocalBuilder { LocalIndex: 7 }) + offset2; + + newInstructions.RemoveRange(index, index2 - index); + + offset = -1; + index = newInstructions.FindIndex(x => x.StoresField(Field(PrivateType, LeadingTeam))) + offset; + + newInstructions.RemoveAt(index); + newInstructions.InsertRange( + index, + new CodeInstruction[] + { + new(OpCodes.Ldloc_S, evEndingRound.LocalIndex), + new(OpCodes.Callvirt, PropertyGetter(typeof(EndingRoundEventArgs), nameof(EndingRoundEventArgs.LeadingTeam))), }); + offset = 1; + index = newInstructions.FindIndex(x => x.StoresField(Field(PrivateType, LeadingTeam))) + offset; + offset2 = 1; + index2 = newInstructions.FindLastIndex(x => x.StoresField(Field(PrivateType, LeadingTeam))) + offset2; + + newInstructions.RemoveRange(index, index2 - index); + // 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;