Exemplo n.º 1
0
        public static Bitmap GetSkillsForSpeciality(Heroes3Master master)
        {
            if (_specImage != null)
            {
                return(_specImage);
            }

            if (_defFile == null)
            {
                _defFile = master.ResolveWith(IMG_FNAME).GetDefFile();
            }

            int rowNum = IndexesOfAllSpecSkills.Length / SPEC_COLNUMBER + (IndexesOfAllSpecSkills.Length % SPEC_COLNUMBER == 0 ? 0 : 1);

            var bmp       = new Bitmap((44 + 1) * SPEC_COLNUMBER, (44 + 1) * rowNum, System.Drawing.Imaging.PixelFormat.Format24bppRgb);
            var imageData = bmp.LockBits24();

            Parallel.For(0, IndexesOfAllSpecSkills.Length, i =>
            {
                int row = i / SPEC_COLNUMBER;
                int col = i % SPEC_COLNUMBER;

                var img = _defFile.GetByAbsoluteNumber2(3 + IndexesOfAllSpecSkills[i] * 3);
                imageData.DrawImage24(col * (44 + 1), row * (44 + 1), 132, img);
            });

            bmp.UnlockBits(imageData);
            _specImage = bmp;

            return(_specImage);
        }
Exemplo n.º 2
0
        public static Bitmap GetAllResources(Heroes3Master master)
        {
            if (BitmapCache.ResourcesAll != null)
            {
                return(BitmapCache.ResourcesAll);
            }

            var h3sprite = master.Resolve(IMG_FNAME);

            if (defFile == null)
            {
                defFile = h3sprite.GetRecord(IMG_FNAME).GetDefFile();
            }

            var bmp       = new Bitmap((82 + 1) * 7, 93, System.Drawing.Imaging.PixelFormat.Format24bppRgb);
            var imageData = bmp.LockBits24();

            Parallel.For(0, 7, i =>
            {
                var img = defFile.GetByAbsoluteNumber2(i);
                imageData.DrawImage24(i * (82 + 1), 0, 248, img);
            });

            bmp.UnlockBits(imageData);
            BitmapCache.ResourcesAll = bmp;

            return(BitmapCache.ResourcesAll);
        }
Exemplo n.º 3
0
        public static Bitmap GetSkillTreeForHeroClass(Heroes3Master master)
        {
            if (_skillTree != null)
            {
                return(_skillTree);
            }

            if (_defFile == null)
            {
                _defFile = master.ResolveWith(IMG_FNAME).GetDefFile();
            }

            var bmp = new Bitmap(44 * 7, (44 + 20) * 4);

            using (var g = Graphics.FromImage(bmp))
            {
                for (int i = 0; i < 4; i++)
                {
                    for (int j = 0; j < 7; j++)
                    {
                        g.DrawImage(_defFile.GetByAbsoluteNumber(3 + (i * 7 + j) * 3), j * 44, 64 * i);
                    }
                }
            }
            _skillTree = bmp;
            return(_skillTree);
        }
Exemplo n.º 4
0
        public static Bitmap GetAvailableSpellsForSpeciality(Heroes3Master master)
        {
            if (BitmapCache.SpellsForSpeciality != null)
            {
                return(BitmapCache.SpellsForSpeciality);
            }

            if (defFile == null)
            {
                defFile = master.ResolveWith(IMG_FNAME).GetDefFile();
            }

            var bmp       = new Bitmap((58 + 1) * 6, (64 + 1) * 5);
            var imageData = bmp.LockBits24();

            Parallel.For(0, SpecSpellIndexes.Length, i =>
            {
                int row = i / 6;
                int col = i % 6;

                var img = defFile.GetByAbsoluteNumber2(AllSpells[SpecSpellIndexes[i]].Index);
                if (img != null)
                {
                    imageData.DrawImage24(col * (58 + 1), row * (64 + 1), 176, img);
                }
            });

            bmp.UnlockBits(imageData);
            BitmapCache.SpellsForSpeciality = bmp;
            return(BitmapCache.SpellsForSpeciality);
        }
Exemplo n.º 5
0
        public static void LoadInfo(Heroes3Master master)
        {
            Unload();

            var lodFile = master.Resolve(TXT_FNAME);
            var rec     = lodFile[TXT_FNAME];

            string text = Encoding.Default.GetString(rec.GetRawData(lodFile.stream));

            allRows = text.Split(new[] { "\r\n" }, StringSplitOptions.None);

            AllSpells = new List <Spell>(allRows.Length);
            int index = 0;

            for (int i = 5; i < allRows.Length; i++)
            {
                string row = allRows[i];
                if (row.StartsWith("Creature Abilities"))
                {
                    break;
                }

                if (string.IsNullOrEmpty(row) || row.StartsWith("\t\t\t") || row.StartsWith("Combat Spells") || row.StartsWith("Adventure Spells") || row.StartsWith("Name"))
                {
                    continue;
                }

                AllSpells.Add(new Spell(index++, row));
            }
            defFile = null;
        }
