Guest User

Untitled

a guest
May 12th, 2016
389
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #define BIT(x) (1 << x)
  2.  
  3.  
  4. /* hidSharedMem can be 0x10000000, 0x10001000, 0x10002000 (maybe even 0x10003000 but didn't see the case until now)
  5. ** the address can be different between games
  6. ** I don't know for now how to retrieve it automatically so you must define the good one manually
  7. */
  8. vu32 *hidSharedMem = (u32 *)0x10002000;
  9. u32 kDown = 0;
  10.  
  11. enum
  12. {
  13. KEY_A = BIT(0), ///< A
  14. KEY_B = BIT(1), ///< B
  15. KEY_SELECT = BIT(2), ///< Select
  16. KEY_START = BIT(3), ///< Start
  17. KEY_DRIGHT = BIT(4), ///< D-Pad Right
  18. KEY_DLEFT = BIT(5), ///< D-Pad Left
  19. KEY_DUP = BIT(6), ///< D-Pad Up
  20. KEY_DDOWN = BIT(7), ///< D-Pad Down
  21. KEY_R = BIT(8), ///< R
  22. KEY_L = BIT(9), ///< L
  23. KEY_X = BIT(10), ///< X
  24. KEY_Y = BIT(11), ///< Y
  25. KEY_CPAD_RIGHT = BIT(28), ///< Circle Pad Right
  26. KEY_CPAD_LEFT = BIT(29), ///< Circle Pad Left
  27. KEY_CPAD_UP = BIT(30), ///< Circle Pad Up
  28. KEY_CPAD_DOWN = BIT(31), ///< Circle Pad Down
  29.  
  30. };
  31.  
  32. u32 hidCheckSectionUpdateTime(vu32 *sharedmem_section, u32 id)
  33. {
  34. s64 tick0 = 0;
  35. s64 tick1 = 0;
  36.  
  37. if (id==0)
  38. {
  39. tick0 = *((u64 *)&sharedmem_section[0]);
  40. tick1 = *((u64 *)&sharedmem_section[2]);
  41. if (tick0 == tick1 || tick0 < 0 || tick1 < 0)
  42. return 1;
  43. }
  44. return 0;
  45. }
  46.  
  47. void scanHID(void)
  48. {
  49. u32 id = 0;
  50. kDown = 0;
  51. id = hidSharedMem[4];
  52.  
  53. if (id > 7)
  54. id = 7;
  55. if (hidCheckSectionUpdateTime(hidSharedMem, id) == 0)
  56. kDown = hidSharedMem[10 + id * 4];
  57. }
  58.  
  59. void editMemoryRights(void)
  60. {
  61. int i;
  62.  
  63. for (i = 0; i < 8; i++)
  64. rtCheckRemoteMemoryRegionSafeForWrite(getCurrentProcessHandle(), (u32)hidSharedMem + (10 + i * 4), 4);
  65. }
  66.  
  67. void setHID(u32 keys)
  68. {
  69. u32 id;
  70.  
  71. id = hidSharedMem[4];
  72. if(id > 7)
  73. id = 7;
  74. hidSharedMem[10 + id * 4] |= keys;
  75. }
  76.  
  77. u32 hidKeysDown()
  78. {
  79. return(kDown);
  80. }
  81.  
  82. void send_key(u32 keys)
  83. {
  84. setHID(keys);
  85. }
  86.  
  87. void my_super_bot(void)
  88. {
  89. editMemoryRights();
  90. //Press L + A +B to exit the loop
  91. while (hidKeysDown() != (KEY_A | KEY_B | KEY_L))
  92. {
  93. //send A
  94. send_key(KEY_A);
  95. //wait 1s
  96. svcSleep(1000000000);
  97. //send B
  98. send_key(KEY_B);
  99. //wait 1s
  100. svcSleep(1000000000);
  101. //send A
  102. send_key(KEY_A);
  103. //wait 10s
  104. svcSleep(10000000000);
  105. scanHID();
  106. }
  107. }
RAW Paste Data