diff --git a/GENESYSLauncher/GENESYSLauncher/GENESYSLauncher.csproj b/GENESYSLauncher/GENESYSLauncher/GENESYSLauncher.csproj index 7b2cb42..b75cf26 100644 --- a/GENESYSLauncher/GENESYSLauncher/GENESYSLauncher.csproj +++ b/GENESYSLauncher/GENESYSLauncher/GENESYSLauncher.csproj @@ -47,6 +47,12 @@ False TRACE + + preview + + + preview + 4.0 diff --git a/GENESYSLauncher/GENESYSLauncher/LauncherForm.cs b/GENESYSLauncher/GENESYSLauncher/LauncherForm.cs index f0d06bb..034f3b8 100644 --- a/GENESYSLauncher/GENESYSLauncher/LauncherForm.cs +++ b/GENESYSLauncher/GENESYSLauncher/LauncherForm.cs @@ -99,35 +99,26 @@ void MainFormLoad(object sender, EventArgs e) } else { - if (!Launcher.IsSteamAppInstalled(243730) || !Launcher.IsSteamAppInstalled(243750) || !Launcher.IsSteamAppInstalled(220)) + if (!GlobalVars.HL2SAvail) { - MessageBox.Show("You must own and install a copy of Half-Life 2 or the Source SDK 2013 Base Singleplayer or Multiplayer in order to run " + Launcher.CreateGame(Launcher.GameType.HL2S).Name, Text, MessageBoxButtons.OK, MessageBoxIcon.Error); tabControl1.TabPages.Remove(tabPage1); } } - bool cdv1Available = Launcher.CreateGame(Launcher.GameType.CyberDiver_v1_00).ValidateGamePath(); - if (!cdv1Available) + bool cdv1Available = Launcher.CreateGame(Launcher.GameType.CyberDiver_v1_00).ValidateGamePath(); + bool cdv12Available = Launcher.CreateGame(Launcher.GameType.CyberDiver_v1_20j).ValidateGamePath(); + if (!cdv1Available) { - bool cdv12Available = Launcher.CreateGame(Launcher.GameType.CyberDiver_v1_20j).ValidateGamePath(); if (!cdv12Available) { tabControl1.TabPages.Remove(tabPage2); } - else - { - if (!Launcher.IsSteamAppInstalled(243730) || !Launcher.IsSteamAppInstalled(243750) || (!Launcher.IsSteamAppInstalled(220) && !Launcher.IsSteamAppInstalled(380) && !Launcher.IsSteamAppInstalled(420))) - { - MessageBox.Show("You must own and install a copy of Half-Life 2, Half-Life 2 Episode One, and Half-Life 2 Episode Two, or the Source SDK 2013 Base Singleplayer or Multiplayer in order to run " + Launcher.CreateGame(Launcher.GameType.CyberDiver_v1_20j).Name, Text, MessageBoxButtons.OK, MessageBoxIcon.Error); - tabControl1.TabPages.Remove(tabPage2); - } - } } - else + + if (cdv1Available || cdv12Available) { - if (!Launcher.IsSteamAppInstalled(243730) || !Launcher.IsSteamAppInstalled(243750) || (!Launcher.IsSteamAppInstalled(220) && !Launcher.IsSteamAppInstalled(380) && !Launcher.IsSteamAppInstalled(420))) + if (!GlobalVars.CDAvail) { - MessageBox.Show("You must own and install a copy of Half-Life 2, Half-Life 2 Episode One, and Half-Life 2 Episode Two, or the Source SDK 2013 Base Singleplayer or Multiplayer in order to run " + Launcher.CreateGame(Launcher.GameType.CyberDiver_v1_00).Name, Text, MessageBoxButtons.OK, MessageBoxIcon.Error); tabControl1.TabPages.Remove(tabPage2); } } @@ -139,19 +130,20 @@ void MainFormLoad(object sender, EventArgs e) } else { - if (!Launcher.IsSteamAppInstalled(550)) + if (!GlobalVars.L4DSAvail) { - MessageBox.Show("You must own and install a copy of Left 4 Dead 2 in order to run " + Launcher.CreateGame(Launcher.GameType.L4DS).Name, Text, MessageBoxButtons.OK, MessageBoxIcon.Error); tabControl1.TabPages.Remove(tabPage3); } } if (tabControl1.TabPages.Count <= 0) { - MessageBox.Show("There are no GENESYS games installed. The launcher will now close.", Text, MessageBoxButtons.OK, MessageBoxIcon.Error); + MessageBox.Show("There are no GENESYS games installed or there are no valid requirements. The launcher will now close.", Text, MessageBoxButtons.OK, MessageBoxIcon.Error); Close(); } + tabControl1.TabPages[0].Select(); + switchImage(); GlobalVars.isConsole = false; init = false; @@ -161,17 +153,18 @@ void MainFormLoad(object sender, EventArgs e) // Discord Functionality if (File.Exists(GlobalVars.DiscordDllPath) && Properties.Settings.Default.DiscordIntegration) { + Console.WriteLine("DISCORD: Loaded!"); + GlobalVars.discord = new Discord.Discord(Properties.Settings.Default.DiscordAppID, (System.UInt64)Discord.CreateFlags.NoRequireDiscord); + GlobalVars.discord.SetLogHook(Discord.LogLevel.Debug, (level, message) => + { + Console.WriteLine("Log[{0}] {1}", level, message); + }); + // Pump the event look to ensure all callbacks continue to get fired. //https://stackoverflow.com/questions/17142842/infinite-while-loop-with-form-application-c-sharp continueDiscordThreadLoop = true; discordThread = new Thread(() => { - Console.WriteLine("DISCORD: Loaded!"); - GlobalVars.discord = new Discord.Discord(Properties.Settings.Default.DiscordAppID, (System.UInt64)Discord.CreateFlags.NoRequireDiscord); - GlobalVars.discord.SetLogHook(Discord.LogLevel.Debug, (level, message) => - { - Console.WriteLine("Log[{0}] {1}", level, message); - }); Launcher.UpdateActivity(Launcher.GameType.None); try @@ -193,7 +186,6 @@ void MainFormLoad(object sender, EventArgs e) } catch (Exception) { - } } @@ -218,6 +210,7 @@ void TabControl1IndexChanged(object sender, EventArgs e) switchImage(); Properties.Settings.Default.LastSelectedTabIndex = tabControl1.SelectedIndex; Properties.Settings.Default.Save(); + Properties.Settings.Default.Reload(); } void switchImage() diff --git a/GENESYSLauncher/GENESYSLauncher/LauncherFuncs.cs b/GENESYSLauncher/GENESYSLauncher/LauncherFuncs.cs index 6f318d9..8be8fe0 100644 --- a/GENESYSLauncher/GENESYSLauncher/LauncherFuncs.cs +++ b/GENESYSLauncher/GENESYSLauncher/LauncherFuncs.cs @@ -90,12 +90,14 @@ public static void WriteString(string setting, string value) { Properties.Settings.Default[setting] = value; Properties.Settings.Default.Save(); + Properties.Settings.Default.Reload(); } public static void WriteBool(string setting, bool value) { Properties.Settings.Default[setting] = value; Properties.Settings.Default.Save(); + Properties.Settings.Default.Reload(); } } @@ -342,7 +344,14 @@ public static void LaunchGame(GameType gameToLaunch) if (gameClass.ValidateGamePath()) { - UpdateActivity(gameToLaunch); + try + { + UpdateActivity(gameToLaunch); + } + catch (Exception) + { + + } var processInfo = new ProcessStartInfo(); processInfo.WorkingDirectory = Path.GetDirectoryName(gameClass.GetGamePath()); processInfo.FileName = gameClass.EXEName; @@ -391,11 +400,39 @@ public static long UnixTimeNow() return (long)timeSpan.TotalSeconds; } - public static bool IsSteamAppInstalled(int steamappid) + public static bool IsSteamAppInstalled(string GameFolder) + { + if (Directory.Exists(Settings.ReadString("SteamAppsDir") + "\\" + GameFolder)) + { + return true; + } + else + { + return false; + } + } + + public static bool CheckFolders(string[] folders) { - string path = @"HKEY_CURRENT_USER\Software\Valve\Steam\Apps\" + steamappid.ToString(); - var isInstalled = Registry.GetValue(path, "Installed", null); - return isInstalled != null; + int folderNum = folders.Length; + int validFolderNum = 0; + + foreach (string s in folders) + { + if (IsSteamAppInstalled(s)) + { + validFolderNum++; + } + } + + if (validFolderNum == folderNum) + { + return true; + } + else + { + return false; + } } } @@ -522,7 +559,10 @@ public static class GlobalVars public static Discord.Discord discord = null; public static bool isConsole = true; public static bool isDebug = false; + public static bool CDAvail = false; + public static bool HL2SAvail = false; + public static bool L4DSAvail = false; } - - #endregion + + #endregion } diff --git a/GENESYSLauncher/GENESYSLauncher/Program.cs b/GENESYSLauncher/GENESYSLauncher/Program.cs index 1c6bf8b..2e378a7 100644 --- a/GENESYSLauncher/GENESYSLauncher/Program.cs +++ b/GENESYSLauncher/GENESYSLauncher/Program.cs @@ -7,6 +7,8 @@ * To change this template use Tools | Options | Coding | Edit Standard Headers. */ using System; +using System.Diagnostics; +using System.Runtime.InteropServices; using System.Windows.Forms; namespace GENESYSLauncher @@ -17,6 +19,84 @@ namespace GENESYSLauncher internal sealed class Program { private static string Text = "GENESYS Launcher"; + private static void ValidateHL2S() + { + string[] check1 = { "Source SDK Base 2013 Singleplayer" }; + if (!Launcher.CheckFolders(check1)) + { + string[] check2 = { "Source SDK Base 2013 Multiplayer" }; + if (!Launcher.CheckFolders(check2)) + { + string[] check3 = { "Half-Life 2" }; + if (!Launcher.CheckFolders(check3)) + { + MessageBox.Show("You must own and install a copy of Half-Life 2 or the Source SDK 2013 Base Singleplayer or Multiplayer in order to run " + Launcher.CreateGame(Launcher.GameType.HL2S).Name, Text, MessageBoxButtons.OK, MessageBoxIcon.Error); + } + else + { + Console.WriteLine("FOUND: HL2"); + GlobalVars.HL2SAvail = true; + } + } + else + { + Console.WriteLine("FOUND: SDK 2013 MP"); + GlobalVars.HL2SAvail = true; + } + } + else + { + Console.WriteLine("FOUND: SDK 2013 SP"); + GlobalVars.HL2SAvail = true; + } + } + + private static void ValidateCD() + { + string[] check1 = { "Source SDK Base 2013 Singleplayer" }; + if (!Launcher.CheckFolders(check1)) + { + string[] check2 = { "Source SDK Base 2013 Multiplayer" }; + if (!Launcher.CheckFolders(check2)) + { + string[] check3 = { "Half-Life 2", "Half-Life 2/episodic", "Half-Life 2/ep2" }; + if (!Launcher.CheckFolders(check3)) + { + MessageBox.Show("You must own and install a copy of Half-Life 2, Half-Life 2 Episode One, and Half-Life 2 Episode Two, or the Source SDK 2013 Base Singleplayer or Multiplayer in order to run " + Launcher.CreateGame(Launcher.GameType.CyberDiver_Main).Name, Text, MessageBoxButtons.OK, MessageBoxIcon.Error); + } + else + { + Console.WriteLine("FOUND: HL2 and EPISODES"); + GlobalVars.CDAvail = true; + } + } + else + { + Console.WriteLine("FOUND: SDK 2013 MP"); + GlobalVars.CDAvail = true; + } + } + else + { + Console.WriteLine("FOUND: SDK 2013 SP"); + GlobalVars.CDAvail = true; + } + } + + private static void ValidateL4DS() + { + string[] check4 = { "Left 4 Dead 2" }; + if (!Launcher.CheckFolders(check4)) + { + MessageBox.Show("You must own and install a copy of Left 4 Dead 2 in order to run " + Launcher.CreateGame(Launcher.GameType.L4DS).Name, Text, MessageBoxButtons.OK, MessageBoxIcon.Error); + } + else + { + Console.WriteLine("FOUND: L4D2"); + GlobalVars.L4DSAvail = true; + } + } + /// /// Program entry point. /// @@ -26,6 +106,55 @@ private static void Main(string[] args) Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); + [DllImport("user32.dll")] + static extern IntPtr SetForegroundWindow(IntPtr hWnd); + + [DllImport("user32.dll")] + static extern bool ShowWindow(IntPtr hWnd, int nCmdShow); + + if (string.IsNullOrWhiteSpace(Settings.ReadString("SteamAppsDir"))) + { + MessageBox.Show("Please define your steamapps/common folder", Text, MessageBoxButtons.OK, MessageBoxIcon.Information); + + using (var fbd = new FolderBrowserDialog()) + { + DialogResult result = fbd.ShowDialog(); + + if (result == DialogResult.OK && !string.IsNullOrWhiteSpace(fbd.SelectedPath) && fbd.SelectedPath.Contains("common")) + { + Settings.WriteString("SteamAppsDir", fbd.SelectedPath); + } + else + { + Process currentProcess = Process.GetCurrentProcess(); + IntPtr hWnd = currentProcess.MainWindowHandle; + if (hWnd != IntPtr.Zero) + { + SetForegroundWindow(hWnd); + ShowWindow(hWnd, 5); + } + + MessageBox.Show("Invalid steamapps/common folder. Please relaunch the application and try again.", Text, MessageBoxButtons.OK, MessageBoxIcon.Error); + Environment.Exit(1); + } + } + } + + if (Launcher.CreateGame(Launcher.GameType.HL2S).ValidateGamePath()) + { + ValidateHL2S(); + } + + if (Launcher.CreateGame(Launcher.GameType.CyberDiver_v1_00).ValidateGamePath() || Launcher.CreateGame(Launcher.GameType.CyberDiver_v1_20j).ValidateGamePath()) + { + ValidateCD(); + } + + if (Launcher.CreateGame(Launcher.GameType.L4DS).ValidateGamePath()) + { + ValidateL4DS(); + } + if (args.Length == 0) { Application.Run(new LauncherForm()); @@ -38,12 +167,8 @@ private static void Main(string[] args) { if (Launcher.CreateGame(Launcher.GameType.HL2S).ValidateGamePath()) { - if (!Launcher.IsSteamAppInstalled(243730) || !Launcher.IsSteamAppInstalled(243750) || !Launcher.IsSteamAppInstalled(220)) - { - MessageBox.Show("You must own and install a copy of Half-Life 2 or the Source SDK 2013 Base Singleplayer or Multiplayer in order to run " + Launcher.CreateGame(Launcher.GameType.HL2S).Name, Text, MessageBoxButtons.OK, MessageBoxIcon.Error); - } - else - { + if (GlobalVars.HL2SAvail) + { Launcher.LaunchGame(Launcher.GameType.HL2S); } } @@ -58,11 +183,7 @@ private static void Main(string[] args) { if (Launcher.CreateGame(Launcher.GameType.CyberDiver_v1_00).ValidateGamePath()) { - if (!Launcher.IsSteamAppInstalled(243730) || !Launcher.IsSteamAppInstalled(243750) || (!Launcher.IsSteamAppInstalled(220) && !Launcher.IsSteamAppInstalled(380) && !Launcher.IsSteamAppInstalled(420))) - { - MessageBox.Show("You must own and install a copy of Half-Life 2, Half-Life 2 Episode One, and Half-Life 2 Episode Two, or the Source SDK 2013 Base Singleplayer or Multiplayer in order to run " + Launcher.CreateGame(Launcher.GameType.CyberDiver_v1_00).Name, Text, MessageBoxButtons.OK, MessageBoxIcon.Error); - } - else + if (GlobalVars.CDAvail) { Launcher.LaunchGame(Launcher.GameType.CyberDiver_v1_00); } @@ -78,11 +199,7 @@ private static void Main(string[] args) { if (Launcher.CreateGame(Launcher.GameType.CyberDiver_v1_20j).ValidateGamePath()) { - if (!Launcher.IsSteamAppInstalled(243730) || !Launcher.IsSteamAppInstalled(243750) || (!Launcher.IsSteamAppInstalled(220) && !Launcher.IsSteamAppInstalled(380) && !Launcher.IsSteamAppInstalled(420))) - { - MessageBox.Show("You must own and install a copy of Half-Life 2, Half-Life 2 Episode One, and Half-Life 2 Episode Two, or the Source SDK 2013 Base Singleplayer or Multiplayer in order to run " + Launcher.CreateGame(Launcher.GameType.CyberDiver_v1_20j).Name, Text, MessageBoxButtons.OK, MessageBoxIcon.Error); - } - else + if (GlobalVars.CDAvail) { Launcher.LaunchGame(Launcher.GameType.CyberDiver_v1_20j); } @@ -98,11 +215,7 @@ private static void Main(string[] args) { if (Launcher.CreateGame(Launcher.GameType.L4DS).ValidateGamePath()) { - if (!Launcher.IsSteamAppInstalled(550)) - { - MessageBox.Show("You must own and install a copy of Left 4 Dead 2 in order to run " + Launcher.CreateGame(Launcher.GameType.L4DS).Name, Text, MessageBoxButtons.OK, MessageBoxIcon.Error); - } - else + if (GlobalVars.L4DSAvail) { Launcher.LaunchGame(Launcher.GameType.L4DS); } @@ -141,6 +254,5 @@ private static void Main(string[] args) } } } - } } diff --git a/GENESYSLauncher/GENESYSLauncher/Properties/AssemblyInfo.cs b/GENESYSLauncher/GENESYSLauncher/Properties/AssemblyInfo.cs index d75555b..5413463 100644 --- a/GENESYSLauncher/GENESYSLauncher/Properties/AssemblyInfo.cs +++ b/GENESYSLauncher/GENESYSLauncher/Properties/AssemblyInfo.cs @@ -12,7 +12,7 @@ [assembly: AssemblyTitle("GENESYSLauncher")] [assembly: AssemblyDescription("")] [assembly: AssemblyConfiguration("")] -[assembly: AssemblyCompany("")] +[assembly: AssemblyCompany("Bitl")] [assembly: AssemblyProduct("GENESYSLauncher")] [assembly: AssemblyCopyright("Copyright 2019")] [assembly: AssemblyTrademark("")] diff --git a/GENESYSLauncher/GENESYSLauncher/Properties/Settings.Designer.cs b/GENESYSLauncher/GENESYSLauncher/Properties/Settings.Designer.cs index c2f3004..811c44c 100644 --- a/GENESYSLauncher/GENESYSLauncher/Properties/Settings.Designer.cs +++ b/GENESYSLauncher/GENESYSLauncher/Properties/Settings.Designer.cs @@ -174,5 +174,17 @@ public bool CSNEO_ShowTab { this["CSNEO_ShowTab"] = value; } } + + [global::System.Configuration.UserScopedSettingAttribute()] + [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] + [global::System.Configuration.DefaultSettingValueAttribute("")] + public string SteamAppsDir { + get { + return ((string)(this["SteamAppsDir"])); + } + set { + this["SteamAppsDir"] = value; + } + } } } diff --git a/GENESYSLauncher/GENESYSLauncher/Properties/Settings.settings b/GENESYSLauncher/GENESYSLauncher/Properties/Settings.settings index 539e440..6ab13b1 100644 --- a/GENESYSLauncher/GENESYSLauncher/Properties/Settings.settings +++ b/GENESYSLauncher/GENESYSLauncher/Properties/Settings.settings @@ -41,5 +41,8 @@ False + + + \ No newline at end of file diff --git a/GENESYSLauncher/GENESYSLauncher/app.config b/GENESYSLauncher/GENESYSLauncher/app.config index 89571c9..57a18bc 100644 --- a/GENESYSLauncher/GENESYSLauncher/app.config +++ b/GENESYSLauncher/GENESYSLauncher/app.config @@ -43,6 +43,9 @@ False + + + diff --git a/GENESYSLauncher/GENESYSLauncher/changelog.txt b/GENESYSLauncher/GENESYSLauncher/changelog.txt index 42045db..af8df1d 100644 --- a/GENESYSLauncher/GENESYSLauncher/changelog.txt +++ b/GENESYSLauncher/GENESYSLauncher/changelog.txt @@ -1,3 +1,7 @@ +v2.0.2: +- Fixed an issue where Steam games wouldn't get validated properly. + - You must now define your steamapps/common folder at launch. +- Fixed further stability issues. v2.0.1: - Fixed a security issue involving the command line arguments. v2.0: