Skip to content

Commit

Permalink
Fix Tokyo Client Crash (#283)
Browse files Browse the repository at this point in the history
  • Loading branch information
hexadecimal233 authored Aug 10, 2023
1 parent 30ec0dc commit 8645f2d
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 65 deletions.
80 changes: 23 additions & 57 deletions src/main/java/anticope/rejects/gui/screens/InteractionScreen.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
import net.minecraft.util.Hand;
import net.minecraft.util.Identifier;
import net.minecraft.util.math.MathHelper;
import org.joml.Vector2f;
import org.lwjgl.glfw.GLFW;

import java.awt.*;
Expand Down Expand Up @@ -167,7 +168,6 @@ public InteractionScreen(Entity entity, InteractionMenu module) {
MeteorStarscript.printChatError(err);
}
});

});
functions.put("Cancel", (Entity e) -> {
closeScreen();
Expand Down Expand Up @@ -215,8 +215,8 @@ public void init() {

private void cursorMode(int mode) {
KeyBinding.unpressAll();
double x = (double) (this.client.getWindow().getWidth() / 2);
double y = (double) (this.client.getWindow().getHeight() / 2);
double x = (double) this.client.getWindow().getWidth() / 2;
double y = (double) this.client.getWindow().getHeight() / 2;
InputUtil.setCursorParameters(this.client.getWindow().getHandle(), mode, x, y);
}

Expand All @@ -226,7 +226,7 @@ public void tick() {
}

private void closeScreen() {
client.setScreen((Screen) null);
client.setScreen(null);
}

public void close() {
Expand All @@ -235,7 +235,7 @@ public void close() {
if (focusedString != null) {
functions.get(focusedString).accept(this.entity);
} else
client.setScreen((Screen) null);
client.setScreen(null);
}

public boolean isPauseScreen() {
Expand All @@ -257,20 +257,7 @@ public void render(DrawContext context, int mouseX, int mouseY, float delta) {
matrix.scale(2f, 2f, 1f);
context.drawCenteredTextWithShadow(textRenderer, entity.getName(), width / 4, 6, 0xFFFFFFFF);

int scale = client.options.getGuiScale().getValue();
Vector2 mouse = new Vector2(mouseX, mouseY);
Vector2 center = new Vector2(width / 2, height / 2);
mouse.subtract(center);
mouse.normalize();

if (scale == 0)
scale = 4;

// Move crossHair based on distance between mouse and center. But with limit
if (Math.hypot(width / 2 - mouseX, height / 2 - mouseY) < 1f / scale * 200f)
mouse.multiply((float) Math.hypot(width / 2 - mouseX, height / 2 - mouseY));
else
mouse.multiply(1f / scale * 200f);
Vector2f mouse = getMouseVecs(mouseX, mouseY);

this.crosshairX = (int) mouse.x + width / 2;
this.crosshairY = (int) mouse.y + height / 2;
Expand All @@ -280,6 +267,21 @@ public void render(DrawContext context, int mouseX, int mouseY, float delta) {
super.render(context, mouseX, mouseY, delta);
}

private Vector2f getMouseVecs(int mouseX, int mouseY) {
int scale = client.options.getGuiScale().getValue();
Vector2f mouse = new Vector2f(mouseX, mouseY);
Vector2f center = new Vector2f(width / 2, height / 2);
mouse.sub(center).normalize();

if (scale == 0) scale = 4;

// Move crossHair based on distance between mouse and center. But with limit
if (Math.hypot(width / 2 - mouseX, height / 2 - mouseY) < 1f / scale * 200f)
mouse.mul((float) Math.hypot(width / 2 - mouseX, height / 2 - mouseY));
else
mouse.mul(1f / scale * 200f);
return mouse;
}

private void drawDots(DrawContext context, int radius, int mouseX, int mouseY) {
ArrayList<Point> pointList = new ArrayList<Point>();
Expand Down Expand Up @@ -326,7 +328,7 @@ private void drawRect(DrawContext context, int startX, int startY, int width, in

private void drawTextField(DrawContext context, int x, int y, String key) {
if (x >= width / 2) {
drawRect(context,x + 10, y - 8, textRenderer.getWidth(key) + 3, 15, backgroundColor, borderColor);
drawRect(context, x + 10, y - 8, textRenderer.getWidth(key) + 3, 15, backgroundColor, borderColor);
context.drawTextWithShadow(textRenderer, key, x + 12, y - 4, textColor);
} else {
drawRect(context, x - 14 - textRenderer.getWidth(key), y - 8, textRenderer.getWidth(key) + 3, 15, backgroundColor, borderColor);
Expand Down Expand Up @@ -361,40 +363,4 @@ private void onKey(KeyEvent event) {
}
}
}
}


// Creating my own Vector class beacause I couldn´t find a good one in minecrafts code
class Vector2 {
float x, y;

Vector2(float x, float y) {
this.x = x;
this.y = y;
}

void normalize() {
float mag = getMag();
if (mag != 0 && mag != 1)
divide(mag);
}

void subtract(Vector2 vec) {
this.x -= vec.x;
this.y -= vec.y;
}

void divide(float n) {
x /= n;
y /= n;
}

void multiply(float n) {
x *= n;
y *= n;
}

private float getMag() {
return (float) Math.sqrt(x * x + y * y);
}
}
}
4 changes: 2 additions & 2 deletions src/main/java/anticope/rejects/modules/VehicleOneHit.java
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
package anticope.rejects.modules;


import anticope.rejects.MeteorRejectsAddon;
import meteordevelopment.meteorclient.events.packets.PacketEvent;
import meteordevelopment.meteorclient.settings.IntSetting;
import meteordevelopment.meteorclient.settings.Setting;
import meteordevelopment.meteorclient.settings.SettingGroup;
import meteordevelopment.meteorclient.systems.modules.Categories;
import meteordevelopment.meteorclient.systems.modules.Module;
import meteordevelopment.orbit.EventHandler;
import net.minecraft.entity.vehicle.AbstractMinecartEntity;
Expand All @@ -28,7 +28,7 @@ public class VehicleOneHit extends Module {
private boolean ignorePackets;

public VehicleOneHit() {
super(Categories.Player, "vehicle-one-hit", "Destroy vehicles with one hit.");
super(MeteorRejectsAddon.CATEGORY, "vehicle-one-hit", "Destroy vehicles with one hit.");
}

@EventHandler
Expand Down
11 changes: 8 additions & 3 deletions src/main/java/anticope/rejects/utils/RejectsUtils.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package anticope.rejects.utils;

import anticope.rejects.MeteorRejectsAddon;
import anticope.rejects.utils.seeds.Seeds;
import meteordevelopment.meteorclient.MeteorClient;
import meteordevelopment.meteorclient.events.entity.player.PlayerMoveEvent;
Expand All @@ -17,7 +18,6 @@
import static meteordevelopment.meteorclient.MeteorClient.mc;

public class RejectsUtils {

@PostInit
public static void init() {
Runtime.getRuntime().addShutdownHook(new Thread(() -> {
Expand All @@ -29,7 +29,12 @@ public static void init() {

public static String getModuleName(String name) {
int dupe = 0;
for (Module module : Modules.get().getAll()) {
Modules modules = Modules.get();
if (modules == null) {
MeteorRejectsAddon.LOG.warn("Module instantiation before Modules initialized.");
return name;
}
for (Module module : modules.getAll()) {
if (module.name.equals(name)) {
dupe++;
break;
Expand Down Expand Up @@ -58,7 +63,7 @@ public static boolean inFov(Entity entity, double fov) {
return angleDistance <= fov;
}

public static float fullFlightMove(PlayerMoveEvent event, double speed, boolean verticalSpeedMatch){
public static float fullFlightMove(PlayerMoveEvent event, double speed, boolean verticalSpeedMatch) {
if (PlayerUtils.isMoving()) {
double dir = getDir();

Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package anticope.rejects.utils.accounts;

import anticope.rejects.MeteorRejectsAddon;
import com.mojang.authlib.exceptions.AuthenticationException;
import com.mojang.authlib.minecraft.MinecraftSessionService;
import meteordevelopment.meteorclient.MeteorClient;
import meteordevelopment.meteorclient.mixin.MinecraftClientAccessor;
import meteordevelopment.meteorclient.systems.accounts.Account;
import meteordevelopment.meteorclient.systems.accounts.AccountType;
Expand Down Expand Up @@ -49,8 +49,8 @@ public boolean login() {
return true;
} catch (AuthenticationException e) {
if (e.getMessage().contains("Invalid username or password") || e.getMessage().contains("account migrated"))
MeteorClient.LOG.error("Wrong password.");
else MeteorClient.LOG.error("Failed to contact the authentication server.");
MeteorRejectsAddon.LOG.error("Wrong password.");
else MeteorRejectsAddon.LOG.error("Failed to contact the authentication server.");
return false;
}
}
Expand Down

0 comments on commit 8645f2d

Please sign in to comment.