Homebrew.cs 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. using ARMeilleure.Memory;
  2. using System.Text;
  3. namespace Ryujinx.HLE.HOS
  4. {
  5. static class Homebrew
  6. {
  7. public const string TemporaryNroSuffix = ".ryu_tmp.nro";
  8. // http://switchbrew.org/index.php?title=Homebrew_ABI
  9. public static void WriteHbAbiData(IMemoryManager memory, long position, int mainThreadHandle, string switchPath)
  10. {
  11. // MainThreadHandle.
  12. WriteConfigEntry(memory, ref position, 1, 0, mainThreadHandle);
  13. // NextLoadPath.
  14. WriteConfigEntry(memory, ref position, 2, 0, position + 0x200, position + 0x400);
  15. // Argv.
  16. long argvPosition = position + 0xC00;
  17. memory.WriteBytes(argvPosition, Encoding.ASCII.GetBytes(switchPath + "\0"));
  18. WriteConfigEntry(memory, ref position, 5, 0, 0, argvPosition);
  19. // AppletType.
  20. WriteConfigEntry(memory, ref position, 7);
  21. // EndOfList.
  22. WriteConfigEntry(memory, ref position, 0);
  23. }
  24. private static void WriteConfigEntry(
  25. IMemoryManager memory,
  26. ref long position,
  27. int key,
  28. int flags = 0,
  29. long value0 = 0,
  30. long value1 = 0)
  31. {
  32. memory.WriteInt32(position + 0x00, key);
  33. memory.WriteInt32(position + 0x04, flags);
  34. memory.WriteInt64(position + 0x08, value0);
  35. memory.WriteInt64(position + 0x10, value1);
  36. position += 0x18;
  37. }
  38. public static string ReadHbAbiNextLoadPath(IMemoryManager memory, long position)
  39. {
  40. string fileName = null;
  41. while (true)
  42. {
  43. long key = memory.ReadInt64(position);
  44. if (key == 2)
  45. {
  46. long value0 = memory.ReadInt64(position + 0x08);
  47. long value1 = memory.ReadInt64(position + 0x10);
  48. fileName = MemoryHelper.ReadAsciiString(memory, value0, value1 - value0);
  49. break;
  50. }
  51. else if (key == 0)
  52. {
  53. break;
  54. }
  55. position += 0x18;
  56. }
  57. return fileName;
  58. }
  59. }
  60. }