public static sNFTR Read(string file, int id, string lang) { sNFTR font = new sNFTR(); font.id = id; BinaryReader br = new BinaryReader(File.OpenRead(file)); // Read the standard header font.header.type = br.ReadChars(4); font.header.endianess = br.ReadUInt16(); font.header.unknown = br.ReadUInt16(); font.header.file_size = br.ReadUInt32(); font.header.block_size = br.ReadUInt16(); font.header.num_blocks = br.ReadUInt16(); // Font INFo section font.fnif.type = br.ReadChars(4); font.fnif.block_size = br.ReadUInt32(); font.fnif.unknown1 = br.ReadByte(); font.fnif.height = br.ReadByte(); font.fnif.unknown2 = br.ReadByte(); font.fnif.unknown3 = br.ReadByte(); font.fnif.unknown4 = br.ReadByte(); font.fnif.width = br.ReadByte(); font.fnif.width_bis = br.ReadByte(); font.fnif.encoding = br.ReadByte(); font.fnif.offset_plgc = br.ReadUInt32(); font.fnif.offset_hdwc = br.ReadUInt32(); font.fnif.offset_pamc = br.ReadUInt32(); if (font.fnif.block_size == 0x20) { font.fnif.height_font = br.ReadByte(); font.fnif.widht_font = br.ReadByte(); font.fnif.bearing_y = br.ReadByte(); font.fnif.unknown5 = br.ReadByte(); } // Character Graphics LP br.BaseStream.Position = font.fnif.offset_plgc - 0x08; font.plgc.type = br.ReadChars(4); font.plgc.block_size = br.ReadUInt32(); font.plgc.tile_width = br.ReadByte(); font.plgc.tile_height = br.ReadByte(); font.plgc.tile_length = br.ReadUInt16(); font.plgc.unknown = br.ReadUInt16(); font.plgc.depth = br.ReadByte(); font.plgc.rotateMode = br.ReadByte(); font.plgc.tiles = new Byte[(font.plgc.block_size - 0x10) / font.plgc.tile_length][]; for (int i = 0; i < font.plgc.tiles.Length; i++) { font.plgc.tiles[i] = BytesToBits(br.ReadBytes(font.plgc.tile_length)); if (font.plgc.rotateMode == 2) { font.plgc.tiles[i] = Rotate270(font.plgc.tiles[i], font.plgc.tile_width, font.plgc.tile_height, font.plgc.depth); } else if (font.plgc.rotateMode == 1) { font.plgc.tiles[i] = Rotate90(font.plgc.tiles[i], font.plgc.tile_width, font.plgc.tile_height, font.plgc.depth); } else if (font.plgc.rotateMode == 3) { font.plgc.tiles[i] = Rotate180(font.plgc.tiles[i], font.plgc.tile_width, font.plgc.tile_height, font.plgc.depth); } } // Character Width DH br.BaseStream.Position = font.fnif.offset_hdwc - 0x08; font.hdwc.type = br.ReadChars(4); font.hdwc.block_size = br.ReadUInt32(); font.hdwc.fist_code = br.ReadUInt16(); font.hdwc.last_code = br.ReadUInt16(); font.hdwc.unknown1 = br.ReadUInt32(); font.hdwc.info = new List <sNFTR.HDWC.Info>(); for (int i = 0; i < font.plgc.tiles.Length; i++) { sNFTR.HDWC.Info info = new sNFTR.HDWC.Info(); info.pixel_start = br.ReadByte(); info.pixel_width = br.ReadByte(); info.pixel_length = br.ReadByte(); font.hdwc.info.Add(info); } // Character MAP br.BaseStream.Position = font.fnif.offset_pamc - 0x08; font.pamc = new List <sNFTR.PAMC>(); uint nextOffset = 0x00; do { sNFTR.PAMC pamc = new sNFTR.PAMC(); pamc.type = br.ReadChars(4); pamc.block_size = br.ReadUInt32(); pamc.first_char = br.ReadUInt16(); pamc.last_char = br.ReadUInt16(); pamc.type_section = br.ReadUInt32(); nextOffset = br.ReadUInt32(); pamc.next_section = nextOffset; switch (pamc.type_section) { case 0: sNFTR.PAMC.Type0 type0 = new sNFTR.PAMC.Type0(); type0.fist_char_code = br.ReadUInt16(); pamc.info = type0; break; case 1: sNFTR.PAMC.Type1 type1 = new sNFTR.PAMC.Type1(); type1.char_code = new ushort[(pamc.block_size - 0x14 - 0x02) / 2]; for (int i = 0; i < type1.char_code.Length; i++) { type1.char_code[i] = br.ReadUInt16(); } pamc.info = type1; break; case 2: sNFTR.PAMC.Type2 type2 = new sNFTR.PAMC.Type2(); type2.num_chars = br.ReadUInt16(); type2.charInfo = new sNFTR.PAMC.Type2.CharInfo[type2.num_chars]; for (int i = 0; i < type2.num_chars; i++) { type2.charInfo[i].chars_code = br.ReadUInt16(); type2.charInfo[i].chars = br.ReadUInt16(); } pamc.info = type2; break; } font.pamc.Add(pamc); br.BaseStream.Position = nextOffset - 0x08; } while (nextOffset != 0x00 && (nextOffset - 0x08) < br.BaseStream.Length); //WriteInfo(font, lang); font.plgc.rotateMode = 0; br.Close(); return(font); }
public static void WriteInfo(sNFTR font, string lang) { try { XElement xml = XElement.Load(System.Windows.Forms.Application.StartupPath + Path.DirectorySeparatorChar + "Plugins" + Path.DirectorySeparatorChar + "FontLang.xml"); xml = xml.Element(lang).Element("NFTR"); Console.WriteLine(xml.Element("S00").Value); Console.WriteLine("<pre>"); Console.WriteLine(xml.Element("S01").Value, font.header.num_blocks.ToString()); Console.WriteLine("<b>" + xml.Element("S02").Value + "</b>", new String(font.fnif.type)); Console.WriteLine(xml.Element("S03").Value, font.fnif.block_size.ToString("x")); Console.WriteLine(xml.Element("S04").Value, font.fnif.unknown1.ToString("x")); Console.WriteLine(xml.Element("S1E").Value, font.fnif.height.ToString("x")); Console.WriteLine(xml.Element("S05").Value, font.fnif.unknown2.ToString("x")); Console.WriteLine(xml.Element("S1F").Value, font.fnif.unknown3.ToString("x")); Console.WriteLine(xml.Element("S20").Value, font.fnif.unknown4.ToString("x")); Console.WriteLine(xml.Element("S21").Value, font.fnif.width.ToString("x")); Console.WriteLine(xml.Element("S22").Value, font.fnif.width_bis.ToString("x")); Console.WriteLine(xml.Element("S23").Value, font.fnif.encoding.ToString("x")); Console.WriteLine(xml.Element("S06").Value, font.fnif.offset_plgc.ToString("x")); Console.WriteLine(xml.Element("S07").Value, font.fnif.offset_hdwc.ToString("x")); Console.WriteLine(xml.Element("S08").Value, font.fnif.offset_pamc.ToString("x")); if (font.fnif.block_size == 0x20) { Console.WriteLine(xml.Element("S24").Value, font.fnif.height_font.ToString("x")); Console.WriteLine(xml.Element("S25").Value, font.fnif.widht_font.ToString("x")); Console.WriteLine(xml.Element("S26").Value, font.fnif.bearing_y.ToString("x")); Console.WriteLine(xml.Element("S09").Value, font.fnif.unknown5.ToString("x")); } Console.WriteLine("<b>" + xml.Element("S02").Value + "</b>", new String(font.plgc.type)); Console.WriteLine(xml.Element("S03").Value, font.plgc.block_size.ToString("x")); Console.WriteLine(xml.Element("S0A").Value, font.plgc.tile_width.ToString()); Console.WriteLine(xml.Element("S0B").Value, font.plgc.tile_height.ToString()); Console.WriteLine(xml.Element("S0C").Value, font.plgc.tile_length.ToString()); Console.WriteLine(xml.Element("S0D").Value, font.plgc.unknown.ToString("x")); Console.WriteLine(xml.Element("S0E").Value, font.plgc.depth.ToString()); Console.WriteLine(xml.Element("S0F").Value, font.plgc.rotateMode.ToString()); //Console.WriteLine(xml.Element("S10").Value, font.plgc.unknown2.ToString()); Console.WriteLine("<b>" + xml.Element("S02").Value + "</b>", new String(font.hdwc.type)); Console.WriteLine(xml.Element("S03").Value, font.hdwc.block_size.ToString("x")); Console.WriteLine(xml.Element("S11").Value, font.hdwc.fist_code.ToString("x")); Console.WriteLine(xml.Element("S12").Value, font.hdwc.last_code.ToString("x")); Console.WriteLine(xml.Element("S13").Value, font.hdwc.unknown1.ToString("x")); Console.WriteLine("<b>" + xml.Element("S02").Value + "</b>", "PAMC"); for (int i = 0; i < font.pamc.Count; i++) { sNFTR.PAMC pamc = font.pamc[i]; Console.WriteLine("<u>" + xml.Element("S02").Value + "</u>", i.ToString()); Console.WriteLine(" |__" + xml.Element("S03").Value, pamc.block_size.ToString("x")); Console.WriteLine(" |_" + xml.Element("S14").Value, pamc.first_char.ToString("x")); Console.WriteLine(" |_" + xml.Element("S15").Value, pamc.last_char.ToString("x")); Console.WriteLine(" |_" + xml.Element("S16").Value, pamc.type_section.ToString()); switch (pamc.type_section) { case 0: sNFTR.PAMC.Type0 type0 = (sNFTR.PAMC.Type0)pamc.info; Console.WriteLine(" \\_" + xml.Element("S17").Value, 0); Console.WriteLine(" \\_" + xml.Element("S18").Value, type0.fist_char_code.ToString("x")); break; case 1: sNFTR.PAMC.Type1 type1 = (sNFTR.PAMC.Type1)pamc.info; Console.WriteLine(" \\_" + xml.Element("S17").Value, 1); Console.WriteLine(" \\_" + xml.Element("S19").Value, type1.char_code.Length.ToString()); for (int j = 0; j < type1.char_code.Length; j++) { Console.WriteLine(" |_" + xml.Element("S1A").Value, j.ToString(), type1.char_code[j].ToString("x"), Encoding.GetEncoding("shift-jis").GetChars( BitConverter.GetBytes(pamc.first_char + j).Reverse().ToArray()).Reverse().ToArray()[0]); } break; case 2: sNFTR.PAMC.Type2 type2 = (sNFTR.PAMC.Type2)pamc.info; Console.WriteLine(" \\_" + xml.Element("S17").Value, 2); Console.WriteLine(" \\_" + xml.Element("S1B").Value, type2.num_chars.ToString()); for (int j = 0; j < type2.num_chars; j++) { Console.WriteLine(" |_" + xml.Element("S1C").Value, j.ToString(), type2.charInfo[j].chars_code.ToString("x")); Console.WriteLine(" |_" + xml.Element("S1D").Value, j.ToString(), type2.charInfo[j].chars.ToString()); } break; } } Console.WriteLine("EOF</pre>"); } catch { throw new NotSupportedException("There was an error reading the language file"); } }
public static sNFTR Read(string file, int id, string lang) { sNFTR font = new sNFTR(); font.id = id; BinaryReader br = new BinaryReader(File.OpenRead(file)); // Read the standard header font.header.type = br.ReadChars(4); font.header.endianess = br.ReadUInt16(); font.header.unknown = br.ReadUInt16(); font.header.file_size = br.ReadUInt32(); font.header.block_size = br.ReadUInt16(); font.header.num_blocks = br.ReadUInt16(); // Font INFo section font.fnif.type = br.ReadChars(4); font.fnif.block_size = br.ReadUInt32(); font.fnif.unknown1 = br.ReadByte(); font.fnif.height = br.ReadByte(); font.fnif.unknown2 = br.ReadByte(); font.fnif.unknown3 = br.ReadByte(); font.fnif.unknown4 = br.ReadByte(); font.fnif.width = br.ReadByte(); font.fnif.width_bis = br.ReadByte(); font.fnif.encoding = br.ReadByte(); font.fnif.offset_plgc = br.ReadUInt32(); font.fnif.offset_hdwc = br.ReadUInt32(); font.fnif.offset_pamc = br.ReadUInt32(); if (font.fnif.block_size == 0x20) { font.fnif.height_font = br.ReadByte(); font.fnif.widht_font = br.ReadByte(); font.fnif.bearing_y = br.ReadByte(); font.fnif.unknown5 = br.ReadByte(); } // Character Graphics LP br.BaseStream.Position = font.fnif.offset_plgc - 0x08; font.plgc.type = br.ReadChars(4); font.plgc.block_size = br.ReadUInt32(); font.plgc.tile_width = br.ReadByte(); font.plgc.tile_height = br.ReadByte(); font.plgc.tile_length = br.ReadUInt16(); font.plgc.unknown = br.ReadUInt16(); font.plgc.depth = br.ReadByte(); font.plgc.rotateMode = br.ReadByte(); font.plgc.tiles = new Byte[(font.plgc.block_size - 0x10) / font.plgc.tile_length][]; for (int i = 0; i < font.plgc.tiles.Length; i++) { font.plgc.tiles[i] = BytesToBits(br.ReadBytes(font.plgc.tile_length)); if (font.plgc.rotateMode == 2) font.plgc.tiles[i] = Rotate270(font.plgc.tiles[i], font.plgc.tile_width, font.plgc.tile_height, font.plgc.depth); else if (font.plgc.rotateMode == 1) font.plgc.tiles[i] = Rotate90(font.plgc.tiles[i], font.plgc.tile_width, font.plgc.tile_height, font.plgc.depth); else if (font.plgc.rotateMode == 3) font.plgc.tiles[i] = Rotate180(font.plgc.tiles[i], font.plgc.tile_width, font.plgc.tile_height, font.plgc.depth); } // Character Width DH br.BaseStream.Position = font.fnif.offset_hdwc - 0x08; font.hdwc.type = br.ReadChars(4); font.hdwc.block_size = br.ReadUInt32(); font.hdwc.fist_code = br.ReadUInt16(); font.hdwc.last_code = br.ReadUInt16(); font.hdwc.unknown1 = br.ReadUInt32(); font.hdwc.info = new List<sNFTR.HDWC.Info>(); for (int i = 0; i < font.plgc.tiles.Length; i++) { sNFTR.HDWC.Info info = new sNFTR.HDWC.Info(); info.pixel_start = br.ReadByte(); info.pixel_width = br.ReadByte(); info.pixel_length = br.ReadByte(); font.hdwc.info.Add(info); } // Character MAP br.BaseStream.Position = font.fnif.offset_pamc - 0x08; font.pamc = new List<sNFTR.PAMC>(); uint nextOffset = 0x00; do { sNFTR.PAMC pamc = new sNFTR.PAMC(); pamc.type = br.ReadChars(4); pamc.block_size = br.ReadUInt32(); pamc.first_char = br.ReadUInt16(); pamc.last_char = br.ReadUInt16(); pamc.type_section = br.ReadUInt32(); nextOffset = br.ReadUInt32(); pamc.next_section = nextOffset; switch (pamc.type_section) { case 0: sNFTR.PAMC.Type0 type0 = new sNFTR.PAMC.Type0(); type0.fist_char_code = br.ReadUInt16(); pamc.info = type0; break; case 1: sNFTR.PAMC.Type1 type1 = new sNFTR.PAMC.Type1(); type1.char_code = new ushort[(pamc.block_size - 0x14 - 0x02) / 2]; for (int i = 0; i < type1.char_code.Length; i++) type1.char_code[i] = br.ReadUInt16(); pamc.info = type1; break; case 2: sNFTR.PAMC.Type2 type2 = new sNFTR.PAMC.Type2(); type2.num_chars = br.ReadUInt16(); type2.charInfo = new sNFTR.PAMC.Type2.CharInfo[type2.num_chars]; for (int i = 0; i < type2.num_chars; i++) { type2.charInfo[i].chars_code = br.ReadUInt16(); type2.charInfo[i].chars = br.ReadUInt16(); } pamc.info = type2; break; } font.pamc.Add(pamc); br.BaseStream.Position = nextOffset - 0x08; } while (nextOffset != 0x00 && (nextOffset - 0x08) < br.BaseStream.Length); //WriteInfo(font, lang); font.plgc.rotateMode = 0; br.Close(); return font; }