From 24116872ebe5d8bfd4ebce2eba8386799deda33f Mon Sep 17 00:00:00 2001 From: Ethan Lee Date: Thu, 20 Feb 2020 14:05:15 -0500 Subject: [PATCH] Steamworks.NET detection! --- rhys/GetAssemblyVersion.cs | 11 +++++++++++ rhys/build.sh | 3 +++ rhys/rhys | 31 +++++++++++++++++++++++++------ 3 files changed, 39 insertions(+), 6 deletions(-) create mode 100644 rhys/GetAssemblyVersion.cs diff --git a/rhys/GetAssemblyVersion.cs b/rhys/GetAssemblyVersion.cs new file mode 100644 index 0000000..328ce69 --- /dev/null +++ b/rhys/GetAssemblyVersion.cs @@ -0,0 +1,11 @@ +using System; +using System.IO; +using System.Reflection; + +static class GetAssemblyVersion +{ + static void Main(string[] args) + { + Console.Write(Assembly.LoadFile(args[0]).GetName().Version.ToString()); + } +} diff --git a/rhys/build.sh b/rhys/build.sh index 517dfe5..243af57 100755 --- a/rhys/build.sh +++ b/rhys/build.sh @@ -29,6 +29,9 @@ cp ../bin/Release/* fna/ msbuild ../lib-projs/FNA/abi/Microsoft.Xna.Framework.sln /p:Configuration=Release cp ../lib-projs/FNA/abi/bin/Release/* fna/ +# GetAssemblyVersion +csc GetAssemblyVersion.cs -out:fna/GetAssemblyVersion.exe + # fnalibs curl -O http://fna.flibitijibibo.com/archive/fnalibs.tar.bz2 tar xvfj fnalibs.tar.bz2 lib64 diff --git a/rhys/rhys b/rhys/rhys index b86b0a0..77aeb4e 100755 --- a/rhys/rhys +++ b/rhys/rhys @@ -8,9 +8,12 @@ import sys rhys_version = "20.02" basedir = os.path.dirname(sys.argv[0]) gamedir = os.path.dirname(sys.argv[2]) +gamesw = os.path.join(gamedir, "Steamworks.NET.dll") libdir = basedir + "/fnalibs" gacdir = basedir + "/fna" +swdir = basedir + "/Steamworks.NET" mono_path = "/usr/bin/mono" +gav_path = os.path.join(gacdir, "GetAssemblyVersion.exe") ld_path_var = "LD_LIBRARY_PATH" mono_path_var = "MONO_PATH" @@ -26,30 +29,41 @@ def append_ldpath(path): os.environ[ld_path_var] = path def steamworks(): - swversion = None - # TODO: Detect Steamworks.NET version - if (swversion == None): - return - sw_path_var = os.path.join(swdir, swversion) - append_ldpath(sw_path_var) + # Does this game use Steamworks.NET? + if not os.path.exists(gamesw): + return; + # Dump AssemblyVersion from game's DLL + gav = subprocess.Popen([mono_path, gav_path, gamesw], stdout=subprocess.PIPE) + swversion = gav.stdout.read().decode('ascii') + # Do we have a match? If so, use our version! + swversionpath = os.path.join(swdir, swversion) + if os.path.exists(swversionpath): + sw_path_var = swversionpath + append_ldpath(sw_path_var) def firsttime(log_file): + # If this file exists, we've been here before processed = os.path.join(gamedir, "RHYS_PROCESSED") if os.path.exists(processed): return # TODO: XnaToFna Windows Mode + # Convert WMV/WMA to OGV/OGG, if user has their own codecs subprocess.call([os.path.join(basedir, "wmpcvt.sh"), gamedir]) + # Replace Steamworks.NET.dll, if applicable if (len(sw_path_var) > 0): swsrc = os.path.join(sw_path_var, "Steamworks.NET.dll") swdst = os.path.join(gamedir, "Steamworks.NET.dll") shutil.copyfile(swsrc, swdst) + # We're done, leave evidence that we've been in the game folder! processed_file = open(processed, "w+") processed_file.write(rhys_version) processed_file.close() def run(): + # Hi Wine! if os.path.basename(str(sys.argv[2])) == "iscriptevaluator.exe": return + # RHYS_LOG writes to ~/steam-$appid.log log_file = None if "SteamGameId" in os.environ: if "RHYS_LOG" in os.environ and nonzero(os.environ["RHYS_LOG"]): @@ -63,14 +77,19 @@ def run(): log_file.write("Command: " + str(sys.argv[2:]) + "\n") log_file.write("======================\n") log_file.flush() + # Check for Steamworks.NET... steamworks() + # ... then do any initial setup... firsttime(log_file) + # ... add fnalibs to the search path... append_ldpath(libdir) + # ... set up the Mono environment variables... if mono_path_var in os.environ: os.environ[mono_path_var] = gacdir + ":" + os.environ[mono_path_var] else: os.environ[mono_path_var] = gacdir os.environ["MONO_IOMAP"] = "all" + # ... run, finally. subprocess.call([mono_path, sys.argv[2]], stderr=log_file, stdout=log_file) if sys.argv[1] == "run":