Advertisement
Anunakin

Untitled

Apr 18th, 2017
217
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.28 KB | None | 0 0
  1. static inline bool loadTitleLocaleConfig(u64 progId, u8 *regionId, u8 *languageId)
  2. {
  3.     /* Here we look for "/luma/titles/[u64 titleID in hex, uppercase]/locale.txt"
  4.        If it exists it should contain, for example, "EUR IT" */
  5.  
  6.     char path[] = "/luma/titles/0000000000000000/locale.txt";
  7.     progIdToStr(path + 28, progId);
  8.  
  9.     IFile file;
  10.  
  11.     if(!openLumaFile(&file, path)) return true;
  12.  
  13.     bool ret = false;
  14.     u64 fileSize;
  15.  
  16.     if(R_FAILED(IFile_GetSize(&file, &fileSize)) || fileSize < 6 || fileSize > 8) goto exit;
  17.  
  18.     char buf[8];
  19.     u64 total;
  20.  
  21.     if(R_FAILED(IFile_Read(&file, &total, buf, fileSize))) goto exit;
  22.  
  23.     u32 i,
  24.         j;
  25.  
  26.     for(i = 0; i < 7; i++)
  27.     {
  28.         static const char *regions[] = {"JPN", "USA", "EUR", "AUS", "CHN", "KOR", "TWN"};
  29.  
  30.         if(memcmp(buf, regions[i], 3) == 0)
  31.         {
  32.             *regionId = (u8)i;
  33.             break;
  34.         }
  35.     }
  36.  
  37.     for(j = 0; j < 12; j++)
  38.     {
  39.         static const char *languages[] = {"JP", "EN", "FR", "DE", "IT", "ES", "ZH", "KO", "NL", "PT", "RU", "TW"};
  40.  
  41.         if(memcmp(buf + 4, languages[j], 2) == 0)
  42.         {
  43.             *languageId = (u8)j;
  44.             break;
  45.         }
  46.     }
  47.  
  48.     ret = i != 7 && j != 12;
  49.  
  50. exit:
  51.     IFile_Close(&file);
  52.  
  53.     return ret;
  54. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement