texl.cs 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. using Microsoft.Xna.Framework.Graphics;
  2. using System;
  3. using System.Collections.Generic;
  4. using System.IO;
  5. using System.Linq;
  6. using System.Text;
  7. using System.Threading.Tasks;
  8. namespace OpenVIII
  9. {
  10. /// <summary>
  11. /// Texl.obj is a file containing 20 high-res TIM textures for world map
  12. /// </summary>
  13. class texl
  14. {
  15. private const int TEX_SIZE = 0x12800;
  16. private const int TEX_COUNT = 20;
  17. private TextureHandler[][] textures;
  18. public texl(byte[] texlBuffer)
  19. {
  20. textures = new TextureHandler[20][];
  21. using (var br = new BinaryReader(new MemoryStream(texlBuffer)))
  22. for (var i = 0; i < TEX_COUNT; i++)
  23. {
  24. var timOffset = i * TEX_SIZE;
  25. var tim = new TIM2(texlBuffer, (uint)timOffset);
  26. textures[i] = new TextureHandler[tim.GetClutCount];
  27. for (ushort k = 0; k < textures[i].Length; k++)
  28. textures[i][k] = TextureHandler.Create($"texl_tim{(i + 1).ToString("D2")}.tim", tim, k, null);
  29. //todo detect if mods aren't using palettes.
  30. }
  31. }
  32. public TextureHandler GetTexture(int index, int clut)
  33. => textures[index][clut];
  34. }
  35. }