SFX.cs 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using System.IO;
  4. namespace OpenVIII.Fields
  5. {
  6. /// <summary>
  7. /// Sound IDs
  8. /// </summary>
  9. /// <see cref="http://wiki.ffrtt.ru/index.php?title=FF8/FileFormat_SFX"/>
  10. public class SFX : IReadOnlyList<uint>
  11. {
  12. #region Fields
  13. private readonly IReadOnlyList<uint> _sndIDs;
  14. #endregion Fields
  15. #region Constructors
  16. public SFX(byte[] sfxB)
  17. {
  18. if (sfxB == null || sfxB.Length < 4) return;
  19. var sndIDs = new List<uint>(sfxB.Length / 4);
  20. MemoryStream ms;
  21. using (var br = new BinaryReader(ms = new MemoryStream(sfxB)))
  22. while (ms.Position < ms.Length)
  23. sndIDs.Add(br.ReadUInt32());
  24. _sndIDs = sndIDs.AsReadOnly();
  25. }
  26. #endregion Constructors
  27. #region Properties
  28. public int Count => _sndIDs.Count;
  29. #endregion Properties
  30. #region Indexers
  31. public uint this[int index] => _sndIDs[index];
  32. #endregion Indexers
  33. #region Methods
  34. public IEnumerator<uint> GetEnumerator() => _sndIDs.GetEnumerator();
  35. IEnumerator IEnumerable.GetEnumerator() => _sndIDs.GetEnumerator();
  36. #endregion Methods
  37. }
  38. }