Advertisement
Guest User

Untitled

a guest
Jan 20th, 2016
141
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 4.10 KB | None | 0 0
  1. #include "global.h"
  2.  
  3. #define WRITEU8(addr, data) *(vu8*)(addr) = data
  4. #define WRITEU16(addr, data) *(vu16*)(addr) = data
  5. #define WRITEU32(addr, data) *(vu32*)(addr) = data
  6.  
  7. u32 threadStack[0x1000];
  8. Handle fsUserHandle;
  9. FS_archive sdmcArchive;
  10.  
  11.  
  12. #define IO_BASE_PAD     1
  13. #define IO_BASE_LCD     2
  14. #define IO_BASE_PDC     3
  15. #define IO_BASE_GSPHEAP     4
  16.  
  17. u32 IoBasePad = 0xFFFD4000;
  18.  
  19. u32 getKey() {
  20.     return (*(vu32*)(IoBasePad) ^ 0xFFF) & 0xFFF;
  21. }
  22.  
  23. void waitKeyUp() {
  24.     while (getKey() != 0) {
  25.         svc_sleepThread(100000000);
  26.     }
  27. }
  28.  
  29. u8 cheatEnabled[64];
  30. int isNewNtr = 0;
  31.  
  32.  
  33. u32 plgGetIoBase(u32 IoType);
  34. GAME_PLUGIN_MENU gamePluginMenu;
  35.  
  36. void initMenu() {
  37.     memset(&gamePluginMenu, 0, sizeof(GAME_PLUGIN_MENU));
  38. }
  39.  
  40. void addMenuEntry(u8* str) {
  41.     if (gamePluginMenu.count > 64) {
  42.         return;
  43.     }
  44.     u32 pos = gamePluginMenu.count;
  45.     u32 len = strlen(str) + 1;
  46.     gamePluginMenu.offsetInBuffer[pos] = gamePluginMenu.bufOffset;
  47.     strcpy(&(gamePluginMenu.buf[gamePluginMenu.bufOffset]), str);
  48.    
  49.     gamePluginMenu.count += 1;
  50.     gamePluginMenu.bufOffset += len;
  51. }
  52.  
  53. u32 updateMenu() {
  54.     PLGLOADER_INFO *plgLoaderInfo = (void*)0x07000000;
  55.     plgLoaderInfo->gamePluginPid = getCurrentProcessId();
  56.     plgLoaderInfo->gamePluginMenuAddr = (u32)&gamePluginMenu;
  57.    
  58.     u32 ret = 0;
  59.     u32 hProcess;
  60.     u32 homeMenuPid = plgGetIoBase(5);
  61.     if (homeMenuPid == 0) {
  62.         return 1;
  63.     }
  64.     ret = svc_openProcess(&hProcess, homeMenuPid);
  65.     if (ret != 0) {
  66.         return ret;
  67.     }
  68.     copyRemoteMemory( hProcess, &(plgLoaderInfo->gamePluginPid), CURRENT_PROCESS_HANDLE,  &(plgLoaderInfo->gamePluginPid), 8);
  69.     final:
  70.     svc_closeHandle(hProcess);
  71.     return ret;
  72. }
  73.  
  74. int scanMenu() {
  75.     u32 i;
  76.     for (i = 0; i < gamePluginMenu.count; i++) {
  77.         if (gamePluginMenu.state[i]) {
  78.             gamePluginMenu.state[i] = 0;
  79.             return i;
  80.         }
  81.     }
  82.     return -1;
  83. }
  84.  
  85. // detect language (0: english)
  86. int detectLanguage() {
  87.     // unimplemented
  88.     return 0;
  89. }
  90.  
  91. // add one cheat menu entry
  92. void addCheatMenuEntry(u8* str) {
  93.     u8 buf[100];
  94.     xsprintf(buf, "[ ] %s", str);
  95.     addMenuEntry(buf);
  96. }
  97.  
  98. // this function will be called when the state of cheat item changed
  99. void onCheatItemChanged(int id, int enable) {
  100.     // TODO: handle on cheat item is select or unselected
  101.    
  102.  
  103. }
  104.  
  105. // freeze the value
  106. void freezeCheatValue() {
  107.     if (cheatEnabled[0]) {
  108.         WRITEU16(0x149997D0, 0x0000270F);
  109.     }
  110.     if (cheatEnabled[1]) {
  111.         WRITEU16(0x17D99848, 0xE1D11AB2);
  112.         WRITEU16(0x17D9984C, 0xE3510000);
  113.     }
  114.     if (cheatEnabled[2]) {
  115.         WRITEU16(0x00720CC4, 0x0F40C3878);
  116.     }
  117.     if (cheatEnabled[3]) {
  118.         WRITEU16(0x00720B84, 0x00000014);
  119.     }
  120.     if (cheatEnabled[4]) {
  121.         WRITEU16(0x00720B44, 0x00000014);
  122.     }
  123.     if (cheatEnabled[5]) {
  124.         WRITEU16(0x00720B5C, 0x00000014);
  125.     }
  126.     if (cheatEnabled[6]) {
  127.         WRITEU16(0x00720B94, 0x00000014);
  128.     }
  129.     if (cheatEnabled[7]) {
  130.         WRITEU16(0x00720B64, 0x00000014);
  131.     }
  132.     // TODO: handle your own cheat items
  133. }
  134.  
  135. // update the menu status
  136. void updateCheatEnableDisplay(id) {
  137.     gamePluginMenu.buf[gamePluginMenu.offsetInBuffer[id] + 1] = cheatEnabled[id] ? 'X' : ' ';
  138. }
  139.  
  140. // scan and handle events
  141. void scanCheatMenu() {
  142.     int ret = scanMenu();
  143.     if (ret != -1) {
  144.         cheatEnabled[ret] = !cheatEnabled[ret];
  145.         updateCheatEnableDisplay(ret);
  146.         onCheatItemChanged(ret, cheatEnabled[ret]);
  147.     }
  148. }
  149.  
  150. // init
  151. void initCheatMenu() {
  152.     initMenu();
  153.     addCheatMenuEntry("Unlimited Gold");
  154.     addCheatMenuEntry("All Enemies Drop Items");
  155.     addCheatMenuEntry("9999 Max HP");
  156.     addCheatMenuEntry("Max Magic Skill");
  157.     addCheatMenuEntry("Max Wind Magic");
  158.     addCheatMenuEntry("Max Earth Magic");
  159.     addCheatMenuEntry("Max Water Magic");
  160.     addCheatMenuEntry("Max Fire Magic");
  161.     // TODO: Add your own menu entries
  162.    
  163.     updateMenu();
  164. }
  165.  
  166. void gamePluginEntry() {
  167.     u32 ret, key;
  168.     INIT_SHARED_FUNC(plgGetIoBase, 8);
  169.     INIT_SHARED_FUNC(copyRemoteMemory, 9);
  170.     // wait for game starts up (5 seconds)
  171.     svc_sleepThread(5000000000);
  172.  
  173.     if (((NS_CONFIG*)(NS_CONFIGURE_ADDR))->sharedFunc[8]) {
  174.         isNewNtr = 1;
  175.     } else {
  176.         isNewNtr = 0;
  177.     }
  178.    
  179.     if (isNewNtr) {
  180.         IoBasePad = plgGetIoBase(IO_BASE_PAD);
  181.     }
  182.     initCheatMenu();
  183.     while (1) {
  184.         svc_sleepThread(100000000);
  185.         scanCheatMenu();
  186.         freezeCheatValue();
  187.     }
  188. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement