Advertisement
ponyboy837

LittleBigPlanet 1 CFart::GetReader psuedocode

Feb 13th, 2023
1,151
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.00 KB | None | 0 0
  1. int CFart::GetReader(const CHash *const hash, SResourceReader *out) {
  2.     CellError errorCode;
  3.     u32 fileIndex = 0xFFFFFFFF;
  4.  
  5.     bool NoMutex = Mutex == NULL;
  6.     if (Mutex != NULL) {
  7.         bool SlowLockAcquired = 0;
  8.         while (1) {
  9.             errorCode = sys_lwmutex_lock(Mutex.cs, &sub_1E8480);
  10.             bool AcquiringLock = SlowLockAcquired == 0;
  11.             if (errorCode != CELL_ETIMEDOUT) {
  12.                 break;
  13.             }
  14.             while (AcquiringLock) {
  15.                 SlowLockAcquired = 1;
  16.                 printf("delay acquiring mutex '%s' %08x retval = %08x\n", Mutex.Name, Mutex.cs.sleep_queue, CELL_ETIMEDOUT);
  17.                 errorCode = sys_lwmutex_lock(Mutex.cs, &sub_1E8480);
  18.                 AcquiringLock = 0;
  19.                 if (errorCode != CELL_ETIMEDOUT) {
  20.                     goto LockCheck;
  21.                 }
  22.             }
  23.         }
  24. LockCheck:
  25.         if (!errorCode) {
  26.             int DEBUGIsLocked = Mutex.DEBUGIsLocked;
  27.             Mutex.LockLine = 0;
  28.             Mutex.LockFile = 0;
  29.             Mutex.DEBUGIsLocked = DEBUGIsLocked + 1;
  30.             fileIndex = CFart::FindFileByHash(this, hash);
  31.             if (fileIndex != 0xFFFFFFFF) {
  32.                 goto OpenCachedHandle;
  33.             }
  34.             // Close the mutex if we have it.
  35.             if (!NoMutex) {
  36.                 --Mutex.DEBUGIsLocked;
  37.                 sys_lwmutex_unlock(Mutex.cs);
  38.             }
  39.             // Return our failure..
  40.             return 0;
  41.         }
  42.     }
  43.     fileIndex = CFart::FindFileByHash(this, hash);
  44.     if (fileIndex == 0xFFFFFFFF) {
  45.         // Close the mutex if we have it.
  46.         if (!NoMutex) {
  47.             --Mutex.DEBUGIsLocked;
  48.             sys_lwmutex_unlock(Mutex.cs);
  49.         }
  50.         // Return our failure..
  51.         return 0;
  52.     }
  53. OpenCachedHandle:
  54.     FileHandle cacheHandle = fd_read_cache;
  55.     if (cacheHandle != 0xFFFFFFFF) {
  56.         out->Handle = cacheHandle;
  57.         fd_read_cache = 0xFFFFFFFF;
  58. OpenHandle:
  59.         FileSeek(out->Handle, FAT.Data[fileIndex].Offset, 0LL);
  60.         ++FAT.Data[fileIndex].Lock;
  61.         out->Size = FAT.Data[fileIndex].Size;
  62.         out->Offset = FAT.Data[fileIndex].Offset;
  63.         out->Owner = this;
  64.         out->OwnerData = fileIndex;
  65.         // Copy the passed hash as our original hash.
  66.         memcpy(out->OriginalHash.Bytes, hash->Bytes, sizeof(CHash))
  67.         // Reset our rolling hash to its default state.
  68.         CSHA1Context::Reset(out->RollingHash);
  69.        
  70.         // Close the mutex if we have it.
  71.         if (!NoMutex) {
  72.             --Mutex.DEBUGIsLocked;
  73.             sys_lwmutex_unlock(Mutex.cs);
  74.         }
  75.         // Return our success!
  76.         return 1;
  77.     }
  78.     if (FileOpen(FullPath, out->Handle, OPEN_READ)) {
  79.         goto OpenHandle;
  80.     }
  81.    
  82.     // We failed to open the file and read it.
  83.  
  84.     // Close the mutex if we have it.
  85.     if (!NoMutex) {
  86.         --Mutex.DEBUGIsLocked;
  87.         sys_lwmutex_unlock(Mutex.cs);
  88.     }
  89.     // Return our failure..
  90.     return 0;
  91. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement