Skip to content

Commit 9e2fbd1

Browse files
committed
Gta install location improvements
- Propagate rust errors to JVM - Use steam paths
1 parent 32a1dbc commit 9e2fbd1

File tree

7 files changed

+52
-20
lines changed

7 files changed

+52
-20
lines changed

client/build.gradle.kts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ plugins {
88
alias(libs.plugins.buildconfig)
99
}
1010

11-
version = "1.6.4"
11+
version = "1.6.5"
1212

1313
repositories {
1414
mavenCentral()

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

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -34,17 +34,19 @@ suspend fun killGta() {
3434

3535
delay(2.seconds)
3636

37-
if (settings.autostartGta) {
38-
LOG.info { "Restarting GTA5.exe" }
39-
try {
40-
val gtaPath = WindowsAPI.readGtaLocation(version) / version.startBinary
41-
Runtime.getRuntime().exec(arrayOf(gtaPath.absolutePathString()))
42-
} catch (e: Exception) {
43-
_events.emit(Event.RestartError(e))
44-
}
45-
}
4637
} else {
4738
LOG.error { "GTA5.exe not found" }
4839
_events.emit(Event.GtaProcessNotFound(version.process))
4940
}
41+
42+
if (settings.autostartGta) {
43+
LOG.info { "Restarting GTA5.exe" }
44+
try {
45+
val gtaPath = WindowsAPI.readGtaLocation(version) / version.startBinary
46+
Runtime.getRuntime().exec(arrayOf(gtaPath.absolutePathString()))
47+
} catch (e: Exception) {
48+
LOG.error(e) { "Could not restart GTA5.exe" }
49+
_events.emit(Event.RestartError(e))
50+
}
51+
}
5052
}

windows_helper/Cargo.lock

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

windows_helper/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ windows-registry = "0.5.0"
1313
mki = "0.2.3"
1414
once_cell = "1.20.3"
1515
runas = "1.2.0"
16+
log = "0.4.29"
1617

1718
[[bin]]
1819
name = "generate-headers"

windows_helper/build.gradle.kts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ tasks {
8080
"--include-struct", "Vec_uint8",
8181
"--include-struct", "Vec_uint8_t",
8282
"--include-struct", "slice_ref_Vec_uint8",
83+
"--include-struct", "GtaInstallLocationResult",
8384
header,
8485
)
8586
}
Lines changed: 31 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,43 @@
11
use enum_ordinalize::Ordinalize;
2-
use safer_ffi::ffi_export;
32
use safer_ffi::::repr_c;
3+
use safer_ffi::{derive_ReprC, ffi_export};
44
use windows_registry::LOCAL_MACHINE;
5+
use log::debug;
56

67
#[derive(Ordinalize)]
78
enum GTAVersion {
89
Legacy,
910
Enhanced,
1011
}
1112

13+
#[derive_ReprC]
14+
#[repr(C)]
15+
struct GtaInstallLocationResult {
16+
is_error: bool,
17+
content: repr_c::String,
18+
}
19+
1220
#[ffi_export]
13-
fn read_gta_location(gta_version: i8) -> repr_c::String {
21+
fn read_gta_location(gta_version: i8) -> GtaInstallLocationResult {
1422
let version = GTAVersion::from_ordinal(gta_version).unwrap();
15-
let location = _read_gta_location(version).unwrap();
16-
location.into()
23+
24+
match _read_gta_location(version) {
25+
Ok(location) => GtaInstallLocationResult {
26+
is_error: false,
27+
content: location.into(),
28+
},
29+
Err(error) => GtaInstallLocationResult {
30+
is_error: true,
31+
content: error.to_string().into(),
32+
},
33+
}
1734
}
1835

1936
#[ffi_export]
2037
fn detect_version() -> i8 {
2138
match _detect_version() {
2239
None => -1,
23-
Some(version) => version.ordinal()
40+
Some(version) => version.ordinal(),
2441
}
2542
}
2643

@@ -37,17 +54,22 @@ fn _detect_version() -> Option<GTAVersion> {
3754
}
3855
}
3956

40-
fn _read_gta_location(gta_version: GTAVersion) -> windows_registry::Result<String> {
41-
let key = LOCAL_MACHINE.open(gta_version.registry_location())?;
57+
fn _read_gta_location(gta_version: GTAVersion, ) -> windows_registry::Result<String> {
58+
let steam_key = LOCAL_MACHINE.open("SOFTWARE\\WOW6432Node\\Rockstar Games\\Steam");
59+
let is_steam = steam_key.is_ok();
60+
debug!("Reading GTA V install location, version: {}, is_steam: {}", gta_version, is_steam);
61+
62+
let key = LOCAL_MACHINE.open(gta_version.registry_location(is_steam))?;
4263

4364
key.get_string("InstallFolder")
4465
}
4566

4667
impl GTAVersion {
47-
fn registry_location(&self) -> &str {
68+
fn registry_location(&self, is_steam: bool) -> &str {
4869
match self {
70+
GTAVersion::Enhanced if !is_steam => "SOFTWARE\\WOW6432Node\\Rockstar Games\\GTAV Enhanced",
71+
GTAVersion::Enhanced => "SOFTWARE\\WOW6432Node\\Rockstar Games\\GTA V Enhanced",
4972
GTAVersion::Legacy => "SOFTWARE\\WOW6432Node\\Rockstar Games\\Grand Theft Auto V",
50-
GTAVersion::Enhanced => "SOFTWARE\\WOW6432Node\\Rockstar Games\\GTAV Enhanced"
5173
}
5274
}
5375
}

windows_helper/src/main/kotlin/Extensions.kt

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,12 @@ private fun SegmentAllocator.allocateCStrings(vararg values: String) = slice_ref
5050

5151
object WindowsAPI {
5252
fun readGtaLocation(version: GTAVersion) = Arena.ofConfined().use {
53-
Path(readString { WindowsHelper.read_gta_location(it, version.ordinal.toByte())})
53+
val result = WindowsHelper.read_gta_location(it, version.ordinal.toByte())
54+
val string = readString { GtaInstallLocationResult.content(result) }
55+
val isError = GtaInstallLocationResult.is_error(result)
56+
57+
if (isError) throw RuntimeException(string)
58+
Path(string)
5459
}
5560

5661
fun registerKeyboardHook() = WindowsHelper.register_keyboard_hook()

0 commit comments

Comments
 (0)