public SkillFile(CTF.File ctf, string filename) { FileName = filename; var br = new ByteReader(File.ReadAllBytes(FileName)); if (br.STRING() != FileID) { throw new Exception("Invalid file format."); } var messages = new List<CTF.Message>(); foreach (var msg in ctf.Messages) { if (msg.SubCategory.Category.Name != "Skills") { continue; } messages.Add(msg); } var skill_count = br.UINT(); Skills = new List<Skill>(); for (int i = 0; i < skill_count; i++) { var s = new Skill(); s.Type = (SkillType)br.BYTE(); var message_id = br.STRING(); if (message_id == "") { Skills.Add(null); br.Skip(39); continue; } var class_id = br.STRING(); foreach (var message in messages) { if (message.SubCategory.ID == uint.Parse(class_id) && message.ID == uint.Parse(message_id)) { s.Message = message; break; } } if (s.Message == null) { throw new Exception("Failed to find message."); } s.IconIndex = br.UINT(); s.ProjectileAnimation = br.USHORT(); s.CharacterAnimation = br.UINT(); s.Honor = br.INT(); s.Level = br.UINT(); s.CharacterType = br.BYTE(); var mana = br.UINT(); if (mana > 1000000000) { s.ManaUsageStyle = ManaUsageStyle.Percentage; s.ManaUsage = mana - 1000000000; } else { s.ManaUsageStyle = ManaUsageStyle.Fixed; s.ManaUsage = mana; } var range = br.SHORT(); if (range > 10000) { s.IsAOE = true; s.Range = (short)(range - 10000); } else { s.IsAOE = false; s.Range = range; } s.NeedsTarget = br.BYTE(); s.Unused1 = br.BYTE(); s.Unused2 = br.BYTE(); s.Unused3 = br.BYTE(); s.EffectType = br.BYTE(); s.Multiplier = br.UINT(); s.Unknown5 = br.UINT(); Skills.Add(s); } }
protected Sprite LoadSprite(ByteReader br, int spriteIndex) { Debug.WriteLine("LoadSprite() {0}:{1} at offset {2}", Filename, spriteIndex, br.Offset); var ret = new Sprite(); // Read length of resource br.UINT(); ret.OffsetX = br.UINT(); ret.OffsetY = br.UINT(); int width = br.INT(); int height = br.INT(); // 16 unknown bytes br.UINT(); br.UINT(); br.UINT(); br.UINT(); // No idea what this is, seems to be some kind of blank if (ret.OffsetX == 99999) { // Extra byte here, not sure what it is br.BYTE(); throw new WeirdSizeException(); } var bmp = new Bitmap(width, height); ret.Image = bmp; int x = 0; int y = 0; while (true) { switch ((EntryType)br.BYTE()) { case EntryType.Paint: int pixels = br.INT(); for (int p = 0; p < pixels; p++) { var data = br.USHORT(); var b = (byte)((data & 0x1F) / 31.0f * 255); var g = (byte)((data >> 5 & 0x3F) / 63.0f * 255); var r = (byte)((data >> 11 & 0x1F) / 31.0f * 255); bmp.SetPixel(x, y, Color.FromArgb(255, r, g, b)); x++; } break; case EntryType.MoveX: x += br.INT() / 2; break; case EntryType.NextLine: y++; break; case EntryType.End: return(ret); default: throw new InvalidFileException(string.Format( "Unrecognized entry at offset {0}.", br.Offset)); } } }