Exemplo n.º 1
0
            public EmtSoundEntry Clone()
            {
                EmtSoundEntry _new = new EmtSoundEntry();

                _new.EntryType         = this.EntryType;
                _new.SoundFile         = this.SoundFile;
                _new.Reserved1         = this.Reserved1;
                _new.WhenActive        = this.WhenActive;
                _new.Volume            = this.Volume;
                _new.FadeInMS          = this.FadeInMS;
                _new.FadeOutMS         = this.FadeOutMS;
                _new.WavLoopType       = this.WavLoopType;
                _new.X                 = this.X;
                _new.Y                 = this.Y;
                _new.Z                 = this.Z;
                _new.WavFullVolRadius  = this.WavFullVolRadius;
                _new.WavMaxAudibleDist = this.WavMaxAudibleDist;
                _new.RandomizeLocation = this.RandomizeLocation;
                _new.ActivationRange   = this.ActivationRange;
                _new.MinRepeatDelay    = this.MinRepeatDelay;
                _new.MaxRepeatDelay    = this.MaxRepeatDelay;
                _new.xmiIndex          = this.xmiIndex;
                _new.EchoLevel         = this.EchoLevel;
                _new.IsEnvSound        = this.IsEnvSound;

                return(_new);
            }
Exemplo n.º 2
0
        public static DialogResult ConvertZone(string EQFolder, string ZoneNick)
        {
            if ((EQFolder == null) || (ZoneNick == null) || (EQFolder == "") || (ZoneNick == ""))
            {
                return(DialogResult.Abort);
            }

            string _zoneSoundEntriesFilename = EQFolder + "\\" + ZoneNick + "_sounds.eff";
            string _zoneSoundBankFilename    = EQFolder + "\\" + ZoneNick + "_sndbnk.eff";
            string _zoneSoundEmitterFilename = EQFolder + "\\" + ZoneNick + ".emt";

            string _line;

            // Preliminary: Read the mp3index.txt file's entries, in case they've been changed from the defaults.

            if (mp3indexFiles == null)
            {
                if (File.Exists(EQFolder + "\\mp3index.txt"))
                {
                    mp3indexFiles = new Dictionary <int, string>();

                    int _mp3LineNumber = 1;

                    using (StreamReader _in = new StreamReader(EQFolder + "\\mp3index.txt"))
                    {
                        while ((_line = _in.ReadLine()) != null)
                        {
                            mp3indexFiles[_mp3LineNumber++] = _line;
                        }
                    }
                }
                else
                {
                    // No mp3index.txt file found?? Use the defaults.

                    mp3indexFiles = DefaultMusicFiles;

                    MessageBox.Show("Note: Could not find the mp3index file at the following location:\n\n" + EQFolder + "\\mp3index.txt\n\nUsing default values from Live.", "No mp3index.txt - Using Defaults", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
            }


            List <string> _emtEntries = new List <string>();

            // Step 1 - Open ZoneNick_sounds.eff (Required)

            BinaryReader _effFile = null;

            while (_effFile == null)
            {
                try
                {
                    _effFile = new BinaryReader(File.OpenRead(_zoneSoundEntriesFilename));
                }
                catch (Exception ex)
                {
                    switch (MessageBox.Show("Could not create Sound Entries File:\n\n" + _zoneSoundEntriesFilename + "\n\nError Message:\n\n" + ex.Message, "Sound Entry Read Error", MessageBoxButtons.AbortRetryIgnore, MessageBoxIcon.Error))
                    {
                    case System.Windows.Forms.DialogResult.Ignore:
                        return(DialogResult.Ignore);

                    case System.Windows.Forms.DialogResult.Abort:
                        return(DialogResult.Abort);
                    }
                }
            }

            // Step 2 - Open ZoneNick.emt if it exists, and read in the current contents for merging our new entries into

            if (File.Exists(_zoneSoundEmitterFilename))
            {
                // Read in existing lines for the merge.
                using (StreamReader _emtFileIn = new StreamReader(_zoneSoundEmitterFilename))
                {
                    while ((_line = _emtFileIn.ReadLine()) != null)
                    {
                        _emtEntries.Add(_line);
                    }
                }
            }

            // Step 3 - Create or replace ZoneNick.emt

            StreamWriter _emtFile = null;

            while (_emtFile == null)
            {
                try
                {
                    _emtFile = new StreamWriter(_zoneSoundEmitterFilename);
                }
                catch (Exception ex)
                {
                    switch (MessageBox.Show("Could not create Sound Emitter File:\n\n" + _zoneSoundEmitterFilename + "\n\nError Message:\n\n" + ex.Message, "Sound Emitter Creation Error", MessageBoxButtons.AbortRetryIgnore, MessageBoxIcon.Error))
                    {
                    case System.Windows.Forms.DialogResult.Ignore:
                        return(DialogResult.Ignore);

                    case System.Windows.Forms.DialogResult.Abort:
                        return(DialogResult.Abort);
                    }
                }
            }

            // Step 4 - Read sound file references from ZoneNick_sndbnk.eff (Required unless only background music entries are in ZoneNick_sounds.eff)

            StreamReader _bnkFile = null;

            SoundBank_Emit = new List <string>();
            SoundBank_Loop = new List <string>();

            bool _inEmitSection = true;

            try
            {
                _bnkFile = new StreamReader(_zoneSoundBankFilename);
            }
            catch
            {
                _bnkFile = null;
            }

            if (_bnkFile != null)
            {
                while ((_line = _bnkFile.ReadLine()) != null)
                {
                    _line = _line.Trim();

                    if (_line == "EMIT")
                    {
                        _inEmitSection = true;
                    }
                    else if ((_line == "LOOP") || (_line == "RAND"))
                    {
                        _inEmitSection = false;
                    }
                    else if (_line != "")
                    {
                        if (_inEmitSection)
                        {
                            SoundBank_Emit.Add(_line);
                        }
                        else
                        {
                            SoundBank_Loop.Add(_line);
                        }
                    }
                }

                _bnkFile.Close();
            }

            // Step 5 - Initialize ZoneNick.emt

            if ((_emtEntries.Count < 1) || (_emtEntries[0].Length < 1) || (_emtEntries[0][0] != ';'))
            {
                _emtFile.WriteLine(EMTLineFormat); // Add our format line for human-readable reference, if it isn't already there.
            }

            foreach (string _emtEntry in _emtEntries)
            {
                _emtFile.WriteLine(_emtEntry); // Write the existing entries to the file. We'll append any new ones to the end.
            }

            // Step 6 - Read binary entries from ZoneNick_sounds.eff and write text entries to ZoneNick.emt if they aren't already there.

            while ((_effFile.BaseStream.Length - _effFile.BaseStream.Position) >= 84)
            {
                EffSoundEntry _effEntry;

                _effEntry.UnkRef00     = _effFile.ReadInt32();
                _effEntry.UnkRef04     = _effFile.ReadInt32();
                _effEntry.Reserved     = _effFile.ReadInt32();
                _effEntry.Sequence     = _effFile.ReadInt32();
                _effEntry.X            = _effFile.ReadSingle();
                _effEntry.Y            = _effFile.ReadSingle();
                _effEntry.Z            = _effFile.ReadSingle();
                _effEntry.Radius       = _effFile.ReadSingle();
                _effEntry.Cooldown1    = _effFile.ReadInt32();
                _effEntry.Cooldown2    = _effFile.ReadInt32();
                _effEntry.RandomDelay  = _effFile.ReadInt32();
                _effEntry.Unk44        = _effFile.ReadInt32();
                _effEntry.SoundID1     = _effFile.ReadInt32();
                _effEntry.SoundID2     = _effFile.ReadInt32();
                _effEntry.SoundType    = _effFile.ReadByte();
                _effEntry.UnkPad57     = _effFile.ReadByte();
                _effEntry.UnkPad58     = _effFile.ReadByte();
                _effEntry.UnkPad59     = _effFile.ReadByte();
                _effEntry.AsDistance   = _effFile.ReadInt32();
                _effEntry.UnkRange64   = _effFile.ReadInt32();
                _effEntry.FadeOutMS    = _effFile.ReadInt32();
                _effEntry.UnkRange72   = _effFile.ReadInt32();
                _effEntry.FullVolRange = _effFile.ReadInt32();
                _effEntry.UnkRange80   = _effFile.ReadInt32();

                EmtSoundEntry _sound1 = new EmtSoundEntry();
                EmtSoundEntry _sound2;

                string _soundFile1;
                string _soundFile2;

                switch (_effEntry.SoundType)
                {
                case 0:     // Day/Night Sound Effect, Constant Volume
                    _soundFile1 = SoundFileNumber(_effEntry.SoundID1);
                    if (_effEntry.SoundID1 == _effEntry.SoundID2)
                    {
                        _soundFile2        = "";
                        _sound1.WhenActive = 0;
                    }
                    else
                    {
                        _soundFile2        = SoundFileNumber(_effEntry.SoundID2);
                        _sound1.WhenActive = 1;
                    }
                    break;

                case 1:     // Background Music
                    _soundFile1 = (_effEntry.SoundID1 < 0) ? SoundFileNumber(_effEntry.SoundID1) : (_effEntry.SoundID1 == 0) ? ZoneNick + ".xmi" : ZoneNick + ".xmi";
                    if (_effEntry.SoundID1 == _effEntry.SoundID2)
                    {
                        _soundFile2        = "";
                        _sound1.WhenActive = 0;     // Same music and location for day and night. No need to add two entries to .emt file.
                    }
                    else
                    {
                        _soundFile2        = (_effEntry.SoundID2 < 0) ? SoundFileNumber(_effEntry.SoundID2) : (_effEntry.SoundID2 == 0) ? "" : ZoneNick + ".xmi";
                        _sound1.WhenActive = 1;
                    }

                    _sound1.xmiIndex = ((_effEntry.SoundID1 > 0) && (_effEntry.SoundID1 < 32)) ? _effEntry.SoundID1 : 0;
                    break;

                case 2:     // Static Sound Effect
                    _soundFile1 = SoundFileNumber(_effEntry.SoundID1);
                    _soundFile2 = "";

                    _sound1.Volume = (_effEntry.AsDistance < 0) ? 0.0f : (_effEntry.AsDistance > 3000) ? 0.0f : (3000.0f - (float)_effEntry.AsDistance) / 3000.0f;
                    break;

                case 3:     // Day/Night Sound Effect, Volume by Distance
                    _soundFile1 = SoundFileNumber(_effEntry.SoundID1);
                    _soundFile2 = SoundFileNumber(_effEntry.SoundID2);

                    _sound1.Volume     = (_effEntry.AsDistance < 0) ? 0.0f : (_effEntry.AsDistance > 3000) ? 0.0f : (3000.0f - (float)_effEntry.AsDistance) / 3000.0f;
                    _sound1.WhenActive = 1;
                    break;

                default:     // Unsupported
                    continue;
                }

                if ((_soundFile1.Length > 0) && (_soundFile1.IndexOf('.') < 0))
                {
                    _soundFile1 += ".wav";
                }

                _sound1.SoundFile = _soundFile1;

                _sound1.FadeOutMS = (_effEntry.FadeOutMS <= 0) ? 0 : (_effEntry.FadeOutMS < 100) ? 100 : _effEntry.FadeOutMS; // Sanity check: make sure FadeOutMS is either 0 or 100+ milliseconds

                // Fade in does not appear to be utilized in ZoneNick_sounds.eff, even if one of the Unk fields is supposed to map to it. Make sounds fade in at twice the speed of fading out,
                // so a running player doesn't feel like a sound effect finished fading in after they already passed by.
                _sound1.FadeInMS = Math.Min(_sound1.FadeOutMS / 2, 5000); // Cap at 5 second FadeIn. Some music entries have a looooong FadeOut.

                _sound1.X = _effEntry.X;
                _sound1.Y = _effEntry.Y;
                _sound1.Z = _effEntry.Z;
                if (_effEntry.SoundType != 1) // Music files ignore cooldowns in ZoneNick.emt.
                {
                    _sound1.WavLoopType    = (_effEntry.Cooldown1 <= 0) && (_effEntry.RandomDelay <= 0) ? 0 : 1;
                    _sound1.MinRepeatDelay = (_sound1.WavLoopType == 0) ? 0 : Math.Max(_effEntry.Cooldown1, 0);
                    _sound1.MaxRepeatDelay = (_sound1.WavLoopType == 0) ? 0 : Math.Max(_effEntry.Cooldown1, 0) + Math.Max(_effEntry.RandomDelay, 0);
                }
                _sound1.WavFullVolRadius  = (_effEntry.SoundType == 0) ? _effEntry.Radius : Math.Max(_effEntry.FullVolRange, 0);
                _sound1.ActivationRange   = (Int32)_effEntry.Radius;
                _sound1.WavMaxAudibleDist = _sound1.ActivationRange; // No fields in ZoneNick_sounds.eff appear to map to this, so use the activation range.
                _sound1.IsEnvSound        = (_effEntry.SoundType != 1);

                if ((_soundFile2 == null) || (_soundFile2 == ""))
                {
                    _sound2 = new EmtSoundEntry();
                }
                else
                {
                    _sound2 = _sound1.Clone();

                    if (_soundFile2.IndexOf('.') < 0)
                    {
                        _soundFile2 += ".wav";
                    }

                    _sound2.SoundFile = _soundFile2;

                    if (_effEntry.SoundType != 1) // Music files ignore cooldowns in ZoneNick.emt.
                    {
                        _sound2.WavLoopType    = (_effEntry.Cooldown2 <= 0) && (_effEntry.RandomDelay <= 0) ? 0 : 1;
                        _sound2.MinRepeatDelay = Math.Max(_effEntry.Cooldown2, 0);
                        _sound2.MaxRepeatDelay = Math.Max(_effEntry.Cooldown2, 0) + Math.Max(_effEntry.RandomDelay, 0);
                    }

                    switch (_effEntry.SoundType)
                    {
                    case 0:     // Day/Night Sound Effect, Constant Volume
                        _sound2.WhenActive = 2;
                        break;

                    case 1:     // Background Music
                        _sound2.WhenActive = 2;
                        _sound2.xmiIndex   = ((_effEntry.SoundID2 > 0) && (_effEntry.SoundID2 < 32)) ? _effEntry.SoundID2 : 0;
                        break;

                    case 3:     // Day/Night Sound Effect, Volume by Distance
                        _sound2.WhenActive = 2;
                        break;

                    default:     // Unsupported
                        continue;
                    }
                }

                _soundFile1 = _sound1.ToString();
                _soundFile2 = _sound2.ToString();

                if ((_soundFile1.Length > 0) && (!_emtEntries.Contains(_soundFile1)))
                {
                    _emtEntries.Add(_soundFile1);
                    _emtFile.WriteLine(_soundFile1);
                }

                if ((_soundFile2.Length > 0) && (!_emtEntries.Contains(_soundFile2)))
                {
                    _emtEntries.Add(_soundFile2);
                    _emtFile.WriteLine(_soundFile2);
                }
            }

            _emtFile.Close();

            return(System.Windows.Forms.DialogResult.OK);
        }