Skip to content
21 changes: 15 additions & 6 deletions src/main/kotlin/com/lambda/module/hud/FPS.kt
Original file line number Diff line number Diff line change
Expand Up @@ -22,31 +22,40 @@ import com.lambda.event.listener.SafeListener.Companion.listen
import com.lambda.gui.dsl.ImGuiBuilder
import com.lambda.module.HudModule
import com.lambda.module.tag.ModuleTag
import kotlin.time.Duration.Companion.seconds

object FPS : HudModule(
name = "FPS",
description = "Displays your games frames per second",
tag = ModuleTag.HUD
) {
val average by setting("Average", false)
val updateDelay by setting("Update Delay", 50, 0..1000, 1, "Time between updating the fps value")

val frames = mutableListOf<Long>();
var lastUpdated = System.currentTimeMillis()
var lastFrameTime = System.nanoTime()
var fps = 0

init {
listen<RenderEvent.Render> {
val currentTimeNano = System.nanoTime()
var currentFps = 0
if (average) {
frames.add(System.nanoTime() + 1.seconds.inWholeNanoseconds)
frames.removeIf { System.nanoTime() > it }
currentFps = frames.size
} else {
val currentTimeNano = System.nanoTime()
val elapsedNs = currentTimeNano - lastFrameTime
currentFps = if (elapsedNs > 0) (1000000000 / elapsedNs).toInt() else 0
lastFrameTime = currentTimeNano
}

val currentTypeMilli = System.currentTimeMillis()
if (currentTypeMilli - lastUpdated >= updateDelay) {
fps = currentFps
lastUpdated = currentTypeMilli
val elapsedNs = currentTimeNano - lastFrameTime
fps = if (elapsedNs > 0) (1000000000 / elapsedNs).toInt()
else 0
}

lastFrameTime = currentTimeNano
}
}

Expand Down
12 changes: 9 additions & 3 deletions src/main/kotlin/com/lambda/module/hud/ModuleList.kt
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ object ModuleList : HudModule(
name = "ModuleList",
tag = ModuleTag.HUD,
) {
val showKeybind by setting("Show Keybind", true, "Display keybind next to a module")

override val isVisible: Boolean
get() = false

Expand All @@ -38,10 +40,14 @@ object ModuleList : HudModule(
.filter { it.isVisible }

enabled.forEach {
text(it.name); sameLine()
val color = if (it.keybind.key == 0 && it.keybind.mouse == -1) Color.RED else Color.GREEN
text(it.name)

if (showKeybind) {
val color = if (it.keybind.key == 0 && it.keybind.mouse == -1) Color.RED else Color.GREEN

withStyleColor(ImGuiCol.Text, color) { text(" [${it.keybind.name}]") }
sameLine()
withStyleColor(ImGuiCol.Text, color) { text(" [${it.keybind.name}]") }
}
}
}
}
Loading