private void ExportHardcodedSounds(IEnumerable <int> indices) { short id = -2; foreach (int index in indices) { Definition.HardcodedSound.SoundMapIndices[index] = id--; } int offset = 2; foreach (short index in Definition.HardcodedSound.SoundMapIndices.Keys) { short val = Definition.HardcodedSound.SoundMapIndices[index]; TRSoundDetails details = Level.SoundDetails[Level.SoundMap[index]]; uint[] sampleIndices = new uint[details.NumSounds]; for (int i = 0; i < details.NumSounds; i++) { sampleIndices[i] = Level.SampleIndices[(ushort)(details.Sample + i)]; } Definition.HardcodedSound.SampleIndices[(ushort)(ushort.MaxValue - offset)] = sampleIndices; Definition.HardcodedSound.SoundDetails[val] = new TRSoundDetails { Chance = details.Chance, Characteristics = details.Characteristics, Sample = (ushort)(ushort.MaxValue - offset), Volume = details.Volume }; offset++; } }
private void PackAnimSounds(PackedAnimation packedAnimation) { foreach (PackedAnimationCommand cmd in packedAnimation.Commands.Values) { if (cmd.Command == TR2AnimCommand.PlaySound) { int soundMapIndex = cmd.Params[1] & 0x3fff; short soundDetailsIndex = Level.SoundMap[soundMapIndex]; packedAnimation.Sound.SoundMapIndices[soundMapIndex] = soundDetailsIndex; if (soundDetailsIndex != -1) { TRSoundDetails soundDetails = Level.SoundDetails[soundDetailsIndex]; packedAnimation.Sound.SoundDetails[soundDetailsIndex] = soundDetails; uint[] sampleIndices = new uint[soundDetails.NumSounds]; for (int i = 0; i < soundDetails.NumSounds; i++) { sampleIndices[i] = Level.SampleIndices[(ushort)(soundDetails.Sample + i)]; } packedAnimation.Sound.SampleIndices[soundDetails.Sample] = sampleIndices; } } } }
private void ResortSoundIndices() { // Store the values from SampleIndices against their current positions // in the list. List <uint> sampleIndices = Level.SampleIndices.ToList(); Dictionary <int, uint> indexMap = new Dictionary <int, uint>(); for (int i = 0; i < sampleIndices.Count; i++) { indexMap[i] = sampleIndices[i]; } // Sort the indices to avoid the game crashing sampleIndices.Sort(); // Remap each SoundDetail to use the new index of the sample it points to foreach (TRSoundDetails soundDetails in Level.SoundDetails) { soundDetails.Sample = (ushort)sampleIndices.IndexOf(indexMap[soundDetails.Sample]); } // Save the samples back to the level Level.SampleIndices = sampleIndices.ToArray(); // Repeat for SoundMap -> SoundDetails Dictionary <int, TRSoundDetails> soundMapIndices = new Dictionary <int, TRSoundDetails>(); List <short> soundMap = Level.SoundMap.ToList(); for (int i = 0; i < soundMap.Count; i++) { if (soundMap[i] != -1) { soundMapIndices[i] = Level.SoundDetails[soundMap[i]]; } } List <TRSoundDetails> soundDetailsList = Level.SoundDetails.ToList(); soundDetailsList.Sort(delegate(TRSoundDetails d1, TRSoundDetails d2) { return(d1.Sample.CompareTo(d2.Sample)); }); foreach (int mapIndex in soundMapIndices.Keys) { TRSoundDetails details = soundMapIndices[mapIndex]; soundMap[mapIndex] = (short)soundDetailsList.IndexOf(details); } Level.SoundDetails = soundDetailsList.ToArray(); Level.SoundMap = soundMap.ToArray(); }
private void GenerateSoundDetailsMap() { // Update each SoundDetails.Sample with the new SampleIndex values. Store // a map of old SoundsDetails indices to new. _soundDetails = _level.SoundDetails.ToList(); _soundDetailsMap = new Dictionary <int, int>(); foreach (int soundDetailsIndex in _sound.SoundDetails.Keys) { TRSoundDetails details = _sound.SoundDetails[soundDetailsIndex]; details.Sample = _sampleMap[details.Sample]; _soundDetailsMap[soundDetailsIndex] = _soundDetails.Count; _soundDetails.Add(details); } }