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);
                }
            }
        }
Exemple #2
0
        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);
                }
            }
        }
Exemple #3
0
 public AudioMetadata(IGameInstance instance)
 {
     Instance = instance;
     Header   = new AudioMetadataHeader();
 }
 public AudioMetadata(IGameInstance instance)
 {
     Instance = instance;
     Header = new AudioMetadataHeader();
 }