Skip to content

Commit b8c5bc1

Browse files
committed
re-enable proguard optimizations
1 parent f510275 commit b8c5bc1

File tree

6 files changed

+80
-46
lines changed

6 files changed

+80
-46
lines changed

client/build.gradle.kts

Lines changed: 31 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ dependencies {
2121
implementation(projects.windowsHelper)
2222
implementation(libs.kotlinx.serialization.json)
2323
implementation(libs.ktor.serialization.kotlinx.json)
24-
implementation(libs.ktor.client.okhttp)
24+
implementation(libs.ktor.client.java)
2525
implementation(libs.ktor.client.websockets)
2626
implementation(libs.ktor.client.resources)
2727
implementation(libs.ktor.client.content.negotiation)
@@ -42,6 +42,21 @@ dependencies {
4242
implementation(libs.androidx.lifecycle.viewmodel.compose)
4343
}
4444

45+
val collectProguardConfigs by tasks.registering(Copy::class) {
46+
dependsOn(":windows_helper:jar", ":common:jar")
47+
into(layout.buildDirectory.dir("proguard-files"))
48+
include("META-INF/proguard/*.pro")
49+
eachFile { path = name }
50+
51+
from({
52+
configurations.runtimeClasspath.get().map {
53+
zipTree(it).matching {
54+
include("META-INF/proguard/*.pro")
55+
}
56+
}
57+
})
58+
}
59+
4560
tasks {
4661
val copyDll by registering(Copy::class) {
4762
dependsOn(":windows_helper:compileRust",":windows_helper:generateHeaders")
@@ -54,9 +69,13 @@ tasks {
5469
named("prepareAppResources") {
5570
dependsOn(copyDll)
5671
}
72+
named("proguardReleaseJars") {
73+
dependsOn(collectProguardConfigs)
74+
}
5775
}
5876
}
5977

78+
6079
compose {
6180
resources {
6281
packageOfResClass = "dev.schlaubi.mastermind.resources"
@@ -67,10 +86,13 @@ compose {
6786
application {
6887
mainClass = "dev.schlaubi.mastermind.LauncherKt"
6988
jvmArgs("--enable-native-access=ALL-UNNAMED")
89+
// jvmArgs("-agentlib:jdwp=transport=dt_socket,server=y,suspend=y,address=*:5005")
7090

7191
nativeDistributions {
7292
modules(
73-
"java.naming" // required by logback
93+
"java.naming", // required by logback
94+
"java.net.http", // HTTP Client
95+
"jdk.jdi"
7496
)
7597
targetFormats(TargetFormat.Msi)
7698

@@ -93,7 +115,13 @@ compose {
93115
release {
94116
proguard {
95117
version = libs.versions.proguard
96-
configurationFiles.from(project.file("rules.pro"))
118+
obfuscate = false
119+
configurationFiles.from(
120+
fileTree(collectProguardConfigs.map { it.destinationDir }) {
121+
include("*.pro")
122+
},
123+
project.file("rules.pro")
124+
)
97125
}
98126
}
99127
}

client/rules.pro

Lines changed: 17 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,18 @@
1-
# Ktor
2-
-keepclassmembers class io.ktor.** { volatile <fields>; }
3-
-keep class io.ktor.client.engine.okhttp.OkHttpEngineContainer
4-
-keep class io.ktor.serialization.kotlinx.json.KotlinxSerializationJsonExtensionProvider
1+
# References to classes only used if needed
2+
-dontwarn ch.qos.logback.**
3+
-dontwarn io.ktor.network.sockets.**
54

6-
# SLF4j
7-
-keep class org.slf4j.simple.SimpleServiceProvider
8-
-dontwarn io.github.oshai.kotlinlogging.logback.**
5+
-keep,allowshrinking,allowobfuscation class androidx.compose.runtime.* { *; }
96

10-
# serialization
11-
# For some reason if we don't do this, we get a VerifyError at runtime
12-
# Serializer for classes with named companion objects are retrieved using `getDeclaredClasses`.
13-
# If you have any, replace classes with those containing named companion objects.
14-
-keepattributes InnerClasses # Needed for `getDeclaredClasses`.
7+
# ktor
8+
-keep class io.ktor.client.HttpClientEngineContainer
9+
-keep class io.ktor.serialization.kotlinx.json.KotlinxSerializationJsonExtensionProvider
10+
11+
# Hotkeys
12+
-dontwarn dev.schlaubi.mastermind.windows_helper.**
13+
-keep class dev.schlaubi.mastermind.windows_helper.register_keyboard_handler$cb$Function {
14+
void apply(int);
15+
}
1516

1617
# Kotlin serialization looks up the generated serializer classes through a function on companion
1718
# objects. The companions are looked up reflectively so we need to explicitly keep these functions.
@@ -27,17 +28,8 @@
2728
<1>.<2>$Companion Companion;
2829
}
2930

30-
-dontwarn kotlinx.atomicfu.**
31-
-dontwarn io.netty.**
32-
-dontwarn com.typesafe.**
33-
-dontwarn org.slf4j.**
34-
-dontwarn ch.qos.logback.**
35-
-dontwarn okhttp3.**
36-
-dontwarn io.ktor.**
37-
38-
# hotkeys
39-
-dontwarn dev.schlaubi.mastermind.windows_helper.**
40-
-keep class dev.schlaubi.mastermind.windows_helper.** { *; }
31+
# Logback
32+
-keep class org.slf4j.spi.SLF4JServiceProvider
33+
-keep class ch.qos.logback.classic.spi.LogbackServiceProvider
4134

42-
# compose
43-
-dontoptimize
35+
-optimizations !method/specialization/parametertype

client/src/main/kotlin/Launcher.kt

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,29 +7,28 @@ import androidx.compose.material3.CircularProgressIndicator
77
import androidx.compose.material3.MaterialTheme
88
import androidx.compose.material3.Scaffold
99
import androidx.compose.material3.Text
10-
import androidx.compose.runtime.*
10+
import androidx.compose.runtime.getValue
11+
import androidx.compose.runtime.mutableStateOf
12+
import androidx.compose.runtime.remember
13+
import androidx.compose.runtime.setValue
1114
import androidx.compose.ui.Alignment
1215
import androidx.compose.ui.Modifier
1316
import androidx.compose.ui.window.Window
1417
import androidx.compose.ui.window.application
18+
import dev.schlaubi.mastermind.core.KeyBoardListener
1519
import dev.schlaubi.mastermind.core.Updater
16-
import dev.schlaubi.mastermind.core.registerKeyBoardListener
1720
import dev.schlaubi.mastermind.resources.Res
1821
import dev.schlaubi.mastermind.resources.icon
1922
import dev.schlaubi.mastermind.theme.AppTheme
2023
import dev.schlaubi.mastermind.ui.GTAKiller
21-
import dev.schlaubi.mastermind.windows_helper.WindowsAPI
2224
import org.jetbrains.compose.resources.painterResource
2325

2426
fun main() = application {
2527
Updater()
2628
Window(title = "GTA Killer", icon = painterResource(Res.drawable.icon), onCloseRequest = ::exitApplication) {
2729
var loading by remember { mutableStateOf(true) }
30+
KeyBoardListener()
2831
if (loading) {
29-
SideEffect {
30-
WindowsAPI.registerKeyboardHook()
31-
registerKeyBoardListener()
32-
}
3332

3433
AppTheme {
3534
Scaffold {

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

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

3+
import androidx.compose.runtime.Composable
4+
import androidx.compose.runtime.DisposableEffect
5+
import androidx.compose.runtime.SideEffect
36
import dev.schlaubi.mastermind.core.settings.settings
47
import dev.schlaubi.mastermind.util.Loom
58
import dev.schlaubi.mastermind.windows_helper.WindowsAPI
69
import kotlinx.coroutines.Dispatchers
710
import kotlinx.coroutines.runBlocking
11+
import java.lang.foreign.Arena
812

9-
fun registerKeyBoardListener() = WindowsAPI.registerKeyboardListener { keyCode ->
10-
if (keyCode == settings.hotkey) {
11-
runBlocking(Dispatchers.Loom) {
12-
reportAndKill()
13+
@Composable
14+
fun KeyBoardListener() {
15+
SideEffect { WindowsAPI.registerKeyboardHook() }
16+
DisposableEffect(Unit) {
17+
val arena = Arena.ofConfined()
18+
19+
WindowsAPI.registerKeyboardListener(arena) { keyCode ->
20+
if (keyCode == settings.hotkey) {
21+
runBlocking(Dispatchers.Loom) {
22+
reportAndKill()
23+
}
24+
}
25+
}
26+
27+
onDispose {
28+
arena.close()
1329
}
1430
}
1531
}

gradle/libs.versions.toml

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,17 +7,16 @@ proguard = "7.6.1"
77

88
[libraries]
99
kotlinGradlePlugin = { group = "org.jetbrains.kotlin", name = "kotlin-gradle-plugin", version.ref = "kotlin" }
10-
jnativehook = { group = "com.github.kwhat", name = "jnativehook", version = "2.2.2" }
1110

1211
kotlinx-serialization-json = { group = "org.jetbrains.kotlinx", name = "kotlinx-serialization-json", version.ref = "kotlinx-serialization" }
1312
kotlinx-serialization-json-io = { group = "org.jetbrains.kotlinx", name = "kotlinx-serialization-json-io", version.ref = "kotlinx-serialization" }
1413
kotlinx-datetime = { group = "org.jetbrains.kotlinx", name = "kotlinx-datetime", version = "0.6.2" }
15-
kotlinx-io-core = { group = "org.jetbrains.kotlinx", name = "kotlinx-io-core", version = "0.6.0" }
14+
kotlinx-io-core = { group = "org.jetbrains.kotlinx", name = "kotlinx-io-core", version = "0.7.0" }
1615

1716
ktor-resources = { group = "io.ktor", name = "ktor-resources", version.ref = "ktor" }
1817
ktor-http = { group = "io.ktor", name = "ktor-http", version.ref = "ktor" }
1918
ktor-serialization-kotlinx-json = { group = "io.ktor", name = "ktor-serialization-kotlinx-json", version.ref = "ktor" }
20-
ktor-client-okhttp = { group = "io.ktor", name = "ktor-client-okhttp", version.ref = "ktor" }
19+
ktor-client-java = { group = "io.ktor", name = "ktor-client-java", version.ref = "ktor" }
2120
ktor-client-resources = { group = "io.ktor", name = "ktor-client-resources", version.ref = "ktor" }
2221
ktor-client-websockets = { group = "io.ktor", name = "ktor-client-websockets", version.ref = "ktor" }
2322
ktor-client-content-negotiation = { group = "io.ktor", name = "ktor-client-content-negotiation", version.ref = "ktor" }
@@ -32,7 +31,7 @@ androidx-lifecycle-viewmodel-compose = { group = "org.jetbrains.androidx.lifecyc
3231
compose-navigation = { group = "org.jetbrains.androidx.navigation", name = "navigation-compose", version = "2.8.0-alpha13" }
3332

3433
kotlin-logging = { group = "io.github.oshai", name = "kotlin-logging", version = "7.0.4" }
35-
logback-classic = { group = "ch.qos.logback", name = "logback-classic", version = "1.5.16" }
34+
logback-classic = { group = "ch.qos.logback", name = "logback-classic", version = "1.5.17" }
3635

3736
kord-gateway = { group = "dev.kord", name = "kord-gateway", version = "0.15.0" }
3837

windows_helper/src/main/kotlin/Extensions.kt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,13 +48,13 @@ private fun SegmentAllocator.allocateCStrings(vararg values: String) = slice_ref
4848
slice_ref_Vec_uint8.ptr(it, array)
4949
}
5050

51-
object WindowsAPI : Arena by Arena.ofConfined() {
51+
object WindowsAPI {
5252
fun readGtaLocation() = Path(readString(WindowsHelper::read_gta_location))
5353

5454
fun registerKeyboardHook() = WindowsHelper.register_keyboard_hook()
5555

56-
fun registerKeyboardListener(callback: (Int) -> Unit) {
57-
val lambda = `register_keyboard_handler$cb`.allocate({ callback(it) }, this)
56+
fun registerKeyboardListener(arena: Arena, callback: (Int) -> Unit) {
57+
val lambda = `register_keyboard_handler$cb`.allocate({ callback(it) }, arena)
5858
WindowsHelper.register_keyboard_handler(lambda)
5959
}
6060

0 commit comments

Comments
 (0)