tt fps

lighter TankTrouble visuals for smoother play.

You will need to install an extension such as Tampermonkey, Greasemonkey or Violentmonkey to install this script.

You will need to install an extension such as Tampermonkey to install this script.

You will need to install an extension such as Tampermonkey or Violentmonkey to install this script.

You will need to install an extension such as Tampermonkey or Userscripts to install this script.

You will need to install an extension such as Tampermonkey to install this script.

You will need to install a user script manager extension to install this script.

(I already have a user script manager, let me install it!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

(I already have a user style manager, let me install it!)

// ==UserScript==
// @name         tt fps
// @namespace    https://tanktrouble.com
// @version      4.5.2
// @description  lighter TankTrouble visuals for smoother play.
// @author       rydragnyx
// @license      MIT
// @match        https://tanktrouble.com/*
// @match        https://*.tanktrouble.com/*
// @run-at       document-idle
// @grant        none
// ==/UserScript==

(function () {
    var page = window;
    var scriptId = 'ttfps_452';
    var startupChecks = 0;
    var cleanTimer = 0;
    var warmupTimer = 0;

    if (page[scriptId]) return;
    page[scriptId] = true;

    function oldHudCleanup() {
        var staleIds = [
            'tt-stable-fps-hud',
            'tt-stable-fps-booster-css',
            'tt-b-hud',
            'tt-ub-css'
        ];
        var i;
        var node;

        for (i = 0; i < staleIds.length; i++) {
            node = document.getElementById(staleIds[i]);
            if (node && node.parentNode) node.parentNode.removeChild(node);
        }
    }

    function tuneTankTroubleConstants() {
        var ui = page.UIConstants;

        if (!ui) return false;

        // These are all local visual extras: rubble, smoke, glitter, trophy bits, camera shake, and menu workshop dust.
        ui.RUBBLE_FRAGMENT_POOL_SIZE = 0;
        ui.RUBBLE_FRAGMENT_MAX_LIFETIME = 0;
        ui.RUBBLE_FRAGMENT_MIN_LIFETIME = 0;
        ui.RUBBLE_FRAGMENT_MAX_ROTATION_SPEED = 0;
        ui.RUBBLE_FRAGMENT_SPEED_SCALE = 0;
        ui.RUBBLE_FRAGMENT_RANDOM_SPEED = 0;
        ui.RUBBLE_SMOKE_SPEED_SCALE = 0;
        ui.RUBBLE_SMOKE_RANDOM_SPEED = 0;
        ui.INVERSE_RUBBLE_SPAWN_PROBABILITY_IN_COLLISION = 9999;
        ui.INVERSE_RUBBLE_SPAWN_PROBABILITY_IN_THE_OPEN = 9999;

        ui.BULLET_PUFF_POOL_SIZE = 0;
        ui.EXPLOSION_FRAGMENT_COUNT = 0;
        ui.EXPLOSION_FRAGMENT_MIN_SPEED = 0;
        ui.EXPLOSION_FRAGMENT_MAX_SPEED = 0;
        ui.EXPLOSION_FRAGMENT_MIN_LIFETIME = 0;
        ui.EXPLOSION_FRAGMENT_MAX_LIFETIME = 0;
        ui.EXPLOSION_FRAGMENT_MAX_ROTATION_SPEED = 0;
        ui.CRATE_LAND_DUST_POOL_SIZE = 0;
        ui.MISSILE_LAUNCH_SMOKE_POOL_SIZE = 0;
        ui.MINE_EXPLOSION_SMOKE_POOL_SIZE = 0;
        ui.MISSILE_TRAIL_POOL_SIZE = 0;

        ui.SPAWN_ZONE_UNSTABLE_PARTICLE_NUM = 0;
        ui.SPAWN_ZONE_COLLAPSE_PARTICLE_NUM = 0;
        ui.INVERSE_SPAWN_ZONE_STABLE_BOLT_PROBABILITY = 9999;
        ui.INVERSE_SPAWN_ZONE_UNSTABLE_BOLT_PROBABILITY = 9999;
        ui.SPAWN_ZONE_NUM_BOLTS = 0;
        ui.SPAWN_ZONE_SPARK_SPEED = 0;
        ui.SPAWN_ZONE_SPARK_RANDOM_SPEED = 0;
        ui.SPAWN_ZONE_UNSTABLE_PARTICLE_SPEED = 0;
        ui.SPAWN_ZONE_UNSTABLE_PARTICLE_OFFSET = 0;
        ui.SPAWN_ZONE_UNSTABLE_SHAKE = 0;
        ui.SPAWN_ZONE_COLLAPSE_MIN_PARTICLE_SPEED = 0;
        ui.SPAWN_ZONE_COLLAPSE_MAX_PARTICLE_SPEED = 0;
        ui.SPAWN_ZONE_HOLE_1_ROTATION_SPEED = 0;
        ui.SPAWN_ZONE_HOLE_2_ROTATION_SPEED = 0;
        ui.SPAWN_ZONE_SWIRL_1_ROTATION_SPEED = 0;
        ui.SPAWN_ZONE_SWIRL_2_ROTATION_SPEED = 0;
        ui.SPAWN_ZONE_HOLE_EXPANSION_SIZE = 0;

        ui.SHIELD_LAYER_1_ROTATION_SPEED = 0;
        ui.SHIELD_LAYER_2_ROTATION_SPEED = 0;
        ui.SHIELD_BOLT_MIN_ROTATION_SPEED = 0;
        ui.SHIELD_BOLT_MAX_ROTATION_SPEED = 0;
        ui.SHIELD_SPARK_BOLT_POOL_SIZE = 0;
        ui.SHIELD_SPARK_SPEED = 0;
        ui.SHIELD_SPARK_RANDOM_SPEED = 0;
        ui.SHIELD_NUM_BOLTS = 0;
        ui.INVERSE_SHIELD_SPARK_PROBABILITY_IN_COLLISION = 9999;
        ui.INVERSE_SHIELD_WEAKENED_FLICKER_PROBABILITY = 9999;

        ui.COIN_FLY_POOL_SIZE = 0;
        ui.DIMITRIUM_FLY_POOL_SIZE = 0;
        ui.TANK_FEATHER_COUNT = 0;
        ui.TANK_FEATHER_POOL_SIZE = 0;
        ui.TROPHY_FRAGMENT_POOL_SIZE = 0;
        ui.TROPHY_BASE_FRAGMENT_POOL_SIZE = 0;
        ui.SPARKLE_POOL_SIZE = 0;
        ui.DIAMOND_SHINE_POOL_SIZE = 0;

        ui.CONFETTI_GRAVITY = 0;
        ui.CONFETTI_DRAG = 0;
        ui.CONFETTI_WOBBLE_AMPLITUDE = 0;
        ui.CONFETTI_MAX_X_SPEED = 0;
        ui.CONFETTI_MAX_Y_SPEED = 0;
        ui.CONFETTI_MIN_X_SPEED = 0;
        ui.CONFETTI_MIN_Y_SPEED = 0;
        ui.STREAMER_MAX_SPEED = 0;
        ui.STREAMER_MIN_SPEED = 0;
        ui.STREAMER_AMPLITUDE_X = 0;
        ui.STREAMER_AMPLITUDE_Y = 0;
        ui.SCORE_FRAGMENT_POOL_SIZE = 0;
        ui.MAX_SCORE_FRAGMENTS_PER_EXPLOSION = 0;
        ui.MIN_SCORE_FRAGMENTS_PER_LETTER = 0;
        ui.SCORE_EXPLOSION_DRAG = 0;
        ui.SCORE_EXPLOSION_MIN_X_SPEED = 0;
        ui.SCORE_EXPLOSION_MAX_X_SPEED = 0;
        ui.SCORE_EXPLOSION_MIN_Y_SPEED = 0;
        ui.SCORE_EXPLOSION_MAX_Y_SPEED = 0;
        ui.SCORE_FRAGMENT_MIN_SPEED = 0;
        ui.SCORE_FRAGMENT_MAX_SPEED = 0;
        ui.SCORE_FRAGMENT_MAX_ROTATION_SPEED = 0;

        ui.TANK_TREAD_BACK_SPEED = 0;
        ui.TANK_TREAD_FORWARD_SPEED = 0;
        ui.TANK_TREAD_INNER_BACK_SPEED = 0;
        ui.TANK_TREAD_INNER_FORWARD_SPEED = 0;
        ui.TANK_TREAD_TURN_SPEED = 0;

        ui.STORM_ZONE_STORM_PARTICLE_RANDOM_SPEED = 0;
        ui.STORM_ZONE_TILE_SPRITE_RANDOM_OFFSET = 0;
        ui.MAX_CAMERA_SHAKE = 0;
        ui.CAMERA_SHAKE_FADE = 0;
        ui.TANK_EXPLOSION_CAMERA_SHAKE = 0;
        ui.MINE_EXPLOSION_CAMERA_SHAKE = 0;

        ui.GARAGE_WELD_PARTICLE_TIME = 0;
        ui.GARAGE_WELD_SMOKE_TIME = 0;
        ui.GARAGE_WELD_SPARK_TIME = 0;
        ui.GARAGE_SPRAY_PARTICLE_TIME = 0;
        ui.GARAGE_SPRAY_SHAKE_PROBABILITY = 0;

        return true;
    }

    function cutQualityPreset(preset) {
        if (!preset) return;

        preset['tank explosion smoke count'] = 0;
        preset['tank explosion fragment count'] = 0;
        preset['missile launch smoke count'] = 0;
        preset['missile smoke frequency'] = 9999;
        preset['mine explosion smoke count'] = 0;
        preset['crate land dust count'] = 0;
        preset['bullet puff count'] = 0;
        preset['shield inverse bolt probability'] = 9999;
        preset['shield spark particles per emit'] = 0;
        preset['spawn zone inverse unstable particle probability'] = 9999;
        preset['spawn zone num collapse particles'] = 0;
        preset['storm zone num storm particles'] = 0;
    }

    function lightenQualityTable() {
        var table = page.QualityManager && page.QualityManager.QUALITY_VALUES;
        var name;

        if (!table) return false;

        cutQualityPreset(table.auto);
        cutQualityPreset(table.high);
        cutQualityPreset(table.medium);
        cutQualityPreset(table.low);
        cutQualityPreset(table.minimum);

        for (name in table) {
            if (Object.prototype.hasOwnProperty.call(table, name)) cutQualityPreset(table[name]);
        }

        return true;
    }

    function deadParticleCall() {
        if (this) {
            this.visible = false;
            this.exists = false;
            if (typeof this.kill === 'function') this.kill();
            if (typeof this.callAll === 'function') this.callAll('retire');
        }
        return false;
    }

    function muzzleTheTinyStuff() {
        var names = [
            'UIRubbleEmitter',
            'UIShieldSparkEmitter',
            'UISpawnZoneSparkEmitter',
            'UIExplosionEmitter',
            'UISmokeEmitter',
            'UIColouredSmokeEmitter',
            'UIMissileLaunchEmitter',
            'UIDustEmitter',
            'UIConfettiEmitter',
            'UITrophyExplosionEmitter',
            'UIScoreExplosionEmitter',
            'UIWelderSmokeEmitter',
            'UIWelderSparkEmitter',
            'UISprayCanEmitter',
            'UIRubbleGroup',
            'UIShieldSparkGroup'
        ];
        var sprites = [
            'UIRubbleFragmentSprite',
            'UIPuffSprite',
            'UIExplosionFragmentSprite',
            'UITankFeatherSprite',
            'UITrophyExplosionFragmentSprite',
            'UIScoreExplosionFragmentSprite',
            'UISparkleImage',
            'UIDiamondShineGroup',
            'UIConfettiParticle',
            'UIWelderSmokeParticle',
            'UIWelderSparkParticle',
            'UISprayCanParticle'
        ];
        var i;
        var proto;
        var obj;

        for (i = 0; i < names.length; i++) {
            obj = page[names[i]];
            proto = obj && obj.prototype;
            if (proto && !proto.__ttfpsQuiet) {
                if (typeof proto.emit === 'function') proto.emit = deadParticleCall;
                if (typeof proto.spawn === 'function') proto.spawn = deadParticleCall;
                if (typeof proto.explode === 'function') proto.explode = deadParticleCall;
                proto.__ttfpsQuiet = true;
            }
        }

        for (i = 0; i < sprites.length; i++) {
            obj = page[sprites[i]];
            proto = obj && obj.prototype;
            if (proto && !proto.__ttfpsQuiet) {
                if (typeof proto.spawn === 'function') proto.spawn = deadParticleCall;
                proto.__ttfpsQuiet = true;
            }
        }
    }

    function getMazeState() {
        var game = page.GameManager && page.GameManager.getGame ? page.GameManager.getGame() : page.game;
        if (game && game.state && game.state.getCurrentState) return game.state.getCurrentState();
        return null;
    }

    function fadeOneThing(thing) {
        if (!thing) return;

        if (typeof thing.retire === 'function') {
            thing.retire();
        } else {
            if (typeof thing.kill === 'function') thing.kill();
            thing.exists = false;
            thing.visible = false;
        }
    }

    function emptyGroup(group) {
        var i;

        if (!group) return;

        if (typeof group.callAll === 'function') group.callAll('retire');

        if (group.children && group.children.length) {
            for (i = 0; i < group.children.length; i++) fadeOneThing(group.children[i]);
        }
    }

    function cleanRoundLeftovers() {
        var round = getMazeState();

        if (!round) return;

        emptyGroup(round.rubbleGroup);
        emptyGroup(round.bulletPuffGroup);
        emptyGroup(round.shieldSparkGroup);
        emptyGroup(round.tankFeatherGroup);
        emptyGroup(round.explosionGroup);
        emptyGroup(round.tankExplosionGroup);
        emptyGroup(round.celebrationTrophyGroup);
        emptyGroup(round.diamondShineGroup);
        emptyGroup(round.sparkleGroup);
        emptyGroup(round.missileSmokeGroup);
        emptyGroup(round.missileLaunchGroup);
        emptyGroup(round.dustGroup);
    }

    function rendererNudges() {
        var game = page.GameManager && page.GameManager.getGame ? page.GameManager.getGame() : page.game;
        var canvas;
        var ctx;
        var nowFps;

        if (!game) return;

        if (game.time) {
            game.time.advancedTiming = true;
            nowFps = Number(game.time.desiredFps) || 0;
            game.time.desiredFps = Math.max(nowFps, 240);
            game.time.desiredFpsMult = 1 / 240;
        }

        if (typeof game.forceSingleUpdate === 'boolean') game.forceSingleUpdate = true;
        if (game.stage) game.stage.smoothed = false;
        if (game.renderer && game.renderer.renderSession) game.renderer.renderSession.roundPixels = true;

        canvas = game.canvas || document.querySelector('canvas');
        ctx = canvas && canvas.getContext ? canvas.getContext('2d') : null;
        if (ctx) {
            ctx.imageSmoothingEnabled = false;
            ctx.webkitImageSmoothingEnabled = false;
            ctx.mozImageSmoothingEnabled = false;
            ctx.msImageSmoothingEnabled = false;
        }
    }

    function pass() {
        oldHudCleanup();
        tuneTankTroubleConstants();
        lightenQualityTable();
        muzzleTheTinyStuff();
        rendererNudges();
        cleanRoundLeftovers();
    }

    function start() {
        pass();

        warmupTimer = setInterval(function () {
            startupChecks++;
            pass();
            if (startupChecks > 35) clearInterval(warmupTimer);
        }, 1600);

        cleanTimer = setInterval(pass, 2100);
    }

    page.__ttfps = {
        run: pass,
        bye: function () {
            clearInterval(cleanTimer);
            clearInterval(warmupTimer);
        },
        version: '4.5.2'
    };

    if (document.readyState === 'loading') {
        document.addEventListener('DOMContentLoaded', start, false);
    } else {
        start();
    }
})();