public static void LoadInfo(Heroes3Master master) { Unload(); string[] names = Encoding.Default.GetString(master.ResolveWith(TXT_FNAME).GetRawData()).Split(new[] { "\r\n" }, StringSplitOptions.RemoveEmptyEntries); AllTownsWithNeutral = new Town[10]; var rec = master.ResolveWith(IMG_FNAME).GetDefFile(); for (int i = 0; i < AllTownsWithNeutral.Length - 1; i++) { var bmp = rec.GetSprite(0, 2 + i * 2); AllTownsWithNeutral[i] = new Town { Index = i, Name = names[i], Image = new Bitmap(bmp, new Size(36, 24)), LargeImage = bmp }; } AllTownsWithNeutral[9] = new Town { Index = 9, Name = "Neutral", LargeImage = rec.GetSprite(38) }; AllTownsWithNeutral[9].Image = new Bitmap(AllTownsWithNeutral[9].LargeImage, new Size(36, 24)); TownNamesWithNeutral = AllTownsWithNeutral.Select(s => s.Name).ToArray(); }
public static Bitmap GetAllSpecs(Heroes3Master master) { if (BitmapCache.SpecialitiesAll != null) { return(BitmapCache.SpecialitiesAll); } var bmp = new Bitmap(16 * (44 + 1), (44 + 1) * 9); using (var g = Graphics.FromImage(bmp)) { for (int i = 0; i < 9; i++) { for (int j = 0; j < 16; j++) { g.DrawImage(GetImage(master, i * 16 + j), j * 45, 45 * i); } } } BitmapCache.SpecialitiesAll = bmp; return(BitmapCache.SpecialitiesAll); }
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 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); }
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); }
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 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); }
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); }
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 Bitmap GetFrame(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); if (backgrounds == null) { backgrounds = new Bitmap[master.CastlesCount + 1]; } if (backgrounds[castleIndex] == null) { backgrounds[castleIndex] = master.ResolveWith(backgroundNames[castleIndex]).GetBitmap(); } Point pt; Size size; ComputeSpriteParameters(creatureAnimation.headers[SPRITES_INDEX], out pt, out size); // var sw = Stopwatch.StartNew(); frames[CurrentFrame] = DrawTransparent(backgrounds[castleIndex], bmp, pt, size); //fullTime += sw.ElapsedMs(); using (var g = Graphics.FromImage(frames[CurrentFrame])) g.DrawRectangle(Pens.Black, 0, 0, 100 - 1, 130 - 1); } return(frames[CurrentFrame]); }
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 void LoadData(Heroes3Master master) { Master = master; OriginalData = new List <FatRecord>(); foreach (var name in FileEntriesToBackups) { string backupName = GetBackupFileName(name); FatRecord temp = master.ResolveWith(backupName, false); FatRecord original = master.ResolveWith(name); if (temp == null || temp.Parent != original.Parent) { List <string> list; if (!master.NameToFileMap.TryGetValue(backupName.ToLower(), out list)) { list = new List <string>(); master.NameToFileMap[backupName.ToLower()] = list; } list.Add(original.Parent.Name.ToLower()); temp = original.Clone(backupName); temp.Parent.AddNewRecord(temp); } OriginalData.Add(temp); } }
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 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) { if (defFile == null) { defFile = master.ResolveWith(IMG_FNAME).GetDefFile(); } return(defFile.GetByAbsoluteNumber(Index)); }
public static void LoadInfo(Heroes3Master master) { Unload(); int startOffset = (int)master.Executable.HeroesSection.FindHeroSpecDataOffset(master.Executable.Data); if (startOffset >= 0) { AllSpecialities = LoadInfo(master.Executable.Data, startOffset); } }
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 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 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 unsafe void Update(Heroes3Master master, byte *ptr, int index) { var spec = AllSpecialities[index]; long offset = master.Executable.HeroesSection.HeroSpecDataOffset + index * BLOCK_SIZE; int *iptr = (int *)(ptr + offset); *iptr++ = spec.TypeId; *iptr++ = spec.ObjectId; Marshal.Copy(spec.Data, 0, new IntPtr((void *)iptr), 32); }
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 static void SaveLocalChanges(Heroes3Master master) { var sb = new StringBuilder(); sb.AppendLine(rows[0]); sb.AppendLine(rows[1]); for (int i = 0; i < AllHeroClasses.Count; i++) { sb.AppendLine(AllHeroClasses[i].GetRow()); } master.ResolveWith(TXT_FNAME).ApplyChanges(Encoding.Default.GetBytes(sb.ToString())); }
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 LodFile(Heroes3Master master, FileStream fs) { Path = fs.Name; Name = System.IO.Path.GetFileName(Path).ToLower(); byte[] temp = new byte[4]; fs.Position = 8; fs.Read(temp, 0, 4); stream = fs; FileCount = BitConverter.ToInt32(temp, 0); FilesTable = new List <FatRecord>(FileCount); Master = master; }
public LodFile Resolve(Heroes3Master master, string fileName) { List <string> masterResoucesForFile; if (!master.NameToFileMap.TryGetValue(fileName.ToLower(), out masterResoucesForFile)) { return(null); } // if no, exception is thrown if (masterResoucesForFile.Count == 1) { return(master.GetByName(masterResoucesForFile[0])); } if (ExplicitRules.Count > 0) { var explicitRule = ExplicitRules.FirstOrDefault(s => string.Compare(fileName, s.FileName, true) == 0); if (explicitRule != null) { if (explicitRule.ResourseFilePriorities != null && explicitRule.ResourseFilePriorities.Length > 0) { foreach (var rName in explicitRule.ResourseFilePriorities) { if (masterResoucesForFile.Any(s => string.Compare(s, rName, true) == 0)) { return(master.GetByName(rName)); } } } } } foreach (var defaultResource in DefaultResourcePriorities) { if (masterResoucesForFile.Any(s => string.Compare(s, defaultResource, true) == 0)) { return(master.GetByName(defaultResource)); } } if (Fallback != null) { return(Fallback.Resolve(master, fileName)); } //throw new Exception("File: " + fileName + " was not found for routing " + Name); return(null); }
public static void LoadFromMaster(Heroes3Master master) { FatRecord un32, un44; un32 = master.ResolveWith(BackupManager.GetBackupFileName(Speciality.IMG_FNAME_SMALL)) ?? master.ResolveWith(Speciality.IMG_FNAME_SMALL); un44 = master.ResolveWith(BackupManager.GetBackupFileName(Speciality.IMG_FNAME)) ?? master.ResolveWith(Speciality.IMG_FNAME); h_specs = master.ResolveWith(BackupManager.GetBackupFileName(HeroesManager.H_SPECS)) ?? master.ResolveWith(HeroesManager.H_SPECS); spec_rows = Encoding.Default.GetString(h_specs.GetRawData()).Split(new[] { "\r\n" }, StringSplitOptions.RemoveEmptyEntries); LoadOriginalSpecs(Properties.Resources.allspecs, 0); LoadDefsUncompressed(un32.GetRawData(), un44.GetRawData()); }
public static void LoadInfo(Heroes3Master master) { AnyChanges = false; var rec = master.ResolveWith(TXT_FNAME); string text = Encoding.Default.GetString(rec.GetRawData()); rows = text.Split(new[] { "\r\n" }, StringSplitOptions.RemoveEmptyEntries); AllHeroClasses = new List <HeroClass>(rows.Length); for (int i = 0; i < rows.Length - 2; i++) { AllHeroClasses.Add(new HeroClass(i, rows[i + 2])); } }
public static void SaveLocalChanges(Heroes3Master master) { var rec = master.ResolveWith(TXT_FNAME); if (rec != null) { var sb = new StringBuilder(); int i; int index = 0; for (i = 0; i < 5; i++) { sb.AppendLine(allRows[i]); } for (; 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")) { sb.AppendLine(row); continue; } var spellCells = AllSpells[index].cells; for (int j = 0; j < spellCells.Length - 1; j++) { sb.Append(spellCells[j]); sb.Append('\t'); } sb.AppendLine(spellCells[spellCells.Length - 1]); index++; } for (; i < allRows.Length; i++) { sb.AppendLine(allRows[i]); } rec.ApplyChanges(Encoding.Default.GetBytes(sb.ToString())); } }
public static Bitmap GetPrimarySkillsPanel(Heroes3Master master) { var bmp = new Bitmap(4 * 42, 42); using (var g = Graphics.FromImage(bmp)) { var ps = master.ResolveWith(H_PRIMARYSKILLS).GetDefFile(); if (ps != null) { g.DrawImage(ps.GetSprite(0), new Point(0, 0)); g.DrawImage(ps.GetSprite(1), new Point(42, 0)); g.DrawImage(ps.GetSprite(2), new Point(84, 0)); g.DrawImage(ps.GetSprite(5), new Point(126, 0)); } } return(bmp); }