Skip to content

Commit

Permalink
Split Tick events into PRE and POST game tick events.
Browse files Browse the repository at this point in the history
  • Loading branch information
coltonk9043 committed Sep 16, 2024
1 parent f140f13 commit fdcfb39
Show file tree
Hide file tree
Showing 50 changed files with 359 additions and 292 deletions.
10 changes: 5 additions & 5 deletions src/main/java/net/aoba/combatmanager/CombatManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@

import net.aoba.Aoba;
import net.aoba.event.events.ReceivePacketEvent;
import net.aoba.event.events.TickEvent;
import net.aoba.event.events.PostTickEvent;
import net.aoba.event.events.TotemPopEvent;
import net.aoba.event.listeners.ReceivePacketListener;
import net.aoba.event.listeners.TickListener;
import net.aoba.event.listeners.PostTickListener;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityStatuses;
import net.minecraft.entity.player.PlayerEntity;
Expand All @@ -16,11 +16,11 @@

import static net.aoba.AobaClient.MC;

public class CombatManager implements TickListener, ReceivePacketListener {
public class CombatManager implements PostTickListener, ReceivePacketListener {
public HashMap<String, Integer> popList = new HashMap<>();

public CombatManager() {
Aoba.getInstance().eventManager.AddListener(TickListener.class, this);
Aoba.getInstance().eventManager.AddListener(PostTickListener.class, this);
Aoba.getInstance().eventManager.AddListener(ReceivePacketListener.class, this);
}

Expand Down Expand Up @@ -48,7 +48,7 @@ public void OnReceivePacket(ReceivePacketEvent event) {
}

@Override
public void OnUpdate(TickEvent event) {
public void onPostTick(PostTickEvent event) {
for (PlayerEntity player : MC.world.getPlayers()) {
if (player.getHealth() <= 0 && popList.containsKey(player.getName().getString()))
popList.remove(player.getName().getString(), popList.get(player.getName().getString()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,23 +19,23 @@
package net.aoba.event.events;

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

import net.aoba.event.listeners.PostTickListener;
import net.aoba.event.listeners.PreTickListener;
import java.util.ArrayList;
import java.util.List;

public class TickEvent extends AbstractEvent {
@Override
public void Fire(ArrayList<? extends AbstractListener> listeners) {
for (AbstractListener listener : List.copyOf(listeners)) {
TickListener tickListener = (TickListener) listener;
tickListener.OnUpdate(this);
}
}
public class PostTickEvent extends AbstractEvent {
@Override
public void Fire(ArrayList<? extends AbstractListener> listeners) {
for (AbstractListener listener : List.copyOf(listeners)) {
PostTickListener tickListener = (PostTickListener) listener;
tickListener.onPostTick(this);
}
}

@SuppressWarnings("unchecked")
@Override
public Class<TickListener> GetListenerClassType() {
return TickListener.class;
}
}
@SuppressWarnings("unchecked")
@Override
public Class<PostTickListener> GetListenerClassType() {
return PostTickListener.class;
}
}
22 changes: 22 additions & 0 deletions src/main/java/net/aoba/event/events/PreTickEvent.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package net.aoba.event.events;

import java.util.ArrayList;
import java.util.List;
import net.aoba.event.listeners.AbstractListener;
import net.aoba.event.listeners.PreTickListener;

public class PreTickEvent extends AbstractEvent{
@Override
public void Fire(ArrayList<? extends AbstractListener> listeners) {
for (AbstractListener listener : List.copyOf(listeners)) {
PreTickListener tickListener = (PreTickListener) listener;
tickListener.onPreTick(this);
}
}

@SuppressWarnings("unchecked")
@Override
public Class<PreTickListener> GetListenerClassType() {
return PreTickListener.class;
}
}
25 changes: 25 additions & 0 deletions src/main/java/net/aoba/event/listeners/PostTickListener.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/*
* Aoba Hacked Client
* Copyright (C) 2019-2024 coltonk9043
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

package net.aoba.event.listeners;

import net.aoba.event.events.PostTickEvent;

public interface PostTickListener extends AbstractListener {
public abstract void onPostTick(PostTickEvent event);
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@

package net.aoba.event.listeners;

import net.aoba.event.events.TickEvent;
import net.aoba.event.events.PreTickEvent;

public interface TickListener extends AbstractListener {
public abstract void OnUpdate(TickEvent event);
public interface PreTickListener extends AbstractListener {
public abstract void onPreTick(PreTickEvent event);
}
10 changes: 5 additions & 5 deletions src/main/java/net/aoba/gui/GuiManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@
import net.aoba.Aoba;
import net.aoba.event.events.KeyDownEvent;
import net.aoba.event.events.Render2DEvent;
import net.aoba.event.events.TickEvent;
import net.aoba.event.events.PostTickEvent;
import net.aoba.event.listeners.KeyDownListener;
import net.aoba.event.listeners.Render2DListener;
import net.aoba.event.listeners.TickListener;
import net.aoba.event.listeners.PostTickListener;
import net.aoba.gui.colors.Color;
import net.aoba.gui.colors.RainbowColor;
import net.aoba.gui.colors.RandomColor;
Expand Down Expand Up @@ -64,7 +64,7 @@
import java.util.HashMap;
import java.util.Map;

public class GuiManager implements KeyDownListener, TickListener, Render2DListener {
public class GuiManager implements KeyDownListener, PostTickListener, Render2DListener {
private static final MinecraftClient MC = MinecraftClient.getInstance();
private static CursorStyle currentCursor = CursorStyle.Default;
private static String tooltip = null;
Expand Down Expand Up @@ -122,7 +122,7 @@ public GuiManager() {
SettingManager.registerSetting(roundingRadius, Aoba.getInstance().settingManager.configContainer);

Aoba.getInstance().eventManager.AddListener(KeyDownListener.class, this);
Aoba.getInstance().eventManager.AddListener(TickListener.class, this);
Aoba.getInstance().eventManager.AddListener(PostTickListener.class, this);
Aoba.getInstance().eventManager.AddListener(Render2DListener.class, this);
}

Expand Down Expand Up @@ -243,7 +243,7 @@ public void SetHudActive(HudWindow hud, boolean state) {
* Getter for the current color used by the GUI for text rendering.
*/
@Override
public void OnUpdate(TickEvent event) {
public void onPostTick(PostTickEvent event) {
/**
* Moves the selected Tab to where the user moves their mouse.
*/
Expand Down
10 changes: 5 additions & 5 deletions src/main/java/net/aoba/gui/colors/AnimatedColor.java
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
package net.aoba.gui.colors;

import net.aoba.Aoba;
import net.aoba.event.events.TickEvent;
import net.aoba.event.listeners.TickListener;
import net.aoba.event.events.PostTickEvent;
import net.aoba.event.listeners.PostTickListener;

public abstract class AnimatedColor extends Color implements TickListener {
public abstract class AnimatedColor extends Color implements PostTickListener {
public AnimatedColor() {
super(255, 0, 0);
Aoba.getInstance().eventManager.AddListener(TickListener.class, this);
Aoba.getInstance().eventManager.AddListener(PostTickListener.class, this);
}

@Override
public abstract void OnUpdate(TickEvent event);
public abstract void onPostTick(PostTickEvent event);
}
4 changes: 2 additions & 2 deletions src/main/java/net/aoba/gui/colors/RainbowColor.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,15 @@
*/
package net.aoba.gui.colors;

import net.aoba.event.events.TickEvent;
import net.aoba.event.events.PostTickEvent;

public class RainbowColor extends AnimatedColor {
public RainbowColor() {
super();
}

@Override
public void OnUpdate(TickEvent event) {
public void onPostTick(PostTickEvent event) {
this.setHue(((this.getHue() + 1f) % 360));
}
}
4 changes: 2 additions & 2 deletions src/main/java/net/aoba/gui/colors/RandomColor.java
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
package net.aoba.gui.colors;

import net.aoba.event.events.TickEvent;
import net.aoba.event.events.PostTickEvent;

public class RandomColor extends AnimatedColor{
public RandomColor() {
super();
}

@Override
public void OnUpdate(TickEvent event) {
public void onPostTick(PostTickEvent event) {
this.setHSV(((float) (Math.random() * 360f)), 1f, 1f);
}
}
14 changes: 7 additions & 7 deletions src/main/java/net/aoba/gui/navigation/windows/GoToWindow.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

import net.aoba.Aoba;
import net.aoba.event.events.Render3DEvent;
import net.aoba.event.events.TickEvent;
import net.aoba.event.events.PostTickEvent;
import net.aoba.event.listeners.Render3DListener;
import net.aoba.event.listeners.TickListener;
import net.aoba.event.listeners.PostTickListener;
import net.aoba.gui.Margin;
import net.aoba.gui.colors.Colors;
import net.aoba.gui.components.*;
Expand Down Expand Up @@ -38,7 +38,7 @@
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

public class GoToWindow extends Window implements TickListener, Render3DListener {
public class GoToWindow extends Window implements PostTickListener, Render3DListener {

public enum Pathfinder {
Walk,
Expand Down Expand Up @@ -218,12 +218,12 @@ private void recalculatePathAsync() {
private void registerEvents() {

Aoba.getInstance().eventManager.AddListener(Render3DListener.class, this);
Aoba.getInstance().eventManager.AddListener(TickListener.class, this);
Aoba.getInstance().eventManager.AddListener(PostTickListener.class, this);
}

private void unregisterEvents() {
Aoba.getInstance().eventManager.RemoveListener(Render3DListener.class, this);
Aoba.getInstance().eventManager.RemoveListener(TickListener.class, this);
Aoba.getInstance().eventManager.RemoveListener(PostTickListener.class, this);
}

private void recalculatePath() {
Expand Down Expand Up @@ -347,7 +347,7 @@ public void OnRender(Render3DEvent event) {
}

@Override
public void OnUpdate(TickEvent event) {
public void onPostTick(PostTickEvent event) {
MinecraftClient MC = MinecraftClient.getInstance();
if (nodes == null)
return;
Expand Down Expand Up @@ -417,7 +417,7 @@ public void OnUpdate(TickEvent event) {
recalculatePathAsync();
} else {
Aoba.getInstance().eventManager.RemoveListener(Render3DListener.class, this);
Aoba.getInstance().eventManager.RemoveListener(TickListener.class, this);
Aoba.getInstance().eventManager.RemoveListener(PostTickListener.class, this);
clear();
startButton.setText("Calculate");
startButton.setOnClick(startRunnable);
Expand Down
15 changes: 12 additions & 3 deletions src/main/java/net/aoba/mixin/MinecraftClientMixin.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@

import net.aoba.Aoba;
import net.aoba.AobaClient;
import net.aoba.event.events.TickEvent;
import net.aoba.event.events.PostTickEvent;
import net.aoba.event.events.PreTickEvent;
import net.aoba.module.modules.render.FocusFps;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.Mouse;
Expand Down Expand Up @@ -64,10 +65,18 @@ private void onfinishedloading(CallbackInfo info) {
Aoba.getInstance().loadAssets();
}

@Inject(at = @At("HEAD"), method = "tick()V")
public void onPreTick(CallbackInfo info) {
if (this.world != null) {
PreTickEvent updateEvent = new PreTickEvent();
Aoba.getInstance().eventManager.Fire(updateEvent);
}
}

@Inject(at = @At("TAIL"), method = "tick()V")
public void tick(CallbackInfo info) {
public void onPostTick(CallbackInfo info) {
if (this.world != null) {
TickEvent updateEvent = new TickEvent();
PostTickEvent updateEvent = new PostTickEvent();
Aoba.getInstance().eventManager.Fire(updateEvent);
}
}
Expand Down
12 changes: 6 additions & 6 deletions src/main/java/net/aoba/module/modules/combat/Aimbot.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@

import net.aoba.Aoba;
import net.aoba.event.events.Render3DEvent;
import net.aoba.event.events.TickEvent;
import net.aoba.event.events.PostTickEvent;
import net.aoba.event.listeners.Render3DListener;
import net.aoba.event.listeners.TickListener;
import net.aoba.event.listeners.PostTickListener;
import net.aoba.utils.render.Render3D;
import net.aoba.module.Category;
import net.aoba.module.Module;
Expand All @@ -42,7 +42,7 @@
import net.minecraft.util.math.Vec3d;
import org.lwjgl.glfw.GLFW;

public class Aimbot extends Module implements TickListener, Render3DListener {
public class Aimbot extends Module implements PostTickListener, Render3DListener {

private LivingEntity temp = null;

Expand Down Expand Up @@ -79,13 +79,13 @@ public Aimbot() {

@Override
public void onDisable() {
Aoba.getInstance().eventManager.RemoveListener(TickListener.class, this);
Aoba.getInstance().eventManager.RemoveListener(PostTickListener.class, this);
Aoba.getInstance().eventManager.RemoveListener(Render3DListener.class, this);
}

@Override
public void onEnable() {
Aoba.getInstance().eventManager.AddListener(TickListener.class, this);
Aoba.getInstance().eventManager.AddListener(PostTickListener.class, this);
Aoba.getInstance().eventManager.AddListener(Render3DListener.class, this);
}

Expand Down Expand Up @@ -126,7 +126,7 @@ public void OnRender(Render3DEvent event) {
}

@Override
public void OnUpdate(TickEvent event) {
public void onPostTick(PostTickEvent event) {
currentTick++;

float radiusSqr = radius.getValue() * radius.getValue();
Expand Down
Loading

0 comments on commit fdcfb39

Please sign in to comment.