Skip to content

Commit

Permalink
fix null pointer issues
Browse files Browse the repository at this point in the history
  • Loading branch information
Cvrwed committed Mar 29, 2024
1 parent 0651a3d commit 65774cc
Show file tree
Hide file tree
Showing 6 changed files with 128 additions and 121 deletions.
2 changes: 1 addition & 1 deletion src/main/java/cc/unknown/module/impl/combat/AutoClick.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public class AutoClick extends Module {
private final BooleanValue breakBlocks = new BooleanValue("Break blocks", false);
private final BooleanValue hitSelect = new BooleanValue("Hit select", false);
private final SliderValue hitSelectDistance = new SliderValue("Hit select distance", 10, 1, 20, 5);
private final SliderValue hitSelectDelay = new SliderValue("Hit select delay", 25, 50, 500, 25);
private final SliderValue hitSelectDelay = new SliderValue("Hit select delay", 50, 50, 500, 25);
private final BooleanValue invClicker = new BooleanValue("Inv clicker", false);
private final SliderValue invDelay = new SliderValue("Inv delay", 5, 0, 10, 1);

Expand Down
200 changes: 96 additions & 104 deletions src/main/java/cc/unknown/module/impl/combat/JumpReset.java
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,103 @@ public void onPacket(PacketEvent e) {

if (e.getType() == Type.RECEIVE) {
if (p instanceof S12PacketEntityVelocity) {
handleEntityVelocity((S12PacketEntityVelocity) p);
S12PacketEntityVelocity wrapper = (S12PacketEntityVelocity)p;

if (wrapper.getEntityID() != mc.thePlayer.getEntityId() || !PlayerUtil.inGame()) {
return;
}

if (mode.is("Tick") || mode.is("Hit")) {
double packetDirection = Math.atan2(wrapper.motionX, wrapper.motionZ);
double degreePlayer = PlayerUtil.getDirection();
double degreePacket = Math.floorMod((int) Math.toDegrees(packetDirection), 360);
double angle = Math.abs(degreePacket + degreePlayer);
double threshold = 120.0;
angle = Math.floorMod((int) angle, 360);
boolean inRange = angle >= 180 - threshold / 2 && angle <= 180 + threshold / 2;
if (inRange) {
reset = true;
}
} else if (mode.is("Motion")) {
if (!mc.gameSettings.keyBindJump.pressed && onlyGround.isToggled() && mc.thePlayer.onGround && mc.thePlayer.fallDistance > 2.5f) {
double reduction = motion.getInputToFloat() * 0.5;

if (reduceYaw.isToggled()) {
float yaw = mc.thePlayer.rotationYaw * 0.017453292f;
double motionX = MathHelper.sin(yaw) * reduction;
double motionZ = MathHelper.cos(yaw) * reduction;

if (custom.isToggled()) {
wrapper.motionX -= motionX;
wrapper.motionZ += motionZ;
} else if (aggressive.isToggled()) {
wrapper.motionX -= reduction * friction.getInput();
wrapper.motionZ -= reduction * friction.getInput();
} else {
wrapper.motionX -= MathHelper.sin(yaw) * 0.2;
wrapper.motionZ += MathHelper.cos(yaw) * 0.2;
}
} else {
double motionX = 0.0;
double motionZ = 0.0;

if (custom.isToggled()) {
wrapper.motionX -= motionX;
wrapper.motionZ += motionZ;
} else if (aggressive.isToggled()) {
wrapper.motionX -= reduction * friction.getInput();
wrapper.motionZ -= reduction * friction.getInput();
} else {
wrapper.motionX -= 0.2;
wrapper.motionZ += 0.2;
}
}
}
}
} else if (p instanceof S27PacketExplosion) {
handleExplosion((S27PacketExplosion) p);
S27PacketExplosion wrapper = (S27PacketExplosion)p;
if (mode.is("Tick") || mode.is("Hit")) {
double packetDirection = Math.atan2(wrapper.field_149152_f, wrapper.field_149159_h);
double degreePlayer = PlayerUtil.getDirection();
double degreePacket = Math.floorMod((int) Math.toDegrees(packetDirection), 360);
double angle = Math.abs(degreePacket + degreePlayer);
double threshold = 120.0;
angle = Math.floorMod((int) angle, 360);
boolean inRange = angle >= 180 - threshold / 2 && angle <= 180 + threshold / 2;
if (inRange) {
reset = true;
}
} else if (mode.is("Motion")) {
if (!mc.gameSettings.keyBindJump.pressed && onlyGround.isToggled() && mc.thePlayer.onGround && mc.thePlayer.fallDistance > 2.5f) {
double reduction = motion.getInputToFloat() * 0.5;
double motionX, motionY, motionZ;

if (reduceYaw.isToggled()) {
float yaw = mc.thePlayer.rotationYaw * 0.017453292f;
motionX = MathHelper.sin(yaw) * reduction;
motionY = reduction * 0.1;
motionZ = MathHelper.cos(yaw) * reduction;
} else {
motionX = 0;
motionY = reduction * 0.1;
motionZ = 0;
}

if (custom.isToggled()) {
wrapper.field_149152_f -= motionX;
wrapper.field_149153_g -= motionY;
wrapper.field_149159_h += motionZ;
} else if (aggressive.isToggled()) {
wrapper.field_149152_f -= reduction * friction.getInput();
wrapper.field_149153_g -= motionY;
wrapper.field_149159_h -= reduction * friction.getInput();
} else {
wrapper.field_149152_f -= 0.2;
wrapper.field_149153_g -= motionY;
wrapper.field_149159_h += 0.2;
}
}
}
}
}
}
Expand Down Expand Up @@ -85,108 +179,6 @@ public void onStrafe(StrafeEvent e) {
break;
}
}

