Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a CPS variable to Meteor Starscript #4057

Merged
merged 3 commits into from
Sep 10, 2023
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import meteordevelopment.meteorclient.systems.modules.player.FastUse;
import meteordevelopment.meteorclient.systems.modules.render.UnfocusedCPU;
import meteordevelopment.meteorclient.utils.Utils;
import meteordevelopment.meteorclient.utils.misc.CPSUtils;
import meteordevelopment.meteorclient.utils.misc.MeteorStarscript;
import meteordevelopment.meteorclient.utils.network.OnlinePlayers;
import meteordevelopment.starscript.Script;
Expand Down Expand Up @@ -82,6 +83,7 @@ private void onInit(CallbackInfo info) {
@Inject(at = @At("HEAD"), method = "tick")
private void onPreTick(CallbackInfo info) {
OnlinePlayers.update();

doItemUseCalled = false;

getProfiler().push(MeteorClient.MOD_ID + "_pre_update");
Expand All @@ -99,6 +101,11 @@ private void onTick(CallbackInfo info) {
getProfiler().pop();
}

@Inject(method = "doAttack", at = @At("HEAD"))
private void onAttack(CallbackInfoReturnable<Boolean> cir) {
CPSUtils.onAttack();
}

@Inject(method = "doItemUse", at = @At("HEAD"))
private void onDoItemUse(CallbackInfo info) {
doItemUseCalled = true;
Expand Down
6 changes: 3 additions & 3 deletions src/main/java/meteordevelopment/meteorclient/utils/Utils.java
Original file line number Diff line number Diff line change
Expand Up @@ -64,17 +64,17 @@
import static org.lwjgl.glfw.GLFW.*;

public class Utils {
public static final Pattern FILE_NAME_INVALID_CHARS_PATTERN = Pattern.compile("[\\s\\\\/:*?\"<>|]");
public static final Color WHITE = new Color(255, 255, 255);

private static final Random random = new Random();
public static boolean firstTimeTitleScreen = true;
public static boolean isReleasingTrident;
public static final Color WHITE = new Color(255, 255, 255);
public static boolean rendering3D = true;
public static double frameTime;
public static Screen screenToOpen;
public static VertexSorter vertexSorter;

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why. If you want to cleanup then move the 2 constants to the top of the file and with a new line to separate constants and static variables.

public static final Pattern FILE_NAME_INVALID_CHARS_PATTERN = Pattern.compile("[\\s\\\\/:*?\"<>|]");

@PreInit
public static void init() {
MeteorClient.EVENT_BUS.subscribe(Utils.class);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
/*
* This file is part of the Meteor Client distribution (https://github.com/MeteorDevelopment/meteor-client).
* Copyright (c) Meteor Development.
*/

package meteordevelopment.meteorclient.utils.misc;

import meteordevelopment.meteorclient.MeteorClient;
import meteordevelopment.meteorclient.events.world.TickEvent;
import meteordevelopment.meteorclient.utils.PreInit;
import meteordevelopment.orbit.EventHandler;


public class CPSUtils {
private static int clicks;
private static int cps;
private static int secondsClicking;
private static long lastTime;

@PreInit
public static void init() {
MeteorClient.EVENT_BUS.subscribe(CPSUtils.class);
}

@EventHandler
private static void onTick(TickEvent.Pre event) {
long currentTime = System.currentTimeMillis();
// Run every second
if (currentTime - CPSUtils.lastTime >= 1000) {
if (CPSUtils.cps == 0) {
CPSUtils.clicks = 0;
CPSUtils.secondsClicking = 0;
} else {
CPSUtils.lastTime = currentTime;
CPSUtils.secondsClicking++;
CPSUtils.cps = 0;
}
}
}


public static void onAttack() {
CPSUtils.clicks++;
CPSUtils.cps++;
}

public static int getCpsAverage() {
return clicks / (secondsClicking == 0 ? 1 : secondsClicking);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ public static void init() {
ss.set("fps", () -> Value.number(MinecraftClientAccessor.getFps()));
ss.set("ping", MeteorStarscript::ping);
ss.set("time", () -> Value.string(LocalTime.now().format(DateTimeFormatter.ofLocalizedTime(FormatStyle.SHORT))));
ss.set("cps", () -> Value.number(CPSUtils.getCpsAverage()));

// Meteor
ss.set("meteor", new ValueMap()
Expand Down Expand Up @@ -125,7 +126,7 @@ public static void init() {
.set("health", () -> Value.number(mc.player != null ? mc.player.getHealth() : 0))
.set("absorption", () -> Value.number(mc.player != null ? mc.player.getAbsorptionAmount() : 0))
.set("hunger", () -> Value.number(mc.player != null ? mc.player.getHungerManager().getFoodLevel() : 0))

.set("speed", () -> Value.number(Utils.getPlayerSpeed().horizontalLength()))
.set("speed_all", new ValueMap()
.set("_toString", () -> Value.string(mc.player != null ? Utils.getPlayerSpeed().toString() : ""))
Expand Down