Ejemplo n.º 1
0
 public void getCurrentAddonEnglish()
 {
     // Parse addon_english.txt KV
     KeyValue[] addonEnglishKeyVals = KVParser.ParseAllKVRootNodes(System.IO.File.ReadAllText(addonEnglishPath));
     for (int i = 0; i < addonEnglishKeyVals.Length; i++)
     {
     }
 }
Ejemplo n.º 2
0
        private void LoadKeyValuesFromFile(string path, bool InVpk)
        {
            string text = "";

            if (InVpk)
            {
                text = DotaVPKService.Instance.ReadTextFromVPK(path);
            }
            else
            {
                text = File.ReadAllText(path);
            }

            KeyValue kv = KVParser.ParseKeyValueText(text);

            KeyValueNode = kv;
        }
Ejemplo n.º 3
0
        public void getUnitTooltips()
        {
            unitEntries.Clear();
            KeyValue[]             unitsKeyVals = KVParser.ParseAllKVRootNodes(System.IO.File.ReadAllText(unitsCustomPath));
            IEnumerable <KeyValue> children     = unitsKeyVals[0].Children;

            for (int i = 0; i < children.Count(); i++)
            {
                string unit = children.ElementAt(i).Key;
                if (unit != "Version")
                {
                    unitEntries.Add(new UnitEntry(unit));
                }
            }
            for (int i = 0; i < unitEntries.Count(); i++)
            {
                // Debug.WriteLine(unitEntries.ElementAt(i).ToString());
            }
        }
Ejemplo n.º 4
0
        public ObservableCollection <KeyValue> ReadKeyValuesFromFile(string path, string rootKey)
        {
            a = "";
            if (!File.Exists(path))
            {
                File.Create(path).Close();
                emptyFile = true;
            }
            a = File.ReadAllText(path);
            KeyValue kv = KVParser.ParseKeyValueText(a);

            Console.WriteLine(kv.Key);
            if (kv.Key != rootKey)
            {
                Utils.CreateNewFile(path, rootKey);
            }
            foreach (KeyValue data in GetChildren(kv))
            {
                tempList.Add((KeyValue)data);
            }
            return(tempList);
        }
Ejemplo n.º 5
0
        private void parseLanguageFile()
        {
            KeyValue[] addon_lang = KVParser.ParseAllKVRootNodes(File.ReadAllText(Lang));

            if (addon_lang.Count() > 0)
            {
                IEnumerable <KeyValue> rootChildren = addon_lang[0].Children;

                for (int k = 0; k < rootChildren.Count(); k++)
                {
                    KeyValue child = rootChildren.ElementAt(k);
                    if (child.Key == "Language")
                    {
                        // extract language name
                        languageName = child.GetString();
                    }
                    if (child.Key == "Tokens")
                    {
                        if (child.HasChildren)
                        {
                            // store the main addon_language keys and vals.
                            LangKV = child.Children;
                            // extract some basic info while we're here
                            for (int i = 0; i < LangKV.Count(); i++)
                            {
                                KeyValue kv = LangKV.ElementAt(i);
                                string   v  = kv.GetString();
                                if (kv.Key == "addon_game_name")
                                {
                                    AddonName = v;
                                }
                            }
                        }
                    }
                }
            }
        }
Ejemplo n.º 6
0
        public void getHeroesTooltips()
        {
            heroesEntries.Clear();
            KeyValue[]             heroesKeyVals = KVParser.ParseAllKVRootNodes(System.IO.File.ReadAllText(heroesCustomPath));
            IEnumerable <KeyValue> children      = heroesKeyVals[0].Children;

            for (int i = 0; i < children.Count(); i++)
            {
                KeyValue child = children.ElementAt(i);
                if (child.HasChildren)
                {
                    IEnumerable <KeyValue> children2 = child.Children;
                    for (int j = 0; j < children2.Count(); j++)
                    {
                        KeyValue child2 = children2.ElementAt(j);
                        if (child2.Key == "override_hero")
                        {
                            HeroEntry h = new HeroEntry(child2.GetString());
                            //Debug.WriteLine(h.ToString());
                        }
                    }
                }
            }
        }