private void handleEntityVelocity(S12PacketEntityVelocity wrapper) {
if (wrapper.getEntityID() != mc.thePlayer.getEntityId() || !PlayerUtil.inGame()) {
return;
}

if (mode.is("Tick") || mode.is("Hit")) {
handleVelocity(wrapper.motionX, wrapper.motionZ);
} else if (mode.is("Motion")) {
if (!mc.gameSettings.keyBindJump.pressed && onlyGround.isToggled() && mc.thePlayer.onGround && mc.thePlayer.fallDistance > 2.5f) {
handleMotion(wrapper);
}
}
}

private void handleExplosion(S27PacketExplosion wrapper) {
if (mode.is("Tick") || mode.is("Hit")) {
handleVelocity(wrapper.field_149152_f, wrapper.field_149159_h);
} else if (mode.is("Motion")) {
if (!mc.gameSettings.keyBindJump.pressed && onlyGround.isToggled() && mc.thePlayer.onGround && mc.thePlayer.fallDistance > 2.5f) {
handleMotion(wrapper);
}
}
}

private void handleVelocity(double motionX, double motionZ) {
double packetDirection = Math.atan2(motionX, motionZ);
double degreePlayer = PlayerUtil.getDirection();
double degreePacket = Math.floorMod((int) Math.toDegrees(packetDirection), 360);
double angle = Math.abs(degreePacket + degreePlayer);
double threshold = 120.0;
angle = Math.floorMod((int) angle, 360);
boolean inRange = angle >= 180 - threshold / 2 && angle <= 180 + threshold / 2;
if (inRange) {
reset = true;
}
}

private void handleMotion(S12PacketEntityVelocity wrapper) {
double reduction = motion.getInputToFloat() * 0.5;

if (reduceYaw.isToggled()) {
float yaw = mc.thePlayer.rotationYaw * 0.017453292f;
double motionX = MathHelper.sin(yaw) * reduction;
double motionZ = MathHelper.cos(yaw) * reduction;

if (custom.isToggled()) {
wrapper.motionX -= motionX;
wrapper.motionZ += motionZ;
} else if (aggressive.isToggled()) {
wrapper.motionX -= reduction * friction.getInput();
wrapper.motionZ -= reduction * friction.getInput();
} else {
wrapper.motionX -= MathHelper.sin(yaw) * 0.2;
wrapper.motionZ += MathHelper.cos(yaw) * 0.2;
}
} else {
double motionX = 0.0;
double motionZ = 0.0;

if (custom.isToggled()) {
wrapper.motionX -= motionX;
wrapper.motionZ += motionZ;
} else if (aggressive.isToggled()) {
wrapper.motionX -= reduction * friction.getInput();
wrapper.motionZ -= reduction * friction.getInput();
} else {
wrapper.motionX -= 0.2;
wrapper.motionZ += 0.2;
}
}
}

private void handleMotion(S27PacketExplosion wrapper) {
double reduction = motion.getInputToFloat() * 0.5;
double motionX, motionY, motionZ;

if (reduceYaw.isToggled()) {
float yaw = mc.thePlayer.rotationYaw * 0.017453292f;
motionX = MathHelper.sin(yaw) * reduction;
motionY = reduction * 0.1;
motionZ = MathHelper.cos(yaw) * reduction;
} else {
motionX = 0;
motionY = reduction * 0.1;
motionZ = 0;
}

if (custom.isToggled()) {
wrapper.field_149152_f -= motionX;
wrapper.field_149153_g -= motionY;
wrapper.field_149159_h += motionZ;
} else if (aggressive.isToggled()) {
wrapper.field_149152_f -= reduction * friction.getInput();
wrapper.field_149153_g -= motionY;
wrapper.field_149159_h -= reduction * friction.getInput();
} else {
wrapper.field_149152_f -= 0.2;
wrapper.field_149153_g -= motionY;
wrapper.field_149159_h += 0.2;
}
}

