private void DrawSkill(HeroExeData hero, int skillIndex, Graphics g, Color color, Font font, float x, float top, float heightLimit, float widthLimit)
        {
            string skillStr = null;

            if (skillIndex == 1 && hero.FirstSkillIndex != -1)
            {
                skillStr = hero.Skill1.Name + " (" + hero.FirstSkillLevel + ")";
            }
            else if (skillIndex == 2 && hero.SecondSkillIndex != -1)
            {
                skillStr = hero.Skill2.Name + " (" + hero.SecondSkillLevel + ")";
            }

            if (string.IsNullOrEmpty(skillStr))
            {
                return;
            }

            SizeF sz = g.MeasureString(skillStr, font);

            if (sz.Width > widthLimit)
            {
                int firstSpace = skillStr.IndexOf(' ');
                if (firstSpace >= 0)
                {
                    skillStr = skillStr.Substring(0, firstSpace) + "\r\n" + skillStr.Substring(firstSpace + 1);
                    sz       = g.MeasureString(skillStr, font);
                }
            }

            float y = top + (heightLimit - sz.Height) / 2;

            DrawShadowedString(skillStr, g, Color.White, font, x, y);
        }
        private static int TryUpdateSpec(HeroExeData hero, DefFile un32, DefFile un44)
        {
            if (OriginalSpecs == null)
            {
                return(-1);
            }

            int index = FindOriginalSpecIndexFromSpeciality(hero.Spec);

            if (index >= 0)
            {
                un44.RetargetSprite(def44, 0, hero.Index, index);
                un32.RetargetSprite(def32, 0, hero.Index, index);

                var hs = HeroesManager.AllHeroes[hero.Index];
                hs.Speciality = SpecialityBuilder.OriginalSpecText(index);
                return(index);
            }
            else
            {
                index = FindSameIconIndexForSpeciality(hero.Spec);
                if (index >= 0)
                {
                    un44.RetargetSprite(def44, 0, hero.Index, index);
                    un32.RetargetSprite(def32, 0, hero.Index, index);
                }
                else
                {
                    CreateNewSpecImage();
                }
                var hs = HeroesManager.AllHeroes[hero.Index];
                hs.Speciality = GenerateCustomSpecText(hero);
            }
            return(index);
        }
Ejemplo n.º 3
0
        public static void LoadInfo(Heroes3Master master)
        {
            Unload();
            byte[] executableBinary = master.Executable.Data;

            Data = new List <HeroExeData>();
            int startOffset   = (int)master.Executable.HeroesSection.FindHeroGeneralDataOffset(executableBinary);
            int currentOffset = startOffset;
            int bound         = HeroesManager.AllHeroes.Count;

            for (int i = 0; i < bound; i++)
            {
                var hero = new HeroExeData
                {
                    Index            = i,
                    GenderInt        = BitConverter.ToInt32(executableBinary, currentOffset),
                    Race             = BitConverter.ToInt32(executableBinary, currentOffset + 4),
                    ClassIndex       = BitConverter.ToInt32(executableBinary, currentOffset + 8),
                    FirstSkillIndex  = BitConverter.ToInt32(executableBinary, currentOffset + 12),
                    FirstSkillLevel  = BitConverter.ToInt32(executableBinary, currentOffset + 16),
                    SecondSkillIndex = BitConverter.ToInt32(executableBinary, currentOffset + 20),
                    SecondSkillLevel = BitConverter.ToInt32(executableBinary, currentOffset + 24),
                    SpellBook        = BitConverter.ToInt32(executableBinary, currentOffset + 28),
                    SpellIndex       = BitConverter.ToInt32(executableBinary, currentOffset + 32),
                    Unit1Index       = BitConverter.ToInt32(executableBinary, currentOffset + 36),
                    Unit2Index       = BitConverter.ToInt32(executableBinary, currentOffset + 40),
                    Unit3Index       = BitConverter.ToInt32(executableBinary, currentOffset + 44)
                };
                Data.Add(hero);
                currentOffset += BLOCK_SIZE_A;
            }
        }
        public static int TryUpdateSpecialityImageAndText(Heroes3Master master, HeroExeData hero)
        {
            var un32 = master.Resolve(Speciality.IMG_FNAME_SMALL);
            var un44 = master.Resolve(Speciality.IMG_FNAME);

            var un32Def = un32.GetRecord(Speciality.IMG_FNAME_SMALL).GetDefFile();
            var un44Def = un44.GetRecord(Speciality.IMG_FNAME).GetDefFile();

            return(TryUpdateSpec(hero, un32Def, un44Def));
        }
