Skip to content

Commit

Permalink
Team Balance Mod Game Issue Workaround
Browse files Browse the repository at this point in the history
- 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
  • Loading branch information
data-bomb committed Jul 7, 2024
1 parent 4d9af49 commit a8274ce
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions Si_BasicTeamBalance/Si_BasicTeamBalance.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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")]

Expand Down Expand Up @@ -381,6 +381,17 @@ public static bool Prefix(MP_Strategy __instance, GameByteStreamReader __0, byte
return false;
}

MP_Strategy strategyInstance = GameObject.FindObjectOfType<MP_Strategy>();

// 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))
{
Expand All @@ -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>();

MP_Strategy.ETeamsVersus versusMode = strategyInstance.TeamsVersus;
Team? ForcedTeam = FindLowestPopulationTeam(versusMode);
if (ForcedTeam != null)
Expand Down

0 comments on commit a8274ce

Please sign in to comment.