public GameScan() { InitializeComponent(); SkinHelperFonts.SetFont(Controls); if (Program.UserConfig != null && !string.IsNullOrWhiteSpace(Program.UserConfig.GameFilesPath)) { tb_GamePath.Text = Program.UserConfig.GameFilesPath; } else { tb_GamePath.Text = GameScannnerApi.GetGameFilesRootPath(); } }
public EditorForm() { var path = !string.IsNullOrWhiteSpace(Program.UserConfig.GameFilesPath) ? Program.UserConfig.GameFilesPath : GameScannnerApi.GetGameFilesRootPath(); try { _gameScannner = GameScannnerApi.InstallGameEditor(Program.UserConfig.IsSteamVersion, path); } catch (Exception) { // } InitializeComponent(); SkinHelperFonts.SetFont(Controls); if (_gameScannner != null && DownloadFileUtils.IsConnectedToInternet()) { if (_gameScannner.QuickScan().GetAwaiter().GetResult()) { Btn_Install_Editor.Enabled = false; btn_Browse.Enabled = true; label2.Text = @"Installed"; label2.ForeColor = Color.Green; _isAutoRun = true; } else { label2.Text = @"Non-Installed Or Outdated"; label2.ForeColor = Color.Red; Btn_Install_Editor.Enabled = true; btn_Browse.Enabled = false; } } else { Btn_Install_Editor.Enabled = true; btn_Browse.Enabled = true; label2.Text = @"Unknow"; label2.ForeColor = Color.OrangeRed; } }
public GameScan() { InitializeComponent(); SkinHelper.SetFont(Controls); if (Program.UserConfig != null && !string.IsNullOrEmpty(Program.UserConfig.GameFilesPath)) { tb_GamePath.Text = Program.UserConfig.GameFilesPath; } else { tb_GamePath.Text = GameScannnerApi.GetGameFilesRootPath(); } if (Program.UserConfig != null && Program.UserConfig.IsLegacyXLive) { rB_Legacy.Checked = true; } else { rB_Sparta.Checked = true; } }
private static void Main() { Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); var mutex = new Mutex(true, AppName, out bool createdNew); //Only one instance if (!createdNew) { MsgBox.ShowMessage( $@"""Celeste Fan Project Launcher"" v{ Assembly.GetEntryAssembly().GetName().Version } already running!", "Celeste Fan Project", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } // Thread.CurrentThread.CurrentCulture = new CultureInfo("en-US"); //Load UserConfig try { if (File.Exists(UserConfigFilePath)) { UserConfig = UserConfig.Load(UserConfigFilePath); } } catch (Exception) { // } try { if (string.IsNullOrEmpty(UserConfig.GameFilesPath)) { UserConfig.GameFilesPath = GameScannnerApi.GetGameFilesRootPath(); } } catch (Exception) { // } //Check if Steam Version try { UserConfig.IsSteamVersion = Assembly.GetEntryAssembly().Location .EndsWith("AOEOnline.exe", StringComparison.OrdinalIgnoreCase); } catch (Exception) { // } //Init WebSocketApi WebSocketApi = new WebSocketApi(UserConfig.ServerUri); //Start Gui Application.Run(new MainForm()); GC.KeepAlive(mutex); }
private async void Btn_Play_Click(object sender, EventArgs e) { btn_Play.Enabled = false; var pname = Process.GetProcessesByName("spartan"); if (pname.Length > 0) { MsgBox.ShowMessage(@"Game already running!"); btn_Play.Enabled = true; return; } //QuickGameScan try { var gameFilePath = !string.IsNullOrWhiteSpace(Program.UserConfig.GameFilesPath) ? Program.UserConfig.GameFilesPath : GameScannnerApi.GetGameFilesRootPath(); var gameScannner = new GameScannnerApi(gameFilePath, Program.UserConfig.IsSteamVersion, Program.UserConfig.IsLegacyXLive); retry: if (!await gameScannner.QuickScan()) { bool success; using (var form = new MsgBoxYesNo( @"Error: Your game files are corrupted or outdated. Click ""Yes"" to run a ""Game Scan"" to fix your game files, or ""No"" to ignore the error (not recommended).") ) { var dr = form.ShowDialog(); if (dr == DialogResult.OK) { using (var form2 = new GameScan()) { form2.ShowDialog(); success = false; } } else { success = true; } } if (!success) { goto retry; } } } catch (Exception ex) { MsgBox.ShowMessage( $"Warning: Error during quick scan. Error message: {ex.Message}", @"Celeste Fan Project", MessageBoxButtons.OK, MessageBoxIcon.Warning); } //isSteam if (!Program.UserConfig.IsSteamVersion) { var steamApiDll = $"{Program.UserConfig.GameFilesPath}\\steam_api.dll"; if (File.Exists(steamApiDll)) { File.Delete(steamApiDll); } } //MpSettings try { if (Program.UserConfig.MpSettings != null) { if (Program.UserConfig.MpSettings.IsOnline) { Program.UserConfig.MpSettings.PublicIp = Program.CurrentUser.Ip; if (Program.UserConfig.MpSettings.AutoPortMapping) { var mapPortTask = OpenNat.MapPortTask(1000, 1000); try { await mapPortTask; NatDiscoverer.TraceSource.Close(); } catch (AggregateException ex) { NatDiscoverer.TraceSource.Close(); if (!(ex.InnerException is NatDeviceNotFoundException)) { throw; } MsgBox.ShowMessage( "Error: Upnp device not found! Set \"Port mapping\" to manual in \"Mp Settings\" and configure your router.", @"Celeste Fan Project", MessageBoxButtons.OK, MessageBoxIcon.Error); btn_Play.Enabled = true; return; } } } } } catch { MsgBox.ShowMessage( "Error: Upnp device not found! Set \"Port mapping\" to manual in \"Mp Settings\" and configure your router.", @"Celeste Fan Project", MessageBoxButtons.OK, MessageBoxIcon.Error); btn_Play.Enabled = true; return; } try { //Save UserConfig Program.UserConfig.Save(Program.UserConfigFilePath); } catch { // } try { //Launch Game var path = !string.IsNullOrEmpty(Program.UserConfig.GameFilesPath) ? Program.UserConfig.GameFilesPath : GameScannnerApi.GetGameFilesRootPath(); if (!path.EndsWith(Path.DirectorySeparatorChar.ToString())) { path += Path.DirectorySeparatorChar; } var spartanPath = Path.Combine(path, "Spartan.exe"); if (!File.Exists(spartanPath)) { throw new FileNotFoundException("Spartan.exe not found!", spartanPath); } string lang; switch (Program.UserConfig.GameLanguage) { case GameLanguage.deDE: lang = "de-DE"; break; case GameLanguage.enUS: lang = "en-US"; break; case GameLanguage.esES: lang = "es-ES"; break; case GameLanguage.frFR: lang = "fr-FR"; break; case GameLanguage.itIT: lang = "it-IT"; break; case GameLanguage.zhCHT: lang = "zh-CHT"; break; default: throw new ArgumentOutOfRangeException(); } try { if (Program.UserConfig.IsDiagnosticMode) { var procdumpFileName = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "procdump.exe"); const int maxNumOfCrashDumps = 30; if (!File.Exists(procdumpFileName)) { throw new FileNotFoundException("Diagonstic Mode requires procdump.exe (File not Found)", procdumpFileName); } // First ensure that all directories are set var pathToCrashDumpFolder = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments), @"Spartan\MiniDumps"); if (!Directory.Exists(pathToCrashDumpFolder)) { Directory.CreateDirectory(pathToCrashDumpFolder); } // Check for cleanup Directory.GetFiles(pathToCrashDumpFolder) .OrderByDescending(File.GetLastWriteTime) // Sort by age --> old one last .Skip(maxNumOfCrashDumps) // Skip max num crash dumps .ToList() .ForEach(File.Delete); // Remove the rest var excludeExceptions = new[] { "E0434F4D.COM", // .NET native exception "E06D7363.msc", "E06D7363.PAVEEFileLoadException@@", "E0434F4D.System.IO.FileNotFoundException" // .NET managed exception }; var excludeExcpetionsCmd = string.Join(" ", excludeExceptions.Select(elem => "-fx " + elem)); var fullCmdArgs = "-accepteula -mm -e 1 -n 10 " + excludeExcpetionsCmd + " -g -w Spartan.exe \"" + pathToCrashDumpFolder + "\""; // MsgBox.ShowMessage(fullCmd); var startInfo = new ProcessStartInfo(procdumpFileName, fullCmdArgs) { WorkingDirectory = path, CreateNoWindow = true, UseShellExecute = false, RedirectStandardError = true, RedirectStandardOutput = true }; Process.Start(startInfo); } } catch (Exception exception) { MsgBox.ShowMessage( $"Warning: {exception.Message}", @"Celeste Fan Project", MessageBoxButtons.OK, MessageBoxIcon.Warning); } var arg = Program.UserConfig?.MpSettings == null || Program.UserConfig.MpSettings.IsOnline ? $"--email \"{Program.UserConfig.LoginInfo.Email}\" --password \"{Program.UserConfig.LoginInfo.Password}\" --ignore_rest LauncherLang={lang} LauncherLocale=1033" : $"--email \"{Program.UserConfig.LoginInfo.Email}\" --password \"{Program.UserConfig.LoginInfo.Password}\" --online-ip \"{Program.UserConfig.MpSettings.PublicIp}\" --ignore_rest LauncherLang={lang} LauncherLocale=1033"; Process.Start(new ProcessStartInfo(spartanPath, arg) { WorkingDirectory = path }); WindowState = FormWindowState.Minimized; } catch (Exception exception) { MsgBox.ShowMessage( $"Error: {exception.Message}", @"Celeste Fan Project", MessageBoxButtons.OK, MessageBoxIcon.Error); } btn_Play.Enabled = true; }
public static async void StartGame(bool isOffline = false) { var pname = Process.GetProcessesByName("spartan"); if (pname.Length > 0) { MsgBox.ShowMessage(@"Game already running!"); return; } //QuickGameScan if (!isOffline || DownloadFileUtils.IsConnectedToInternet()) { try { var gameFilePath = !string.IsNullOrWhiteSpace(Program.UserConfig.GameFilesPath) ? Program.UserConfig.GameFilesPath : GameScannnerApi.GetGameFilesRootPath(); var gameScannner = new GameScannnerApi(gameFilePath, Program.UserConfig.IsSteamVersion); retry: if (!await gameScannner.QuickScan()) { bool success; using (var form = new MsgBoxYesNo( @"Error: Your game files are corrupted or outdated. Click ""Yes"" to run a ""Game Scan"" to fix your game files, or ""No"" to ignore the error (not recommended).") ) { var dr = form.ShowDialog(); if (dr == DialogResult.OK) { using (var form2 = new GameScan()) { form2.ShowDialog(); success = false; } } else { success = true; } } if (!success) { goto retry; } } } catch (Exception ex) { MsgBox.ShowMessage( $"Warning: Error during quick scan. Error message: {ex.Message}", @"Celeste Fan Project", MessageBoxButtons.OK, MessageBoxIcon.Warning); } } //isSteam if (!Program.UserConfig.IsSteamVersion) { var steamApiDll = Path.Combine(Program.UserConfig.GameFilesPath, "steam_api.dll"); if (File.Exists(steamApiDll)) { File.Delete(steamApiDll); } } //MpSettings if (!isOffline && Program.UserConfig.MpSettings != null) { if (Program.UserConfig.MpSettings.ConnectionType == ConnectionType.Wan) { Program.UserConfig.MpSettings.PublicIp = Program.CurrentUser.Ip; if (Program.UserConfig.MpSettings.PortMappingType == PortMappingType.Upnp) { try { await OpenNat.MapPortTask(1000, 1000); } catch (Exception) { Program.UserConfig.MpSettings.PortMappingType = PortMappingType.NatPunch; MsgBox.ShowMessage( "Error: Upnp device not found! \"UPnP Port Mapping\" has been disabled.", @"Celeste Fan Project", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
private void Btn_RunEditor_Click(object sender, EventArgs e) { try { var pname = Process.GetProcessesByName("editor"); if (pname.Length > 0) { MsgBox.ShowMessage(@"Editor already running!"); return; } btn_Browse.Enabled = false; //Launch Game var path = !string.IsNullOrWhiteSpace(Program.UserConfig.GameFilesPath) ? Program.UserConfig.GameFilesPath : GameScannnerApi.GetGameFilesRootPath(); var spartanPath = Path.Combine(path, "Editor.exe"); if (!File.Exists(spartanPath)) { throw new FileNotFoundException("Editor.exe not found!", spartanPath); } //isSteam if (!Program.UserConfig.IsSteamVersion) { var steamApiDll = Path.Combine(Program.UserConfig.GameFilesPath, "steam_api.dll"); if (File.Exists(steamApiDll)) { File.Delete(steamApiDll); } } // string lang; switch (Program.UserConfig.GameLanguage) { case GameLanguage.deDE: lang = "de-DE"; break; case GameLanguage.enUS: lang = "en-US"; break; case GameLanguage.esES: lang = "es-ES"; break; case GameLanguage.frFR: lang = "fr-FR"; break; case GameLanguage.itIT: lang = "it-IT"; break; case GameLanguage.zhCHT: lang = "zh-CHT"; break; default: throw new ArgumentOutOfRangeException(nameof(Program.UserConfig.GameLanguage), Program.UserConfig.GameLanguage, null); } //SymLink Profile Folder var profileDir = Path.Combine(Environment.GetEnvironmentVariable("userprofile")); var path1 = Path.Combine(profileDir, "Documents", "Age of Empires Online"); var path2 = Path.Combine(profileDir, "Documents", "Spartan"); if (!Directory.Exists(path2)) { Directory.CreateDirectory(path2); } if (Directory.Exists(path1) && (!Misc.IsSymLink(path1, Misc.SymLinkFlag.Directory) || !string.Equals(Misc.GetRealPath(path1), path2, StringComparison.OrdinalIgnoreCase))) { Directory.Delete(path1, true); Misc.CreateSymbolicLink(path1, path2, Misc.SymLinkFlag.Directory); } else { Misc.CreateSymbolicLink(path1, path2, Misc.SymLinkFlag.Directory); } //ExtractAiBarFiles var inputFile = Path.Combine(Program.UserConfig.GameFilesPath, "AI", "AI.bar"); if (!File.Exists(inputFile)) { throw new FileNotFoundException($"File '{inputFile}' not found!", inputFile); } var outputPath = Path.Combine(Program.UserConfig.GameFilesPath, "AI"); using (var fileStream = File.Open(inputFile, FileMode.Open, FileAccess.Read, FileShare.Read)) { using (var binReader = new BinaryReader(fileStream)) { binReader.BaseStream.Seek(284, SeekOrigin.Begin); var filesTableOffset = binReader.ReadUInt32(); binReader.BaseStream.Seek(filesTableOffset, SeekOrigin.Begin); var rootNameLength = binReader.ReadUInt32(); binReader.BaseStream.Seek(rootNameLength * 2, SeekOrigin.Current); var numberOfRootFiles = binReader.ReadUInt32(); for (uint i = 0; i < numberOfRootFiles; i++) { var offset = binReader.ReadInt32(); var fileSize = binReader.ReadInt32(); binReader.BaseStream.Seek(20, SeekOrigin.Current); var lengthFileName = binReader.ReadUInt32(); var fileName = Encoding.Unicode.GetString(binReader.ReadBytes((int)lengthFileName * 2)); var baseDir = Path.GetDirectoryName(fileName) ?? string.Empty; if (baseDir.ToLower().Contains("celeste")) { continue; } var position = binReader.BaseStream.Position; // binReader.BaseStream.Seek(offset, SeekOrigin.Begin); var bytes = binReader.ReadBytes(fileSize); binReader.BaseStream.Seek(position, SeekOrigin.Begin); var str = Encoding.Default.GetString(bytes); if (!str.ToLower().Contains("include \"aimain.xs\";")) { continue; } // var outFile = new FileInfo(Path.Combine(outputPath, fileName)); if (outFile.Exists) { if (outFile.Length == fileSize && Crc32Utils.GetCrc32File(outFile.FullName) == Crc32Utils.GetCrc32FromBytes(bytes)) { continue; } outFile.Delete(); } // var dir = new DirectoryInfo(Path.Combine(outputPath, baseDir)); if (!dir.Exists) { dir.Create(); } if ((dir.Attributes & FileAttributes.Hidden) != FileAttributes.Hidden) { dir.Attributes |= FileAttributes.Hidden; } // File.WriteAllBytes(outFile.FullName, bytes); if ((outFile.Attributes & FileAttributes.ReadOnly) != FileAttributes.ReadOnly) { outFile.Attributes |= FileAttributes.ReadOnly; } } } } // Process.Start( new ProcessStartInfo(spartanPath, $"LauncherLang={lang} LauncherLocale=1033") { WorkingDirectory = path }); WindowState = FormWindowState.Minimized; Close(); } catch (Exception ex) { MsgBox.ShowMessage( $"Error: {ex.Message}", @"Celeste Fan Project", MessageBoxButtons.OK, MessageBoxIcon.Error); btn_Browse.Enabled = true; } }
private void RefreshForm() { try { //Launcher var launcherPath = Assembly.GetEntryAssembly().Location; if (!File.Exists(launcherPath)) { throw new FileNotFoundException("Launcher not found!", launcherPath); } var rule = (StandardRuleWin7)FirewallHelper.FindRule("celeste_launcher_inbound_tcp"); if (rule == null) { l_State_L_In.Text = @"Not Found"; l_State_L_In.ForeColor = Color.Red; } else { if (rule.Protocol != FirewallProtocol.TCP || rule.ApplicationName != launcherPath || rule.LocalPortType != FirewallPortType.All || rule.Direction != FirewallDirection.Inbound) { l_State_L_In.Text = @"Invalid"; l_State_L_In.ForeColor = Color.Red; } else { l_State_L_In.Text = @"Valid"; l_State_L_In.ForeColor = Color.Green; } } rule = (StandardRuleWin7)FirewallHelper.FindRule("celeste_launcher_outbound_tcp"); if (rule == null) { l_State_L_Out.Text = @"Not Found"; l_State_L_Out.ForeColor = Color.Red; } else { if (rule.Protocol != FirewallProtocol.TCP || rule.ApplicationName != launcherPath || rule.LocalPortType != FirewallPortType.All || rule.Direction != FirewallDirection.Outbound) { l_State_L_Out.Text = @"Invalid"; l_State_L_Out.ForeColor = Color.Red; } else { l_State_L_Out.Text = @"Valid"; l_State_L_Out.ForeColor = Color.Green; } } var path = !string.IsNullOrWhiteSpace(Program.UserConfig?.GameFilesPath) ? Program.UserConfig?.GameFilesPath : GameScannnerApi.GetGameFilesRootPath(); var spartanPath = Path.Combine(path, "Spartan.exe"); if (!File.Exists(spartanPath)) { throw new FileNotFoundException("Spartan.exe not found!", spartanPath); } //Spartan var rule1 = (StandardRuleWin7)FirewallHelper.FindRule("celeste_spartan_inbound_tcp"); var rule2 = (StandardRuleWin7)FirewallHelper.FindRule("celeste_spartan_inbound_udp"); if (rule1 == null || rule2 == null) { l_State_S_In.Text = @"Not Found"; l_State_S_In.ForeColor = Color.Red; } else { if (rule1.Protocol != FirewallProtocol.TCP || rule1.ApplicationName != spartanPath || rule1.LocalPortType != FirewallPortType.All || rule1.Direction != FirewallDirection.Inbound || rule2.Protocol != FirewallProtocol.UDP || rule2.ApplicationName != spartanPath || rule2.LocalPortType != FirewallPortType.All || rule2.Direction != FirewallDirection.Inbound) { l_State_S_In.Text = @"Invalid"; l_State_S_In.ForeColor = Color.Red; } else { l_State_S_In.Text = @"Valid"; l_State_S_In.ForeColor = Color.Green; } } rule1 = (StandardRuleWin7)FirewallHelper.FindRule("celeste_spartan_outbound_tcp"); rule2 = (StandardRuleWin7)FirewallHelper.FindRule("celeste_spartan_outbound_udp"); if (rule1 == null || rule2 == null) { l_State_S_Out.Text = @"Not Found"; l_State_S_Out.ForeColor = Color.Red; } else { if (rule1.Protocol != FirewallProtocol.TCP || rule1.ApplicationName != spartanPath || rule1.LocalPortType != FirewallPortType.All || rule1.Direction != FirewallDirection.Outbound || rule2.Protocol != FirewallProtocol.UDP || rule2.ApplicationName != spartanPath || rule2.LocalPortType != FirewallPortType.All || rule2.Direction != FirewallDirection.Outbound) { l_State_S_Out.Text = @"Invalid"; l_State_S_Out.ForeColor = Color.Red; } else { l_State_S_Out.Text = @"Valid"; l_State_S_Out.ForeColor = Color.Green; } } //Port 1000 rule = (StandardRuleWin7)FirewallHelper.FindRule("celeste_port1000_inbound_udp"); if (rule == null) { l_State_MP_In.Text = @"Not Found"; l_State_MP_In.ForeColor = Color.Red; } else { if (rule.Protocol != FirewallProtocol.UDP || rule.LocalPorts.All(key => key != 1000) || rule.LocalPortType != FirewallPortType.Specific || rule.Direction != FirewallDirection.Inbound) { l_State_MP_In.Text = @"Invalid"; l_State_MP_In.ForeColor = Color.Red; } else { l_State_MP_In.Text = @"Valid"; l_State_MP_In.ForeColor = Color.Green; } } rule = (StandardRuleWin7)FirewallHelper.FindRule("celeste_port1000_outbound_udp"); if (rule == null) { l_State_MP_Out.Text = @"Not Found"; l_State_MP_Out.ForeColor = Color.Red; } else { if (rule.Protocol != FirewallProtocol.UDP || rule.LocalPorts.All(key => key != 1000) || rule.LocalPortType != FirewallPortType.Specific || rule.Direction != FirewallDirection.Outbound) { l_State_MP_Out.Text = @"Invalid"; l_State_MP_Out.ForeColor = Color.Red; } else { l_State_MP_Out.Text = @"Valid"; l_State_MP_Out.ForeColor = Color.Green; } } } catch (Exception ex) { MsgBox.ShowMessage( $"Error: {ex.Message}", @"Celeste Fan Project", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
private void Btn_Fix_SpartanRules_Click(object sender, EventArgs e) { Enabled = false; try { var path = !string.IsNullOrWhiteSpace(Program.UserConfig?.GameFilesPath) ? Program.UserConfig?.GameFilesPath : GameScannnerApi.GetGameFilesRootPath(); var spartanPath = Path.Combine(path, "Spartan.exe"); if (!File.Exists(spartanPath)) { throw new FileNotFoundException("Spartan.exe not found!", spartanPath); } //inbound_tcp var rule = FirewallHelper.RuleExist("celeste_spartan_inbound_tcp"); if (rule) { FirewallHelper.RemoveRules("celeste_spartan_inbound_tcp"); } FirewallHelper.AddApplicationRule("celeste_spartan_inbound_tcp", spartanPath, FirewallDirection.Inbound, FirewallProtocol.TCP); //outbound_tcp rule = FirewallHelper.RuleExist("celeste_spartan_outbound_tcp"); if (rule) { FirewallHelper.RemoveRules("celeste_spartan_outbound_tcp"); } FirewallHelper.AddApplicationRule("celeste_spartan_outbound_tcp", spartanPath, FirewallDirection.Outbound, FirewallProtocol.TCP); //inbound_udp rule = FirewallHelper.RuleExist("celeste_spartan_inbound_udp"); if (rule) { FirewallHelper.RemoveRules("celeste_spartan_inbound_udp"); } FirewallHelper.AddApplicationRule("celeste_spartan_inbound_udp", spartanPath, FirewallDirection.Inbound, FirewallProtocol.UDP); //outbound_udp rule = FirewallHelper.RuleExist("celeste_spartan_outbound_udp"); if (rule) { FirewallHelper.RemoveRules("celeste_spartan_outbound_udp"); } FirewallHelper.AddApplicationRule("celeste_spartan_outbound_udp", spartanPath, FirewallDirection.Outbound, FirewallProtocol.UDP); } catch (Exception ex) { MsgBox.ShowMessage( $"Error: {ex.Message}", @"Celeste Fan Project", MessageBoxButtons.OK, MessageBoxIcon.Error); } RefreshForm(); Enabled = true; }