Ejemplo n.º 5
0
        public void SaveHeroExeData(string backupFolder)
        {
            if (HeroExeData.Data != null && HeroExeData.Data.Any(f => f.HasChanged))
            {
                File.WriteAllBytes(Path.Combine(backupFolder, Executable.Name), Executable.Data);
            }


            if (HeroExeData.UpdateDataInMemory(this))
            {
                File.WriteAllBytes(Executable.Path, Executable.Data);
            }
        }
Ejemplo n.º 6
0
        public void RefreshData()
        {
            routingCache  = new Dictionary <string, LodFile>();
            BackupManager = new BackupManager();

            Resource.Unload();
            CreatureAnimationLoop.Unload();
            BitmapCache.UnloadCachedDrawItems();

            HeroesManager.LoadInfo(this);
            HeroClass.LoadInfo(this);
            CreatureManager.LoadInfo(this);
            Spell.LoadInfo(this);
            SecondarySkill.LoadInfo(this);
            StringsData.LoadInfo(this);

            Speciality.LoadInfo(this);
            Town.LoadInfo(this);
            HeroExeData.LoadInfo(this);

            BackupManager.LoadData(this);
        }
        //331 288
        public void LoadHero(int heroIndex, Heroes3Master master)
        {
            HeroIndex = heroIndex;
            Hero      = null;
            if (heroIndex > -1 && heroIndex < HeroesManager.HeroesOrder.Length && master != null)
            {
                var hs = HeroesManager.AllHeroes[heroIndex];

                var bckgImage = HeroesManager.GetBackground(master);

                var canvas = new Bitmap(bckgImage);

                var g = Graphics.FromImage(canvas);

                /*    g.InterpolationMode = InterpolationMode.High;
                 *  g.SmoothingMode = SmoothingMode.HighQuality;
                 *  g.TextRenderingHint = TextRenderingHint.AntiAliasGridFit;
                 *  g.CompositingQuality = CompositingQuality.HighQuality;*/

                g.DrawImage(bckgImage, Point.Empty);

                var portrait = master.ResolveWith(HeroesManager.HeroesOrder[hs.ImageIndex]).GetBitmap();
                g.DrawImage(portrait, new Point(4, 3));

                var heroData = HeroExeData.Data[heroIndex];

                var z = Speciality.GetImage(master, heroData.Index);
                g.DrawImage(z, new Point(4, 166));

                Hero = heroData;
                if (heroData.Skill1 != null)
                {
                    g.DrawImage(heroData.Skill1.GetImage(master, heroData.FirstSkillLevel), new Point(5, 213));
                }

                if (heroData.Skill2 != null)
                {
                    g.DrawImage(heroData.Skill2.GetImage(master, heroData.SecondSkillLevel), new Point(148, 213));
                }

                var img1 = CreatureManager.GetImage(master, heroData.Unit1Index);
                g.DrawImage(img1, new Point(5, 262));
                var img2 = CreatureManager.GetImage(master, heroData.Unit2Index);
                g.DrawImage(img2, new Point(68, 262));
                var img3 = CreatureManager.GetImage(master, heroData.Unit3Index);
                g.DrawImage(img3, new Point(129, 262));

                if (heroData.Spell != null)
                {
                    g.DrawImage(heroData.Spell.GetImage(master), 192, 262);
                }

                DrawData(g, heroData);


                //heroData.Class.Stats

                /*
                 *  g.DrawImage(ps.GetSprite(0), new Point(18, 97));
                 *  g.DrawImage(ps.GetSprite(1), new Point(88, 97));
                 *  g.DrawImage(ps.GetSprite(2), new Point(158, 97));
                 *  g.DrawImage(ps.GetSprite(5), new Point(228, 97));
                 */
                g.Dispose();
                PictureBox.Image = canvas;
                CalculateRatio();
            }
        }
        private void DrawData(Graphics g, HeroExeData hero)
        {
            var cl = hero.Class;
            var hs = HeroesManager.AllHeroes[hero.Index];

            var   strData   = StringsData.JKTEXT;
            Color mainColor = Color.FromArgb(255, 231, 148);
            SizeF sz;

            var nameFont = new Font(font1.FontFamily, 14, FontStyle.Bold);

            sz = g.MeasureString(hs.Name, nameFont);
            DrawShadowedString(hs.Name, g, mainColor, nameFont, 67 + (220 - sz.Width) / 2, 15);

            var classFont = new Font(font1.FontFamily, 9);

            sz = g.MeasureString(cl.Stats[0], classFont);
            DrawShadowedString(cl.Stats[0], g, Color.White, classFont, 67 + (220 - sz.Width) / 2, 40);


            sz = g.MeasureString(strData[1], font1);
            DrawShadowedString(strData[1], g, mainColor, font1, 16 + (44 - sz.Width) / 2, 77);

            sz = g.MeasureString(strData[2], font1);
            DrawShadowedString(strData[2], g, mainColor, font1, 86 + (44 - sz.Width) / 2, 77);

            sz = g.MeasureString(strData[3], font1);
            DrawShadowedString(strData[3], g, mainColor, font1, 156 + (44 - sz.Width) / 2, 77);

            sz = g.MeasureString(strData[4], font1);
            DrawShadowedString(strData[4], g, mainColor, font1, 226 + (44 - sz.Width) / 2, 77);


            DrawShadowedString(strData[5].Replace("{", "").Replace("}", ""), g, mainColor, font1, 52, 171);

            float  fontSize = font1.Size;
            Font   temp;
            string specName = hs.Speciality.Split('\t')[0];

            do
            {
                temp = new Font(font1.FontFamily.Name, fontSize--);
                sz   = g.MeasureString(specName, temp);
            }while (sz.Width > 93);
            DrawShadowedString(specName, g, Color.White, temp, 52, 189);

            DrawShadowedString(string.Format("{0}/{0}", cl.Mana), g, Color.White, font1, 221 + (51 - 33) / 2, 165 + 22 - 7);

            DrawSkill(hero, 1, g, Color.White, font1, 52, 213, 44, 93);
            DrawSkill(hero, 2, g, Color.White, font1, 194, 213, 44, 93);

            DrawShadowedString(cl.Attack.ToString(), g, Color.White, font1, 18 + 22 - 6, 143);
            DrawShadowedString(cl.Defense.ToString(), g, Color.White, font1, 88 + 22 - 6, 143);
            DrawShadowedString(cl.MagicPower.ToString(), g, Color.White, font1, 158 + 22 - 6, 143);
            DrawShadowedString(cl.Knowledge.ToString(), g, Color.White, font1, 228 + 22 - 6, 143);
            DrawStacks(g, Color.White, hs, new Font(font1.FontFamily, 10, FontStyle.Bold));

            //string stack1Str = hs.LowStack1 + "-" + hs.HighStack1;

            //DrawShadowedString2(stack1Str, g, Color.White, new Font(font1.FontFamily, 10, FontStyle.Bold), 34, 303);
            //DrawOutline(stack1Str, g, new Font(font1.FontFamily, 10), new Point(34, 313));
            // g.DrawString(stack1Str, new Font(font1.FontFamily, 18), new SolidBrush(Color.Yellow), 34, 213);
        }
        private static string GenerateCustomSpecText(HeroExeData hero)
        {
            string title = "", shortDescription = "", longDescription = "";
            var    spec = hero.Spec;

            // if spec is secondary skill, it would be found in original data;

            if (spec.Type == SpecialityType.CreatureLevelBonus)
            {
                var creature = CreatureManager.GetByCreatureIndex(spec.ObjectId);
                title            = creature.Plural1.ChangeFirstCharCase();
                shortDescription = "Creature Bonus: " + creature.Plural1.ChangeFirstCharCase();
                if (creature.TownIndex <= 8)
                {
                    longDescription = string.Format("Increases Speed of any {0} by 1 and their Attack and Defense skills by 5% for every {1} (rounded up)."
                                                    , GetCreatureSiblingsText(creature),
                                                    creature.CreatureTownLevel == 1 ? "level" : (creature.CreatureTownLevel + " levels"));
                }
                else
                {
                    longDescription = string.Format("Increases Speed of any {0} by 1 and their Attack and Defense skills by 5% for every 4 levels (rounded up).", creature.Plural1.ChangeFirstCharCase());
                }
            }
            else if (spec.Type == SpecialityType.Resource)
            {
                int d = 1;
                if (spec.ObjectId == (int)ResourceSpeciality.Gold350)
                {
                    d = 350;
                }

                string resourceType = Enum.GetName(typeof(ResourceSpeciality), spec.ObjectId);
                title            = "+ " + d + " " + resourceType;
                shortDescription = title + " each day.";
                longDescription  = "Increases kingdom's " + resourceType.ChangeFirstCharCase(false) + " production by " + d + " per day.";
            }
            else if (spec.Type == SpecialityType.Spell)
            {
                var spell = Spell.GetSpellByIndex(spec.ObjectId);

                title            = spell.Name;
                shortDescription = "Spell Bonus: " + spell.Name;
                longDescription  = "Casts " + spell.Name + "with effect increased by 3% for every n hero levels, where n is the level of the targeted creature.";
            }
            else if (spec.Type == SpecialityType.CreatureStaticBonus)
            {
                var creature = CreatureManager.GetByCreatureIndex(spec.ObjectId);

                int attack, defense, damage;
                spec.TryGetCreatureStaticBonuses(out attack, out defense, out damage);

                title            = creature.Plural1.ChangeFirstCharCase();
                shortDescription = "Creature Bonus: " + title;

                longDescription  = GetCreatureSiblingsText(creature);
                longDescription += " receive ";

                if (attack != 0)
                {
                    longDescription += " +" + attack + " Attack";
                }
                if (defense != 0)
                {
                    longDescription += " +" + defense + " Attack";
                }
                if (damage != 0)
                {
                    longDescription += " +" + damage + " Damage";
                }
            }
            else if (spec.Type == SpecialityType.CreaturesUpgrade)
            {
                int crFrom2 = BitConverter.ToInt32(spec.Data, 12);
                int crTo    = BitConverter.ToInt32(spec.Data, 16);

                title            = CreatureManager.GetByCreatureIndex(crTo).Plural1.ChangeFirstCharCase();
                shortDescription = "Creature Bonus: " + title;
                if (crFrom2 >= 0 || spec.ObjectId >= 0)
                {
                    longDescription = "Can upgrade ";
                    if (spec.ObjectId >= 0)
                    {
                        longDescription += GetCreatureSiblingsText(CreatureManager.GetByCreatureIndex(spec.ObjectId));
                    }

                    if (crFrom2 >= 0 && spec.ObjectId >= 0)
                    {
                        longDescription += " and ";
                    }

                    if (crFrom2 >= 0)
                    {
                        longDescription += GetCreatureSiblingsText(CreatureManager.GetByCreatureIndex(crFrom2));
                    }

                    longDescription += " to " + title;
                }
                else
                {
                    longDescription = shortDescription;
                }
            }
            return(string.Format("{0}\t{1}\t{2}", title, shortDescription, longDescription));
        }