FontUtils.cs 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. using System.IO;
  2. namespace Ryujinx.HLE.Utilities
  3. {
  4. public static class FontUtils
  5. {
  6. private static readonly uint FontKey = 0x06186249;
  7. public static byte[] DecryptFont(Stream bfttfStream)
  8. {
  9. uint KXor(uint In) => In ^ 0x06186249;
  10. using (BinaryReader reader = new BinaryReader(bfttfStream))
  11. {
  12. using (MemoryStream ttfStream = new MemoryStream())
  13. {
  14. using (BinaryWriter output = new BinaryWriter(ttfStream))
  15. {
  16. if (KXor(reader.ReadUInt32()) != 0x18029a7f)
  17. {
  18. throw new InvalidDataException("Error: Input file is not in BFTTF format!");
  19. }
  20. bfttfStream.Position += 4;
  21. for (int i = 0; i < (bfttfStream.Length - 8) / 4; i++)
  22. {
  23. output.Write(KXor(reader.ReadUInt32()));
  24. }
  25. return ttfStream.ToArray();
  26. }
  27. }
  28. }
  29. }
  30. }
  31. }