Skip to content

Commit

Permalink
Improved failsafe tab
Browse files Browse the repository at this point in the history
  • Loading branch information
onixiya1337 committed Jul 9, 2024
1 parent c4a1f0d commit 11ade09
Show file tree
Hide file tree
Showing 10 changed files with 147 additions and 153 deletions.
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@ mcVersion=1.8.9
modid=farmhelperv2
modName=FarmHelper
version=2.8.2-pre3
shouldRelease=true
shouldRelease=false
204 changes: 90 additions & 114 deletions src/main/java/com/jelly/farmhelperv2/config/FarmHelperConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -394,138 +394,114 @@ public class FarmHelperConfig extends Config {
//</editor-fold>

//<editor-fold desc="FAILSAFES">
//<editor-fold desc="Failsafe Misc">
@Switch(
name = "Pop-up Notification", category = FAILSAFE, subcategory = "Miscellaneous",
description = "Enable pop-up notification"
)
public static boolean popUpNotification = true;
@Switch(
name = "Auto alt-tab when failsafe triggered", category = FAILSAFE, subcategory = "Miscellaneous",
description = "Automatically alt-tabs to the game when the dark times come"
)

// General Settings
@Switch(name = "Pop-up Notifications", category = FAILSAFE, subcategory = "General",
description = "Enable on-screen failsafe notifications")
public static boolean popUpNotifications = true;

@Switch(name = "Auto Alt-Tab", category = FAILSAFE, subcategory = "General",
description = "Switch to game window when failsafe triggers")
public static boolean autoAltTab = false;
@Switch(
name = "Try to use jumping and flying in failsafes reactions", category = FAILSAFE, subcategory = "Miscellaneous",
description = "Tries to use jumping and flying in failsafes reactions"
)
public static boolean tryToUseJumpingAndFlying = true;
@Slider(
name = "Failsafe Stop Delay", category = FAILSAFE, subcategory = "Miscellaneous",
description = "The delay to stop the macro after failsafe has been triggered (in milliseconds)",
min = 1_000, max = 7_500
)
public static int failsafeStopDelay = 2_000;
@Switch(
name = "Auto TP back on World Change", category = FAILSAFE, subcategory = "Miscellaneous",
description = "Automatically warps back to the garden on server reboot, server update, etc"
)
public static boolean autoTPOnWorldChange = true;
@Switch(
name = "Auto Evacuate on World update", category = FAILSAFE, subcategory = "Miscellaneous",
description = "Automatically evacuates the island on server reboot, server update, etc"
)
public static boolean autoEvacuateOnWorldUpdate = true;
@Switch(
name = "Auto reconnect on disconnect", category = FAILSAFE, subcategory = "Miscellaneous",
description = "Automatically reconnects to the server when disconnected"
)
public static boolean autoReconnect = true;
@Switch(
name = "Pause the macro when a guest arrives", category = FAILSAFE, subcategory = "Miscellaneous",
description = "Pauses the macro when a guest arrives"
)
public static boolean pauseWhenGuestArrives = false;
@Slider(
name = "Teleport Check Lag Sensitivity", category = FAILSAFE, subcategory = "Miscellaneous",
description = "Variation in distance between expected and actual positions when lagging",
min = 0, max = 2
)
public static float teleportCheckLagSensitivity = 0.5f;
@Slider(
name = "Teleport/Rotation Check Time Window (in milliseconds)", category = FAILSAFE, subcategory = "Miscellaneous",
description = "The time window to check for teleports (in seconds)",
min = 50, max = 4000, step = 50
)
public static int teleportRotationCheckTimeWindow = 500;
@Slider(
name = "Rotation Check Pitch Sensitivity", category = FAILSAFE, subcategory = "Miscellaneous",
description = "The sensitivity of the rotation check; the lower the sensitivity, the more accurate the check is, but it will also increase the chance of getting false positives.",
min = 1, max = 30
)
public static float rotationCheckPitchSensitivity = 7;
@Slider(
name = "Rotation Check Yaw Sensitivity", category = FAILSAFE, subcategory = "Miscellaneous",
description = "The sensitivity of the rotation check; the lower the sensitivity, the more accurate the check is, but it will also increase the chance of getting false positives.",
min = 1, max = 30
)
public static float rotationCheckYawSensitivity = 5;
@Slider(
name = "Teleport Check Sensitivity", category = FAILSAFE, subcategory = "Miscellaneous",
description = "The minimum distance between the previous and teleported position to trigger failsafe",
min = 0.5f, max = 20f
)
public static float teleportCheckSensitivity = 4;
@Slider(
name = "Knockback Check Vertical Sensitivity", category = FAILSAFE, subcategory = "Miscellaneous",
description = "The minimum power of vertical knockback (motionY) to trigger failsafe",
min = 2000, max = 10000, step = 1000
)
public static float knockbackCheckVerticalSensitivity = 4000;

@Switch(
name = "Average BPS Drop check", category = FAILSAFE, subcategory = "Miscellaneous",
description = "Checks for average BPS drop"
)
public static boolean averageBPSDropCheck = true;
@Slider(name = "Failsafe Stop Delay", category = FAILSAFE, subcategory = "General",
description = "Delay before stopping macro after failsafe (ms)",
min = 1000, max = 7500)
public static int failsafeStopDelay = 2000;

@Slider(
name = "BPS drop threshold (seconds)", category = FAILSAFE, subcategory = "Miscellaneous",
description = "Keeps track of the duration for which the BPS has been dropping",
min = 2, max = 10
)
public static int BPSDropThreshold = 5;
// Automatic Actions
@Switch(name = "Auto Warp on World Change", category = FAILSAFE, subcategory = "Auto Actions",
description = "Warp to garden after server reboot or update")
public static boolean autoWarpOnWorldChange = true;

@Button(
name = "Test failsafe", category = FAILSAFE, subcategory = "Miscellaneous",
description = "Tests failsafe",
text = "Test failsafe"
)
@Switch(name = "Auto Evacuate on Server Reboot", category = FAILSAFE, subcategory = "Auto Actions",
description = "Leave island during server reboot or update")
public static boolean autoEvacuateOnServerReboot = true;

@Switch(name = "Auto Reconnect", category = FAILSAFE, subcategory = "Auto Actions",
description = "Automatically reconnect after disconnect")
public static boolean autoReconnect = true;

@Switch(name = "Pause on Guest Arrival", category = FAILSAFE, subcategory = "Auto Actions",
description = "Pause macro when a guest joins your island")
public static boolean pauseOnGuestArrival = false;

// Detection Sensitivity
@Slider(name = "Teleport Lag Tolerance", category = FAILSAFE, subcategory = "Detection",
description = "Variation in distance between expected and actual positions when lagging",
min = 0, max = 2)
public static float teleportLagTolerance = 0.5f;

@Slider(name = "Detection Time Window", category = FAILSAFE, subcategory = "Detection",
description = "Time frame for teleport/rotation checks (ms)",
min = 50, max = 4000, step = 50)
public static int detectionTimeWindow = 500;

@Slider(name = "Pitch Sensitivity", category = FAILSAFE, subcategory = "Detection",
description = "Pitch change sensitivity (lower = stricter)",
min = 1, max = 30)
public static float pitchSensitivity = 7;

@Slider(name = "Yaw Sensitivity", category = FAILSAFE, subcategory = "Detection",
description = "Yaw change sensitivity (lower = stricter)",
min = 1, max = 30)
public static float yawSensitivity = 5;

@Slider(name = "Teleport Distance Threshold", category = FAILSAFE, subcategory = "Detection",
description = "Minimum teleport distance to trigger failsafe (blocks)",
min = 0.5f, max = 20f)
public static float teleportDistanceThreshold = 4;

@Slider(name = "Vertical Knockback Threshold", category = FAILSAFE, subcategory = "Detection",
description = "Minimum vertical knockback to trigger failsafe",
min = 2000, max = 10000, step = 1000)
public static float verticalKnockbackThreshold = 4000;

// BPS Check
@Switch(name = "Enable BPS Check", category = FAILSAFE, subcategory = "BPS",
description = "Monitor for drops in blocks per second")
public static boolean enableBpsCheck = true;

@Slider(name = "Minimum BPS", category = FAILSAFE, subcategory = "BPS",
description = "Trigger failsafe if BPS falls below this value",
min = 5, max = 15)
public static float minBpsThreshold = 10f;

// Failsafe Testing
@Button(name = "Test Failsafe", category = FAILSAFE, subcategory = "Testing",
description = "Simulate a failsafe trigger",
text = "Run Test")
Runnable _testFailsafe = () -> {
if (!MacroHandler.getInstance().isMacroToggled()) {
LogUtils.sendError("You need to start the macro first!");
return;
}
LogUtils.sendWarning("Testing failsafe...");
PlayerUtils.closeScreen();
if (testFailsafeTypeSelected == 0) {
FailsafeManager.getInstance().possibleDetection(FailsafeManager.getInstance().failsafes.get(testFailsafeTypeSelected));
if (testFailsafeType == 0) {
FailsafeManager.getInstance().possibleDetection(FailsafeManager.getInstance().failsafes.get(testFailsafeType));
return;
} // else if (testFailsafeTypeSelected != 6)
// LowerAvgBpsFailsafe.getInstance().clearQueue(); // Clear the queue to avoid false positives
FailsafeManager.getInstance().possibleDetection(FailsafeManager.getInstance().failsafes.get(testFailsafeTypeSelected + 2));
}
FailsafeManager.getInstance().possibleDetection(FailsafeManager.getInstance().failsafes.get(testFailsafeType + 2));
};

@Dropdown(
name = "Test Failsafe Type", category = FAILSAFE, subcategory = "Miscellaneous",
description = "The failsafe type to test",
@Dropdown(name = "Test Failsafe Type", category = FAILSAFE, subcategory = "Testing",
description = "Select failsafe scenario to test",
options = {
"Banwave",
// "Bedrock Cage Check",
// "Dirt Check",
"Disconnect",
"Evacuate",
"Full Inventory",
"Guest Visit",
"Item Change Check",
"Item Change",
"Jacob",
"Knockback Check",
"Lower Average Bps",
"Rotation Check",
"Teleport Check",
"World Change Check"
}
)
public static int testFailsafeTypeSelected = 0;
"Knockback",
"Low BPS",
"Rotation",
"Teleport",
"World Change"
})
public static int testFailsafeType = 0;

