Exemplo n.º 1
0
        public MainForm()
        {
            //
            // Necessario per il supporto di Progettazione Windows Form
            //
            InitializeComponent();

            //
            // TODO: aggiungere il codice del costruttore dopo la chiamata a InitializeComponent.
            //
            DataPath.LoadPaths();
            Translation.Initialize();
            DataDumper.LoadFilesList();
            DataDumper.LoadAbilitiesConfig();
        }
Exemplo n.º 2
0
        public static string GetRaceFromLua(string luaName)
        {
            if (luaName == "")
            {
                return("none");
            }
            string lua = "";

            try
            {
                StreamReader file = new StreamReader(File.OpenRead(DataPath.GetPath(Path.Combine("research", luaName))), System.Text.Encoding.ASCII);
                file.BaseStream.Seek(0, SeekOrigin.Begin);

                lua = file.ReadToEnd();

                file.Close();
            }
            catch (Exception e)
            {
                MainForm.Log("Unable to open file: " + luaName + " Exception: " + e.Message);
                return("none");
            }

            Match m = Regex.Match(lua, @"GameData\s=\sInherit\(\[\[(?<parent>.*)\]\]\)");

            if (!m.Success)
            {
                return("none");
            }

            string parent = m.Groups["parent"].Value;

            Match mc = Regex.Match(parent, @"research\\(?<race>.*)_research\.nil");

            if (mc.Success)
            {
                return(GetRace(mc.Groups["race"].Value));
            }
            try
            {
                return(GetRaceFromLua(DataPath.GetPath(parent)));
            }
            catch (Exception e)
            {
                return("none");
            }
        }
Exemplo n.º 3
0
        // Load File Index from previous saved index
        public static bool LoadFilesList()
        {
            FilesTable = new Hashtable();

            string file = Path.Combine(Directory.GetCurrentDirectory(), "Config/FilesIndex.def");

            if (File.Exists(file))
            {
                StreamReader reader = new StreamReader(File.OpenRead(file));
                while (reader.Peek() > -1)
                {
                    string line = reader.ReadLine();

                    Match m = Regex.Match(line, @"<(?<type>.*)\>\s\<(?<race>.*)\>\s\<(?<file>.*)\>");
                    if (m.Success)
                    {
                        Group typeGr = m.Groups["type"];
                        Group raceGr = m.Groups["race"];
                        Group fileGr = m.Groups["file"];

                        string lua = fileGr.Value;

                        InfoTypes infoType = GetInfoType(typeGr.Value);
                        if (!FilesTable.Contains(lua))
                        {
                            try
                            {
                                string path = DataPath.GetPath(DataPath.GetCategoryPath(lua, infoType, raceGr.Value));
                                FilesTable.Add(/*Regex.Replace(file, @"^.*\\", "")*/ lua, new LuaInfo(path, infoType, raceGr.Value));
                            }
                            catch (Exception e)
                            {
                            }
                        }
                    }
                }
                reader.Close();
                return(true);
            }
            return(false);
        }
