Advertisement
Jo-Milk

menu_loader.h

Jul 26th, 2022
1,270
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 12.18 KB | None | 0 0
  1. //menu_loader.h
  2.  
  3. CDECL uint32_t vshmain_0624D3AE();
  4. #define GetGameProcessID vshmain_0624D3AE
  5.  
  6. #pragma comment(lib, "vshmain_export_stub")
  7.  
  8.  
  9.  
  10. uint64_t g_game_procces_id = 0;
  11. bool bLoadMenu = true;
  12. bool enableCCAPISysCall = true;
  13. static void* vsh_pdata_addr = NULL;
  14.  
  15. #include <cell/pad.h>
  16.  
  17. // redefinition of pad bit flags
  18. #define    PAD_SELECT    (1<<0)
  19. #define    PAD_L3        (1<<1)
  20. #define    PAD_R3        (1<<2)
  21. #define    PAD_START     (1<<3)
  22. #define    PAD_UP        (1<<4)
  23. #define    PAD_RIGHT     (1<<5)
  24. #define    PAD_DOWN      (1<<6)
  25. #define    PAD_LEFT      (1<<7)
  26. #define    PAD_L2        (1<<8)
  27. #define    PAD_R2        (1<<9)
  28. #define    PAD_L1        (1<<10)
  29. #define    PAD_R1        (1<<11)
  30. #define    PAD_TRIANGLE  (1<<12)
  31. #define    PAD_CIRCLE    (1<<13)
  32. #define    PAD_CROSS     (1<<14)
  33. #define    PAD_SQUARE    (1<<15)
  34.  
  35.  
  36.  
  37. #define unk_title_id_var ""
  38. #define unk_title_id_var_as_char ''
  39.  
  40. bool IsGameAW(char* cur_title_id)
  41. {
  42.     if (!strcmp(cur_title_id, unk_title_id_var "BLUS31466") || !strcmp(cur_title_id, unk_title_id_var "BLES02077") ||
  43.         !strcmp(cur_title_id, unk_title_id_var "BLES02078") || !strcmp(cur_title_id, unk_title_id_var "BLES02079") ||
  44.         !strcmp(cur_title_id, unk_title_id_var "NPUB31553") || !strcmp(cur_title_id, unk_title_id_var "NPEB02087")
  45.         // BLJM61227 BLJM61228
  46.         )
  47.     {
  48.         return true;
  49.     }
  50.  
  51.     return false;
  52. }
  53. bool IsGameBO1(char* cur_title_id)
  54. {
  55.     if (!strcmp(cur_title_id, unk_title_id_var "BLES01031") || !strcmp(cur_title_id, unk_title_id_var "BLES01032") ||
  56.         !strcmp(cur_title_id, unk_title_id_var "BLES01033") || !strcmp(cur_title_id, unk_title_id_var "BLES01034") ||
  57.         !strcmp(cur_title_id, unk_title_id_var "BLES01035") || !strcmp(cur_title_id, unk_title_id_var "BLES01105") ||
  58.         !strcmp(cur_title_id, unk_title_id_var "BLUS30591")
  59.         // BLJM60286
  60.         )
  61.     {
  62.         return true;
  63.     }
  64.  
  65.     return false;
  66. }
  67. bool IsGameBO2(char* cur_title_id)
  68. {
  69.     if (!strcmp(cur_title_id, unk_title_id_var "BLUS31011") || !strcmp(cur_title_id, unk_title_id_var "BLES01717") ||
  70.         !strcmp(cur_title_id, unk_title_id_var "BLES01718") || !strcmp(cur_title_id, unk_title_id_var "BLES01719") ||
  71.         !strcmp(cur_title_id, unk_title_id_var "BLES01720") || !strcmp(cur_title_id, unk_title_id_var "BLUS31141") ||
  72.         !strcmp(cur_title_id, unk_title_id_var "BLUS31140") || !strcmp(cur_title_id, unk_title_id_var "NPEB01205")
  73.         )
  74.     {
  75.         return true;
  76.     }
  77.  
  78.     return false;
  79. }
  80. bool IsGameBO3(char* cur_title_id)
  81. {
  82.     if (!strcmp(cur_title_id, unk_title_id_var "BLES02166") || !strcmp(cur_title_id, unk_title_id_var "BLES02168") ||
  83.         !strcmp(cur_title_id, unk_title_id_var "NPUB31054") || !strcmp(cur_title_id, unk_title_id_var "NPUB31055") ||
  84.         !strcmp(cur_title_id, unk_title_id_var "NPUB31056") || !strcmp(cur_title_id, unk_title_id_var "NPUB31665") ||
  85.         !strcmp(cur_title_id, unk_title_id_var "NPEB02266") || !strcmp(cur_title_id, unk_title_id_var "BLUS31527")
  86.         )
  87.     {
  88.         return true;
  89.     }
  90.  
  91.     return false;
  92. }
  93. bool IsGameGhosts(char* cur_title_id)
  94. {
  95.     if (!strcmp(cur_title_id, unk_title_id_var "BLES01948") || !strcmp(cur_title_id, unk_title_id_var "BLES01945") ||
  96.         !strcmp(cur_title_id, unk_title_id_var "BLUS31270") || !strcmp(cur_title_id, unk_title_id_var "NPUB31301") ||
  97.         !strcmp(cur_title_id, unk_title_id_var "NPEB01832")
  98.         )
  99.     {
  100.         return true;
  101.     }
  102.  
  103.     return false;
  104. }
  105. bool IsGameMW3(char* cur_title_id)
  106. {
  107.     if (!strcmp(cur_title_id, unk_title_id_var "BLUS30838") || !strcmp(cur_title_id, unk_title_id_var "BLES01432") ||
  108.         !strcmp(cur_title_id, unk_title_id_var "BLES01428") || !strcmp(cur_title_id, unk_title_id_var "BLES01429") ||
  109.         !strcmp(cur_title_id, unk_title_id_var "NPUB30787") || !strcmp(cur_title_id, unk_title_id_var "NPUB30788") ||
  110.         !strcmp(cur_title_id, unk_title_id_var "BLES01433") || !strcmp(cur_title_id, unk_title_id_var "BLES01431") ||
  111.         !strcmp(cur_title_id, unk_title_id_var "NPEB00964")
  112.         )
  113.     {
  114.         return true;
  115.     }
  116.  
  117.     return false;
  118. }
  119. bool IsGameMW2(char* cur_title_id)
  120. {
  121.     if (!strcmp(cur_title_id, unk_title_id_var "BLUS30377") || !strcmp(cur_title_id, unk_title_id_var "BLES00683") ||
  122.         !strcmp(cur_title_id, unk_title_id_var "BLES00684") || !strcmp(cur_title_id, unk_title_id_var "BLES00685") ||
  123.         !strcmp(cur_title_id, unk_title_id_var "BLES00686") || !strcmp(cur_title_id, unk_title_id_var "BLES00687") ||
  124.         !strcmp(cur_title_id, unk_title_id_var "BLES00690") || !strcmp(cur_title_id, unk_title_id_var "BLES00691") ||
  125.         !strcmp(cur_title_id, unk_title_id_var "NPUB30585") || !strcmp(cur_title_id, unk_title_id_var "NPUB30586") ||
  126.         !strcmp(cur_title_id, unk_title_id_var "NPEB00731")
  127.         )
  128.     {
  129.         return true;
  130.     }
  131.  
  132.     return false;
  133. }
  134.  
  135.  
  136. int32_t sys_get_game_application_title_id(char* title_id)
  137. {
  138.     system_call_1(986, (uint64_t)title_id);
  139.     return_to_user_prog(int32_t);
  140. }
  141. char* GetCurrentGameID()
  142. {
  143.     char csTitle_id[64];
  144.     sys_get_game_application_title_id(csTitle_id);
  145.  
  146.     // remove unknown var from title id
  147.     // if (csTitle_id[0] == unk_title_id_var_as_char)
  148.     //  memmove(csTitle_id, csTitle_id + 1, strlen(csTitle_id));
  149.  
  150.     return csTitle_id;
  151. }
  152.  
  153. int write_payload(uint32_t start_addr, const char* file)
  154. {
  155.     int next_write = 0;
  156.  
  157.     int fd = 0; uint64_t pos, read_e = 1;
  158.  
  159.     if (cellFsOpen(file, CELL_FS_O_RDONLY, &fd, NULL, 0) == CELL_FS_SUCCEEDED)
  160.     {
  161.         while (read_e)
  162.         {
  163.             char* data = (char*)malloc(BYTES_PER_WRITE);
  164.             if (cellFsRead(fd, (void*)(data), BYTES_PER_WRITE, &read_e) == CELL_FS_SUCCEEDED)
  165.             {
  166.                 CCAPIWriteProcessMemory(g_game_procces_id, (void*)(start_addr + next_write), data, read_e);
  167.                 next_write += read_e;
  168.                 if (data)
  169.                     free(data);
  170.             }
  171.         }
  172.  
  173.         cellFsClose(fd);
  174.     }
  175.     else
  176.     {
  177.         return ENOENT;
  178.     }
  179.  
  180.     return 0;
  181. }
  182.  
  183. bool inject_menu(char *file_name, uint32_t file_size)
  184. {
  185.     int ret;
  186.     if (enableCCAPISysCall)
  187.     {
  188.         ret = CCAPIEnableSysCall();
  189.         printf("CCAPIEnableSysCall ret: 0x%X\n", ret);
  190.         if (ret == 0)
  191.         {
  192.             // success, we don't need this option anymore
  193.             enableCCAPISysCall = false;
  194.         }
  195.         if (ret != 0)
  196.         {
  197.             enableCCAPISysCall = false;
  198.             printf("failed to enable ccapi syscall\n");
  199.             printf("something wrong happened\n");
  200.             return false;
  201.         }
  202.     }
  203.  
  204.     uint64_t kernel_adr, game_adr;
  205.     ret = CCAPIAllocatePage(g_game_procces_id, file_size, 0x100, 0x2F, 0x1, &kernel_adr, &game_adr);
  206.     if (ret != 0)
  207.     {
  208.         printf("failed to allocated\n");
  209.         return false;
  210.     }
  211.  
  212.  
  213.     // printf("game_adr: 0x%X\n", game_adr);
  214.  
  215.     uint32_t temp_bytes;
  216.     ret = CCAPIReadProcessMemory(g_game_procces_id, (void *)game_adr, (void *)&temp_bytes, 4);
  217.     if (ret != 0)
  218.     {
  219.         printf("address not yet alloacted\n");
  220.         return false;
  221.     }
  222.  
  223.     ret = write_payload(game_adr, file_name);
  224.     if (ret != 0)
  225.     {
  226.         printf("failed to open file\n");
  227.         return false;
  228.     }
  229.  
  230.  
  231.     uint32_t toc[2];
  232.     toc[0] = game_adr;
  233.     toc[1] = 0x00000000;
  234.     thread_t th;
  235.     ret = CCAPICreateProcessThread(g_game_procces_id, &th, toc, 0, 0x7D0, 0x4000, "temp_game_thread");
  236.     if (ret != 0)
  237.     {
  238.         printf("failed to create thread for game\n");
  239.         return false;
  240.     }
  241.  
  242.  
  243.     return true;
  244. }
  245.  
  246. void VSHPadGetData(CellPadData* data)
  247. {
  248.     uint32_t pm_start = 0x10000UL;
  249.     uint64_t pat[2] = { 0x380000077D3F4B78ULL, 0x7D6C5B787C0903A6ULL };
  250.  
  251.     if (!vsh_pdata_addr)        // first time, get address
  252.     {
  253.         while (pm_start < 0x700000UL)
  254.         {
  255.             if ((*(uint64_t*)pm_start == pat[0])
  256.                 && (*(uint64_t*)(pm_start + 8) == pat[1]))
  257.             {
  258.                 vsh_pdata_addr = (void*)(uint32_t)(
  259.                     (int32_t)((*(uint32_t*)(pm_start + 0x234) & 0x0000FFFF) << 16) +
  260.                     (int16_t)(*(uint32_t*)(pm_start + 0x244) & 0x0000FFFF));
  261.  
  262.                 // 0x00748954  4.84D
  263.                 printf("vsh_pdata_addr: 0x%X\n", vsh_pdata_addr);
  264.  
  265.                 break;
  266.             }
  267.  
  268.             pm_start += 4;
  269.         }
  270.     }
  271.  
  272.     memcpy(data, vsh_pdata_addr, sizeof(CellPadData));
  273. }
  274.  
  275. void ccapi_menu_loader_thread(uint64_t arg)
  276. {
  277.     // change CCSC with HxD so it can work with CEX to
  278.  
  279.     // wait for vsh to start up
  280.     Sleep(10000);
  281.  
  282.     printf("FMT Menu loader thread starting\n");
  283.  
  284.     /*
  285.     ret = CCAPIEnableSysCall();
  286.     if (ret != 0)
  287.     {
  288.         printf("failed to enable ccapi syscall x2\n");
  289.         goto thread_exit;
  290.     }
  291.     else
  292.     {
  293.         // incompatible version but doesn't reach here becuase it will crash if incompatible
  294.     }
  295.     */
  296.  
  297.     bool bInjection_result = true;
  298.     bool bWait_for_game_feedback = true;
  299.  
  300.     uint32_t uiOldpad = 0, uiCurpad = 0;
  301.     CellPadData pData;
  302.  
  303.     while (true)
  304.     {
  305.         VSHPadGetData(&pData); // start scanning for address
  306.  
  307.         g_game_procces_id = GetGameProcessID();
  308.         //printf("g_game_procces_id: 0x%X\n", g_game_procces_id);
  309.         if (g_game_procces_id != 0)
  310.         {
  311.             if (bWait_for_game_feedback)
  312.             {
  313.                 // 10 works fine on aw
  314.                 // 20 for bo2
  315.                 // 180 didn't work for bo3, I think it might be that we need the FMT eboot. UPDATE: it was that we needed the FMT eboot
  316.                 // 27 should be enough for all games
  317.                 for (int x = 0; x < (30 * 100); x++) //30 second delay
  318.                 {
  319.                     sys_timer_usleep(10000);
  320.                     sys_ppu_thread_yield();
  321.                 }
  322.  
  323.                 bWait_for_game_feedback = false;
  324.             }
  325.  
  326.             char *game_id = GetCurrentGameID();
  327.             //printf("game region: %s\n", game_id);
  328.  
  329.             if (pData.len > 0)
  330.             {
  331.                 uiCurpad = (pData.button[2] | (pData.button[3] << 8));
  332.                 if (uiCurpad != uiOldpad)
  333.                 {
  334.                     if ((uiCurpad & PAD_L1) && (uiCurpad & PAD_R2))
  335.                     {
  336.                         printf("pressing L1 + R2\n");
  337.                         if (uiCurpad & PAD_L3)
  338.                         {
  339.                             printf("pressing L3\n");
  340.  
  341.                             if (IsGameAW(game_id)) // Advance Warfare
  342.                             {
  343.                                 printf("Advance Warfare inject started\n");
  344.                                 if (bLoadMenu)
  345.                                 {
  346.                                     bInjection_result = inject_menu("/dev_hdd0/tmp/enstone/fury_by_enstone_220.bin", KB(496));
  347.                                     bLoadMenu = false;
  348.                                 }
  349.                             }
  350.                             else if (IsGameBO1(game_id)) // BO1
  351.                             {
  352.                                 printf("Black Ops 1 inject started\n");
  353.                                 if (bLoadMenu)
  354.                                 {
  355.                                     bInjection_result = inject_menu("/dev_hdd0/tmp/enstone/fusion_by_enstone_114.bin", KB(156));
  356.                                     bLoadMenu = false;
  357.                                 }
  358.                             }
  359.                             else if (IsGameBO2(game_id)) // BO2
  360.                             {
  361.                                 printf("Black Ops 2 inject started\n");
  362.                                 if (bLoadMenu)
  363.                                 {
  364.                                     if (true) // load only destiny
  365.                                     {
  366.                                         bInjection_result = inject_menu("/dev_hdd0/tmp/enstone/destiny_by_enstone_120.bin", KB(628));
  367.                                     }
  368.                                     else
  369.                                     {
  370.                                         bInjection_result = inject_menu("/dev_hdd0/tmp/enstone/revolution_by_enstone_unk.bin", KB(224)); // fake number 224 and fake version _unk. we don't know becuase we never dumped it
  371.                                     }
  372.  
  373.                                     bLoadMenu = false;
  374.                                 }
  375.                             }
  376.                             else if (IsGameBO3(game_id)) // BO3
  377.                             {
  378.                                 printf("Black Ops 3 inject started\n");
  379.                                 if (bLoadMenu)
  380.                                 {
  381.                                     bInjection_result = inject_menu("/dev_hdd0/tmp/enstone/fatality_by_enstone_102.bin", KB(444));
  382.                                     bLoadMenu = false;
  383.                                 }
  384.                             }
  385.                             else if (IsGameGhosts(game_id)) // Ghosts
  386.                             {
  387.                                 printf("Ghosts inject started\n");
  388.  
  389.                                 if (bLoadMenu)
  390.                                 {
  391.                                     bInjection_result = inject_menu("/dev_hdd0/tmp/enstone/eternity_by_enstone_105.bin", KB(300));
  392.                                     bLoadMenu = false;
  393.                                 }
  394.                             }
  395.                             else if (IsGameMW3(game_id)) // MW3
  396.                             {
  397.                                 printf("Modern Warfare 3 inject started\n");
  398.                                 if (bLoadMenu)
  399.                                 {
  400.                                     if (true) // load only phantom
  401.                                     {
  402.                                         bInjection_result = inject_menu("/dev_hdd0/tmp/enstone/phantom_by_enstone_221.bin", KB(484));
  403.                                     }
  404.                                     else
  405.                                     {
  406.                                         bInjection_result = inject_menu("/dev_hdd0/tmp/enstone/project_memories_by_enstone_388.bin", KB(112));
  407.                                     }
  408.  
  409.                                     bLoadMenu = false;
  410.                                 }
  411.                             }
  412.                             else if (IsGameMW2(game_id)) // MW2
  413.                             {
  414.                                 printf("Modern Warfare 2 inject started\n");
  415.                                 if (bLoadMenu)
  416.                                 {
  417.                                     bInjection_result = inject_menu("/dev_hdd0/tmp/enstone/reborn_by_enstone_446.bin", KB(140));
  418.                                     bLoadMenu = false;
  419.                                 }
  420.                             }
  421.                             else
  422.                             {
  423.                                 // no other game cracks
  424.                             }
  425.  
  426.  
  427.                         }
  428.                     }
  429.                 }
  430.  
  431.                 uiOldpad = uiCurpad;
  432.             }
  433.             else
  434.             {
  435.                 uiOldpad = 0;
  436.             }
  437.  
  438.             if (!bInjection_result) // if something failed then stop the thread
  439.             {
  440.                 printf("injection failed\n");
  441.                 break;
  442.             }
  443.  
  444.         }
  445.         else
  446.         {
  447.             g_game_procces_id = 0;
  448.             bLoadMenu = true;
  449.         }
  450.  
  451.  
  452.  
  453.         Sleep(200); // 2000 10000  // smaller sleep for faster input on controller
  454.     }
  455.  
  456.  
  457. thread_exit:
  458.  
  459.     sys_ppu_thread_exit(0);
  460. }
  461.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement