Advertisement
SciresM

rsavin.c

Jan 27th, 2015
6,457
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include "spider.h"
  2. #include "fs.h"
  3.  
  4. 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;
  5. int (*GSPGPU_FlushDataCache)(void *addr, unsigned int len) = 0x00191504;
  6.  
  7. int uvl_entry()
  8. {
  9.     FILE *fin = (void *)0x08F10000;
  10.     unsigned int addr;
  11.     int *buf = 0x18410000;
  12.     int *read_len = 0x08F10020;
  13.     int i;
  14.     unsigned int EBUS;
  15.     unsigned int constblock;
  16.     unsigned int offset;
  17.     int j;
  18.     int ADJ;
  19.     int ORAS = 0;
  20.  
  21.     addr = 0x17900000; //Way lower than necessary, but we're going to hunt for the relative offsets of box data.
  22.  
  23.     EBUS = 0;
  24.     constblock = 0;
  25.     offset = 0;
  26.  
  27.     for (j = 0; j < 0x10 && offset == 0; j++)
  28.     {
  29.         GSPGPU_FlushDataCache(addr, 0x10000);
  30.         GX_SetTextureCopy(addr, buf, 0x10000, 0, 0, 0, 0, 8);
  31.         GSPGPU_FlushDataCache(buf, 0x10000);
  32.         svcSleepThread(0x400000LL);
  33.         for (i = 0; i < 0x4000; i++)
  34.         {
  35.             if ((buf[i] == 0x53554245 && buf[i - 1] == 0 && buf[i - 2] == 0 && buf[i - 3] == 0) && EBUS == 0)
  36.             {
  37.                 EBUS = addr + 4 * i;
  38.             }
  39.             if ((buf[i] == 0x53554245 && buf[i + 1] == 0 && buf[i + 2] == 0 && buf[i + 3] == 0) && EBUS == 0)
  40.             {
  41.                 EBUS = addr + 4 * i;
  42.             }
  43.             if ((buf[i] == 0x00000126) && (buf[i + 1] == 0x00000000) && (buf[i + 2] == 0x22018230) && (buf[i + 3] == 0x09060D30)) //Static data in save files.
  44.             {
  45.                 constblock = addr + 4 * i;
  46.             }
  47.         }
  48.         if (constblock != 0 && EBUS != 0)
  49.         {
  50.             unsigned int diff = constblock - EBUS;
  51.             if (diff == 0x38A0 || diff == 0x383C || diff == 0x3750 || diff == 0x3664 || diff == 0x3608) // ORAS
  52.             {
  53.                 offset = constblock - 0x1F7AC;
  54.                 ADJ = 0;
  55.                 ORAS = 1;
  56.             }
  57.             else if (diff == 0x37DC || diff == 0x3778 || diff == 0x368C || diff == 0x35A0) //XY
  58.             {
  59.                 offset = constblock - 0x1E6EC;
  60.                 ADJ = 1;
  61.                 ORAS = 0;
  62.             }
  63.             else //wtf
  64.             {
  65.                 offset = 0;
  66.                 ADJ = 0;
  67.             }
  68.         }
  69.         addr += 0x10000;
  70.     }
  71.  
  72.     if (offset != 0)
  73.     {
  74.         IFile_Open(fin, L"dmc:/ramsav.bin", FILE_R);
  75.         fin->pos = 0x00;
  76.  
  77.         //first 0xFFFC / 0xFFF8 byte
  78.         GSPGPU_FlushDataCache(offset, 0x10000);
  79.         GX_SetTextureCopy(offset, buf, 0x10000, 0, 0, 0, 0, 8);
  80.         GSPGPU_FlushDataCache(buf, 0x10000);
  81.         svcSleepThread(0x400000LL);
  82.         IFile_Read(fin, read_len, buf + ADJ, 0x10000);
  83.         GSPGPU_FlushDataCache(buf, 0x10000);
  84.         GX_SetTextureCopy(buf, offset, 0x10000, 0, 0, 0, 0, 8);
  85.         GSPGPU_FlushDataCache(offset, 0x10000);
  86.         svcSleepThread(0x400000LL);
  87.         offset += 0x10000;
  88.  
  89.         //0x60000 Bytes
  90.         for (i = 0; i < 6; i++)
  91.         {
  92.             IFile_Read(fin, read_len, buf, 0x10000);
  93.             GSPGPU_FlushDataCache(buf, 0x10000);
  94.             GX_SetTextureCopy(buf, offset, 0x10000, 0, 0, 0, 0, 8);
  95.             GSPGPU_FlushDataCache(offset, 0x10000);
  96.             svcSleepThread(0x400000LL);
  97.             offset += 0x10000;
  98.         }
  99.        
  100.         if (ORAS == 1)
  101.         {
  102.             IFile_Read(fin, read_len, buf, 0x10000);
  103.             GSPGPU_FlushDataCache(buf, 0x10000);
  104.             GX_SetTextureCopy(buf, offset, 0x10000, 0, 0, 0, 0, 8);
  105.             GSPGPU_FlushDataCache(offset, 0x10000);
  106.             svcSleepThread(0x400000LL);
  107.             offset += 0x10000;
  108.         }
  109.    
  110.         //Green - Success!
  111.         for (i = 0; i < 0xE100; i += 3)
  112.         {
  113.             buf[i] = 0x0000FF00;
  114.             buf[i + 1] = 0xFF0000FF;
  115.             buf[i + 2] = 0x00FF0000;
  116.         }
  117.  
  118.        
  119.     }
  120.     else
  121.     {
  122.         //Red - Failure!
  123.         for (i = 0; i < 0xE100; i+=3)
  124.         {
  125.             buf[i] = 0x00FF0000;
  126.             buf[i+1] = 0x0000FF00;
  127.             buf[i+2] = 0xFF0000FF;
  128.         }
  129.     }
  130.  
  131.     GSPGPU_FlushDataCache(buf, 0x00038400);
  132.     GX_SetTextureCopy(buf, 0x1F48F000, 0x00038400, 0, 0, 0, 0, 8);
  133.     svcSleepThread(0x400000LL);
  134.     GSPGPU_FlushDataCache(buf, 0x00038400);
  135.     GX_SetTextureCopy(buf, 0x1F4C7800, 0x00038400, 0, 0, 0, 0, 8);
  136.     svcSleepThread(0x400000LL);
  137.  
  138.     return 0;
  139. }
Advertisement
Advertisement
Advertisement
RAW Paste Data Copied
Advertisement