From a8274ce7bffd54df8ca203903f553ce83db96432 Mon Sep 17 00:00:00 2001 From: data-bomb Date: Sun, 7 Jul 2024 12:42:18 -0700 Subject: [PATCH] Team Balance Mod Game Issue Workaround - Accounts for issue where a player is on an invalid team (e.g., after round ends and versus-mode changes) and the mods prevent a team join from occurring - Now the mod detects when an invalid configuration is present and allows the team change to occur unabated --- Si_BasicTeamBalance/Si_BasicTeamBalance.cs | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/Si_BasicTeamBalance/Si_BasicTeamBalance.cs b/Si_BasicTeamBalance/Si_BasicTeamBalance.cs index 0e70d06..61b6f5d 100644 --- a/Si_BasicTeamBalance/Si_BasicTeamBalance.cs +++ b/Si_BasicTeamBalance/Si_BasicTeamBalance.cs @@ -38,7 +38,7 @@ You should have received a copy of the GNU General Public License using SilicaAdminMod; using System.Linq; -[assembly: MelonInfo(typeof(BasicTeamBalance), "Basic Team Balance", "1.3.2", "databomb", "https://github.com/data-bomb/Silica")] +[assembly: MelonInfo(typeof(BasicTeamBalance), "Basic Team Balance", "1.3.3", "databomb", "https://github.com/data-bomb/Silica")] [assembly: MelonGame("Bohemia Interactive", "Silica")] [assembly: MelonOptionalDependencies("Admin Mod")] @@ -381,6 +381,17 @@ public static bool Prefix(MP_Strategy __instance, GameByteStreamReader __0, byte return false; } + MP_Strategy strategyInstance = GameObject.FindObjectOfType(); + + // if there is some kind of game bug and the player is on an invalid team then let the change occur + if (JoiningPlayer.Team != null && strategyInstance.GetStrategyTeamSetup(JoiningPlayer.Team) == null) + { + MelonLogger.Warning("Found player on invalid team. Allowing role change."); + JoiningPlayer.Team = TargetTeam; + NetworkLayer.SendPlayerSelectTeam(JoiningPlayer, TargetTeam); + return false; + } + // the team change should be permitted as it doesn't impact balance if (!JoinCausesImbalance(TargetTeam)) { @@ -392,7 +403,7 @@ public static bool Prefix(MP_Strategy __instance, GameByteStreamReader __0, byte // if the player hasn't joined a team yet, force them to the team that needs it the most if (JoiningPlayer.Team == null) { - MP_Strategy strategyInstance = GameObject.FindObjectOfType(); + MP_Strategy.ETeamsVersus versusMode = strategyInstance.TeamsVersus; Team? ForcedTeam = FindLowestPopulationTeam(versusMode); if (ForcedTeam != null)