Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 15 additions & 15 deletions failsafes/AlertUtils.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { drawRect, drawText } from '../gui/Utils';
import { Chat } from '../utils/Chat';
import { chatFailsafe } from '../utils/Chat';
import { File, globalAssetsDir } from '../utils/Constants';
import { Utils } from '../utils/Utils';
import { getConfigFile, writeConfigFile } from '../utils/Utils';
import FailsafeUtils from './FailsafeUtils';

let failsafeSound = 'Tave Check.wav';
Expand Down Expand Up @@ -42,8 +42,8 @@ class AlertUtilsClass {
triggerReaction() {
if (this.isAlerting) return;

Chat.messageFailsafe('Suspicious activity detected, reaction occuring!');
Chat.messageFailsafe(`Press &c&l${this.cancelKey}&r &fto disable the reaction`);
chatFailsafe('Suspicious activity detected, reaction occuring!');
chatFailsafe(`Press &c&l${this.cancelKey}&r &fto disable the reaction`);

this.isAlerting = true;
this.playSound();
Expand Down Expand Up @@ -87,12 +87,12 @@ class AlertUtilsClass {
drawText(line2End, currentX2, y2, fontSize, redColor);
NVG.restore();
} catch (e) {
console.error('V5 Caught error' + e + e.stack);
console.error(e);
} finally {
try {
NVG.endFrame();
} catch (e) {
console.error('V5 Caught error' + e + e.stack);
console.error(e);
}
}
});
Expand Down Expand Up @@ -163,7 +163,7 @@ class AlertUtilsClass {
}
} catch (e) {
this._closeSound();
console.error('V5 Caught error' + e + e.stack);
console.error(e);
}
}