Exemplo n.º 6
0
 private void button4_Click(object sender, EventArgs e)
 {
     if (lbFiles.SelectedIndex != -1)
     {
         FatRecord rec = selectedLodFile[lbFiles.SelectedItem.ToString()];
         if (rec.Extension == "TXT" || rec.Extension == "ZBK")
         {
             rtbMain.Text = Encoding.Default.GetString(rec.GetRawData());
         }
         else if (rec.Extension == "PCX")
         {
             bmp = rec.GetBitmap();
             Invalidate();
         }
         else if (rec.Extension == "DEF")
         {
             def = rec.GetDefFile();
             bmp = def.GetSprite(0, 0);
             lbDecomposed.Items.Clear();
             for (int i = 0; i < def.BlockCount; i++)
             {
                 lbDecomposed.Items.AddRange(def.headers[i].Names);
             }
         }
     }
 }
Exemplo n.º 7
0
        public static Bitmap GetAllCreaturesBitmapParallel(Heroes3Master master)
        {
            if (BitmapCache.CreaturesAll != null)
            {
                return(BitmapCache.CreaturesAll);
            }

            var h3sprite = master.Resolve(IMG_FNAME);

            if (creatureDef == null)
            {
                creatureDef = h3sprite.GetRecord(IMG_FNAME).GetDefFile();
            }

            int totalrows = OnlyActiveCreatures.Count / 14 + (OnlyActiveCreatures.Count % 14 == 0 ? 0 : 1);
            var bmp       = new Bitmap((58 + 1) * 14, (64 + 1) * totalrows);
            var imageData = bmp.LockBits24();

            Parallel.For(0, OnlyActiveCreatures.Count, i =>
            {
                int row = i / 14;
                int col = i % 14;
                var img = creatureDef.GetByAbsoluteNumber2(OnlyActiveCreatures[i].CreatureIndex + 2);
                if (img != null)
                {
                    imageData.DrawImage24(col * (58 + 1), row * (64 + 1), 176, img);
                }
            });

            bmp.UnlockBits(imageData);

            BitmapCache.CreaturesAll = bmp;
            return(BitmapCache.CreaturesAll);
        }
Exemplo n.º 8
0
        public static Bitmap GetSkillTree(Heroes3Master master)
        {
            if (_skillTree2 != null)
            {
                return(_skillTree2);
            }

            if (_defFile == null)
            {
                _defFile = master.ResolveWith(IMG_FNAME).GetDefFile();
            }



            int rowCount = 3 * AllSkills.Count / ALL_COLNUMBER;

            var bmp       = new Bitmap((44 + 1) * ALL_COLNUMBER, (44 + 1) * rowCount, System.Drawing.Imaging.PixelFormat.Format24bppRgb);
            var imageData = bmp.LockBits24();

            Parallel.For(0, AllSkills.Count * 3, i =>
            {
                int row = i / ALL_COLNUMBER;
                int col = i % ALL_COLNUMBER;

                var img = _defFile.GetByAbsoluteNumber2(3 + row * ALL_COLNUMBER + col);
                imageData.DrawImage24(col * (44 + 1), row * (44 + 1), 132, img);
            });

            bmp.UnlockBits(imageData);
            _skillTree2 = bmp;

            return(_skillTree2);
        }
Exemplo n.º 9
0
 public static void Unload()
 {
     AllSkills   = null;
     _defFile    = null;
     _specImage  = null;
     _skillTree  = null;
     _skillTree2 = null;
 }
Exemplo n.º 10
0
        public static void Unload()
        {
            allRows   = null;
            AllSpells = null;

            defFile = null;
            BitmapCache.SpellsAll           = null;
            BitmapCache.SpellsForSpeciality = null;
        }
Exemplo n.º 11
0
        public Bitmap GetImage(Heroes3Master master)
        {
            if (defFile == null)
            {
                defFile = master.ResolveWith(IMG_FNAME).GetDefFile();
            }

            return(defFile.GetByAbsoluteNumber(Index));
        }
Exemplo n.º 12
0
        public Bitmap GetImage(Heroes3Master master, int level)
        {
            var lodFile = master.Resolve(IMG_FNAME);

            if (_defFile == null)
            {
                _defFile = lodFile.GetRecord(IMG_FNAME).GetDefFile();
            }
            return(_defFile.GetByAbsoluteNumber(Index * 3 + level + 2));
        }
Exemplo n.º 13
0
        public static Bitmap GetImage(Heroes3Master master, int index)
        {
            var lodFile = master.Resolve(IMG_FNAME);

            if (defFile == null)
            {
                defFile = lodFile.GetRecord(IMG_FNAME).GetDefFile();
            }

            return(defFile.GetByAbsoluteNumber(index));
        }
