Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
coltonk9043 committed Aug 7, 2024
2 parents e3c0fb6 + 06787a3 commit 1054977
Show file tree
Hide file tree
Showing 19 changed files with 634 additions and 33 deletions.
7 changes: 5 additions & 2 deletions .github/workflows/nightly-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ jobs:
- name: Grant execute permission for gradlew
run: chmod +x gradlew

- name: Fetch Build Time
run: echo "time=$(date + "%Y-%m-%d")" >> $GITHUB_ENV

- name: Build
run: ./gradlew build

Expand All @@ -34,8 +37,8 @@ jobs:
- uses: "0xDylan/[email protected]"
with:
repo_token: "${{ secrets.GITHUB_TOKEN }}"
automatic_release_tag: nightly-${{ github.run_number }}
automatic_release_tag: nightly-${{ env.TIME }}
prerelease: true
title: Nightly Build ${{ github.run_number }}
title: Nightly Build ${{ env.TIME }}
files: |
./build/libs/*.jar
12 changes: 8 additions & 4 deletions src/main/java/net/aoba/cmd/CommandManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,11 @@
import net.minecraft.util.Formatting;

import java.lang.reflect.Field;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Objects;
import java.util.*;

public class CommandManager {
private HashMap<String, Command> commands = new HashMap<String, Command>();
private List<String> commandHistory = new ArrayList<>();

public final CmdAimbot aimbot = new CmdAimbot();
public final CmdAutoEat autoeat = new CmdAutoEat();
Expand Down Expand Up @@ -69,6 +67,7 @@ public class CommandManager {
public final CmdTP tp = new CmdTP();
public final CmdTracer tracer = new CmdTracer();
public final CmdXRay xray = new CmdXRay();
public final CmdHistory history = new CmdHistory();

public static StringSetting PREFIX;

Expand Down Expand Up @@ -138,6 +137,7 @@ public int getNumOfCommands() {
*/
public void command(String[] commandIn) {
try {
commandHistory.add(String.join(" ", commandIn));

// Get the command from the user's message. (Index 0 is Username)
Command command = commands.get(commandIn[1]);
Expand All @@ -160,6 +160,10 @@ public void command(String[] commandIn) {
}
}

public List<String> getCommandHistory() {
return commandHistory;
}

/**
* Prints a message into the Minecraft Chat.
*
Expand Down
58 changes: 58 additions & 0 deletions src/main/java/net/aoba/cmd/commands/CmdHistory.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
package net.aoba.cmd.commands;

import net.aoba.Aoba;
import net.aoba.cmd.Command;
import net.aoba.cmd.CommandManager;
import net.minecraft.util.Formatting;
import org.apache.commons.lang3.StringUtils;

import java.util.ArrayList;

public class CmdHistory extends Command {

private static final int HISTORY_PER_PAGE = 5;

public CmdHistory() {
super("history", "Shows the command history.", "[page]");
}

@Override
public void runCommand(String[] parameters) {
if (parameters.length == 0) {
showHistory(1);
} else if (StringUtils.isNumeric(parameters[0])) {
int page = Integer.parseInt(parameters[0]);
showHistory(page);
} else {
CommandManager.sendChatMessage("Invalid parameter. Usage: .aoba history [page]");
}
}

private void showHistory(int page) {
CommandManager cm = Aoba.getInstance().commandManager;
ArrayList<String> history = new ArrayList<>(cm.getCommandHistory());
int totalPages = (int) Math.ceil((double) history.size() / HISTORY_PER_PAGE);

if (page < 1 || page > totalPages) {
CommandManager.sendChatMessage("Page " + page + " does not exist. There are only " + totalPages + " pages.");
return;
}

String title = "------------ Command History [Page " + page + " of " + totalPages + "] ------------";
CommandManager.sendChatMessage(title);

int startIndex = (page - 1) * HISTORY_PER_PAGE;
int endIndex = Math.min(startIndex + HISTORY_PER_PAGE, history.size());

for (int i = startIndex; i < endIndex; i++) {
CommandManager.sendChatMessage((i + 1) + ": " + history.get(i));
}

CommandManager.sendChatMessage("-".repeat(title.length() - 2)); // Adjust for Minecraft font width
}

@Override
public String[] getAutocorrect(String previousParameter) {
return new String[0]; // No autocorrect needed for history command
}
}
39 changes: 39 additions & 0 deletions src/main/java/net/aoba/event/events/SendMovementPacketEvent.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package net.aoba.event.events;

import net.aoba.event.listeners.AbstractListener;
import net.aoba.event.listeners.SendMovementPacketListener;

import java.util.ArrayList;
import java.util.List;

public class SendMovementPacketEvent {
public static class Pre extends AbstractEvent {
@Override
public void Fire(ArrayList<? extends AbstractListener> listeners) {
for (AbstractListener listener : List.copyOf(listeners)) {
SendMovementPacketListener sendMovementPacketListener = (SendMovementPacketListener) listener;
sendMovementPacketListener.onSendMovementPacket(this);
}
}

@Override
public Class<SendMovementPacketListener> GetListenerClassType() {
return SendMovementPacketListener.class;
}
}

public static class Post extends AbstractEvent {
@Override
public void Fire(ArrayList<? extends AbstractListener> listeners) {
for (AbstractListener listener : List.copyOf(listeners)) {
SendMovementPacketListener sendMovementPacketListener = (SendMovementPacketListener) listener;
sendMovementPacketListener.onSendMovementPacket(this);
}
}

@Override
public Class<SendMovementPacketListener> GetListenerClassType() {
return SendMovementPacketListener.class;
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package net.aoba.event.listeners;

import net.aoba.event.events.SendMovementPacketEvent;

public interface SendMovementPacketListener extends AbstractListener {
public abstract void onSendMovementPacket(SendMovementPacketEvent.Pre event);
public abstract void onSendMovementPacket(SendMovementPacketEvent.Post event);
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
public class AobaButtonWidget extends PressableWidget {
private Consumer<AobaButtonWidget> pressAction;
private long hoverStartTime = 0;
private static final long HOVER_ANIMATION_DURATION = 200;
private static final long HOVER_ANIMATION_DURATION = 200000000;

public AobaButtonWidget(int x, int y, int width, int height, Text message) {
super(x, y, width, height, message);
Expand All @@ -44,12 +44,12 @@ protected void renderWidget(DrawContext context, int mouseX, int mouseY, float d
Matrix4f matrix = context.getMatrices().peek().getPositionMatrix();

if (isHovered() && hoverStartTime == 0) {
hoverStartTime = System.currentTimeMillis();
hoverStartTime = System.nanoTime();
} else if (!isHovered()) {
hoverStartTime = 0;
}

long currentTime = System.currentTimeMillis();
long currentTime = System.nanoTime();
float hoverProgress = hoverStartTime > 0 ? (currentTime - hoverStartTime) / (float) HOVER_ANIMATION_DURATION : 0;
hoverProgress = Math.min(hoverProgress, 1.0f);
hoverProgress = (float) Math.sin(hoverProgress * Math.PI / 2);
Expand Down Expand Up @@ -77,4 +77,4 @@ protected void appendClickableNarrations(NarrationMessageBuilder builder) {
// For brevity, we'll just skip this for now - if you want to add narration to your widget, you can do so here.
return;
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package net.aoba.interfaces;

public interface IClientPlayerInteractionManager {
void aoba$syncSelected();
}
31 changes: 31 additions & 0 deletions src/main/java/net/aoba/mixin/ClientPlayerEntityMixin.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import net.aoba.Aoba;
import net.aoba.AobaClient;
import net.aoba.event.events.PlayerHealthEvent;
import net.aoba.event.events.SendMovementPacketEvent;
import net.aoba.gui.GuiManager;
import net.aoba.mixin.interfaces.ICamera;
import net.aoba.module.modules.movement.*;
Expand All @@ -40,6 +41,8 @@ public abstract class ClientPlayerEntityMixin extends AbstractClientPlayerEntity
@Shadow
private ClientPlayNetworkHandler networkHandler;

@Shadow protected abstract void sendMovementPackets();

@Inject(at = {@At("HEAD")}, method = "setShowsDeathScreen(Z)V")
private void onShowDeathScreen(boolean state, CallbackInfo ci) {
GuiManager hudManager = Aoba.getInstance().hudManager;
Expand Down Expand Up @@ -124,4 +127,32 @@ public void onChangeLookDirection(double cursorDeltaX,
ci.cancel();
}
}

@Inject(method = "sendMovementPackets", at = @At("HEAD"))
private void onSendMovementPacketsHead(CallbackInfo info) {
SendMovementPacketEvent.Pre sendMovementPacketPreEvent = new SendMovementPacketEvent.Pre();

Aoba.getInstance().eventManager.Fire(sendMovementPacketPreEvent);
}

@Inject(method = "tick", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/network/ClientPlayNetworkHandler;sendPacket(Lnet/minecraft/network/packet/Packet;)V", ordinal = 0))
private void onTickHasVehicleBeforeSendPackets(CallbackInfo info) {
SendMovementPacketEvent.Pre sendMovementPacketPreEvent = new SendMovementPacketEvent.Pre();

Aoba.getInstance().eventManager.Fire(sendMovementPacketPreEvent);
}

@Inject(method = "sendMovementPackets", at = @At("TAIL"))
private void onSendMovementPacketsTail(CallbackInfo info) {
SendMovementPacketEvent.Post sendMovementPacketPostEvent = new SendMovementPacketEvent.Post();

Aoba.getInstance().eventManager.Fire(sendMovementPacketPostEvent);
}

@Inject(method = "tick", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/network/ClientPlayNetworkHandler;sendPacket(Lnet/minecraft/network/packet/Packet;)V", ordinal = 1, shift = At.Shift.AFTER))
private void onTickHasVehicleAfterSendPackets(CallbackInfo info) {
SendMovementPacketEvent.Post sendMovementPacketPostEvent = new SendMovementPacketEvent.Post();

Aoba.getInstance().eventManager.Fire(sendMovementPacketPostEvent);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,21 @@

package net.aoba.mixin;

import net.aoba.interfaces.IClientPlayerInteractionManager;
import net.minecraft.client.network.ClientPlayerInteractionManager;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;

@Mixin(ClientPlayerInteractionManager.class)
public class ClientPlayerInteractionManagerMixin {
public abstract class ClientPlayerInteractionManagerMixin implements IClientPlayerInteractionManager {
@Shadow
protected abstract void syncSelectedSlot();

@Override
public void aoba$syncSelected() {
syncSelectedSlot();
}

// TODO Reach?
/*
* @Inject(at = { @At("HEAD") }, method = { "getReachDistance()F" }, cancellable
Expand Down
17 changes: 17 additions & 0 deletions src/main/java/net/aoba/mixin/interfaces/IPlayerMoveC2SPacket.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package net.aoba.mixin.interfaces;

import net.minecraft.network.packet.c2s.play.PlayerMoveC2SPacket;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Mutable;
import org.spongepowered.asm.mixin.gen.Accessor;

@Mixin(PlayerMoveC2SPacket.class)
public interface IPlayerMoveC2SPacket {
@Mutable
@Accessor("y")
void setY(double y);

@Mutable
@Accessor("onGround")
void setOnGround(boolean onGround);
}
Loading

0 comments on commit 1054977

Please sign in to comment.