Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feature] Get game version from DLLs with Mono.Cecil #3990

Closed
HebaruSan opened this issue Jan 1, 2024 · 4 comments · Fixed by #4034
Closed

[Feature] Get game version from DLLs with Mono.Cecil #3990

HebaruSan opened this issue Jan 1, 2024 · 4 comments · Fixed by #4034
Assignees
Labels
Core (ckan.dll) Issues affecting the core part of CKAN Enhancement New features or functionality Linux Issues specific for Linux macOS Issues specific for macOS Mono Issues specific for Mono

Comments

@HebaruSan
Copy link
Member

@cheese3660 made this suggestion in the context of how CKAN gets the version of a game instance, and I have not been able to forget about it:

image

Despite the tongue-sticking-out emoji at the end, this could be a quite good idea:

  • It solves the problem of how to get the game version in a cross-platform way once KSP2_x64.exe is replaced by KSP2.x86_64 on Linux and we can no longer rely on getting properties from a Windows EXE
  • It doesn't require the KSP2 devs to add a separate buildID.txt-style file specifically for us that may or may not be kept accurate and up to date or have a convenient format
  • It's probably the best "source of truth" for the info, given that they're not going to forget to update that part of the game DLL
  • It could also be used for KSP1, replacing the cumbersome IGameVersionProvider / KspBuildIdVersionProvider / KspReadmeVersionProvider family of classes
  • I already used Mono.Cecil in Add test to check GUI thread safety #3914, and it's a nice tool and distributed under an MIT license
@HebaruSan HebaruSan added Enhancement New features or functionality Core (ckan.dll) Issues affecting the core part of CKAN Linux Issues specific for Linux macOS Issues specific for macOS Mono Issues specific for Mono labels Jan 1, 2024
@cheese3660
Copy link

Let me grab cecil and see if I can write a simple version of this as a test

@cheese3660
Copy link

using Mono.Cecil;

Console.Write("Assembly-CSharp Path: ");
var path = Console.ReadLine();
var assembly = AssemblyDefinition.ReadAssembly(path);
var type = assembly.Modules.SelectMany(x => x.GetTypes()).First(x => x.Name == "VersionID" && x.Fields.Any(y => y.Name == "VERSION_TEXT"));
var field = type.Fields.First(x => x.Name == "VERSION_TEXT");
var constant = field.Constant as string;
Console.WriteLine($"Version {constant}");

image

@cheese3660
Copy link

Now let me see if KSP1 has a similar class

@cheese3660
Copy link

Okay, on inspection KSP1 does some wacky stuff with having a Versioning monobehaviour running somewhere that has the version set in its prefab likely, not really fetchable with Mono

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Core (ckan.dll) Issues affecting the core part of CKAN Enhancement New features or functionality Linux Issues specific for Linux macOS Issues specific for macOS Mono Issues specific for Mono
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants