Skip to content

Commit

Permalink
wawa
Browse files Browse the repository at this point in the history
  • Loading branch information
jasonlaubb committed Feb 8, 2025
1 parent 9bb26ae commit b507d32
Show file tree
Hide file tree
Showing 10 changed files with 120 additions and 126 deletions.
4 changes: 2 additions & 2 deletions Matrix_BP/src/program/detection/entityFly.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ const FACTOR = 100;
function tickEvent(tickData: TickData, player: Player) {
const isRiding = player.getComponent("riding")?.entityRidingOn;
const data = tickData.entityFly;
const { x, y: velocityY, z } = player.getVelocity();
const { y: velocityY } = tickData.instant.velocity;
data.pastVelocityY.push(velocityY);
data.pastVelocityY.shift();
if (!isRiding) {
Expand All @@ -55,7 +55,7 @@ function tickEvent(tickData: TickData, player: Player) {
data.pastVelocityY = new Array(10).fill(0);
}
}
const horizontalSpeed = Math.sqrt(x ** 2 + z ** 2);
const horizontalSpeed = tickData.instant.speedXZ;
if (velocityY === 0 && horizontalSpeed > SPEED_THRESHOLD && !isRiding.isOnGround && player.isOnGround) {
data.prefectCombo++;
if (data.prefectCombo >= MIN_COMBO_BEFORE_FLAG) {
Expand Down
51 changes: 18 additions & 33 deletions Matrix_BP/src/program/detection/fly.ts
Original file line number Diff line number Diff line change
@@ -1,25 +1,15 @@
import { EquipmentSlot, GameMode, Player, system, Vector3 } from "@minecraft/server";
import { EquipmentSlot, GameMode, Player, system } from "@minecraft/server";
import { IntegratedSystemEvent, Module } from "../../matrixAPI";
import { rawtextTranslate } from "../../util/rawtext";
import { isSurroundedByAir } from "../../util/util";
import { MinecraftEffectTypes, MinecraftItemTypes } from "../../node_modules/@minecraft/vanilla-data/lib/index";
import { fastAbs } from "../../util/fastmath";
import { TickData } from "../import";
const MAX_VELOCITY_Y = 0.7;
const MIN_REQUIRED_REPEAT_AMOUNT = 6;
const HIGH_VELOCITY_Y = 22;
const MAX_BDS_PREDICTION = 20;
const START_SKIP_CHECK = 6000;
interface FlyData {
previousVelocityY: number;
lastVelocityY: number;
lastOnGroundLocation: Vector3;
lastFlaggedLocation: Vector3;
velocityYList: number[];
flagAmount: number;
lastFlagTimestamp: number;
hasStarted: number;
}
const flyData = new Map<string, FlyData>();
let eventId: IntegratedSystemEvent;
const fly = new Module()
.addCategory("detection")
Expand All @@ -32,45 +22,41 @@ const fly = new Module()
})
.onModuleDisable(() => {
Module.clearPlayerTickEvent(eventId);
flyData.clear();
})
.initPlayer((playerId, player) => {
flyData.set(playerId, {
lastVelocityY: 0,
.initPlayer((tickData, _playerId, player) => {
tickData.fly = {
lastOnGroundLocation: player.location,
velocityYList: [],
velocityYList: new Array(60).fill(0),
lastFlaggedLocation: player.location,
flagAmount: 0,
lastFlagTimestamp: 0,
hasStarted: Date.now(),
previousVelocityY: 0,
});
})
.initClear((playerId) => {
flyData.delete(playerId);
};
return tickData;
});
fly.register();
/**
* @author jasonlaubb
* @description Anti Fly.
*/
function tickEvent(player: Player) {
function tickEvent(tickData: TickData, player: Player) {
const hasFlyDebugTag = player.hasTag("matrix:flyDebug");
const now = Date.now();
const data = flyData.get(player.id)!;
const { y: velocityY } = player.getVelocity();
const data = tickData.fly;
const { y: velocityY } = tickData.instant.velocity;
const surroundAir = !player.isOnGround && isSurroundedByAir(player.location, player.dimension);
const playerStarted = now - data.hasStarted > START_SKIP_CHECK;
const isPlayerNotCreative = player.getGameMode() !== GameMode.creative;
const pistonNotPushed = now - player.timeStamp.pistonPush > 4000;
const previousVelY = data.velocityYList[1];
if (player.isOnGround && velocityY === 0) {
data.lastOnGroundLocation = player.location;
} else if (
playerStarted &&
pistonNotPushed &&
now - player.timeStamp.knockBack > 2000 &&
now - player.timeStamp.riptide > 5000 &&
(data.lastVelocityY < 0 || (data.previousVelocityY < 0 && velocityY === 0) || (velocityY > 0 && data.previousVelocityY / velocityY > 4 && data.previousVelocityY > 2.5 && fastAbs(data.lastVelocityY - velocityY) < 0.5)) &&
(previousVelY < 0 || (previousVelY < 0 && velocityY === 0) || (velocityY > 0 && previousVelY / velocityY > 4 && previousVelY > 2.5 && fastAbs(tickData.global.lastVelocity.y- velocityY) < 0.5)) &&
!player.isRiding() &&
!player.isFlying &&
!player.isGliding &&
Expand All @@ -89,7 +75,7 @@ function tickEvent(player: Player) {
if (data.flagAmount >= Module.config.sensitivity.antiFly.type1MaxFlag) {
data.flagAmount = 0;
player.teleport(data.lastOnGroundLocation);
player.flag(fly, { t: "1", lastVelocityY: data.lastVelocityY, velocityY });
player.flag(fly, { t: "1", lastVelocityY: tickData.global.lastVelocity.y, velocityY });
}
}
}
Expand All @@ -102,11 +88,11 @@ function tickEvent(player: Player) {
player.flag(fly, { t: "2", velocityY });
}
if (player.isFlying) {
data.velocityYList.push(HIGH_VELOCITY_Y);
data.velocityYList.unshift(HIGH_VELOCITY_Y);
} else {
data.velocityYList.push(velocityY);
data.velocityYList.unshift(velocityY);
}
if (data.velocityYList.length > 60) data.velocityYList.shift();
data.velocityYList.pop();
const minAmount = Math.min(...data.velocityYList);
const maxAmount = Math.max(...data.velocityYList);
const bdsPrediction = calculateBdsPrediction(data.velocityYList);
Expand All @@ -127,9 +113,8 @@ function tickEvent(player: Player) {
});
data.lastFlaggedLocation = player.location;
}
data.previousVelocityY = data.lastVelocityY;
data.lastVelocityY = velocityY;
flyData.set(player.id, data);
tickData.fly = data;
return tickData;
}

function repeatChecks(list: number[]) {
Expand Down
9 changes: 6 additions & 3 deletions Matrix_BP/src/program/detection/insteabreak.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { BlockPermutation, Dimension, EntityHitBlockAfterEvent, ItemStack, Playe
import { IntegratedSystemEvent, Module } from "../../matrixAPI";
import { rawtextTranslate } from "../../util/rawtext";
import { MinecraftBlockTypes, MinecraftEffectTypes, MinecraftEnchantmentTypes, MinecraftItemTypes } from "../../node_modules/@minecraft/vanilla-data/lib/index";
import { TickData } from "../import";
type BrokenBlockList = { blockPermutation: BlockPermutation; blockPosition: Vector3 }[];
interface BreakData {
brokenBlocks: BrokenBlockList;
Expand Down Expand Up @@ -29,8 +30,9 @@ const insteabreak = new Module()
Module.clearPlayerTickEvent(eventId);
breakData = {};
})
.initPlayer((playerId) => {
.initPlayer((tickData, playerId) => {
breakData[playerId] = DEFAULT_BREAK_DATA;
return tickData;
})
.initClear((playerId) => {
delete breakData[playerId];
Expand All @@ -57,14 +59,15 @@ function onPlayerHitBlock({ damagingEntity: player }: EntityHitBlockAfterEvent)
breakData[player.id].startBreakingTime = Date.now();
}
}
function tickEvent(player: Player) {
if (breakData[player.id].brokenBlocks.length == 0) return;
function tickEvent(tickData: TickData, player: Player) {
if (breakData[player.id].brokenBlocks.length == 0) return tickData;
if (breakData[player.id].brokenAmount > MAX_BREAK_IN_TICK || breakData[player.id].flagInsteaBreak) {
// Recover the blocks
system.runJob(recoverBlocks(breakData[player.id].brokenBlocks, player.dimension));
player.flag(insteabreak, { type: breakData[player.id].flagInsteaBreak ? "instabreak" : "nuking", breakAmount: breakData[player.id].brokenAmount });
}
breakData[player.id] = DEFAULT_BREAK_DATA;
return tickData;
}
function isTool(itemStack: ItemStack) {
TOOL_SET.has(itemStack.type.id as MinecraftItemTypes);
Expand Down
43 changes: 18 additions & 25 deletions Matrix_BP/src/program/detection/invalidSprint.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,9 @@ import { Player } from "@minecraft/server";
import { MinecraftEffectTypes } from "../../node_modules/@minecraft/vanilla-data/lib/index";
import { IntegratedSystemEvent, Module } from "../../matrixAPI";
import { rawtextTranslate } from "../../util/rawtext";
import { TickData } from "../import";
import { compareLoc } from "../../util/util";
let runId: IntegratedSystemEvent;
interface SprintData {
flagCount: number;
nonBlindnessSprintState: boolean;
}
const sprintData = new Map<string, SprintData>();
const invalidSprint = new Module()
.setName(rawtextTranslate("module.invalidSprint.name"))
.setDescription(rawtextTranslate("module.invalidSprint.description"))
Expand All @@ -18,44 +15,40 @@ const invalidSprint = new Module()
runId = Module.subscribePlayerTickEvent(tickEvent, false);
})
.onModuleDisable(() => {
sprintData.clear();
Module.clearPlayerTickEvent(runId);
})
.initPlayer((playerId, player) => {
sprintData.set(playerId, {
.initPlayer((tickData, _playerId, player) => {
tickData.invalidSprint ={
flagCount: 0,
nonBlindnessSprintState: player.isSprinting,
});
})
.initClear((playerId) => {
sprintData.delete(playerId);
};
return tickData;
});
invalidSprint.register();
function isMovementKeyPressed(player: Player) {
const { x, y } = player.inputInfo.getMovementVector();
return x !== 0 || y !== 0;
}
function tickEvent(player: Player) {
const data = sprintData.get(player.id)!;
function tickEvent(tickData: TickData, player: Player) {
if (!player.isSprinting) {
if (data.flagCount > 0) {
data.flagCount--;
sprintData.set(player.id, data);
if (tickData.invalidSprint.flagCount > 0) {
tickData.invalidSprint.flagCount--;
return tickData;
}
return;
return tickData;
};
const hasEffect = player.getEffect(MinecraftEffectTypes.Blindness);
if ((player.isSneaking || !isMovementKeyPressed(player)) && !player.isSwimming) {
data.flagCount++;
if (data.flagCount > Module.config.sensitivity.antiInvalidSprint.maxFlag) {
if ((player.isSneaking || !isMovementKeyPressed(player)) && !player.isSwimming && !compareLoc(player.location, tickData.global.lastLocation)) {
tickData.invalidSprint.flagCount++;
if (tickData.invalidSprint.flagCount > Module.config.sensitivity.antiInvalidSprint.maxFlag) {
player.flag(invalidSprint, { t: "1" });
}
} else if (data.flagCount > 0) data.flagCount = 0;
if (hasEffect && player.isSprinting && !data.nonBlindnessSprintState) {
} else if (tickData.invalidSprint.flagCount > 0) tickData.invalidSprint.flagCount = 0;
if (hasEffect && player.isSprinting && !tickData.invalidSprint.nonBlindnessSprintState) {
player.flag(invalidSprint, { t: "2" });
}
if (!hasEffect || !player.isSprinting) {
data.nonBlindnessSprintState = player.isSprinting;
tickData.invalidSprint.nonBlindnessSprintState = player.isSprinting;
}
sprintData.set(player.id, data);
return tickData;
}
40 changes: 14 additions & 26 deletions Matrix_BP/src/program/detection/killaura.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { rawtextTranslate } from "../../util/rawtext";
import { calculateAngleFromView, calculateDistance, fastAbs, fastRound, pythag } from "../../util/fastmath";
import { getAngleLimit } from "../../util/util";
import { getTotalAbsMovementVector } from "../../util/assets";
import { TickData } from "../import";
const KILLAURA_DISTANCE_THRESHOLD = 3.5;
const KILLAURA_PVP_DISTANCE_THRESHOLD = 4.5;
const KILLAURA_ROTATION_THRESHOLD = 89;
Expand All @@ -21,35 +22,21 @@ const killaura = new Module()
eventId = Module.subscribePlayerTickEvent(tickEvent);
})
.onModuleDisable(() => {
killauraData.clear();
world.afterEvents.entityHitEntity.unsubscribe(entityHitEntity);
Module.clearPlayerTickEvent(eventId);
})
.initPlayer((playerId, player) => {
killauraData.set(playerId, {
entityHurtList: [],
.initPlayer((tickData, _playerId, player) => {
tickData.killaura = {
roundFlagAmount: 0,
lastAttackRot: player.getRotation(),
lastRoundTimestamp: 0,
lastIntegerTimestamp: 0,
integerFlagAmount: 0,
});
})
.initClear((playerId) => {
killauraData.delete(playerId);
};
return tickData;
});

killaura.register();
interface killAuraData {
entityHurtList: string[];
roundFlagAmount: number;
lastAttackRot: Vector2;
lastRoundTimestamp: number;
lastIntegerTimestamp: number;
integerFlagAmount: number;
}
const killauraData = new Map<string, killAuraData>();

/**
* @author jasonlaubb
* @description The basic killaura detection module.
Expand All @@ -70,7 +57,8 @@ function entityHitEntity({ damagingEntity: player, hitEntity: target }: EntityHi
player.flag(killaura, { t: "2", distance, pitch });
return;
}
const data = killauraData.get(player.id)!;
const tickData = Module.tickData.get(player.id)!;
const data = tickData.killaura!;
const notKillAuraTag = inputMode === InputMode.Touch && pitch === data.lastAttackRot.x && yaw === data.lastAttackRot.y;
if (!notKillAuraTag && distance > KILLAURA_DISTANCE_THRESHOLD && isPvp) {
const angle = calculateAngleFromView(player.location, target.location, yaw);
Expand All @@ -86,8 +74,8 @@ function entityHitEntity({ damagingEntity: player, hitEntity: target }: EntityHi
}
}
}
if (!data.entityHurtList.includes(target.id)) data.entityHurtList.push(target.id);
if (data.entityHurtList.length >= 3) {
if (!player.killAuraIdList.includes(target.id)) player.killAuraIdList.push(target.id);
if (player.killAuraIdList.length >= 3) {
player.flag(killaura, { t: "4" });
}
if (pitch % 1 === 0 && fastAbs(yaw - data.lastAttackRot.y) > 0) {
Expand Down Expand Up @@ -122,11 +110,11 @@ function entityHitEntity({ damagingEntity: player, hitEntity: target }: EntityHi
}
}
data.lastAttackRot = { x: pitch, y: yaw } as Vector2;
killauraData.set(player.id, data);
tickData.killaura = data;
Module.tickData.set(player.id, tickData);
}

function tickEvent(player: Player) {
const data = killauraData.get(player.id)!;
data.entityHurtList = [];
killauraData.set(player.id, data);
function tickEvent(tickData: TickData,player: Player) {
player.killAuraIdList = [];
return tickData;
}
3 changes: 2 additions & 1 deletion Matrix_BP/src/program/detection/mobAura.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,10 @@ const mobAura = new Module()
.onModuleDisable(() => {
world.afterEvents.entityHitEntity.unsubscribe(entityHitEntity);
})
.initPlayer((_playerId, player) => {
.initPlayer((tickData, _playerId, player) => {
player.mobAuraFlag = 0;
player.mobAuraLastFlagTimestamp = 0;
return tickData;
});
mobAura.register();
const SUMMON_RANDOM_OFFSET = 1.3;
Expand Down
Loading

0 comments on commit b507d32

Please sign in to comment.