From: js6pak Date: Sun, 4 Oct 2020 14:13:26 +0000 (+0200) Subject: Fix steam proton path detection X-Git-Tag: v1.2.2~113^2~25^2~2^2~1 X-Git-Url: https://git.deb.at/?a=commitdiff_plain;h=dc0fbd7e07bea1e16e5dc3bee157b28f6ba5bd20;p=rhonda%2Fimpostor.git Fix steam proton path detection --- diff --git a/src/Impostor.Client/Core/AmongUsModifier.cs b/src/Impostor.Client/Core/AmongUsModifier.cs index e6f7b6e..94fb7a9 100644 --- a/src/Impostor.Client/Core/AmongUsModifier.cs +++ b/src/Impostor.Client/Core/AmongUsModifier.cs @@ -1,9 +1,13 @@ using System; +using System.Collections.Generic; using System.IO; using System.Linq; using System.Net; using System.Net.Sockets; +using System.Runtime.InteropServices; using System.Threading.Tasks; +using Gameloop.Vdf; +using Gameloop.Vdf.Linq; using Impostor.Client.Core.Events; using Impostor.Shared.Innersloth; using ErrorEventArgs = Impostor.Client.Core.Events.ErrorEventArgs; @@ -12,31 +16,90 @@ namespace Impostor.Client.Core { public class AmongUsModifier { + private const uint AppId = 945360; private const string RegionName = "Impostor"; public const ushort DefaultPort = 22023; - + private readonly string _amongUsDir; private readonly string _regionFile; - + public AmongUsModifier() { var appData = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), "..", "LocalLow"); - var amongUsDir = Path.Combine(appData, "Innersloth", "Among Us"); - _amongUsDir = amongUsDir; - _regionFile = Path.Combine(amongUsDir, "regionInfo.dat"); + if (!Directory.Exists(appData)) + { + appData = FindProtonAppData(); + } + + if (appData == null) + return; + + _amongUsDir = Path.Combine(appData, "Innersloth", "Among Us"); + _regionFile = Path.Combine(_amongUsDir, "regionInfo.dat"); + } + + private string FindProtonAppData() + { + string steamApps; + + if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux)) + { + steamApps = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.UserProfile), ".steam", "steam", "steamapps"); + } + else if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX)) + { + steamApps = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.UserProfile), "Library", "Application Support", "Steam", "steamapps"); + } + else + { + return null; + } + + if (!Directory.Exists(steamApps)) + return null; + + var libraries = new List + { + steamApps + }; + + var vdf = Path.Combine(steamApps, "libraryfolders.vdf"); + if (File.Exists(vdf)) + { + var libraryFolders = VdfConvert.Deserialize(File.ReadAllText(vdf)); + + foreach (var libraryFolder in libraryFolders.Value.Children()) + { + if (!int.TryParse(libraryFolder.Key, out _)) + continue; + + libraries.Add(Path.Combine(libraryFolder.Value.Value(), "steamapps")); + } + } + + foreach (var library in libraries) + { + var path = Path.Combine(library, "compatdata", AppId.ToString(), "pfx", "drive_c", "users", "steamuser", "AppData", "LocalLow"); + if (Directory.Exists(path)) + { + return path; + } + } + + return null; } - + public async Task SaveIp(string input) { // Filter out whitespace. input = input.Trim(); - + // Split port from ip. // Only IPv4 is supported so just do it simple. var ip = string.Empty; var port = DefaultPort; - + var parts = input.Split(':'); if (parts.Length >= 1) { @@ -47,7 +110,7 @@ namespace Impostor.Client.Core { ushort.TryParse(parts[1], out port); } - + // Check if a valid IP address was entered. if (!IPAddress.TryParse(ip, out var ipAddress)) { @@ -60,7 +123,7 @@ namespace Impostor.Client.Core OnError("Invalid IP Address entered"); return; } - + // Use first IPv4 result. ipAddress = hostAddresses.First(x => x.AddressFamily == AddressFamily.InterNetwork); } @@ -70,7 +133,7 @@ namespace Impostor.Client.Core return; } } - + // Only IPv4. if (ipAddress.AddressFamily == AddressFamily.InterNetworkV6) { @@ -88,18 +151,18 @@ namespace Impostor.Client.Core /// private void WriteIp(IPAddress ipAddress, ushort port) { - if (ipAddress == null || + if (ipAddress == null || ipAddress.AddressFamily != AddressFamily.InterNetwork) { throw new ArgumentException(nameof(ipAddress)); } - + if (!Directory.Exists(_amongUsDir)) { OnError("Among Us directory was not found, is it installed? Try running it once."); return; } - + using (var file = File.Open(_regionFile, FileMode.Create, FileAccess.Write)) using (var writer = new BinaryWriter(file)) { @@ -108,7 +171,7 @@ namespace Impostor.Client.Core { new ServerInfo($"{RegionName}-Master-1", ip, port) }); - + region.Serialize(writer); OnSaved(ip, port); @@ -122,7 +185,7 @@ namespace Impostor.Client.Core public bool TryLoadIp(out string ipAddress) { ipAddress = null; - + if (!File.Exists(_regionFile)) { return false; @@ -134,7 +197,7 @@ namespace Impostor.Client.Core var region = RegionInfo.Deserialize(reader); if (region.Name == RegionName && region.Servers.Count >= 1) { - ipAddress = region.Servers[0].Ip; + ipAddress = region.Servers.ElementAt(0).Ip; return true; } } @@ -151,7 +214,7 @@ namespace Impostor.Client.Core { Saved?.Invoke(this, new SavedEventArgs(ipAddress, port)); } - + public event EventHandler Error; public event EventHandler Saved; } diff --git a/src/Impostor.Client/Impostor.Client.csproj b/src/Impostor.Client/Impostor.Client.csproj index c603b6b..b68f8ad 100644 --- a/src/Impostor.Client/Impostor.Client.csproj +++ b/src/Impostor.Client/Impostor.Client.csproj @@ -1,102 +1,27 @@ - - - - - Debug - AnyCPU - {804CF172-0C87-4423-9688-BD97D549891E} - WinExe - Impostor.Client - Impostor - v4.5.2 - 512 - true - true - - - AnyCPU - true - full - false - bin\Debug\ - DEBUG;TRACE - prompt - 4 - - - AnyCPU - none - true - bin\Release\ - TRACE - prompt - 4 - - - Impostor.Client.Program - - - icon.ico - - - - - - - - - - - - - - - - - - - - - Form - - - FrmMain.cs - - - - - FrmMain.cs - - - ResXFileCodeGenerator - Resources.Designer.cs - Designer - - - True - Resources.resx - - - SettingsSingleFileGenerator - Settings.Designer.cs - - - True - Settings.settings - True - - - - - - - - {1d109a96-fadf-41b9-a845-457a7a5c0c5a} - Impostor.Shared - - - - - - + + + {804CF172-0C87-4423-9688-BD97D549891E} + WinExe + Impostor + net462 + Impostor + Impostor + Copyright © AeonLucid 2020 + icon.ico + + true + true + + + + none + + + + + + + + + \ No newline at end of file diff --git a/src/Impostor.Client/Properties/AssemblyInfo.cs b/src/Impostor.Client/Properties/AssemblyInfo.cs deleted file mode 100644 index 4f318b8..0000000 --- a/src/Impostor.Client/Properties/AssemblyInfo.cs +++ /dev/null @@ -1,36 +0,0 @@ -using System.Reflection; -using System.Runtime.CompilerServices; -using System.Runtime.InteropServices; - -// General Information about an assembly is controlled through the following -// set of attributes. Change these attribute values to modify the information -// associated with an assembly. -[assembly: AssemblyTitle("Impostor")] -[assembly: AssemblyDescription("")] -[assembly: AssemblyConfiguration("")] -[assembly: AssemblyCompany("")] -[assembly: AssemblyProduct("Impostor")] -[assembly: AssemblyCopyright("Copyright © AeonLucid 2020")] -[assembly: AssemblyTrademark("")] -[assembly: AssemblyCulture("")] - -// Setting ComVisible to false makes the types in this assembly not visible -// to COM components. If you need to access a type in this assembly from -// COM, set the ComVisible attribute to true on that type. -[assembly: ComVisible(false)] - -// The following GUID is for the ID of the typelib if this project is exposed to COM -[assembly: Guid("804CF172-0C87-4423-9688-BD97D549891E")] - -// Version information for an assembly consists of the following four values: -// -// Major Version -// Minor Version -// Build Number -// Revision -// -// You can specify all the values or you can default the Build and Revision Numbers -// by using the '*' as shown below: -// [assembly: AssemblyVersion("1.0.*")] -[assembly: AssemblyVersion("1.0.0.0")] -[assembly: AssemblyFileVersion("1.0.0.0")] \ No newline at end of file