private TlkFile ParseFile(BinaryReader br)
        {
            var header = (TlkHeaderBinary)Common.ReadStruct(br, typeof(TlkHeaderBinary));

            List<TlkEntryBinary> stringDataEntries = new List<TlkEntryBinary>();
            List<string> stringEntries = new List<string>();

            br.BaseStream.Seek(18, SeekOrigin.Begin);
            for (int i = 0; i < header.StringCount; i++)
            {
                var stringDataEntry = (TlkEntryBinary)Common.ReadStruct(br, typeof(TlkEntryBinary));
                stringDataEntries.Add(stringDataEntry);
            }

            br.BaseStream.Seek(header.StringOffset, SeekOrigin.Begin);
            for (int i = 0; i < header.StringCount; i++)
            {
                var stringEntry = br.ReadChars(stringDataEntries[i].StringLength);
                stringEntries.Add(new string(stringEntry));
            }

            TlkFile tlk = new TlkFile();
            tlk.LangugeId = header.LanguageId;

            int stringIndex = 0;
            foreach (var data in stringDataEntries)
            {
                var stringInfo = new StringEntry();
                stringInfo.Strref = stringIndex;
                stringInfo.Flags = (StringEntryType)data.Flags;
                stringInfo.PitchVariance = data.PitchVariance;
                stringInfo.Sound = data.Sound.ToString();
                stringInfo.Text = stringEntries[stringIndex];
                stringInfo.VolumeVariance = data.VolumeVariance;
                tlk.Strings.Add(stringInfo);
                stringIndex++;
            }

            tlk.Checksum = MD5HashGenerator.GenerateKey(tlk);
            return tlk;
        }
Exemple #2
0
 public static int WriteString(IEString stringInfo, TlkFile tlkFile)
 {
     var strref = stringInfo.Strref;
     if (tlkFile != null)
     {
         if ((stringInfo.Strref != Common.NewString) && (stringInfo.Strref <= tlkFile.Strings.Count))
         {
             tlkFile.Strings[stringInfo.Strref].Flags = stringInfo.Flags;
             tlkFile.Strings[stringInfo.Strref].PitchVariance = stringInfo.PitchVariance;
             tlkFile.Strings[stringInfo.Strref].Sound = stringInfo.Sound;
             tlkFile.Strings[stringInfo.Strref].Text = stringInfo.Text;
             tlkFile.Strings[stringInfo.Strref].VolumeVariance = stringInfo.VolumeVariance;
         }
         else
         {
             // Re-use an existing strref if possible (based only on the text)
             var existingEntry = tlkFile.Strings.Where(a => a.Text == stringInfo.Text).SingleOrDefault();
             if (existingEntry != null)
             {
                 strref = existingEntry.Strref;
             }
             else
             {
                 strref = tlkFile.Strings.Count + 1;
                 var stringEntry = new StringEntry();
                 stringEntry.Flags = stringInfo.Flags;
                 stringEntry.PitchVariance = stringInfo.PitchVariance;
                 stringEntry.Sound = stringInfo.Sound;
                 stringEntry.Strref = strref;
                 stringEntry.Text = stringInfo.Text;
                 stringEntry.VolumeVariance = stringInfo.VolumeVariance;
                 tlkFile.Strings.Add(stringEntry);
             }
         }
     }
     return strref;
 }
Exemple #3
0
        public static IEString ReadString(Int32 strref, TlkFile tlkFile)
        {
            var stringInfo = new IEString();
            stringInfo.Strref = strref;

            if (tlkFile != null)
            {
                if ((strref <= tlkFile.Strings.Count) && (strref > -1))
                {
                    stringInfo.Flags = tlkFile.Strings[strref].Flags;
                    stringInfo.PitchVariance = tlkFile.Strings[strref].PitchVariance;
                    stringInfo.Sound = tlkFile.Strings[strref].Sound;
                    stringInfo.Text = tlkFile.Strings[strref].Text;
                    stringInfo.VolumeVariance = tlkFile.Strings[strref].VolumeVariance;
                }
            }
            return stringInfo;
        }