SciresM

Code.c (X/Y/OR/AS injection to box 1 slot 1)

Jan 24th, 2015
17,811
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include "spider.h"
  2.  
  3. int(*IFile_Open)(void *this, const short *path, int flags) = 0x0022FE08;
  4. int(*IFile_Read)(void *this, unsigned int *read, unsigned int *buffer, unsigned int len) = 0x001686DC;
  5. int(*IFile_Write)(void *this, unsigned int *written, void *src, unsigned int len) = 0x00168764;
  6. int (*GX_SetTextureCopy)(void *input_buffer, void *output_buffer, unsigned int size, int in_x, int in_y, int out_x, int out_y, int flags) = 0x0011DD48;
  7. int (*GSPGPU_FlushDataCache)(void *addr, unsigned int len) = 0x00191504;
  8.  
  9. int uvl_entry ()
  10. {
  11.     unsigned int addr;
  12.     void *this = 0x08F10000;
  13.     int *read_len = 0x08F10020;
  14.     int *buf = 0x18410000;
  15.     int *written = 0x08F01000;
  16.     int pkData[0x3A];
  17.     int boxData[0x3A*30];
  18.     int *HID = 0x10146000;
  19.     unsigned int keyPresses = HID[0];
  20.     int i;
  21.     IFile_Open(this, L"dmc:/pokemon.ekx", 0x1);
  22.     *((int *)this + 1) = 0x00000000; //Fseek to 0
  23.     IFile_Read(this, read_len, buf, 0xE8);
  24.     svcSleepThread(0x400000LL);
  25.    
  26.     for (i = 0;i<0x3A;i++)
  27.     {
  28.         pkData[i] = buf[i]; //Copy 0xE8 of Pokemon Data to pkData
  29.     }
  30.     unsigned int EBUS;
  31.     unsigned int constblock;
  32.     unsigned int offset;
  33.     int j;
  34.     int ADJ;
  35.    
  36.     addr = 0x17900000; //Way lower than necessary, but we're going to hunt for the relative offsets of box data.
  37.    
  38.     EBUS = 0;
  39.     constblock = 0;
  40.     offset = 0;
  41.     ADJ = 0;
  42.    
  43.     for (j=0; j<0x10 && offset == 0;j++)
  44.     {
  45.         GSPGPU_FlushDataCache(addr, 0x10000);
  46.         GX_SetTextureCopy(addr, buf, 0x10000, 0, 0, 0, 0, 8);
  47.         GSPGPU_FlushDataCache(buf, 0x10000);
  48.         svcSleepThread(0x400000LL);
  49.         for (i = 0; i < 0x4000; i++)
  50.         {
  51.             if ((buf[i] == 0x53554245 && buf[i-1] == 0 && buf[i-2] == 0 && buf[i-3] == 0) && EBUS == 0)
  52.             {
  53.                 EBUS = addr+4*i;
  54.             }
  55.             if ((buf[i] == 0x53554245 && buf[i+1] == 0 && buf[i+2] == 0 && buf[i+3] == 0) && EBUS == 0)
  56.             {
  57.                 EBUS = addr+4*i;
  58.             }
  59.             if ((buf[i] == 0x00000126) && (buf[i+1] == 0x00000000) && (buf[i+2] == 0x22018230) && (buf[i+3] == 0x09060D30)) //Static data in save files.
  60.             {
  61.                 constblock = addr+4*i;
  62.             }
  63.         }
  64.         if (constblock != 0 && EBUS != 0)
  65.         {
  66.             unsigned int diff = constblock-EBUS;
  67.             if (diff == 0x38A0 || diff == 0x383C || diff == 0x3750 || diff == 0x3664 || diff == 0x3608) // ORAS
  68.             {
  69.                 offset = constblock+0xFFE8;
  70.                 ADJ = 1;
  71.             }
  72.             else if (diff == 0x37DC|| diff == 0x3778 || diff == 0x368C || diff == 0x35A0) //XY
  73.             {
  74.                 offset = constblock+0x848;
  75.                 ADJ = 2;
  76.             }
  77.             else //wtf
  78.             {
  79.                 offset = 0;
  80.                 ADJ=0;
  81.             }
  82.         }
  83.         addr += 0x10000;
  84.     }
  85.        
  86.     if (offset != 0)
  87.     {
  88.         addr = offset;
  89.         GSPGPU_FlushDataCache(addr, 0x10000);
  90.         GX_SetTextureCopy(addr, buf, 0x10000, 0, 0, 0, 0, 8);
  91.         GSPGPU_FlushDataCache(buf, 0x10000);
  92.         svcSleepThread(0x400000LL);
  93.         svcSleepThread(0x400000LL);
  94.         for (i = 0; i < 0x3A; i++)
  95.         {
  96.             buf[i+ADJ] = pkData[i];
  97.         }
  98.     }
  99.    
  100.     IFile_Open(this, L"dmc:/injectiondebug.bin", 0x6);
  101.     *((int *)this + 1) = 0x00000000; //Fseek to 0
  102.     IFile_Write(this, written, buf, 0x10000);
  103.     svcSleepThread(0x400000LL);
  104.    
  105.     if (offset != 0)
  106.     {
  107.         svcSleepThread(0x400000LL);
  108.         GSPGPU_FlushDataCache(buf, 0x10000);
  109.         GX_SetTextureCopy(buf, addr, 0x10000, 0, 0, 0, 0, 8);
  110.         GSPGPU_FlushDataCache(addr, 0x10000);
  111.         svcSleepThread(0x400000LL);
  112.     }  
  113.  
  114.     return 0;
  115. }
RAW Paste Data