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)); }
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; }
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); }
public static Bitmap GetAllBasicCreatures(Heroes3Master master) { if (BitmapCache.CreaturesUnupgraded != null) { return(BitmapCache.CreaturesUnupgraded); } var h3sprite = master.Resolve(IMG_FNAME); int totalrows = IndexesOfFirstLevelCreatures.Length / 14 + (IndexesOfFirstLevelCreatures.Length % 14 == 0 ? 0 : 1); var bmp = new Bitmap((58 + 1) * 14, (64 + 1) * totalrows); var imageData = bmp.LockBits24(); Parallel.For((int)0, IndexesOfFirstLevelCreatures.Length, i => { int row = i / 14; int col = i % 14; var img = creatureDef.GetByAbsoluteNumber2(IndexesOfFirstLevelCreatures[i] + 2); if (img != null) { imageData.DrawImage24(col * (58 + 1), row * (64 + 1), 176, img); } }); bmp.UnlockBits(imageData); BitmapCache.CreaturesUnupgraded = bmp; return(BitmapCache.CreaturesUnupgraded); }
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); }
public static void LoadInfo(Heroes3Master master) { Unload(); var lodFile = master.Resolve(FNAME_JKTEXT); var rec = lodFile.GetRecord(FNAME_JKTEXT); JKTEXT = Encoding.Default.GetString(rec.GetRawData(lodFile.stream)).Split(new string[] { "\r\n" }, StringSplitOptions.None); }
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)); }
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)); }
public Bitmap GetFrame2(Heroes3Master master) { if (frames == null || CurrentFrame >= frames.Length) { return(null); } if (frames[CurrentFrame] == null) { var bmp = creatureAnimation.GetSprite(SPRITES_INDEX, CurrentFrame); int castleIndex = GetBackgroundIndex(CreatureIndex); int imageWidth = 0; if (backgroundBytes == null) { backgroundBytes = new byte[master.CastlesCount + 1][]; } if (widths == null) { widths = new int[master.CastlesCount + 1]; } if (backgroundBytes[castleIndex] == null) { var lodFile = master.Resolve(backgroundNames[castleIndex]); backgroundBytes[castleIndex] = lodFile.GetRecord(backgroundNames[castleIndex]).GetBitmap24Data(lodFile.stream, out imageWidth); widths[castleIndex] = imageWidth; } Point pt; Size size; ComputeSpriteParameters(creatureAnimation.headers[SPRITES_INDEX], out pt, out size); int width = widths[castleIndex]; int padding = (4 - ((width * 3) % 4)) % 4; int stride = 3 * width + padding; int height = backgroundBytes[castleIndex].Length / stride; //var sw = Stopwatch.StartNew(); /*bckgBytes[castleIndex] = new byte[bckgBytes[castleIndex].Length]; * for (int i = 0; i < bckgBytes[castleIndex].Length; i++) * bckgBytes[castleIndex][i] = (byte)0xff; */ frames[CurrentFrame] = DrawTransparent2(backgroundBytes[castleIndex], widths[castleIndex], height, bmp, pt, size); // fullTime += sw.ElapsedMs(); using (var g = Graphics.FromImage(frames[CurrentFrame])) g.DrawRectangle(Pens.Black, 0, 0, width - 1, height - 1); } return(frames[CurrentFrame]); }
public static void SaveLocalChanges(Heroes3Master master) { var lodFile = master.Resolve(FAT_NAME); var rec = lodFile.GetRecord(FAT_NAME); if (rec != null) { string val = GetAllStats(); rec.ApplyChanges(Encoding.Default.GetBytes(val)); } }
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); }
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]); }
public static void LoadInfo(Heroes3Master master) { Unload(); AnyChanges = false; var lod1 = master.Resolve(TXT_BIOGRAPHIES_FNAME); var lod2 = master.Resolve(H_SPECS); var lod3 = master.Resolve(H_HEROES); // TO DO: fix this var imageLodFile = master.GetByName("h3bitmap.lod");// master.Resolve("HPL000EL.pcx"); //int index = lodFile.IndexOf("HPL000EL.pcx"); int index = imageLodFile.IndexOf("HPL000EL.pcx"); int bound = imageLodFile.FilesTable.FindLastIndex(index + types.Length * 22, fat => fat.FileName.Contains("HPL")); var heroes = new Dictionary <string, List <string> >(types.Length); for (int i = index; i < bound; i++) { List <string> list = null; string end = imageLodFile[i].FileName.Substring(6, 2); if (!heroes.TryGetValue(end, out list)) { heroes.Add(end, new List <string> { imageLodFile[i].FileName }); } else { list.Add(imageLodFile[i].FileName); } } List <string> stringList = new List <string>(types.Length * 16); for (int i = 0; i < types.Length; i++) { stringList.AddRange(heroes[types[i]]); } HeroesOrder = stringList.ToArray(); bio_rows = Encoding.Default.GetString(lod1.GetRawData(TXT_BIOGRAPHIES_FNAME)).Split(new[] { "\r\n" }, StringSplitOptions.RemoveEmptyEntries); spec_rows = Encoding.Default.GetString(lod2.GetRawData(H_SPECS)).Split(new[] { "\r\n" }, StringSplitOptions.RemoveEmptyEntries); hero_rows = Encoding.Default.GetString(lod3.GetRawData(H_HEROES)).Split(new[] { "\r\n" }, StringSplitOptions.RemoveEmptyEntries); AllHeroes = new List <HeroStats>(HeroesOrder.Length); for (int i = 0; i < HeroesOrder.Length; i++) { string[] traits = hero_rows[2 + i].Split('\t'); AllHeroes.Add(new HeroStats() { Biography = bio_rows[i], Speciality = spec_rows[2 + i], CastleIndex = types[i / 16], Name = traits[0], ImageIndex = i, LowStack1 = int.Parse(traits[1]), HighStack1 = int.Parse(traits[2]), LowStack2 = int.Parse(traits[4]), HighStack2 = int.Parse(traits[5]), LowStack3 = int.Parse(traits[7]), HighStack3 = int.Parse(traits[8]) }); } }
public static void SaveLocalChanges(Heroes3Master master) { var lod1 = master.Resolve(TXT_BIOGRAPHIES_FNAME); var lod2 = master.Resolve(H_SPECS); var lod3 = master.Resolve(H_HEROES); StringBuilder bios, spec, traits; bios = new StringBuilder(); spec = new StringBuilder(); traits = new StringBuilder(); spec.AppendLine(spec_rows[0] + "\r\n" + spec_rows[1]); traits.AppendLine(hero_rows[0] + "\r\n" + hero_rows[1]); for (int i = 0; i < HeroesOrder.Length; i++) { bios.AppendLine(AllHeroes[i].Biography); spec.AppendLine(AllHeroes[i].Speciality); traits.Append(AllHeroes[i].Name); traits.Append('\t'); traits.Append(AllHeroes[i].LowStack1); traits.Append('\t'); traits.Append(AllHeroes[i].HighStack1); traits.Append('\t'); traits.Append("cr1"); traits.Append('\t'); traits.Append(AllHeroes[i].LowStack2); traits.Append('\t'); traits.Append(AllHeroes[i].HighStack2); traits.Append('\t'); traits.Append("cr2"); traits.Append('\t'); traits.Append(AllHeroes[i].LowStack3); traits.Append('\t'); traits.Append(AllHeroes[i].HighStack3); traits.Append('\t'); traits.AppendLine("cr3"); if (AllHeroes[i].Large != null) { var rec = master.ResolveWith(HeroesOrder[AllHeroes[i].ImageIndex]); rec.ApplyChanges(PcxFile.FromBitmap(AllHeroes[i].Large).GetBytes); } if (AllHeroes[i].Small != null) { var rec = master.ResolveWith(HeroesOrder[AllHeroes[i].ImageIndex].Replace("HPL", "HPS")); rec.ApplyChanges(PcxFile.FromBitmap(AllHeroes[i].Small).GetBytes); } } for (int i = HeroesOrder.Length; i < bio_rows.Length; i++) { bios.AppendLine(bio_rows[i]); if (i + 2 < spec_rows.Length) { spec.AppendLine(spec_rows[2 + i]); } if (i + 2 < hero_rows.Length) { traits.AppendLine(hero_rows[2 + i]); } } lod1[TXT_BIOGRAPHIES_FNAME].ApplyChanges(Encoding.Default.GetBytes(bios.ToString())); lod2[H_SPECS].ApplyChanges(Encoding.Default.GetBytes(spec.ToString())); lod3[H_HEROES].ApplyChanges(Encoding.Default.GetBytes(traits.ToString())); }
public static void LoadInfo(Heroes3Master master) { AnyChanges = false; Loaded = false; Unload(); var lodFile = master.Resolve(FAT_NAME); var rec = lodFile.GetRecord(FAT_NAME); if (rec != null) { string text = Encoding.Default.GetString(rec.GetRawData()); rows = text.Split(new string[] { "\r\n" }, StringSplitOptions.None); AllCreatures2 = new Creature[rows.Length]; OnlyActiveCreatures = new List <Creature>(); int curIndex = 0; for (int i = 0; i < 8; i++) { for (int j = 0; j < 14; j++) { var stat = new Creature(rows[2 + i * 17 + j]) { TownIndex = i, CreatureIndex = curIndex++, CreatureCastleRelativeIndex = j }; AllCreatures2[stat.CreatureIndex] = stat; OnlyActiveCreatures.Add(stat); } } int off = 2 + 17 * 8; int ccri = 0; int ccri8 = 0; List <Creature> misc = new List <Creature>(); for (int i = off; i < rows.Length - 1; i++) { if (rows[i].Contains("\t\t\t")) { misc.Add(null); } else { if (!rows[i].Contains("NOT USED")) { int townIndex = 9; if (curIndex >= 112 && curIndex <= 131 && curIndex != 116 && curIndex != 117) { townIndex = 8; } var stat = new Creature(rows[i]) { TownIndex = townIndex, CreatureIndex = curIndex, CreatureCastleRelativeIndex = townIndex == 9 ? ccri : ccri8 }; AllCreatures2[stat.CreatureIndex] = stat; misc.Add(stat); if (townIndex == 9) { ccri++; } else { ccri8++; } } curIndex++; } } OnlyActiveCreatures.AddRange(misc.Where(s => s != null).ToArray()); var indexes = new List <int>(100); for (int i = 0; i < OnlyActiveCreatures.Count; i++) { if (i < 112 && i % 2 == 1) { continue; } if (i == 119 || (i >= 121 && i <= 125) || i == 127) { continue; } indexes.Add(OnlyActiveCreatures[i].CreatureIndex); } IndexesOfFirstLevelCreatures = indexes.ToArray(); BitmapCache.CreaturesSmall = new Bitmap[AllCreatures2.Length]; Loaded = true; } }