Advertisement
fastman92

LoadCDdirectoryItem

Jul 21st, 2015
292
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.81 KB | None | 0 0
  1.     // Loads CD directory item and returns file ID
  2.     __int32 __cdecl LoadCDdirectoryItem(const CDirectoryEntryExtended& entry, int imgId)
  3.     {      
  4.         // return UNDEFINED_FILE_ID_INT32;
  5.  
  6.         CDirectoryEntryExtended xEntry = entry;
  7.  
  8.         char* pDot = strchr(xEntry.Name, '.');
  9.  
  10.         if (!pDot)
  11.             return UNDEFINED_FILE_ID_INT32;
  12.  
  13.         *pDot = NULL;
  14.  
  15.         const char* pExtension = pDot + 1;
  16.  
  17.         if (strlen(pExtension) < 3)
  18.             return UNDEFINED_FILE_ID_INT32;
  19.  
  20.         const char* name = xEntry.Name;
  21.  
  22.         __int32 fileIndex;
  23.  
  24.         // printf("filename: %s", entry->Filename);
  25.  
  26.        
  27.         if (!memicmp(pExtension, "DFF", 3))
  28.         {
  29.             if (!CModelInfo::GetModelInfo(name, &fileIndex))
  30.             {
  31.                 xEntry.PositionInSectors |= imgId << 24;
  32.                
  33.                 // CDirectoryEntry convertedEntry;
  34.                 // convertedEntry.SetDataBasedOnExtendedEntry(xEntry);
  35.  
  36.                 /*
  37.                 printf_MessageBox(
  38.                     "entry details\n"
  39.                     "name: %s\n"
  40.                     "pos: 0x%X\n"
  41.                     "size priority2: %d\n"
  42.                     "size priority1: %d\n"
  43.                     ,
  44.                     convertedEntry.Filename,
  45.                     (int)(entry.PositionInSectors & 0xFFFFFF)  * IMG_ARCHIVE_SECTOR_SIZE,
  46.                     (int)convertedEntry.sizePriority2 * IMG_ARCHIVE_SECTOR_SIZE,
  47.                     (int)convertedEntry.sizePriority1 * IMG_ARCHIVE_SECTOR_SIZE
  48.                     );
  49.                 */
  50.  
  51.                 CStreaming::ms_pExtraObjectsDir->AddItem(xEntry);
  52.  
  53.                 return UNDEFINED_FILE_ID_INT32;
  54.             }
  55.             else
  56.                 return fileIndex;
  57.         }      
  58.         else if (!memicmp(pExtension, "TXD", 3))
  59.         {
  60.             // CGenericLogStorage::SaveFormattedTextLn("TXD name: %s", name);
  61.  
  62.             int TXDslot =
  63.                 ((int(__cdecl *)(const char *))0x731850)(
  64.                 name
  65.                 );      // CTxdStore::FindTxdSlot
  66.  
  67.             if (TXDslot == -1)
  68.             {
  69.                 TXDslot = ((int(__cdecl *)(const char *))0x731C80)(
  70.                     name
  71.                     );      // CTxdStore::AddTxdSlot
  72.  
  73.                 ((void(__cdecl *)(const char *, int))0x4C9360)(
  74.                     name,
  75.                     TXDslot
  76.                     );      // set paintjobs for vehicle model.
  77.             }
  78.  
  79.             // printf_MessageBox("returned file ID: %d", TXDslot + ModelIDlimit::GetBaseID(FILE_TYPE_TXD));
  80.  
  81.             return TXDslot + ModelIDlimit::GetBaseID(FILE_TYPE_TXD);               
  82.         }              
  83.         else if (!memicmp(pExtension, "COL", 3))
  84.         {          
  85.             int COLslot =
  86.                 ((int(__cdecl *)(const char *))0x410390)(
  87.                     name
  88.                 );      // CColStore::FindColSlot          
  89.  
  90.             if (COLslot == -1)
  91.                 COLslot = ((int(__cdecl *)(const char *))0x411140)(
  92.                     name
  93.                 );      // CColStore::AddColSlot
  94.            
  95.             return COLslot + ModelIDlimit::GetBaseID(FILE_TYPE_COL);
  96.            
  97.         }      
  98.        
  99.         else if (!memicmp(pExtension, "IPL", 3))
  100.         {
  101.             int IPLslot =
  102.                 ((int(__cdecl *)(const char *))0x404AC0)(
  103.                     name
  104.                 );      // CIplStore::FindIplSlot
  105.  
  106.             if (IPLslot == -1)
  107.                 IPLslot = ((int(__cdecl *)(const char *))0x405AC0)(
  108.                     name
  109.                 );      // CIplStore::AddIplSlot
  110.  
  111.             return IPLslot + ModelIDlimit::GetBaseID(FILE_TYPE_IPL);
  112.  
  113.         }      
  114.  
  115.        
  116.         else if (!memicmp(pExtension, "DAT", 3))
  117.         {
  118.             int DATslot = 0xCCCCCCCC;
  119.             sscanf(name + 5, "%d", &DATslot);
  120.  
  121.             return DATslot + ModelIDlimit::GetBaseID(FILE_TYPE_DAT);
  122.         }      
  123.         else if (!memicmp(pExtension, "IFP", 3))
  124.         {
  125.             int IFPslot = ((int(__cdecl *)(const char *))0x4D3E50)(
  126.                     name
  127.                 );      // CAnimManager::RegisterAnimBlock
  128.  
  129.             return IFPslot + ModelIDlimit::GetBaseID(FILE_TYPE_IFP);
  130.         }
  131.         if (!memicmp(pExtension, "RRR", 3))
  132.         {
  133.             int RRRslot = ((int(__cdecl *)(const char *))0x459F80)(
  134.                     name
  135.                 );      // CVehicleRecording::RegisterRecordingFile
  136.  
  137.             return RRRslot + ModelIDlimit::GetBaseID(FILE_TYPE_RRR);
  138.         }
  139.         else if (!memicmp(pExtension, "SCM", 3))
  140.         {
  141.             int SCMslot = ((int(__thiscall *)(char*, const char *))0x4706C0)(
  142.                 ModelIDlimit::CTheScripts__StreamedScripts,
  143.                     name
  144.                 );      // CStreamedScripts::RegisterScript
  145.  
  146.             return SCMslot + ModelIDlimit::GetBaseID(FILE_TYPE_SCM);
  147.         }
  148.        
  149.         else
  150.         {
  151.             // printf_MessageBox("filename: %s unknown extension: %s", entry.Filename, pExtension);
  152.             return UNDEFINED_FILE_ID_INT32;
  153.         }              
  154.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement