Esempio n. 1
0
        public override bool Equals(object obj)
        {
            FNT compareFnt = (FNT)obj;

            for (int i = 0; i < entryTable.Count; i++)
            {
                if (entryTable[i].subtitle != compareFnt.entryTable[i].subtitle)
                {
                    return(false);
                }
                if (entryTable[i].subtitleAddress != compareFnt.entryTable[i].subtitleAddress)
                {
                    return(false);
                }
                if (entryTable[i].messageIdBranchSequence != compareFnt.entryTable[i].messageIdBranchSequence)
                {
                    return(false);
                }
                if (entryTable[i].entryType != compareFnt.entryTable[i].entryType)
                {
                    return(false);
                }
                if (entryTable[i].subtitleActiveTime != compareFnt.entryTable[i].subtitleActiveTime)
                {
                    return(false);
                }
                if (entryTable[i].audioId != compareFnt.entryTable[i].audioId)
                {
                    return(false);
                }
            }
            return(true);
        }
Esempio n. 2
0
        /// <summary>
        /// Parses a .fnt file
        /// </summary>
        /// <param name="fileName">Full name (not SafeName) retrieved via a FilePicker</param>
        /// <param name="file">Bytes of file to parse</param>
        /// <param name="filterString">String to remove when ToString() is called</param>
        /// <returns>FNT</returns>
        public static FNT ParseFNTFile(String fileName, ref byte[] file, String filterString = "")
        {
            FNT fnt = new FNT();

            fnt.fileName     = fileName;
            fnt.filterString = filterString;

            int numberOfEntries = BitConverter.ToInt32(file, 0);
            int positionIndex   = 4; // position of byte to read

            fnt.entryTable = new List <TableEntry>();

            // Length of single table entry
            int subtitleTableEntryStructSize = 0x14;

            // read table entries
            for (int i = 0; i < numberOfEntries; i++)
            {
                TableEntry entry = new TableEntry {
                    subtitleAddress         = BitConverter.ToInt32(file, positionIndex),
                    messageIdBranchSequence = BitConverter.ToInt32(file, positionIndex + 4),
                    entryType          = (EntryType)BitConverter.ToInt32(file, positionIndex + 8),
                    subtitleActiveTime = BitConverter.ToInt32(file, positionIndex + 12),
                    audioId            = BitConverter.ToInt32(file, positionIndex + 16)
                };

                fnt.entryTable.Add(entry);
                positionIndex += subtitleTableEntryStructSize;
            }

            // read UTF-16 strings
            for (int i = 0; i < numberOfEntries; i++)
            {
                int    subtitleLength;
                String subtitle;
                if (i == numberOfEntries - 1)
                {
                    // if last subtitleTable entry, size is originalFilesize - entry index
                    // however the original .fnt files sometimes have junk strings at the end
                    // end at first "\0"
                    subtitleLength = file.Length - fnt.entryTable[i].subtitleAddress;
                    subtitle       = Encoding.Unicode.GetString(file, positionIndex, subtitleLength).Split("\0")[0];
                }
                else
                {
                    // otherwise calculate based on next entry in list
                    subtitleLength = fnt.entryTable[i + 1].subtitleAddress - fnt.entryTable[i].subtitleAddress;
                    subtitle       = Encoding.Unicode.GetString(file, positionIndex, subtitleLength);
                }
                fnt.UpdateEntrySubtitle(i, subtitle);
                positionIndex += subtitleLength;
            }

            return(fnt);
        }