IlDivinoGlade

GTA V PS3 - Vehicle Spawner by pool

Jul 17th, 2025 (edited)
321
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.10 KB | None | 0 0
  1. /*
  2. The function you're looking at was originally created by a developer who made a mod menu called "African" aka "NiNjA" on Xbox. I made some modifications to make this pool (which saves a lot of memory) work on PS3. I haven’t tested it due to lack of time — there are probably some grammatical and programming errors. If it works, enjoy it. If it doesn’t, make it work. Note: this would also be very useful on GTA V PC (makes even more sense there since new vehicles are added sometimes) and on PS4 (for those creating mod menus for servers). Feel free to contact me on Discordo: gladeildivino
  3.  
  4.  
  5. Technical optimizations
  6. Avoid iterating the entire modelInfoPool every frame:
  7.  
  8. Cache the result of CollectVehiclesByClass() in a ModelHash[] array.
  9.  
  10. Map vehicleNamesBuffer[i] → modelHash[i] directly only once.
  11.  
  12. Invalid hash protection: Check if modelHash is valid with IsModelValid(modelHash) before spawning.
  13. */
  14.  
  15.  
  16. case SpawnVehicle:
  17. {
  18.     printf("[DEBUG] caseFoundViewVehicle called\n");
  19.  
  20.     uint32_t vehiclesFound = CollectVehiclesByClass(vehicleNamesBuffer, 64, iVehicleClassSelection);
  21.     printf("[DEBUG] Vehicles found for class %d: %u\n", iVehicleClassSelection, vehiclesFound);
  22.  
  23.     addTitle("Spawn Vehicles");
  24.     addIntOption("Vehicle Class", &iVehicleClassSelection, 0, 21);
  25.  
  26.     for (uint32_t i = 0; i < vehiclesFound; i++) {
  27.         printf("[DEBUG] Adding vehicle option %u: %s\n", i + 1, vehicleNamesBuffer[i]);
  28.         addOption(vehicleNamesBuffer[i]);
  29.     }
  30.  
  31.     uint32_t selected = getOption();
  32.     printf("[DEBUG] User selected option: %u\n", selected);
  33.  
  34.     switch (selected) {
  35.     case 0:
  36.         printf("[DEBUG] User chose to go back / no action\n");
  37.         break;
  38.  
  39.     case 1:
  40.         printf("[DEBUG] User selected option 1 (could add action here)\n");
  41.         break;
  42.  
  43.     default:
  44.     {
  45.         uint32_t vehicleIndex = selected - 1;
  46.         printf("[DEBUG] Vehicle index resolved to: %u\n", vehicleIndex);
  47.  
  48.         if (vehicleIndex >= vehiclesFound) {
  49.             printf("[WARN] Vehicle index out of range: %u >= %u\n", vehicleIndex, vehiclesFound);
  50.             break;
  51.         }
  52.  
  53.         uint32_t modelHash = 0;
  54.         uint32_t modelInfoPoolAddr = 0x1EA3A44;
  55.         uint32_t poolSize = GetListPoolSize(modelInfoPoolAddr);
  56.         uint32_t foundIndex = 0;
  57.  
  58.         printf("[DEBUG] Searching model pool of size: %u\n", poolSize);
  59.  
  60.         for (uint32_t i = 0; i < poolSize; i++) {
  61.             uint32_t* elemPtr = GetListPoolElementFromIndex(modelInfoPoolAddr, i);
  62.             if (!elemPtr) continue;
  63.  
  64.             uint32_t modelInfoAddr = *elemPtr;
  65.             if (!modelInfoAddr) continue;
  66.  
  67.             char vehicleType = *(char*)(modelInfoAddr + 0x6B);
  68.             if (vehicleType != 0x28) continue;
  69.  
  70.             int vehicleClass = GetClassFromVehicleInfo(modelInfoAddr);
  71.             if (vehicleClass != iVehicleClassSelection) continue;
  72.  
  73.             if (foundIndex == vehicleIndex) {
  74.                 modelHash = *(uint32_t*)(modelInfoAddr + 0xC);
  75.                 printf("[DEBUG] Found modelHash: 0x%X for vehicle index: %u\n", modelHash, vehicleIndex);
  76.                 break;
  77.             }
  78.             foundIndex++;
  79.         }
  80.  
  81.         if (modelHash == 0) {
  82.             printf("[WARN] modelHash not found for selected vehicle\n");
  83.         }
  84.         else {
  85.             printf("[DEBUG] Spawning vehicle with modelHash: 0x%X\n", modelHash);
  86.             spawnVehicle(modelHash);
  87.         }
  88.     }
  89.     break;
  90.     }
  91. }
Advertisement
Add Comment
Please, Sign In to add comment