"Uncaught Error: Header is wrong"

Hey there,
players have been reporting the "Uncaught Error: Header is wrong" message when playing my game.
I'm pretty sure that it's caused by the loading screen plugin (based on RED_RandomLoadingScreen) that I've almost completely rewritten into spaghetti, so please bear with my terrible code.
So far I've been unable to reproduce the error as it seems to happen randomly ;_;

Description of the plugin:
I wanted to adjust the plugin to be able to permanently adjust the range of the loading screens used, so instead of giving a range, I adjusted it to accept an array of numbers.
Because I wanted to add unlockable screens over the course of the game, I added a second array (filled with only 0 or 1) where the array index corresponds to the loading screen number and the 0/1 decides whether the screen had been unlocked yet.

Code:
/*:
 * @param ID of loading images
 * @desc ID of loading images, seperate with ','
 * @default 0
 *
 * @param Max number of images
 * @desc number of screens (minus locked ones)
 * @default 0
 *
 * @help
 * ================================================================================
 * COMMANDS:
 * setLoadingScreen # #
 * ~~~Allows you to manually set the loading screen range, f.e. 1 1 2 3 4 6
 *
 * setScreen screenID 1|0
 * ~~~Choose to lock or unlock the version of the loading screen. 0 to lock, 1 to unlock
 * setScreen 2 1
 * to unlock loading screen 2
 *
 * ================================================================================
 */

(function() {
    
    var parameters = PluginManager.parameters('RED_RandomLoadingScreen');
    var screens = parameters['ID of loading images'].split(/\s*,\s*/).filter(function(value) { return !!value; }); //array for loading screens available
    var maxscreens = Number(parameters['Max number of images']);
    var screenSwitches = []; //array for choosing locked/unlocked version

    var _Game_Interpreter_pluginCommand = Game_Interpreter.prototype.pluginCommand;
    Game_Interpreter.prototype.pluginCommand = function(command, args)
    {
        _Game_Interpreter_pluginCommand.call(this, command, args);
        if (command.toLowerCase() === 'setloadingscreen') //fill array with the numbers specified
        {
            screens = [];
            for(var i = 0; i < args.length; i++){
                screens.push(Number(args[i]));
            }
        }
        if (command.toLowerCase() === 'setscreen'){ // sets array field of the screen id to 0 or 1
            screenSwitches[args[0]] = (Number(args[1]));
        }
    };
    
    var startLoading_leftovers = Graphics.startLoading;
    Graphics.startLoading = function() {
        do{
            var liran = Math.randomInt(screens.length);
            var newlimg = 'img/system/Loading.png';
            var picid = Number(screens[liran]);
            if(picid <= maxscreens && (screenSwitches[picid] === 1)){
                screens[liran]+=maxscreens;
                screens[liran]=screens[liran]%(maxscreens*2+1); //errorhandling
                }
            } while(Number(screens[liran])>(maxscreens*2)); //error handling
        newlimg = 'img/system/Loading' + Number(screens[liran]) + '.png';
        Graphics.setLoadingImage(newlimg);
        startLoading_leftovers.call(this);
    };
    
}) ();

I also have common events set up that run after loading the game and closing the menu in order to constantly refresh the loading screen range.

I am suspecting that the error is likely from an erronous input/plugin command but since I don't know what the error means, I can't pinpoint the mistake 🙁

I am completely at a loss here, so any help would be much appreciated!
Do you have the full error log from the console?

By just looking at that code, I cannot see any major issues tho.
@waynee95 Unfortunately not, because I've been unable to reproduce it even though I've played through my game multiple times and it happend to my players after deployment ;_;

I'll delete my save files and retry again...
@Verdelite
Can someelse who got that error before, reproduce it?
Did you just deploy the project the default way or did you use Enigma Box etc?
@waynee95 The people that have reported it all said it seemed to happen randomly. Yep, I did indeed use Enigma Box for encryption.
The problem is that I never seen that error and the MV error display is just not enough.
You could enable the use of the console in a deployed project, so when someone gets that error, we could get more information.
Just comment this part out. This function can be found in rpg_managers.
PHP:
SceneManager.onKeyDown = function(event) {
    if (!event.ctrlKey && !event.altKey) {
        switch (event.keyCode) {
        case 116:   // F5
            if (Utils.isNwjs()) {
                location.reload();
            }
            break;
        case 119:   // F8
            if (Utils.isNwjs()/* && Utils.isOptionValid('test')*/) { <- that part
                require('nw.gui').Window.get().showDevTools();
            }
            break;
        }
    }
};

Or maybe someone else has an idea.
@waynee95 I'll do that! Thank you so much~ 😍
@waynee95 I'll do that! Thank you so much~ 😍
Good good, fix the problems😅, maybe there is an new version, still can't reproduce the error.

Original thread: https://forums.rpgmakerweb.com/threads/uncaught-error-header-is-wrong.83288/