Added primitive Steam Game Version detection, and improved handling

This commit is contained in:
Assistant 2019-05-21 04:22:39 -04:00
parent d7479a6295
commit 1d06f82807
8 changed files with 239 additions and 5 deletions

View file

@ -35,6 +35,9 @@
<setting name="GameVersion" serializeAs="String">
<value />
</setting>
<setting name="AllGameVersions" serializeAs="String">
<value />
</setting>
</ModAssistant.Properties.Settings>
<ModAssistant.Settings1>
<setting name="InstallFolder" serializeAs="String">

View file

@ -30,6 +30,14 @@ namespace ModAssistant
public const string MD5Spacer = " ";
}
public static class GameVersions
{
public static Dictionary<string, string> SteamVersions = new Dictionary<string, string>
{
{"3708884", "0.13.2"}
};
}
public static void SendNotify(string message, string title = "Mod Assistant")
{
var notification = new System.Windows.Forms.NotifyIcon()
@ -177,6 +185,59 @@ namespace ModAssistant
return null;
}
public static string GetSteamVersion()
{
string SteamInstall = RegistryKey.OpenBaseKey(RegistryHive.LocalMachine, RegistryView.Registry64)?.OpenSubKey("SOFTWARE")?.OpenSubKey("WOW6432Node")?.OpenSubKey("Valve")?.OpenSubKey("Steam")?.GetValue("InstallPath").ToString();
if (String.IsNullOrEmpty(SteamInstall))
{
SteamInstall = Registry.LocalMachine.OpenSubKey("SOFTWARE")?.OpenSubKey("WOW6432Node")?.OpenSubKey("Valve")?.OpenSubKey("Steam")?.GetValue("InstallPath").ToString();
}
if (String.IsNullOrEmpty(SteamInstall)) return null;
string vdf = Path.Combine(SteamInstall, @"steamapps\libraryfolders.vdf");
if (!File.Exists(@vdf)) return null;
Regex regex = new Regex("\\s\"\\d\"\\s+\"(.+)\"");
List<string> SteamPaths = new List<string>();
SteamPaths.Add(Path.Combine(SteamInstall, @"steamapps"));
using (StreamReader reader = new StreamReader(@vdf))
{
string line;
while ((line = reader.ReadLine()) != null)
{
Match match = regex.Match(line);
if (match.Success)
{
SteamPaths.Add(Path.Combine(match.Groups[1].Value.Replace(@"\\", @"\"), @"steamapps"));
}
}
}
regex = new Regex("\\s\"buildid\"\\s+\"(.+)\"");
foreach (string path in SteamPaths)
{
if (File.Exists(Path.Combine(@path, @"appmanifest_" + Constants.BeatSaberAPPID + ".acf")))
{
using (StreamReader reader = new StreamReader(Path.Combine(@path, @"appmanifest_" + Constants.BeatSaberAPPID + ".acf")))
{
string line;
while ((line = reader.ReadLine()) != null)
{
Match match = regex.Match(line);
if (match.Success)
{
string _version;
GameVersions.SteamVersions.TryGetValue(match.Groups[1].Value, out _version);
return _version ?? "";
}
}
}
}
}
return null;
}
public static string GetOculusDir()
{
string OculusInstall = RegistryKey.OpenBaseKey(RegistryHive.LocalMachine, RegistryView.Registry64)?.OpenSubKey("SOFTWARE")?.OpenSubKey("Wow6432Node")?.OpenSubKey("Oculus VR, LLC")?.OpenSubKey("Oculus")?.OpenSubKey("Config")?.GetValue("InitialAppLibrary").ToString();
@ -284,6 +345,19 @@ namespace ModAssistant
return null;
}
public static bool isVoid()
{
string directory = App.BeatSaberInstallDirectory;
if (File.Exists(Path.Combine(directory, "IGG-GAMES.COM.url")) ||
File.Exists(Path.Combine(directory, "SmartSteamEmu.ini")) ||
File.Exists(Path.Combine(directory, "GAMESTORRENT.CO.url")) ||
File.Exists(Path.Combine(directory, "Beat Saber_Data", "Plugins", "BSteam crack.dll")) ||
File.Exists(Path.Combine(directory, "Beat Saber_Data", "Plugins", "HUHUVR_steam_api64.dll")) ||
Directory.GetFiles(Path.Combine(directory, "Beat Saber_Data", "Plugins"), "*.ini", SearchOption.TopDirectoryOnly).Length > 0)
return true;
return false;
}
public static void Download(string link, string output)
{
@ -293,5 +367,24 @@ namespace ModAssistant
byte[] file = webClient.DownloadData(link);
File.WriteAllBytes(output, file);
}
private delegate void ShowMessageBoxDelegate(string Message, string Caption);
private static void ShowMessageBox(string Message, string Caption)
{
MessageBox.Show(Message, Caption);
}
public static void ShowMessageBoxAsync(string Message, string Caption)
{
ShowMessageBoxDelegate caller = new ShowMessageBoxDelegate(ShowMessageBox);
caller.BeginInvoke(Message, Caption, null, null);
}
public static void ShowMessageBoxAsync(string Message)
{
ShowMessageBoxDelegate caller = new ShowMessageBoxDelegate(ShowMessageBox);
caller.BeginInvoke(Message, null, null, null);
}
}
}

View file

@ -49,6 +49,17 @@ namespace ModAssistant
VersionText.Text = App.Version;
if (Utils.isVoid())
{
Main.Content = Invalid.Instance;
MainWindow.Instance.ModsButton.IsEnabled = false;
MainWindow.Instance.OptionsButton.IsEnabled = false;
MainWindow.Instance.IntroButton.IsEnabled = false;
MainWindow.Instance.AboutButton.IsEnabled = false;
MainWindow.Instance.GameVersionsBox.IsEnabled = false;
return;
}
Main.Content = Intro.Instance;
List<string> versions;
@ -64,14 +75,11 @@ namespace ModAssistant
using (Stream stream = response.GetResponseStream())
using (StreamReader reader = new StreamReader(stream))
{
var serializer = new JavaScriptSerializer();
JavaScriptSerializer serializer = new JavaScriptSerializer();
versions = serializer.Deserialize<string[]>(reader.ReadToEnd()).ToList();
}
if (!String.IsNullOrEmpty(Properties.Settings.Default.GameVersion) && versions.Contains(Properties.Settings.Default.GameVersion))
GameVersion = Properties.Settings.Default.GameVersion;
else
GameVersion = versions[versions.Count - 1];
GameVersion = GetGameVersion(versions);
GameVersionsBox.ItemsSource = versions;
GameVersionsBox.SelectedValue = GameVersion;
@ -88,6 +96,29 @@ namespace ModAssistant
}
}
private string GetGameVersion(List<string> versions)
{
if (App.BeatSaberInstallType == "Steam")
{
string steamVersion = Utils.GetSteamVersion();
if (!String.IsNullOrEmpty(steamVersion) && versions.Contains(steamVersion))
return steamVersion;
}
string versionsString = String.Join(",", versions.ToArray());
if (Properties.Settings.Default.AllGameVersions != versionsString)
{
Properties.Settings.Default.AllGameVersions = versionsString;
Properties.Settings.Default.Save();
Utils.ShowMessageBoxAsync("It looks like there's been a game update.\n\nPlease double check that the correct version is selected at the bottom left corner!", "New Game Version Detected!");
return versions[0];
}
if (!String.IsNullOrEmpty(Properties.Settings.Default.GameVersion) && versions.Contains(Properties.Settings.Default.GameVersion))
return Properties.Settings.Default.GameVersion;
return versions[0];
}
private void ModsButton_Click(object sender, RoutedEventArgs e)
{
Main.Content = Mods.Instance;

View file

@ -69,6 +69,9 @@
<DependentUpon>Intro.xaml</DependentUpon>
</Compile>
<Compile Include="Classes\Mod.cs" />
<Compile Include="Pages\Invalid.xaml.cs">
<DependentUpon>Invalid.xaml</DependentUpon>
</Compile>
<Compile Include="Pages\Mods.xaml.cs">
<DependentUpon>Mods.xaml</DependentUpon>
</Compile>
@ -93,6 +96,10 @@
<DependentUpon>MainWindow.xaml</DependentUpon>
<SubType>Code</SubType>
</Compile>
<Page Include="Pages\Invalid.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
<Page Include="Pages\Mods.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>

View file

@ -0,0 +1,48 @@
<Page x:Class="ModAssistant.Pages.Invalid"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:local="clr-namespace:ModAssistant.Pages"
mc:Ignorable="d"
d:DesignHeight="629" d:DesignWidth="1182"
Title="Invalid">
<Grid HorizontalAlignment="Center" VerticalAlignment="Center">
<Grid.RowDefinitions>
<RowDefinition Height="auto"/>
<RowDefinition Height="auto"/>
<RowDefinition Height="auto"/>
<RowDefinition Height="auto"/>
<RowDefinition Height="auto"/>
<RowDefinition Height="auto"/>
</Grid.RowDefinitions>
<TextBlock VerticalAlignment="Center" HorizontalAlignment="Left" FontSize="48" Margin="0">Invalid Installation Detected</TextBlock>
<TextBlock Grid.Row="1" FontWeight="Bold" Margin="0" FontSize="28">Your game installation is corrupted or otherwise invalid</TextBlock>
<TextBlock Grid.Row="2" Margin="0,5" FontSize="16" TextWrapping="Wrap">This can happen if your copy of the game is pirated, or if you copied a pirated copy over your legit install</TextBlock>
<TextBlock Grid.Row="3" Margin="15,5" FontSize="16" TextWrapping="Wrap">
If your copy of the game is pirated,
<Bold>please purchase the game
<Hyperlink NavigateUri="https://beatgames.com/" RequestNavigate="Hyperlink_RequestNavigate">
HERE
</Hyperlink>.
</Bold>
</TextBlock>
<TextBlock Grid.Row="4" Margin="15,5" FontSize="16" TextWrapping="Wrap">
If your copy of the game is <Bold>not</Bold> pirated, please
<Hyperlink NavigateUri="https://bsmg.wiki/support#clean-installation" RequestNavigate="Hyperlink_RequestNavigate">
do a clean install
</Hyperlink>.
</TextBlock>
<TextBlock Grid.Row="5" Margin="15,5" FontSize="16" TextWrapping="Wrap">
If those don't help, ask for support in the <Span Foreground="Blue">#support</Span> channel in
<Hyperlink NavigateUri="https://discord.gg/beatsabermods" RequestNavigate="Hyperlink_RequestNavigate">
BSMG
</Hyperlink>.
</TextBlock>
</Grid>
</Page>

View file

@ -0,0 +1,37 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
namespace ModAssistant.Pages
{
/// <summary>
/// Interaction logic for Invalid.xaml
/// </summary>
public partial class Invalid : Page
{
public static Invalid Instance = new Invalid();
public Invalid()
{
InitializeComponent();
}
private void Hyperlink_RequestNavigate(object sender, RequestNavigateEventArgs e)
{
Process.Start(new ProcessStartInfo(e.Uri.AbsoluteUri));
e.Handled = true;
}
}
}

View file

@ -118,5 +118,17 @@ namespace ModAssistant.Properties {
this["GameVersion"] = value;
}
}
[global::System.Configuration.UserScopedSettingAttribute()]
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
[global::System.Configuration.DefaultSettingValueAttribute("")]
public string AllGameVersions {
get {
return ((string)(this["AllGameVersions"]));
}
set {
this["AllGameVersions"] = value;
}
}
}
}

View file

@ -26,5 +26,8 @@
<Setting Name="GameVersion" Type="System.String" Scope="User">
<Value Profile="(Default)" />
</Setting>
<Setting Name="AllGameVersions" Type="System.String" Scope="User">
<Value Profile="(Default)" />
</Setting>
</Settings>
</SettingsFile>