Skip to content

Commit d121a97

Browse files
committed
Use own Rust dll to avoid admin requirement
1 parent fd8cb21 commit d121a97

File tree

19 files changed

+1019
-119
lines changed

19 files changed

+1019
-119
lines changed

.github/workflows/client.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@ jobs:
1212
with:
1313
distribution: "temurin"
1414
java-version: "23"
15+
- uses: actions-rust-lang/setup-rust-toolchain@v1
16+
with:
17+
cache-workspaces: windows_helper
1518
- uses: gradle/actions/setup-gradle@v4
1619
- run: ./gradlew client:packageReleaseDistributionForCurrentOS
1720
- run: mv 'GTA Killer-*.msi' client.msi

.gitignore

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,4 +118,9 @@ gradle-app.setting
118118

119119
# End of https://www.toptal.com/developers/gitignore/api/intellij+all,gradle
120120

121-
store/
121+
store/
122+
123+
# Added by cargo
124+
125+
/target
126+
windows_helper/target

client/build.gradle.kts

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ plugins {
77
alias(libs.plugins.compose)
88
}
99

10-
version = "1.2.0"
10+
version = "1.3.0"
1111

1212
repositories {
1313
mavenCentral()
@@ -17,8 +17,8 @@ repositories {
1717

1818
dependencies {
1919
implementation(projects.common)
20+
implementation(projects.windowsHelper)
2021
implementation(libs.kotlinx.serialization.json)
21-
implementation(libs.jnativehook)
2222
implementation(libs.ktor.serialization.kotlinx.json)
2323
implementation(libs.ktor.client.okhttp)
2424
implementation(libs.ktor.client.websockets)
@@ -40,15 +40,34 @@ dependencies {
4040
implementation(libs.androidx.lifecycle.viewmodel.compose)
4141
}
4242

43+
tasks {
44+
val copyDll by registering(Copy::class) {
45+
dependsOn(":windows_helper:compileRust",":windows_helper:generateHeaders")
46+
from(project(":windows_helper").layout.projectDirectory.dir("target/release/windows_helper.dll"))
47+
include("*.dll")
48+
into(layout.buildDirectory.dir("dll/common"))
49+
}
50+
51+
afterEvaluate {
52+
named("prepareAppResources") {
53+
dependsOn(copyDll)
54+
}
55+
}
56+
}
57+
4358
compose.desktop {
4459
application {
4560
mainClass = "dev.schlaubi.mastermind.LauncherKt"
61+
jvmArgs("--enable-native-access=ALL-UNNAMED")
62+
4663
nativeDistributions {
4764
modules(
4865
"java.naming" // required by logback
4966
)
5067
targetFormats(TargetFormat.Msi)
5168

69+
appResourcesRootDir.set(layout.buildDirectory.dir("dll"))
70+
5271
licenseFile = rootProject.file("LICENSE")
5372
vendor = "Schlaubi"
5473
description = "GTA kill script"

client/rules.pro

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,8 @@
3636
-dontwarn io.ktor.**
3737

3838
# hotkeys
39-
-keep class com.github.kwhat.jnativehook.** { *; } # Preserve all native hook classes and their methods
39+
-dontwarn dev.schlaubi.mastermind.windows_helper.**
40+
-keep class dev.schlaubi.mastermind.windows_helper.** { *; }
4041

4142
# compose
4243
-dontoptimize

client/src/main/kotlin/Launcher.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
package dev.schlaubi.mastermind
22

33
import androidx.compose.ui.window.singleWindowApplication
4-
import com.github.kwhat.jnativehook.GlobalScreen
54
import dev.schlaubi.mastermind.core.registerKeyBoardListener
65
import dev.schlaubi.mastermind.ui.GTAKiller
6+
import dev.schlaubi.mastermind.windows_helper.WindowsAPI
77

88
fun main() {
9-
GlobalScreen.registerNativeHook()
9+
WindowsAPI.registerKeyboardHook()
1010
registerKeyBoardListener()
1111

1212
singleWindowApplication(title = "GTA Killer") {

client/src/main/kotlin/Main.kt

Lines changed: 0 additions & 96 deletions
This file was deleted.

client/src/main/kotlin/core/KeyBoardListener.kt

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,18 @@
11
package dev.schlaubi.mastermind.core
22

3-
import com.github.kwhat.jnativehook.GlobalScreen
4-
import com.github.kwhat.jnativehook.keyboard.NativeKeyEvent
5-
import com.github.kwhat.jnativehook.keyboard.NativeKeyListener
63
import dev.schlaubi.mastermind.core.settings.settings
74
import dev.schlaubi.mastermind.util.Loom
5+
import dev.schlaubi.mastermind.windows_helper.WindowsAPI
86
import kotlinx.coroutines.Dispatchers
97
import kotlinx.coroutines.runBlocking
108

11-
fun registerKeyBoardListener() = GlobalScreen.addNativeKeyListener(object : NativeKeyListener {
12-
override fun nativeKeyPressed(nativeEvent: NativeKeyEvent) {
13-
if (nativeEvent.keyCode == settings.hotkey) {
14-
runBlocking(Dispatchers.Loom) {
15-
reportAndKill()
16-
}
9+
fun registerKeyBoardListener() = WindowsAPI.registerKeyboardListener { keyCode ->
10+
if (keyCode == settings.hotkey) {
11+
runBlocking(Dispatchers.Loom) {
12+
reportAndKill()
1713
}
1814
}
19-
})
15+
}
2016

2117
suspend fun reportAndKill() {
2218
safeApi.killGta()

client/src/main/kotlin/core/settings/Settings.kt

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,16 @@
11
package dev.schlaubi.mastermind.core.settings
22

3-
import com.github.kwhat.jnativehook.keyboard.NativeKeyEvent
4-
import io.ktor.http.Url
3+
import io.ktor.http.*
54
import kotlinx.serialization.Serializable
65

6+
const val F3_KEY = 113
7+
78
@Serializable
89
data class Settings(
910
val currentUrl: Url?,
1011
val pastUrls: Set<Url>,
1112
val userName: String,
12-
val hotkey: Int = NativeKeyEvent.VC_F3,
13+
val hotkey: Int = F3_KEY,
1314
val tokens: Map<String, String> = emptyMap()
1415
)
1516

client/src/main/kotlin/core/settings/Storage.kt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ package dev.schlaubi.mastermind.core.settings
55
import androidx.compose.runtime.getValue
66
import androidx.compose.runtime.mutableStateOf
77
import androidx.compose.runtime.setValue
8-
import com.github.kwhat.jnativehook.keyboard.NativeKeyEvent
98
import kotlinx.coroutines.sync.Mutex
109
import kotlinx.coroutines.sync.withLock
1110
import kotlinx.io.buffered
@@ -30,7 +29,7 @@ private fun readSettings(): Settings {
3029
if (!fs.exists(file)) {
3130
return Settings(
3231
null, emptySet(), System.getProperty("user.name"),
33-
NativeKeyEvent.VC_F3
32+
F3_KEY
3433
)
3534
}
3635

gradle.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,4 @@ org.gradle.caching=true
44
# Enable the configuration cache to reuse the build configuration and enable parallel task execution.
55
# (Note that some plugins may not yet be compatible with the configuration cache.)
66
# https://docs.gradle.org/current/userguide/configuration_cache.html
7-
org.gradle.configuration-cache=true
7+
org.gradle.configuration-cache=false

0 commit comments

Comments
 (0)