Exemplo n.º 4
0
        public static void Dump()
        {
            // Clear Resources
            Addons.Clear();
            Skills.Clear();
            Squads.Clear();
            Buildings.Clear();
            Units.Clear();
            Researches.Clear();
            MainForm.Log("Lua processing started...");
            DateTime start = DateTime.Now;


            Hashtable temp = (Hashtable)FilesTable.Clone();

            foreach (string lua in temp.Keys)
            {
                LuaInfo lInfo = temp[lua] as LuaInfo;
                if (lInfo.Type == InfoTypes.Building)
                {
                    StreamReader file = new StreamReader(File.OpenRead(lInfo.Path), System.Text.Encoding.ASCII);
                    file.BaseStream.Seek(0, SeekOrigin.Begin);

                    string s = file.ReadToEnd();

                    file.Close();

                    MatchCollection mccR = Regex.Matches(s, @"GameData\[""research_ext""\]\[""research_table""\]\[""research_([0-9]?[0-9]?)""\]\s=\s""(.*\\\\)?((?<research>.*)\.lua|(?<research>.*))""");
                    if (mccR.Count > 0)
                    {
                        foreach (Match mt in mccR)
                        {
                            Group research = mt.Groups["research"];

                            if (research.Success && research.Value != "")
                            {
                                string res = research.Value;
                                if (!res.EndsWith(".lua"))
                                {
                                    res += ".lua";
                                }
                                res = Path.Combine("research", res);
                                string path = DataPath.GetPath(res);

                                string  race   = GetRace(lInfo.Path);
                                LuaInfo resLua = new LuaInfo(path, InfoTypes.Research, race);

                                if (!FilesTable.Contains(res))
                                {
                                    FilesTable.Add(res, resLua);
                                }
                            }
                        }
                    }
                }
            }
            int count = FilesTable.Count;

            MainForm.BarSetMax(Bars.Data, count);
            // Collecting resources from lua files.
            foreach (string lua in FilesTable.Keys)
            {
                LuaInfo lInfo = FilesTable[lua] as LuaInfo;

                switch (lInfo.Type)
                {
                case InfoTypes.Research:
                    ResearchInfo rInfo = new ResearchInfo();
                    rInfo.Race     = lInfo.Race;
                    rInfo.FileName = Regex.Replace(lua, @"\.lua|\.nil|(.*)\\", "");

                    try
                    {
                        LuaParser.ParseResearch(lInfo.Path, rInfo);
                    }
                    catch (Exception e)
                    {
                    }

                    MainForm.BarInc(Bars.Data);
                    Researches.Add(rInfo);
                    break;

                case InfoTypes.Unit:

                    SquadInfo sInfo = new SquadInfo();
                    sInfo.Race     = lInfo.Race;
                    sInfo.FileName = Regex.Replace(lua, @"\.lua|\.nil", "");
                    LuaParser.ParseSquad(lInfo.Path, sInfo);
                    MainForm.BarInc(Bars.Data);
                    if (sInfo.Unit != null)
                    {
                        Squads.Add(sInfo);
                    }
                    break;

                case InfoTypes.Building:
                    BuildingInfo bInfo = new BuildingInfo();
                    bInfo.Race     = lInfo.Race;
                    bInfo.FileName = Regex.Replace(lua, @"\.lua|\.nil", "");
                    LuaParser.ParseBuilding(lInfo.Path, bInfo);
                    MainForm.BarInc(Bars.Data);
                    Buildings.Add(bInfo);
                    break;
                }
            }
            Researches.Sort();
            Squads.Sort();
            Buildings.Sort();

            TimeSpan elapsed = DateTime.Now - start;

            MainForm.Log("Lua processing done in " + Math.Round(elapsed.TotalSeconds, 2) + " seconds.");
        }
