Advertisement
SciresM

rsavout.c

Jan 27th, 2015
3,668
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 *fout = (void *)0x08F10000;
  10.     unsigned int addr;
  11.     int *buf = 0x18410000;
  12.     int *written = 0x08F01000;
  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(fout, L"dmc:/ramsav.bin", FILE_W);
  75.         fout->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_Write(fout, written, buf + ADJ, 0x10000);
  83.         svcSleepThread(0x400000LL);
  84.         offset += 0x10000;
  85.        
  86.         //0x70000 Bytes
  87.         for (i = 0; i < 6; i++)
  88.         {
  89.             GSPGPU_FlushDataCache(offset, 0x10000);
  90.             GX_SetTextureCopy(offset, buf, 0x10000, 0, 0, 0, 0, 8);
  91.             GSPGPU_FlushDataCache(buf, 0x10000);
  92.             svcSleepThread(0x400000LL);
  93.             IFile_Write(fout, written, buf, 0x10000);
  94.             svcSleepThread(0x400000LL);
  95.             offset += 0x10000;
  96.         }
  97.        
  98.         if (ORAS == 1)
  99.         {
  100.             GSPGPU_FlushDataCache(offset, 0x10000);
  101.             GX_SetTextureCopy(offset, buf, 0x10000, 0, 0, 0, 0, 8);
  102.             GSPGPU_FlushDataCache(buf, 0x10000);
  103.             svcSleepThread(0x400000LL);
  104.             IFile_Write(fout, written, buf, 0x10000);
  105.             svcSleepThread(0x400000LL);
  106.             offset += 0x10000;
  107.         }
  108.  
  109.         //Green - Success!
  110.         for(i = 0; i < 0xE100; i+=3)
  111.         {
  112.             buf[i] = 0x0000FF00;
  113.             buf[i+1] = 0xFF0000FF;
  114.             buf[i+2] = 0x00FF0000;
  115.         }
  116.        
  117.     }
  118.     else
  119.     {
  120.         //Red - Failure!
  121.         for (i = 0; i < 0xE100; i+=3)
  122.         {
  123.             buf[i] = 0x00FF0000;
  124.             buf[i+1] = 0x0000FF00;
  125.             buf[i+2] = 0xFF0000FF;
  126.         }
  127.     }
  128.  
  129.     GSPGPU_FlushDataCache(buf, 0x00038400);
  130.     GX_SetTextureCopy(buf, 0x1F48F000, 0x00038400, 0, 0, 0, 0, 8);
  131.     svcSleepThread(0x400000LL);
  132.     GSPGPU_FlushDataCache(buf, 0x00038400);
  133.     GX_SetTextureCopy(buf, 0x1F4C7800, 0x00038400, 0, 0, 0, 0, 8);
  134.     svcSleepThread(0x400000LL);
  135.  
  136.     return 0;
  137. }
Advertisement
Advertisement
Advertisement
RAW Paste Data Copied
Advertisement