diff --git a/src/main/kotlin/org/aresclient/ares/Ares.kt b/src/main/kotlin/org/aresclient/ares/Ares.kt index 1058518c..11fc61d1 100644 --- a/src/main/kotlin/org/aresclient/ares/Ares.kt +++ b/src/main/kotlin/org/aresclient/ares/Ares.kt @@ -21,119 +21,119 @@ import org.slf4j.LoggerFactory import java.io.File class Ares: ModInitializer, Wrapper { - companion object { - val LOGGER = LoggerFactory.getLogger("Ares") - @JvmStatic val EVENT_MANAGER = AresEventManager() - - val PLUGINS = ArrayList() - - val SETTINGS_FILE = File("ares/config/settings.json") - val SETTINGS = SettingGroup().also { - try { - it.read(SETTINGS_FILE) - } catch (_: Exception) { - } - } - - val COMMAND_PREFIX = SETTINGS.addString("CmdPrefix", "-") - - fun load(plugin: Plugin) { - val start = System.currentTimeMillis() - - plugin.globals.forEach(Instrument::registerEvents) - plugin.modules.forEach(Instrument::registerEvents) - - plugin.init() - PLUGINS.add(plugin) - - LOGGER.info( - "Loaded plugin {} with {} globals, {} modules and {} commands in {} milliseconds.", - plugin.name, plugin.globals.size, plugin.modules.size, plugin.commands.size, - System.currentTimeMillis() - start - ) - } - } - - @field:EventHandler - val tickEventListener = EventListener { event -> - if(event.era != Era.BEFORE) return@EventListener - else if(event is TickEvent.Client) PLUGINS.forEach { plugin -> - plugin.tickClient() - } - else if(event is TickEvent.Motion)PLUGINS.forEach { plugin -> - plugin.tickMotion() - } - } - - @field:EventHandler - val renderEventListener = EventListener { event -> - if(event is RenderEvent.Hud) { - val state = Renderer.begin2d() - PLUGINS.forEach { plugin -> - plugin.renderHud(event.tickDelta, state.buffers, state.matrixStack) - } - Renderer.end(state) - } - else if(event is RenderEvent.World) { - val state = Renderer.begin3d(event.matrix4f) - PLUGINS.forEach { plugin -> - plugin.renderWorld(event.tickDelta, state) - } - Renderer.end(state) - } - } - - @field:EventHandler - val inputEventListener = EventListener { event -> - if(MC.currentScreen !is TitleScreen && MC.currentScreen !is AresScreen && MC.currentScreen != null) - return@EventListener - - when(event) { - is InputEvent.Keyboard.Pressed -> BindSetting.getAll().forEach { it.triggerCallback(event.key, true, event.repeat) } - is InputEvent.Keyboard.Released -> BindSetting.getAll().forEach { it.triggerCallback(event.key, false, false) } - is InputEvent.Mouse.Pressed -> BindSetting.getAll().forEach { it.triggerCallback(event.key, true, event.repeat) } - is InputEvent.Mouse.Released -> BindSetting.getAll().forEach { it.triggerCallback(event.key, false, false) } - } - } - - private fun BindSetting.triggerCallback(key: Int, state: Boolean, repeat: Boolean) { - if(this.value != key) return - this.callback.accept(state, repeat) - } - - @field:EventHandler - val chatListener = EventListener { event -> - if(event.message.startsWith(COMMAND_PREFIX.value)) { - Command.execute(ChatUtil, event.message.substring(COMMAND_PREFIX.value.length)) - MC.inGameHud.chatHud.addToMessageHistory(event.message) - event.isCancelled = true - } - } - - @field:EventHandler - val charTypedListener = EventListener { event -> - if(MC.currentScreen == null && !MC.NULL && COMMAND_PREFIX.value.length == 1 && event.codePoint.toChar() == COMMAND_PREFIX.value[0]) - MC.setScreen(ChatScreen("")) - } - - @field:EventHandler - val shutdownListener = EventListener { - FriendUtil.save() - SETTINGS_FILE.parentFile.mkdirs() - SETTINGS.write(SETTINGS_FILE) - Renderer.cleanup() - } - - override fun onInitialize() { - val start = System.currentTimeMillis() - - EVENT_MANAGER.register(this) - - FriendUtil - load(AresPlugin) - // TODO: Dynamic Plugin Loading? - - LOGGER.info("Ares loaded {} plugins in {} milliseconds.", PLUGINS.size, System.currentTimeMillis() - start) - } + companion object { + val LOGGER = LoggerFactory.getLogger("Ares") + @JvmStatic + val EVENT_MANAGER = AresEventManager() + + val PLUGINS = ArrayList() + + val SETTINGS_FILE = File("ares/config/settings.json") + val SETTINGS = SettingGroup().also { + try { + it.read(SETTINGS_FILE) + } catch(_: Exception) { + } + } + + val COMMAND_PREFIX = SETTINGS.addString("CmdPrefix", "-") + + fun load(plugin: Plugin) { + val start = System.currentTimeMillis() + + plugin.globals.forEach(Instrument::registerEvents) + plugin.modules.forEach(Instrument::registerEvents) + + plugin.init() + PLUGINS.add(plugin) + + LOGGER.info( + "Loaded plugin {} with {} globals, {} modules and {} commands in {} milliseconds.", + plugin.name, plugin.globals.size, plugin.modules.size, plugin.commands.size, + System.currentTimeMillis() - start + ) + } + } + + @field:EventHandler + val tickEventListener = EventListener { event -> + if(event.era != Era.BEFORE) return@EventListener + else if(event is TickEvent.Client) PLUGINS.forEach { plugin -> + plugin.tickClient() + } + else if(event is TickEvent.Motion) PLUGINS.forEach { plugin -> + plugin.tickMotion() + } + } + + @field:EventHandler + val renderEventListener = EventListener { event -> + if(event is RenderEvent.Hud) { + val state = Renderer.begin2d() + PLUGINS.forEach { plugin -> + plugin.renderHud(event.tickDelta, state.buffers, state.matrixStack) + } + Renderer.end(state) + } else if(event is RenderEvent.World) { + val state = Renderer.begin3d(event.matrix4f) + PLUGINS.forEach { plugin -> + plugin.renderWorld(event.tickDelta, state) + } + Renderer.end(state) + } + } + + @field:EventHandler + val inputEventListener = EventListener { event -> + if(MC.currentScreen !is TitleScreen && MC.currentScreen !is AresScreen && MC.currentScreen != null) + return@EventListener + + when(event) { + is InputEvent.Keyboard.Pressed -> BindSetting.getAll().forEach { it.triggerCallback(event.key, true, event.repeat) } + is InputEvent.Keyboard.Released -> BindSetting.getAll().forEach { it.triggerCallback(event.key, false, false) } + is InputEvent.Mouse.Pressed -> BindSetting.getAll().forEach { it.triggerCallback(event.key, true, event.repeat) } + is InputEvent.Mouse.Released -> BindSetting.getAll().forEach { it.triggerCallback(event.key, false, false) } + } + } + + private fun BindSetting.triggerCallback(key: Int, state: Boolean, repeat: Boolean) { + if(this.value != key) return + this.callback.accept(state, repeat) + } + + @field:EventHandler + val chatListener = EventListener { event -> + if(event.message.startsWith(COMMAND_PREFIX.value)) { + Command.execute(ChatUtil, event.message.substring(COMMAND_PREFIX.value.length)) + MC.inGameHud.chatHud.addToMessageHistory(event.message) + event.isCancelled = true + } + } + + @field:EventHandler + val charTypedListener = EventListener { event -> + if(MC.currentScreen == null && !MC.NULL && COMMAND_PREFIX.value.length == 1 && event.codePoint.toChar() == COMMAND_PREFIX.value[0]) + MC.setScreen(ChatScreen("")) + } + + @field:EventHandler + val shutdownListener = EventListener { + FriendUtil.save() + SETTINGS_FILE.parentFile.mkdirs() + SETTINGS.write(SETTINGS_FILE) + Renderer.cleanup() + } + + override fun onInitialize() { + val start = System.currentTimeMillis() + + EVENT_MANAGER.register(this) + + FriendUtil + load(AresPlugin) + // TODO: Dynamic Plugin Loading? + + LOGGER.info("Ares loaded {} plugins in {} milliseconds.", PLUGINS.size, System.currentTimeMillis() - start) + } } diff --git a/src/main/kotlin/org/aresclient/ares/api/JWrapper.java b/src/main/kotlin/org/aresclient/ares/api/JWrapper.java index a195da57..89437c8c 100644 --- a/src/main/kotlin/org/aresclient/ares/api/JWrapper.java +++ b/src/main/kotlin/org/aresclient/ares/api/JWrapper.java @@ -5,6 +5,6 @@ import org.aresclient.ares.Ares; public interface JWrapper { - MinecraftClient MC = MinecraftClient.getInstance(); - EventManager EVENTS = Ares.getEVENT_MANAGER(); + MinecraftClient MC = MinecraftClient.getInstance(); + EventManager EVENTS = Ares.getEVENT_MANAGER(); } diff --git a/src/main/kotlin/org/aresclient/ares/api/Plugin.kt b/src/main/kotlin/org/aresclient/ares/api/Plugin.kt index 9693975a..dcacb577 100644 --- a/src/main/kotlin/org/aresclient/ares/api/Plugin.kt +++ b/src/main/kotlin/org/aresclient/ares/api/Plugin.kt @@ -7,26 +7,28 @@ import org.aresclient.ares.api.instruments.Module import org.aresclient.ares.api.render.MatrixStack import org.aresclient.ares.api.render.Renderer -open class Plugin(val name: String, val description: String, val version: String, val mcVersion: String, - val authors: Array, val globals: List = emptyList(), val modules: List = emptyList(), - val commands: List = emptyList()): Wrapper { - open fun init() { - } +open class Plugin( + val name: String, val description: String, val version: String, val mcVersion: String, + val authors: Array, val globals: List = emptyList(), val modules: List = emptyList(), + val commands: List = emptyList() +): Wrapper { + open fun init() { + } - open fun tickClient() { - modules.forEach(Instrument::tick) - globals.forEach(Instrument::tick) - } + open fun tickClient() { + modules.forEach(Instrument::tick) + globals.forEach(Instrument::tick) + } - open fun tickMotion() { - modules.forEach(Module::motion) - } + open fun tickMotion() { + modules.forEach(Module::motion) + } - open fun renderHud(delta: Float, buffers: Renderer.Buffers, matrixStack: MatrixStack) { - modules.forEach { module -> module.renderHud(delta, buffers, matrixStack) } - } + open fun renderHud(delta: Float, buffers: Renderer.Buffers, matrixStack: MatrixStack) { + modules.forEach { module -> module.renderHud(delta, buffers, matrixStack) } + } - open fun renderWorld(delta: Float, renderer: Renderer.State) { - modules.forEach { module -> module.renderWorld(delta, renderer) } - } + open fun renderWorld(delta: Float, renderer: Renderer.State) { + modules.forEach { module -> module.renderWorld(delta, renderer) } + } } diff --git a/src/main/kotlin/org/aresclient/ares/api/Wrapper.kt b/src/main/kotlin/org/aresclient/ares/api/Wrapper.kt index 77a4b9c1..b7732a30 100644 --- a/src/main/kotlin/org/aresclient/ares/api/Wrapper.kt +++ b/src/main/kotlin/org/aresclient/ares/api/Wrapper.kt @@ -12,20 +12,20 @@ import org.slf4j.Logger interface Wrapper { - val profiler: Profiler get() = Profilers.get() + val profiler: Profiler get() = Profilers.get() - val EVENTS: AresEventManager get() = Ares.EVENT_MANAGER + val EVENTS: AresEventManager get() = Ares.EVENT_MANAGER - val MC: MinecraftClient get() = MinecraftClient.getInstance() + val MC: MinecraftClient get() = MinecraftClient.getInstance() - val MinecraftClient.NULL: Boolean get() = world == null || player == null + val MinecraftClient.NULL: Boolean get() = world == null || player == null - val SELF: ClientPlayerEntity get() = MC.player!! + val SELF: ClientPlayerEntity get() = MC.player!! - val WORLD: ClientWorld get() = MC.world!! + val WORLD: ClientWorld get() = MC.world!! - val CAMERA: Camera get() = MC.gameRenderer.camera + val CAMERA: Camera get() = MC.gameRenderer.camera - val LOGGER: Logger get() = Ares.LOGGER + val LOGGER: Logger get() = Ares.LOGGER } \ No newline at end of file diff --git a/src/main/kotlin/org/aresclient/ares/api/events/AresEventManager.kt b/src/main/kotlin/org/aresclient/ares/api/events/AresEventManager.kt index 9f00032a..44155867 100644 --- a/src/main/kotlin/org/aresclient/ares/api/events/AresEventManager.kt +++ b/src/main/kotlin/org/aresclient/ares/api/events/AresEventManager.kt @@ -9,15 +9,16 @@ enum class Era { BEFORE, AFTER } abstract class AresEvent(val name: String, val era: Era? = null): Event(), Wrapper class AresEventManager: EventManager(), Wrapper { - override fun post(event: T): T = when (event) { - is AresEvent -> { - profiler.push("ares_" + event.name.lowercase() + event.era?.let { "_" + it.name.lowercase() }) - val out = super.post(event) - profiler.pop() - out - } - else -> { - super.post(event) - } - } + override fun post(event: T): T = when(event) { + is AresEvent -> { + profiler.push("ares_" + event.name.lowercase() + event.era?.let { "_" + it.name.lowercase() }) + val out = super.post(event) + profiler.pop() + out + } + + else -> { + super.post(event) + } + } } diff --git a/src/main/kotlin/org/aresclient/ares/api/events/Events.kt b/src/main/kotlin/org/aresclient/ares/api/events/Events.kt index a9ba09f4..3f7c20fa 100644 --- a/src/main/kotlin/org/aresclient/ares/api/events/Events.kt +++ b/src/main/kotlin/org/aresclient/ares/api/events/Events.kt @@ -6,56 +6,56 @@ import org.aresclient.ares.api.instruments.Module import org.joml.Matrix4f abstract class CameraEvent(val delta: Float, type: String): AresEvent("camera-$type") { - class Position(delta: Float, var x: Double, var y: Double, var z: Double): CameraEvent(delta, "position") - class Rotation(delta: Float, var yaw: Float, var pitch: Float): CameraEvent(delta, "rotation") + class Position(delta: Float, var x: Double, var y: Double, var z: Double): CameraEvent(delta, "position") + class Rotation(delta: Float, var yaw: Float, var pitch: Float): CameraEvent(delta, "rotation") } abstract class InputEvent(val type: Type): AresEvent("input-" + type.name) { - enum class Type { KEYBOARD, MOUSE } + enum class Type { KEYBOARD, MOUSE } - abstract class Keyboard(val state: State, val key: Int): InputEvent(Type.KEYBOARD) { - enum class State { PRESSED, RELEASED } + abstract class Keyboard(val state: State, val key: Int): InputEvent(Type.KEYBOARD) { + enum class State { PRESSED, RELEASED } - class Pressed(key: Int, val repeat: Boolean): Keyboard(State.PRESSED, key) - class Released(key: Int): Keyboard(State.RELEASED, key) - } + class Pressed(key: Int, val repeat: Boolean): Keyboard(State.PRESSED, key) + class Released(key: Int): Keyboard(State.RELEASED, key) + } - abstract class Mouse(val state: State): InputEvent(Type.MOUSE) { - enum class State { PRESSED, RELEASED, SCROLLED, MOVED } + abstract class Mouse(val state: State): InputEvent(Type.MOUSE) { + enum class State { PRESSED, RELEASED, SCROLLED, MOVED } - class Pressed(val key: Int, val repeat: Boolean): Mouse(State.PRESSED) - class Released(val key: Int): Mouse(State.RELEASED) - class Scrolled(val vertical: Double): Mouse(State.SCROLLED) + class Pressed(val key: Int, val repeat: Boolean): Mouse(State.PRESSED) + class Released(val key: Int): Mouse(State.RELEASED) + class Scrolled(val vertical: Double): Mouse(State.SCROLLED) // class Moved(val x: Double, val y: Double, val dX: Double, val dY: Double, key: Int): Mouse(State.MOVED, key) - } + } } class CharTypedEvent(val codePoint: Int, val modifers: Int): AresEvent("char-typed") abstract class PlayerEvent(name: String): AresEvent("player-$name") { - class ChangeLookDirection(val cursorDeltaX: Double, val cursorDeltaY: Double): PlayerEvent("change-look-direction") - class Move(val movementType: MovementType, val movement: Vec3d): PlayerEvent("move") - class UpdateVelocityYaw(var yaw: Float): PlayerEvent("update-velocity-yaw") + class ChangeLookDirection(val cursorDeltaX: Double, val cursorDeltaY: Double): PlayerEvent("change-look-direction") + class Move(val movementType: MovementType, val movement: Vec3d): PlayerEvent("move") + class UpdateVelocityYaw(var yaw: Float): PlayerEvent("update-velocity-yaw") } abstract class RenderEvent(val type: Type): AresEvent("render-" + type.name) { - //TODO: ERA? - enum class Type { HUD, WORLD } + //TODO: ERA? + enum class Type { HUD, WORLD } - class Hud(val tickDelta: Float): RenderEvent(Type.HUD) - class World(val tickDelta: Float, val matrix4f: Matrix4f): RenderEvent(Type.WORLD) + class Hud(val tickDelta: Float): RenderEvent(Type.HUD) + class World(val tickDelta: Float, val matrix4f: Matrix4f): RenderEvent(Type.WORLD) } class ScreenOpenedEvent(val mainMenu: Boolean): AresEvent("screen-open") class ShutdownEvent: AresEvent("shutdown") abstract class TickEvent(val type: Type, era: Era): AresEvent("tick-" + type.name, era) { - enum class Type { CLIENT, GAMELOOP, WORLD, MOTION } + enum class Type { CLIENT, GAMELOOP, WORLD, MOTION } - class Client(era: Era): TickEvent(Type.CLIENT, era) - class GameLoop(era: Era): TickEvent(Type.GAMELOOP, era) - class World(era: Era): TickEvent(Type.WORLD, era) - class Motion(era: Era): TickEvent(Type.MOTION, era) + class Client(era: Era): TickEvent(Type.CLIENT, era) + class GameLoop(era: Era): TickEvent(Type.GAMELOOP, era) + class World(era: Era): TickEvent(Type.WORLD, era) + class Motion(era: Era): TickEvent(Type.MOTION, era) } class ChatEvent(val message: String): AresEvent("chat") diff --git a/src/main/kotlin/org/aresclient/ares/api/gui/Button.kt b/src/main/kotlin/org/aresclient/ares/api/gui/Button.kt index 1a453cd1..059d2e86 100644 --- a/src/main/kotlin/org/aresclient/ares/api/gui/Button.kt +++ b/src/main/kotlin/org/aresclient/ares/api/gui/Button.kt @@ -8,7 +8,8 @@ import kotlin.math.min abstract class Button( x: Float, y: Float, width: Float, height: Float, private var action: (Button) -> Unit = {}, - private val clipping: Clipping = Clipping.STENCIL, private val ref: Int = 1): StaticElement(x, y, width, height) { + private val clipping: Clipping = Clipping.STENCIL, private val ref: Int = 1 +): StaticElement(x, y, width, height) { enum class Clipping { STENCIL, SCISSOR, @@ -28,7 +29,7 @@ abstract class Button( 1, 2, 3 ) } - + protected var hovering = false protected var hoverSince = 0L diff --git a/src/main/kotlin/org/aresclient/ares/api/gui/Element.kt b/src/main/kotlin/org/aresclient/ares/api/gui/Element.kt index c638494d..301fa8ae 100644 --- a/src/main/kotlin/org/aresclient/ares/api/gui/Element.kt +++ b/src/main/kotlin/org/aresclient/ares/api/gui/Element.kt @@ -30,28 +30,31 @@ abstract class Element: Wrapper { fun getChildren(): Stack = children - open fun pushChild(child:Element):Element { + open fun pushChild(child: Element): Element { getChildren().push(child).setParent(this) child.update() return this } - fun pushChildren(vararg children:Element):Element { + fun pushChildren(vararg children: Element): Element { children.forEach { pushChild(it) } return this } - fun pushChildren(children: Iterable):Element { + + fun pushChildren(children: Iterable): Element { children.forEach { pushChild(it) } return this } - fun removeChild(element:Element):Element { + + fun removeChild(element: Element): Element { getChildren().remove(element) return this } - open fun popChild():Element = getChildren().pop().setParent(null) + + open fun popChild(): Element = getChildren().pop().setParent(null) fun getParent(): Element? = parent - fun setParent(parent: Element?):Element { + fun setParent(parent: Element?): Element { this.parent = parent return this } @@ -200,8 +203,10 @@ open class ScreenElement(title: String): Element() { fontRenderer.bindTexture() state.buffers.triangleTexColor.draw(matrixStack) { for((i, line) in tooltip!!.withIndex()) { - fontRenderer.drawString(this, line, - padding, padding - height + i * fontRenderer.charHeight, theme.lightground.value) + fontRenderer.drawString( + this, line, + padding, padding - height + i * fontRenderer.charHeight, theme.lightground.value + ) } } @@ -276,31 +281,31 @@ open class DynamicElement( override fun getWidth(): Float = width.invoke() override fun getHeight(): Float = height.invoke() - fun setVisible(value: () -> Boolean):DynamicElement { + fun setVisible(value: () -> Boolean): DynamicElement { visible = value return this } - fun setX(value: () -> Float):DynamicElement { + fun setX(value: () -> Float): DynamicElement { x = value return this } - fun setY(value: () -> Float):DynamicElement { + fun setY(value: () -> Float): DynamicElement { y = value return this } - fun setWidth(value: () -> Float):DynamicElement { + fun setWidth(value: () -> Float): DynamicElement { width = value return this } - fun setHeight(value: () -> Float):DynamicElement { + fun setHeight(value: () -> Float): DynamicElement { height = value return this } - } +} // an element that doesn't change dimension or size @@ -318,40 +323,42 @@ open class StaticElement( override fun getWidth(): Float = width override fun getHeight(): Float = height - fun setVisible(value: Boolean):StaticElement { + fun setVisible(value: Boolean): StaticElement { visible = value return this } - fun setX(value: Float):StaticElement { + fun setX(value: Float): StaticElement { x = value return this } - fun setY(value: Float):StaticElement { + fun setY(value: Float): StaticElement { y = value return this } - fun setWidth(value: Float):StaticElement { + fun setWidth(value: Float): StaticElement { width = value return this } - fun setHeight(value: Float):StaticElement { + fun setHeight(value: Float): StaticElement { height = value return this } } -open class DynamicElementGroup(private val columns: Int, - visible: () -> Boolean = { true }, x: () -> Float = { 0f }, y: () -> Float = { 0f }, - width: () -> Float = { 0f }, height: () -> Float = { 0f }): DynamicElement(visible, x, y, width, height) { +open class DynamicElementGroup( + private val columns: Int, + visible: () -> Boolean = { true }, x: () -> Float = { 0f }, y: () -> Float = { 0f }, + width: () -> Float = { 0f }, height: () -> Float = { 0f } +): DynamicElement(visible, x, y, width, height) { init { if(columns < 1) throw RuntimeException("Fewer than 1 columns in DynamicElementGroup is not possible") } - override fun pushChild(child:Element):Element { + override fun pushChild(child: Element): Element { if(child !is DynamicElement) throw RuntimeException("Cannot add static element to dynamic group!") val curr = getChildren().size diff --git a/src/main/kotlin/org/aresclient/ares/api/gui/TextBox.kt b/src/main/kotlin/org/aresclient/ares/api/gui/TextBox.kt index 6089b7ee..1248a8bd 100644 --- a/src/main/kotlin/org/aresclient/ares/api/gui/TextBox.kt +++ b/src/main/kotlin/org/aresclient/ares/api/gui/TextBox.kt @@ -1,12 +1,12 @@ package org.aresclient.ares.api.gui -import org.aresclient.ares.impl.util.RenderHelper -import org.aresclient.ares.impl.util.RenderHelper.draw -import org.aresclient.ares.impl.util.Theme import org.aresclient.ares.api.render.FontRenderer import org.aresclient.ares.api.render.MatrixStack import org.aresclient.ares.api.render.Renderer import org.aresclient.ares.api.util.Keys +import org.aresclient.ares.impl.util.RenderHelper +import org.aresclient.ares.impl.util.RenderHelper.draw +import org.aresclient.ares.impl.util.Theme import java.lang.Integer.max import java.lang.Integer.min import java.util.concurrent.atomic.AtomicBoolean @@ -163,8 +163,10 @@ open class TextBox(x: Float, y: Float, width: Float, fontSize: Float, private va // TODO: \n support for return/enter/line feed/line break/idkwhytherearesomanynamesforit // returns number of lines used - private fun FontRenderer.runSplitString(text: String, x: Float, y: Float, wrapWidth: Float, padding: Float, rgba: FloatArray, - callback: (Char, Float, Float) -> Boolean): Int { + private fun FontRenderer.runSplitString( + text: String, x: Float, y: Float, wrapWidth: Float, padding: Float, rgba: FloatArray, + callback: (Char, Float, Float) -> Boolean + ): Int { var lines = 1 var currX = x var currY = y diff --git a/src/main/kotlin/org/aresclient/ares/api/instruments/Command.kt b/src/main/kotlin/org/aresclient/ares/api/instruments/Command.kt index e5dded4e..1223a636 100644 --- a/src/main/kotlin/org/aresclient/ares/api/instruments/Command.kt +++ b/src/main/kotlin/org/aresclient/ares/api/instruments/Command.kt @@ -8,52 +8,52 @@ import com.mojang.brigadier.tree.CommandNode import com.mojang.brigadier.tree.LiteralCommandNode abstract class Command(val name: String, vararg val aliases: String = arrayOf()) { - interface IContext { - fun print(message: String) - fun error(message: String) - fun clear() - } - - companion object { - private val DISPATCHER: CommandDispatcher = CommandDispatcher() - - fun getUsages(context: IContext, node: CommandNode): Collection { - return DISPATCHER.getSmartUsage(node, context).values - } - - fun execute(context: IContext, command: String) { - try { - DISPATCHER.execute(command, context) - } catch(e: CommandSyntaxException) { - context.error(e.localizedMessage) - } - } - } - - private val node: LiteralCommandNode = DISPATCHER.register(literal(name).builder()) - - protected abstract fun LiteralArgumentBuilder.builder(): LiteralArgumentBuilder - - init { - for(alias in aliases) { - DISPATCHER.register(literal(alias).fixedRedirect(node)) - } - } - - fun getNode(): CommandNode { - return node - } - - fun getUsages(context: IContext): Collection { - return getUsages(context, node) - } - - // Brigadier's redirect is broken for commands with no arguments, and has been for many years. See: - // https://github.com/Mojang/brigadier/issues/46 - // https://github.com/PaperMC/Velocity/blob/8abc9c80a69158ebae0121fda78b55c865c0abad/proxy/src/main/java/com/velocitypowered/proxy/util/BrigadierUtils.java#L38 - private fun LiteralArgumentBuilder.fixedRedirect(target: LiteralCommandNode): LiteralArgumentBuilder { - val builder = requires(target.requirement).forward(target.redirect, target.redirectModifier, target.isFork).executes(target.command) - target.children.forEach { builder.then(it) } - return builder - } + interface IContext { + fun print(message: String) + fun error(message: String) + fun clear() + } + + companion object { + private val DISPATCHER: CommandDispatcher = CommandDispatcher() + + fun getUsages(context: IContext, node: CommandNode): Collection { + return DISPATCHER.getSmartUsage(node, context).values + } + + fun execute(context: IContext, command: String) { + try { + DISPATCHER.execute(command, context) + } catch(e: CommandSyntaxException) { + context.error(e.localizedMessage) + } + } + } + + private val node: LiteralCommandNode = DISPATCHER.register(literal(name).builder()) + + protected abstract fun LiteralArgumentBuilder.builder(): LiteralArgumentBuilder + + init { + for(alias in aliases) { + DISPATCHER.register(literal(alias).fixedRedirect(node)) + } + } + + fun getNode(): CommandNode { + return node + } + + fun getUsages(context: IContext): Collection { + return getUsages(context, node) + } + + // Brigadier's redirect is broken for commands with no arguments, and has been for many years. See: + // https://github.com/Mojang/brigadier/issues/46 + // https://github.com/PaperMC/Velocity/blob/8abc9c80a69158ebae0121fda78b55c865c0abad/proxy/src/main/java/com/velocitypowered/proxy/util/BrigadierUtils.java#L38 + private fun LiteralArgumentBuilder.fixedRedirect(target: LiteralCommandNode): LiteralArgumentBuilder { + val builder = requires(target.requirement).forward(target.redirect, target.redirectModifier, target.isFork).executes(target.command) + target.children.forEach { builder.then(it) } + return builder + } } diff --git a/src/main/kotlin/org/aresclient/ares/api/instruments/Component.kt b/src/main/kotlin/org/aresclient/ares/api/instruments/Component.kt index 137e9ea3..62f1b78f 100644 --- a/src/main/kotlin/org/aresclient/ares/api/instruments/Component.kt +++ b/src/main/kotlin/org/aresclient/ares/api/instruments/Component.kt @@ -13,34 +13,34 @@ import org.aresclient.ares.api.setting.SettingGroup */ open class Component(val master: I) { - init { - master.addComponent(this) - } - - open class Function(master: I, private val function: () -> Unit): Component(master) { - fun run() = function.invoke() - } - - /** - * @param The type the function should return - */ - open class Returnable(master: I, private val returnableFunction: () -> T): Component(master) { - fun get(): T = returnableFunction.invoke() - } - - /** - * @param The type the function takes as a parameter - */ - open class Parameterized(master: I, private val parameterizedFunction: (T) -> Unit): Component(master) { - fun run(parameter: T) = parameterizedFunction.invoke(parameter) - } - - /** - * @param The event the listener should listen to - */ - open class Listener(master: I, @field:EventHandler private val eventListener: EventListener): Component(master) - - open class Settings(master: I, val pathName: String): Component(master) { - val settings: SettingGroup = master.settings.addGroup(pathName) - } + init { + master.addComponent(this) + } + + open class Function(master: I, private val function: () -> Unit): Component(master) { + fun run() = function.invoke() + } + + /** + * @param The type the function should return + */ + open class Returnable(master: I, private val returnableFunction: () -> T): Component(master) { + fun get(): T = returnableFunction.invoke() + } + + /** + * @param The type the function takes as a parameter + */ + open class Parameterized(master: I, private val parameterizedFunction: (T) -> Unit): Component(master) { + fun run(parameter: T) = parameterizedFunction.invoke(parameter) + } + + /** + * @param The event the listener should listen to + */ + open class Listener(master: I, @field:EventHandler private val eventListener: EventListener): Component(master) + + open class Settings(master: I, val pathName: String): Component(master) { + val settings: SettingGroup = master.settings.addGroup(pathName) + } } \ No newline at end of file diff --git a/src/main/kotlin/org/aresclient/ares/api/instruments/Global.kt b/src/main/kotlin/org/aresclient/ares/api/instruments/Global.kt index 7f8ee4b1..054ca3ea 100644 --- a/src/main/kotlin/org/aresclient/ares/api/instruments/Global.kt +++ b/src/main/kotlin/org/aresclient/ares/api/instruments/Global.kt @@ -7,60 +7,61 @@ import org.aresclient.ares.Ares * modules but do not themselves directly do anything, and also holds related utility * functions to the purpose of the Global */ -abstract class Global(name:String, description:String +abstract class Global( + name: String, description: String ): Instrument(name, description, SETTINGS) { - companion object { - private val SETTINGS = Ares.SETTINGS.addGroup("Globals") - } + companion object { + private val SETTINGS = Ares.SETTINGS.addGroup("Globals") + } - abstract class PriorityHandler(name: String, description: String): Global(name, description) { - protected val keys: HashSet = HashSet() + abstract class PriorityHandler(name: String, description: String): Global(name, description) { + protected val keys: HashSet = HashSet() - fun begin(key: K): Boolean { - if (keys.isNotEmpty()) { - if (!keys.contains(key)) keys.add(key) - return hasPriority(key) - } + fun begin(key: K): Boolean { + if(keys.isNotEmpty()) { + if(!keys.contains(key)) keys.add(key) + return hasPriority(key) + } - keys.add(key) - begin() + keys.add(key) + begin() - return true - } + return true + } - protected abstract fun begin() + protected abstract fun begin() - fun end(key: K) { - if (keys.contains(key)) keys.remove(key) - if (keys.isEmpty()) end() - } + fun end(key: K) { + if(keys.contains(key)) keys.remove(key) + if(keys.isEmpty()) end() + } - protected abstract fun end() + protected abstract fun end() - fun isActive(key: K): Boolean = keys.contains(key) + fun isActive(key: K): Boolean = keys.contains(key) - fun hasPriority(key: K): Boolean = key == getCurrent() + fun hasPriority(key: K): Boolean = key == getCurrent() - fun getCurrent(): K? { - var key: K? = null - keys.forEach { - if (key == null) { - key = it - return@forEach - } + fun getCurrent(): K? { + var key: K? = null + keys.forEach { + if(key == null) { + key = it + return@forEach + } - if (key!!.priority() < it.priority()) key = it - } - return key - } - } + if(key!!.priority() < it.priority()) key = it + } + return key + } + } } interface Prioritizer { - fun priority(): Int - fun interruptor(): Boolean = false - fun onInterrupt() {} + fun priority(): Int + fun interruptor(): Boolean = false + fun onInterrupt() {} } diff --git a/src/main/kotlin/org/aresclient/ares/api/instruments/Instrument.kt b/src/main/kotlin/org/aresclient/ares/api/instruments/Instrument.kt index 2bf80754..38b91321 100644 --- a/src/main/kotlin/org/aresclient/ares/api/instruments/Instrument.kt +++ b/src/main/kotlin/org/aresclient/ares/api/instruments/Instrument.kt @@ -4,33 +4,33 @@ import org.aresclient.ares.api.Wrapper import org.aresclient.ares.api.setting.SettingGroup abstract class Instrument(val name: String, val description: String, parentSettings: SettingGroup): Wrapper { - private val components = ArrayList>() - val settings = parentSettings.addGroup(name, description) - - open fun tick() { - } - - internal fun addComponent(component: Component<*>) { - components.add(component) - } - - open fun registerEvents() { - EVENTS.register(this) - EVENTS.register(javaClass) - - components.forEach { - EVENTS.register(it) - EVENTS.register(it.javaClass) - } - } - - open fun unregisterEvents() { - EVENTS.unregister(this) - EVENTS.unregister(javaClass) - - components.forEach { - EVENTS.unregister(it) - EVENTS.unregister(it.javaClass) - } - } + private val components = ArrayList>() + val settings = parentSettings.addGroup(name, description) + + open fun tick() { + } + + internal fun addComponent(component: Component<*>) { + components.add(component) + } + + open fun registerEvents() { + EVENTS.register(this) + EVENTS.register(javaClass) + + components.forEach { + EVENTS.register(it) + EVENTS.register(it.javaClass) + } + } + + open fun unregisterEvents() { + EVENTS.unregister(this) + EVENTS.unregister(javaClass) + + components.forEach { + EVENTS.unregister(it) + EVENTS.unregister(it.javaClass) + } + } } diff --git a/src/main/kotlin/org/aresclient/ares/api/instruments/Module.kt b/src/main/kotlin/org/aresclient/ares/api/instruments/Module.kt index e34a819b..c5dec3cf 100644 --- a/src/main/kotlin/org/aresclient/ares/api/instruments/Module.kt +++ b/src/main/kotlin/org/aresclient/ares/api/instruments/Module.kt @@ -5,138 +5,150 @@ import org.aresclient.ares.api.events.ToggleEvent import org.aresclient.ares.api.render.MatrixStack import org.aresclient.ares.api.render.Renderer import org.aresclient.ares.api.render.Texture -import org.aresclient.ares.api.setting.settings.EnumSetting import org.aresclient.ares.api.setting.settings.BindSetting import org.aresclient.ares.api.setting.settings.BooleanSetting +import org.aresclient.ares.api.setting.settings.EnumSetting import java.util.* abstract class Module(val category: Category, name: String, description: String, private val defaults: Defaults = Defaults()): - Instrument(name, description, category.settings) { - companion object { - internal val SETTINGS = Ares.SETTINGS.addGroup("Modules") - } - - /* ---------------------------------------------------------------------- */ - - enum class Category { - PLAYER, - OFFENSE, - DEFENSE, - MOVEMENT, - RENDER, - HUD, - MISC; - - companion object { - fun getAll(): List = entries - } - - val prettyName = name.lowercase().replaceFirstChar { it.titlecase(Locale.getDefault()) } - val settings = SETTINGS.addGroup(prettyName) - val modules = ArrayList() - - val icon by lazy { - Texture(this::class.java.getResourceAsStream( - "/assets/ares/textures/icons/categories/" + name.lowercase() + ".png" - )!!, false) - } - } - - enum class ToggleOn { PRESS, RELEASE, HOLD } - class Defaults { - internal var enabled = false - internal var bind = -1 - internal var toggleOn = ToggleOn.PRESS - internal var alwaysListening = false - - fun setEnabled(value: Boolean): Defaults { enabled = value; return this } - fun setBind(value: Int): Defaults { bind = value; return this } - fun setToggleOn(value: ToggleOn): Defaults { toggleOn = value; return this } - fun setAlwaysListening(value: Boolean): Defaults { alwaysListening = value; return this } - } - - /* ---------------------------------------------------------------------- */ - - private val enabled = settings - .addBoolean("Enabled", defaults.enabled) - .addListener { value: Boolean -> - if(value) { - if(!defaults.alwaysListening) registerEvents() - onEnable() - EVENTS.post(ToggleEvent(this, true)) - } - else { - if(!defaults.alwaysListening) unregisterEvents() - onDisable() - EVENTS.post(ToggleEvent(this, false)) - } - } as BooleanSetting - - private val bind: BindSetting = settings - .addBind("Bind", defaults.bind) - .setCallback { state: Boolean, repeat: Boolean -> - val toggle = toggleOn.value - if (toggle == ToggleOn.PRESS && state && !repeat) toggle(); - else if (toggle == ToggleOn.RELEASE && !state) toggle(); - else if (toggle == ToggleOn.HOLD && !repeat) setEnabled(state); - } - - private val toggleOn: EnumSetting = settings.addEnum("Toggle On", defaults.toggleOn) - - init { - category.modules.add(this) - } - - /* ---------------------------------------------------------------------- */ - - fun isEnabled(): Boolean = enabled.value - fun setEnabled(value: Boolean) { - enabled.value = value - } - - fun getBind() = bind.value - fun setBind(value: Int) { - bind.value = value - } - - fun getToggleOn() = toggleOn.value - fun setToggleOn(value: ToggleOn) { - toggleOn.value = value - } - - /* ---------------------------------------------------------------------- */ - - fun toggle() = setEnabled(!isEnabled()) - fun isListening() = isEnabled() || defaults.alwaysListening - - override fun registerEvents() = if (isListening()) super.registerEvents() else Unit - override fun unregisterEvents() = if(!isListening()) super.unregisterEvents() else Unit - - /* ---------------------------------------------------------------------- */ - - override fun tick() { - if(isListening()) onTick() - } - - fun motion() { - if(isListening()) onMotion() - } - - fun renderHud(delta: Float, buffers: Renderer.Buffers, matrixStack: MatrixStack) { - if (isListening()) onRenderHud(delta, buffers, matrixStack) - } - - fun renderWorld(delta: Float, state: Renderer.State) { - if (isListening()) onRenderWorld(delta, state) - } - - /* ---------------------------------------------------------------------- */ - - protected open fun onTick() {} - protected open fun onMotion() {} - protected open fun onRenderHud(delta: Float, buffers: Renderer.Buffers, matrixStack: MatrixStack) {} - protected open fun onRenderWorld(delta: Float, renderer: Renderer.State) {} - - protected open fun onEnable() {} - protected open fun onDisable() {} + Instrument(name, description, category.settings) { + companion object { + internal val SETTINGS = Ares.SETTINGS.addGroup("Modules") + } + + /* ---------------------------------------------------------------------- */ + + enum class Category { + PLAYER, + OFFENSE, + DEFENSE, + MOVEMENT, + RENDER, + HUD, + MISC; + + companion object { + fun getAll(): List = entries + } + + val prettyName = name.lowercase().replaceFirstChar { it.titlecase(Locale.getDefault()) } + val settings = SETTINGS.addGroup(prettyName) + val modules = ArrayList() + + val icon by lazy { + Texture( + this::class.java.getResourceAsStream( + "/assets/ares/textures/icons/categories/" + name.lowercase() + ".png" + )!!, false + ) + } + } + + enum class ToggleOn { PRESS, RELEASE, HOLD } + class Defaults { + internal var enabled = false + internal var bind = -1 + internal var toggleOn = ToggleOn.PRESS + internal var alwaysListening = false + + fun setEnabled(value: Boolean): Defaults { + enabled = value; return this + } + + fun setBind(value: Int): Defaults { + bind = value; return this + } + + fun setToggleOn(value: ToggleOn): Defaults { + toggleOn = value; return this + } + + fun setAlwaysListening(value: Boolean): Defaults { + alwaysListening = value; return this + } + } + + /* ---------------------------------------------------------------------- */ + + private val enabled = settings + .addBoolean("Enabled", defaults.enabled) + .addListener { value: Boolean -> + if(value) { + if(!defaults.alwaysListening) registerEvents() + onEnable() + EVENTS.post(ToggleEvent(this, true)) + } else { + if(!defaults.alwaysListening) unregisterEvents() + onDisable() + EVENTS.post(ToggleEvent(this, false)) + } + } as BooleanSetting + + private val bind: BindSetting = settings + .addBind("Bind", defaults.bind) + .setCallback { state: Boolean, repeat: Boolean -> + val toggle = toggleOn.value + if(toggle == ToggleOn.PRESS && state && !repeat) toggle() + else if(toggle == ToggleOn.RELEASE && !state) toggle() + else if(toggle == ToggleOn.HOLD && !repeat) setEnabled(state) + } + + private val toggleOn: EnumSetting = settings.addEnum("Toggle On", defaults.toggleOn) + + init { + category.modules.add(this) + } + + /* ---------------------------------------------------------------------- */ + + fun isEnabled(): Boolean = enabled.value + fun setEnabled(value: Boolean) { + enabled.value = value + } + + fun getBind() = bind.value + fun setBind(value: Int) { + bind.value = value + } + + fun getToggleOn() = toggleOn.value + fun setToggleOn(value: ToggleOn) { + toggleOn.value = value + } + + /* ---------------------------------------------------------------------- */ + + fun toggle() = setEnabled(!isEnabled()) + fun isListening() = isEnabled() || defaults.alwaysListening + + override fun registerEvents() = if(isListening()) super.registerEvents() else Unit + override fun unregisterEvents() = if(!isListening()) super.unregisterEvents() else Unit + + /* ---------------------------------------------------------------------- */ + + override fun tick() { + if(isListening()) onTick() + } + + fun motion() { + if(isListening()) onMotion() + } + + fun renderHud(delta: Float, buffers: Renderer.Buffers, matrixStack: MatrixStack) { + if(isListening()) onRenderHud(delta, buffers, matrixStack) + } + + fun renderWorld(delta: Float, state: Renderer.State) { + if(isListening()) onRenderWorld(delta, state) + } + + /* ---------------------------------------------------------------------- */ + + protected open fun onTick() {} + protected open fun onMotion() {} + protected open fun onRenderHud(delta: Float, buffers: Renderer.Buffers, matrixStack: MatrixStack) {} + protected open fun onRenderWorld(delta: Float, renderer: Renderer.State) {} + + protected open fun onEnable() {} + protected open fun onDisable() {} } diff --git a/src/main/kotlin/org/aresclient/ares/api/render/BlurFramebuffer.java b/src/main/kotlin/org/aresclient/ares/api/render/BlurFramebuffer.java index c5310dd6..a900de4d 100644 --- a/src/main/kotlin/org/aresclient/ares/api/render/BlurFramebuffer.java +++ b/src/main/kotlin/org/aresclient/ares/api/render/BlurFramebuffer.java @@ -13,7 +13,7 @@ public class BlurFramebuffer extends CustomFramebuffer { private static final Buffer BUFFER = Buffer .createStatic(SHADER, VertexFormat.POSITION_UV, 4, 6) .vertices( - 1, 1, 0, 1, 1, + 1, 1, 0, 1, 1, 1, -1, 0, 1, 0, -1, 1, 0, 0, 1, -1, -1, 0, 0, 0 diff --git a/src/main/kotlin/org/aresclient/ares/api/render/Renderer.java b/src/main/kotlin/org/aresclient/ares/api/render/Renderer.java index 776a8b66..4a70c220 100644 --- a/src/main/kotlin/org/aresclient/ares/api/render/Renderer.java +++ b/src/main/kotlin/org/aresclient/ares/api/render/Renderer.java @@ -155,7 +155,7 @@ private static State begin(MatrixStack matrixStack) { GpuTexture gpuTexture = framebuffer.getColorAttachment(); GpuTexture gpuTexture2 = framebuffer.getDepthAttachment(); GlStateManager._glBindFramebuffer(GlConst.GL_FRAMEBUFFER, - ((GlTexture)gpuTexture).getOrCreateFramebuffer(((GlBackend) RenderSystem.getDevice()).getFramebufferManager(), gpuTexture2)); + ((GlTexture) gpuTexture).getOrCreateFramebuffer(((GlBackend) RenderSystem.getDevice()).getFramebufferManager(), gpuTexture2)); GlStateManager._viewport(0, 0, gpuTexture.getWidth(0), gpuTexture.getHeight(0)); State state = new State( diff --git a/src/main/kotlin/org/aresclient/ares/api/render/StencilFramebuffer.java b/src/main/kotlin/org/aresclient/ares/api/render/StencilFramebuffer.java index a3caab1b..a484f18b 100644 --- a/src/main/kotlin/org/aresclient/ares/api/render/StencilFramebuffer.java +++ b/src/main/kotlin/org/aresclient/ares/api/render/StencilFramebuffer.java @@ -9,7 +9,7 @@ public class StencilFramebuffer extends CustomFramebuffer { private static final Buffer BUFFER = Buffer .createStatic(Shader.POSITION_TEXTURE, VertexFormat.POSITION_UV, 4, 6) .vertices( - 1, 1, 0, 1, 1, + 1, 1, 0, 1, 1, 1, -1, 0, 1, 0, -1, 1, 0, 0, 1, -1, -1, 0, 0, 0 diff --git a/src/main/kotlin/org/aresclient/ares/api/render/Texture.java b/src/main/kotlin/org/aresclient/ares/api/render/Texture.java index af65246c..680a78ef 100644 --- a/src/main/kotlin/org/aresclient/ares/api/render/Texture.java +++ b/src/main/kotlin/org/aresclient/ares/api/render/Texture.java @@ -62,8 +62,8 @@ public static ByteBuffer readImage(BufferedImage image) { // allocate buffer to create color data ByteBuffer buffer = BufferUtils.createByteBuffer(image.getWidth() * image.getHeight() * 4); - for(int y = 0; y < image.getHeight(); y++){ - for(int x = 0; x < image.getWidth(); x++){ + for(int y = 0; y < image.getHeight(); y++) { + for(int x = 0; x < image.getWidth(); x++) { int pixel = pixels[y * image.getWidth() + x]; buffer.put((byte) ((pixel >> 16) & 0xFF)); buffer.put((byte) ((pixel >> 8) & 0xFF)); diff --git a/src/main/kotlin/org/aresclient/ares/api/render/Uniform.java b/src/main/kotlin/org/aresclient/ares/api/render/Uniform.java index f70947ec..8742090d 100644 --- a/src/main/kotlin/org/aresclient/ares/api/render/Uniform.java +++ b/src/main/kotlin/org/aresclient/ares/api/render/Uniform.java @@ -11,6 +11,7 @@ public abstract class Uniform { private static boolean LEGACY; + static { try { GL20.class.getDeclaredMethod("glUniformMatrix4fv", int.class, boolean.class, float[].class); @@ -266,6 +267,7 @@ protected void uniform() { public static class Mat2f extends Uniform { private static Method LEGACY_METHOD; + static { try { LEGACY_METHOD = GL20.class.getMethod("glUniformMatrix2", int.class, boolean.class, FloatBuffer.class); @@ -306,6 +308,7 @@ protected void uniform() { public static class Mat3f extends Uniform { private static Method LEGACY_METHOD; + static { try { LEGACY_METHOD = GL20.class.getMethod("glUniformMatrix3", int.class, boolean.class, FloatBuffer.class); @@ -346,6 +349,7 @@ protected void uniform() { public static class Mat3x2f extends Uniform { private static Method LEGACY_METHOD; + static { try { LEGACY_METHOD = GL21.class.getMethod("glUniformMatrix3x2", int.class, boolean.class, FloatBuffer.class); @@ -386,6 +390,7 @@ protected void uniform() { public static class Mat4f extends Uniform { private static Method LEGACY_METHOD; + static { try { LEGACY_METHOD = GL20.class.getMethod("glUniformMatrix4", int.class, boolean.class, FloatBuffer.class); @@ -430,6 +435,7 @@ static void uniform(int id, Matrix4f value) { public static class Mat4x3f extends Uniform { private static Method LEGACY_METHOD; + static { try { LEGACY_METHOD = GL21.class.getMethod("glUniformMatrix4x3", int.class, boolean.class, FloatBuffer.class); @@ -469,7 +475,7 @@ protected void uniform() { } private final String name; - private final Shader shader; + private final Shader shader; protected final int id; protected boolean dirty = false; diff --git a/src/main/kotlin/org/aresclient/ares/api/render/VertexFormat.java b/src/main/kotlin/org/aresclient/ares/api/render/VertexFormat.java index f603a88c..b0c2267b 100644 --- a/src/main/kotlin/org/aresclient/ares/api/render/VertexFormat.java +++ b/src/main/kotlin/org/aresclient/ares/api/render/VertexFormat.java @@ -71,7 +71,7 @@ void use() { int i = 0; long p = 0; for(Vertex vertex: vertices) { - GL20.glVertexAttribPointer(i, vertex.len, vertex.type.gl, false, stride, p); + GL20.glVertexAttribPointer(i, vertex.len, vertex.type.gl, false, stride, p); GL20.glEnableVertexAttribArray(i++); p += (long) vertex.len * vertex.type.size; } @@ -158,7 +158,7 @@ public ByteBuffer build() { } } } - return (ByteBuffer) buffer.flip(); + return buffer.flip(); } } } diff --git a/src/main/kotlin/org/aresclient/ares/api/setting/Setting.java b/src/main/kotlin/org/aresclient/ares/api/setting/Setting.java index 92b18546..4b24e0b1 100644 --- a/src/main/kotlin/org/aresclient/ares/api/setting/Setting.java +++ b/src/main/kotlin/org/aresclient/ares/api/setting/Setting.java @@ -1,146 +1,147 @@ package org.aresclient.ares.api.setting; import com.google.gson.Gson; -import com.google.gson.GsonBuilder; import com.google.gson.JsonElement; import com.google.gson.JsonSyntaxException; import org.aresclient.ares.api.setting.settings.ListSetting; -import org.jetbrains.annotations.NotNull; -import java.io.*; -import java.util.*; +import java.io.File; +import java.io.FileReader; +import java.io.FileWriter; +import java.io.IOException; +import java.util.ArrayList; import java.util.function.Consumer; import java.util.function.Supplier; public abstract class Setting { - public enum Type { - STRING, BOOLEAN, ENUM, - COLOR, INTEGER, DOUBLE, - FLOAT, LONG, BIND, - LIST, MAP - } - - private static final Gson GSON = new Gson(); - - private Setting parent = null; - private java.lang.String name = null; - private java.lang.String[] description = null; - private Supplier visible = () -> true; - private final java.util.List> listeners = new ArrayList<>(); - - private final Type type; - private final T defaultValue; - private T value; - - protected Setting(Type type, T value) { - this.type = type; - this.defaultValue = value; - this.value = value; - } - - public abstract void read(JsonElement jsonElement); - - public void read(String json) throws JsonSyntaxException { - read(GSON.fromJson(json, JsonElement.class)); - } - - public void read(File file) throws IOException { - FileReader fileReader = new FileReader(file); - read(GSON.fromJson(fileReader, JsonElement.class)); - fileReader.close(); - } - - public abstract JsonElement write(); - - public void write(File file) throws IOException { - FileWriter fileWriter = new FileWriter(file); - GSON.toJson(write(), fileWriter); - fileWriter.close(); - } - - public String writeToString() { - return GSON.toJson(write()); - } - - public Setting getParent() { - return parent; - } - - public void setParent(Setting parent) { - this.parent = parent; - } - - public String getName() { - if(getParent() instanceof ListSetting) - return java.lang.String.valueOf(((ListSetting) getParent()).indexOf((SettingGroup) this)); - return name; - } - - public Setting setName(String name) { - this.name = name; - return this; - } - - public String getPath() { - String prefix = null; - if(getParent() != null) prefix = getParent().getPath(); - return prefix == null ? getName() : prefix + ":" + getName(); - } - - public String[] getDescription() { - return description; - } - - public Setting setDescription(String... description) { - this.description = description; - return this; - } - - public java.lang.Boolean isVisible() { - return visible.get(); - } - - public Setting setVisibility(Supplier hidden) { - this.visible = hidden; - return this; - } - - public Setting addListener(Consumer listener) { - listeners.add(listener); - return this; - } - - public Setting removeListener(Consumer listener) { - listeners.remove(listener); - return this; - } - - public java.util.List> getListeners() { - return listeners; - } - - public Type getType() { - return type; - } - - public T getValue() { - return value; - } - - public void setValue(T value) { - T prev = this.value; - this.value = value; - if(prev != value) - for(Consumer consumer: listeners) - consumer.accept(value); - } - - public void setDefault() { - this.value = defaultValue; - } - - @Override - public java.lang.String toString() { - return "Setting(type: " + type.name() + ", value: " + value.toString() + ", name: " + (name == null ? "" : name) + ")"; - } + public enum Type { + STRING, BOOLEAN, ENUM, + COLOR, INTEGER, DOUBLE, + FLOAT, LONG, BIND, + LIST, MAP + } + + private static final Gson GSON = new Gson(); + + private Setting parent = null; + private java.lang.String name = null; + private java.lang.String[] description = null; + private Supplier visible = () -> true; + private final java.util.List> listeners = new ArrayList<>(); + + private final Type type; + private final T defaultValue; + private T value; + + protected Setting(Type type, T value) { + this.type = type; + this.defaultValue = value; + this.value = value; + } + + public abstract void read(JsonElement jsonElement); + + public void read(String json) throws JsonSyntaxException { + read(GSON.fromJson(json, JsonElement.class)); + } + + public void read(File file) throws IOException { + FileReader fileReader = new FileReader(file); + read(GSON.fromJson(fileReader, JsonElement.class)); + fileReader.close(); + } + + public abstract JsonElement write(); + + public void write(File file) throws IOException { + FileWriter fileWriter = new FileWriter(file); + GSON.toJson(write(), fileWriter); + fileWriter.close(); + } + + public String writeToString() { + return GSON.toJson(write()); + } + + public Setting getParent() { + return parent; + } + + public void setParent(Setting parent) { + this.parent = parent; + } + + public String getName() { + if(getParent() instanceof ListSetting) + return java.lang.String.valueOf(((ListSetting) getParent()).indexOf((SettingGroup) this)); + return name; + } + + public Setting setName(String name) { + this.name = name; + return this; + } + + public String getPath() { + String prefix = null; + if(getParent() != null) prefix = getParent().getPath(); + return prefix == null ? getName() : prefix + ":" + getName(); + } + + public String[] getDescription() { + return description; + } + + public Setting setDescription(String... description) { + this.description = description; + return this; + } + + public java.lang.Boolean isVisible() { + return visible.get(); + } + + public Setting setVisibility(Supplier hidden) { + this.visible = hidden; + return this; + } + + public Setting addListener(Consumer listener) { + listeners.add(listener); + return this; + } + + public Setting removeListener(Consumer listener) { + listeners.remove(listener); + return this; + } + + public java.util.List> getListeners() { + return listeners; + } + + public Type getType() { + return type; + } + + public T getValue() { + return value; + } + + public void setValue(T value) { + T prev = this.value; + this.value = value; + if(prev != value) + for(Consumer consumer: listeners) + consumer.accept(value); + } + + public void setDefault() { + this.value = defaultValue; + } + + @Override + public java.lang.String toString() { + return "Setting(type: " + type.name() + ", value: " + value.toString() + ", name: " + (name == null ? "" : name) + ")"; + } } diff --git a/src/main/kotlin/org/aresclient/ares/api/setting/settings/EnumSetting.java b/src/main/kotlin/org/aresclient/ares/api/setting/settings/EnumSetting.java index 30646634..a634f764 100644 --- a/src/main/kotlin/org/aresclient/ares/api/setting/settings/EnumSetting.java +++ b/src/main/kotlin/org/aresclient/ares/api/setting/settings/EnumSetting.java @@ -17,8 +17,8 @@ public EnumSetting(T value) { @Override public void setValue(T value) { - for (java.util.Map.Entry, String>> restriction : restrictions.entrySet()) { - if (value == restriction.getKey() && restriction.getValue().getFirst().get()) { + for(java.util.Map.Entry, String>> restriction: restrictions.entrySet()) { + if(value == restriction.getKey() && restriction.getValue().getFirst().get()) { // TODO: Error Message - "Error setting Enum value: " + restriction.getValue().getSecond() return; } diff --git a/src/main/kotlin/org/aresclient/ares/api/setting/settings/number/DoubleSetting.java b/src/main/kotlin/org/aresclient/ares/api/setting/settings/number/DoubleSetting.java index 989cf468..7a833508 100644 --- a/src/main/kotlin/org/aresclient/ares/api/setting/settings/number/DoubleSetting.java +++ b/src/main/kotlin/org/aresclient/ares/api/setting/settings/number/DoubleSetting.java @@ -10,7 +10,7 @@ public DoubleSetting(Double value) { @Override public void setValue(Double value) { - if (getPrecision() != null) { + if(getPrecision() != null) { int scale = (int) Math.pow(10, getPrecision()); value = (double) Math.round(value * scale) / scale; } diff --git a/src/main/kotlin/org/aresclient/ares/api/setting/settings/number/FloatSetting.java b/src/main/kotlin/org/aresclient/ares/api/setting/settings/number/FloatSetting.java index 3e88ee4f..9da3e3e8 100644 --- a/src/main/kotlin/org/aresclient/ares/api/setting/settings/number/FloatSetting.java +++ b/src/main/kotlin/org/aresclient/ares/api/setting/settings/number/FloatSetting.java @@ -10,7 +10,7 @@ public FloatSetting(Float value) { @Override public void setValue(Float value) { - if (getPrecision() != null) { + if(getPrecision() != null) { int scale = (int) Math.pow(10, getPrecision()); value = (float) Math.round(value * scale) / scale; } diff --git a/src/main/kotlin/org/aresclient/ares/api/setting/settings/number/IntegerSetting.java b/src/main/kotlin/org/aresclient/ares/api/setting/settings/number/IntegerSetting.java index 14259dfe..aafbace8 100644 --- a/src/main/kotlin/org/aresclient/ares/api/setting/settings/number/IntegerSetting.java +++ b/src/main/kotlin/org/aresclient/ares/api/setting/settings/number/IntegerSetting.java @@ -10,7 +10,7 @@ public IntegerSetting(Integer value) { @Override public void setValue(Integer value) { - if (getPrecision() != null) { + if(getPrecision() != null) { int scale = (int) Math.pow(10, getPrecision()); value = (int) Math.round(value.doubleValue() / scale) * scale; } diff --git a/src/main/kotlin/org/aresclient/ares/api/setting/settings/number/NumberSetting.java b/src/main/kotlin/org/aresclient/ares/api/setting/settings/number/NumberSetting.java index eb037744..7cff89d1 100644 --- a/src/main/kotlin/org/aresclient/ares/api/setting/settings/number/NumberSetting.java +++ b/src/main/kotlin/org/aresclient/ares/api/setting/settings/number/NumberSetting.java @@ -38,7 +38,7 @@ public java.lang.Integer getPrecision() { } public org.aresclient.ares.api.setting.settings.number.NumberSetting setPrecision(java.lang.Integer precision) { - if (this.getValue() instanceof java.lang.Double + if(this.getValue() instanceof java.lang.Double || this.getValue() instanceof java.lang.Float || this.getValue() instanceof java.lang.Integer) this.precision = precision; diff --git a/src/main/kotlin/org/aresclient/ares/api/util/Color.java b/src/main/kotlin/org/aresclient/ares/api/util/Color.java index 2e8b92e6..3d7fa031 100644 --- a/src/main/kotlin/org/aresclient/ares/api/util/Color.java +++ b/src/main/kotlin/org/aresclient/ares/api/util/Color.java @@ -4,154 +4,154 @@ import java.util.Objects; public class Color { - public static final Color BLACK = new Color(0, 0, 0, 1); - public static final Color GRAY = new Color(0.5f, 0.5f, 0.5f, 1); - public static final Color WHITE = new Color(1, 1, 1, 1); - public static final Color RED = new Color(1, 0, 0, 1); - public static final Color GREEN = new Color(0, 1, 0, 1); - public static final Color BLUE = new Color(0, 0, 1, 1); - public static final Color COLORLESS = new Color(0,0,0,0); - - private final float r; - private final float g; - private final float b; - private final float a; - - public Color(int rgb) { - this((float) (rgb >> 16) / 255.0F, (float) (rgb >> 8 & 255) / 255.0F, (float) (rgb & 255) / 255.0F, 1); - } - - public Color(float r, float g, float b, float a) { - this.r = r; - this.g = g; - this.b = b; - this.a = a; - } - - public static Color fromDistance(float distance) { - float fraction = distance > 50 ? 1 : distance / 50; - return fraction > 0.5d ? new Color(1 - (fraction - 0.5f) * 2, 1, 0, 1) : new Color(1, fraction * 2, 0, 1); - } - - public static int HSBtoRGB(float hue, float saturation, float brightness) { - if(saturation == 0) - return convert(brightness, brightness, brightness, 0); - if(saturation < 0 || saturation > 1 || brightness < 0 || brightness > 1) - throw new IllegalArgumentException(); - hue = hue - (float) Math.floor(hue); - int i = (int) (6 * hue); - float f = 6 * hue - i; - float p = brightness * (1 - saturation); - float q = brightness * (1 - saturation * f); - float t = brightness * (1 - saturation * (1 - f)); - switch(i) { - case 0: - return convert(brightness, t, p, 0); - case 1: - return convert(q, brightness, p, 0); - case 2: - return convert(p, brightness, t, 0); - case 3: - return convert(p, q, brightness, 0); - case 4: - return convert(t, p, brightness, 0); - case 5: - return convert(brightness, p, q, 0); - default: - throw new InternalError("impossible"); - } - } - - private static int convert(float red, float green, float blue, float alpha) { - if(red < 0 || red > 1 || green < 0 || green > 1 || blue < 0 || blue > 1 - || alpha < 0 || alpha > 1) - throw new IllegalArgumentException("Bad RGB values"); - int redval = Math.round(255 * red); - int greenval = Math.round(255 * green); - int blueval = Math.round(255 * blue); - int alphaval = Math.round(255 * alpha); - return (alphaval << 24) | (redval << 16) | (greenval << 8) | blueval; - } - - public float getRed() { - return r; - } - - public float getGreen() { - return g; - } - - public float getBlue() { - return b; - } - - public float getAlpha() { - return a; - } - - public Color deriveRed(float value) { - return new Color(value, g, b, a); - } - - public Color deriveGreen(float value) { - return new Color(r, value, b, a); - } - - public Color deriveBlue(float value) { - return new Color(r, g, value, a); - } - - public Color deriveAlpha(float value) { - return new Color(r, g, b, value); - } - - public int getRGB() { - return (((int) (getAlpha() * 255 + 0.5) & 0xFF) << 24) | - (((int) (getRed() * 255 + 0.5) & 0xFF) << 16) | - (((int) (getGreen() * 255 + 0.5) & 0xFF) << 8) | - (((int) (getBlue() * 255 + 0.5) & 0xFF)); - } - - public static Color rainbow() { - float hue = (System.currentTimeMillis() % (320 * 32)) / (320f * 32); - return new Color(Color.HSBtoRGB(hue, 1, 1)); - } - - public static Color rainbow(int speed, float offset, float saturation, float brightness) { - float hue = ((System.currentTimeMillis() % ((speed *10) *speed)) / ((speed *10f) *speed)) -offset; - float hue2 = hue; - if(hue<0) hue2 = 1f + hue; - return new Color(Color.HSBtoRGB(hue2, saturation, brightness)); - } - - public Color getColorBetween(Color color) { - return getColorBetween(new Color(r, g, b, a), color); - } - - public static Color getColorBetween(Color color1, Color color2) { - float - r = (color1.getRed() + color2.getRed()) /2, - g = (color1.getGreen() + color2.getGreen()) /2, - b = (color1.getBlue() + color2.getBlue()) /2, - a = (color1.getAlpha() + color2.getAlpha()) /2; - return new Color(r,g,b,a); - } - - @Override - public String toString() { - return Arrays.toString(new float[] { getRed(), getGreen(), getBlue(), getAlpha() }); - } - - @Override - public boolean equals(Object o) { - if(this == o) return true; - if(o == null || getClass() != o.getClass()) return false; - Color color = (Color) o; - return Float.compare(r, color.r) == 0 && Float.compare(g, color.g) == 0 && Float.compare(b, color.b) == 0 && Float.compare(a, color.a) == 0; - } - - @Override - public int hashCode() { - return Objects.hash(r, g, b, a); - } + public static final Color BLACK = new Color(0, 0, 0, 1); + public static final Color GRAY = new Color(0.5f, 0.5f, 0.5f, 1); + public static final Color WHITE = new Color(1, 1, 1, 1); + public static final Color RED = new Color(1, 0, 0, 1); + public static final Color GREEN = new Color(0, 1, 0, 1); + public static final Color BLUE = new Color(0, 0, 1, 1); + public static final Color COLORLESS = new Color(0, 0, 0, 0); + + private final float r; + private final float g; + private final float b; + private final float a; + + public Color(int rgb) { + this((float) (rgb >> 16) / 255.0F, (float) (rgb >> 8 & 255) / 255.0F, (float) (rgb & 255) / 255.0F, 1); + } + + public Color(float r, float g, float b, float a) { + this.r = r; + this.g = g; + this.b = b; + this.a = a; + } + + public static Color fromDistance(float distance) { + float fraction = distance > 50 ? 1 : distance / 50; + return fraction > 0.5d ? new Color(1 - (fraction - 0.5f) * 2, 1, 0, 1) : new Color(1, fraction * 2, 0, 1); + } + + public static int HSBtoRGB(float hue, float saturation, float brightness) { + if(saturation == 0) + return convert(brightness, brightness, brightness, 0); + if(saturation < 0 || saturation > 1 || brightness < 0 || brightness > 1) + throw new IllegalArgumentException(); + hue = hue - (float) Math.floor(hue); + int i = (int) (6 * hue); + float f = 6 * hue - i; + float p = brightness * (1 - saturation); + float q = brightness * (1 - saturation * f); + float t = brightness * (1 - saturation * (1 - f)); + switch(i) { + case 0: + return convert(brightness, t, p, 0); + case 1: + return convert(q, brightness, p, 0); + case 2: + return convert(p, brightness, t, 0); + case 3: + return convert(p, q, brightness, 0); + case 4: + return convert(t, p, brightness, 0); + case 5: + return convert(brightness, p, q, 0); + default: + throw new InternalError("impossible"); + } + } + + private static int convert(float red, float green, float blue, float alpha) { + if(red < 0 || red > 1 || green < 0 || green > 1 || blue < 0 || blue > 1 + || alpha < 0 || alpha > 1) + throw new IllegalArgumentException("Bad RGB values"); + int redval = Math.round(255 * red); + int greenval = Math.round(255 * green); + int blueval = Math.round(255 * blue); + int alphaval = Math.round(255 * alpha); + return (alphaval << 24) | (redval << 16) | (greenval << 8) | blueval; + } + + public float getRed() { + return r; + } + + public float getGreen() { + return g; + } + + public float getBlue() { + return b; + } + + public float getAlpha() { + return a; + } + + public Color deriveRed(float value) { + return new Color(value, g, b, a); + } + + public Color deriveGreen(float value) { + return new Color(r, value, b, a); + } + + public Color deriveBlue(float value) { + return new Color(r, g, value, a); + } + + public Color deriveAlpha(float value) { + return new Color(r, g, b, value); + } + + public int getRGB() { + return (((int) (getAlpha() * 255 + 0.5) & 0xFF) << 24) | + (((int) (getRed() * 255 + 0.5) & 0xFF) << 16) | + (((int) (getGreen() * 255 + 0.5) & 0xFF) << 8) | + (((int) (getBlue() * 255 + 0.5) & 0xFF)); + } + + public static Color rainbow() { + float hue = (System.currentTimeMillis() % (320 * 32)) / (320f * 32); + return new Color(Color.HSBtoRGB(hue, 1, 1)); + } + + public static Color rainbow(int speed, float offset, float saturation, float brightness) { + float hue = ((System.currentTimeMillis() % ((speed * 10) * speed)) / ((speed * 10f) * speed)) - offset; + float hue2 = hue; + if(hue < 0) hue2 = 1f + hue; + return new Color(Color.HSBtoRGB(hue2, saturation, brightness)); + } + + public Color getColorBetween(Color color) { + return getColorBetween(new Color(r, g, b, a), color); + } + + public static Color getColorBetween(Color color1, Color color2) { + float + r = (color1.getRed() + color2.getRed()) / 2, + g = (color1.getGreen() + color2.getGreen()) / 2, + b = (color1.getBlue() + color2.getBlue()) / 2, + a = (color1.getAlpha() + color2.getAlpha()) / 2; + return new Color(r, g, b, a); + } + + @Override + public String toString() { + return Arrays.toString(new float[] {getRed(), getGreen(), getBlue(), getAlpha()}); + } + + @Override + public boolean equals(Object o) { + if(this == o) return true; + if(o == null || getClass() != o.getClass()) return false; + Color color = (Color) o; + return Float.compare(r, color.r) == 0 && Float.compare(g, color.g) == 0 && Float.compare(b, color.b) == 0 && Float.compare(a, color.a) == 0; + } + + @Override + public int hashCode() { + return Objects.hash(r, g, b, a); + } } diff --git a/src/main/kotlin/org/aresclient/ares/impl/AresPlugin.kt b/src/main/kotlin/org/aresclient/ares/impl/AresPlugin.kt index 50003dcd..2ebd6714 100644 --- a/src/main/kotlin/org/aresclient/ares/impl/AresPlugin.kt +++ b/src/main/kotlin/org/aresclient/ares/impl/AresPlugin.kt @@ -2,7 +2,9 @@ package org.aresclient.ares.impl import org.aresclient.ares.api.Plugin import org.aresclient.ares.impl.instrument.commands.* -import org.aresclient.ares.impl.instrument.global.* +import org.aresclient.ares.impl.instrument.global.Camera +import org.aresclient.ares.impl.instrument.global.Interaction +import org.aresclient.ares.impl.instrument.global.Rotation import org.aresclient.ares.impl.instrument.module.modules.misc.ClickGUI import org.aresclient.ares.impl.instrument.module.modules.misc.MsgOnToggle import org.aresclient.ares.impl.instrument.module.modules.misc.TitleScreen @@ -16,44 +18,44 @@ import org.aresclient.ares.impl.instrument.module.modules.render.TestModule import org.aresclient.ares.impl.instrument.module.modules.render.Tracers object AresPlugin: Plugin( - "Ares", - "The main Ares utility mod plugin", - "3.0.0-SNAPSHOT", - "1.21.5", - arrayOf("Tigermouthbear", "Makrennel"), - globals = listOf( - Camera, - Interaction, - Rotation - ), - modules = listOf( - ClickGUI, - MsgOnToggle, - TitleScreen, + "Ares", + "The main Ares utility mod plugin", + "3.0.0-SNAPSHOT", + "1.21.5", + arrayOf("Tigermouthbear", "Makrennel"), + globals = listOf( + Camera, + Interaction, + Rotation + ), + modules = listOf( + ClickGUI, + MsgOnToggle, + TitleScreen, - Speed, + Speed, - CrystalAura, + CrystalAura, - AntiAFK, - Freecam, + AntiAFK, + Freecam, - ESP, - TestModule, - Tracers, - Fullbright - ), - commands = listOf( - EchoCommand, - HelpCommand, - SaveCommand, - LoadCommand, - SetCommand, - ResetCommand, - GetCommand, - ToggleCommand, - PrefixCommand, - FriendCommand, - ClearCommand - ) + ESP, + TestModule, + Tracers, + Fullbright + ), + commands = listOf( + EchoCommand, + HelpCommand, + SaveCommand, + LoadCommand, + SetCommand, + ResetCommand, + GetCommand, + ToggleCommand, + PrefixCommand, + FriendCommand, + ClearCommand + ) ) \ No newline at end of file diff --git a/src/main/kotlin/org/aresclient/ares/impl/gui/AresSkybox.kt b/src/main/kotlin/org/aresclient/ares/impl/gui/AresSkybox.kt index f19abc59..3ba6c609 100644 --- a/src/main/kotlin/org/aresclient/ares/impl/gui/AresSkybox.kt +++ b/src/main/kotlin/org/aresclient/ares/impl/gui/AresSkybox.kt @@ -11,12 +11,12 @@ object AresSkybox { fun update(width: Float, height: Float) { SKYBOX_STACK - .projection().setPerspective(1.5f, width / height, 0.1f, 2f) + .projection().setPerspective(1.5f, width / height, 0.1f, 2f) } fun draw(delta: Float) { SKYBOX.render(SKYBOX_STACK) SKYBOX_STACK - .model().rotate((0.0002 * delta).toFloat(), 0f, 1f, 0f) + .model().rotate((0.0002 * delta).toFloat(), 0f, 1f, 0f) } } \ No newline at end of file diff --git a/src/main/kotlin/org/aresclient/ares/impl/gui/game/AresClickGUI.kt b/src/main/kotlin/org/aresclient/ares/impl/gui/game/AresClickGUI.kt index 26bd12ed..605b372d 100644 --- a/src/main/kotlin/org/aresclient/ares/impl/gui/game/AresClickGUI.kt +++ b/src/main/kotlin/org/aresclient/ares/impl/gui/game/AresClickGUI.kt @@ -1,12 +1,12 @@ package org.aresclient.ares.impl.gui.game -import org.aresclient.ares.api.render.BlurFramebuffer import org.aresclient.ares.api.gui.ScreenElement -import org.aresclient.ares.impl.util.Theme +import org.aresclient.ares.api.render.BlurFramebuffer import org.aresclient.ares.api.render.MatrixStack import org.aresclient.ares.api.render.Renderer import org.aresclient.ares.api.setting.SettingGroup import org.aresclient.ares.impl.gui.AresSkybox +import org.aresclient.ares.impl.util.Theme class AresClickGUI(settings: SettingGroup): ScreenElement("Ares ClickGUI") { private val windowManager = WindowManager(settings.addList("Windows")) diff --git a/src/main/kotlin/org/aresclient/ares/impl/gui/game/NavigationBar.kt b/src/main/kotlin/org/aresclient/ares/impl/gui/game/NavigationBar.kt index 37ab703a..af6ffe08 100644 --- a/src/main/kotlin/org/aresclient/ares/impl/gui/game/NavigationBar.kt +++ b/src/main/kotlin/org/aresclient/ares/impl/gui/game/NavigationBar.kt @@ -3,17 +3,17 @@ package org.aresclient.ares.impl.gui.game import org.aresclient.ares.api.gui.Button import org.aresclient.ares.api.gui.StaticElement import org.aresclient.ares.api.instruments.Module -import org.aresclient.ares.impl.util.RenderHelper -import org.aresclient.ares.impl.util.RenderHelper.draw -import org.aresclient.ares.impl.util.Theme import org.aresclient.ares.api.render.MatrixStack import org.aresclient.ares.api.render.Renderer import org.aresclient.ares.api.render.Texture +import org.aresclient.ares.impl.util.RenderHelper +import org.aresclient.ares.impl.util.RenderHelper.draw +import org.aresclient.ares.impl.util.Theme val DEFAULT_ICON = Texture(NavigationBar::class.java.getResourceAsStream("/assets/ares/textures/icons/gears.png")) -class NavigationBar(private val windowManager:WindowManager, private val scale: Float): StaticElement() { +class NavigationBar(private val windowManager: WindowManager, private val scale: Float): StaticElement() { val padding = scale / 6f init { @@ -58,9 +58,11 @@ class NavigationBar(private val windowManager:WindowManager, private val scale: super.draw(theme, buffers, matrixStack, mouseX, mouseY, delta) } - private class NavButton(private val navigationBar:NavigationBar, index: Int, private val category: Module.Category?): - Button((navigationBar.scale - 12 + navigationBar.padding) * index + navigationBar.padding, (navigationBar.scale / 2) - (navigationBar.scale - 12) / 2, - navigationBar.scale - 12, navigationBar.scale - 12, clipping = Clipping.NONE) { + private class NavButton(private val navigationBar: NavigationBar, index: Int, private val category: Module.Category?): + Button( + (navigationBar.scale - 12 + navigationBar.padding) * index + navigationBar.padding, (navigationBar.scale / 2) - (navigationBar.scale - 12) / 2, + navigationBar.scale - 12, navigationBar.scale - 12, clipping = Clipping.NONE + ) { private var open = false diff --git a/src/main/kotlin/org/aresclient/ares/impl/gui/game/SettingElement.kt b/src/main/kotlin/org/aresclient/ares/impl/gui/game/SettingElement.kt index b5c76231..08d61b7a 100644 --- a/src/main/kotlin/org/aresclient/ares/impl/gui/game/SettingElement.kt +++ b/src/main/kotlin/org/aresclient/ares/impl/gui/game/SettingElement.kt @@ -3,40 +3,32 @@ package org.aresclient.ares.impl.gui.game import org.aresclient.ares.Ares import org.aresclient.ares.api.gui.Button import org.aresclient.ares.api.gui.DynamicElement -import org.aresclient.ares.impl.util.RenderHelper -import org.aresclient.ares.impl.util.RenderHelper.draw -import org.aresclient.ares.impl.util.Theme -import org.aresclient.ares.api.render.MatrixStack -import org.aresclient.ares.api.render.Renderer -import org.aresclient.ares.api.setting.Setting import org.aresclient.ares.api.gui.DynamicElementGroup import org.aresclient.ares.api.gui.ScreenElement import org.aresclient.ares.api.instruments.Module +import org.aresclient.ares.api.render.MatrixStack +import org.aresclient.ares.api.render.Renderer +import org.aresclient.ares.api.setting.Setting import org.aresclient.ares.api.setting.SettingGroup import org.aresclient.ares.api.setting.settings.* import org.aresclient.ares.api.setting.settings.number.DoubleSetting import org.aresclient.ares.api.setting.settings.number.FloatSetting import org.aresclient.ares.api.setting.settings.number.IntegerSetting import org.aresclient.ares.api.setting.settings.number.LongSetting -import org.aresclient.ares.impl.gui.game.setting.BindElement -import org.aresclient.ares.impl.gui.game.setting.BooleanElement -import org.aresclient.ares.impl.gui.game.setting.ColorElement -import org.aresclient.ares.impl.gui.game.setting.DoubleElement -import org.aresclient.ares.impl.gui.game.setting.EnumElement -import org.aresclient.ares.impl.gui.game.setting.FloatElement -import org.aresclient.ares.impl.gui.game.setting.IntElement -import org.aresclient.ares.impl.gui.game.setting.ListElement -import org.aresclient.ares.impl.gui.game.setting.LongElement -import org.aresclient.ares.impl.gui.game.setting.MapElement -import org.aresclient.ares.impl.gui.game.setting.StringElement +import org.aresclient.ares.impl.gui.game.setting.* +import org.aresclient.ares.impl.util.RenderHelper +import org.aresclient.ares.impl.util.RenderHelper.draw +import org.aresclient.ares.impl.util.Theme import java.util.concurrent.atomic.AtomicBoolean fun String.formatToPretty(): String = this.split('_').joinToString(separator = " ") { it.lowercase().replaceFirstChar { c -> c.uppercase() } } -class SettingsGroup(private val setting: Setting<*>, columns: Int, private val content:SettingsContent, private val skipEnabled: Boolean = false, - private val settingHeight: Float = 18f, visible: () -> Boolean = { true }, x: () -> Float = { 0f }, y: () -> Float = { 0f }, - width: () -> Float = { 0f }, height: () -> Float = { 0f }): DynamicElementGroup(columns, visible, x, y, width, height) { +class SettingsGroup( + private val setting: Setting<*>, columns: Int, private val content: SettingsContent, private val skipEnabled: Boolean = false, + private val settingHeight: Float = 18f, visible: () -> Boolean = { true }, x: () -> Float = { 0f }, y: () -> Float = { 0f }, + width: () -> Float = { 0f }, height: () -> Float = { 0f } +): DynamicElementGroup(columns, visible, x, y, width, height) { init { refresh() @@ -49,10 +41,12 @@ class SettingsGroup(private val setting: Setting<*>, columns: Int, private val c if(/*name.first() != '.' && */(!skipEnabled || name != "Enabled")) pushChild(content.createSettingElement(setting, settingHeight)) } + Setting.Type.COLOR -> pushChild(ColorElement.DropDown(setting as ColorSetting, settingHeight)) Setting.Type.LIST -> (setting as ListSetting).value.forEach { pushChild(content.createSettingElement(it, settingHeight)) } + else -> throw RuntimeException("Can't open setting of type ${setting.type.name} in window") } } @@ -61,7 +55,7 @@ class SettingsGroup(private val setting: Setting<*>, columns: Int, private val c class SettingsContent(settings: SettingGroup): WindowContent(settings) { private val name = settings.addString("setting", "") private val setting = Ares.SETTINGS.find(name.value) - private val group = SettingsGroup(setting, 1, this, width = this::getWidth) + private val group = SettingsGroup(setting, 1, this, width = this::getWidth) init { // set icon if category @@ -80,7 +74,7 @@ class SettingsContent(settings: SettingGroup): WindowContent(settings) { override fun getHeight() = group.getHeight() - fun createSettingElement(setting: Setting<*>, settingHeight: Float = 18f):SettingElement<*> = when(setting.type) { + fun createSettingElement(setting: Setting<*>, settingHeight: Float = 18f): SettingElement<*> = when(setting.type) { Setting.Type.BOOLEAN -> BooleanElement(setting as BooleanSetting, settingHeight) Setting.Type.ENUM -> EnumElement(setting as EnumSetting<*>, settingHeight) Setting.Type.BIND -> BindElement(setting as BindSetting, settingHeight) @@ -97,7 +91,7 @@ class SettingsContent(settings: SettingGroup): WindowContent(settings) { } open class SettingElement>(protected val setting: T, scale: Float, private val start: Float = 3f): DynamicElement(height = { scale }) { - protected val fontRenderer = RenderHelper.getFontRenderer(scale * 13f/18f) + protected val fontRenderer = RenderHelper.getFontRenderer(scale * 13f / 18f) private var prev = setting.value init { @@ -168,8 +162,10 @@ open class SettingElement>(protected val setting: T, scale: Float, } } - protected class SettingElementButton(private val element:SettingElement<*>, action: (Button) -> Unit): Button(0f, 0f, 0f, 0f, - action, Clipping.SCISSOR) { + protected class SettingElementButton(private val element: SettingElement<*>, action: (Button) -> Unit): Button( + 0f, 0f, 0f, 0f, + action, Clipping.SCISSOR + ) { override fun getWidth(): Float = element.getWidth() override fun getHeight(): Float = element.getHeight() @@ -178,10 +174,10 @@ open class SettingElement>(protected val setting: T, scale: Float, } protected abstract class SettingSubButton(scale: Float, action: (Button) -> Unit, size: Float = 0.7f, clipping: Clipping = Clipping.STENCIL): - Button(0f, scale * (1 - size) / 2f, scale * size, scale * size, action, clipping, 2) { + Button(0f, scale * (1 - size) / 2f, scale * size, scale * size, action, clipping, 2) { private val offset = (1f - size) / 2f - override fun getX(): Float = getParent()?.getWidth()?.let { it - getY() - getWidth() } ?: 0f + override fun getX(): Float = getParent()?.getWidth()?.let { it - getY() - getWidth() } ?: 0f } protected abstract class SettingSubToggleButton(scale: Float): SettingSubButton(scale, { @@ -228,6 +224,7 @@ open class SettingElement>(protected val setting: T, scale: Float, } private const val DROPDOWN_PADDING = 1f + abstract class DropDownSettingElement>(setting: T, private val scale: Float): SettingElement(setting, scale, scale) { protected var element: DynamicElement? = null set(value) { diff --git a/src/main/kotlin/org/aresclient/ares/impl/gui/game/Window.kt b/src/main/kotlin/org/aresclient/ares/impl/gui/game/Window.kt index 303df4f1..827c4258 100644 --- a/src/main/kotlin/org/aresclient/ares/impl/gui/game/Window.kt +++ b/src/main/kotlin/org/aresclient/ares/impl/gui/game/Window.kt @@ -4,14 +4,14 @@ import org.aresclient.ares.api.gui.Button import org.aresclient.ares.api.gui.DynamicElement import org.aresclient.ares.api.gui.Image import org.aresclient.ares.api.gui.StaticElement -import org.aresclient.ares.impl.util.RenderHelper -import org.aresclient.ares.impl.util.RenderHelper.draw -import org.aresclient.ares.impl.util.Theme import org.aresclient.ares.api.render.MatrixStack import org.aresclient.ares.api.render.Renderer import org.aresclient.ares.api.render.Texture import org.aresclient.ares.api.setting.SettingGroup import org.aresclient.ares.api.setting.settings.ListSetting +import org.aresclient.ares.impl.util.RenderHelper +import org.aresclient.ares.impl.util.RenderHelper.draw +import org.aresclient.ares.impl.util.Theme import java.util.concurrent.atomic.AtomicBoolean import kotlin.math.max import kotlin.math.min @@ -36,12 +36,12 @@ class WindowManager(private val settings: ListSetting): StaticElement() { }) } - fun close(window:WindowElement) { + fun close(window: WindowElement) { settings.remove(window.settings) getChildren().remove(window) } - fun float(window:WindowElement) { + fun float(window: WindowElement) { removeChild(window) pushChild(window) } @@ -66,7 +66,7 @@ abstract class WindowContent(internal val settings: SettingGroup): StaticElement override fun getWidth() = getParent()?.getWidth() ?: 0f } -class WindowElement(internal val settings: SettingGroup, private val windowManager:WindowManager): DynamicElement() { +class WindowElement(internal val settings: SettingGroup, private val windowManager: WindowManager): DynamicElement() { private val content = settings.addList("Content") private val x = settings.addFloat("x", 0f) private val y = settings.addFloat("y", 0f) @@ -97,7 +97,7 @@ class WindowElement(internal val settings: SettingGroup, private val windowManag content.value.lastOrNull()?.let { open(map = it) } } - private fun open(map: SettingGroup, defaults: SettingGroup.() -> Class? = {null}) { + private fun open(map: SettingGroup, defaults: SettingGroup.() -> Class? = { null }) { val data = map.addGroup("data") val default = defaults(data) val type = map.addString("class", default?.name ?: ErrorWindowContent::class.java.name) @@ -106,7 +106,7 @@ class WindowElement(internal val settings: SettingGroup, private val windowManag setWindow(Class.forName(type.value).constructors.firstOrNull()?.newInstance(data) as? WindowContent) } - fun open(defaults: SettingGroup.() -> Class? = {null}) { + fun open(defaults: SettingGroup.() -> Class? = { null }) { val map = SettingGroup() content.add(map) open(map, defaults) @@ -176,7 +176,7 @@ class WindowElement(internal val settings: SettingGroup, private val windowManag 1, 2, 3 ) } - }){ + }) { window?.render(theme, buffers, matrixStack, mouseX, mouseY, delta) } diff --git a/src/main/kotlin/org/aresclient/ares/impl/gui/game/setting/BindElement.kt b/src/main/kotlin/org/aresclient/ares/impl/gui/game/setting/BindElement.kt index 5966c29a..3b1721ef 100644 --- a/src/main/kotlin/org/aresclient/ares/impl/gui/game/setting/BindElement.kt +++ b/src/main/kotlin/org/aresclient/ares/impl/gui/game/setting/BindElement.kt @@ -2,9 +2,9 @@ package org.aresclient.ares.impl.gui.game.setting import dev.tigr.simpleevents.listener.EventListener import org.aresclient.ares.api.events.InputEvent -import org.aresclient.ares.impl.gui.game.SettingElement import org.aresclient.ares.api.setting.settings.BindSetting import org.aresclient.ares.api.util.Keys +import org.aresclient.ares.impl.gui.game.SettingElement import org.aresclient.ares.impl.gui.game.formatToPretty import java.util.concurrent.atomic.AtomicBoolean @@ -44,7 +44,7 @@ class BindElement(setting: BindSetting, height: Float): SettingElement(setting, scale) { private val button = ColorSelectButton(this, scale) @@ -46,7 +46,7 @@ class ColorElement(private val content:WindowContent, setting: ColorSetting, sca } } - private class RGBColorSelectElement(val element:DropDown, private val scale: Float): DynamicElement(height = { scale * 4 }) { + private class RGBColorSelectElement(val element: DropDown, private val scale: Float): DynamicElement(height = { scale * 4 }) { init { arrayOf( Slider(element, "Red", 0f, 1f, { element.setting.value.red }) { element.setting.setRed(it) }, @@ -76,7 +76,7 @@ class ColorElement(private val content:WindowContent, setting: ColorSetting, sca } } - private class RNBWColorSelectElement(val element:DropDown, scale: Float): DynamicElement(height = { scale }) { + private class RNBWColorSelectElement(val element: DropDown, scale: Float): DynamicElement(height = { scale }) { init { Slider(element, "Alpha", 0f, 1f, { element.setting.value.alpha }) { element.setting.setAlpha(it) }.also { it.setHeight(scale) @@ -85,8 +85,8 @@ class ColorElement(private val content:WindowContent, setting: ColorSetting, sca } } - private class ColorSelectButton(private val colorElement:ColorElement, scale: Float): SettingSubButton(scale, { - colorElement.open = !colorElement.open + private class ColorSelectButton(private val colorElement: ColorElement, scale: Float): SettingSubButton(scale, { + colorElement.open = !colorElement.open }, 0.5f) { override fun draw(theme: Theme, buffers: Renderer.Buffers, matrixStack: MatrixStack, mouseX: Int, mouseY: Int) { val size = getHeight() @@ -122,7 +122,7 @@ class ColorElement(private val content:WindowContent, setting: ColorSetting, sca } } - private class ColorSelector(private val element:DropDown, scale: Float): StaticElement(height = scale) { + private class ColorSelector(private val element: DropDown, scale: Float): StaticElement(height = scale) { init { pushChild(ColorSelectionTypeButton(this, "RGBA", false)) pushChild(ColorSelectionTypeButton(this, "RNBW", true)) @@ -130,10 +130,10 @@ class ColorElement(private val content:WindowContent, setting: ColorSetting, sca override fun getWidth() = getParent()?.getWidth() ?: 0f - private class ColorSelectionTypeButton(private val selector:ColorSelector, private val name: String, private val rainbow: Boolean): - Button(0f, 0f, 0f, 0f, { - selector.element.setting.isRainbow = rainbow - }, clipping = Clipping.SCISSOR) { + private class ColorSelectionTypeButton(private val selector: ColorSelector, private val name: String, private val rainbow: Boolean): + Button(0f, 0f, 0f, 0f, { + selector.element.setting.isRainbow = rainbow + }, clipping = Clipping.SCISSOR) { override fun draw(theme: Theme, buffers: Renderer.Buffers, matrixStack: MatrixStack, mouseX: Int, mouseY: Int) { val width = getWidth() val height = getHeight() @@ -167,7 +167,13 @@ class ColorElement(private val content:WindowContent, setting: ColorSetting, sca } val textWidth = selector.element.fontRenderer.getStringWidth(name) - selector.element.fontRenderer.drawString(matrixStack, name, width / 2f - textWidth / 2f, height / 2f - selector.element.fontRenderer.charHeight / 2f, theme.lightground.value) + selector.element.fontRenderer.drawString( + matrixStack, + name, + width / 2f - textWidth / 2f, + height / 2f - selector.element.fontRenderer.charHeight / 2f, + theme.lightground.value + ) } override fun getX() = (if(rainbow) 1f else 0f) * getWidth() @@ -176,8 +182,10 @@ class ColorElement(private val content:WindowContent, setting: ColorSetting, sca } } - private class Slider(private val element:DropDown, private val name: String, private val min: Float, private val max: Float, - private val get: () -> Float, private val set: (Float) -> Unit): StaticElement() { + private class Slider( + private val element: DropDown, private val name: String, private val min: Float, private val max: Float, + private val get: () -> Float, private val set: (Float) -> Unit + ): StaticElement() { private var holding = false override fun getWidth() = getParent()?.getWidth() ?: 0f diff --git a/src/main/kotlin/org/aresclient/ares/impl/gui/game/setting/EnumElement.kt b/src/main/kotlin/org/aresclient/ares/impl/gui/game/setting/EnumElement.kt index 77b6d9be..661be5c4 100644 --- a/src/main/kotlin/org/aresclient/ares/impl/gui/game/setting/EnumElement.kt +++ b/src/main/kotlin/org/aresclient/ares/impl/gui/game/setting/EnumElement.kt @@ -1,9 +1,9 @@ package org.aresclient.ares.impl.gui.game.setting -import org.aresclient.ares.api.render.MatrixStack -import org.aresclient.ares.api.render.Renderer import org.aresclient.ares.api.gui.Button import org.aresclient.ares.api.gui.DynamicElement +import org.aresclient.ares.api.render.MatrixStack +import org.aresclient.ares.api.render.Renderer import org.aresclient.ares.api.setting.settings.EnumSetting import org.aresclient.ares.impl.gui.game.DropDownSettingElement import org.aresclient.ares.impl.gui.game.formatToPretty @@ -27,7 +27,7 @@ class EnumElement>(setting: EnumSetting, scale: Float): DropDownSe override fun getSecondaryText() = text - class DropDown>(val element:EnumElement, scale: Float): DynamicElement() { + class DropDown>(val element: EnumElement, scale: Float): DynamicElement() { val fontRenderer = RenderHelper.getFontRenderer(scale * 0.87f) init { @@ -42,7 +42,7 @@ class EnumElement>(setting: EnumSetting, scale: Float): DropDownSe } } - class EnumSelector>(private val dropDown:DropDown, private val value: T): Button(0f, 0f, 0f, 0f, { + class EnumSelector>(private val dropDown: DropDown, private val value: T): Button(0f, 0f, 0f, 0f, { dropDown.element.setting.value = value }, Clipping.SCISSOR) { private val text = value.name.formatToPretty() diff --git a/src/main/kotlin/org/aresclient/ares/impl/gui/game/setting/ListElement.kt b/src/main/kotlin/org/aresclient/ares/impl/gui/game/setting/ListElement.kt index 4be84ff4..4fba9301 100644 --- a/src/main/kotlin/org/aresclient/ares/impl/gui/game/setting/ListElement.kt +++ b/src/main/kotlin/org/aresclient/ares/impl/gui/game/setting/ListElement.kt @@ -5,8 +5,8 @@ import org.aresclient.ares.impl.gui.game.DropDownSettingElement import org.aresclient.ares.impl.gui.game.SettingsContent import org.aresclient.ares.impl.gui.game.SettingsGroup -class ListElement(private val content:SettingsContent, setting: ListSetting, private val scale: Float): - DropDownSettingElement(setting, scale) { +class ListElement(private val content: SettingsContent, setting: ListSetting, private val scale: Float): + DropDownSettingElement(setting, scale) { init { pushChild(SettingElementButton(this) { content.getWindow()?.open { @@ -14,7 +14,7 @@ class ListElement(private val content:SettingsContent, setting: ListSetting, pri SettingsContent::class.java } }) - element = SettingsGroup(setting, 1, content, settingHeight = scale * 0.87f) + element = SettingsGroup(setting, 1, content, settingHeight = scale * 0.87f) } override fun change() { diff --git a/src/main/kotlin/org/aresclient/ares/impl/gui/game/setting/MapElement.kt b/src/main/kotlin/org/aresclient/ares/impl/gui/game/setting/MapElement.kt index ed7aa151..5229508f 100644 --- a/src/main/kotlin/org/aresclient/ares/impl/gui/game/setting/MapElement.kt +++ b/src/main/kotlin/org/aresclient/ares/impl/gui/game/setting/MapElement.kt @@ -10,7 +10,7 @@ import org.aresclient.ares.impl.gui.game.SettingsGroup import org.aresclient.ares.impl.util.Theme class MapElement(private val content: SettingsContent, setting: SettingGroup, scale: Float): - DropDownSettingElement(setting, scale) { + DropDownSettingElement(setting, scale) { private val enabled: Setting? = setting.value["Enabled"] as? BooleanSetting init { @@ -21,7 +21,7 @@ class MapElement(private val content: SettingsContent, setting: SettingGroup, sc SettingsContent::class.java } }) - element = SettingsGroup(setting, 1, content, enabled != null, scale * 0.87f) + element = SettingsGroup(setting, 1, content, enabled != null, scale * 0.87f) } override fun getTextColor(theme: Theme): ColorSetting = if(enabled?.value == true) theme.primary else theme.lightground diff --git a/src/main/kotlin/org/aresclient/ares/impl/gui/game/setting/NumberElement.kt b/src/main/kotlin/org/aresclient/ares/impl/gui/game/setting/NumberElement.kt index 5a3154f6..5e515b0d 100644 --- a/src/main/kotlin/org/aresclient/ares/impl/gui/game/setting/NumberElement.kt +++ b/src/main/kotlin/org/aresclient/ares/impl/gui/game/setting/NumberElement.kt @@ -1,11 +1,11 @@ package org.aresclient.ares.impl.gui.game.setting -import org.aresclient.ares.impl.gui.game.SettingElement -import org.aresclient.ares.impl.util.RenderHelper.draw -import org.aresclient.ares.impl.util.Theme import org.aresclient.ares.api.render.MatrixStack import org.aresclient.ares.api.render.Renderer import org.aresclient.ares.api.setting.settings.number.* +import org.aresclient.ares.impl.gui.game.SettingElement +import org.aresclient.ares.impl.util.RenderHelper.draw +import org.aresclient.ares.impl.util.Theme import java.util.concurrent.atomic.AtomicBoolean import kotlin.math.abs import kotlin.math.max @@ -15,7 +15,7 @@ import kotlin.math.min abstract class NumberElement(setting: NumberSetting, scale: Float): SettingElement>(setting, scale) { // 0 = max && min != null 1 = max && min == null // 2 = min == null 3 = max == null - protected val mode = if(setting.max == null || setting.min == null) (if(setting.min == null) (if(setting.max == null) 1 else 2) else 3 ) else 0 + protected val mode = if(setting.max == null || setting.min == null) (if(setting.min == null) (if(setting.max == null) 1 else 2) else 3) else 0 private var mouse = false private var time = 0L @@ -66,7 +66,7 @@ abstract class NumberElement(setting: NumberSetting, scale: Float) vertices( 0f, getHeight() - 2, 0f, 3f, theme.primary.value.red, theme.primary.value.green, theme.primary.value.blue, theme.primary.value.alpha, (setting.value.toFloat() - setting.min!!.toFloat()) / (setting.max!!.toFloat() - setting.min.toFloat()) * getWidth(), getHeight() - 2, 0f, 3f, - theme.primary.value.red, theme.primary.value.green, theme.primary.value.blue, theme.primary.value.alpha + theme.primary.value.red, theme.primary.value.green, theme.primary.value.blue, theme.primary.value.alpha ) indices(0, 1) } diff --git a/src/main/kotlin/org/aresclient/ares/impl/gui/game/setting/StringElement.kt b/src/main/kotlin/org/aresclient/ares/impl/gui/game/setting/StringElement.kt index a6edf648..2960685a 100644 --- a/src/main/kotlin/org/aresclient/ares/impl/gui/game/setting/StringElement.kt +++ b/src/main/kotlin/org/aresclient/ares/impl/gui/game/setting/StringElement.kt @@ -22,8 +22,8 @@ class StringElement(setting: StringSetting, scale: Float): SettingElement.builder(): LiteralArgumentBuilder { return then(argument("setting", string()).executes { val path = getString(it, "setting") diff --git a/src/main/kotlin/org/aresclient/ares/impl/instrument/global/Camera.kt b/src/main/kotlin/org/aresclient/ares/impl/instrument/global/Camera.kt index f556f68f..a7b53f2d 100644 --- a/src/main/kotlin/org/aresclient/ares/impl/instrument/global/Camera.kt +++ b/src/main/kotlin/org/aresclient/ares/impl/instrument/global/Camera.kt @@ -15,64 +15,67 @@ import org.aresclient.ares.impl.util.MathUtil.duplicate import org.aresclient.ares.impl.util.MathUtil.set interface CameraAdjustor: Prioritizer { - val cameraPosition: Vec3d? - val cameraRotation: Vec2f? - val shouldRenderCharacter: Boolean + val cameraPosition: Vec3d? + val cameraRotation: Vec2f? + val shouldRenderCharacter: Boolean } object Camera: Global.PriorityHandler("Camera", "Manages camera interactions") { - override fun begin() { - lastPosition.set(MC.gameRenderer.camera.pos) - lastRotation.set(MC.gameRenderer.camera.yaw, MC.gameRenderer.camera.pitch) - } + override fun begin() { + lastPosition.set(MC.gameRenderer.camera.pos) + lastRotation.set(MC.gameRenderer.camera.yaw, MC.gameRenderer.camera.pitch) + } - override fun end() { - lastPosition.set(Vec3d.ZERO) - lastRotation.set(Vec2f.ZERO) - } + override fun end() { + lastPosition.set(Vec3d.ZERO) + lastRotation.set(Vec2f.ZERO) + } - // ════════════════════════════════════════════════════════════════════════ // + // ════════════════════════════════════════════════════════════════════════ // - private val lastPosition = Vec3d.ZERO.duplicate() - private val lastRotation = Vec2f.ZERO.duplicate() + private val lastPosition = Vec3d.ZERO.duplicate() + private val lastRotation = Vec2f.ZERO.duplicate() - // ════════════════════════════════════════════════════════════════════════ // + // ════════════════════════════════════════════════════════════════════════ // - // Run on tick event with higher priority than default tick so that this runs before default tick events - @field:EventHandler private val tickEvent = EventListener(Priority.HIGH) { event -> - if (event.era != Era.BEFORE) return@EventListener - val current = getCurrent() ?: return@EventListener - lastPosition.set(current.cameraPosition ?: MC.gameRenderer.camera.pos) - } + // Run on tick event with higher priority than default tick so that this runs before default tick events + @field:EventHandler + private val tickEvent = EventListener(Priority.HIGH) { event -> + if(event.era != Era.BEFORE) return@EventListener + val current = getCurrent() ?: return@EventListener + lastPosition.set(current.cameraPosition ?: MC.gameRenderer.camera.pos) + } - @field:EventHandler private val onCameraUpdate = EventListener { event -> - val current = getCurrent() ?: return@EventListener + @field:EventHandler + private val onCameraUpdate = EventListener { event -> + val current = getCurrent() ?: return@EventListener - when (event) { - is CameraEvent.Position -> { - val currentPosition: Vec3d = current.cameraPosition ?: return@EventListener - event.x = MathHelper.lerp(event.delta.toDouble(), lastPosition.x, currentPosition.x) - event.y = MathHelper.lerp(event.delta.toDouble(), lastPosition.y, currentPosition.y) - event.z = MathHelper.lerp(event.delta.toDouble(), lastPosition.z, currentPosition.z) - } - is CameraEvent.Rotation -> { - val currentRotation: Vec2f = current.cameraRotation ?: return@EventListener - event.yaw = currentRotation.x - event.pitch = currentRotation.y - } - } + when(event) { + is CameraEvent.Position -> { + val currentPosition: Vec3d = current.cameraPosition ?: return@EventListener + event.x = MathHelper.lerp(event.delta.toDouble(), lastPosition.x, currentPosition.x) + event.y = MathHelper.lerp(event.delta.toDouble(), lastPosition.y, currentPosition.y) + event.z = MathHelper.lerp(event.delta.toDouble(), lastPosition.z, currentPosition.z) + } - event.isCancelled = true - } + is CameraEvent.Rotation -> { + val currentRotation: Vec2f = current.cameraRotation ?: return@EventListener + event.yaw = currentRotation.x + event.pitch = currentRotation.y + } + } - // ════════════════════════════════════════════════════════════════════════ // + event.isCancelled = true + } - fun shouldRenderCharacter(): Boolean? { - val current = getCurrent() ?: return null - val cameraPosition = current.cameraPosition ?: return null - val player = MC.player ?: return false - return (current.shouldRenderCharacter || MC.gameRenderer.camera.isThirdPerson) - && !player.boundingBox.intersects(cameraPosition, cameraPosition) - } + // ════════════════════════════════════════════════════════════════════════ // + + fun shouldRenderCharacter(): Boolean? { + val current = getCurrent() ?: return null + val cameraPosition = current.cameraPosition ?: return null + val player = MC.player ?: return false + return (current.shouldRenderCharacter || MC.gameRenderer.camera.isThirdPerson) + && !player.boundingBox.intersects(cameraPosition, cameraPosition) + } } \ No newline at end of file diff --git a/src/main/kotlin/org/aresclient/ares/impl/instrument/global/Interaction.kt b/src/main/kotlin/org/aresclient/ares/impl/instrument/global/Interaction.kt index 806ae99c..39821331 100644 --- a/src/main/kotlin/org/aresclient/ares/impl/instrument/global/Interaction.kt +++ b/src/main/kotlin/org/aresclient/ares/impl/instrument/global/Interaction.kt @@ -4,7 +4,6 @@ import org.aresclient.ares.api.instruments.Global import org.aresclient.ares.api.instruments.Prioritizer import org.aresclient.ares.api.setting.Setting import org.aresclient.ares.api.setting.SettingGroup -import org.aresclient.ares.api.setting.settings.number.NumberSetting import kotlin.math.ceil interface Placer: Prioritizer { diff --git a/src/main/kotlin/org/aresclient/ares/impl/instrument/global/Rotation.kt b/src/main/kotlin/org/aresclient/ares/impl/instrument/global/Rotation.kt index f96268d5..b66d084d 100644 --- a/src/main/kotlin/org/aresclient/ares/impl/instrument/global/Rotation.kt +++ b/src/main/kotlin/org/aresclient/ares/impl/instrument/global/Rotation.kt @@ -19,124 +19,124 @@ import org.aresclient.ares.impl.util.Timer import kotlin.math.min interface Rotator: Prioritizer { - val yawStep: Float get() = Rotation.yaw_step.value - val pitchStep: Float get() = Rotation.pitch_step.value - val rotation: Vec2f + val yawStep: Float get() = Rotation.yaw_step.value + val pitchStep: Float get() = Rotation.pitch_step.value + val rotation: Vec2f } object Rotation: Global.PriorityHandler("Rotation", "Handles rotation so that the character is facing in the expected direction for an action."), CameraAdjustor { - private val reset_delay = settings.addLong("Reset Delay", 10) - .setMin(0) - .setMax(100) - .setDescription("How long to wait after completing a rotation before resetting to the same rotation as the camera.") - - private val completion_delay = settings.addLong("Completion Delay", 1) - .setMin(0) - .setMax(10) - .setDescription("How long to wait after completing a rotation before interactions can happen.") - - private val grouping_density = settings.addFloat("Grouping Density", 0F) - .setMin(0F) - .setMax(180F) - .setDescription("The rotation distance in degrees within which to ignore the completion delay.") - - internal val yaw_step = settings.addFloat("Yaw Step", 180F) - .setMin(1F) - .setMax(180F) - .setDescription("How many degrees to turn horizontally per tick.") - - internal val pitch_step = settings.addFloat("Pitch Step", 180F) - .setMin(1F) - .setMax(180F) - .setDescription("How many degrees to turn vertically per tick.") - - // ════════════════════════════════════════════════════════════════════════ // - - override fun begin() { - cameraRotation!!.set(MC.gameRenderer.camera.yaw, MC.gameRenderer.camera.pitch) - lastRotation.set(MC.player?.yaw ?: 0F, MC.player?.pitch ?: 0F) - } - - override fun end() { - MC.player!!.rotation = cameraRotation - Camera.end(this) - } - - override val cameraPosition: Vec3d? = null - override val cameraRotation: Vec2f = Vec2f.ZERO.duplicate() - override val shouldRenderCharacter: Boolean = false - override fun priority(): Int = 1 - - // ════════════════════════════════════════════════════════════════════════ // - - val currentRotation = Vec2f.ZERO.duplicate() - val lastRotation = Vec2f.ZERO.duplicate() - val resetTimer = Timer() - var steppingComplete = true - - // ════════════════════════════════════════════════════════════════════════ // - - override fun tick() { - if (keys.isEmpty() && Camera.isActive(this) && resetTimer.hasTicksPassed(reset_delay.value)) { - Camera.end(this) - resetTimer.reset() - return - } - - if (MC.world == null || MC.player == null || keys.isEmpty()) { - resetTimer.reset() - return - } - - val current = getCurrent() ?: return - currentRotation.set(current.rotation).normalizeRotation() - Camera.begin(this) - - val yawStep = min(current.yawStep, yaw_step.value) - val pitchStep = min(current.pitchStep, pitch_step.value) - - if (!lastRotation.equals(currentRotation) && yawStep != 180F || pitchStep != 180F) { - val xChange = lastRotation.x.getAngleDifference(currentRotation.x) - val yChange = lastRotation.y.getAngleDifference(currentRotation.y) - currentRotation._x = steppedAngle(xChange, yawStep, lastRotation.x, currentRotation.x) - currentRotation._y = steppedAngle(yChange, pitchStep, lastRotation.y, currentRotation.y) - } else steppingComplete = true - - MC.player!!.rotation = currentRotation - - lastRotation.set(currentRotation) - } - - @field:EventHandler private val changeLookDirection = EventListener { event -> - if (!isRotating) return@EventListener - if (Camera.hasPriority(this)) event.isCancelled = true - cameraRotation.moveCameraWithCursor(event) - } - - @field:EventHandler private val updateVelocityYaw = EventListener { event -> - if (!Camera.hasPriority(this)) return@EventListener - - event.isCancelled = true - event.yaw = cameraRotation.x - } - - // ════════════════════════════════════════════════════════════════════════ // - - private fun steppedAngle(change: Float, step: Float, last: Float, current: Float): Float = - if (change > step) { - steppingComplete = false - last +step - } - else if(change < -step) { - steppingComplete = false - last -step - } - else { - steppingComplete = true - current - } - - val isRotating: Boolean get() = Camera.isActive(this) + private val reset_delay = settings.addLong("Reset Delay", 10) + .setMin(0) + .setMax(100) + .setDescription("How long to wait after completing a rotation before resetting to the same rotation as the camera.") + + private val completion_delay = settings.addLong("Completion Delay", 1) + .setMin(0) + .setMax(10) + .setDescription("How long to wait after completing a rotation before interactions can happen.") + + private val grouping_density = settings.addFloat("Grouping Density", 0F) + .setMin(0F) + .setMax(180F) + .setDescription("The rotation distance in degrees within which to ignore the completion delay.") + + internal val yaw_step = settings.addFloat("Yaw Step", 180F) + .setMin(1F) + .setMax(180F) + .setDescription("How many degrees to turn horizontally per tick.") + + internal val pitch_step = settings.addFloat("Pitch Step", 180F) + .setMin(1F) + .setMax(180F) + .setDescription("How many degrees to turn vertically per tick.") + + // ════════════════════════════════════════════════════════════════════════ // + + override fun begin() { + cameraRotation.set(MC.gameRenderer.camera.yaw, MC.gameRenderer.camera.pitch) + lastRotation.set(MC.player?.yaw ?: 0F, MC.player?.pitch ?: 0F) + } + + override fun end() { + MC.player!!.rotation = cameraRotation + Camera.end(this) + } + + override val cameraPosition: Vec3d? = null + override val cameraRotation: Vec2f = Vec2f.ZERO.duplicate() + override val shouldRenderCharacter: Boolean = false + override fun priority(): Int = 1 + + // ════════════════════════════════════════════════════════════════════════ // + + val currentRotation = Vec2f.ZERO.duplicate() + val lastRotation = Vec2f.ZERO.duplicate() + val resetTimer = Timer() + var steppingComplete = true + + // ════════════════════════════════════════════════════════════════════════ // + + override fun tick() { + if(keys.isEmpty() && Camera.isActive(this) && resetTimer.hasTicksPassed(reset_delay.value)) { + Camera.end(this) + resetTimer.reset() + return + } + + if(MC.world == null || MC.player == null || keys.isEmpty()) { + resetTimer.reset() + return + } + + val current = getCurrent() ?: return + currentRotation.set(current.rotation).normalizeRotation() + Camera.begin(this) + + val yawStep = min(current.yawStep, yaw_step.value) + val pitchStep = min(current.pitchStep, pitch_step.value) + + if(!lastRotation.equals(currentRotation) && yawStep != 180F || pitchStep != 180F) { + val xChange = lastRotation.x.getAngleDifference(currentRotation.x) + val yChange = lastRotation.y.getAngleDifference(currentRotation.y) + currentRotation._x = steppedAngle(xChange, yawStep, lastRotation.x, currentRotation.x) + currentRotation._y = steppedAngle(yChange, pitchStep, lastRotation.y, currentRotation.y) + } else steppingComplete = true + + MC.player!!.rotation = currentRotation + + lastRotation.set(currentRotation) + } + + @field:EventHandler + private val changeLookDirection = EventListener { event -> + if(!isRotating) return@EventListener + if(Camera.hasPriority(this)) event.isCancelled = true + cameraRotation.moveCameraWithCursor(event) + } + + @field:EventHandler + private val updateVelocityYaw = EventListener { event -> + if(!Camera.hasPriority(this)) return@EventListener + + event.isCancelled = true + event.yaw = cameraRotation.x + } + + // ════════════════════════════════════════════════════════════════════════ // + + private fun steppedAngle(change: Float, step: Float, last: Float, current: Float): Float = + if(change > step) { + steppingComplete = false + last + step + } else if(change < -step) { + steppingComplete = false + last - step + } else { + steppingComplete = true + current + } + + val isRotating: Boolean get() = Camera.isActive(this) } diff --git a/src/main/kotlin/org/aresclient/ares/impl/instrument/module/components/movement/speed/Strafe.kt b/src/main/kotlin/org/aresclient/ares/impl/instrument/module/components/movement/speed/Strafe.kt index 2f842099..332301f2 100644 --- a/src/main/kotlin/org/aresclient/ares/impl/instrument/module/components/movement/speed/Strafe.kt +++ b/src/main/kotlin/org/aresclient/ares/impl/instrument/module/components/movement/speed/Strafe.kt @@ -11,49 +11,50 @@ import kotlin.math.sqrt object Strafe: Component.Settings(Speed, "Strafe"), Wrapper { - init { - settings.setDescription("Settings for Strafe mode") - settings.setVisibility { Speed.mode.value == Speed.Mode.STRAFE } - } - - private val low_hop = settings - .addBoolean("Low Hop", false) - - private val height = settings - .addDouble("Height", 0.3) - .setMin(0.3) - .setMax(0.5) - .setVisibility(low_hop::getValue) - - private val modify_speed = settings - .addBoolean("Modify Speed", false) - - private val speed = settings - .addDouble("Speed", 0.32) - .setMin(0.2) - .setMax(0.6) - .setVisibility(modify_speed::getValue) - - private val sprint = settings - .addBoolean("Auto Sprint", true) - - @field:EventHandler val motionTickListener = EventListener { - if (master.mode.value != Speed.Mode.STRAFE || MC.NULL) return@EventListener - - val input = SELF.input?.playerInput ?: return@EventListener - if (!input.forward && !input.backward && !input.left && !input.right) return@EventListener - - if (sprint.value) SELF.setSprinting(true) - if (SELF.isOnGround) { - if (low_hop.value) SELF.addVelocity(0.0, height.value, 0.0) - return@EventListener - } - - val speed = - if (!modify_speed.value) sqrt(SELF.velocity.x * SELF.velocity.x + SELF.velocity.z * SELF.velocity.z) - else speed.value - - SELF.withTransverseMovement(speed) - } + init { + settings.setDescription("Settings for Strafe mode") + settings.setVisibility { Speed.mode.value == Speed.Mode.STRAFE } + } + + private val low_hop = settings + .addBoolean("Low Hop", false) + + private val height = settings + .addDouble("Height", 0.3) + .setMin(0.3) + .setMax(0.5) + .setVisibility(low_hop::getValue) + + private val modify_speed = settings + .addBoolean("Modify Speed", false) + + private val speed = settings + .addDouble("Speed", 0.32) + .setMin(0.2) + .setMax(0.6) + .setVisibility(modify_speed::getValue) + + private val sprint = settings + .addBoolean("Auto Sprint", true) + + @field:EventHandler + val motionTickListener = EventListener { + if(master.mode.value != Speed.Mode.STRAFE || MC.NULL) return@EventListener + + val input = SELF.input?.playerInput ?: return@EventListener + if(!input.forward && !input.backward && !input.left && !input.right) return@EventListener + + if(sprint.value) SELF.setSprinting(true) + if(SELF.isOnGround) { + if(low_hop.value) SELF.addVelocity(0.0, height.value, 0.0) + return@EventListener + } + + val speed = + if(!modify_speed.value) sqrt(SELF.velocity.x * SELF.velocity.x + SELF.velocity.z * SELF.velocity.z) + else speed.value + + SELF.withTransverseMovement(speed) + } } \ No newline at end of file diff --git a/src/main/kotlin/org/aresclient/ares/impl/instrument/module/components/movement/speed/StrafeHop.kt b/src/main/kotlin/org/aresclient/ares/impl/instrument/module/components/movement/speed/StrafeHop.kt index ac36e1a6..23d77a62 100644 --- a/src/main/kotlin/org/aresclient/ares/impl/instrument/module/components/movement/speed/StrafeHop.kt +++ b/src/main/kotlin/org/aresclient/ares/impl/instrument/module/components/movement/speed/StrafeHop.kt @@ -13,69 +13,70 @@ import org.aresclient.ares.impl.util.MathUtil._z object StrafeHop: Component.Settings(Speed, "Strafe Hop"), Wrapper { - init { - settings.setDescription("Settings for Strafe Hop mode") - settings.setVisibility { Speed.mode.value == Speed.Mode.STRAFE_HOP } - } - - private val strict = settings.addBoolean("Strict", true, "Whether to use NCP strict speed or not.") - - private var phase = Phase.START - - @field:EventHandler private val moveEventListener = EventListener { event -> - if (master.mode.value != Speed.Mode.STRAFE_HOP || MC.NULL) return@EventListener - - master.v = 0.2873 - master.y = SELF.velocity.y - - if (SELF.activeStatusEffects.containsValue(SELF.getStatusEffect(StatusEffects.SPEED))) { - val amplifier = SELF.getStatusEffect(StatusEffects.SPEED)?.amplifier ?: 0 - master.v *= 1.0 + 0.2 * (amplifier + 1) - } - - if (SELF.forwardSpeed == 0F && SELF.sidewaysSpeed == 0F) { - phase = Phase.START - master.speed = 0.0 - event.movement._x = 0.0 - event.movement._z = 0.0 - event.isCancelled = true - return@EventListener - } - - if (SELF.isOnGround || SELF.horizontalCollision) { - master.speed = 0.0 - reset() - } - - phase.action.invoke() - event.changeMovement() - } - - fun reset() { - phase = Phase.START - } - - private enum class Phase(val action: () -> Unit) { - START(StrafeHop::start), - MIDDLE(StrafeHop::middle), - END(StrafeHop::end) - } - - private fun start() { - if (!SELF.isOnGround) return - - master.y = 0.42 - master.speed = master.v * (if (strict.value) 1.87 else 1.91) - phase = Phase.MIDDLE - } - - private fun middle() { - master.speed -= 0.66 * master.v - phase = Phase.END - } - - private fun end() { - master.speed = master.lastDist - master.lastDist / 159 - } + init { + settings.setDescription("Settings for Strafe Hop mode") + settings.setVisibility { Speed.mode.value == Speed.Mode.STRAFE_HOP } + } + + private val strict = settings.addBoolean("Strict", true, "Whether to use NCP strict speed or not.") + + private var phase = Phase.START + + @field:EventHandler + private val moveEventListener = EventListener { event -> + if(master.mode.value != Speed.Mode.STRAFE_HOP || MC.NULL) return@EventListener + + master.v = 0.2873 + master.y = SELF.velocity.y + + if(SELF.activeStatusEffects.containsValue(SELF.getStatusEffect(StatusEffects.SPEED))) { + val amplifier = SELF.getStatusEffect(StatusEffects.SPEED)?.amplifier ?: 0 + master.v *= 1.0 + 0.2 * (amplifier + 1) + } + + if(SELF.forwardSpeed == 0F && SELF.sidewaysSpeed == 0F) { + phase = Phase.START + master.speed = 0.0 + event.movement._x = 0.0 + event.movement._z = 0.0 + event.isCancelled = true + return@EventListener + } + + if(SELF.isOnGround || SELF.horizontalCollision) { + master.speed = 0.0 + reset() + } + + phase.action.invoke() + event.changeMovement() + } + + fun reset() { + phase = Phase.START + } + + private enum class Phase(val action: () -> Unit) { + START(StrafeHop::start), + MIDDLE(StrafeHop::middle), + END(StrafeHop::end) + } + + private fun start() { + if(!SELF.isOnGround) return + + master.y = 0.42 + master.speed = master.v * (if(strict.value) 1.87 else 1.91) + phase = Phase.MIDDLE + } + + private fun middle() { + master.speed -= 0.66 * master.v + phase = Phase.END + } + + private fun end() { + master.speed = master.lastDist - master.lastDist / 159 + } } \ No newline at end of file diff --git a/src/main/kotlin/org/aresclient/ares/impl/instrument/module/components/movement/speed/YPort.kt b/src/main/kotlin/org/aresclient/ares/impl/instrument/module/components/movement/speed/YPort.kt index 8e3eecd3..20fc81d4 100644 --- a/src/main/kotlin/org/aresclient/ares/impl/instrument/module/components/movement/speed/YPort.kt +++ b/src/main/kotlin/org/aresclient/ares/impl/instrument/module/components/movement/speed/YPort.kt @@ -12,57 +12,58 @@ import org.aresclient.ares.impl.util.MathUtil._z object YPort: Component(Speed), Wrapper { - private var phase = Phase.START + private var phase = Phase.START - @field:EventHandler private val moveEventListener = EventListener { event -> - if (master.mode.value != Speed.Mode.Y_PORT || MC.NULL) return@EventListener + @field:EventHandler + private val moveEventListener = EventListener { event -> + if(master.mode.value != Speed.Mode.Y_PORT || MC.NULL) return@EventListener - master.v = 0.2873 - master.y = SELF.velocity.y + master.v = 0.2873 + master.y = SELF.velocity.y - if (SELF.horizontalCollision) { - phase = Phase.START - } + if(SELF.horizontalCollision) { + phase = Phase.START + } - if (SELF.forwardSpeed == 0F && SELF.sidewaysSpeed == 0F) { - reset() - master.speed = 0.0 - event.movement._x = 0.0 - event.movement._z = 0.0 - event.isCancelled = true - return@EventListener - } + if(SELF.forwardSpeed == 0F && SELF.sidewaysSpeed == 0F) { + reset() + master.speed = 0.0 + event.movement._x = 0.0 + event.movement._z = 0.0 + event.isCancelled = true + return@EventListener + } - phase.action.invoke() - event.changeMovement() - } + phase.action.invoke() + event.changeMovement() + } - private enum class Phase(val action: () -> Unit) { - START(YPort::start), - MIDDLE(YPort::middle), - END(YPort::end) - } + private enum class Phase(val action: () -> Unit) { + START(YPort::start), + MIDDLE(YPort::middle), + END(YPort::end) + } - fun reset() { - phase = Phase.START - } + fun reset() { + phase = Phase.START + } - private fun start() { - phase = Phase.MIDDLE - master.y = -1.0 - master.speed = master.v - } + private fun start() { + phase = Phase.MIDDLE + master.y = -1.0 + master.speed = master.v + } - private fun middle() { - master.speed *= 2.149 - master.y = 0.42 - phase = Phase.END - } + private fun middle() { + master.speed *= 2.149 + master.y = 0.42 + phase = Phase.END + } - private fun end() { - master.speed = master.lastDist - 0.66 * (master.lastDist - master.v) - phase = Phase.MIDDLE - master.y = -1.0 - } + private fun end() { + master.speed = master.lastDist - 0.66 * (master.lastDist - master.v) + phase = Phase.MIDDLE + master.y = -1.0 + } } \ No newline at end of file diff --git a/src/main/kotlin/org/aresclient/ares/impl/instrument/module/components/offence/crystalaura/TargetSettings.kt b/src/main/kotlin/org/aresclient/ares/impl/instrument/module/components/offence/crystalaura/TargetSettings.kt index b7ca0da4..19662102 100644 --- a/src/main/kotlin/org/aresclient/ares/impl/instrument/module/components/offence/crystalaura/TargetSettings.kt +++ b/src/main/kotlin/org/aresclient/ares/impl/instrument/module/components/offence/crystalaura/TargetSettings.kt @@ -20,7 +20,7 @@ object TargetSettings: Component.Settings(CrystalAura, "Target") { val boss = settings.addBoolean("Boss", true) val target_priority = settings - .addEnum("Target Priority", TargetPriority.MOST_DAMAGE) + .addEnum("Target Priority", TargetPriority.MOST_DAMAGE) enum class TargetPriority { CLOSEST, diff --git a/src/main/kotlin/org/aresclient/ares/impl/instrument/module/modules/movement/Speed.kt b/src/main/kotlin/org/aresclient/ares/impl/instrument/module/modules/movement/Speed.kt index c64315ef..409f4d81 100644 --- a/src/main/kotlin/org/aresclient/ares/impl/instrument/module/modules/movement/Speed.kt +++ b/src/main/kotlin/org/aresclient/ares/impl/instrument/module/modules/movement/Speed.kt @@ -16,52 +16,52 @@ import kotlin.math.max object Speed: Module(Category.MOVEMENT, "Speed", "") { - init { - Strafe - StrafeHop - YPort - } + init { + Strafe + StrafeHop + YPort + } - enum class Mode { - STRAFE, - STRAFE_HOP, - Y_PORT - } + enum class Mode { + STRAFE, + STRAFE_HOP, + Y_PORT + } - val mode = settings.addEnum("Mode", Mode.STRAFE_HOP) + val mode = settings.addEnum("Mode", Mode.STRAFE_HOP) - var lastMode: Mode? = null - var lastDist = 0.2873 - var speed = 0.2873 - var v = 0.2873 - var y = 0.0 + var lastMode: Mode? = null + var lastDist = 0.2873 + var speed = 0.2873 + var v = 0.2873 + var y = 0.0 - override fun onTick() { - if (MC.NULL) return + override fun onTick() { + if(MC.NULL) return - if (mode.value != lastMode) { - lastMode = mode.value - StrafeHop.reset() - YPort.reset() - speed = 0.0 - lastDist = 0.0 - return - } + if(mode.value != lastMode) { + lastMode = mode.value + StrafeHop.reset() + YPort.reset() + speed = 0.0 + lastDist = 0.0 + return + } - if (mode.value == Mode.STRAFE) return + if(mode.value == Mode.STRAFE) return - ((MC as AccessMinecraftClient).renderTickCounter as AccessRenderTickCounter).setTickTime(45.99221F) + ((MC as AccessMinecraftClient).renderTickCounter as AccessRenderTickCounter).setTickTime(45.99221F) - lastDist = hypot(SELF.x - SELF.lastX, SELF.z - SELF.lastZ) - } + lastDist = hypot(SELF.x - SELF.lastX, SELF.z - SELF.lastZ) + } - fun PlayerEvent.Move.changeMovement() { - val dir = SELF.getTransverseMovement(max(v, speed)) - SELF.setVelocity(dir.x, y, dir.y) + fun PlayerEvent.Move.changeMovement() { + val dir = SELF.getTransverseMovement(max(v, speed)) + SELF.setVelocity(dir.x, y, dir.y) - movement._x = SELF.velocity.x - movement._y = SELF.velocity.y - movement._z = SELF.velocity.z - isCancelled = true - } + movement._x = SELF.velocity.x + movement._y = SELF.velocity.y + movement._z = SELF.velocity.z + isCancelled = true + } } \ No newline at end of file diff --git a/src/main/kotlin/org/aresclient/ares/impl/instrument/module/modules/offence/CrystalAura.kt b/src/main/kotlin/org/aresclient/ares/impl/instrument/module/modules/offence/CrystalAura.kt index 137294c7..f133866d 100644 --- a/src/main/kotlin/org/aresclient/ares/impl/instrument/module/modules/offence/CrystalAura.kt +++ b/src/main/kotlin/org/aresclient/ares/impl/instrument/module/modules/offence/CrystalAura.kt @@ -4,13 +4,13 @@ import org.aresclient.ares.api.instruments.Module import org.aresclient.ares.impl.instrument.module.components.offence.crystalaura.* object CrystalAura: Module(Category.OFFENSE, "CrystalAura", "Automatically places and breaks end crystals") { - init { - // Settings - DelaySettings - HaltSettings - ValiditySettings - CalculationSettings - TargetSettings - MiscellaneousSettings - } + init { + // Settings + DelaySettings + HaltSettings + ValiditySettings + CalculationSettings + TargetSettings + MiscellaneousSettings + } } diff --git a/src/main/kotlin/org/aresclient/ares/impl/instrument/module/modules/player/Freecam.kt b/src/main/kotlin/org/aresclient/ares/impl/instrument/module/modules/player/Freecam.kt index c53ea0c7..0b364a77 100644 --- a/src/main/kotlin/org/aresclient/ares/impl/instrument/module/modules/player/Freecam.kt +++ b/src/main/kotlin/org/aresclient/ares/impl/instrument/module/modules/player/Freecam.kt @@ -14,95 +14,97 @@ import org.aresclient.ares.impl.util.MathUtil._x import org.aresclient.ares.impl.util.MathUtil._y import org.aresclient.ares.impl.util.MathUtil._z import org.aresclient.ares.impl.util.MathUtil.duplicate -import org.aresclient.ares.impl.util.MathUtil.toTransverseMovement import org.aresclient.ares.impl.util.MathUtil.moveCameraWithCursor import org.aresclient.ares.impl.util.MathUtil.set +import org.aresclient.ares.impl.util.MathUtil.toTransverseMovement object Freecam: Module(Category.PLAYER, "Freecam", "Allows the player to move the camera independently of the character"), CameraAdjustor { - private val speed = settings.addDouble("Speed", 1.0, "The speed at which the camera moves.") - .setMin(0.0) - .setPrecision(1) - - // ════════════════════════════════════════════════════════════════════════ // - - override fun priority(): Int = 100 - override val cameraPosition: Vec3d = Vec3d.ZERO.duplicate() - override val cameraRotation: Vec2f = Vec2f.ZERO.duplicate() - override val shouldRenderCharacter: Boolean = true - - // ════════════════════════════════════════════════════════════════════════ // - - private var forward = false - private var backward = false - private var leftward = false - private var rightward = false - private var upward = false - private var downward = false - - // ════════════════════════════════════════════════════════════════════════ // - - override fun onEnable() { - MC.gameRenderer.camera.let { - cameraPosition.set(it.pos) - cameraRotation.set(it.yaw, it.pitch) - } - Camera.begin(this) - } - - override fun onDisable() { - Camera.end(this) - } - - override fun onTick() { - if (MC.world == null || MC.player == null) return - - var speed = speed.value - if (!MC.options.sprintKey.isPressed) speed *= 0.5 - - val transverseMovement = MC.gameRenderer.camera.yaw.toTransverseMovement( - speed, - if (forward && !backward) 1F else if (backward && !forward) -1F else 0F, - if (leftward && !rightward) 1F else if (rightward && !leftward) -1F else 0F - ) - - cameraPosition._x += transverseMovement.x - cameraPosition._y += if (upward) speed else if (downward) -speed else 0.0 - cameraPosition._z += transverseMovement.y - } - - @field:EventHandler private val changeLookDirectionListener = EventListener { event -> - if (!Camera.hasPriority(this)) return@EventListener - event.isCancelled = true - cameraRotation.moveCameraWithCursor(event) - } - - @field:EventHandler private val keyboardListener = EventListener { event -> - val opt = MC.options - - if (opt.forwardKey.matchesKey(event.key, 0)) { - opt.forwardKey.isPressed = false - forward = event is Pressed - } else if (opt.backKey.matchesKey(event.key, 0)) { - opt.backKey.isPressed = false - backward = event is Pressed - } else if (opt.leftKey.matchesKey(event.key, 0)) { - opt.leftKey.isPressed = false - leftward = event is Pressed - } else if (opt.rightKey.matchesKey(event.key, 0)) { - opt.rightKey.isPressed = false - rightward = event is Pressed - } else if (opt.jumpKey.matchesKey(event.key, 0)) { - opt.jumpKey.isPressed = false - upward = event is Pressed - } else if (opt.sneakKey.matchesKey(event.key, 0)) { - opt.sneakKey.isPressed = false - downward = event is Pressed - } else return@EventListener - - event.isCancelled = true - } - - // ════════════════════════════════════════════════════════════════════════ // + private val speed = settings.addDouble("Speed", 1.0, "The speed at which the camera moves.") + .setMin(0.0) + .setPrecision(1) + + // ════════════════════════════════════════════════════════════════════════ // + + override fun priority(): Int = 100 + override val cameraPosition: Vec3d = Vec3d.ZERO.duplicate() + override val cameraRotation: Vec2f = Vec2f.ZERO.duplicate() + override val shouldRenderCharacter: Boolean = true + + // ════════════════════════════════════════════════════════════════════════ // + + private var forward = false + private var backward = false + private var leftward = false + private var rightward = false + private var upward = false + private var downward = false + + // ════════════════════════════════════════════════════════════════════════ // + + override fun onEnable() { + MC.gameRenderer.camera.let { + cameraPosition.set(it.pos) + cameraRotation.set(it.yaw, it.pitch) + } + Camera.begin(this) + } + + override fun onDisable() { + Camera.end(this) + } + + override fun onTick() { + if(MC.world == null || MC.player == null) return + + var speed = speed.value + if(!MC.options.sprintKey.isPressed) speed *= 0.5 + + val transverseMovement = MC.gameRenderer.camera.yaw.toTransverseMovement( + speed, + if(forward && !backward) 1F else if(backward && !forward) -1F else 0F, + if(leftward && !rightward) 1F else if(rightward && !leftward) -1F else 0F + ) + + cameraPosition._x += transverseMovement.x + cameraPosition._y += if(upward) speed else if(downward) -speed else 0.0 + cameraPosition._z += transverseMovement.y + } + + @field:EventHandler + private val changeLookDirectionListener = EventListener { event -> + if(!Camera.hasPriority(this)) return@EventListener + event.isCancelled = true + cameraRotation.moveCameraWithCursor(event) + } + + @field:EventHandler + private val keyboardListener = EventListener { event -> + val opt = MC.options + + if(opt.forwardKey.matchesKey(event.key, 0)) { + opt.forwardKey.isPressed = false + forward = event is Pressed + } else if(opt.backKey.matchesKey(event.key, 0)) { + opt.backKey.isPressed = false + backward = event is Pressed + } else if(opt.leftKey.matchesKey(event.key, 0)) { + opt.leftKey.isPressed = false + leftward = event is Pressed + } else if(opt.rightKey.matchesKey(event.key, 0)) { + opt.rightKey.isPressed = false + rightward = event is Pressed + } else if(opt.jumpKey.matchesKey(event.key, 0)) { + opt.jumpKey.isPressed = false + upward = event is Pressed + } else if(opt.sneakKey.matchesKey(event.key, 0)) { + opt.sneakKey.isPressed = false + downward = event is Pressed + } else return@EventListener + + event.isCancelled = true + } + + // ════════════════════════════════════════════════════════════════════════ // } diff --git a/src/main/kotlin/org/aresclient/ares/impl/instrument/module/modules/render/ESP.kt b/src/main/kotlin/org/aresclient/ares/impl/instrument/module/modules/render/ESP.kt index fe4bf78e..b396ff78 100644 --- a/src/main/kotlin/org/aresclient/ares/impl/instrument/module/modules/render/ESP.kt +++ b/src/main/kotlin/org/aresclient/ares/impl/instrument/module/modules/render/ESP.kt @@ -12,8 +12,8 @@ import org.aresclient.ares.api.render.Renderer import org.aresclient.ares.api.util.Color import org.aresclient.ares.impl.util.EntityUtil.getTargetColor import org.aresclient.ares.impl.util.EntityUtil.isTarget -import org.aresclient.ares.impl.util.RenderUtil import org.aresclient.ares.impl.util.RenderPipelines +import org.aresclient.ares.impl.util.RenderUtil import java.util.* // TODO: FIX DEPTH ON OUTLINE ESP @@ -36,22 +36,24 @@ object ESP: Module(Category.RENDER, "ESP", "See outlines of entities through wal fun shouldRenderOutline() = isEnabled() && mode.value == Mode.OUTLINE fun shouldRenderOutline(entity: Entity) = shouldRenderOutline() && entity.isTarget( - players.value,friends.value, teammates.value, passive.value, + players.value, friends.value, teammates.value, passive.value, hostile.value, items.value, nametagged.value, bots.value ) override fun onRenderWorld(delta: Float, renderer: Renderer.State) { if(mode.value != Mode.BOX) return - MC.world?.entities?.filter { it.isTarget( - players.value,friends.value, teammates.value, passive.value, + MC.world?.entities?.filter { + it.isTarget( + players.value, friends.value, teammates.value, passive.value, hostile.value, items.value, nametagged.value, bots.value - ) }?.forEach { entity -> - if(entity != MC.player) { - val box = entity.getInterpolatedBoundingBox(delta) - val color = getEntityColor(entity) - RenderUtil.Lines.box(box, color, 1f) - RenderUtil.Fill.box(box, color.deriveAlpha(0.2f)) - } + ) + }?.forEach { entity -> + if(entity != MC.player) { + val box = entity.getInterpolatedBoundingBox(delta) + val color = getEntityColor(entity) + RenderUtil.Lines.box(box, color, 1f) + RenderUtil.Fill.box(box, color.deriveAlpha(0.2f)) + } } } @@ -81,15 +83,15 @@ object ESP: Module(Category.RENDER, "ESP", "See outlines of entities through wal val gpuBuffer = shapeIndexBuffer.getIndexBuffer(6) val gpuBuffer2 = RenderSystem.getQuadVertexBuffer() RenderSystem.getDevice().createCommandEncoder().createRenderPass(MC.framebuffer.colorAttachment, OptionalInt.empty()) - .use { renderPass -> - renderPass.setPipeline(RenderPipelines.outline) - renderPass.setVertexBuffer(0, gpuBuffer2) - renderPass.setIndexBuffer(gpuBuffer, shapeIndexBuffer.indexType) - renderPass.bindSampler("theTexture", framebuffer.colorAttachment) - renderPass.setUniform("viewportSize", MC.framebuffer.textureWidth.toFloat(), MC.framebuffer.textureHeight.toFloat()) - renderPass.setUniform("lineWeight", 1f) - renderPass.drawIndexed(0, 6) - } + .use { renderPass -> + renderPass.setPipeline(RenderPipelines.outline) + renderPass.setVertexBuffer(0, gpuBuffer2) + renderPass.setIndexBuffer(gpuBuffer, shapeIndexBuffer.indexType) + renderPass.bindSampler("theTexture", framebuffer.colorAttachment) + renderPass.setUniform("viewportSize", MC.framebuffer.textureWidth.toFloat(), MC.framebuffer.textureHeight.toFloat()) + renderPass.setUniform("lineWeight", 1f) + renderPass.drawIndexed(0, 6) + } RenderSystem.getDevice().createCommandEncoder().clearColorAndDepthTextures(framebuffer.colorAttachment, 0, framebuffer.depthAttachment, 0.0) } } diff --git a/src/main/kotlin/org/aresclient/ares/impl/instrument/module/modules/render/Fullbright.kt b/src/main/kotlin/org/aresclient/ares/impl/instrument/module/modules/render/Fullbright.kt index 1fa0c1be..a316f72a 100644 --- a/src/main/kotlin/org/aresclient/ares/impl/instrument/module/modules/render/Fullbright.kt +++ b/src/main/kotlin/org/aresclient/ares/impl/instrument/module/modules/render/Fullbright.kt @@ -2,5 +2,4 @@ package org.aresclient.ares.impl.instrument.module.modules.render import org.aresclient.ares.api.instruments.Module -object Fullbright: Module(Category.RENDER, "Fullbright", "Lets you see everything with full brightness") { -} \ No newline at end of file +object Fullbright: Module(Category.RENDER, "Fullbright", "Lets you see everything with full brightness") \ No newline at end of file diff --git a/src/main/kotlin/org/aresclient/ares/impl/instrument/module/modules/render/TestModule.kt b/src/main/kotlin/org/aresclient/ares/impl/instrument/module/modules/render/TestModule.kt index 9252bf35..3bba4764 100644 --- a/src/main/kotlin/org/aresclient/ares/impl/instrument/module/modules/render/TestModule.kt +++ b/src/main/kotlin/org/aresclient/ares/impl/instrument/module/modules/render/TestModule.kt @@ -7,7 +7,6 @@ import org.aresclient.ares.api.util.Color import org.aresclient.ares.api.util.Keys import org.aresclient.ares.impl.util.RenderHelper import org.aresclient.ares.impl.util.RenderHelper.draw -import org.lwjgl.opengl.GL11 object TestModule: Module(Category.RENDER, "Test", "A simple test module", Defaults().setBind(Keys.Y).setEnabled(true)) { private val renderer by lazy { RenderHelper.getFontRenderer(24f) } diff --git a/src/main/kotlin/org/aresclient/ares/impl/util/EntityUtil.kt b/src/main/kotlin/org/aresclient/ares/impl/util/EntityUtil.kt index e2d8c009..f6a151f0 100644 --- a/src/main/kotlin/org/aresclient/ares/impl/util/EntityUtil.kt +++ b/src/main/kotlin/org/aresclient/ares/impl/util/EntityUtil.kt @@ -14,85 +14,87 @@ import org.aresclient.ares.impl.util.MathUtil.toTransverseMovement import org.joml.Vector2d object EntityUtil: Wrapper { - var Entity.rotation: Vec2f - get() = Vec2f(yaw, pitch) - set(value) { - this.yaw = value.x - this.pitch = value.y - } + var Entity.rotation: Vec2f + get() = Vec2f(yaw, pitch) + set(value) { + this.yaw = value.x + this.pitch = value.y + } - fun Entity.setRotation(yaw: Float, pitch: Float) { - this.yaw = yaw - this.pitch = pitch - } + fun Entity.setRotation(yaw: Float, pitch: Float) { + this.yaw = yaw + this.pitch = pitch + } - fun Entity.isFriend(): Boolean = this is PlayerEntity && FriendUtil.isFriend(this.gameProfile) + fun Entity.isFriend(): Boolean = this is PlayerEntity && FriendUtil.isFriend(this.gameProfile) - fun Entity.isBot(): Boolean = this is PlayerEntity && isInvisibleTo(MC.player) && !isOnGround && !collidesWith(MC.player) + fun Entity.isBot(): Boolean = this is PlayerEntity && isInvisibleTo(MC.player) && !isOnGround && !collidesWith(MC.player) - enum class TargetType { - SELF, PLAYER, FRIEND, TEAMMATE, PASSIVE, HOSTILE, ITEM, BOT, OTHER; - } + enum class TargetType { + SELF, PLAYER, FRIEND, TEAMMATE, PASSIVE, HOSTILE, ITEM, BOT, OTHER; + } - fun Entity.getTargetType(): TargetType { - if(this == MC.player) return TargetType.SELF - return when(this) { - is ItemEntity -> TargetType.ITEM - is PassiveEntity -> TargetType.PASSIVE - is Monster -> TargetType.HOSTILE - is PlayerEntity -> { - return if(isFriend()) TargetType.FRIEND - else if(isBot()) TargetType.BOT - else if(scoreboardTeam != null && scoreboardTeam == MC.player?.scoreboardTeam) TargetType.TEAMMATE - else TargetType.PLAYER - } - else -> TargetType.OTHER - } - } + fun Entity.getTargetType(): TargetType { + if(this == MC.player) return TargetType.SELF + return when(this) { + is ItemEntity -> TargetType.ITEM + is PassiveEntity -> TargetType.PASSIVE + is Monster -> TargetType.HOSTILE + is PlayerEntity -> { + return if(isFriend()) TargetType.FRIEND + else if(isBot()) TargetType.BOT + else if(scoreboardTeam != null && scoreboardTeam == MC.player?.scoreboardTeam) TargetType.TEAMMATE + else TargetType.PLAYER + } - fun Entity.getTargetColor(): Color { - return when(getTargetType()) { - TargetType.SELF -> Color.WHITE - TargetType.PLAYER -> Color.BLUE - TargetType.FRIEND -> Color.rainbow() - TargetType.TEAMMATE -> Color.rainbow() - TargetType.PASSIVE -> Color.GREEN - TargetType.HOSTILE -> Color.RED - TargetType.ITEM -> Color.WHITE - TargetType.BOT -> Color.BLACK - TargetType.OTHER -> Color.WHITE - } - } + else -> TargetType.OTHER + } + } - fun Entity.isTarget(players: Boolean, friends: Boolean, teammates: Boolean, passive: Boolean, hostile: Boolean, items: Boolean, nametagged: Boolean, bots: Boolean): Boolean { - if(this == MC.player) return false - if(hasCustomName() && nametagged) return true - return when(this) { - is ItemEntity -> items - is PassiveEntity -> passive - is Monster -> hostile - is PlayerEntity -> { - return if(players) { - if(isFriend()) friends - else if(isBot()) bots - else if(scoreboardTeam != null && scoreboardTeam == MC.player?.scoreboardTeam) teammates - else true - } else false - } - else -> false - } - } + fun Entity.getTargetColor(): Color { + return when(getTargetType()) { + TargetType.SELF -> Color.WHITE + TargetType.PLAYER -> Color.BLUE + TargetType.FRIEND -> Color.rainbow() + TargetType.TEAMMATE -> Color.rainbow() + TargetType.PASSIVE -> Color.GREEN + TargetType.HOSTILE -> Color.RED + TargetType.ITEM -> Color.WHITE + TargetType.BOT -> Color.BLACK + TargetType.OTHER -> Color.WHITE + } + } - fun ClientPlayerEntity.getTransverseMovement(speed: Double, cameraRotation: Boolean = true): Vector2d { - val yaw = if (cameraRotation && Rotation.isRotating) { - if (MC.options.perspective.isFrontView) MC.gameRenderer.camera.yaw - 180F - else MC.gameRenderer.camera.yaw - } else this.yaw - return yaw.toTransverseMovement(speed, forwardSpeed, sidewaysSpeed) - } + fun Entity.isTarget(players: Boolean, friends: Boolean, teammates: Boolean, passive: Boolean, hostile: Boolean, items: Boolean, nametagged: Boolean, bots: Boolean): Boolean { + if(this == MC.player) return false + if(hasCustomName() && nametagged) return true + return when(this) { + is ItemEntity -> items + is PassiveEntity -> passive + is Monster -> hostile + is PlayerEntity -> { + return if(players) { + if(isFriend()) friends + else if(isBot()) bots + else if(scoreboardTeam != null && scoreboardTeam == MC.player?.scoreboardTeam) teammates + else true + } else false + } - fun ClientPlayerEntity.withTransverseMovement(speed: Double, cameraRotation: Boolean = true, y: Double = this.velocity.y) { - val movement = getTransverseMovement(speed, cameraRotation) - this.setVelocity(movement.x, y, movement.y) - } + else -> false + } + } + + fun ClientPlayerEntity.getTransverseMovement(speed: Double, cameraRotation: Boolean = true): Vector2d { + val yaw = if(cameraRotation && Rotation.isRotating) { + if(MC.options.perspective.isFrontView) MC.gameRenderer.camera.yaw - 180F + else MC.gameRenderer.camera.yaw + } else this.yaw + return yaw.toTransverseMovement(speed, forwardSpeed, sidewaysSpeed) + } + + fun ClientPlayerEntity.withTransverseMovement(speed: Double, cameraRotation: Boolean = true, y: Double = this.velocity.y) { + val movement = getTransverseMovement(speed, cameraRotation) + this.setVelocity(movement.x, y, movement.y) + } } \ No newline at end of file diff --git a/src/main/kotlin/org/aresclient/ares/impl/util/FriendUtil.kt b/src/main/kotlin/org/aresclient/ares/impl/util/FriendUtil.kt index 55e82753..0c68a47e 100644 --- a/src/main/kotlin/org/aresclient/ares/impl/util/FriendUtil.kt +++ b/src/main/kotlin/org/aresclient/ares/impl/util/FriendUtil.kt @@ -39,7 +39,8 @@ object FriendUtil: Wrapper { } } - data class ProfileLookupResponse(val id: String, val name: String) + private data class ProfileLookupResponse(val id: String, val name: String) + fun getProfileByName(name: String): GameProfile? { val profile = MC.networkHandler?.playerList?.find { it.profile.name == name }?.profile if(profile != null) return profile diff --git a/src/main/kotlin/org/aresclient/ares/impl/util/MathUtil.kt b/src/main/kotlin/org/aresclient/ares/impl/util/MathUtil.kt index 2dfe99aa..678d2ba6 100644 --- a/src/main/kotlin/org/aresclient/ares/impl/util/MathUtil.kt +++ b/src/main/kotlin/org/aresclient/ares/impl/util/MathUtil.kt @@ -10,121 +10,128 @@ import kotlin.math.cos import kotlin.math.sin object MathUtil { - fun Float.getAngleDifference(otherAngle: Float): Float { - var a = this - otherAngle - if (a > 180) a -= 360 - else if (a < -180) a += 360 - return -a - } - - fun Float.lerp(tickProgress: Float, previous: Float): Float { - return if (tickProgress == 1F) this - else MathHelper.lerp(tickProgress, this, previous) - } - - fun Float.lerpAngleDegrees(tickProgress: Float, previous: Float): Float { - return if (tickProgress == 1F) this - else MathHelper.lerpAngleDegrees(tickProgress, this, previous) - } - - fun Float.normalizeAngle(): Float { - var a = this % 360 - if (a >= 180) a -= 360 - if (a < -180) a += 360 - return a - } - - fun Vec2f.normalizeRotation(): Vec2f { - _x = x.normalizeAngle() - _y = y.normalizeAngle() - return this - } - - fun Vec2f.moveCameraWithCursor(event: PlayerEvent.ChangeLookDirection): Vec2f = moveCameraWithCursor(event.cursorDeltaX, event.cursorDeltaY) - fun Vec2f.moveCameraWithCursor(x: Double, y: Double): Vec2f = moveCameraWithCursor(x.toFloat(), y.toFloat()) - fun Vec2f.moveCameraWithCursor(x: Float, y: Float): Vec2f { - _x += 0.15F * x - _y += 0.15F * y - return this - } - - fun Vec2f.duplicate(): Vec2f = Vec2f(this.x, this.y) - fun Vec3d.duplicate(): Vec3d = Vec3d(this.x, this.y, this.z) - - // ──────────────────────────────────────────────────────────────────────── // - - // Was creating a buttload of Vectors so it's probably better to access the values and - // modify them to reduce object creation overhead when just pushing around numbers. - // Also probably reduces GC. Just don't use this to set MC values. - - fun Vec2f.set(vector: Vec2f): Vec2f = (this as AccessMath.Vec2f).let { - setX(vector.x); setY(vector.y) - return this - } - - fun Vec2f.set(x: Float = this.x, y: Float = this.y): Vec2f = (this as AccessMath.Vec2f).let { - setX(x); setY(y) - return this - } - - var Vec2f._x: Float get() = this.x - set(value) = (this as AccessMath.Vec2f).setX(value) - - var Vec2f._y: Float get() = this.y - set(value) = (this as AccessMath.Vec2f).setY(value) - - fun Vec3d.set(vector: Vec3d): Vec3d = (this as AccessMath.Vec3d).let { - setX(vector.x); setY(vector.y); setZ(vector.z) - return this - } - - fun Vec3d.set(x: Double = this.x, y: Double = this.y, z: Double = this.z): Vec3d = (this as AccessMath.Vec3d).let { - setX(x); setY(y); setZ(z) - return this - } - - var Vec3d._x: Double get() = this.x - set(value) = (this as AccessMath.Vec3d).setX(value) - - var Vec3d._y: Double get() = this.y - set(value) = (this as AccessMath.Vec3d).setY(value) - - var Vec3d._z: Double get() = this.z - set(value) = (this as AccessMath.Vec3d).setZ(value) - - // ──────────────────────────────────────────────────────────────────────── // - - private const val PI_2 = Math.PI / 2 - private const val PI_4 = Math.PI / 4 - - /** - * @receiver yaw in degrees - */ - fun Float.toTransverseMovement(speed: Double, forwards: Float, sideways: Float): Vector2d { - return Math.toRadians(this.toDouble()).toTransverseMovement(speed, forwards, sideways) - } - - /** - * @receiver yaw in radians - */ - fun Double.toTransverseMovement(speed: Double, forwards: Float, sideways: Float): Vector2d { - var yaw = this; var forwards = forwards; var sideways = sideways - - if (forwards != 0F) { - if (sideways > 0) yaw += if (forwards > 0) -PI_4 else PI_4 - else if (sideways < 0) yaw += if (forwards > 0) PI_4 else -PI_4 - - sideways = 0F - - if (forwards > 0) forwards = 1F - else if (forwards < 0) forwards = -1F - } - - yaw += PI_2 - - return Vector2d( - forwards * speed * cos(yaw) + sideways * speed * sin(yaw), - forwards * speed * sin(yaw) - sideways * speed * cos(yaw) - ) - } + fun Float.getAngleDifference(otherAngle: Float): Float { + var a = this - otherAngle + if(a > 180) a -= 360 + else if(a < -180) a += 360 + return -a + } + + fun Float.lerp(tickProgress: Float, previous: Float): Float { + return if(tickProgress == 1F) this + else MathHelper.lerp(tickProgress, this, previous) + } + + fun Float.lerpAngleDegrees(tickProgress: Float, previous: Float): Float { + return if(tickProgress == 1F) this + else MathHelper.lerpAngleDegrees(tickProgress, this, previous) + } + + fun Float.normalizeAngle(): Float { + var a = this % 360 + if(a >= 180) a -= 360 + if(a < -180) a += 360 + return a + } + + fun Vec2f.normalizeRotation(): Vec2f { + _x = x.normalizeAngle() + _y = y.normalizeAngle() + return this + } + + fun Vec2f.moveCameraWithCursor(event: PlayerEvent.ChangeLookDirection): Vec2f = moveCameraWithCursor(event.cursorDeltaX, event.cursorDeltaY) + fun Vec2f.moveCameraWithCursor(x: Double, y: Double): Vec2f = moveCameraWithCursor(x.toFloat(), y.toFloat()) + fun Vec2f.moveCameraWithCursor(x: Float, y: Float): Vec2f { + _x += 0.15F * x + _y += 0.15F * y + return this + } + + fun Vec2f.duplicate(): Vec2f = Vec2f(this.x, this.y) + fun Vec3d.duplicate(): Vec3d = Vec3d(this.x, this.y, this.z) + + // ──────────────────────────────────────────────────────────────────────── // + + // Was creating a buttload of Vectors so it's probably better to access the values and + // modify them to reduce object creation overhead when just pushing around numbers. + // Also probably reduces GC. Just don't use this to set MC values. + + fun Vec2f.set(vector: Vec2f): Vec2f = (this as AccessMath.Vec2f).let { + setX(vector.x); setY(vector.y) + return this + } + + fun Vec2f.set(x: Float = this.x, y: Float = this.y): Vec2f = (this as AccessMath.Vec2f).let { + setX(x); setY(y) + return this + } + + var Vec2f._x: Float + get() = this.x + set(value) = (this as AccessMath.Vec2f).setX(value) + + var Vec2f._y: Float + get() = this.y + set(value) = (this as AccessMath.Vec2f).setY(value) + + fun Vec3d.set(vector: Vec3d): Vec3d = (this as AccessMath.Vec3d).let { + setX(vector.x); setY(vector.y); setZ(vector.z) + return this + } + + fun Vec3d.set(x: Double = this.x, y: Double = this.y, z: Double = this.z): Vec3d = (this as AccessMath.Vec3d).let { + setX(x); setY(y); setZ(z) + return this + } + + var Vec3d._x: Double + get() = this.x + set(value) = (this as AccessMath.Vec3d).setX(value) + + var Vec3d._y: Double + get() = this.y + set(value) = (this as AccessMath.Vec3d).setY(value) + + var Vec3d._z: Double + get() = this.z + set(value) = (this as AccessMath.Vec3d).setZ(value) + + // ──────────────────────────────────────────────────────────────────────── // + + private const val PI_2 = Math.PI / 2 + private const val PI_4 = Math.PI / 4 + + /** + * @receiver yaw in degrees + */ + fun Float.toTransverseMovement(speed: Double, forwards: Float, sideways: Float): Vector2d { + return Math.toRadians(this.toDouble()).toTransverseMovement(speed, forwards, sideways) + } + + /** + * @receiver yaw in radians + */ + fun Double.toTransverseMovement(speed: Double, forwards: Float, sideways: Float): Vector2d { + var yaw = this + var forwards = forwards + var sideways = sideways + + if(forwards != 0F) { + if(sideways > 0) yaw += if(forwards > 0) -PI_4 else PI_4 + else if(sideways < 0) yaw += if(forwards > 0) PI_4 else -PI_4 + + sideways = 0F + + if(forwards > 0) forwards = 1F + else if(forwards < 0) forwards = -1F + } + + yaw += PI_2 + + return Vector2d( + forwards * speed * cos(yaw) + sideways * speed * sin(yaw), + forwards * speed * sin(yaw) - sideways * speed * cos(yaw) + ) + } } \ No newline at end of file diff --git a/src/main/kotlin/org/aresclient/ares/impl/util/RenderHelper.kt b/src/main/kotlin/org/aresclient/ares/impl/util/RenderHelper.kt index 1f830b0a..a395b8cc 100644 --- a/src/main/kotlin/org/aresclient/ares/impl/util/RenderHelper.kt +++ b/src/main/kotlin/org/aresclient/ares/impl/util/RenderHelper.kt @@ -20,6 +20,7 @@ object RenderHelper: Wrapper { fun getFontRenderer(size: Float, style: Int) = fontRenderers.getOrPut(style) { hashMapOf() } .getOrPut(size) { FontRenderer(font, size, style) } + fun getFontRenderer(size: Float) = getFontRenderer(size, Font.PLAIN) inline fun Buffer.draw(matrixStack: MatrixStack? = null, callback: Buffer.() -> Unit) { diff --git a/src/main/kotlin/org/aresclient/ares/impl/util/Theme.kt b/src/main/kotlin/org/aresclient/ares/impl/util/Theme.kt index 4703c6a3..076bd5d8 100644 --- a/src/main/kotlin/org/aresclient/ares/impl/util/Theme.kt +++ b/src/main/kotlin/org/aresclient/ares/impl/util/Theme.kt @@ -8,12 +8,8 @@ data class Theme(val primary: ColorSetting, val secondary: ColorSetting, val bac companion object { private val SETTING = Ares.SETTINGS.addGroup("Theme") private val THEME = Theme( - SETTING.addColor("Primary", - Color(0.37254903f, 0.019607844f, 0.019607844f, 1f) - ), - SETTING.addColor("Secondary", - Color(0.09803922f, 0.09803922f, 0.09803922f, 1f) - ), + SETTING.addColor("Primary", Color(0.37254903f, 0.019607844f, 0.019607844f, 1f)), + SETTING.addColor("Secondary", Color(0.09803922f, 0.09803922f, 0.09803922f, 1f)), SETTING.addColor("Background", Color(0f, 0f, 0f, 0.9f)), SETTING.addColor("Lightground", Color.WHITE) ) diff --git a/src/main/kotlin/org/aresclient/ares/mixin/accessors/AccessMath.java b/src/main/kotlin/org/aresclient/ares/mixin/accessors/AccessMath.java index 4af9af59..57f29580 100644 --- a/src/main/kotlin/org/aresclient/ares/mixin/accessors/AccessMath.java +++ b/src/main/kotlin/org/aresclient/ares/mixin/accessors/AccessMath.java @@ -5,16 +5,16 @@ import org.spongepowered.asm.mixin.gen.Accessor; public class AccessMath { - @Mixin(net.minecraft.util.math.Vec2f.class) - public interface Vec2f { - @Accessor("x") @Mutable void setX(float value); - @Accessor("y") @Mutable void setY(float value); - } + @Mixin(net.minecraft.util.math.Vec2f.class) + public interface Vec2f { + @Accessor("x") @Mutable void setX(float value); + @Accessor("y") @Mutable void setY(float value); + } - @Mixin(net.minecraft.util.math.Vec3d.class) - public interface Vec3d { - @Accessor("x") @Mutable void setX(double value); - @Accessor("y") @Mutable void setY(double value); - @Accessor("z") @Mutable void setZ(double value); - } + @Mixin(net.minecraft.util.math.Vec3d.class) + public interface Vec3d { + @Accessor("x") @Mutable void setX(double value); + @Accessor("y") @Mutable void setY(double value); + @Accessor("z") @Mutable void setZ(double value); + } } diff --git a/src/main/kotlin/org/aresclient/ares/mixin/accessors/AccessMinecraftClient.java b/src/main/kotlin/org/aresclient/ares/mixin/accessors/AccessMinecraftClient.java index db160315..5e5a7293 100644 --- a/src/main/kotlin/org/aresclient/ares/mixin/accessors/AccessMinecraftClient.java +++ b/src/main/kotlin/org/aresclient/ares/mixin/accessors/AccessMinecraftClient.java @@ -7,5 +7,5 @@ @Mixin(MinecraftClient.class) public interface AccessMinecraftClient { - @Accessor("renderTickCounter") RenderTickCounter.Dynamic getRenderTickCounter(); + @Accessor("renderTickCounter") RenderTickCounter.Dynamic getRenderTickCounter(); } diff --git a/src/main/kotlin/org/aresclient/ares/mixin/accessors/AccessRenderTickCounter.java b/src/main/kotlin/org/aresclient/ares/mixin/accessors/AccessRenderTickCounter.java index 1ed2893b..dbcba07f 100644 --- a/src/main/kotlin/org/aresclient/ares/mixin/accessors/AccessRenderTickCounter.java +++ b/src/main/kotlin/org/aresclient/ares/mixin/accessors/AccessRenderTickCounter.java @@ -7,5 +7,5 @@ @Mixin(RenderTickCounter.Dynamic.class) public interface AccessRenderTickCounter { - @Accessor("tickTime") @Mutable void setTickTime(float value); + @Accessor("tickTime") @Mutable void setTickTime(float value); } diff --git a/src/main/kotlin/org/aresclient/ares/mixin/mixins/MixinCamera.java b/src/main/kotlin/org/aresclient/ares/mixin/mixins/MixinCamera.java index 578485a9..7aa0025d 100644 --- a/src/main/kotlin/org/aresclient/ares/mixin/mixins/MixinCamera.java +++ b/src/main/kotlin/org/aresclient/ares/mixin/mixins/MixinCamera.java @@ -15,34 +15,34 @@ @Mixin(Camera.class) public class MixinCamera implements JWrapper { - @Shadow private boolean thirdPerson; - @Shadow private float lastTickProgress; + @Shadow private boolean thirdPerson; + @Shadow private float lastTickProgress; - @Inject(method = "update", at = @At(value = "RETURN")) - private void onUpdateThirdPerson(BlockView area, Entity focusedEntity, boolean thirdPerson, boolean inverseView, float tickProgress, CallbackInfo ci) { - var b = org.aresclient.ares.impl.instrument.global.Camera.INSTANCE.shouldRenderCharacter(); - if (b == null) return; - this.thirdPerson = b; - } + @Inject(method = "update", at = @At(value = "RETURN")) + private void onUpdateThirdPerson(BlockView area, Entity focusedEntity, boolean thirdPerson, boolean inverseView, float tickProgress, CallbackInfo ci) { + var b = org.aresclient.ares.impl.instrument.global.Camera.INSTANCE.shouldRenderCharacter(); + if (b == null) return; + this.thirdPerson = b; + } - @ModifyArgs(method = "update", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/render/Camera;setPos(DDD)V")) - private void onUpdatePosition(Args args) { - var event = EVENTS.post(new CameraEvent.Position(lastTickProgress, args.get(0), args.get(1), args.get(2))); + @ModifyArgs(method = "update", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/render/Camera;setPos(DDD)V")) + private void onUpdatePosition(Args args) { + var event = EVENTS.post(new CameraEvent.Position(lastTickProgress, args.get(0), args.get(1), args.get(2))); - if (!event.isCancelled()) return; + if (!event.isCancelled()) return; - args.set(0, event.getX()); - args.set(1, event.getY()); - args.set(2, event.getZ()); - } + args.set(0, event.getX()); + args.set(1, event.getY()); + args.set(2, event.getZ()); + } - @ModifyArgs(method = "update", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/render/Camera;setRotation(FF)V")) - private void onUpdateRotation(Args args) { - var event = EVENTS.post(new CameraEvent.Rotation(lastTickProgress, args.get(0), args.get(1))); + @ModifyArgs(method = "update", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/render/Camera;setRotation(FF)V")) + private void onUpdateRotation(Args args) { + var event = EVENTS.post(new CameraEvent.Rotation(lastTickProgress, args.get(0), args.get(1))); - if (!event.isCancelled()) return; + if (!event.isCancelled()) return; - args.set(0, event.getYaw()); - args.set(1, event.getPitch()); - } + args.set(0, event.getYaw()); + args.set(1, event.getPitch()); + } } diff --git a/src/main/kotlin/org/aresclient/ares/mixin/mixins/MixinClientPlayerEntity.java b/src/main/kotlin/org/aresclient/ares/mixin/mixins/MixinClientPlayerEntity.java index c00677c6..30805a6e 100644 --- a/src/main/kotlin/org/aresclient/ares/mixin/mixins/MixinClientPlayerEntity.java +++ b/src/main/kotlin/org/aresclient/ares/mixin/mixins/MixinClientPlayerEntity.java @@ -35,7 +35,7 @@ private void postMotion(CallbackInfo ci) { @Inject(method = "move", at = @At("HEAD"), cancellable = true) private void onMovePlayer(MovementType type, Vec3d movement, CallbackInfo ci) { var event = EVENTS.post(new PlayerEvent.Move(type, MathUtil.INSTANCE.duplicate(movement))); - if (!event.isCancelled()) return; + if(!event.isCancelled()) return; ci.cancel(); super.move(type, event.getMovement()); } diff --git a/src/main/kotlin/org/aresclient/ares/mixin/mixins/MixinEntity.java b/src/main/kotlin/org/aresclient/ares/mixin/mixins/MixinEntity.java index 4caf5733..5135c3a7 100644 --- a/src/main/kotlin/org/aresclient/ares/mixin/mixins/MixinEntity.java +++ b/src/main/kotlin/org/aresclient/ares/mixin/mixins/MixinEntity.java @@ -12,20 +12,20 @@ @Mixin(Entity.class) public class MixinEntity implements JWrapper { - @Inject(method = "changeLookDirection", at = @At("HEAD"), cancellable = true) - private void onChangeLookDirection(double cursorDeltaX, double cursorDeltaY, CallbackInfo ci) { - if ((Object) this != MC.player) return; + @Inject(method = "changeLookDirection", at = @At("HEAD"), cancellable = true) + private void onChangeLookDirection(double cursorDeltaX, double cursorDeltaY, CallbackInfo ci) { + if((Object) this != MC.player) return; - if (EVENTS.post(new PlayerEvent.ChangeLookDirection(cursorDeltaX, cursorDeltaY)).isCancelled()) ci.cancel(); - } + if(EVENTS.post(new PlayerEvent.ChangeLookDirection(cursorDeltaX, cursorDeltaY)).isCancelled()) ci.cancel(); + } - @WrapOperation(method = "updateVelocity", at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/Entity;getYaw()F")) - private float modifyCalcYaw(Entity instance, Operation original) { - if (instance != MC.player) return original.call(instance); + @WrapOperation(method = "updateVelocity", at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/Entity;getYaw()F")) + private float modifyCalcYaw(Entity instance, Operation original) { + if(instance != MC.player) return original.call(instance); - var event = EVENTS.post(new PlayerEvent.UpdateVelocityYaw(MC.player.getYaw())); - if (event.isCancelled()) return event.getYaw(); + var event = EVENTS.post(new PlayerEvent.UpdateVelocityYaw(MC.player.getYaw())); + if(event.isCancelled()) return event.getYaw(); - return original.call(instance); - } + return original.call(instance); + } } diff --git a/src/main/kotlin/org/aresclient/ares/mixin/mixins/MixinKeyboard.java b/src/main/kotlin/org/aresclient/ares/mixin/mixins/MixinKeyboard.java index c34bd733..f934d06b 100644 --- a/src/main/kotlin/org/aresclient/ares/mixin/mixins/MixinKeyboard.java +++ b/src/main/kotlin/org/aresclient/ares/mixin/mixins/MixinKeyboard.java @@ -14,18 +14,18 @@ @Mixin(Keyboard.class) public class MixinKeyboard implements JWrapper { - @Unique private static IntArraySet pressed = new IntArraySet(); + @Unique private static final IntArraySet pressed = new IntArraySet(); @Inject(method = "onKey", at = @At("HEAD"), cancellable = true) public void onKey(long window, int key, int scancode, int action, int modifiers, CallbackInfo ci) { if(window == MinecraftClient.getInstance().getWindow().getHandle()) { if(action == 0) { - if (EVENTS.post(new InputEvent.Keyboard.Released(key)).isCancelled()) ci.cancel(); + if(EVENTS.post(new InputEvent.Keyboard.Released(key)).isCancelled()) ci.cancel(); pressed.remove(key); } else { var isRepeat = pressed.contains(key); - if (EVENTS.post(new InputEvent.Keyboard.Pressed(key, isRepeat)).isCancelled()) ci.cancel(); - if (!isRepeat) pressed.add(key); + if(EVENTS.post(new InputEvent.Keyboard.Pressed(key, isRepeat)).isCancelled()) ci.cancel(); + if(!isRepeat) pressed.add(key); } } } diff --git a/src/main/kotlin/org/aresclient/ares/mixin/mixins/MixinMinecraftClient.java b/src/main/kotlin/org/aresclient/ares/mixin/mixins/MixinMinecraftClient.java index eeb60dae..03a0953a 100644 --- a/src/main/kotlin/org/aresclient/ares/mixin/mixins/MixinMinecraftClient.java +++ b/src/main/kotlin/org/aresclient/ares/mixin/mixins/MixinMinecraftClient.java @@ -5,7 +5,10 @@ import net.minecraft.client.gui.screen.TitleScreen; import net.minecraft.resource.ReloadableResourceManagerImpl; import org.aresclient.ares.api.JWrapper; -import org.aresclient.ares.api.events.*; +import org.aresclient.ares.api.events.Era; +import org.aresclient.ares.api.events.ScreenOpenedEvent; +import org.aresclient.ares.api.events.ShutdownEvent; +import org.aresclient.ares.api.events.TickEvent; import org.aresclient.ares.impl.util.RenderPipelines; import org.spongepowered.asm.mixin.Final; import org.spongepowered.asm.mixin.Mixin; diff --git a/src/main/kotlin/org/aresclient/ares/mixin/mixins/MixinMouse.java b/src/main/kotlin/org/aresclient/ares/mixin/mixins/MixinMouse.java index 981bb846..c838f076 100644 --- a/src/main/kotlin/org/aresclient/ares/mixin/mixins/MixinMouse.java +++ b/src/main/kotlin/org/aresclient/ares/mixin/mixins/MixinMouse.java @@ -14,13 +14,13 @@ @Mixin(Mouse.class) public class MixinMouse implements JWrapper { - @Unique private double realX = -1; + /*@Unique private double realX = -1; @Unique private double realY = -1; @Shadow private double cursorDeltaX; - @Shadow private double cursorDeltaY; + @Shadow private double cursorDeltaY;*/ - @Unique private static IntArraySet pressed = new IntArraySet(); + @Unique private static final IntArraySet pressed = new IntArraySet(); @Inject(method = "onMouseButton", at = @At("HEAD")) public void onMouseButton(long window, int button, int action, int mods, CallbackInfo ci) { @@ -31,7 +31,7 @@ public void onMouseButton(long window, int button, int action, int mods, Callbac } else { var isRepeat = pressed.contains(button); EVENTS.post(new InputEvent.Mouse.Pressed(button, isRepeat)); - if (!isRepeat) pressed.add(button); + if(!isRepeat) pressed.add(button); } } }