Exemplo n.º 14
0
        public static Bitmap GetImage(Heroes3Master master, int index)
        {
            var lodFile = master.Resolve(IMG_FNAME);

            if (creatureDef == null)
            {
                creatureDef = lodFile.GetRecord(IMG_FNAME).GetDefFile();
            }

            var bmp = creatureDef.GetByAbsoluteNumber(index + 2);

            return(bmp);
        }
Exemplo n.º 15
0
        public static void Unload()
        {
            BitmapCache.CreaturesAll        = null;
            BitmapCache.CreaturesUnupgraded = null;

            OnlyActiveCreatures          = null;
            AllCreatures2                = null;
            IndexesOfFirstLevelCreatures = null;

            smallCreatureDef = null;
            creatureDef      = null;

            rows = null;
        }
        public CreatureAnimationLoop(int creatureIndex, DefFile def)
        {
            timer          = new Timer();
            timer.Interval = TIMER_INTERVAL;
            timer.Tick    += timer_Tick;
            if (def.headers.Count <= SPRITES_INDEX)
            {
                throw new Exception("not a creature");
            }

            creatureAnimation = def;
            CreatureIndex     = creatureIndex;
            FrameCount        = def.headers[SPRITES_INDEX].SpritesCount;
            frames            = new Bitmap[FrameCount];
        }
Exemplo n.º 17
0
        public unsafe static Bitmap GetSmallImage(Heroes3Master master, int creatureIndex)
        {
            var h3sprite = master.Resolve(IMG_SMALL_FNAME);


            if (smallCreatureDef == null)
            {
                smallCreatureDef = h3sprite.GetRecord(IMG_SMALL_FNAME).GetDefFile();
            }


            Bitmap bmp;

            if (BitmapCache.CreaturesSmall[creatureIndex] == null)
            {
                bmp = smallCreatureDef.GetByAbsoluteNumber(creatureIndex + 2);
                var creature = AllCreatures2[creatureIndex];
                var clr      = Town.AllColors[creature.TownIndex];

                var imageData = bmp.LockBits(new Rectangle(0, 0, bmp.Width, bmp.Height), System.Drawing.Imaging.ImageLockMode.ReadWrite, System.Drawing.Imaging.PixelFormat.Format24bppRgb);
                for (int i = 0; i < imageData.Height; i++)
                {
                    byte *offset = (byte *)imageData.Scan0 + i * imageData.Stride;
                    for (int j = 0; j < imageData.Width; j++)
                    {
                        byte b = *offset;
                        byte g = *(offset + 1);
                        byte r = *(offset + 2);
                        if (r == 0 && g == 0xff && b == 0xff)
                        {
                            *(offset++) = clr.B;
                            *(offset++) = clr.G;
                            *(offset++) = clr.R;
                        }
                        else
                        {
                            offset += 3;
                        }
                    }
                }
                bmp.UnlockBits(imageData);
                BitmapCache.CreaturesSmall[creatureIndex] = bmp;
            }

            return(BitmapCache.CreaturesSmall[creatureIndex]);
        }
Exemplo n.º 18
0
        public static Bitmap GetAllSpells(Heroes3Master master)
        {
            if (BitmapCache.SpellsAll != null)
            {
                return(BitmapCache.SpellsAll);
            }

            if (defFile == null)
            {
                defFile = master.ResolveWith(IMG_FNAME).GetDefFile();
            }

            int total = defFile.headers[0].SpritesCount;

            var baseSprite = defFile.headers[0].spriteHeaders[0];
            int imgWidth   = baseSprite.SpriteWidth;
            int imgHeight  = baseSprite.SpriteHeight;
            int stride     = baseSprite.Stride24;

            int colCount = ALL_SPELLS_COLUMN_NUMBER;
            int rowCount = (total / colCount) + (total % colCount == 0 ? 0 : 1);

            var bmp       = new Bitmap((imgWidth + 1) * colCount, (imgHeight + 1) * rowCount);
            var imageData = bmp.LockBits24();

            Parallel.For(0, total, i =>
            {
                int row = i / colCount;
                int col = i % colCount;

                var img = defFile.GetByAbsoluteNumber2(i);
                if (img != null)
                {
                    imageData.DrawImage24(col * (imgWidth + 1), row * (imgHeight + 1), stride, img);
                }
            });

            bmp.UnlockBits(imageData);
            BitmapCache.SpellsAll = bmp;
            return(BitmapCache.SpellsAll);
        }
 private static void LoadDefsUncompressed(byte[] un32, byte[] un44)
 {
     def32 = new DefFile(null, un32);
     def44 = new DefFile(null, un44);
 }
Exemplo n.º 20
0
 public static void Unload()
 {
     defFile = null;
     BitmapCache.ResourcesAll = null;
 }