Exemplo n.º 5
0
        public void Parse(string lua, bool inherited, bool isChild)
        {
            if (lua != "" && !lua.EndsWith(".lua") && !lua.EndsWith(".nil"))
            {
                lua += ".lua";
            }
            IsChild = isChild;
            string path = DataPath.GetPath("abilities\\" + lua);

            if (path != "")
            {
                StreamReader file = new StreamReader(File.OpenRead(path), System.Text.Encoding.ASCII);
                file.BaseStream.Seek(0, SeekOrigin.Begin);

                string s = file.ReadToEnd();

                file.Close();

                #region CHILD ABILITY

                if (ChildSkill == null)
                {
                    Match mtc = Regex.Match(s, @"GameData\[""child_ability_name""\]\s=\s""(?<child>.*)""");
                    if (mtc.Success)
                    {
                        string child = mtc.Groups["child"].Value;

                        if (child != "" && CheckLoop(child))
                        {
                            ChildSkill             = new SkillInfo();
                            ChildSkill.Parent      = Parent;
                            ChildSkill.LuaName     = child;
                            ChildSkill.Name        = child;
                            ChildSkill.ParentSkill = this;

                            ChildSkill.Parse(child, false, true);
                        }
                    }
                }
                #endregion

                #region INHERITANCE
                Match mc = Regex.Match(s, @"GameData\s=\sInherit\(\[\[abilities\\(?<inherit>.*)\]\]\)");
                if (mc.Success)
                {
                    Group grp = mc.Groups["inherit"];
                    if (grp.Success && grp.Value != "")
                    {
                        Parse(grp.Value, true, isChild);
                    }
                }
                #endregion

                double numValue    = 0.0;
                string stringValue = "";


                if (LuaParser.ReadNumericValue(s, @"GameData\[""refresh_time""\]\s=\s(?<refresh>.*)", out numValue))
                {
                    Refresh = numValue;
                }

                if (LuaParser.ReadStringValue(s, @"GameData\[""activation""\]\s=\sReference\(\[\[type_abilityactivation\\(?<actvationType>.*)\.lua\]\]\)", out stringValue))
                {
                    ActivationType = stringValue;
                }
                if (LuaParser.ReadNumericValue(s, @"GameData\[""duration_time""\]\s=\s(?<duration>.*)", out numValue))
                {
                    Duration = numValue;
                }
                if (LuaParser.ReadNumericValue(s, @"GameData\[""initial_delay_time""\]\s=\s(?<duration>.*)", out numValue))
                {
                    Delay = numValue;
                }
                if (LuaParser.ReadNumericValue(s, @"GameData\[""recharge_time""\]\s=\s(?<duration>.*)", out numValue))
                {
                    RechargeTime = numValue;
                }
                if (Regex.Match(s, @"GameData\[""recharge_timer_global""\]\s=\strue").Success)
                {
                    GlobalTimer = true;
                }
                if (LuaParser.ReadNumericValue(s, @"GameData\[""fire_cost""\]\[""requisition""\]\s=\s(.*)", out numValue))
                {
                    RequisitionCost = (int)numValue;
                }
                if (LuaParser.ReadNumericValue(s, @"GameData\[""fire_cost""\]\[""power""\]\s=\s(.*)", out numValue))
                {
                    PowerCost = (int)numValue;
                }
                if (LuaParser.ReadNumericValue(s, @"GameData\[""area_effect""\]\[""area_effect_information""\]\[""radius""\]\s=\s(.*)", out numValue))
                {
                    Radius = numValue;
                }

                if (LuaParser.ReadNumericValue(s, @"GameData\[""range""\]\s=\s(.*)", out numValue))
                {
                    Range = numValue;
                }

                if (LuaParser.ReadNumericValue(s, @"GameData\[""time_cost""\]\[""cost""\]\[""power""\]\s=\s(.*)", out numValue))
                {
                    PowerCost = (int)numValue;
                }
                if (LuaParser.ReadNumericValue(s, @"GameData\[""time_cost""\]\[""time_seconds""\]\s=\s(.*)", out numValue))
                {
                    RechargeTime = (int)numValue;
                }

                if (LuaParser.ReadStringValue(s, @"GameData\[""area_effect""\]\[""area_effect_information""\]\[""area_type""\]\s=\sReference\(\[\[type_areaeffect\\(.*)\.lua\]\]\)", out stringValue))
                {
                    AreaType = GetAreaType(stringValue);
                }

                if (LuaParser.ReadStringValue(s, @"GameData\[""area_effect""\]\[""area_effect_information""\]\[""filter_type""\]\s=\sReference\(\[\[type_areafilter\\(.*)\.lua\]\]\)", out stringValue))
                {
                    AOEFilter = stringValue;
                }

                if (Regex.Match(s, @"GameData\[""target_ground""\]\s=\strue").Success)
                {
                    TargetGround = true;
                }

                if (LuaParser.ReadStringValue(s, @"GameData\[""spawned_entity_name""\]\s=\s""(?<spawn>.*\.lua)""", out stringValue))
                {
                    bool     loopcheck = true;
                    UnitInfo root      = null;
                    if (this.RootParent is UnitInfo)
                    {
                        root = RootParent as UnitInfo;
                        string spawnName = Regex.Replace(stringValue, @".*\\\\", "");
                        if (root.FileName == spawnName)
                        {
                            loopcheck = false;
                        }
                    }
                    if (loopcheck)
                    {
                        UnitInfo uInfo = new UnitInfo();
                        LuaParser.ParseUnit(DataPath.GetPath(Regex.Replace(stringValue, @"\\\\", "\\")), uInfo);
                        Spawn = uInfo;
                    }
                }
                if (LuaParser.ReadStringValue(s, @"GameData\[""ui_info""\]\[""icon_name""\]\s=\s""(.*)""", out stringValue))
                {
                    Icon = stringValue;
                }


                if (LuaParser.ReadNumericValue(s, @"GameData\[""area_effect""\]\[""weapon_damage""\]\[""armour_damage""\]\[""armour_piercing""\]\s=\s(.*)", out numValue))
                {
                    BasePiercing = numValue;
                }
                if (LuaParser.ReadNumericValue(s, @"GameData\[""area_effect""\]\[""weapon_damage""\]\[""armour_damage""\]\[""morale_damage""\]\s=\s(.*)", out numValue))
                {
                    MoraleDamage = numValue;
                }

                if (LuaParser.ReadNumericValue(s, @"\[""ui_info""\]\[""screen_name_id""\]\s=\s""\$(.*)""", out numValue))
                {
                    UI = (int)numValue;
                }

                string luaName = Regex.Replace(path, @".*\\", "");

                if (!inherited && !isChild)
                {
                    Name = Translation.Translate(UI, luaName);
                }


                MatchCollection mtcs = Regex.Matches(s, @"GameData\[""area_effect""\]\[""area_effect_information""\]\[""target_filter""\]\[""(?<filter_entry>entry_[0-9][0-9])""\]\s=\sReference\(\[\[type_armour\\(?<armour_type>.*)\.lua\]\]\)");
                foreach (Match m in mtcs)
                {
                    ArmorTypes armor;
                    string     entry      = m.Groups["filter_entry"].Value;
                    string     armourType = m.Groups["armour_type"].Value;
                    try
                    {
                        armor = (ArmorTypes)Enum.Parse(typeof(ArmorTypes), armourType);
                    }
                    catch { armor = ArmorTypes.unknown; }

                    if (!Filter.ContainsKey(entry))
                    {
                        Filter.Add(entry, armor);
                    }
                    else if (armor != ArmorTypes.unknown)
                    {
                        Filter[entry] = armor;
                    }
                    else
                    {
                        Filter.Remove(entry);
                    }
                }

                #region DPS

                if (LuaParser.ReadNumericValue(s, @"GameData\[""area_effect""\]\[""weapon_damage""\]\[""armour_damage""\]\[""min_damage""\]\s=\s(.*)", out numValue))
                {
                    MinDamage = numValue;
                }
                if (LuaParser.ReadNumericValue(s, @"GameData\[""area_effect""\]\[""weapon_damage""\]\[""armour_damage""\]\[""max_damage""\]\s=\s(.*)", out numValue))
                {
                    MaxDamage = numValue;
                }
                if (LuaParser.ReadNumericValue(s, @"GameData\[""area_effect""\]\[""throw_data""\]\[""force_min""\]\s=\s(.*)", out numValue))
                {
                    MinForce = numValue;
                }
                if (LuaParser.ReadNumericValue(s, @"GameData\[""area_effect""\]\[""throw_data""\]\[""force_max""\]\s=\s(.*)", out numValue))
                {
                    MaxForce = numValue;
                }


                MatchCollection aMcs = Regex.Matches(s, @"GameData\[""area_effect""\]\[""weapon_damage""\]\[""armour_damage""\]\[""armour_piercing_types""\]\[""entry_(?<armor_entry>[0-9][0-9])""\]\[""armour_type""\]\s=\sReference\(\[\[type_armour\\(?<armor_type>.*)\.lua\]\]\)");

                foreach (Match m in aMcs) // Retrieve ArmorTypes entries
                {
                    string armor = m.Groups["armor_type"].Value;


                    int armorEntry = System.Convert.ToInt32(Regex.Replace(m.Groups["armor_entry"].Value, "\b0", ""), LuaParser.NumberFormat);

                    if (!ArmorPiercingValues.Contains(armorEntry))
                    {
                        ArmorPiercing ap = new ArmorPiercing();
                        ap.Entry = armorEntry;
                        try
                        {
                            ap.ArmorType = (ArmorTypes)Enum.Parse(typeof(ArmorTypes), armor);
                        }
                        catch { ap.ArmorType = ArmorTypes.unknown; }
                        ArmorPiercingValues.Add(armorEntry, ap);
                    }
                    else
                    {
                        ArmorPiercing ap = ArmorPiercingValues[armorEntry] as ArmorPiercing;
                        ap.Entry = armorEntry;
                        try
                        {
                            ap.ArmorType = (ArmorTypes)Enum.Parse(typeof(ArmorTypes), armor);
                        }
                        catch { ap.ArmorType = ArmorTypes.unknown; }
                    }
                }

                foreach (ArmorPiercing ap in ArmorPiercingValues.Values)
                {
                    if (ap.ArmorType != ArmorTypes.unknown)
                    {
                        string subIndex = "";
                        int    j        = ap.Entry;
                        if (j < 10)
                        {
                            subIndex = "0" + j.ToString();
                        }
                        else
                        {
                            subIndex = j.ToString();
                        }
                        if (LuaParser.ReadNumericValue(s, @"GameData\[""area_effect""\]\[""weapon_damage""\]\[""armour_damage""\]\[""armour_piercing_types""\]\[""entry_+" + subIndex + @"""\]\[""armour_piercing_value""\]\s=\s(.*)", out numValue))
                        {
                            ap.PiercingValue = numValue;
                        }
                    }
                    else
                    {
                        ap.PiercingValue = 0.0;
                    }
                }
                #endregion


                LuaParser.ParseToolTips(s, this);
                LuaParser.ParseRequirements(s, this);
                LuaParser.ParseModifiers(s, this, this.Modifiers, AreaOfEffectTypes.area_effect);
            }
        }