blackhack-utils

Utility functions for blackhack

As of 2026-03-31. See the latest version.

This script should not be not be installed directly. It is a library for other scripts to include with the meta directive // @require https://update.greatest.deepsurf.us/scripts/571913/1787018/blackhack-utils.js

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           blackhack-utils
// @namespace      brofist.io 1st-cheat (FOR ALL MODES)
// @version        1.0
// @description    Utility functions for blackhack
// @author         CiNoP
// @license        GPL-3.0-only
// ==/UserScript==


/* blackhack-utils.js */
(function () {
	'use strict';
	const BH = window.BH = window.BH || {};

	BH.clamp = (v, min, max) => Math.max(min, Math.min(max, v));
	BH.round3 = v => Math.round(v * 1000) / 1000;

	const _c = document.createElement('canvas'), _x = _c.getContext('2d');
	BH.measureTextWidth = (fs, t) => { _x.font = fs + 'px Arial'; return Math.round(_x.measureText(t).width); };

	BH.STORAGE_KEY = 'blackhack_settings';
	BH.DEFAULTS = {
		mult: 3, gravScale: 2, jumpHeight: 8,
		mass: 1, damping: 0.9,
		alphaCollision: 1, alphaPoison: 1, alphaFunctional: 1
	};

	BH.saveSettings = () => {
		try {
			const v = window.hack.vars;
			localStorage.setItem(BH.STORAGE_KEY, JSON.stringify({
				mult: v.mult.uiValue, gravScale: v.gravNoclipGravScale,
				jumpHeight: v.jumpHeight, mass: v.playerMass, damping: v.playerDamping,
				alphaCollision: v.layoutAlpha.collision, alphaPoison: v.layoutAlpha.poison,
				alphaFunctional: v.layoutAlpha.functional
			}));
		} catch (_) {}
	};

	BH.loadSettings = () => {
		try {
			const raw = localStorage.getItem(BH.STORAGE_KEY);
			if (raw) return { ...BH.DEFAULTS, ...JSON.parse(raw) };
		} catch (_) {}
		return { ...BH.DEFAULTS };
	};

	// loadLZMA больше не нужна — LZMA загружается через @require
})();