private void UploadLogToPastebinToolStripMenuItem_Click(object sender, EventArgs e) { if (!File.Exists(Strings.FileName.Log)) { MsgBox.Error(StringLoader.GetText("exception_log_not_exist")); return; } #if DEBUG Process.Start(Strings.FileName.Log); #else string logTitle = $"{AssemblyAccessor.Version} ({GetSHA256(Application.ExecutablePath).Substring(0, 12)}) at {Methods.DateToString(DateTime.UtcNow)}"; byte[] logBytes = File.ReadAllBytes(Strings.FileName.Log); logBytes = TrimArrayIfNecessary(logBytes); string logText = BitConverter.ToString(logBytes).Replace("-", ""); var pasteUrl = UploadToPasteBin(logTitle, logText, PasteBinExpiration.OneHour, false, "text"); if (!String.IsNullOrEmpty(pasteUrl)) { Clipboard.SetText(pasteUrl); MsgBox.Success(StringLoader.GetText("success_log_file_upload", pasteUrl)); } else { MsgBox.Error(StringLoader.GetText("exception_log_file_failed")); } #endif }
private static string GetKRGameStartProtocol(MyWebClient client) { string response = Encoding.UTF8.GetString(client.UploadData(Urls.SoulworkerKRGameStart, new byte[] { })); var gameStartJSON = new { code = Int32.MaxValue, message = "", memberNo = Int64.MaxValue, gameAuthToken = "", maintenenceType = "", endTime = "", maintenenceTime = "" }; var jsonResponse = JsonConvert.DeserializeAnonymousType(response, gameStartJSON); switch (jsonResponse.code) { case 0: return($"sgup://run/11/{jsonResponse.memberNo}/{jsonResponse.gameAuthToken ?? throw new Exception("unexpected null gameAuthToken")}"); case -1: throw new Exception($"You are not logged in."); case -3: string maintType = jsonResponse.maintenenceType ?? throw new Exception("unexpected null maintenenceType"); string maintTime = jsonResponse.maintenenceTime ?? throw new Exception("unexpected null maintenenceTime"); string maintEndTime = jsonResponse.endTime ?? throw new Exception("unexpected null endTime"); string message = jsonResponse.message ?? throw new Exception("unexpected null message"); throw new Exception(StringLoader.GetText("exception_game_stove_maintenance", maintType, maintTime, maintEndTime, message.Replace("<p>", "").Replace("</p>", "\n"))); case -4: case -5: throw new Exception(StringLoader.GetText("exception_account_not_validated")); default: throw new Exception($"code=[{jsonResponse.code}]"); } }
private void ButtonDownload_Click(object sender, EventArgs e) { switch (this.CurrentState) { case State.Idle: this.CurrentState = State.RTPatch; this._nextState = NextState.Download; this.RTPatcher.Run(this.ComboBoxLanguages.SelectedItem as Language); break; case State.Download: this.ButtonDownload.Text = StringLoader.GetText("button_cancelling"); this.Downloader.Cancel(); break; case State.Patch: this.ButtonDownload.Text = StringLoader.GetText("button_cancelling"); this.Patcher.Cancel(); break; case State.RTPatch: this.ButtonDownload.Text = StringLoader.GetText("button_cancelling"); this.RTPatcher.Cancel(); break; } }
private static MyWebClient GamecomLogin(MyWebClient client) { string id = UserSettings.GameId; string pw = UserSettings.GamePw; if (String.IsNullOrEmpty(id)) { throw new Exception(StringLoader.GetText("exception_empty_id")); } var values = new NameValueCollection(2) { [Strings.Web.JP.Gamecom.PostId] = HttpUtility.UrlEncode(id), }; using (System.Security.SecureString secure = Methods.DecryptString(pw)) { if (String.IsNullOrEmpty(values[Strings.Web.JP.Gamecom.PostPw] = Methods.ToInsecureString(secure))) { throw new Exception(StringLoader.GetText("exception_empty_pw")); } } byte[] byteResponse = client.UploadValues(Urls.GamecomLogin, values); string loginResponse = Encoding.GetEncoding("shift-jis").GetString(byteResponse); client.DownloadString(Urls.SoulworkerJPGamecomHome); return(client); }
private static string GetGameStartArgumentGamecomJP(MyWebClient client) { string response = client.DownloadString(Urls.SoulworkerJPGamecomGameStart); if (response.Length > 3) { return(response.Trim('"').Replace("\\", "")); } else { switch (response) { case "110": throw new Exception("error login (110)"); case "320": throw new Exception(StringLoader.GetText("exception_game_maintenance")); case "340": throw new Exception("error block (340)"); default: throw new Exception($"errCode=[{response}"); } } }
private static void StartupBackupCheck(Language language) { if (Directory.Exists(language.BackupPath)) { if (Directory.GetFiles(language.BackupPath, "*", SearchOption.AllDirectories).Length > 0) { DialogResult result = MsgBox.Question(StringLoader.GetText("question_backup_files_found", language.ToString())); if (result == DialogResult.Yes) { RestoreBackup(language); } else { string[] filePaths = Directory.GetFiles(language.BackupPath, "*", SearchOption.AllDirectories); foreach (var file in filePaths) { File.Delete(file); } } } } else { Directory.CreateDirectory(language.BackupPath); } }
private void InitializeTextComponent() { this.Text = StringLoader.GetText("form_settings"); this.ButtonOk.Text = StringLoader.GetText("button_ok"); this.ButtonCancel.Text = StringLoader.GetText("button_cancel"); this.ButtonApply.Text = StringLoader.GetText("button_apply"); this.TabPageGame.Text = StringLoader.GetText("tab_game"); this.GroupBoxGameDirectory.Text = StringLoader.GetText("box_game_dir"); this.ButtonOpenGameDirectory.Text = StringLoader.GetText("button_open"); this.CustomGamePathButton.Text = StringLoader.GetText("button_change"); this.ButtonChangePatcherDirectory.Text = StringLoader.GetText("button_change"); this.GroupBoxPatchExe.Text = StringLoader.GetText("box_patch_exe"); this.CheckBoxPatchExe.Text = StringLoader.GetText("check_patch_exe"); this.TabPageCredentials.Text = StringLoader.GetText("tab_credentials"); this.GroupBoxGameUserId.Text = StringLoader.GetText("box_id"); this.GroupBoxGameUserPassword.Text = StringLoader.GetText("box_pw"); this.GroupBoxGameWantLogin.Text = StringLoader.GetText("box_want_login"); this.CheckBoxWantToLogin.Text = StringLoader.GetText("check_want_login"); this.TabPagePatcher.Text = StringLoader.GetText("tab_patcher"); this.GroupBoxPatcherDirectory.Text = StringLoader.GetText("box_patcher_dir"); this.GroupBoxUILanguagePicker.Text = StringLoader.GetText("box_language"); this.GroupBoxGameOptions.Text = StringLoader.GetText("box_game_options"); this.ButtonOpenGameOptions.Text = StringLoader.GetText("button_game_options"); this.CustomSourceWarnLabel.Text = "NOTE: The translation source can be a url or a path.\nMake sure it has the correct format, otherwise it won't work."; }
public static Species GetSpecies(string name = "") { GradientColorKey[] colorKeys = new GradientColorKey[3]; float position = 0.0f; for (int i = 0; i < 3; i++) { colorKeys[i] = new GradientColorKey(Constants.GetRandomPastelColor(), position); position += 0.50f; } GradientAlphaKey[] alphaKeys = new GradientAlphaKey[2] { new GradientAlphaKey(1, 0), new GradientAlphaKey(1, 1) }; Gradient g = new Gradient(); g.alphaKeys = alphaKeys; g.colorKeys = colorKeys; Sprite[] sprites = SpriteLoader.GetRandomSetOfAlienSprites().ToArray(); if (name == "") { name = MarkovGenerator.GenerateMarkovWord(StringLoader.GetAllStrings("SpeciesButterfly"), 1)[0]; } return(new Species(name, sprites, g)); }
private string GetResourceString(string resourceString) { if (!string.IsNullOrEmpty(resourceString)) { var strResource = resourceString.Trim(); if (strResource.StartsWith("@", StringComparison.InvariantCultureIgnoreCase) && strResource.Contains(",")) { var lastIndex = strResource.LastIndexOf(','); try { var resFile = strResource.Substring(1, lastIndex - 1).Trim(); var strIndex = strResource.Substring(lastIndex + 1, strResource.Length - lastIndex - 1).Trim(); var resIndex = 0; if (Int32.TryParse(strIndex, out resIndex) && File.Exists(resFile)) { using (var resource = new StringLoader(resFile)) { var result = resource.Load(resIndex); return(result ?? resourceString); } } } catch (Exception) { //throw; } } } return(resourceString); }
private void ButtonChangePatcherDirectory_Click(object sender, EventArgs e) { using (var folderDialog = new FolderBrowserDialog { Description = StringLoader.GetText("dialog_folder_change_patcher_dir") }) { DialogResult result = folderDialog.ShowDialog(); if (result == DialogResult.OK) { if (Methods.IsValidSwPatcherPath(folderDialog.SelectedPath)) { this.TextBoxPatcherDirectory.Text = this.PatcherWorkingDirectory = folderDialog.SelectedPath; } else { DialogResult dialogResult = MsgBox.Question(StringLoader.GetText("question_folder_same_path_game")); if (dialogResult == DialogResult.Yes) { this.TextBoxPatcherDirectory.Text = this.PatcherWorkingDirectory = folderDialog.SelectedPath; } } } } }
private void ApplyChanges() { try { if (UserSettings.PatcherPath != this.PatcherWorkingDirectory) { MoveOldPatcherFolder(UserSettings.PatcherPath, this.PatcherWorkingDirectory, (this.Owner as MainForm).GetTranslationFolders()); UserSettings.PatcherPath = this.PatcherWorkingDirectory; } if (UserSettings.WantToPatchExe != this.WantToPatchSoulworkerExe) { Region region = (this.Owner as MainForm).GetSelectedRegion(); string gameExePatchedPath = Path.Combine(UserSettings.PatcherPath, region.Folder, Methods.GetGameExeName(region.Id)); if (File.Exists(gameExePatchedPath)) { File.Delete(gameExePatchedPath); } UserSettings.WantToPatchExe = this.WantToPatchSoulworkerExe; } if (UserSettings.GameId != this.GameUserId) { UserSettings.GameId = this.GameUserId; } if (this.GameUserPassword != MaskPassword(UserSettings.GamePw)) { using (var secure = Methods.ToSecureString(this.GameUserPassword)) { UserSettings.GamePw = Methods.EncryptString(secure); } } if (UserSettings.WantToLogin != this.WantToLogin) { UserSettings.WantToLogin = this.WantToLogin; } if (UserSettings.UILanguageCode != this.UILanguage) { UserSettings.UILanguageCode = this.UILanguage; this.PendingRestart = true; } this.ButtonApply.Enabled = false; if (this.PendingRestart) { MsgBox.Notice(StringLoader.GetText("notice_pending_restart")); } } catch (Exception ex) { Logger.Error(ex); MsgBox.Error(Methods.ExeptionParser(ex)); } }
private static void RestoreBackup(Language language) { if (!Directory.Exists(language.BackupPath)) { return; } string regionId = language.ApplyingRegionId; string backupFilePath = Path.Combine(language.BackupPath, Methods.GetGameExeName(regionId)); if (File.Exists(backupFilePath)) { string gameExePath = Path.Combine(UserSettings.GamePath, Methods.GetGameExeName(regionId)); string gameExePatchedPath = Path.Combine(UserSettings.PatcherPath, regionId, Methods.GetGameExeName(regionId)); Logger.Info($"Restoring .exe original=[{gameExePath}] backup=[{gameExePatchedPath}]"); if (File.Exists(gameExePath)) { if (File.Exists(gameExePatchedPath)) { File.Delete(gameExePatchedPath); } File.Move(gameExePath, gameExePatchedPath); } File.Move(backupFilePath, gameExePath); } string[] filePaths = Directory.GetFiles(language.BackupPath, "*", SearchOption.AllDirectories); foreach (var file in filePaths) { string path = Path.Combine(UserSettings.GamePath, file.Substring(language.BackupPath.Length + 1)); Logger.Info($"Restoring file original=[{path}] backup=[{file}]"); if (File.Exists(path)) { string langPath = Path.Combine(language.Path, path.Substring(UserSettings.GamePath.Length + 1)); if (File.Exists(langPath)) { File.Delete(langPath); } File.Move(path, langPath); } try { File.Move(file, path); } catch (DirectoryNotFoundException) { MsgBox.Error(StringLoader.GetText("exception_cannot_restore_file", Path.GetFullPath(file))); Logger.Error($"Cannot restore file=[{file}]"); File.Delete(file); } } }
private void OpenSWWebpageToolStripMenuItem_Click(object sender, EventArgs e) { Region region = (this.ComboBoxRegions.SelectedItem as Region); switch (region.Id) { case "jp": Process.Start(Urls.SoulworkerJPHangeHome); break; case "gjp": Process.Start(Urls.SoulworkerJPGamecomHome); break; case "kr": Process.Start(Urls.SoulworkerKRHome); break; case "nkr": Process.Start(Urls.SoulworkerNaverKRHome); break; case "gf": Process.Start(Urls.SoulworkerGFHome); break; default: throw new Exception(StringLoader.GetText("exception_region_unknown", region.Id)); } }
public static string LoadStringFromDLLByPath(string StringPath) { if (StringPath.StartsWith(@"@")) { string[] aPathDetails = StringPath.Split(','); string DllString = string.Empty; if (aPathDetails.Length == 2) { string sDLLPath = aPathDetails[0].Replace(@"@", ""); if (!File.Exists(Environment.ExpandEnvironmentVariables(sDLLPath))) { return(string.Empty); } StringLoader sl = new StringLoader(sDLLPath); try { DllString = sl.Load(Convert.ToInt32(aPathDetails[1].Replace("-", ""))); } catch (Exception e) { Debug.WriteLine("Could not extract String from DLL Path " + StringPath + ". Error:" + e.Message); DllString = string.Empty; } sl.Dispose(); return(DllString); } return(string.Empty); } return(StringPath); }
public static StringLoader Instance() { if (loader == null) { loader = new StringLoader(); } return(loader); }
public void TestReadingStrings() { var testStream = new MemoryStream(Encoding.ASCII.GetBytes("FooString = \"AString\"")); var loader = StringLoader.Instance(); loader.LoadStrings(testStream); Assert.AreEqual(loader.GetString("FooString"), "AString"); }
private void Downloader_DownloaderProgressChanged(object sender, DownloaderProgressChangedEventArgs e) { if (this.CurrentState == State.Download) { this.ToolStripStatusLabel.Text = $"{StringLoader.GetText("form_status_download")} {e.FileName} ({e.FileNumber}/{e.FileCount})"; this.ToolStripProgressBar.Value = e.Progress; } }
public void StringLoader_Should_Just_Pass_Through() { var loader = new StringLoader(); const string template = "{{foo}}"; var loadedTemplate = loader.Load("{{foo}}"); Assert.Equal(template, loadedTemplate); }
public void StringLoader_Should_Be_Distinct() { var loader = new StringLoader(); var clone = loader.Clone(); Assert.IsType <StringLoader>(clone); Assert.NotEqual(clone, loader); }
public void GenerateEntities() { data = GameDataManager.instance.masterGalaxyData; GameDataManager.instance.ClearAllEntities(); GameDataManager.instance.ClearAllSpecies(); string[] speciesNames = MarkovGenerator.GenerateMarkovWord(StringLoader.GetAllStrings("SpeciesButterfly"), numberOfSpecies); for (int i = 0; i < numberOfSpecies; i++) { GameDataManager.instance.AddNewSpecies(SpeciesGenerator.GetSpecies(speciesNames[i])); } for (int i = 0; i < data.sectors.Length; i++) { for (int j = 0; j < data.sectors[0].Length; j++) { if (data.sectors[i][j].Owner == null && data.sectors[i][j].SystemCount > 0) { unoccupiedSectors.Add(data.sectors[i][j]); } } } List <List <SectorData> > partitions = GenerateSectorPartitions(unoccupiedSectors); string[] entityNames = MarkovGenerator.GenerateMarkovWord(StringLoader.GetAllStrings("StarNames"), partitions.Count); for (int i = 0; i < partitions.Count; i++) { float averageSystem = 0; float maxSystem = 0; float minSystem = 10000; float sumOfSquares = 0; foreach (SectorData d in partitions[i]) { averageSystem += d.SystemCount; sumOfSquares += d.SystemCount * d.SystemCount; if (d.SystemCount > maxSystem) { maxSystem = d.SystemCount; } if (d.SystemCount < minSystem) { minSystem = d.SystemCount; } } float totalSystem = averageSystem; averageSystem = averageSystem / partitions[i].Count; float sumOfSquaresAverage = sumOfSquares / partitions[i].Count; float standardDeviation = Mathf.Sqrt(sumOfSquaresAverage - (averageSystem * averageSystem)); Debug.Log("Total System:" + totalSystem + " averageSystem:" + averageSystem + " minSystem:" + minSystem + " maxSystem:" + maxSystem + " stdDeviation:" + standardDeviation); GalaxyEntity g = GetEntity(partitions[i]); g.name = entityNames[i]; Debug.Log(g.leader.FullName + " " + g.Government.governmentName + " " + g.Government.governmentCatagory); GameDataManager.instance.AddNewEntity(g); } entityList.Display(GameDataManager.instance.Entitites); speciesList.Display(GameDataManager.instance.Species); WorldMap.instance.ShowTerritory(); }
private void InitRegionsConfigData() { var doc = new XmlDocument(); string xmlPath = Urls.TranslationGitHubHome + Strings.IniName.LanguagePack; Logger.Debug(Methods.MethodFullName(System.Reflection.MethodBase.GetCurrentMethod(), xmlPath)); doc.Load(xmlPath); XmlElement configRoot = doc.DocumentElement; XmlElement xmlRegions = configRoot[Strings.Xml.Regions]; int regionCount = xmlRegions.ChildNodes.Count; Region[] regions = new Region[regionCount]; for (int i = 0; i < regionCount; i++) { XmlNode regionNode = xmlRegions.ChildNodes[i]; string regionId = regionNode.Name; string regionName = StringLoader.GetText(regionNode.Attributes[Strings.Xml.Attributes.Name].Value); XmlElement xmlLanguages = regionNode[Strings.Xml.Languages]; int languageCount = xmlLanguages.ChildNodes.Count; Language[] regionLanguages = new Language[languageCount]; for (int j = 0; j < languageCount; j++) { XmlNode languageNode = xmlLanguages.ChildNodes[j]; string languageId = languageNode.Name; string languageName = languageNode.Attributes[Strings.Xml.Attributes.Name].Value; string languageDateString = languageNode[Strings.Xml.Value].InnerText; DateTime languageDate = Methods.ParseDate(languageDateString); regionLanguages[j] = new Language(languageId, languageName, languageDate, regionId); } regions[i] = new Region(regionId, regionName, regionLanguages); } this.ComboBoxRegions.DataSource = regions.Length > 0 ? regions : null; if (this.ComboBoxRegions.DataSource != null) { if (String.IsNullOrEmpty(UserSettings.RegionId)) { UserSettings.RegionId = (this.ComboBoxRegions.SelectedItem as Region).Id; } else { int index = this.ComboBoxRegions.Items.IndexOf(new Region(UserSettings.RegionId)); this.ComboBoxRegions.SelectedIndex = index == -1 ? 0 : index; } this.ComboBoxRegions_SelectionChangeCommitted(this, EventArgs.Empty); } }
private void AppendEffectsMenu(String name) { ToggleMenuFlyoutItem menuItem = new ToggleMenuFlyoutItem(); menuItem.Text = StringLoader.Get(name); menuItem.Click += OnEffectClicked; EffectsMenu.Items.Add(menuItem); }
private void CheckNaverKRVersion() { int serverVersion = Methods.GetKRServerVersion(); int clientVersion = Convert.ToInt32(Methods.GetRegistryValue(Strings.Registry.NaverKR.RegistryKey, Strings.Registry.NaverKR.Key32Path, Strings.Registry.NaverKR.Version, 0)); if (clientVersion != serverVersion) { throw new Exception(StringLoader.GetText("exception_game_not_latest")); } }
private void InitializeTextComponent() { this.ButtonOk.Text = StringLoader.GetText("button_ok"); this.Text = $"About {AssemblyAccessor.Title}"; this.LabelProductName.Text = AssemblyAccessor.Product; this.LabelVersion.Text = $"Version {AssemblyAccessor.Version}"; this.TextBoxDescription.Text = StringLoader.GetText("patcher_description"); this.LinkLabelWebsite.Links.Add(0, this.LinkLabelWebsite.Text.Length, Urls.SoulworkerWebsite); this.LogoPictureBox.ImageLocation = $"https://raw.githubusercontent.com/Miyuyami/SWPatcher/master/Images/{(new Random()).Next(ImagesCount) + 1}.png"; }
public static Species[] GetMultipleSpecies(int number) { Species[] species = new Species[number]; string[] names = MarkovGenerator.GenerateMarkovWord(StringLoader.GetAllStrings("SpeciesButterfly"), 400); for (int i = 0; i < number; i++) { species[i] = GetSpecies(names[i]); } return(species); }
private void Start() { speciesList.Display(GameDataManager.instance.Species); speciesList.OnListElementSelectedEvent += SpeciesListChange; portraitGenerator.OnLayeredSpriteChangeEvent += PortraitGeneratorChange; speciesList.ForceSelect(0); firstName.onValueChanged.AddListener(SetPlayerFirstName); lastName.onValueChanged.AddListener(SetPlayerLastName); firstName.text = StringLoader.GetAString("FirstNamesMasculine"); lastName.text = StringLoader.GetAString("LastNames"); }
private void Worker_DoWork(object sender, DoWorkEventArgs e) { Logger.Debug(Methods.MethodFullName("Downloader", Thread.CurrentThread.ManagedThreadId.ToString(), this.Language.ToString())); if (UserSettings.BypassTranslationDateCheck || Methods.HasNewTranslations(this.Language) || Methods.IsTranslationOutdated(this.Language)) { SWFileManager.LoadFileConfiguration(this.Language); } else { throw new Exception(StringLoader.GetText("exception_already_latest_translation", Methods.DateToLocalString(this.Language.LastUpdate))); } }
private void Awake() { player = PlayerManager.instance.activePlayer; player.Funds += 2000; title.ClearOptions(); title.options.Add(new Dropdown.OptionData("<i>None</i>")); foreach (string s in StringLoader.GetAllStrings("Titles")) { title.options.Add(new Dropdown.OptionData(s)); } title.value = 0; title.RefreshShownValue(); }
public static Shield GetRandomShield() { Shield p = new Shield(); p.sprite = SpriteLoader.GetPartSprite("defaultShieldS"); p.Tier = 1; p.Size = PartSize.S; p.shieldType = ShieldType.Generator; p.DescriptionName = "Shield Generator"; p.ModelName = StringLoader.GetAString("sensorNames"); p.strength.Value = UnityEngine.Random.Range(2, 20); p.rechargeTime.Value = UnityEngine.Random.Range(20, 100); return(p); }
private void MainForm_Load(object sender, EventArgs e) { this.InitRegionsConfigData(); StartupBackupCheck(this.ComboBoxLanguages.SelectedItem as Language); if (!Methods.IsValidSwPatcherPath(UserSettings.PatcherPath)) { string error = StringLoader.GetText("exception_folder_same_path_game"); Logger.Error(error); MsgBox.Error(error); } }
public override WFState Run() { WFState retval = new WFState(); try { retval.Value = WFState.WFStateFail; StringLoader sl = new StringLoader(this.FileToProcess); // string output = sl.Load(strId); sl.Dispose(); // Assembly assembly = Assembly.LoadFile(this.FileToProcess); // string[] resources = assembly.GetManifestResourceNames(); } catch (Exception) { } return retval; }