public static BindingSource GetCaravanBindingSource() { Dictionary <ushort, SimpleVillager> WA_Database = VillagerInfo.GetVillagerDatabase(SaveType.Welcome_Amiibo); if (WA_Database != null) { foreach (var v in WA_Special_Villagers) { SimpleVillager SpecialVillager = new SimpleVillager(); SpecialVillager.Villager_ID = v.Key; SpecialVillager.Name = v.Value; WA_Database.Add(v.Key, SpecialVillager); } return(new BindingSource(WA_Database, null)); } return(new BindingSource(WA_Special_Villagers, null)); }
public static BindingSource GetCaravanBindingSource() { var waDatabase = VillagerInfo.GetVillagerDatabase(SaveType.WelcomeAmiibo); if (waDatabase == null) { return(new BindingSource(WaSpecialVillagers, null)); } foreach (var v in WaSpecialVillagers) { var specialVillager = new SimpleVillager { VillagerId = v.Key, Name = v.Value }; waDatabase.Add(v.Key, specialVillager); } return(new BindingSource(waDatabase, null)); }
public static Dictionary <ushort, SimpleVillager> GetVillagerDatabase(SaveType saveType, string language = "en") { var database = new Dictionary <ushort, SimpleVillager>(); StreamReader contents; var databaseFilename = MainForm.AssemblyLocation + "\\Resources\\{0}_Villagers_" + language + ".txt"; switch (saveType) { case SaveType.DoubutsuNoMori: case SaveType.DongwuSenlin: databaseFilename = string.Format(databaseFilename, "DnM"); break; case SaveType.DoubutsuNoMoriPlus: case SaveType.AnimalCrossing: databaseFilename = string.Format(databaseFilename, "AC"); break; case SaveType.DoubutsuNoMoriEPlus: case SaveType.AnimalForestEPlus: databaseFilename = string.Format(databaseFilename, "DBNM_e_Plus"); break; case SaveType.WildWorld: databaseFilename = string.Format(databaseFilename, "WW"); break; case SaveType.NewLeaf: databaseFilename = string.Format(databaseFilename, "NL"); break; case SaveType.WelcomeAmiibo: databaseFilename = string.Format(databaseFilename, "WA"); break; case SaveType.Unknown: break; case SaveType.CityFolk: break; default: throw new ArgumentOutOfRangeException(nameof(saveType), saveType, null); } try { contents = File.OpenText(databaseFilename); } catch (Exception e) { MessageBox.Show( $"An error occured opening villager database file:\n\"{databaseFilename}\"\nError Info:\n{e.Message}"); return(null); } string line; switch (saveType) { case SaveType.NewLeaf: case SaveType.WelcomeAmiibo: while ((line = contents.ReadLine()) != null) { if (!line.Contains("0x")) { continue; } var entry = new SimpleVillager(); var id = Regex.Match(line, @"ID = 0x....,").Value.Substring(7, 4); entry.VillagerId = ushort.Parse(id, NumberStyles.AllowHexSpecifier); var nameStr = Regex.Match(line, @"Name = .+").Value.Substring(7); entry.Name = nameStr.Substring(0, nameStr.IndexOf(',')); var personality = Regex.Match(line, @"Personality = .").Value; entry.Personality = byte.Parse(personality.Substring(personality.Length - 1, 1)); database.Add(entry.VillagerId, entry); } break; case SaveType.WildWorld: while ((line = contents.ReadLine()) != null) { if (!line.Contains("0x")) { continue; } var entry = new SimpleVillager { VillagerId = ushort.Parse(line.Substring(2, 2), NumberStyles.AllowHexSpecifier), Name = line.Substring(6) }; database.Add(entry.VillagerId, entry); } break; case SaveType.DoubutsuNoMori: case SaveType.AnimalCrossing: case SaveType.DoubutsuNoMoriPlus: case SaveType.DoubutsuNoMoriEPlus: case SaveType.AnimalForestEPlus: case SaveType.DongwuSenlin: while ((line = contents.ReadLine()) != null) { if (!line.Contains("0x")) { continue; } var entry = new SimpleVillager { VillagerId = ushort.Parse(line.Substring(2, 4), NumberStyles.AllowHexSpecifier), Name = line.Substring(8) }; database.Add(entry.VillagerId, entry); } break; case SaveType.Unknown: break; case SaveType.CityFolk: break; default: throw new ArgumentOutOfRangeException(nameof(saveType), saveType, null); } contents.Close(); contents.Dispose(); return(database); }
public static Dictionary <ushort, SimpleVillager> GetVillagerDatabase(SaveType Save_Type, string Language = "en") { Dictionary <ushort, SimpleVillager> Database = new Dictionary <ushort, SimpleVillager>(); StreamReader Contents = null; string Database_Filename = NewMainForm.Assembly_Location + "\\Resources\\{0}_Villagers_" + Language + ".txt"; switch (Save_Type) { //Temp case SaveType.Doubutsu_no_Mori_Plus: case SaveType.Doubutsu_no_Mori_e_Plus: case SaveType.Animal_Crossing: Database_Filename = string.Format(Database_Filename, "AC"); break; case SaveType.Wild_World: Database_Filename = string.Format(Database_Filename, "WW"); break; case SaveType.New_Leaf: Database_Filename = string.Format(Database_Filename, "NL"); break; case SaveType.Welcome_Amiibo: Database_Filename = string.Format(Database_Filename, "WA"); break; } try { Contents = File.OpenText(Database_Filename); } catch (Exception e) { MessageBox.Show(string.Format("An error occured opening villager database file:\n\"{0}\"\nError Info:\n{1}", Database_Filename, e.Message)); return(null); } string Line; if (Save_Type == SaveType.New_Leaf || Save_Type == SaveType.Welcome_Amiibo) { while ((Line = Contents.ReadLine()) != null) { if (Line.Contains("0x")) { SimpleVillager Entry = new SimpleVillager(); string ID = Regex.Match(Line, @"ID = 0x....,").Value.Substring(7, 4); Entry.Villager_ID = ushort.Parse(ID, NumberStyles.AllowHexSpecifier); string Name_Str = Regex.Match(Line, @"Name = .+").Value.Substring(7); Entry.Name = Name_Str.Substring(0, Name_Str.IndexOf(',')); string Personality = Regex.Match(Line, @"Personality = .").Value; Entry.Personality = byte.Parse(Personality.Substring(Personality.Length - 1, 1)); Database.Add(Entry.Villager_ID, Entry); //MessageBox.Show("ID: " + Entry.Villager_ID.ToString("X4") + " | Name: " + Entry.Name + " | Personality: " + Entry.Personality); } } } else if (Save_Type == SaveType.Wild_World) { while ((Line = Contents.ReadLine()) != null) { if (Line.Contains("0x")) { SimpleVillager Entry = new SimpleVillager { Villager_ID = ushort.Parse(Line.Substring(2, 2), NumberStyles.AllowHexSpecifier), Name = Line.Substring(6) }; Database.Add(Entry.Villager_ID, Entry); } } } else if (Save_Type == SaveType.Animal_Crossing || Save_Type == SaveType.Doubutsu_no_Mori_Plus || Save_Type == SaveType.Doubutsu_no_Mori_e_Plus) { while ((Line = Contents.ReadLine()) != null) { if (Line.Contains("0x")) { SimpleVillager Entry = new SimpleVillager { Villager_ID = ushort.Parse(Line.Substring(2, 4), NumberStyles.AllowHexSpecifier), Name = Line.Substring(8) }; Database.Add(Entry.Villager_ID, Entry); } } } return(Database); }