Fix Tokyo Client Crash (#283)

This commit is contained in:
OnlyRain233
2023-08-10 23:58:24 +08:00
committed by GitHub
parent 30ec0dca52
commit 8645f2dd22
4 changed files with 36 additions and 65 deletions

View File

@@ -37,6 +37,7 @@ import net.minecraft.text.Text;
import net.minecraft.util.Hand; import net.minecraft.util.Hand;
import net.minecraft.util.Identifier; import net.minecraft.util.Identifier;
import net.minecraft.util.math.MathHelper; import net.minecraft.util.math.MathHelper;
import org.joml.Vector2f;
import org.lwjgl.glfw.GLFW; import org.lwjgl.glfw.GLFW;
import java.awt.*; import java.awt.*;
@@ -167,7 +168,6 @@ public class InteractionScreen extends Screen {
MeteorStarscript.printChatError(err); MeteorStarscript.printChatError(err);
} }
}); });
}); });
functions.put("Cancel", (Entity e) -> { functions.put("Cancel", (Entity e) -> {
closeScreen(); closeScreen();
@@ -215,8 +215,8 @@ public class InteractionScreen extends Screen {
private void cursorMode(int mode) { private void cursorMode(int mode) {
KeyBinding.unpressAll(); KeyBinding.unpressAll();
double x = (double) (this.client.getWindow().getWidth() / 2); double x = (double) this.client.getWindow().getWidth() / 2;
double y = (double) (this.client.getWindow().getHeight() / 2); double y = (double) this.client.getWindow().getHeight() / 2;
InputUtil.setCursorParameters(this.client.getWindow().getHandle(), mode, x, y); InputUtil.setCursorParameters(this.client.getWindow().getHandle(), mode, x, y);
} }
@@ -226,7 +226,7 @@ public class InteractionScreen extends Screen {
} }
private void closeScreen() { private void closeScreen() {
client.setScreen((Screen) null); client.setScreen(null);
} }
public void close() { public void close() {
@@ -235,7 +235,7 @@ public class InteractionScreen extends Screen {
if (focusedString != null) { if (focusedString != null) {
functions.get(focusedString).accept(this.entity); functions.get(focusedString).accept(this.entity);
} else } else
client.setScreen((Screen) null); client.setScreen(null);
} }
public boolean isPauseScreen() { public boolean isPauseScreen() {
@@ -257,20 +257,7 @@ public class InteractionScreen extends Screen {
matrix.scale(2f, 2f, 1f); matrix.scale(2f, 2f, 1f);
context.drawCenteredTextWithShadow(textRenderer, entity.getName(), width / 4, 6, 0xFFFFFFFF); context.drawCenteredTextWithShadow(textRenderer, entity.getName(), width / 4, 6, 0xFFFFFFFF);
int scale = client.options.getGuiScale().getValue(); Vector2f mouse = getMouseVecs(mouseX, mouseY);
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);
this.crosshairX = (int) mouse.x + width / 2; this.crosshairX = (int) mouse.x + width / 2;
this.crosshairY = (int) mouse.y + height / 2; this.crosshairY = (int) mouse.y + height / 2;
@@ -280,6 +267,21 @@ public class InteractionScreen extends Screen {
super.render(context, mouseX, mouseY, 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) { private void drawDots(DrawContext context, int radius, int mouseX, int mouseY) {
ArrayList<Point> pointList = new ArrayList<Point>(); ArrayList<Point> pointList = new ArrayList<Point>();
@@ -326,7 +328,7 @@ public class InteractionScreen extends Screen {
private void drawTextField(DrawContext context, int x, int y, String key) { private void drawTextField(DrawContext context, int x, int y, String key) {
if (x >= width / 2) { 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); context.drawTextWithShadow(textRenderer, key, x + 12, y - 4, textColor);
} else { } else {
drawRect(context, x - 14 - textRenderer.getWidth(key), y - 8, textRenderer.getWidth(key) + 3, 15, backgroundColor, borderColor); drawRect(context, x - 14 - textRenderer.getWidth(key), y - 8, textRenderer.getWidth(key) + 3, 15, backgroundColor, borderColor);
@@ -361,40 +363,4 @@ public class InteractionScreen extends Screen {
} }
} }
} }
} }
// 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);
}
}

View File

@@ -1,11 +1,11 @@
package anticope.rejects.modules; package anticope.rejects.modules;
import anticope.rejects.MeteorRejectsAddon;
import meteordevelopment.meteorclient.events.packets.PacketEvent; import meteordevelopment.meteorclient.events.packets.PacketEvent;
import meteordevelopment.meteorclient.settings.IntSetting; import meteordevelopment.meteorclient.settings.IntSetting;
import meteordevelopment.meteorclient.settings.Setting; import meteordevelopment.meteorclient.settings.Setting;
import meteordevelopment.meteorclient.settings.SettingGroup; import meteordevelopment.meteorclient.settings.SettingGroup;
import meteordevelopment.meteorclient.systems.modules.Categories;
import meteordevelopment.meteorclient.systems.modules.Module; import meteordevelopment.meteorclient.systems.modules.Module;
import meteordevelopment.orbit.EventHandler; import meteordevelopment.orbit.EventHandler;
import net.minecraft.entity.vehicle.AbstractMinecartEntity; import net.minecraft.entity.vehicle.AbstractMinecartEntity;
@@ -28,7 +28,7 @@ public class VehicleOneHit extends Module {
private boolean ignorePackets; private boolean ignorePackets;
public VehicleOneHit() { 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 @EventHandler

View File

@@ -1,5 +1,6 @@
package anticope.rejects.utils; package anticope.rejects.utils;
import anticope.rejects.MeteorRejectsAddon;
import anticope.rejects.utils.seeds.Seeds; import anticope.rejects.utils.seeds.Seeds;
import meteordevelopment.meteorclient.MeteorClient; import meteordevelopment.meteorclient.MeteorClient;
import meteordevelopment.meteorclient.events.entity.player.PlayerMoveEvent; import meteordevelopment.meteorclient.events.entity.player.PlayerMoveEvent;
@@ -17,7 +18,6 @@ import java.util.Random;
import static meteordevelopment.meteorclient.MeteorClient.mc; import static meteordevelopment.meteorclient.MeteorClient.mc;
public class RejectsUtils { public class RejectsUtils {
@PostInit @PostInit
public static void init() { public static void init() {
Runtime.getRuntime().addShutdownHook(new Thread(() -> { Runtime.getRuntime().addShutdownHook(new Thread(() -> {
@@ -29,7 +29,12 @@ public class RejectsUtils {
public static String getModuleName(String name) { public static String getModuleName(String name) {
int dupe = 0; 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)) { if (module.name.equals(name)) {
dupe++; dupe++;
break; break;
@@ -58,7 +63,7 @@ public class RejectsUtils {
return angleDistance <= 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()) { if (PlayerUtils.isMoving()) {
double dir = getDir(); double dir = getDir();

View File

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