Skip to content

Commit

Permalink
💝 Finish.
Browse files Browse the repository at this point in the history
  • Loading branch information
Tryflle committed Jan 8, 2024
1 parent b73988c commit 8b5aaf5
Show file tree
Hide file tree
Showing 8 changed files with 67 additions and 41 deletions.
27 changes: 27 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# KtLon - A double clicker for Weave
## How do I use KtLon?
1. Download and setup [Weave](https://github.com/tryflle/weaveinstalldocs).
2. Download the mod from the [releases](https://github.com/tryflle/ktlon/releases/latest) page.
3. Put the mod in `~/.weave/mods`.
4. Run the mod with Weave.
## KtLon's commands
- `/ktlon` - Gives help for each command.
- `/ktltoggle` - Toggles the mod on and off. (Default: Off)
- `/ktlbutton` - Sets the button to click. (Default: Left)
- `/ktlcps` - Requires you to click at least 5 CPS in order for the mod to work (Default: Off)
- `/ktlchance` - Sets the chance of the mod clicking. (Default: 50%)
## Frequently Asked Questions
### Why don't I see clicks from KtLon on my CPS counter?
Due to the way that Lunar Client's click counter checks for clicks, it would require me to hook the CPS count in order to add KtLon clicks to the CPS count.
### Will my configuration save once I close the game?
Yes! Your configuration will save once you close the game. The configuration is saved at `~/.weave/config/ktlon.json`.
### Does this have randomization?
Of course, KtLon has randomization built in. Clicks from the mod are sent at a random interval after the last click if your chance succeeds.
### Will this get me banned?
https://tryitands.ee
### How do I build KtLon?
1. Clone the repository or download the source code.
2. Execute the task 'shadowJar' with Gradle.
3. The built jar will be in `build/libs` and be called "KtLon-1.0.0-all.jar"
4. Put the jar in `~/.weave/mods`
5. Run the game with Weave.
7 changes: 5 additions & 2 deletions build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
plugins {
kotlin("jvm") version "1.8.21"
kotlin("jvm") version "1.9.21"
kotlin("plugin.serialization") version "1.9.21"
id("com.github.weave-mc.weave-gradle") version "649dba7468"
id ("java")
id ("com.github.johnrengelman.shadow") version "8.1.1"
}

group = "me.tryfle"
Expand All @@ -18,8 +20,9 @@ dependencies {
compileOnly("com.github.weave-mc:weave-loader:v0.2.4")
compileOnly("org.spongepowered:mixin:0.8.5")
implementation("org.jetbrains.kotlinx:kotlinx-serialization-json:1.6.1")
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core:1.7.3")
}

tasks.compileJava {
options.release.set(17)
}
}
1 change: 1 addition & 0 deletions src/main/kotlin/me/tryfle/ktlon/Init.kt
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import net.weavemc.loader.api.event.EventBus
import net.weavemc.loader.api.event.StartGameEvent

class Init: ModInitializer {

override fun preInit() {
println("[KtLon] Loading..")
Data.loadData()
Expand Down
4 changes: 2 additions & 2 deletions src/main/kotlin/me/tryfle/ktlon/command/Help.kt
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@ import me.tryfle.ktlon.util.Util
class Help: Command("ktlon") {
override fun handle(args: Array<out String>) {
Util.msg("Ktlon - A double clicker for Weave written in Kotlin.")
Util.msg("---------------------------------------------------")
Util.msg("-------------------------------------------------")
Util.msg("Commands:")
Util.msg("/ktlon - Shows this message.")
Util.msg("/ktlcps - Toggles 5 CPS check.")
Util.msg("/ktltoggle - Toggles the mod.")
Util.msg("/ktlbutton - Toggles between LMB and RMB modes.")
Util.msg("/ktlchance (int) - Sets the chance of a double click.")
Util.msg("---------------------------------------------------")
Util.msg("-------------------------------------------------")
}
}
5 changes: 3 additions & 2 deletions src/main/kotlin/me/tryfle/ktlon/command/Toggle.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,16 @@ import me.tryfle.ktlon.config.Data
import me.tryfle.ktlon.listener.ClickListener
import me.tryfle.ktlon.util.Util
import net.weavemc.loader.api.command.Command
import net.weavemc.loader.api.event.EventBus

class Toggle: Command("ktltoggle") {
override fun handle(args: Array<out String>) {
if (Data.instance.enabled) {
Data.instance.enabled = false
ClickListener.disable()
EventBus.unsubscribe(ClickListener())
} else {
Data.instance.enabled = true
ClickListener.enable()
EventBus.subscribe(ClickListener())
}
Util.msg("Ktlon has been " + if (Data.instance.enabled) "enabled" else "disabled" + ".")
Data.saveData(Data.instance)
Expand Down
53 changes: 21 additions & 32 deletions src/main/kotlin/me/tryfle/ktlon/listener/ClickListener.kt
Original file line number Diff line number Diff line change
@@ -1,43 +1,45 @@
package me.tryfle.ktlon.listener

import kotlinx.coroutines.GlobalScope
import kotlinx.coroutines.delay
import kotlinx.coroutines.launch
import me.tryfle.ktlon.config.Data
import me.tryfle.ktlon.util.TimerUtil
import me.tryfle.ktlon.util.Util
import net.minecraft.client.Minecraft
import net.weavemc.loader.api.event.EventBus
import net.minecraft.client.settings.KeyBinding
import net.weavemc.loader.api.event.MouseEvent
import net.weavemc.loader.api.event.SubscribeEvent
import net.weavemc.loader.api.event.TickEvent

import java.awt.*

class ClickListener {

private var cps: Int = 0
private var t: TimerUtil = TimerUtil()
private var r = Robot()
private var shouldClick: Boolean = false

private fun getEventButton(): Int {
return if (Data.loadData().isLmb) 1 else 2
return if (Data.loadData().isLmb) 0 else 1
}

private fun robotGetButton(): Int {
return if (Data.loadData().isLmb) 16 else 4
private fun getButton(): Int {
return if (Data.loadData().isLmb) Minecraft.getMinecraft().gameSettings.keyBindAttack.keyCode
else Minecraft.getMinecraft().gameSettings.keyBindUseItem.keyCode
}

private fun rClick() {
private suspend fun rClick() {
val sleepTime: Long = Util.randInt(30, 60).toLong()
Thread {
shouldClick = if (shouldClick) {
r.mouseRelease(robotGetButton())
r.mousePress(robotGetButton())
Thread.sleep(sleepTime)
r.mouseRelease(robotGetButton())
false
} else true
}
println("[K-Debug] Sleeping for $sleepTime")
if (shouldClick) {
delay(sleepTime)
KeyBinding.setKeyBindState(getButton(), false)
KeyBinding.onTick(getButton())
delay(sleepTime + Util.randInt(-10, 10).toLong())
KeyBinding.setKeyBindState(getButton(), true)
KeyBinding.onTick(getButton())
KeyBinding.setKeyBindState(getButton(), false)
KeyBinding.onTick(getButton())
shouldClick = false
} else shouldClick = true
}

@SubscribeEvent
Expand All @@ -47,12 +49,11 @@ class ClickListener {
if (shouldClick) {
val ch: Double = Math.random() * 100;
if (ch.toInt() >= Data.instance.chance) {
println("[K-Debug] Chance missed, value $ch")
return
}
}
if (Data.instance.fiveCps && cps < 5) return
rClick()
GlobalScope.launch { rClick() }
}
}

Expand All @@ -63,16 +64,4 @@ class ClickListener {
t.reset()
}
}

companion object {
fun disable() {
EventBus.unsubscribe(this)
println("[K-Debug] Disabled ClickListener")
}

fun enable() {
EventBus.subscribe(this)
println("[K-Debug] Enabled ClickListener")
}
}
}
9 changes: 7 additions & 2 deletions src/main/kotlin/me/tryfle/ktlon/listener/WorldLoadListener.kt
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,23 @@ class WorldLoadListener {
fun onWorldLoad(e: WorldEvent.Load) {
if (Data.instance.firstJoin) {
Data.instance.firstJoin = false
Data.instance.enabled = false
Data.instance.isLmb = true
Data.instance.fiveCps = false
Data.instance.chance = 50
Data.saveData(Data.instance)
Util.msg("This is your first time using KtLon! Here's a list of commands.")
Util.msg("---------------------------------------------------")
Util.msg("-------------------------------------------------")
Util.msg("Commands:")
Util.msg("/ktlon - Shows this message.")
Util.msg("/ktlcps - Toggles 5 CPS check.")
Util.msg("/ktltoggle - Toggles the mod.")
Util.msg("/ktlbutton - Toggles between LMB and RMB modes. (Default: LMB)")
Util.msg("/ktlchance (int) - Sets the chance of a double click. (Default: 50)")
Util.msg("---------------------------------------------------")
Util.msg("-------------------------------------------------")
Util.msg("Remember, you can run the command /ktlon at any time to see a list of commands.")
Util.msg("By default, the mod is disabled. You can enable it by running /ktltoggle.")
//unsure of why this message doesn't send but it's whatever, i'll fix it later i guess.
}
EventBus.unsubscribe(this)
}
Expand Down
2 changes: 1 addition & 1 deletion src/main/kotlin/me/tryfle/ktlon/util/TimerUtil.kt
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ class TimerUtil {
fun hasPassed(ms: Long): Boolean {
return getCurrentMS() - lastMS >= ms
}
fun getCurrentMS(): Long {
private fun getCurrentMS(): Long {
return System.nanoTime() / 1000000
}
fun reset() {
Expand Down

0 comments on commit 8b5aaf5

Please sign in to comment.