Fight/Escape removal plugin causes "Maximum call stack size exceeded" in battle when using either Time Progress Battle option.

I'm aware there's an infinite loop going on somewhere but I don't know what could be causing it. I am unsure if this is a plugin issue question or a question suited to those who know more about the workings of TPB. Sorry if this is in the wrong spot.

What happens?
  • With no other controllable Actors present, whether alone or with up to the other three Actors using autobattle, manually selecting actions ei choosing Attack or Guard or a skill will immediately crash the game with the "Maximum call stack size exceeded" error.
  • If there is more than one controllable Actor to pass onto (which won't happen in the game anyway), the game sometimes does not immediately crash and the player will be able to select an action for the Actor to perform and pass control to the next Actor and sometimes the player can make an action and pass control to the next Actor with an imminent crash.
When does the error not happen?
  • Simply waiting around and manually performing no actions does not trigger the error, even when another actor is set to autobattle.
  • Opening the submenus to access skills (which the player won't be able to do anyway).

What I'm after:
Advice on why the error is happening only in TPB, how to fix it. If I have to use another plugin or modify the one below that's fine.

What am I trying to do in game?
  • Remove any trace of the Fight/Escape option on battle start and throughout battle.
Why?
  • In the game being made battles should not give players the option immediately flee, if allowed at all.
  • If a battle is triggered the assumption is the player wants the battle to happen, asking if they want to fight is redundant.
  • When using TPB, Troops and auto battle actors attack through the Fight/Escape menu and the extra step the player is currently forced to choose from before picking an option themselves wrecks the flow of the gameplay loop, feels clunky and annoying.
Notes:
  • Because turns start while the Fight/Escape menu is open and there's no selection made it seems the Fight/Escape menu doesn't lock all the battle participants out from doing anything which confuses me as to why attempting to remove it is causing a crash if Troops and autobattlers ignore it.

  • There is only one controllable Actor and any other Actors present would be controlled using Autobattle (+ any scripts to modify their "behaviour", "battle options", "AI").

  • I currently have a skill the enemies within the Troop use to call a Common Event to make Actor 1 "skip" their turn by teaching them a skill and forcing them to use it (Actor still performs the "step forward and use skill" motion unfortunately, a different thread for that issue sometime). I want them to skip turn as a skill because after using it the TPB bar immediately starts to refill, which is preferable to only giving them a State such as Paralysis which adds the Cannot Move restriction, emptying but also freezing the APB bar for way too long. The take away here is forced actions do not cause the game to crash.

Here's the plugin
/*:
* @target MZ
* @plugindesc Skip the party command window in battle.
* @author Caethyril
* @help Free to use and modify.
*/

(function(alias) {
Scene_Battle.prototype.startPartyCommandSelection = function() {
alias.apply(this, arguments);
this.commandFight();
};
})(Scene_Battle.prototype.startPartyCommandSelection);

The plugin isn't perfect because it doesn't remove the "back" button that sits right center on the screen.
Ideally I want to rip the whole Fight/Escape menu out (as well as a few other sub menus) but if that code is just a longer more complicated version of the above that causes the game to crash I'm back to where I am now.

I found this thread which seems to have a similar issue even if what they're trying to do is different, so I'm not sure if the problem I'm having is some code trying to reference itself.
Confirmed, oops! The console (F8 during test) shows a more detailed error trace:

RangeError: Maximum call stack size exceeded at Scene_Battle.changeInputWindow (rmmz_scenes.js:3014) at Scene_Battle.selectNextCommand (rmmz_scenes.js:3407) at Scene_Battle.commandFight (rmmz_scenes.js:3355) at Scene_Battle.startPartyCommandSelection (<anonymous>:4:6) at Scene_Battle.changeInputWindow (rmmz_scenes.js:3014) ...
I think the problem is that TPB starts battle with a party command selection, but at that point it is unlikely any actor is available for input. So changeInputWindow reverts to the party selection window, which...yeah. Endless loop. 😴

For TPB, try this instead:
Spoiler: plugin code
JavaScript:
/*:
 * @target MZ
 * @plugindesc No party command (Fight, Escape) for TPB system.
 * @author Caethyril
 * @url https://forums.rpgmakerweb.com/threads/155764/
 * @help Free to use and/or modify for any project, no credit required.
 */

// Reset flag to false so party command does not show on turn 0.
;void (alias => {
    BattleManager.initMembers = function() {
        alias.apply(this, arguments);
        this._tpbNeedsPartyCommand = false;
    };
})(BattleManager.initMembers);

// Remove "cancel" handler from actor command window.
void (alias => {
    Scene_Battle.prototype.createActorCommandWindow = function() {
        alias.apply(this, arguments);
        delete this._actorCommandWindow._handlers.cancel;
    };
})(Scene_Battle.prototype.createActorCommandWindow);

// Hide Touch UI cancel button when actor command window is active.
void (alias => {
    Scene_Battle.prototype.updateCancelButton = function() {
        alias.apply(this, arguments);
        if (this._cancelButton && this._actorCommandWindow.active)
            this._cancelButton.visible = false;
    };
})(Scene_Battle.prototype.updateCancelButton);
I did a quick test and it seems to work for me, but let me know if you find problems with it~
@caethyril
And it works!
Thank you for sorting that out.

Original thread: https://forums.rpgmakerweb.com/threads/fight-escape-removal-plugin-causes-maximum-call-stack-size-exceeded-in-battle-when-using-either-time-progress-battle-option.155764/