diff --git a/MainForm.cs b/MainForm.cs index b5426f0..983a09e 100644 --- a/MainForm.cs +++ b/MainForm.cs @@ -4,6 +4,7 @@ using System.Collections.Generic; using System.IO; using System.Linq; using System.Runtime.InteropServices; +using System.Text.RegularExpressions; using System.Windows.Forms; namespace SaveWizard_rewritten @@ -18,7 +19,7 @@ namespace SaveWizard_rewritten [DllImport("SII_Decrypt.dll")] public static extern int DecryptAndDecodeFile(string InputFile, string OutputFile); - private Dictionary items = null; + private Dictionary items = null; private string opened_file_path, selected_game; private Dictionary owns = null; @@ -34,12 +35,12 @@ namespace SaveWizard_rewritten // File.Delete(path); } - private class WindowText + private class WindowItem { private readonly CheckBox Check; private readonly string Str; - public WindowText(CheckBox _check, string _str) + public WindowItem(CheckBox _check, string _str) { Check = _check; Str = _str; @@ -59,30 +60,53 @@ namespace SaveWizard_rewritten private void boxTextChanged(object sender, EventArgs e) { TextBox _sender = sender as TextBox; - items[_sender].GetCheck().Checked = false; + if (_sender != txt_adr) + items[_sender].GetCheck().Checked = false; + else + chk_adr.Checked = false; } private void ValidateBasic(object sender, KeyPressEventArgs e) { - if (!(e.KeyChar >= '0' && e.KeyChar <= '9') && !char.IsControl(e.KeyChar)) + //if (!(e.KeyChar >= '0' && e.KeyChar <= '9') && !char.IsControl(e.KeyChar)) + if (!(e.KeyChar >= '0' && e.KeyChar <= '9') && e.KeyChar != (char)Keys.Back) e.Handled = true; } private void ValidateSkills(object sender, KeyPressEventArgs e) { - if (!(e.KeyChar >= '0' && e.KeyChar <= '6') && !char.IsControl(e.KeyChar)) + //if (!(e.KeyChar >= '0' && e.KeyChar <= '6') && !char.IsControl(e.KeyChar)) + if (!(e.KeyChar >= '0' && e.KeyChar <= '6') && e.KeyChar != (char)Keys.Back) e.Handled = true; } + private List GetADR(string value) + { + string binaryCode = Convert.ToString(int.Parse(value), 2); + binaryCode = new string('0', 6 - binaryCode.Length) + binaryCode; + List result = new List(); + foreach (char character in binaryCode) + result.Add(character.ToString()); + return result; + } + private void GetFileData(string filename) { RegexHandler.FillLines(File.ReadAllLines(filename).ToList()); - foreach (KeyValuePair item in items) + foreach (KeyValuePair item in items) { item.Key.Text = RegexHandler.GetValue(RegexHandler.SearchLine(item.Value.GetString())); item.Value.GetCheck().Checked = true; } + + List adr_value = GetADR(RegexHandler.GetValue(RegexHandler.SearchLine("adr:"))); + for (int i = 0; i < 6; i++) + { + txt_adr.Text += adr_value[i]; + if (i != 5) + txt_adr.Text += ","; + } if (RegexHandler.SearchLine("company.volatile.stokes.calais") != 0) selected_game = "ets2"; @@ -121,7 +145,7 @@ namespace SaveWizard_rewritten RegexHandler.FillLines(null); selected_game = null; owns = null; - foreach (KeyValuePair item in items) + foreach (KeyValuePair item in items) { item.Key.Text = ""; item.Value.GetCheck().Checked = true; @@ -144,16 +168,16 @@ namespace SaveWizard_rewritten Close(); } - items = new Dictionary + items = new Dictionary { - { txt_money, new WindowText(chk_money, "money_account:") }, - { txt_experience, new WindowText(chk_experience, "experience_points:") }, - { txt_loan_limit, new WindowText(chk_loan_limit, "loan_limit:") }, - { txt_long_distance, new WindowText(chk_long_distance, "long_dist:") }, - { txt_high_value_cargo, new WindowText(chk_high_value_cargo, "heavy:") }, - { txt_fragile_cargo, new WindowText(chk_fragile_cargo, "fragile:") }, - { txt_urgent_delivery, new WindowText(chk_urgent_delivery, "urgent:") }, - { txt_ecodriving, new WindowText(chk_ecodriving, "mechanical:") }, + { txt_money, new WindowItem(chk_money, "money_account:") }, + { txt_experience, new WindowItem(chk_experience, "experience_points:") }, + { txt_loan_limit, new WindowItem(chk_loan_limit, "loan_limit:") }, + { txt_long_distance, new WindowItem(chk_long_distance, "long_dist:") }, + { txt_high_value_cargo, new WindowItem(chk_high_value_cargo, "heavy:") }, + { txt_fragile_cargo, new WindowItem(chk_fragile_cargo, "fragile:") }, + { txt_urgent_delivery, new WindowItem(chk_urgent_delivery, "urgent:") }, + { txt_ecodriving, new WindowItem(chk_ecodriving, "mechanical:") }, }; KeyPressEventHandler basic = new KeyPressEventHandler(ValidateBasic); txt_money.KeyPress += basic; @@ -168,6 +192,7 @@ namespace SaveWizard_rewritten txt_ecodriving.KeyPress += skills; foreach (TextBox txtbox in items.Keys) txtbox.TextChanged += boxTextChanged; + txt_adr.TextChanged += boxTextChanged; Dictionary update_conf = new Dictionary { { "update_on_start", false } diff --git a/RegexHandler.cs b/RegexHandler.cs index fa71624..8d7a63b 100644 --- a/RegexHandler.cs +++ b/RegexHandler.cs @@ -117,6 +117,16 @@ namespace SaveWizard_rewritten return items; } + public static List GetArrayItems(int line) + { + List items = new List(); + for (int i = 0; i < GetArrayLength(line); i++) + items.Add(Regex.Match(lines[line + i + 1], ": (.+)$").Groups[1].ToString()); + if (items.Count == 0) + return null; + return items; + } + public static void AddArrayValue(int line, string value) { string name = Regex.Match(lines[line], "(.+):").Groups[1].ToString(); diff --git a/SecondForm.cs b/SecondForm.cs index 86ccb7b..dcad5d2 100644 --- a/SecondForm.cs +++ b/SecondForm.cs @@ -333,7 +333,7 @@ namespace SaveWizard_rewritten } List all_cities = AllCities(); int file_line = RegexHandler.SearchLine(search_line); - List unlocked_cities = RegexHandler.GetArrayItems(search_line); + List unlocked_cities = RegexHandler.GetArrayItems(file_line); foreach (string element in cities_list) if (all_cities.Contains(element) && (unlocked_cities == null || !unlocked_cities.Contains(element))) RegexHandler.AddArrayValue(file_line, element);