示例#1
0
        public List <ConsResProperties> GetResources(string source)
        {
            List <ConsResProperties> resList = new List <ConsResProperties>();

            for (int i = 0; i < Lvl4_strings.Count; i++)
            {
                for (int j = 0; j < Lvl4_strings.ElementAt(i).Strings.Count; j++)
                {
                    ConsResProperties crp = new ConsResProperties();
                    crp.Id         = Lvl4_strings.ElementAt(i).Strings.ElementAt(j).Id;
                    crp.LanguageID = (int)Lvl2_Language.ElementAt(i).Name;
                    crp.CodePage   = (int)Lvl3_Data.ElementAt(i).CodePage;
                    crp.Source     = source;

                    if (Type == ResType.XML)
                    {
                        crp.Data = XMLParser.Parse(Lvl4_strings.ElementAt(i).Strings.ElementAt(j).Data);
                    }
                    else if (Type == ResType.String)
                    {
                        crp.Data = Lvl4_strings.ElementAt(i).Strings.ElementAt(j).Data;
                    }

                    crp.Type = Type;

                    resList.Add(crp);
                }
            }

            return(resList);
        }
示例#2
0
        public List <ConsResProperties> GetResourcesByData(string data)
        {
            List <ConsResProperties> resList = new List <ConsResProperties>();

            for (int i = 0; i < Lvl4_strings.Count; i++)
            {
                for (int j = 0; j < Lvl4_strings.ElementAt(i).Strings.Count; j++)
                {
                    if (Lvl4_strings.ElementAt(i).Strings.ElementAt(j).Data.Contains(data))
                    {
                        ConsResProperties crp = new ConsResProperties();
                        crp.Id         = Lvl4_strings.ElementAt(i).Strings.ElementAt(j).Id;
                        crp.LanguageID = (int)Lvl2_Language.ElementAt(i).Name;
                        crp.CodePage   = (int)Lvl3_Data.ElementAt(i).CodePage;
                        crp.Data       = Lvl4_strings.ElementAt(i).Strings.ElementAt(j).Data;
                        crp.Type       = Type;
                        resList.Add(crp);
                    }
                }
            }

            if (resList.Count == 0)
            {
                throw new Exception("No resources contain " + data);
            }

            return(resList);
        }
示例#3
0
 public ConsResProperties GetResourceByID(int id)
 {
     for (int i = 0; i < Lvl4_strings.Count; i++)
     {
         for (int j = 0; j < Lvl4_strings.ElementAt(i).Strings.Count; j++)
         {
             if (Lvl4_strings.ElementAt(i).Strings.ElementAt(j).Id == id)
             {
                 ConsResProperties crp = new ConsResProperties();
                 crp.Id         = Lvl4_strings.ElementAt(i).Strings.ElementAt(j).Id;
                 crp.LanguageID = (int)Lvl2_Language.ElementAt(i).Name;
                 crp.CodePage   = (int)Lvl3_Data.ElementAt(i).CodePage;
                 crp.Data       = Lvl4_strings.ElementAt(i).Strings.ElementAt(j).Data;
                 crp.Type       = Type;
                 return(crp);
             }
         }
     }
     throw new Exception("Couldn't find the resource " + id);
 }