//</editor-fold>

Expand Down Expand Up @@ -562,7 +538,7 @@ public class FarmHelperConfig extends Config {
public static int captureClipDelay = 30;

@Info(
text = "You need to use ShadowPlay (or any alternative with Replay Buffer) and configure it to capture clips!",
text = "You need to use either ShadowPlay, OBS, Medal.tv or any alternative with Replay Buffer, then configure it to capture clips!",
type = InfoType.WARNING,
category = FAILSAFE,
subcategory = "Clip Capturing",
Expand Down Expand Up @@ -2188,7 +2164,7 @@ public FarmHelperConfig() {

this.addDependency("pestRepellentType", "autoPestRepellent");

this.addDependency("averageBPSDrop", "averageBPSDropCheck");
this.addDependency("averageBPSDrop", "enableBpsCheck");

this.addDependency("captureClipKeybind", "", () -> captureClipAfterFailsafe || captureClipAfterGettingBanned);
this.addDependency("clipCapturingType", "", () -> captureClipAfterFailsafe || captureClipAfterGettingBanned);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public boolean shouldAltTab() {
@Override
public void onTickDetection(TickEvent.ClientTickEvent event) {
if (!MacroHandler.getInstance().isMacroToggled()) return;
if (!FarmHelperConfig.autoEvacuateOnWorldUpdate) return;
if (!FarmHelperConfig.autoEvacuateOnServerReboot) return;
if (evacuateState != EvacuateState.NONE) return;

GameStateHandler.getInstance().getServerClosingSeconds().ifPresent(seconds -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public boolean shouldAltTab() {
@Override
public void onTickDetection(TickEvent.ClientTickEvent event) {
tabListCheckDelay.schedule(5000L);
if (FarmHelperConfig.pauseWhenGuestArrives && wasGuestOnGarden && GameStateHandler.getInstance().isGuestOnGarden()) {
if (FarmHelperConfig.pauseOnGuestArrival && wasGuestOnGarden && GameStateHandler.getInstance().isGuestOnGarden()) {
if (!MacroHandler.getInstance().isCurrentMacroPaused()) {
LogUtils.sendFailsafeMessage("[Failsafe] Paused the macro because of guest visit!", false);
MacroHandler.getInstance().pauseMacro();
Expand Down Expand Up @@ -101,7 +101,7 @@ public void onChatDetection(ClientChatReceivedEvent event) {
wasGuestOnGarden = true;
tabListCheckDelay.schedule(5000L);
FailsafeManager.getInstance().possibleDetection(this);
if (!FarmHelperConfig.pauseWhenGuestArrives)
if (!FarmHelperConfig.pauseOnGuestArrival)
Multithreading.schedule(() -> {
if (FailsafeManager.getInstance().triggeredFailsafe.isPresent()
&& FailsafeManager.getInstance().triggeredFailsafe.get().getType() == FailsafeManager.EmergencyType.GUEST_VISIT) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ public void onReceivedPacketDetection(ReceivePacketEvent event) {
}
if (((S12PacketEntityVelocity) event.packet).getEntityID() != mc.thePlayer.getEntityId())
return;
if (((S12PacketEntityVelocity) event.packet).getMotionY() < FarmHelperConfig.knockbackCheckVerticalSensitivity)
if (((S12PacketEntityVelocity) event.packet).getMotionY() < FarmHelperConfig.verticalKnockbackThreshold)
return;

if (FlyPathFinderExecutor.getInstance().isRunning()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@
public class LowerAvgBpsFailsafe extends Failsafe {
private static LowerAvgBpsFailsafe instance;
private float lastBPS;
private long lastStableBpsTime = 0;
private static final float BPS_DROP_TOLERANCE = 1f;
private static final long STABLE_BPS_RESET_TIME = 5000L;

private final Clock clock = new Clock();

Expand Down Expand Up @@ -63,29 +66,50 @@ public boolean shouldAltTab() {
public void onTickDetection(TickEvent.ClientTickEvent event) {
if (FeatureManager.getInstance().shouldPauseMacroExecution()
|| BPSTracker.getInstance().dontCheckForBPS()
|| !FarmHelperConfig.averageBPSDropCheck) {
if (clock.isScheduled())
clock.reset();
|| !FarmHelperConfig.enableBpsCheck) {
resetStates();
return;
}
if (event.phase != TickEvent.Phase.START)
return;

if (BPSTracker.getInstance().getBPSFloat() - lastBPS < 0) {
if (!clock.isScheduled())
clock.schedule(FarmHelperConfig.BPSDropThreshold * 1000L);
} else if (BPSTracker.getInstance().getBPSFloat() - lastBPS > 0) {
clock.reset();
float currentBPS = BPSTracker.getInstance().getBPSFloat();
float bpsDrop = lastBPS - currentBPS;

boolean shouldTrigger = false;

// Check for BPS below threshold
if (currentBPS < FarmHelperConfig.minBpsThreshold) {
shouldTrigger = true;
LogUtils.sendDebug("BPS below threshold. Current: " + currentBPS + ", Threshold: " + FarmHelperConfig.minBpsThreshold);
}
lastBPS = BPSTracker.getInstance().getBPSFloat();

if (!clock.isScheduled())
return;
// Check for significant BPS drop
if (bpsDrop > BPS_DROP_TOLERANCE) {
shouldTrigger = true;
lastStableBpsTime = System.currentTimeMillis();
LogUtils.sendDebug("BPS drop detected. Current: " + currentBPS + ", Last: " + lastBPS);
} else if (bpsDrop < -BPS_DROP_TOLERANCE) {
resetStates();
LogUtils.sendDebug("BPS increased. Clock reset.");
} else {
// BPS is stable
if (System.currentTimeMillis() - lastStableBpsTime > STABLE_BPS_RESET_TIME) {
resetStates();
LogUtils.sendDebug("BPS stable for " + STABLE_BPS_RESET_TIME + "ms. Clock reset.");
}
}

if (clock.passed()) {
FailsafeManager.getInstance().possibleDetection(this);
if (shouldTrigger && !clock.isScheduled()) {
clock.schedule(5000L);
}

lastBPS = currentBPS;

if (clock.isScheduled() && clock.passed()) {
LogUtils.sendDebug("Failsafe triggered. Current BPS: " + currentBPS);
FailsafeManager.getInstance().possibleDetection(this);
}
}

@Override
Expand Down Expand Up @@ -139,9 +163,10 @@ public void endOfFailsafeTrigger() {

@Override
public void resetStates() {
LogUtils.sendDebug("RESET");
LogUtils.sendDebug("Resetting LowerAvgBpsFailsafe states");
clock.reset();
lastBPS = 0;
lastBPS = BPSTracker.getInstance().getBPSFloat();
lastStableBpsTime = System.currentTimeMillis();
lowerBPSState = LowerBPSState.NONE;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ public void onReceivedPacketDetection(ReceivePacketEvent event) {
if (shouldTriggerCheck(packetYaw, packetPitch))
if (rotationBeforeReacting == null)
rotationBeforeReacting = new Rotation((float) playerYaw, (float) playerPitch);
triggerCheck.schedule(FarmHelperConfig.teleportRotationCheckTimeWindow);
triggerCheck.schedule(FarmHelperConfig.detectionTimeWindow);
}

private static final Clock triggerCheck = new Clock();
Expand Down Expand Up @@ -146,8 +146,8 @@ private void evaluateRotation() {
private boolean shouldTriggerCheck(double newYaw, double newPitch) {
double yawDiff = Math.abs(newYaw - mc.thePlayer.rotationYaw) % 360;
double pitchDiff = Math.abs(newPitch - mc.thePlayer.rotationPitch) % 360;
double yawThreshold = FarmHelperConfig.rotationCheckYawSensitivity;
double pitchThreshold = FarmHelperConfig.rotationCheckPitchSensitivity;
double yawThreshold = FarmHelperConfig.pitchSensitivity;
double pitchThreshold = FarmHelperConfig.pitchSensitivity;
if (yawDiff >= yawThreshold || pitchDiff >= pitchThreshold) {
LogUtils.sendDebug("[Failsafe] Rotation detected! Yaw diff: " + yawDiff + ", Pitch diff: " + pitchDiff);
return true;
Expand Down
Loading

0 comments on commit 11ade09

Please sign in to comment.