Get KSP2 version from game assembly #4034
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Motivation
Based on how KSP1 works, if/when KSP2 is released for Linux someday, it will have a Linux executable called
KSP2.x86_64
instead of a Windows executable calledKSP2_x64.exe
.Since KSP2 has no equivalent of KSP1's
buildID.txt
orreadme.txt
files, we currently get the game version from the Windows executable's assembly properties. This will no longer be viable once there is a Linux release, and so far there is no sign that the KSP2 devs have heard our pleas to create abuildID.txt
equivalent.Changes
Now we get the KSP2 game version by using Mono.Cecil to retrieve the
VersionID.VERSION_TEXT
string constant from<GameRoot>/KSP2_x64_Data/Managed/Assembly-CSharp.dll
(the main assembly for the game). If this doesn't work, we fall back to the previous method of looking for the EXE's properties.Thanks to @cheese3660 for showing us where to find this value. 👍
Caveats:
GameVersion
type only allows 4, so we have to use.Take(4)
to drop the last piece (which is a build ID)KSP2_x64_Data
folder path will probably becomeKSP2_Data
on Linux. At this point I have opted not to overly future-proof this due to the uncertainty of whether that will actually be the case and the complexity of handling multiple folder paths here. If it turns out that we do need this when a Linux port happens, we can tackle it at that point.Fixes #3990.