Skip to content

Commit

Permalink
Modified binding system to use Custom bindings.
Browse files Browse the repository at this point in the history
Minecraft's default bindings suck, so here's a replacement.
  • Loading branch information
coltonk9043 committed Oct 12, 2023
1 parent 98cddc8 commit 7ee0cf9
Show file tree
Hide file tree
Showing 54 changed files with 154 additions and 101 deletions.
2 changes: 1 addition & 1 deletion src/main/java/net/aoba/core/settings/SettingManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ public static void loadSettings(String name, List<Setting> setting_list) {
}
case KEYBIND -> {
int keyCode = Integer.parseInt(config.getProperty(setting.ID, null));
setting.setValue(new KeyBinding(setting.ID, keyCode, "key.categories.aoba"));
setting.setValue(InputUtil.fromKeyCode(keyCode, 0));
}
case VECTOR2 -> {
String value_x = config.getProperty(setting.ID + "_x", null);
Expand Down
11 changes: 6 additions & 5 deletions src/main/java/net/aoba/core/settings/types/KeybindSetting.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,20 @@
import java.util.function.Consumer;
import net.aoba.core.settings.Setting;
import net.minecraft.client.option.KeyBinding;
import net.minecraft.client.util.InputUtil.Key;

public class KeybindSetting extends Setting<KeyBinding> {
public KeybindSetting(String ID, String description, KeyBinding default_value) {
public class KeybindSetting extends Setting<Key> {
public KeybindSetting(String ID, String description, Key default_value) {
super(ID, description, default_value);
type = TYPE.KEYBIND;
}

public KeybindSetting(String ID, String displayName, String description, KeyBinding default_value) {
public KeybindSetting(String ID, String displayName, String description, Key default_value) {
super(ID, displayName, description, default_value);
type = TYPE.KEYBIND;
}

public KeybindSetting(String ID, String description, KeyBinding default_value, Consumer<KeyBinding> onUpdate) {
public KeybindSetting(String ID, String description, Key default_value, Consumer<Key> onUpdate) {
super(ID, description, default_value, onUpdate);
type = TYPE.KEYBIND;
}
Expand All @@ -24,7 +25,7 @@ public KeybindSetting(String ID, String description, KeyBinding default_value, C
* Checks whether or not a value is with this setting's valid range.
*/
@Override
protected boolean isValueValid(KeyBinding value) {
protected boolean isValueValid(Key value) {
return true;
}
}
2 changes: 1 addition & 1 deletion src/main/java/net/aoba/gui/tabs/ModuleSettingsTab.java
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public ModuleSettingsTab(String title, float x, float y, Module module) {
i += 30;
}

this.setHeight(i);
this.setHeight(i - 30);
}

public final String getTitle() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public void draw(DrawContext drawContext, float partialTicks, Color color) {
renderUtils.drawString(drawContext, "Keybind", actualX + 8, actualY + 8, 0xFFFFFF);
renderUtils.drawBox(drawContext.getMatrices(), actualX + actualWidth - 100, actualY + 2, 98, actualHeight - 4, new Color(115, 115, 115), 0.8f);
renderUtils.drawOutline(drawContext.getMatrices(), actualX + actualWidth - 100, actualY + 2, 98, actualHeight - 4);
renderUtils.drawString(drawContext, this.keyBind.getValue().getBoundKeyLocalizedText().getString(), actualX + actualWidth - 90, actualY + 8, 0xFFFFFF);
renderUtils.drawString(drawContext, this.keyBind.getValue().getLocalizedText().getString(), actualX + actualWidth - 90, actualY + 8, 0xFFFFFF);
}

@Override
Expand All @@ -47,8 +47,7 @@ public void OnKeyDown(KeyDownEvent event) {
if(listeningForKey) {
int key = event.GetKey();
int scanCode = event.GetScanCode();

keyBind.getValue().setBoundKey(InputUtil.fromKeyCode(key, scanCode));
keyBind.setValue(InputUtil.fromKeyCode(key, scanCode));
listeningForKey = false;

event.SetCancelled(true);
Expand Down
12 changes: 7 additions & 5 deletions src/main/java/net/aoba/mixin/KeyboardMixin.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package net.aoba.mixin;

import org.lwjgl.glfw.GLFW;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
Expand All @@ -15,11 +16,12 @@ public class KeyboardMixin {
@Inject(at = {@At("HEAD")}, method = {"onKey(JIIII)V" }, cancellable = true)
private void OnKeyDown(long window, int key, int scancode,
int action, int modifiers, CallbackInfo ci) {
KeyDownEvent event = new KeyDownEvent(window, key, scancode, action, modifiers);
Aoba.getInstance().eventManager.Fire(event);

if(event.IsCancelled()) {
ci.cancel();
if(action == GLFW.GLFW_PRESS) {
KeyDownEvent event = new KeyDownEvent(window, key, scancode, action, modifiers);
Aoba.getInstance().eventManager.Fire(event);
if(event.IsCancelled()) {
ci.cancel();
}
}
}
}
30 changes: 17 additions & 13 deletions src/main/java/net/aoba/module/ModuleManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,9 @@
import net.aoba.Aoba;
import net.aoba.core.settings.Setting;
import net.aoba.core.settings.SettingManager;
import net.aoba.event.events.KeyDownEvent;
import net.aoba.event.events.RenderEvent;
import net.aoba.event.listeners.KeyDownListener;
import org.lwjgl.opengl.GL11;
import net.aoba.misc.RenderUtils;
import net.aoba.module.modules.combat.*;
Expand All @@ -36,9 +38,10 @@
import net.aoba.module.modules.world.*;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.option.KeyBinding;
import net.minecraft.client.util.InputUtil.Key;
import net.minecraft.client.util.math.MatrixStack;

public class ModuleManager {
public class ModuleManager implements KeyDownListener {
public ArrayList<Module> modules = new ArrayList<Module>();

//Modules
Expand Down Expand Up @@ -145,18 +148,11 @@ public ModuleManager() {
SettingManager.register_setting(setting, Aoba.getInstance().settingManager.modules_category);
}
}

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

public void update() {


for(Module module : modules) {
KeyBinding binding = module.getBind().getValue();
if(binding.wasPressed()) {
module.toggle();
binding.setPressed(false);
}
}
}

public void render(MatrixStack matrixStack) {
Expand All @@ -165,9 +161,7 @@ public void render(MatrixStack matrixStack) {
GL11.glEnable(GL11.GL_LINE_SMOOTH);
GL11.glEnable(GL11.GL_CULL_FACE);
GL11.glDisable(GL11.GL_DEPTH_TEST);




matrixStack.push();
RenderUtils.applyRenderOffset(matrixStack);

Expand Down Expand Up @@ -198,4 +192,14 @@ public Module getModuleByName(String string) {
}
return null;
}

@Override
public void OnKeyDown(KeyDownEvent event) {
for(Module module : modules) {
Key binding = module.getBind().getValue();
if(binding.getCode() == event.GetKey()) {
module.toggle();
}
}
}
}
6 changes: 4 additions & 2 deletions src/main/java/net/aoba/module/modules/combat/Aimbot.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@
import net.minecraft.command.argument.EntityAnchorArgumentType.EntityAnchor;
import net.minecraft.entity.Entity;
import net.minecraft.entity.LivingEntity;
import net.minecraft.client.util.InputUtil;
import net.minecraft.client.util.InputUtil.Key;

public class Aimbot extends Module implements RenderListener, TickListener {

Expand All @@ -45,9 +47,9 @@ public class Aimbot extends Module implements RenderListener, TickListener {
private BooleanSetting targetPlayers;

public Aimbot() {
super(new KeybindSetting("key.aimbot", "Aimbot Key", new KeyBinding("key.aimbot", GLFW.GLFW_KEY_K, "key.categories.aoba")));
super(new KeybindSetting("key.aimbot", "Aimbot Key", InputUtil.fromKeyCode(GLFW.GLFW_KEY_UNKNOWN, 0)));
this.setName("Aimbot");

this.setCategory(Category.Combat);
this.setDescription("Locks your crosshair towards a desire player or entity.");

Expand Down
6 changes: 3 additions & 3 deletions src/main/java/net/aoba/module/modules/combat/AntiInvis.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,15 @@
package net.aoba.module.modules.combat;

import org.lwjgl.glfw.GLFW;

import net.aoba.core.settings.types.KeybindSetting;
import net.aoba.module.Module;
import net.minecraft.client.option.KeyBinding;
import net.minecraft.client.util.InputUtil;

public class AntiInvis extends Module {

public AntiInvis() {
super(new KeybindSetting("key.antiinvis", "AntiInvis Key", new KeyBinding("key.antiinvis", GLFW.GLFW_KEY_UNKNOWN, "key.categories.aoba")));
super(new KeybindSetting("key.antiinvis", "AntiInvis Key", InputUtil.fromKeyCode(GLFW.GLFW_KEY_UNKNOWN, 0)));

this.setName("AntiInvis");
this.setCategory(Category.Combat);
this.setDescription("Reveals players who are invisible.");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,12 @@
import net.aoba.core.settings.types.KeybindSetting;
import net.aoba.module.Module;
import net.minecraft.client.option.KeyBinding;
import net.minecraft.client.util.InputUtil;

public class AntiKnockback extends Module {

public AntiKnockback() {
super(new KeybindSetting("key.antiknockback", "AntiKnockback Key", new KeyBinding("key.antiknockback", GLFW.GLFW_KEY_UNKNOWN, "key.categories.aoba")));
super(new KeybindSetting("key.antiknockback", "AntiKnockback Key", InputUtil.fromKeyCode(GLFW.GLFW_KEY_UNKNOWN, 0)));

this.setName("AntiKnockback");

Expand Down
4 changes: 2 additions & 2 deletions src/main/java/net/aoba/module/modules/combat/AutoRespawn.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,15 @@
import net.aoba.event.listeners.ReceivePacketListener;
import net.aoba.module.Module;
import net.minecraft.client.option.KeyBinding;
import net.minecraft.client.util.InputUtil;
import net.minecraft.network.packet.Packet;
import net.minecraft.network.packet.c2s.play.ClientStatusC2SPacket;
import net.minecraft.network.packet.s2c.play.HealthUpdateS2CPacket;

public class AutoRespawn extends Module implements ReceivePacketListener {

public AutoRespawn() {

super(new KeybindSetting("key.autorespawn", "AutoRespawn Key", new KeyBinding("key.autorespawn", GLFW.GLFW_KEY_UNKNOWN, "key.categories.aoba")));
super(new KeybindSetting("key.autorespawn", "AutoRespawn Key", InputUtil.fromKeyCode(GLFW.GLFW_KEY_UNKNOWN, 0)));

this.setName("AutoRespawn");

Expand Down
3 changes: 2 additions & 1 deletion src/main/java/net/aoba/module/modules/combat/AutoSoup.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import net.aoba.event.listeners.TickListener;
import net.aoba.module.Module;
import net.minecraft.client.option.KeyBinding;
import net.minecraft.client.util.InputUtil;
import net.minecraft.entity.player.PlayerInventory;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
Expand All @@ -44,7 +45,7 @@ public class AutoSoup extends Module implements TickListener {
private int previousSlot = -1;

public AutoSoup() {
super(new KeybindSetting("key.autosoup", "AutoSoup Key", new KeyBinding("key.autosoup", GLFW.GLFW_KEY_UNKNOWN, "key.categories.aoba")));
super(new KeybindSetting("key.autosoup", "AutoSoup Key", InputUtil.fromKeyCode(GLFW.GLFW_KEY_UNKNOWN, 0)));

this.setName("AutoSoup");
this.setCategory(Category.Combat);
Expand Down
5 changes: 3 additions & 2 deletions src/main/java/net/aoba/module/modules/combat/AutoTotem.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,13 @@
import net.aoba.core.settings.types.KeybindSetting;
import net.aoba.module.Module;
import net.minecraft.client.option.KeyBinding;
import net.minecraft.client.util.InputUtil;

public class AutoTotem extends Module{

public AutoTotem() {
super(new KeybindSetting("key.autototem", "AutoTotem Key", new KeyBinding("key.autototem", GLFW.GLFW_KEY_UNKNOWN, "key.categories.aoba")));

super(new KeybindSetting("key.autototem", "AutoTotem Key", InputUtil.fromKeyCode(GLFW.GLFW_KEY_UNKNOWN, 0)));
this.setName("AutoTotem");
this.setCategory(Category.Combat);
this.setDescription("Automatically replaced totems.");
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/net/aoba/module/modules/combat/Criticals.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,12 @@
import net.aoba.event.listeners.SendPacketListener;
import net.aoba.module.Module;
import net.minecraft.client.option.KeyBinding;
import net.minecraft.client.util.InputUtil;

public class Criticals extends Module implements SendPacketListener {

public Criticals() {
super(new KeybindSetting("key.criticals", "Criticals Key", new KeyBinding("key.criticals", GLFW.GLFW_KEY_UNKNOWN, "key.categories.aoba")));
super(new KeybindSetting("key.criticals", "Criticals Key", InputUtil.fromKeyCode(GLFW.GLFW_KEY_UNKNOWN, 0)));

this.setName("Criticals");
this.setCategory(Category.Combat);
Expand Down
5 changes: 3 additions & 2 deletions src/main/java/net/aoba/module/modules/combat/CrystalAura.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
import net.minecraft.block.BlockState;
import net.minecraft.block.Blocks;
import net.minecraft.client.option.KeyBinding;
import net.minecraft.client.util.InputUtil;
import net.minecraft.entity.Entity;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.entity.decoration.EndCrystalEntity;
Expand All @@ -48,8 +49,8 @@ public class CrystalAura extends Module implements TickListener {
private float radius = 10.0f;

public CrystalAura() {
super(new KeybindSetting("key.crystalaura", "Crystal Aura Key", new KeyBinding("key.crystalaura", GLFW.GLFW_KEY_UNKNOWN, "key.categories.aoba")));

super(new KeybindSetting("key.crystalaura", "Crystal Aura Key", InputUtil.fromKeyCode(GLFW.GLFW_KEY_UNKNOWN, 0)));
this.setName("CrystalAura");
this.setCategory(Category.Combat);
this.setDescription("Attacks anything within your personal space.");
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/net/aoba/module/modules/combat/KillAura.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import net.aoba.event.listeners.TickListener;
import net.aoba.module.Module;
import net.minecraft.client.option.KeyBinding;
import net.minecraft.client.util.InputUtil;
import net.minecraft.entity.Entity;
import net.minecraft.entity.LivingEntity;
import net.minecraft.entity.mob.Monster;
Expand All @@ -50,7 +51,7 @@ private enum Priority {
private BooleanSetting targetPlayers;

public KillAura() {
super(new KeybindSetting("key.killaura", "Kill Aura Key", new KeyBinding("key.killaura", GLFW.GLFW_KEY_UNKNOWN, "key.categories.aoba")));
super(new KeybindSetting("key.killaura", "Kill Aura Key", InputUtil.fromKeyCode(GLFW.GLFW_KEY_UNKNOWN, 0)));

this.setName("KillAura");
this.setCategory(Category.Combat);
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/net/aoba/module/modules/combat/Nametags.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import net.aoba.core.settings.types.KeybindSetting;
import net.aoba.module.Module;
import net.minecraft.client.option.KeyBinding;
import net.minecraft.client.util.InputUtil;

public class Nametags extends Module {

Expand All @@ -35,7 +36,7 @@ public class Nametags extends Module {
private BooleanSetting alwaysVisible;

public Nametags() {
super(new KeybindSetting("key.nametags", "NameTags Key", new KeyBinding("key.nametags", GLFW.GLFW_KEY_UNKNOWN, "key.categories.aoba")));
super(new KeybindSetting("key.nametags", "NameTags Key", InputUtil.fromKeyCode(GLFW.GLFW_KEY_UNKNOWN, 0)));

this.setName("Nametags");
this.setCategory(Category.Combat);
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/net/aoba/module/modules/combat/NoOverlay.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,12 @@
import net.aoba.core.settings.types.KeybindSetting;
import net.aoba.module.Module;
import net.minecraft.client.option.KeyBinding;
import net.minecraft.client.util.InputUtil;

public class NoOverlay extends Module {

public NoOverlay() {
super(new KeybindSetting("key.nooverlay", "NoOverlay Key", new KeyBinding("key.nooverlay", GLFW.GLFW_KEY_UNKNOWN, "key.categories.aoba")));
super(new KeybindSetting("key.nooverlay", "NoOverlay Key", InputUtil.fromKeyCode(GLFW.GLFW_KEY_UNKNOWN, 0)));

this.setName("NoOverlay");
this.setCategory(Category.Combat);
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/net/aoba/module/modules/combat/Reach.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,14 @@
import net.aoba.core.settings.types.KeybindSetting;
import net.aoba.module.Module;
import net.minecraft.client.option.KeyBinding;
import net.minecraft.client.util.InputUtil;

public class Reach extends Module {

private FloatSetting distance;

public Reach() {
super(new KeybindSetting("key.reach", "Reach Key", new KeyBinding("key.reach", GLFW.GLFW_KEY_UNKNOWN, "key.categories.aoba")));
super(new KeybindSetting("key.reach", "Reach Key", InputUtil.fromKeyCode(GLFW.GLFW_KEY_UNKNOWN, 0)));

this.setName("Reach");
this.setCategory(Category.Combat);
Expand Down
5 changes: 3 additions & 2 deletions src/main/java/net/aoba/module/modules/combat/TriggerBot.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import net.aoba.event.listeners.TickListener;
import net.aoba.module.Module;
import net.minecraft.client.option.KeyBinding;
import net.minecraft.client.util.InputUtil;
import net.minecraft.entity.Entity;
import net.minecraft.entity.mob.Monster;
import net.minecraft.entity.passive.AnimalEntity;
Expand All @@ -25,8 +26,8 @@ public class TriggerBot extends Module implements TickListener {
private BooleanSetting targetPlayers;

public TriggerBot() {
super(new KeybindSetting("key.triggerbot", "TriggerBot Key", new KeyBinding("key.triggerbot", GLFW.GLFW_KEY_UNKNOWN, "key.categories.aoba")));
super(new KeybindSetting("key.triggerbot", "TriggerBot Key", InputUtil.fromKeyCode(GLFW.GLFW_KEY_UNKNOWN, 0)));

this.setName("Triggerbot");
this.setCategory(Category.Combat);
this.setDescription("Attacks anything you are looking at.");
Expand Down
Loading

0 comments on commit 7ee0cf9

Please sign in to comment.