Guest User

Untitled

a guest
May 27th, 2018
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.45 KB | None | 0 0
  1. void LoadGame() // DVD Loader! HUGE thanks to crediar who did absolutely all the work.
  2. {
  3. u8 *buffer = (u8*)0x93000000;
  4. int game_partition_offset=0;
  5.  
  6. void (*app_init)(void (*report)(const char *fmt, ...));
  7. int (*app_main)(void **dst, int *size, int *offset);
  8. void * (*app_final)();
  9. void (*entrypoint)();
  10. void (*app_entry)(void(**init)(const char *fmt, ...), int (**main)(), void *(**final)());
  11.  
  12. WPAD_Disconnect(0);
  13. WPAD_Shutdown();
  14. ISFS_Deinitialize();
  15. __ES_Close();
  16.  
  17. // TODO: Choose the correct IOS from the games TMD
  18. //printf("\n");
  19. //printf("Current IOS: %d\n", (*(vu32*)0x80003140)>>16);
  20. //printf("IOS_ReloadIOS(): %d\n", IOS_ReloadIOS(36));
  21. //printf("Current IOS: %d\n", (*(vu32*)0x80003140)>>16);
  22.  
  23. //printf("\x1b[2;0H\n");
  24.  
  25. IOS_ReloadIOS(36);
  26.  
  27. DVDInit();
  28. DVDLowClosePartition();
  29. DVDLowStopMotor();
  30.  
  31. if( DVDLowGetCoverStatus() == DVD_COVER_OPEN )
  32. {
  33. //printf("No Disc Inserted! Please insert a disc...\nReturning to main menu.");
  34.  
  35. sleep(4);
  36. IOS_Close(DVDGetHandle());
  37. return;
  38. }
  39. //printf("Disc found! Launching...\n");
  40.  
  41. DVDLowReset();
  42. DVDLowReadDiskID( (void*)0x80000000 );
  43. DVDLowUnencryptedRead( buffer, 0x20, 0x40000>>2);
  44.  
  45. DCFlushRange(buffer, 0x100);
  46.  
  47. int partitions = ((u32*)buffer)[0];
  48. int partition_info_offset = ((u32*)buffer)[1] << 2;
  49.  
  50. DVDLowUnencryptedRead( buffer, 0x20, partition_info_offset>>2 );
  51.  
  52. int i;
  53. for( i=0; i < partitions; i++)
  54. if( ((u32*)buffer)[i*2+1] == 0 )
  55. game_partition_offset = ((u32*)buffer)[i*2]<<2;
  56.  
  57. //let's open the partition
  58.  
  59. ((u32*)buffer)[(0x40>>2)] = 0x8B000000;
  60. ((u32*)buffer)[(0x40>>2)+1] = game_partition_offset>>2;
  61.  
  62. //in
  63. ((u32*)buffer)[0x00] = (unsigned int)PHYSADDR(buffer+0x40); //0x00
  64. ((u32*)buffer)[0x01] = 0x20; //0x04
  65. ((u32*)buffer)[0x02] = 0; //0x08
  66. ((u32*)buffer)[0x03] = 0x2A4; //0x0C
  67. ((u32*)buffer)[0x04] = 0; //0x10
  68. ((u32*)buffer)[0x05] = 0; //0x14
  69.  
  70. //out
  71. ((u32*)buffer)[0x06] = (unsigned int)PHYSADDR(buffer+0x380); //0x18
  72. ((u32*)buffer)[0x07] = 0x49E4; //0x1C
  73. ((u32*)buffer)[0x08] = (unsigned int)PHYSADDR(buffer+0x360); //0x20
  74. ((u32*)buffer)[0x09] = 0x20; //0x24
  75.  
  76. DCFlushRange(buffer, 0x100);
  77.  
  78. IOS_Ioctlv( DVDGetHandle(), 0x8B, 3, 2, (ioctlv*)buffer);
  79.  
  80. DVDLowRead( buffer, 0x40, 0x20>>2);
  81.  
  82. DVDLowRead( buffer, 0x20, 0x2440>>2);
  83.  
  84. DVDLowRead((void*)0x81200000, *(unsigned long*)(buffer+0x14)+*(unsigned long*)(buffer+0x18), 0x2460>>2);
  85.  
  86. app_entry = (u8*)(buffer+0x10);
  87. app_entry(&app_init, &app_main, &app_final);
  88. app_init(printf);
  89.  
  90. void *dst=0;
  91. int lenn, offset;
  92.  
  93. while (1)
  94. {
  95. lenn=0;
  96. offset=0;
  97. dst=0;
  98.  
  99. if( app_main(&dst, &lenn, &offset) != 1)
  100. break;
  101.  
  102. DVDLowRead( dst, lenn, offset );
  103. DCFlushRange(dst, lenn);
  104. }
  105.  
  106. IOS_Close(DVDGetHandle());
  107. __IOS_ShutdownSubsystems();
  108.  
  109. entrypoint = app_final();
  110.  
  111. *(vu32*)0x80000020 = 0x0D15EA5E; // Magic word (how did the console boot?)
  112. *(vu32*)0x80000024 = 0x00000001; // Version (usually set to 1 by apploader)
  113. *(vu32*)0x80000028 = 0x01800000; // physical Memory Size
  114. *(vu32*)0x8000002C = 0x00000023; // Console type
  115. *(vu32*)0x80000030 = 0x00000000; // ArenaLo
  116. *(vu32*)0x80000034 = 0x9000FFC0; // ArenaHi
  117. *(vu32*)0x80000040 = 0x00000000; // Debugger present?
  118. *(vu32*)0x80000044 = 0x00000000; // Debugger Exception mask
  119. *(vu32*)0x80000048 = 0x00000000; // Exception hook destination
  120. *(vu32*)0x8000004C = 0x00000000; // Temp for LR
  121. *(vu32*)0x80000050 = 0x00000000; // padding zeros
  122. *(vu32*)0x80000060 = 0x38a00040; // Exception init
  123. *(vu32*)0x800000E4 = 0x8008f7b8; // Thread Init
  124. *(vu32*)0x800000cc = 0x00000005; // VIInit
  125. *(vu32*)0x800000F0 = 0x01800000; // Console Simulated Memory Size
  126. *(vu32*)0x800000F4 = 0x00000000; // DVD BI2 location in main memory
  127. *(vu32*)0x800000F8 = 0x0E7BE2C0; // Bus Clock Speed
  128. *(vu32*)0x800000FC = 0x2B73A840; // CPU Clock Speed
  129.  
  130. memcpy((void*)0xC0003180,(void*)0x80000000,4);
  131.  
  132. //printf("Switching to:");
  133. switch(*(vu8*)0x80000003)
  134. {
  135. case 'P':
  136. //printf("PAL60\n");
  137. *(vu32*)0x800000CC = 0x00000005;
  138. break;
  139. case 'J':
  140. case 'U':
  141. //printf("NTSC\n");
  142. *(vu32*)0x800000CC = 0x00000001;
  143. break;
  144. default:
  145. //printf("AUTO\n");
  146. *(vu32*)0x800000CC = 0x00000000;
  147. break;
  148. }
  149.  
  150. *(vu32*)0xCC003024 = 0x00000007;
  151. *(vu32*)0xC00030F0 = 0x0000001C;
  152. *(vu32*)0xC000318C = 0x00000000;
  153. *(vu32*)0xC0003190 = 0x00000000;
  154.  
  155. //sleep(10);
  156.  
  157. entrypoint();
  158.  
  159. }
Add Comment
Please, Sign In to add comment