Ejemplo n.º 7
0
        /// <summary>
        /// Try to find the route where Steam and Dota 2 are installed.
        /// </summary>
        /// <returns></returns>
        static void FindGameDirectory()
        {
            // Look for the Steam installation path in the registry.
            string steamDirectory = (string)Registry.GetValue("HKEY_CURRENT_USER\\Software\\Valve\\Steam", "SteamPath", null);

            // So... you dont have it in the registry huh.
            if (steamDirectory == null || !Directory.Exists(steamDirectory))
            {
                Console.WriteLine("The Steam installation path could not be found from the registry. Do you have Steam installed?");
                goto unableToObtain;
            }

            string configFile = steamDirectory + "/config/config.vdf";

            // So... you dont have Steam Configuration file...
            if (!File.Exists(configFile))
            {
                Console.WriteLine("The Steam installation path has been found, but the configuration file dont exist!");
                goto unableToObtain;
            }

            try {
                // Read and Parse the Steam configuration file.
                String   configData = File.ReadAllText(configFile);
                KeyValue values     = KVParser.ParseKeyValueText(configData);

                KeyValue software = FindChildren(values, "Software");
                KeyValue valve    = FindChildren(software, "Valve");
                KeyValue steam    = FindChildren(valve, "Steam");

                KeyValue installFolder1 = FindChildren(steam, "BaseInstallFolder_1");
                KeyValue installFolder2 = FindChildren(steam, "BaseInstallFolder_2");

                // Try with 2 routes
                string baseInstallFolder  = null;
                string baseInstallFolder2 = null;

                if (installFolder1 != null)
                {
                    baseInstallFolder = installFolder1.GetString();
                }

                if (installFolder2 != null)
                {
                    baseInstallFolder2 = installFolder2.GetString();
                }

                String gamePathExt = "\\steamapps\\common\\dota 2 beta\\game";

                if (baseInstallFolder != null && Directory.Exists(baseInstallFolder + gamePathExt))
                {
                    gameDirectory = baseInstallFolder + gamePathExt;
                }
                else if (baseInstallFolder2 != null && Directory.Exists(baseInstallFolder2 + gamePathExt))
                {
                    gameDirectory = baseInstallFolder2 + gamePathExt;
                }
                else if (Directory.Exists(steamDirectory + gamePathExt))
                {
                    gameDirectory = steamDirectory + gamePathExt;
                }
                else
                {
                    goto unableToObtain;
                }

                goto setupPaths;
            }
            catch (Exception why) {
                Console.WriteLine("There was a problem reading the Steam configuration file, please report the following message: " + why.Message);
                goto unableToObtain;
            }

unableToObtain:
            Console.WriteLine("Unable to obtain the location of the Dota 2 folder. Checking if we are already in the /game/ folder...");

setupPaths:
            // ?
            if (!Directory.Exists(gameDirectory + "\\dota\\"))
            {
                Console.WriteLine();
                Console.WriteLine(gameDirectory);
                Abort("We are sorry but the Dota 2 installation folder could not be found. Try placing the Updater files in the /game/ folder of Dota 2.");
            }

            installDirectory = gameDirectory + "\\dota_divine_ui";
            versionFilePath  = installDirectory + "\\version.txt";
        }
Ejemplo n.º 8
0
        static void Main(string[] args)
        {
            Dictionary <string, string> langdict = new Dictionary <string, string>();

            KVItem langtree = KVParser.ReadFromFile("tf_english.txt");

            for (int i = 0; i < langtree.subItems.Count; i++)
            {
                for (int x = 0; x < langtree.subItems[i].subItems.Count; x++)
                {
                    KVItem subitem = langtree.subItems[i].subItems[x];
                    string lower   = subitem.key.ToLower();

                    langdict.Add(lower, subitem.value);
                }
            }

            KVItem        tree    = KVParser.ReadFromFile("items.txt");
            List <short>  indexes = new List <short>();
            List <string> names   = new List <string>();

            for (int i = 0; i < tree.subItems.Count; i++)
            {
                string index = tree.subItems[i].key;

                for (int x = 0; x < tree.subItems[i].subItems.Count; x++)
                {
                    KVItem subitem = tree.subItems[i].subItems[x];

                    if (subitem.key == "item_name")
                    {
                        string lang = subitem.value;

                        if (lang.Substring(0, 1) == "#")
                        {
                            lang = langdict[lang.Substring(1).ToLower()];
                            if (lang.Length > 63)
                            {
                                lang = lang.Substring(0, 63);
                            }
                        }

                        indexes.Add(Int16.Parse(index));
                        names.Add(lang);

                        break;
                    }
                }
            }

            FileStream   fs = File.Create("item.db");
            BinaryWriter bw = new BinaryWriter(fs);

            bw.Write((Int16)indexes.Count);
            for (int x = 0; x < indexes.Count; x++)
            {
                bw.Write(indexes[x]);
                bw.Write(names[x]);
            }

            bw.Close();
            fs.Close();

            Console.WriteLine("Completed. (" + indexes.Count + " items)");
        }
