public AudioMetadata(Stream stream, IGameInstance instance) { Instance = instance; Header = stream.ReadStruct <AudioMetadataHeader>(); if (Header.LipsyncSize > 0) { stream.Seek(0x24 + Header.LipsyncOffset, SeekOrigin.Begin); LipsyncData = new byte[Header.LipsyncSize]; stream.Read(LipsyncData, 0, LipsyncData.Length); } if (Header.SubtitleSize > 0) { stream.Seek(0x24 + Header.SubtitleOffset, SeekOrigin.Begin); SubtitleHeader = stream.ReadStruct <AudioMetadataSubtitleHeader>(); long subtitleOffset = stream.Position; for (int i = 0; i < SubtitleHeader.LocalizedVoiceSubtitleHeaders.Length; i++) { LocalizedVoiceSubtitleHeader localizedVoiceSubtitleHeader = SubtitleHeader.LocalizedVoiceSubtitleHeaders[i]; Language language = (Language)i; if (localizedVoiceSubtitleHeader.Length == 0) { Subtitles.Add(language, ""); continue; } long offset = subtitleOffset + localizedVoiceSubtitleHeader.Offset; stream.Seek(offset, SeekOrigin.Begin); byte[] subtitleData = new byte[localizedVoiceSubtitleHeader.Length]; stream.Read(subtitleData, 0, (int)localizedVoiceSubtitleHeader.Length); var map = LanguageUtility.GetDecodeCharMap(instance, language); StringBuilder subtitleBuilder = new StringBuilder(); for (int pos = 0; pos < subtitleData.Length; pos += 2) { char src = BitConverter.ToChar(subtitleData, pos); char value = src; if (map.ContainsKey(src)) { value = map[src]; } if (value == 0x00) { continue; } subtitleBuilder.Append(value); } string subtitle = subtitleBuilder.ToString(); Subtitles.Add(language, subtitle); } } }
public StringFile(Stream stream, Language language, IGameInstance instance) { GameInstance = instance; Language = language; Header = stream.ReadStruct <StringHeader>(); var map = LanguageUtility.GetDecodeCharMap(GameInstance, Language); StringBuilder sb = new StringBuilder(); for (int i = 0; i < Header.BucketCount; i++) { // Seek to the start of our new bucket stream.Seek(Marshal.SizeOf(typeof(StringHeader)) + (i * Marshal.SizeOf(typeof(StringBucket))), SeekOrigin.Begin); StringBucket bucket = stream.ReadStruct <StringBucket>(); Dictionary <UInt32, string> bucketData = new Dictionary <uint, string>(); for (int j = 0; j < bucket.StringCount; j++) { stream.Seek(bucket.StringOffset + (sizeof(UInt32) * j), SeekOrigin.Begin); UInt32 stringOffset = stream.ReadUInt32(); stream.Seek(stringOffset, SeekOrigin.Begin); UInt32 stringHash = stream.ReadUInt32(); if (FileIsSaintsRow2) { stringHash = stringHash.Swap(); } sb.Clear(); int length = 0; while (true) { UInt16 charValue = stream.ReadUInt16(); if (charValue == 0x0000) { break; } if (FileIsSaintsRow2) { charValue = charValue.Swap(); } char src = (char)charValue; char value = src; if (map.ContainsKey(src)) { value = map[src]; } sb.Append(value); length++; } string text = sb.ToString(); bucketData.Add(stringHash, text); } Buckets.Add(bucketData); } }