Ejemplo n.º 1
0
        private void lstAudio_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            if (lstAudio.SelectedIndex != -1)
            {
                currentEntry = tmx.audioEntries[lstAudio.SelectedIndex];

                lblIndex.Content   = currentEntry.index;
                lblType.Content    = currentEntry.type;
                lblOffsetR.Content = currentEntry.relativeOffset;
                lblOffsetA.Content = currentEntry.absoluteOffset;

                switch (currentEntry.type)
                {
                case "GIN":
                    streamType          = "EA-XAS 4-bit ADPCM v0";
                    txtMinRpm.IsEnabled = true;
                    txtMaxRpm.IsEnabled = true;
                    txtMinRpm.Text      = currentEntry.ginData.minRpm.ToString();
                    txtMaxRpm.Text      = currentEntry.ginData.maxRpm.ToString();
                    break;

                case "SNR":
                    streamType          = "EA-XAS 4-bit ADPCM v1";
                    txtMinRpm.IsEnabled = false;
                    txtMaxRpm.IsEnabled = false;
                    txtMinRpm.Text      = "";
                    txtMaxRpm.Text      = "";
                    break;
                }

                lblStream.Content = string.Format("{0} byte {1} stream", currentEntry.audioData == null ? currentEntry.ginData.audioData.Length : currentEntry.audioData.Length, streamType);
            }
        }
Ejemplo n.º 2
0
        public TMX ReadTMX(string path)
        {
            var bytes = File.ReadAllBytes(path);

            fileName = path;

            using (var stream = new BinaryStream(new MemoryStream(bytes)))
            {
                audioEntries = new List <AudioEntry>();

                if (stream.ReadUInt32() != 2292214557)
                {
                    MessageBox.Show("Not a valid TMX file. Please open a valid TMX file and try again.", "Error", MessageBoxButton.OK, MessageBoxImage.Error);

                    return(null);
                }
                else
                {
                    bool       searching = true;
                    int        offset = -1;
                    List <int> ginOffsets = new List <int>(), snrOffsets = new List <int>();
                    byte[]     ginHeader = new byte[] { 0x20, 0x4E, 0x49, 0x47 };
                    byte[]     snrHeader = new byte[] { 0x20, 0x52, 0x4E, 0x53 };

                    // Search for GIN headers
                    while (searching)
                    {
                        offset = FindSequenceMultiple(bytes, ginHeader, ginOffsets);
                        if (offset != -1)
                        {
                            ginOffsets.Add(offset);
                        }
                        else
                        {
                            searching = false;
                        }
                    }

                    searching = true;

                    // Search for SNR headers
                    while (searching)
                    {
                        offset = FindSequenceMultiple(bytes, snrHeader, snrOffsets);
                        if (offset != -1)
                        {
                            snrOffsets.Add(offset);
                        }
                        else
                        {
                            searching = false;
                        }
                    }

                    numSounds = ginOffsets.Count + snrOffsets.Count;

                    stream.Position = 0;

                    tmxHeader1      = stream.ReadBytes(88);
                    ginHeaderOffset = stream.ReadInt32();
                    audioDataOffset = stream.ReadInt32();
                    tmxHeader2      = stream.ReadBytes(ginHeaderOffset - 96);

                    for (int i = 0; i < numSounds; i++)
                    {
                        AudioEntry entry = new AudioEntry();

                        entry.entrySize = (byte)stream.ReadByte();

                        entry.type = new string(stream.ReadString(3).Reverse().ToArray());

                        entry.index          = stream.ReadInt32();
                        entry.relativeOffset = stream.ReadInt32();
                        entry.absoluteOffset = entry.relativeOffset + audioDataOffset;
                        entry.unk1           = stream.ReadInt32();
                        entry.unk2           = stream.ReadInt32();
                        entry.version        = stream.ReadInt32();
                        entry.unk3           = stream.ReadInt32();
                        entry.unk4           = BitConverter.ToSingle(stream.ReadBytes(4), 0);
                        entry.unk5           = stream.ReadInt32();

                        audioEntries.Add(entry);
                    }

                    for (int i = 0; i < audioEntries.Count; i++)
                    {
                        int readTo = 0;

                        stream.Position = audioEntries[i].absoluteOffset;

                        // If last sound file, read to end, otherwise to next header
                        if (i == audioEntries.Count - 1)
                        {
                            readTo = bytes.Length;
                        }
                        else
                        {
                            readTo = audioEntries[i + 1].absoluteOffset;
                        }

                        if (audioEntries[i].type == "GIN")
                        {
                            audioEntries[i].ginData = GIN.ReadGIN(stream.ReadBytes((int)(readTo - stream.Position)));
                        }
                        else
                        {
                            audioEntries[i].audioData = stream.ReadBytes((int)(readTo - stream.Position));
                        }
                    }
                }
            }

            return(this);
        }