Ejemplo n.º 9
0
        private bool parse()
        {
            if (!File.Exists(wiki.Addon.HeroesCustomPath))
            {
                return false;
            }

            KeyValue[] heroKeyVals = KVParser.ParseAllKVRootNodes(File.ReadAllText(wiki.Addon.HeroesCustomPath));

            // ensure we can get to the main heroKey data.
            if (heroKeyVals.Count() == 0 || !heroKeyVals[0].HasChildren)
            {
                return false;
            }

            IEnumerable<KeyValue> entries = heroKeyVals[0].Children;

            for (int i = 0; i < entries.Count(); i++)
            {
                // create a new heroKey hero from this data
                HeroEntry hero = new HeroEntry();

                KeyValue heroKey = entries.ElementAt(i);
                hero.kvName = heroKey.Key;
                if (heroKey.HasChildren)
                {
                    IEnumerable<KeyValue> children = heroKey.Children;
                    for (int j = 0; j < children.Count(); j++)
                    {
                        KeyValue child = children.ElementAt(j);
                        string k = child.Key;
                        string v = child.GetString();

                        // Extract num of abilities.
                        if (k == "AbilityLayout")
                        {
                            hero.numAbilities = Int32.Parse(v);
                        }
                        // extract heroKey name.
                        else if (k == "override_hero")
                        {
                            hero.baseName = v;
                        }
                        else if (k.Contains("Ability"))
                        {
                            int abilNum = Int32.Parse(k.Substring(7));
                            hero.abilities[abilNum] = v;
                        }
                        else if (k == "MovementTurnRate")
                        {
                            hero.movementTurnRate = v;
                        }
                        else if (k == "MovementSpeed")
                        {
                            hero.movementSpeed = v;
                        }
                        else if (k == "VisionDaytimeRange")
                        {
                            hero.visionDaytimeRange = v;
                        }
                        else if (k == "VisionNighttimeRange")
                        {
                            hero.visionNighttimeRange = v;
                        }
                        else if (k == "MovementSpeed")
                        {
                            hero.movementSpeed = v;
                        }
                        else if (k == "StatusHealth")
                        {
                            hero.statusHealth = v;
                        }
                        else if (k == "AttackCapabilities")
                        {
                            hero.attackCapabilities = v;
                        }
                        else if (k == "AttackRate")
                        {
                            hero.attackRate = v;
                        }
                        else if (k == "StatusMana")
                        {
                            hero.statusMana = v;
                        }
                        else if (k == "AttackDamageMin")
                        {
                            hero.attackDamageMin = v;
                        }
                        else if (k == "AttackDamageMax")
                        {
                            hero.attackDamageMax = v;
                        }
                        else if (k == "MovementCapabilities")
                        {
                            hero.movementCapabilities = v;
                        }
                    }
                    // now extract the useful info from the LangKV.
                    for (int j = 0; j < wiki.LangKV.Count(); j++)
                    {
                        KeyValue kv = wiki.LangKV.ElementAt(j);
                        // check for ex. npc_dota_hero_blah
                        if (kv.Key == hero.baseName)
                        {
                            hero.actualName = kv.GetString();
                            // this is the only useful thing to extract for heroes, so break here is fine.
                            break;
                        }
                    }

                    heroEntries.Add(hero);
                }
            }

            return true;
        }