Expand All @@ -173,7 +173,7 @@ class AlertUtilsClass {
this.clip.stop();
this.clip.close();
} catch (e) {
console.error('V5 Caught error' + e + e.stack);
console.error(e);
}
this.clip = null;
}
Expand All @@ -182,7 +182,7 @@ class AlertUtilsClass {
try {
this.audioStream.close();
} catch (e) {
console.error('V5 Caught error' + e + e.stack);
console.error(e);
}
this.audioStream = null;
}
Expand All @@ -208,7 +208,7 @@ class AlertUtilsClass {
*/
_makeFailsafeKeybind() {
const keyName = 'Cancel Reaction';
const existingKeybinds = Utils.getConfigFile('keybinds.json') || {};
const existingKeybinds = getConfigFile('keybinds.json') || {};
let savedKeycode = existingKeybinds[keyName];

if (savedKeycode === undefined || savedKeycode === 0 || savedKeycode === -1 || savedKeycode === 75) savedKeycode = Keyboard.KEY_K;
Expand All @@ -218,16 +218,16 @@ class AlertUtilsClass {

this.cancelKeyBind.registerKeyPress(() => {
if (!this.isAlerting) return;
Chat.messageFailsafe('Reaction disabled due to keybind being pressed');
chatFailsafe('Reaction disabled due to keybind being pressed');
this.disableReaction();
});

register('gameUnload', () => {
this.disableReaction();
this._closeSound();
const allKeybinds = Utils.getConfigFile('keybinds.json') || {};
const allKeybinds = getConfigFile('keybinds.json') || {};
allKeybinds[keyName] = this.cancelKeyBind.getKeyCode();
Utils.writeConfigFile('keybinds.json', allKeybinds);
writeConfigFile('keybinds.json', allKeybinds);
});
}

Expand Down Expand Up @@ -256,8 +256,8 @@ class AlertUtilsClass {
GLFW.glfwFocusWindow(windowHandle);
GLFW.glfwRequestWindowAttention(windowHandle);
} catch (e) {
Chat.messageFailsafe('GLFW error occured! report this. ' + e);
console.error('V5 Caught error' + e + e.stack);
chatFailsafe('GLFW error occured! report this. ' + e);
console.error(e);
}
}
}
Expand Down
10 changes: 5 additions & 5 deletions failsafes/Failsafe.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { manager } from '../utils/SkyblockEvents';
import { MacroState } from '../utils/MacroState';
import { finiteNumber } from '../utils/NumberUtils';
import { registerSkyblockEvent } from '../utils/SkyblockEvents';
import { isFailsafeMacroRunning } from '../utils/MacroState';
import { finiteNumber } from '../utils/Math';
export class Failsafe {
registered = false;
disabled = false;
Expand All @@ -15,7 +15,7 @@ export class Failsafe {
return true;
}
isActive() {
return MacroState.isFailsafeMacroRunning();
return isFailsafeMacroRunning();
}
onTrigger() {}
reset() {
Expand Down Expand Up @@ -52,7 +52,7 @@ export class Failsafe {
register('worldLoad', () => {
this._setDisabled(1000);
});
['serverchange', 'death', 'warp'].forEach((event) => manager.subscribe(event, () => this._setDisabled(1000)));
['serverchange', 'death', 'warp'].forEach((event) => registerSkyblockEvent(event, () => this._setDisabled(1000)));
}

_getReactionDelay(settings) {
Expand Down
25 changes: 6 additions & 19 deletions failsafes/FailsafeManager.js
Original file line number Diff line number Diff line change
@@ -1,19 +1,6 @@
import ChatMentionFailsafe from './impl/ChatMentionFailsafe';
import PlayerGriefFailsafe from './impl/PlayerGriefFailsafe';
import RotationFailsafe from './impl/RotationFailsafe';
import SlotChangeFailsafe from './impl/SlotChangeFailsafe';
import TeleportFailsafe from './impl/TeleportFailsafe';
import VelocityFailsafe from './impl/VelocityFailsafe';

// just keep it here to import all the failsafes to loader :)
class FailsafeManager {
constructor() {
this.failsafes = [ChatMentionFailsafe, PlayerGriefFailsafe, RotationFailsafe, SlotChangeFailsafe, TeleportFailsafe, VelocityFailsafe];
}

getFailsafes() {
return this.failsafes;
}
}

export default new FailsafeManager();
import './impl/ChatMentionFailsafe';
import './impl/PlayerGriefFailsafe';
import './impl/RotationFailsafe';
import './impl/SlotChangeFailsafe';
import './impl/TeleportFailsafe';
import './impl/VelocityFailsafe';
12 changes: 5 additions & 7 deletions failsafes/FailsafeUtils.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { V5ConfigFile } from '../utils/Constants';
import { finiteNumber } from '../utils/NumberUtils';
import { finiteNumber } from '../utils/Math';

const DEFAULT_FAILSAFE_SETTINGS = {
isEnabled: true,
Expand All @@ -19,7 +19,6 @@ class FailsafeUtils {
config: {},
normalized: null,
};
this._utils = null;
}

_getConfig() {
Expand All @@ -30,8 +29,7 @@ class FailsafeUtils {
return this._cache.config;
}

if (!this._utils) this._utils = require('../utils/Utils').Utils;
const config = this._utils.getConfigFile('config.json');
const config = require('../utils/Utils').getConfigFile('config.json');

this._cache.expiresAt = now + 250;
this._cache.lastModified = lastModified;
Expand Down Expand Up @@ -117,12 +115,12 @@ class FailsafeUtils {
}

sendFailsafeEmbed(type, severity, description, color) {
const { Webhook } = require('../utils/Webhooks');
const { sendFailsafeEmbed, sendFailsafeScreenshot } = require('../utils/Webhooks');

const pingOnCheckValue = this.getFailsafeSettings(type).pingOnCheck;

if (pingOnCheckValue === 'Ping' || pingOnCheckValue === 'Embed Only') {
Webhook.sendFailsafeEmbed(
sendFailsafeEmbed(
[
{
title: `**[${severity.toUpperCase()}]** ${type} Failsafe Triggered!`,
Expand All @@ -136,7 +134,7 @@ class FailsafeUtils {
);
} else if (pingOnCheckValue === 'Ping & Screenshot' || pingOnCheckValue === 'Screenshot Only') {
Client.scheduleTask(5, () =>
Webhook.sendFailsafeScreenshot(
sendFailsafeScreenshot(
`**[${severity.toUpperCase()}]** ${type} Failsafe Triggered!`,
description,
color,
Expand Down
6 changes: 3 additions & 3 deletions failsafes/impl/ChatMentionFailsafe.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Chat } from '../../utils/Chat';
import { chatFailsafe } from '../../utils/Chat';
import { Failsafe } from '../Failsafe';
import FailsafeUtils from '../FailsafeUtils';
import { ClientboundSystemChatPacket } from '../../utils/Packets';
Expand Down Expand Up @@ -51,7 +51,7 @@ class ChatMentionFailsafe extends Failsafe {
const severity = result.isHigh ? 'high' : 'medium';
const embedColour = result.isHigh ? 16744448 : 16776960;

Chat.messageFailsafe(`&c&lDetected blacklisted word - "${result.blockedWord}"!`);
chatFailsafe(`&c&lDetected blacklisted word - "${result.blockedWord}"!`);
FailsafeUtils.incrementFailsafeIntensity(pressure);
FailsafeUtils.sendFailsafeEmbed(
'Chat Mention',
Expand All @@ -62,4 +62,4 @@ class ChatMentionFailsafe extends Failsafe {
}
}

export default new ChatMentionFailsafe();
new ChatMentionFailsafe();
10 changes: 5 additions & 5 deletions failsafes/impl/PlayerGriefFailsafe.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Chat } from '../../utils/Chat';
import { chatFailsafe } from '../../utils/Chat';
import { File, globalAssetsDir } from '../../utils/Constants';
import { Failsafe } from '../Failsafe';
import FailsafeUtils from '../FailsafeUtils';
Expand All @@ -7,7 +7,7 @@ const warpPoints = (() => {
try {
return JSON.parse(FileLib.read(new File(globalAssetsDir, 'WarpPoints.json').getPath()) || '{}').warps || [];
} catch (e) {
console.error('V5 Caught error' + e + e.stack);
console.error(e);
return [];
}
})();
Expand Down Expand Up @@ -69,7 +69,7 @@ class PlayerGriefFailsafe extends Failsafe {
const lz = look.getZ();

if (Math.trunc(lx) === Math.trunc(px) && Math.trunc(ly) === Math.trunc(py) && Math.trunc(lz) === Math.trunc(pz)) {
Chat.messageFailsafe(`&c&l${lookedName} is standing inside you!`);
chatFailsafe(`&c&l${lookedName} is standing inside you!`);
FailsafeUtils.incrementFailsafeIntensity(120);
FailsafeUtils.sendFailsafeEmbed('Player Grief', 'very high', `${lookedName} is standing inside you!`, 16711680);

Expand Down Expand Up @@ -101,7 +101,7 @@ class PlayerGriefFailsafe extends Failsafe {

if (distanceSq <= maxDistanceSq && distanceSq > 1) {
const distance = Math.sqrt(distanceSq);
Chat.messageFailsafe(`&c&l${playerName} is ${distance.toFixed(1)} blocks away from you!`);
chatFailsafe(`&c&l${playerName} is ${distance.toFixed(1)} blocks away from you!`);
FailsafeUtils.incrementFailsafeIntensity(20);
FailsafeUtils.sendFailsafeEmbed('Player Grief', 'medium', `${playerName} is ${distance.toFixed(1)} blocks away!`, 16776960);

Expand All @@ -111,4 +111,4 @@ class PlayerGriefFailsafe extends Failsafe {
}
}

export default new PlayerGriefFailsafe();
new PlayerGriefFailsafe();
18 changes: 9 additions & 9 deletions failsafes/impl/RotationFailsafe.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Chat } from '../../utils/Chat';
import { MathUtils } from '../../utils/Math';
import { chatDebug, chatFailsafe } from '../../utils/Chat';
import { getAngleDifference } from '../../utils/Math';
import { ClientboundPlayerPositionPacket } from '../../utils/Packets';
import { Failsafe } from '../Failsafe';
import FailsafeUtils from '../FailsafeUtils';
Expand Down Expand Up @@ -37,12 +37,12 @@ class RotationFailsafe extends Failsafe {
const dz = Math.abs(newZ - fromZ);
const posDistance = Math.hypot(dx, dy, dz);

const yawDiff = Math.abs(MathUtils.getAngleDifference(currYaw, newYaw));
const yawDiff = Math.abs(getAngleDifference(currYaw, newYaw));
const pitchDiff = Math.abs(newPitch - currPitch);

// todo: this isnt what a null rotation packet is, which retard made these failsafes?
if (yawDiff === 0 && pitchDiff === 0) {
Chat.messageDebug('null rotation packet ignored (yawDiff=0, pitchDiff=0)', false);
chatDebug('null rotation packet ignored (yawDiff=0, pitchDiff=0)', false);
return;
}

Expand All @@ -68,10 +68,10 @@ class RotationFailsafe extends Failsafe {

const { pressure, severity, color } = tiers.find((t) => totalRotation < t.limit);

Chat.messageFailsafe(`&c&lYou were rotated by the server!`, false);
Chat.messageFailsafe(`&c&lFrom: &r&7Yaw ${fromYaw.toFixed(2)} &f| &7Pitch ${fromPitch.toFixed(2)}`, false);
Chat.messageFailsafe(`&c&lTo: &r&7Yaw ${toYaw.toFixed(2)} &f| &7Pitch ${toPitch.toFixed(2)}`, false);
Chat.messageFailsafe(`&c&lTotal Rotation: &r&7${totalRotation.toFixed(2)}°`, true);
chatFailsafe(`&c&lYou were rotated by the server!`, false);
chatFailsafe(`&c&lFrom: &r&7Yaw ${fromYaw.toFixed(2)} &f| &7Pitch ${fromPitch.toFixed(2)}`, false);
chatFailsafe(`&c&lTo: &r&7Yaw ${toYaw.toFixed(2)} &f| &7Pitch ${toPitch.toFixed(2)}`, false);
chatFailsafe(`&c&lTotal Rotation: &r&7${totalRotation.toFixed(2)}°`, true);
FailsafeUtils.incrementFailsafeIntensity(pressure);

FailsafeUtils.sendFailsafeEmbed(
Expand All @@ -85,4 +85,4 @@ class RotationFailsafe extends Failsafe {
}
}

export default new RotationFailsafe();
new RotationFailsafe();
6 changes: 3 additions & 3 deletions failsafes/impl/SlotChangeFailsafe.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Chat } from '../../utils/Chat';
import { chatFailsafe } from '../../utils/Chat';
import { ClientboundSetHeldSlotPacket } from '../../utils/Packets';
import { Failsafe } from '../Failsafe';
import FailsafeUtils from '../FailsafeUtils';
Expand Down Expand Up @@ -30,10 +30,10 @@ class SlotChangeFailsafe extends Failsafe {
}

onTrigger(fromSlot, toSlot) {
Chat.messageFailsafe(`&c&lHeld slot has changed from ${fromSlot} to slot ${toSlot}!`);
chatFailsafe(`&c&lHeld slot has changed from ${fromSlot} to slot ${toSlot}!`);
FailsafeUtils.incrementFailsafeIntensity(50);
FailsafeUtils.sendFailsafeEmbed('Slot Change', 'high', `Slot changed from ${fromSlot} to ${toSlot}!`, 16744448);
}
}

export default new SlotChangeFailsafe();
new SlotChangeFailsafe();
20 changes: 10 additions & 10 deletions failsafes/impl/TeleportFailsafe.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Chat } from '../../utils/Chat';
import { MathUtils } from '../../utils/Math';
import { chatDebug, chatFailsafe } from '../../utils/Chat';
import { getAngleDifference } from '../../utils/Math';
import { ServerboundUseItemPacket, ClientboundPlayerPositionPacket, ServerboundChatCommandPacket } from '../../utils/Packets';
import PathConfig from '../../utils/pathfinder/PathConfig';
import { Failsafe } from '../Failsafe';
Expand Down Expand Up @@ -39,7 +39,7 @@ class TeleportFailsafe extends Failsafe {
const command = packet.command().toLowerCase();
if (command.includes('warp')) {
lastCommandTime = Date.now();
Chat.messageDebug(`warp command used, awaiting warp-point teleport ignore`, false);
chatDebug(`warp command used, awaiting warp-point teleport ignore`, false);
pendingWarpIgnore = true;
if (pendingWarpIgnoreTimer) clearTimeout(pendingWarpIgnoreTimer);
pendingWarpIgnoreTimer = setTimeout(() => {
Expand Down Expand Up @@ -79,7 +79,7 @@ class TeleportFailsafe extends Failsafe {
const { yaw, pitch, currYaw, currPitch } = data;
if (yaw === undefined || pitch === undefined) return false;

const yawDiff = Math.abs(MathUtils.getAngleDifference(currYaw, yaw));
const yawDiff = Math.abs(getAngleDifference(currYaw, yaw));
const pitchDiff = Math.abs(pitch - currPitch);
return yawDiff < 30 && pitchDiff < 30;
}
Expand Down Expand Up @@ -184,17 +184,17 @@ class TeleportFailsafe extends Failsafe {
}

handleNullPacket(x, y, z) {
Chat.messageFailsafe('&c&lNULL PACKET DETECTED, DO NOT REACT!', false);
chatFailsafe('&c&lNULL PACKET DETECTED, DO NOT REACT!', false);
FailsafeUtils.sendFailsafeEmbed('TP', 'very high - null packet', `You just recieved a null packet to ${x}, ${y}, ${z}!`, 16711680);
}

onTrigger(fX, fY, fZ, nX, nY, nZ, dist) {
const { pressure, severity, color } = TELEPORT_TIERS.find((t) => dist < t.threshold);

Chat.messageFailsafe(`&l&cTeleport Detected!`, false);
Chat.messageFailsafe(`&c&lFrom: &r&7${fX.toFixed(2)}&f, &7${fY.toFixed(2)}&f, &7${fZ.toFixed(2)}&f`, false);
Chat.messageFailsafe(`&c&lTo: &r&7${nX.toFixed(2)}&f, &7${nY.toFixed(2)}&f, &7${nZ.toFixed(2)}&f`, false);
Chat.messageFailsafe(`&c&lTotal Blocks: &r&7${dist.toFixed(0)}`, true);
chatFailsafe(`&l&cTeleport Detected!`, false);
chatFailsafe(`&c&lFrom: &r&7${fX.toFixed(2)}&f, &7${fY.toFixed(2)}&f, &7${fZ.toFixed(2)}&f`, false);
chatFailsafe(`&c&lTo: &r&7${nX.toFixed(2)}&f, &7${nY.toFixed(2)}&f, &7${nZ.toFixed(2)}&f`, false);
chatFailsafe(`&c&lTotal Blocks: &r&7${dist.toFixed(0)}`, true);
FailsafeUtils.incrementFailsafeIntensity(pressure);

FailsafeUtils.sendFailsafeEmbed(
Expand All @@ -208,4 +208,4 @@ class TeleportFailsafe extends Failsafe {
}
}

export default new TeleportFailsafe();
new TeleportFailsafe();
Loading
Loading