KazoWAR

pcin.c

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