Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- 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
- Technical optimizations
- Avoid iterating the entire modelInfoPool every frame:
- Cache the result of CollectVehiclesByClass() in a ModelHash[] array.
- Map vehicleNamesBuffer[i] → modelHash[i] directly only once.
- Invalid hash protection: Check if modelHash is valid with IsModelValid(modelHash) before spawning.
- */
- case SpawnVehicle:
- {
- printf("[DEBUG] caseFoundViewVehicle called\n");
- uint32_t vehiclesFound = CollectVehiclesByClass(vehicleNamesBuffer, 64, iVehicleClassSelection);
- printf("[DEBUG] Vehicles found for class %d: %u\n", iVehicleClassSelection, vehiclesFound);
- addTitle("Spawn Vehicles");
- addIntOption("Vehicle Class", &iVehicleClassSelection, 0, 21);
- for (uint32_t i = 0; i < vehiclesFound; i++) {
- printf("[DEBUG] Adding vehicle option %u: %s\n", i + 1, vehicleNamesBuffer[i]);
- addOption(vehicleNamesBuffer[i]);
- }
- uint32_t selected = getOption();
- printf("[DEBUG] User selected option: %u\n", selected);
- switch (selected) {
- case 0:
- printf("[DEBUG] User chose to go back / no action\n");
- break;
- case 1:
- printf("[DEBUG] User selected option 1 (could add action here)\n");
- break;
- default:
- {
- uint32_t vehicleIndex = selected - 1;
- printf("[DEBUG] Vehicle index resolved to: %u\n", vehicleIndex);
- if (vehicleIndex >= vehiclesFound) {
- printf("[WARN] Vehicle index out of range: %u >= %u\n", vehicleIndex, vehiclesFound);
- break;
- }
- uint32_t modelHash = 0;
- uint32_t modelInfoPoolAddr = 0x1EA3A44;
- uint32_t poolSize = GetListPoolSize(modelInfoPoolAddr);
- uint32_t foundIndex = 0;
- printf("[DEBUG] Searching model pool of size: %u\n", poolSize);
- for (uint32_t i = 0; i < poolSize; i++) {
- uint32_t* elemPtr = GetListPoolElementFromIndex(modelInfoPoolAddr, i);
- if (!elemPtr) continue;
- uint32_t modelInfoAddr = *elemPtr;
- if (!modelInfoAddr) continue;
- char vehicleType = *(char*)(modelInfoAddr + 0x6B);
- if (vehicleType != 0x28) continue;
- int vehicleClass = GetClassFromVehicleInfo(modelInfoAddr);
- if (vehicleClass != iVehicleClassSelection) continue;
- if (foundIndex == vehicleIndex) {
- modelHash = *(uint32_t*)(modelInfoAddr + 0xC);
- printf("[DEBUG] Found modelHash: 0x%X for vehicle index: %u\n", modelHash, vehicleIndex);
- break;
- }
- foundIndex++;
- }
- if (modelHash == 0) {
- printf("[WARN] modelHash not found for selected vehicle\n");
- }
- else {
- printf("[DEBUG] Spawning vehicle with modelHash: 0x%X\n", modelHash);
- spawnVehicle(modelHash);
- }
- }
- break;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment