coryshaw1 / saliens-hack

Hack for Sailens, the game of Steam Summer Sale 2018 - AutoSelect Planet, Invincibility, and InstaKill
MIT License
106 stars 31 forks source link

Uncaught TypeError: Cannot read property 'destroy' of undefined at CBattleSelectionState.Shutdown #37

Open csis0247 opened 6 years ago

csis0247 commented 6 years ago

I am getting this error occasionally whenever a round has ended, but before printing "round done" to console, and the script has been unable to recover from it.

Uncaught TypeError: Cannot read property 'destroy' of undefined
    at CBattleSelectionState.Shutdown (game.js?v=cQtonveOglA4&l=english:1299)
    at CGame.Update (game.js?v=cQtonveOglA4&l=english:108)
    at t.gApp.ticker.add [as fn] (game.js?v=cQtonveOglA4&l=english:69)
    at t.emit (pixi.min.js?v=.tDHAybGykI1O:16)
    at t.update (pixi.min.js?v=.tDHAybGykI1O:16)
    at Window._tick (pixi.min.js?v=.tDHAybGykI1O:16)
    at <anonymous>:2:491
    at e.string.g.function.c.(/saliengame/play/anonymous function) (eval at exec_fn (:1:107), <anonymous>:52:483)
csis0247 commented 6 years ago

I made some makeshift adjustments to the code, and it has been running for 9 hours without any major issue. There may still be difficulty exiting the planet once it has been conquered, but it is very likely that it is Steam's issue rather than the script's, as I cannot manually leave the planet either, for minutes.

Step 1: Add a global error catching function in an empty space just below the header comments and above the first line of real code "(function() {..." , to allow recovery after the occurrence of the above exception (or in fact any uncatched exception).

window.onerror = function(msg, url, line, col, error) {
    // Basically I copied the original reload method to a "global" level.
    setTimeout(function() {
        if (typeof unsafeWindow !== "undefined")
            unsafeWindow.location.reload();
        else
            window.location.reload();
    }, 750);

    var suppressErrorAlert = true;
    // If you return true, then error alerts (like in older versions of
    // Internet Explorer) will be suppressed.
    return suppressErrorAlert;
};

Step 2: I am not certain if it really is useful. But the rate of error was reduced after I increased the interval of the "loop".

Change all

setInterval(gameCheck, 100)

into

setInterval(gameCheck, 200)

Effectively doubling the timer interval, whatever it does.

Step 3: This change is irrelevant, but I added it to keep track of my progress (score) in the console.

Look for the line:

console.log('Joining zone:', zoneId);

And add the following line below it:

console.log('Current score: ' + gPlayerInfo.score);
coryshaw1 commented 6 years ago

My only worry with overwriting window.onerror is being able to help users that are saying that they are just constantly refreshing. They could keep "Preserve Log" checked in console, but it adds an extra problem to try support them with.