Ejemplo n.º 10
0
        public void writeTooltips()
        {
            alreadyHasKeys.Clear();
            if (Directory.Exists(addonEnglishPath))
            {
                KeyValue[]             currAddonEnglish = KVParser.ParseAllKVRootNodes(System.IO.File.ReadAllText(addonEnglishPath));
                IEnumerable <KeyValue> children         = currAddonEnglish[0].Children;

                for (int i = 0; i < children.Count(); i++)
                {
                    KeyValue child = children.ElementAt(i);
                    if (child.HasChildren)
                    {
                        IEnumerable <KeyValue> children2 = child.Children;
                        for (int j = 0; j < children2.Count(); j++)
                        {
                            KeyValue child2 = children2.ElementAt(j);
                            alreadyHasKeys.Add(child2.Key);
                        }
                    }
                }
            }

            // WriteAllText will clear the contents of this file first
            string header =
                "// **********************************************************************************************************************\n" +
                "// This file contains generated tooltips created from the files in the scripts/npc directory of this mod.\n" +
                "// It does not contain tooltips already defined in addon_english.txt, nor modifiers with the property \"IsHidden\" \"1\".\n" +
                "// **********************************************************************************************************************\n";

            System.IO.File.WriteAllText(generatedTooltips, header, Encoding.Unicode);


            string head1 = "\n// ******************** HEROES ********************\n";

            System.IO.File.AppendAllText(GeneratedTooltips, head1, Encoding.Unicode);
            for (int i = 0; i < heroesEntries.Count(); i++)
            {
                HeroEntry hero = heroesEntries.ElementAt(i);
                if (!alreadyHasKeys.Contains(hero.Hero.Key))
                {
                    System.IO.File.AppendAllText(GeneratedTooltips, hero.ToString(), Encoding.Unicode);
                }
            }

            string head2 = "\n// ******************** UNITS ********************\n";

            System.IO.File.AppendAllText(GeneratedTooltips, head2, Encoding.Unicode);
            for (int i = 0; i < unitEntries.Count(); i++)
            {
                UnitEntry unit = unitEntries.ElementAt(i);
                if (!alreadyHasKeys.Contains(unit.Name.Key))
                {
                    System.IO.File.AppendAllText(GeneratedTooltips, unit.ToString(), Encoding.Unicode);
                }
            }

            string head3 = "\n// ******************** ABILITY MODIFIERS ********************\n";

            System.IO.File.AppendAllText(GeneratedTooltips, head3, Encoding.Unicode);
            for (int i = 0; i < modifierAbilityEntries.Count(); i++)
            {
                ModifierEntry mod = modifierAbilityEntries.ElementAt(i);
                if (!alreadyHasKeys.Contains(mod.Name.Key))
                {
                    System.IO.File.AppendAllText(GeneratedTooltips, mod.ToString() + "\n", Encoding.Unicode);
                }
            }

            string head6 = "\n// ******************** ITEM MODIFIERS ********************\n";

            System.IO.File.AppendAllText(GeneratedTooltips, head6, Encoding.Unicode);
            for (int i = 0; i < modifierItemEntries.Count(); i++)
            {
                ModifierEntry mod = modifierItemEntries.ElementAt(i);
                if (!alreadyHasKeys.Contains(mod.Name.Key))
                {
                    System.IO.File.AppendAllText(GeneratedTooltips, mod.ToString() + "\n", Encoding.Unicode);
                }
            }

            string head4 = "\n// ******************** ABILITIES ********************\n";

            System.IO.File.AppendAllText(GeneratedTooltips, head4, Encoding.Unicode);
            for (int i = 0; i < abilityEntries.Count(); i++)
            {
                AbilityEntry abil = abilityEntries.ElementAt(i);
                if (!alreadyHasKeys.Contains(abil.Name.Key))
                {
                    System.IO.File.AppendAllText(GeneratedTooltips, abil.ToString() + "\n", Encoding.Unicode);
                }
            }

            string head5 = "\n// ******************** ITEMS ********************\n";

            System.IO.File.AppendAllText(GeneratedTooltips, head5, Encoding.Unicode);
            for (int i = 0; i < itemEntries.Count(); i++)
            {
                AbilityEntry item = itemEntries.ElementAt(i);
                if (!alreadyHasKeys.Contains(item.Name.Key))
                {
                    System.IO.File.AppendAllText(GeneratedTooltips, item.ToString() + "\n", Encoding.Unicode);
                }
            }

            /*string head7 = "\n// ******************** HIDDEN MODIFIERS ********************\n";
             * System.IO.File.AppendAllText(GeneratedTooltips, head7, Encoding.Unicode);
             * for (int i = 0; i < hiddenModifierEntries.Count(); i++)
             * {
             *  ModifierEntry mod = hiddenModifierEntries.ElementAt(i);
             *  if (!alreadyHasKeys.Contains(mod.Name.Key))
             *  {
             *      System.IO.File.AppendAllText(GeneratedTooltips, mod.ToString() + "\n", Encoding.Unicode);
             *  }
             * }*/

            // open the tooltips.txt in a text editor
            Process.Start(Path.Combine(gamePath, "resource", "tooltips.txt"));

            //MessageBox.Show("Tooltips successfully generated in: " + Path.Combine(gamePath,"resource", "tooltips.txt"), "Success",
            //    MessageBoxButtons.OK, MessageBoxIcon.Information);
        }