示例#4
0
        public List <ConsResProperties> GetResourcesByType(ResType type)
        {
            List <ConsResProperties> resList = new List <ConsResProperties>();

            if (Type == type)
            {
                for (int i = 0; i < Lvl4_strings.Count; i++)
                {
                    for (int j = 0; j < Lvl4_strings.ElementAt(i).Strings.Count; j++)
                    {
                        ConsResProperties crp = new ConsResProperties();
                        crp.Id         = Lvl4_strings.ElementAt(i).Strings.ElementAt(j).Id;
                        crp.LanguageID = (int)Lvl2_Language.ElementAt(i).Name;
                        crp.CodePage   = (int)Lvl3_Data.ElementAt(i).CodePage;
                        crp.Data       = Lvl4_strings.ElementAt(i).Strings.ElementAt(j).Data;
                        crp.Type       = Type;

                        resList.Add(crp);
                    }
                }
            }

            return(resList);
        }
        private void CreateElement(List <KeyValue> dataBlock)
        {
            if (dataBlock.ElementAt(0).Value.Equals("[Base]"))
            {
                int id = Convert.ToInt32((from db in dataBlock
                                          where db.Key.Equals("strid_name")
                                          select db.Value).FirstOrDefault());

                if (id != 0)
                {
                    string nickName = (from db in dataBlock
                                       where db.Key.Equals("nickname")
                                       select db.Value).FirstOrDefault().ToLower();

                    string SystemNN = (from db in dataBlock
                                       where db.Key.Equals("system")
                                       select db.Value).FirstOrDefault();

                    string hex   = id.ToString("X");
                    int    resID = Convert.ToInt32(hex.Substring(1), 16);

                    string name = (from rsrc in this.Dllstrings
                                   where rsrc.Id == resID &&
                                   rsrc.Type == ResType.String &&
                                   !rsrc.Data.Contains("\n") && !string.IsNullOrWhiteSpace(rsrc.Data) && !string.IsNullOrEmpty(rsrc.Data) && !rsrc.Data.StartsWith("I'll sell you the location of a")
                                   select rsrc.Data).FirstOrDefault();

                    List <string> details = this.GetBaseDetails(nickName, SystemNN);
                    if (details != null && name != null && details.Count > 1)
                    {
                        string infos = "";
                        if (details.ElementAt(1).Length > 1)
                        {
                            hex   = Int32.Parse(details.ElementAt(1)).ToString("X");
                            resID = Convert.ToInt32(hex.Substring(1), 16);

                            ConsResProperties chunk = (from rsrc in this.DllXml
                                                       where rsrc.Id == resID &&
                                                       rsrc.Type == ResType.XML &&
                                                       (rsrc.Source == "infocards" || rsrc.Source == "Discovery")
                                                       select rsrc).DefaultIfEmpty(null).First();

                            if (chunk == null)
                            {
                                throw new Exception("First part of the Base " + nickName + " : " + name + " infocard couldn't be found.");
                            }

                            infos = chunk.Data + "|@|@";

                            int secondHash = (from infosMap in this.InfosMap
                                              where infosMap.First == Int32.Parse(details.ElementAt(1))
                                              select infosMap.Second).FirstOrDefault();
                            if (secondHash != 0)
                            {
                                hex   = secondHash.ToString("X");
                                resID = Convert.ToInt32(hex.Substring(1), 16);
                                ConsResProperties secondChunk = (from rsrc in this.DllXml
                                                                 where rsrc.Id == resID &&
                                                                 rsrc.Type == ResType.XML &&
                                                                 (rsrc.Source == "infocards" || rsrc.Source == "Discovery" || rsrc.Source == "DsyAddition")
                                                                 select rsrc).DefaultIfEmpty(null).First();

                                if (secondChunk == null)
                                {
                                    hex   = Int32.Parse(details.ElementAt(1)).ToString("X");
                                    resID = Convert.ToInt32(hex.Substring(1), 16);
                                    string secondPart = (from rsrc in this.DllXml
                                                         where rsrc.Id == (resID + 1) &&
                                                         rsrc.Type == ResType.XML &&
                                                         rsrc.Source == chunk.Source
                                                         select rsrc.Data).DefaultIfEmpty(String.Empty).First();

                                    //if (secondPart == null)
                                    //  throw new Exception("Second part of the Base " + nickName + " : " + name + " infocard couldn't be found.");

                                    infos += secondPart;
                                }
                                else
                                {
                                    infos += secondChunk.Data;
                                }
                            }
                        }

                        this.Bases.Add(new Base(nickName, name, SystemNN.ToLower(), details.ElementAt(0), infos));
                    }
                }
            }
            else if (dataBlock.ElementAt(0).Value.Equals("[system]"))
            {
                string nickName = (from db in dataBlock
                                   where db.Key.Equals("nickname")
                                   select db.Value).FirstOrDefault().ToLower();

                int id = Convert.ToInt32((from db in dataBlock
                                          where db.Key.Equals("strid_name")
                                          select db.Value).FirstOrDefault());

                string pos = (from db in dataBlock
                              where db.Key.Equals("pos")
                              select db.Value).FirstOrDefault();
                float x = float.Parse(pos.Substring(0, pos.IndexOf(",")).Trim(), CultureInfo.InvariantCulture.NumberFormat);
                float y = float.Parse(pos.Substring(pos.IndexOf(",") + 1).Trim(), CultureInfo.InvariantCulture.NumberFormat);

                string hex   = id.ToString("X");
                int    resID = Convert.ToInt32(hex.Substring(1), 16);

                string name = (from rsrc in this.Dllstrings
                               where rsrc.Id == resID &&
                               rsrc.Type == ResType.String &&
                               !rsrc.Data.Contains("\n")
                               select rsrc.Data).FirstOrDefault();

                this.Systems.Add(new StarSystem(nickName, name, x, y));
                this.GetSystemConnections(nickName);
            }
        }