~hutzdog/TOS2-Auto-Crossout

d00a9a027e9e8b86f403354a434e5fe18bf69bf9 — Danielle Hutzley 4 months ago 6bdf2de
Add position role tracking to deal with a bug seemingly exclusive to BTOS2
3 files changed, 16 insertions(+), 6 deletions(-)

M resources/AutoCrossout.modinfo.json
M src/Accessors.cs
M src/Patches.cs
M resources/AutoCrossout.modinfo.json => resources/AutoCrossout.modinfo.json +1 -1
@@ 3,7 3,7 @@
  "DisplayName": "Auto Crossout",
  "Authors": [ "Hutzdog" ],
  "Description": "Automatically crosses out used slots in wills. Source code available at https://sr.ht/~hutzdog/TOS2-Auto-Crossout/",
  "Version": "0.2.0",
  "Version": "0.2.2",
  "Platforms": [ "Windows", "Mac", "Linux" ],
  "RequiredMods": [],
  "ConflictingMods": [],

M src/Accessors.cs => src/Accessors.cs +11 -1
@@ 6,6 6,7 @@
using HarmonyLib;
using Server.Shared.Extensions;
using Server.Shared.State;
using System.Collections.Generic;

namespace AutoCrossout.Accessors
{


@@ 13,6 14,7 @@ namespace AutoCrossout.Accessors
  public class RoleListAccessor
  {
    public static Game.Interface.HudRoleListAndGraveyardController? hrg_controller = null;
    public static List<uint> players_with_known_roles = new List<uint>();

    /// <summary>
    /// Cross out a given role list item


@@ 26,7 28,7 @@ namespace AutoCrossout.Accessors
    /// <summary>
    /// Cross out the slot for a given role in the role list
    /// </summary>
    public static void CrossOutA(Role role)
    public static void CrossOutA(Role role, uint position)
    {
      if (hrg_controller == null || !(Pepper.IsRoleRevealPhase() || Pepper.IsGamePhasePlay()))
      {


@@ 34,6 36,13 @@ namespace AutoCrossout.Accessors
        return;
      }

      if (players_with_known_roles.Contains(position))
      {
        Utils.WriteDebug("Cancelling crossout : player role already crossed out");
        return;
      }
      players_with_known_roles.Add(position);

      foreach (var item in hrg_controller!.roleListPanel.roleListItems)
      {
        if (!item.isCrossedOut)


@@ 59,6 68,7 @@ namespace AutoCrossout.Accessors
    [HarmonyPostfix]
    public static void Postfix(Game.Interface.HudRoleListAndGraveyardController __instance)
    {
      players_with_known_roles.Clear();
      hrg_controller = __instance;
    }
  }

M src/Patches.cs => src/Patches.cs +4 -4
@@ 13,7 13,7 @@ namespace AutoCrossout.Patches
  // HACK: Delay crossing out the current player's role until after the game loads
  public static class CrossOutStartingRoles
  {
    public static List<Role> StartingRoles = new List<Role>();
    public static List<(Role, uint)> StartingRoles = new List<(Role, uint)>();

    internal static void HandlePostfix(GameInfo gameInfo)
    {


@@ 22,7 22,7 @@ namespace AutoCrossout.Patches
        foreach (var role in StartingRoles)
        {
          Utils.WriteDebug("Crossing out known player role at start of game : " + role);
          Accessors.RoleListAccessor.CrossOutA(role);
          Accessors.RoleListAccessor.CrossOutA(role.Item1, role.Item2);
        }

        StartingRoles.Clear();


@@ 71,9 71,9 @@ namespace AutoCrossout.Patches
          Utils.WriteDebug("Crossing out role " + data.role + " for player at position " + data.position);

          if (Pepper.IsGamePhasePlay() && Accessors.RoleListAccessor.hrg_controller != null)
            Accessors.RoleListAccessor.CrossOutA(data.role);
            Accessors.RoleListAccessor.CrossOutA(data.role, (uint)data.position);
          else if (Pepper.IsRoleRevealPhase() || Pepper.IsGamePhasePlay())
            CrossOutStartingRoles.StartingRoles.Add(data.role);
            CrossOutStartingRoles.StartingRoles.Add((data.role, (uint)data.position));
          else
          {
            Utils.WriteDebug("Cancelling role crossout: not in correct game phase");