Ejemplo n.º 11
0
        public void getAbilityTooltips(bool items)
        {
            if (items)
            {
                itemEntries.Clear();
                modifierItemEntries.Clear();
            }
            else
            {
                AbilityEntries.Clear();
                modifierAbilityEntries.Clear();
            }
            //hiddenModifierEntries.Clear();

            // Parse abilities_custom.txt KV

            KeyValue[] abilitiesCustomKeyVals = KVParser.ParseAllKVRootNodes(System.IO.File.ReadAllText(AbilitiesCustomPath));
            if (items)
            {
                abilitiesCustomKeyVals = KVParser.ParseAllKVRootNodes(System.IO.File.ReadAllText(ItemsCustomPath));
            }

            IEnumerable <KeyValue> abilityNames = abilitiesCustomKeyVals[0].Children;

            for (int i = 0; i < abilityNames.Count(); i++)
            {
                KeyValue ability = abilityNames.ElementAt(i);
                if (ability.Key == "Version")
                {
                    continue;
                }
                // NOTE: can't have a blank comment (//) above the ability or else the Key will be blank.
                //Debug.WriteLine("Abil name: " + ability.Key);
                if (ability.HasChildren)
                {
                    IEnumerable <KeyValue> children = ability.Children;
                    // Find the abilityspecial stuff.
                    for (int j = 0; j < children.Count(); j++)
                    {
                        KeyValue child = children.ElementAt(j);
                        if (child.Key == "AbilitySpecial" || child.Key == "Modifiers")
                        {
                            bool modifiers = false;
                            if (child.Key == "Modifiers")
                            {
                                modifiers = true;
                            }

                            // We have the AbilitySpecial now. See if there is actually anything in it.
                            if (child.HasChildren)
                            {
                                List <string>          kvs       = new List <string>();
                                IEnumerable <KeyValue> children2 = child.Children;
                                for (int k = 0; k < children2.Count(); k++)
                                {
                                    KeyValue child2   = children2.ElementAt(k);
                                    bool     isHidden = false;
                                    if (child2.HasChildren)
                                    {
                                        IEnumerable <KeyValue> children3 = child2.Children;
                                        for (int l = 0; l < children3.Count(); l++)
                                        {
                                            KeyValue child3 = children3.ElementAt(l);
                                            if (modifiers)
                                            {
                                                if (child3.Key == "IsHidden")
                                                {
                                                    // Ensure it's actually hidden.
                                                    Debug.WriteLine("IsHidden? " + child3.GetString());
                                                    if (child3.GetString() == "1")
                                                    {
                                                        isHidden = true;
                                                    }
                                                }
                                            }
                                            else // we have a modifier, not ability.
                                            {
                                                // Map item name to its item specials.
                                                if (child3.Key != "var_type")
                                                {
                                                    kvs.Add(child3.Key);
                                                }
                                            }
                                        }
                                    }
                                    // we're done going through all the children of this ability/modifier.
                                    if (modifiers)
                                    {
                                        if (!isHidden)
                                        {
                                            if (items)
                                            {
                                                modifierItemEntries.Add(new ModifierEntry(child2.Key));
                                            }
                                            else
                                            {
                                                modifierAbilityEntries.Add(new ModifierEntry(child2.Key));
                                            }
                                        }
                                        else
                                        {
                                            //hiddenModifierEntries.Add(new ModifierEntry(child2.Key));
                                        }
                                    }
                                }
                                if (!modifiers)
                                {
                                    if (items)
                                    {
                                        itemEntries.Add(new AbilityEntry(ability.Key, kvs));
                                    }
                                    else
                                    {
                                        AbilityEntries.Add(new AbilityEntry(ability.Key, kvs));
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
Ejemplo n.º 12
0
 private static KeyValue parseKVStream(Stream s)
 {
     return(KVParser.ParseAllKVRootNodes(s.ReadAsUTF8())[0]);
 }