private boolean shouldJump() {
switch (mode.getMode()) {
Expand Down
33 changes: 20 additions & 13 deletions src/main/java/cc/unknown/module/impl/exploit/FakeLag.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,6 @@
import cc.unknown.utils.helpers.MathHelper;
import cc.unknown.utils.network.PacketUtil;
import cc.unknown.utils.network.TimedPacket;
import cc.unknown.utils.player.PlayerUtil;
import net.minecraft.entity.Entity;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.network.INetHandler;
import net.minecraft.network.Packet;
Expand Down Expand Up @@ -120,7 +118,7 @@ public void onDisable() {

@EventLink
public void onPreUpdate(PreUpdateEvent e) {
if (PlayerUtil.inGame() && target != null && vec3 != null && lastVec3 != null) {
try {
attackTicks++;

if (attackTicks > 7 || vec3.distanceTo(mc.thePlayer.getPositionVector()) > enemyDistance.getInput()) {
Expand All @@ -129,6 +127,8 @@ public void onPreUpdate(PreUpdateEvent e) {
}

lastVec3 = vec3;
} catch (NullPointerException ignored) {

}

}
Expand Down Expand Up @@ -167,7 +167,7 @@ public void onWorld(WorldEvent e) {
public void onRender3D(Render3DEvent event) {
if (target == null)
return;

if (renderPosition.isToggled()) {
RenderUtil.drawBox(target, vec3, lastVec3, Theme.getMainColor(), false);
}
Expand Down Expand Up @@ -213,7 +213,8 @@ public void onPacket(PacketEvent e) {
} else if (e.getPacket() instanceof S14PacketEntity) {
S14PacketEntity wrapper = (S14PacketEntity) e.getPacket();
if (((IS14PacketEntity) wrapper).getEntityId() == target.getEntityId()) {
vec3 = vec3.addVector(wrapper.func_149062_c() / 32.0D, wrapper.func_149061_d() / 32.0D, wrapper.func_149064_e() / 32.0D);
vec3 = vec3.addVector(wrapper.func_149062_c() / 32.0D, wrapper.func_149061_d() / 32.0D,
wrapper.func_149064_e() / 32.0D);
}
} else if (e.getPacket() instanceof S18PacketEntityTeleport) {
S18PacketEntityTeleport wrapper = (S18PacketEntityTeleport) e.getPacket();
Expand All @@ -229,15 +230,21 @@ public void onPacket(PacketEvent e) {

if (e.getType() == Type.SEND) {
if (mode.is("Latency")) {

if (e.getPacket() instanceof C02PacketUseEntity) {
C02PacketUseEntity wrapper = (C02PacketUseEntity) e.getPacket();
attackTicks = 0;
try {
C02PacketUseEntity wrapper = (C02PacketUseEntity) e.getPacket();
attackTicks = 0;

Entity entity = wrapper.getEntityFromWorld(mc.theWorld);
if (target != null && ((IC02PacketUseEntity) wrapper).getEntityId() == target.getEntityId())
return;
target = (EntityPlayer) entity;
vec3 = lastVec3 = entity.getPositionVector();
EntityPlayer entity = (EntityPlayer) wrapper.getEntityFromWorld(mc.theWorld);

if (target != null && ((IC02PacketUseEntity) wrapper).getEntityId() == target.getEntityId())
return;
target = entity;
vec3 = lastVec3 = entity.getPositionVector();
} catch (ClassCastException fuck) {

}
}
}

Expand Down Expand Up @@ -294,7 +301,7 @@ public void onDisconnect(final DisconnectionEvent e) {

private void release() {
while (!packetQueue.isEmpty()) {
if (packetQueue.peek().getCold().reached(latency.getInputToInt())) {
if (packetQueue.peek().getCold().getCum(latency.getInputToInt())) {
Packet<?> packet = packetQueue.poll().getPacket();
PacketUtil.receivePacketNoEvent((Packet<INetHandler>) packet);
} else {
Expand Down
8 changes: 8 additions & 0 deletions src/main/java/cc/unknown/utils/client/Cold.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ public class Cold {
public Cold(long lasts) {
this.lastMs = lasts;
}

public Cold() {
lastMs = System.currentTimeMillis();
}

// Resets the timer to the current time and clears the checkedFinish flag
public void start() {
Expand Down Expand Up @@ -95,6 +99,10 @@ public void reset() {
public long getTime() {
return Math.max(0L, System.currentTimeMillis() - time);
}

public boolean getCum(long hentai) {
return System.currentTimeMillis() - lastMs >= hentai;
}

/**
* Checks if a specified time has elapsed.
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/cc/unknown/utils/helpers/MathHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -81,9 +81,9 @@ public static double round(double n, int d) {
}

public static int randomInt(double x, double v) {
return (int) (Math.random() * (v - x) + x);
return (int) (Math.random() * (x - v) + v);
}

public static double randomDouble(double x, double v) {
return Math.random() * (x - v) + v;
}
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/cc/unknown/utils/network/TimedPacket.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ public class TimedPacket {

public TimedPacket(Packet<?> packet) {
this.packet = packet;
this.time = new Cold(0);
this.time = new Cold();
}

public Packet<?> getPacket() {
Expand Down

0 comments on commit 65774cc

Please sign in to comment.