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.Identifier;
import net.minecraft.util.math.MathHelper;
import org.joml.Vector2f;
import org.lwjgl.glfw.GLFW;
import java.awt.*;
@@ -167,7 +168,6 @@ public class InteractionScreen extends Screen {
MeteorStarscript.printChatError(err);
}
});
});
functions.put("Cancel", (Entity e) -> {
closeScreen();
@@ -215,8 +215,8 @@ public class InteractionScreen extends Screen {
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);
}
@@ -226,7 +226,7 @@ public class InteractionScreen extends Screen {
}
private void closeScreen() {
client.setScreen((Screen) null);
client.setScreen(null);
}
public void close() {
@@ -235,7 +235,7 @@ public class InteractionScreen extends Screen {
if (focusedString != null) {
functions.get(focusedString).accept(this.entity);
} else
client.setScreen((Screen) null);
client.setScreen(null);
}
public boolean isPauseScreen() {
@@ -257,20 +257,7 @@ public class InteractionScreen extends Screen {
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;
@@ -280,6 +267,21 @@ public class InteractionScreen extends Screen {
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>();
@@ -362,39 +364,3 @@ 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;
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;
@@ -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

View File

@@ -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;
@@ -17,7 +18,6 @@ import java.util.Random;
import static meteordevelopment.meteorclient.MeteorClient.mc;
public class RejectsUtils {
@PostInit
public static void init() {
Runtime.getRuntime().addShutdownHook(new Thread(() -> {
@@ -29,7 +29,12 @@ public class RejectsUtils {
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;

View File

@@ -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;
@@ -49,8 +49,8 @@ public class CustomYggdrasilAccount extends Account<CustomYggdrasilAccount> {
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;
}
}