Fractal Softworks Forum

Please login or register.

Login with username, password and session length

Author Topic: Detecting installed Starsector version out-of-game  (Read 1342 times)

AtlanticAccent

  • Lieutenant
  • **
  • Posts: 73
    • View Profile
Detecting installed Starsector version out-of-game
« on: November 02, 2021, 06:09:12 AM »

First off, this is probably more suited to the Modding Tools subforum but I'm not sure how to get posting rights for there.

In the course of developing my mod manager https://fractalsoftworks.com/forum/index.php?topic=21995.0, one thing I've wondered is if I could determine version compatibility between the Starsector version being managed, and the mods being installed/managed. So far though, there doesn't seem to be an obvious way to do so.

Is there a version file I'm missing, or some way to read out the version from the binary itself?
Logged

Jaghaimo

  • Admiral
  • *****
  • Posts: 661
    • View Profile
Re: Detecting installed Starsector version out-of-game
« Reply #1 on: November 03, 2021, 07:28:04 AM »

I don't think so. I would probably implement it myself if I were you, like a map with hashes of starfarer_obf.jar as keys and version as values.
Logged

Alex

  • Administrator
  • Admiral
  • *****
  • Posts: 24128
    • View Profile
Re: Detecting installed Starsector version out-of-game
« Reply #2 on: November 03, 2021, 08:22:43 AM »

Let me add SettingsAPI.getGameVersion() - there, done for the next release. It'll return a string like "0.95a-RC12"; does that cover what's necessary?
Logged

Jaghaimo

  • Admiral
  • *****
  • Posts: 661
    • View Profile
Re: Detecting installed Starsector version out-of-game
« Reply #3 on: November 03, 2021, 08:30:28 AM »

The problem is "external" aspect. The mod manager is written in Rust :)

Perhaps a simple text file with the version? Or have the version present inside jar, say in the manifest file? Then he could unzip it and read from there.
« Last Edit: November 03, 2021, 08:34:38 AM by Jaghaimo »
Logged

Alex

  • Administrator
  • Admiral
  • *****
  • Posts: 24128
    • View Profile
Re: Detecting installed Starsector version out-of-game
« Reply #4 on: November 03, 2021, 10:33:51 AM »

Ah, right! Duh, wasn't thinking, thank you.

Let me exclude com.fs.starfarer.Version and com.fs.starfarer.launcher.VersionInfo from obfuscation. Version in particular has a field named "versionString" which contains the version string, and it seems like it should be possible to extract that out of the binary without *too* much trouble.

(A version text file would probably be better, but this is faster for me to do right now, and also doesn't run the risk of me forgetting to update it. I mean... ideally the game would read the version from that version file, so it wouldn't be an extra place for it, just *the* place, but there are some other considerations that make it inconvenient, such as needing separate version numbers for the in-dev version, and for checking against mods to be able to run them against the dev version, etc...)
Logged

Wyvern

  • Admiral
  • *****
  • Posts: 3803
    • View Profile
Re: Detecting installed Starsector version out-of-game
« Reply #5 on: November 03, 2021, 10:37:54 AM »

The MacOS version of Starsector contains an Info.plist file that has a version string.

I take it that no equivalent exists on other platforms?
Logged
Wyvern is 100% correct about the math.

Alex

  • Administrator
  • Admiral
  • *****
  • Posts: 24128
    • View Profile
Re: Detecting installed Starsector version out-of-game
« Reply #6 on: November 03, 2021, 11:29:24 AM »

Nope!

(And, incidentally, there's been at least a couple of release candidates I've had to scrap because I forgot to update that [redacted] file.)
Logged

AtlanticAccent

  • Lieutenant
  • **
  • Posts: 73
    • View Profile
Re: Detecting installed Starsector version out-of-game
« Reply #7 on: November 04, 2021, 06:27:37 AM »

Fantastic! Thanks so much Alex!
Logged

Alex

  • Administrator
  • Admiral
  • *****
  • Posts: 24128
    • View Profile
Re: Detecting installed Starsector version out-of-game
« Reply #8 on: November 04, 2021, 08:06:40 AM »

*thumbs up*

(Please let me know if this turns out to be inadequate once it's actually out.)
Logged

AtlanticAccent

  • Lieutenant
  • **
  • Posts: 73
    • View Profile
Re: Detecting installed Starsector version out-of-game
« Reply #9 on: December 22, 2021, 08:23:06 AM »

I can confirm that this (mostly) works! I can pull the static version string out of the Version class no problem (I'm using a Java bytecode/class parser instead of actually calling the code). I did run into some errors when parsing Version.class, but I'm putting that down to parsers moving on to more recent versions of Java and losing some compatibility (there may also be a compiler bug in JDK 7 but that possibility only came up in a single random google search).

Whilst we're on the topic, I perused the unobfuscated ModManager.class, and I think there might be a slight bug in the regex
Spoiler
used in
Code
setFromString
The regex used is
Code
\\.|a-RC|a
when I believe it's meant to be
Code
\.|a-RC|a

The former (Regexr example) matches on
Code
"backwards slash followed by anything" OR "a-RC" OR "a"

Whereas the latter (Regexr example) matches
Code
"full stop" OR "a-RC" OR "a"

Sorry if this isn't the right place for this and/or this is intended behaviour.
[close]

Ignore all that I forgot that double escaping is a thing...  :-[
« Last Edit: December 22, 2021, 10:04:17 AM by AtlanticAccent »
Logged