private async Task InstallSKSE() { try { string url = await Net.GetUrlToSKSE(); string destinationPath = $@"{Settings.PathToSkyrimTmp}{url.Substring(url.LastIndexOf('/'), url.Length - url.LastIndexOf('/'))}"; bool ok = await DownloadFile(destinationPath, url, Res.DownloadingSKSE); if (ok) { progressBar.Show(true, Res.ExtractingSKSE); try { await Task.Run(() => Unpacker.UnpackArchive(destinationPath, Settings.PathToSkyrim, Path.GetFileNameWithoutExtension(destinationPath))); } catch (Exception e) { Logger.Error("ExtractSKSE", e); NotifyController.Show(e); mainButton.ButtonStatus = MainButtonStatus.Retry; } progressBar.Hide(); } } catch (Exception e) { Logger.Error("InstallSKSE", e); } }
private async Task InstallRuFixConsole() { try { string url = Net.URL_Mod_RuFix; string destinationPath = $@"{Settings.PathToSkyrimTmp}{url.Substring(url.LastIndexOf('/'), url.Length - url.LastIndexOf('/'))}"; bool ok = await DownloadFile(destinationPath, url, Res.DownloadingSSERuFixConsole); if (ok) { try { progressBar.Show(true, Res.Extracting); ModVersion.HasRuFixConsole = await Task.Run(() => Unpacker.UnpackArchive(destinationPath, Settings.PathToSkyrim + "\\Data")); ModVersion.Save(); progressBar.Hide(); } catch (Exception e) { Logger.Error("ExtractRuFix", e); NotifyController.Show(e); } } } catch (Exception e) { Logger.Error("InstallRuFixConsole", e); } }
public static async Task <bool> InstallClient(bool update = false) { if (!Mods.ExistMod("SkyMPCore") || update) { if (update && Mods.ExistMod("SkyMPCore")) { await Mods.DisableMod("SkyMPCore"); } (string, string)url = (null, null); try { url = await Net.GetUrlToClient(); } catch (WebException we) { NotifyController.Show(we); return(false); } string destinationPath = $"{Settings.PathToSkyrimTmp}client.zip"; try { IO.DeleteFile(destinationPath); } catch (Exception e) { Logger.Error("DelClientZip", e); } string path = Mods.GetTmpPath(); bool ok = await DownloadManager.DownloadFile(destinationPath, url.Item1, () => { try { Unpacker.UnpackArchive(destinationPath, path, "client"); } catch (Exception e) { Logger.Error("Extract", e); NotifyController.Show(e); } }, Res.Extracting); if (ok) { await Mods.AddMod("SkyMPCore", url.Item2, path, false); return(true); } } await Mods.EnableMod("SkyMPCore"); return(true); }
private async void Signup_Click(object sender, RoutedEventArgs e) { if (passReg.Password != passCheckReg.Password) { passCheckReg.Password = ""; return; } registerPanel.IsEnabled = false; backButton.IsEnabled = false; try { ReqRegisterModel model = new ReqRegisterModel() { Email = emailReg.Text, Name = nameReg.Text, Password = passReg.Password }; ResRegisterModel ds = await Account.Register(model); NotifyController.Show(PopupNotify.Normal, Res.Successfully, Res.VerifyAccount); Clear(); } catch (WebException we) { WebResponse s = we.Response; if (s != null) { using (var reader = new StreamReader(s.GetResponseStream())) { string raw = reader.ReadToEnd(); try { JArray jObject = JArray.Parse(raw); foreach (JToken par in jObject.Children()) { NotifyController.Show(PopupNotify.Error, par.Value <string>("property"), ((JProperty)par.Value <JToken>("constraints").First()).Value.ToString(), 4000); } } catch { NotifyController.Show(PopupNotify.Error, Res.Error, raw, 5000); } } } } catch (Exception err) { Logger.Error("Auth_Register", err); } registerPanel.IsEnabled = true; backButton.IsEnabled = true; }
private async void Signin_Click(object sender, RoutedEventArgs e) { authPanel.IsEnabled = false; backButton.IsEnabled = false; Settings.RememberMe = (bool)rmAuth.IsChecked; try { ReqLoginModel model = new ReqLoginModel() { Email = emailAuth.Text, Password = passAuth.Password }; ResLoginModel ds = await Account.Login(model); Settings.UserId = ds.Id; Settings.UserToken = ds.Token; Settings.Save(); SignIn?.Invoke(); } catch (WebException we) { var s = we.Response; if (s != null) { using (var reader = new StreamReader(s.GetResponseStream())) { string raw = reader.ReadToEnd(); try { JArray jObject = JArray.Parse(raw); foreach (JToken par in jObject.Children()) { NotifyController.Show(PopupNotify.Error, par.Value <string>("property"), ((JProperty)par.Value <JToken>("constraints").First()).Value.ToString(), 4000); } } catch { NotifyController.Show(PopupNotify.Error, Res.Error, raw, 5000); } } } } catch (Exception err) { Logger.Error("Auth_Login", err); } authPanel.IsEnabled = true; backButton.IsEnabled = true; }
private static async Task <string> Request(string url, string method, bool auth, string data) { try { return(await Net.Request(url, method, auth, data)); } catch (WebSocketException wse) { NotifyController.Show(wse); } catch (WebException we) { NotifyController.Show(we); } return(null); }
private async Task UpdateClientNew() { (string, string)url = await Net.GetUrlToClient(); string destinationPath = $"{Settings.PathToSkyrimTmp}client.zip"; try { if (File.Exists(destinationPath)) { File.Delete(destinationPath); } } catch (Exception e) { Logger.Error("DelClientZip", e); } bool ok = await DownloadFile(destinationPath, url.Item1, Res.DownloadingClient, url.Item2); if (ok) { progressBar.Show(true, Res.ExtractingClient); try { string path = Mods.GetTmpPath(); if (await Task.Run(() => Unpacker.UnpackArchive(destinationPath, path, "client"))) { Mods.AddMod("SkyMPCore", url.Item2, path, false); Mods.EnableMod("SkyMPCore"); ModVersion.Version = url.Item2; ModVersion.Save(); NotifyController.Show(PopupNotify.Normal, Res.InstallationCompleted, Res.HaveAGG); } } catch (Exception e) { Logger.Error("Extract", e); NotifyController.Show(e); mainButton.ButtonStatus = MainButtonStatus.Retry; return; } progressBar.Hide(); } await CheckClientUpdates(); }
public static async Task <bool> InstallSKSE() { try { if (!Mods.ExistMod("SKSE") || !Mods.CheckModFiles("SKSE")) { if (Mods.ExistMod("SKSE")) { await Mods.DisableMod("SKSE"); } string url = await Net.GetUrlToSKSE(); string destinationPath = $@"{Settings.PathToSkyrimTmp}{url.Substring(url.LastIndexOf('/'), url.Length - url.LastIndexOf('/'))}"; string path = Mods.GetTmpPath(); bool ok = await DownloadManager.DownloadFile(destinationPath, url, () => { try { Unpacker.UnpackArchive(destinationPath, path, Path.GetFileNameWithoutExtension(destinationPath)); } catch (Exception e) { Logger.Error("ExtractSKSE", e); NotifyController.Show(e); } }, Res.Extracting); if (ok) { await Mods.AddMod("SKSE", "SKSEHash", path, false); } } await Mods.EnableMod("SKSE"); return(true); } catch (Exception e) { Logger.Error("InstallSKSE", e); return(false); } }
private async void Forgot_Click(object sender, RoutedEventArgs e) { forgotPassPanel.IsEnabled = false; backButton.IsEnabled = false; try { ReqResetPassword model = new ReqResetPassword() { Email = emailForgot.Text }; await Account.ResetPassword(model); await Task.Delay(200); Clear(); } catch (WebException we) { var s = we.Response; using (var reader = new StreamReader(s.GetResponseStream())) { string raw = reader.ReadToEnd(); try { JArray jObject = JArray.Parse(raw); foreach (JToken par in jObject.Children()) { NotifyController.Show(PopupNotify.Error, par.Value <string>("property"), ((JProperty)par.Value <JToken>("constraints").First()).Value.ToString(), 4000); } } catch { NotifyController.Show(PopupNotify.Error, Res.Error, raw, 5000); } } } catch (Exception err) { Logger.Error("Auth_ResetPassword", err); } forgotPassPanel.IsEnabled = true; backButton.IsEnabled = true; }
private void StartDown() { try { if (File.Exists(sDestinationPath) && File.GetAttributes(sDestinationPath) != FileAttributes.Normal) { File.SetAttributes(sDestinationPath, FileAttributes.Normal); } Downloading = true; DownloadFile(); } catch (WebException we) { sDestinationPath = null; NotifyController.Show(we); } catch (SocketException se) { sDestinationPath = null; NotifyController.Show(se); } catch (UnauthorizedAccessException uae) { sDestinationPath = null; Dictionary <string, string> tags = new Dictionary <string, string>(1) { { "FullPath", sDestinationPath } }; Logger.Error("Downloader_UAE", uae, tags); } catch (Exception e) { if (e.HResult == -2146232800) { NotifyController.Show(e.Message); } sDestinationPath = null; Logger.Error("Downloader", e); } finally { Downloading = false; } }
public static async Task <bool> InstallRuFixConsole() { try { if (!Mods.ExistMod("RuFixConsole") || !Mods.CheckModFiles("RuFixConsole")) { if (Mods.ExistMod("RuFixConsole")) { await Mods.DisableMod("RuFixConsole"); } const string url = Net.URL_Mod_RuFix; string destinationPath = $@"{Settings.PathToSkyrimTmp}{url.Substring(url.LastIndexOf('/'), url.Length - url.LastIndexOf('/'))}"; string path = Mods.GetTmpPath(); bool ok = await DownloadManager.DownloadFile(destinationPath, url, () => { try { Unpacker.UnpackArchive(destinationPath, path + "\\Data"); } catch (Exception e) { Logger.Error("ExtractRuFix", e); NotifyController.Show(e); } }, Res.Extracting); if (ok) { await Mods.AddMod("RuFixConsole", "RuFixConsoleHash", path, false); } } await Mods.EnableMod("RuFixConsole"); return(true); } catch (Exception e) { Logger.Error("InstallRuFixConsole", e); return(false); } }
internal static void Save() { try { if (string.IsNullOrEmpty(Settings.PathToSkyrim)) { return; } string path = $"{Settings.PathToSkyrim}\\version.json"; lock (sync) File.WriteAllText(path, JsonConvert.SerializeObject(model)); } catch (Exception e) { NotifyController.Show(UI.Controllers.PopupNotify.Error, Res.Error, Res.ErrorSaveFileBusy); Logger.Error("Version_Save", e); } }
private async Task CheckClientUpdates() { progressBar.Show(true, Res.CheckingUpdates); try { if (await Net.UpdateAvailable()) { mainButton.ButtonStatus = MainButtonStatus.Update; } else { mainButton.ButtonStatus = MainButtonStatus.Play; } } catch (Exception e) { Logger.Error("CheckClient", e); NotifyController.Show(e); mainButton.ButtonStatus = MainButtonStatus.Retry; } progressBar.Hide(); }
private async Task <bool> SetMods(string adress) { string path = Settings.PathToLocalSkyrim + "Plugins.txt"; string content = ""; #if (DEBUG) bool d = true; #else bool d = false; #endif if (d || (NetworkSettings.EnableModLoader && ExperimentalFunctions.HasExperimentalFunctions())) { try { Mods.DisableAll(); ServerModsManifest mods = Mods.CheckCore(await GetManifest(adress)); Dictionary <string, List <(string, uint)> > needMods = GetMods(mods); foreach (KeyValuePair <string, List <(string, uint)> > mod in needMods) { if (!Mods.ExistMod(mod.Key) || !Mods.CheckMod(mod.Key, mod.Value)) { string tmpPath = Mods.GetTmpPath(); string desPath = tmpPath + "\\Data\\"; IO.CreateDirectory(desPath); string mainFile = null; foreach (var file in mod.Value) { await DownloadMod(desPath + file.Item1, adress, file.Item1); if (mods.LoadOrder.Contains(file.Item1)) { mainFile = file.Item1; } } Mods.AddMod(mod.Key, "", tmpPath, true, mainFile); } Mods.EnableMod(Path.GetFileNameWithoutExtension(mod.Key)); } foreach (var item in mods.LoadOrder) { content += $"*{item}\n"; } } catch (WebException) { if (NetworkSettings.CompatibilityMode) { NotifyController.Show(PopupNotify.Normal, Res.Attempt, "Вероятно целевой сервер устер, используется режим совместимости"); if (Mods.ExistMod("Farm")) { Mods.OldModeEnable(); } await Task.Delay(3000); content = @"*FarmSystem.esp"; } else { NotifyController.Show(PopupNotify.Error, Res.Attempt, "Возможно целевой сервер устарел, так как не ответил на запрос"); return(false); } } catch (FileNotFoundException) { NotifyController.Show(PopupNotify.Error, Res.Error, "Один или несколько модов не удалось загрузить с сервера"); return(false); } catch (Exception e) { Logger.Error("EnablerMods", e); NotifyController.Show(e); return(false); } } else { content = @"*FarmSystem.esp"; } try { if (!Directory.Exists(Settings.PathToLocalSkyrim)) { Directory.CreateDirectory(Settings.PathToLocalSkyrim); } if (File.Exists(path) && File.GetAttributes(path) != FileAttributes.Normal) { File.SetAttributes(path, FileAttributes.Normal); } File.WriteAllText(path, content); } catch (UnauthorizedAccessException) { FileAttributes attr = new FileInfo(path).Attributes; Logger.Error("Write_Plugin_UAException", new UnauthorizedAccessException($"UnAuthorizedAccessException: Unable to access file. Attributes: {attr}")); } catch (Exception e) { Logger.Error("Write_Plugin_txt", e); } return(true); }
private static async void ACDetected(object s, EventArgs e) { NotifyController.Show(s.ToString()); await GameLauncher.StopGame(); }
private static async Task <bool> SetMods(string adress) { string path = DefaultPaths.PathToLocalSkyrim + "Plugins.txt"; string content = ""; try { await Mods.DisableAll(); ServerModsManifest mods = Mods.CheckCore(await GetManifest(adress)); Dictionary <string, List <(string, uint)> > needMods = mods.GetMods(); foreach (KeyValuePair <string, List <(string, uint)> > mod in needMods) { if (!Mods.ExistMod(mod.Key) || !Mods.CheckMod(mod.Key, mod.Value)) { string tmpPath = Mods.GetTmpPath(); string desPath = tmpPath + "\\Data\\"; IO.CreateDirectory(desPath); string mainFile = null; foreach (var file in mod.Value) { ServerList.ShowProgressBar = true; await DownloadMod(desPath + file.Item1, adress, file.Item1); ServerList.ShowProgressBar = false; if (mods.LoadOrder.Contains(file.Item1)) { mainFile = file.Item1; } } await Mods.AddMod(mod.Key, "", tmpPath, true, mainFile); } await Mods.EnableMod(mod.Key); } foreach (var item in mods.LoadOrder) { content += $"*{item}\n"; } } catch (HttpRequestException) { if (NetworkSettings.CompatibilityMode) { NotifyController.Show(Res.CompatibilityModeOn); if (Mods.ExistMod("Farm")) { await Mods.OldModeEnable(); } await Task.Delay(3000); content = @"*FarmSystem.esp"; } else { NotifyController.Show(Res.CompatibilityModeOff); return(false); } } catch (WebException) { if (NetworkSettings.CompatibilityMode) { NotifyController.Show(Res.CompatibilityModeOn); if (Mods.ExistMod("Farm")) { await Mods.OldModeEnable(); } await Task.Delay(3000); content = @"*FarmSystem.esp"; } else { NotifyController.Show(Res.CompatibilityModeOff); return(false); } } catch (FileNotFoundException) { NotifyController.Show(Res.DownloadModError); return(false); } catch (Exception e) { Logger.Error("EnablerMods", e); NotifyController.Show(e); return(false); } try { if (!Directory.Exists(DefaultPaths.PathToLocalSkyrim)) { Directory.CreateDirectory(DefaultPaths.PathToLocalSkyrim); } if (File.Exists(path) && File.GetAttributes(path) != FileAttributes.Normal) { File.SetAttributes(path, FileAttributes.Normal); } File.WriteAllText(path, content); } catch (UnauthorizedAccessException) { FileAttributes attr = new FileInfo(path).Attributes; Logger.Error("Write_Plugin_UAException", new UnauthorizedAccessException($"Unable to access file. Attributes: {attr}")); } catch (Exception e) { Logger.Error("Write_Plugin_txt", e); } return(true); }
public static async Task Play(ServerModel server, Window window) { string adressData; bool hasAc = false; try { if (Directory.Exists(Path.GetDirectoryName(Settings.PathToSkympClientSettings)) && File.Exists(Settings.PathToSkympClientSettings)) { File.SetAttributes(Settings.PathToSkympClientSettings, FileAttributes.Normal); } SetServer(server); string adress = server.Address; adressData = server.AddressData; object gameData = await Account.GetSession(adress); if (gameData == null) { return; } try { string res = await Net.RequestHttp($"http://{adressData}/SkyEye", "GET", false, null); if (res == "true") { hasAc = true; } } catch (Exception) { } if (hasAc) { ResultInitModel res = await SkyEye.AntiCheat.Init(Settings.UserId, Settings.UserName, ((JObject)gameData)["session"].ToObject <string>()); if (!res.Success) { NotifyController.Show(res.Message); return; } } SetSession(gameData); } catch (JsonSerializationException) { NotifyController.Show(Res.ErrorReadSkyMPSettings); return; } catch (JsonReaderException) { NotifyController.Show(Res.ErrorReadSkyMPSettings); return; } catch (UnauthorizedAccessException) { FileAttributes attr = new FileInfo(Settings.PathToSkympClientSettings).Attributes; Logger.Error("Play_UAException", new UnauthorizedAccessException($"UnAuthorizedAccessException: Unable to access file. Attributes: {attr}")); NotifyController.Show($"Unable to access file {Settings.PathToSkympClientSettings}"); return; } catch (Exception e) { Logger.Error("Play", e); NotifyController.Show(e); return; } if (!await SetMods(adressData)) { return; } try { window.Hide(); if (hasAc) { SkyEye.AntiCheat.Detected += ACDetected; } bool crash = await GameLauncher.StartGame(); window.Show(); if (hasAc) { SkyEye.AntiCheat.Close(); } if (crash) { Logger.ReportMetricaEvent("CrashDetected"); await Task.Delay(500); await DebuggerUtilities.ReportDmp(); } } catch { Logger.ReportMetricaEvent("HasNotAccess"); window.Show(); } finally { if (hasAc) { SkyEye.AntiCheat.Detected -= ACDetected; } } }
private async Task Play() { if (!File.Exists($"{Settings.PathToSkyrim}\\skse64_loader.exe")) { await CheckGame(); return; } if (serverList.SelectedItem == null) { NotifyController.Show(PopupNotify.Error, Res.Warning, Res.SelectServer); return; } try { if (Directory.Exists(Path.GetDirectoryName(Settings.PathToSkympClientSettings)) && File.Exists(Settings.PathToSkympClientSettings)) { File.SetAttributes(Settings.PathToSkympClientSettings, FileAttributes.Normal); } SetServer(); ServerModel server = (ServerModel)serverList.SelectedItem; object gameData = await Account.GetSession(server.Address); if (gameData == null) { return; } SetSession(gameData); } catch (JsonSerializationException) { NotifyController.Show(PopupNotify.Error, Res.Error, Res.ErrorReadSkyMPSettings); return; } catch (JsonReaderException) { NotifyController.Show(PopupNotify.Error, Res.Error, Res.ErrorReadSkyMPSettings); return; } catch (UnauthorizedAccessException) { FileAttributes attr = new FileInfo(Settings.PathToSkympClientSettings).Attributes; Logger.Error("Play_UAException", new UnauthorizedAccessException($"UnAuthorizedAccessException: Unable to access file. Attributes: {attr}")); NotifyController.Show(PopupNotify.Error, Res.Error, "UnAuthorizedAccessException: Unable to access file"); return; } catch (Exception e) { Logger.Error("Play", e); NotifyController.Show(PopupNotify.Error, Res.Error, e.Message); return; } SetMods(); try { Hide(); bool crash = await GameLauncher.StartGame(); Show(); if (crash) { YandexMetrica.ReportEvent("CrashDetected"); await Task.Delay(500); await ReportDmp(); } } catch { YandexMetrica.ReportEvent("HasNotAccess"); Close(); } }