Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // ==================================================
- // VEHICLE MODEL MANAGEMENT SYSTEM
- // ==================================================
- // This system dynamically scans GTA V's memory to detect all available vehicle models.
- // Unlike hardcoded lists, this approach automatically finds vehicles by reading the game's
- // internal model pool, making it compatible with different game versions and DLCs.
- //
- // Key advantages:
- // - No manual hash lists needed
- // - Automatically detects all vehicles in memory
- // - Handles variants intelligently (Police, Armored, Racecar versions, etc.)
- // - Memory-efficient: only stores what's actually available
- // - Works with any PS3 GTA V build
- // ==================================================
- struct VehicleModel {
- Hash hash; // Model hash identifier
- char displayName[64]; // Localized display name (e.g., "Adder")
- char makeName[64]; // Vehicle manufacturer (e.g., "Truffade")
- int vehicleClass; // Vehicle class (0-21: Compacts, Sedans, Super, etc.)
- int memoryAddress; // Memory address where model was found (for debugging)
- };
- VehicleModel* g_vehicles = nullptr;
- int g_vehicleCount = 0;
- bool g_vehiclesScanned = false;
- // ==================================================
- // MEMORY ALLOCATION
- // ==================================================
- void initModels()
- {
- if (!g_vehicles)
- {
- // Allocate memory for up to 500 vehicle models
- g_vehicles = (VehicleModel*)_sys_malloc(sizeof(VehicleModel) * 500);
- if (g_vehicles)
- printf("Allocated %d bytes for vehicles\n", sizeof(VehicleModel) * 500);
- else
- printf("ERROR: Failed to allocate memory for vehicles!\n");
- }
- }
- // ==================================================
- // VEHICLE CLASS NAMES
- // ==================================================
- const char* vehicleClasses_pool[] = {
- "Compacts", // 0
- "Sedans", // 1
- "SUVs", // 2
- "Coupes", // 3
- "Muscle", // 4
- "Sports Classics", // 5
- "Sports", // 6
- "Super", // 7
- "Motorcycles", // 8
- "Off-road", // 9
- "Industrial", // 10
- "Utility", // 11
- "Vans", // 12
- "Cycles", // 13
- "Boats", // 14
- "Helicopters", // 15
- "Planes", // 16
- "Service", // 17
- "Emergency", // 18
- "Military", // 19
- "Commercial", // 20
- "Trains" // 21
- };
- // ==================================================
- // VARIANT TYPE DETECTION
- // ==================================================
- // Identifies special vehicle variants by analyzing their label names
- // Returns a descriptive string for the variant type
- const char* getVariantType(const char* labelName, Hash modelHash)
- {
- // Check for numeric suffixes (e.g., BATI2, TORNADO3)
- int len = strlen(labelName);
- if (len > 0)
- {
- char lastChar = labelName[len - 1];
- if (lastChar >= '2' && lastChar <= '9')
- return "Variant";
- }
- // Special variant keywords
- if (strstr(labelName, "RACE") != NULL) return "Racecar";
- if (strstr(labelName, "ARMOR") != NULL) return "Armored";
- if (strstr(labelName, "LIVERY") != NULL) return "Livery";
- if (strstr(labelName, "POLICE") != NULL) return "Police";
- if (strstr(labelName, "GANG") != NULL) return "Gang";
- if (strstr(labelName, "TAXI") != NULL) return "Taxi";
- if (strstr(labelName, "SHERIFF") != NULL) return "Sheriff";
- if (strstr(labelName, "LOST") != NULL) return "Lost MC";
- if (strstr(labelName, "SNOW") != NULL) return "Snow";
- if (strstr(labelName, "RUSTED") != NULL) return "Rusted";
- if (strstr(labelName, "RUSTY") != NULL) return "Rusty";
- if (strstr(labelName, "LIFEGUARD") != NULL) return "Lifeguard";
- if (strstr(labelName, "CLOWN") != NULL) return "Clown";
- if (strstr(labelName, "PARK") != NULL) return "Park Ranger";
- if (strstr(labelName, "RIOT") != NULL) return "Riot";
- // Model-specific suffixes
- if (strstr(labelName, "XL") != NULL) return "XL";
- if (strstr(labelName, "GT") != NULL) return "GT";
- if (strstr(labelName, "XS") != NULL) return "XS";
- if (strstr(labelName, "RR") != NULL) return "RR";
- if (strstr(labelName, "SWB") != NULL) return "Short Wheelbase";
- // Fallback: use passenger capacity to differentiate
- int seats = VEHICLE::_GET_VEHICLE_MODEL_MAX_NUMBER_OF_PASSENGERS(modelHash);
- static char seatsBuf[32];
- if (seats > 0 && seats < 20)
- {
- sprintf(seatsBuf, "%d-Seater", seats);
- return seatsBuf;
- }
- return "Alt";
- }
- // ==================================================
- // MAIN VEHICLE SCANNING FUNCTION
- // ==================================================
- // Scans specific memory regions where vehicle models are stored
- // Automatically detects and catalogs all available vehicles
- void scanAllVehicles()
- {
- initModels();
- if (g_vehiclesScanned)
- {
- return;
- }
- g_vehicleCount = 0;
- // Memory regions containing vehicle model data on PS3
- // Region 1: 0x40200000 - 0x40400000 (Primary vehicle models)
- // Region 2: 0x40800000 - 0x40A00000 (Additional vehicle models)
- int regions[][2] = {
- {0x40200000, 0x40400000},
- {0x40800000, 0x40A00000}
- };
- for (int r = 0; r < 2; r++)
- {
- // Scan memory in 4-byte increments (size of a Hash)
- for (int addr = regions[r][0]; addr < regions[r][1]; addr += 0x4)
- {
- Hash modelHash = *(Hash*)addr;
- // Skip null or invalid hashes
- if (modelHash == 0 || modelHash == 0xFFFFFFFF)
- continue;
- // Verify this is a valid vehicle model using game natives
- if (STREAMING::IS_MODEL_IN_CDIMAGE(modelHash) &&
- STREAMING::IS_MODEL_A_VEHICLE(modelHash))
- {
- // Get the model's label name (e.g., "ADDER", "ZENTORNO")
- const char* labelName = VEHICLE::GET_DISPLAY_NAME_FROM_VEHICLE_MODEL(modelHash);
- if (labelName && strlen(labelName) > 0 && strcmp(labelName, "CARNOTFOUND") != 0)
- {
- // Check for duplicate hashes
- bool duplicate = false;
- for (int i = 0; i < g_vehicleCount; i++)
- {
- if (g_vehicles[i].hash == modelHash)
- {
- duplicate = true;
- break;
- }
- }
- if (!duplicate && g_vehicleCount < 500)
- {
- g_vehicles[g_vehicleCount].hash = modelHash;
- // Get localized display name from game text database
- const char* fullName = UI::_GET_LABEL_TEXT((char*)labelName);
- char baseName[64];
- if (fullName && strlen(fullName) > 0 && strcmp(fullName, labelName) != 0)
- {
- strncpy(baseName, fullName, 63);
- }
- else
- {
- // Fallback to label name if localization fails
- strncpy(baseName, labelName, 63);
- }
- baseName[63] = '\0';
- // ==================================================
- // DUPLICATE NAME HANDLING WITH VARIANT DETECTION
- // ==================================================
- // Count how many vehicles with the same base name already exist
- int nameCount = 0;
- bool isVariant = false;
- for (int i = 0; i < g_vehicleCount; i++)
- {
- // Extract base name (without variant suffix)
- char existingBase[64];
- strcpy(existingBase, g_vehicles[i].displayName);
- // Remove variant suffix in parentheses
- char* paren = strstr(existingBase, " (");
- if (paren) *paren = '\0';
- // Compare base names
- if (strcmp(existingBase, baseName) == 0)
- {
- nameCount++;
- }
- }
- // Determine if this is a known variant type
- int len = strlen(labelName);
- char lastChar = (len > 0) ? labelName[len - 1] : '\0';
- if ((lastChar >= '2' && lastChar <= '9') ||
- strstr(labelName, "RACE") != NULL ||
- strstr(labelName, "ARMOR") != NULL ||
- strstr(labelName, "LIVERY") != NULL ||
- strstr(labelName, "POLICE") != NULL ||
- strstr(labelName, "GANG") != NULL)
- {
- isVariant = true;
- }
- // Build final display name
- char finalName[64];
- if (nameCount > 0)
- {
- if (isVariant)
- {
- // This is a recognized variant - add descriptive suffix
- const char* variantType = getVariantType(labelName, modelHash);
- snprintf(finalName, 63, "%s (%s)", baseName, variantType);
- }
- else
- {
- // Generic duplicate - add numeric suffix
- snprintf(finalName, 63, "%s (%d)", baseName, nameCount + 1);
- }
- }
- else
- {
- // Unique name - no suffix needed
- strcpy(finalName, baseName);
- }
- finalName[63] = '\0';
- strncpy(g_vehicles[g_vehicleCount].displayName, finalName, 63);
- g_vehicles[g_vehicleCount].displayName[63] = '\0';
- // Get vehicle class (Compacts, Sedans, Super, etc.)
- int vehClass = VEHICLE::GET_VEHICLE_CLASS_FROM_NAME(modelHash);
- if (vehClass < 0 || vehClass > 21)
- vehClass = 0; // Default to Compacts if invalid
- g_vehicles[g_vehicleCount].vehicleClass = vehClass;
- g_vehicles[g_vehicleCount].memoryAddress = addr;
- g_vehicleCount++;
- }
- }
- }
- }
- }
- g_vehiclesScanned = true;
- }
- // ==================================================
- // DEBUG: PRINT VEHICLES BY CLASS
- // ==================================================
- // Outputs a formatted list of all detected vehicles organized by class
- void printVehiclesByClass()
- {
- if (!g_vehiclesScanned || g_vehicleCount == 0)
- {
- return;
- }
- // Count vehicles per class
- int classCounts[22] = { 0 };
- for (int i = 0; i < g_vehicleCount; i++)
- {
- int classId = g_vehicles[i].vehicleClass;
- if (classId >= 0 && classId < 22)
- classCounts[classId]++;
- }
- // Print details for each class
- for (int classId = 0; classId < 22; classId++)
- {
- if (classCounts[classId] == 0)
- continue;
- for (int i = 0; i < g_vehicleCount; i++)
- {
- if (g_vehicles[i].vehicleClass == classId)
- {
- // Output: Display Name (Hash)
- }
- }
- }
- }
- // ==================================================
- // MEMORY CLEANUP
- // ==================================================
- // Frees all allocated memory for vehicle data
- void cleanupModels()
- {
- if (g_vehicles)
- {
- _sys_free(g_vehicles);
- g_vehicles = nullptr;
- g_vehicleCount = 0;
- g_vehiclesScanned = false;
- }
- }
- // ==================================================
- // MENU INTEGRATION STRUCTURES
- // ==================================================
- // Organizes vehicle data for use in the spawn menu system
- struct VehicleClassMenuInfo {
- const char** names; // Array of display names
- Hash* models; // Array of model hashes
- int count; // Number of vehicles in this class
- };
- VehicleClassMenuInfo vehicleClassesMenuInfo[22];
- bool g_menuDataReady = false;
- // ==================================================
- // PREPARE MENU DATA
- // ==================================================
- // Organizes scanned vehicles into class-specific arrays for menu display
- // This function should be called once before accessing the vehicle spawn menu
- void prepareVehicleMenuData()
- {
- if (g_menuDataReady) return;
- if (!g_vehiclesScanned) {
- scanAllVehicles();
- }
- // Count vehicles per class
- int classCounts[22] = { 0 };
- for (int i = 0; i < g_vehicleCount; i++) {
- int classId = g_vehicles[i].vehicleClass;
- if (classId >= 0 && classId < 22) {
- classCounts[classId]++;
- }
- }
- // Allocate and populate arrays for each class
- for (int classId = 0; classId < 22; classId++) {
- if (classCounts[classId] > 0) {
- // Allocate array of name pointers
- vehicleClassesMenuInfo[classId].names = (const char**)_sys_malloc(sizeof(char*) * classCounts[classId]);
- // Allocate array of model hashes
- vehicleClassesMenuInfo[classId].models = (Hash*)_sys_malloc(sizeof(Hash) * classCounts[classId]);
- vehicleClassesMenuInfo[classId].count = classCounts[classId];
- // Fill arrays with vehicle data
- int currentIndex = 0;
- for (int i = 0; i < g_vehicleCount; i++) {
- if (g_vehicles[i].vehicleClass == classId) {
- vehicleClassesMenuInfo[classId].names[currentIndex] = g_vehicles[i].displayName;
- vehicleClassesMenuInfo[classId].models[currentIndex] = g_vehicles[i].hash;
- currentIndex++;
- }
- }
- }
- else {
- // No vehicles in this class
- vehicleClassesMenuInfo[classId].names = nullptr;
- vehicleClassesMenuInfo[classId].models = nullptr;
- vehicleClassesMenuInfo[classId].count = 0;
- }
- }
- g_menuDataReady = true;
- }
- // ============================================================
- // VEHICLE POOL USAGE EXPLANATION (old version)
- // ============================================================
- //
- // The vehicle pool (created by scanAllVehicles()) contains all detected vehicle models found in the game's memory.
- //
- // Each entry includes:
- // • VehName[i] → the display name of the vehicle
- // • VehHash[i] → the model hash used to spawn it
- //
- // The following loop dynamically builds a vehicle menu
- // by adding every vehicle name as an option.
- //
- // Example:
- // for (int i = 0; i < vehPoolsz; i++)
- // addOption(VehName[i]);
- //
- // This means you don’t need to hardcode any vehicle names —
- // the menu automatically fills with every model found.
- //
- // When the player selects one of these options, the code below
- // retrieves the correct hash from the pool and spawns the vehicle:
- //
- // spawnVehicle(VehHash[index - 1]);
- //
- // In simple terms:
- // - The "vehicle pool" acts like a live database of all vehicles.
- // - The "for loop" builds the menu interface.
- // - The "spawnVehicle" call creates the selected car in the game.
- //
- // ============================================================
- // NOTE:
- // This pool can contain 300+ vehicles (especially on GTA V PS3 - 1.27/1.28),
- // so it’s recommended to load or scan it only once during game startup.
- // Doing so prevents short freezes when building the list.
- // ============================================================
- //-discord: gladeildivino
- struct VehicleModel {
- Hash hash;
- char name[64];
- };
- VehicleModel g_vehicles[500];
- int g_vehicleCount = 0;
- bool g_vehiclesScanned = false;
- // ==================================================
- // Function: scanAllVehicles()
- // Description: Scans memory regions to detect vehicle models
- // ==================================================
- void scanAllVehicles()
- {
- if (g_vehiclesScanned)
- {
- printf("Vehicles already scanned! Count: %d\n", g_vehicleCount);
- return;
- }
- printf("=== Scanning Vehicles ===\n");
- g_vehicleCount = 0;
- // Only scan the regions that contain vehicle model data
- int regions[][2] = {
- {0x40200000, 0x40400000}, // Main region (contains most vehicle data)
- {0x40800000, 0x40A00000} // Secondary region (contains most vehicle data)
- };
- for (int r = 0; r < 2; r++)
- {
- printf("Scanning region %d...\n", r + 1);
- // Step through memory, reading 4 bytes at a time
- for (int addr = regions[r][0]; addr < regions[r][1]; addr += 0x4)
- {
- Hash modelHash = *(Hash*)addr;
- // Skip invalid or empty model hashes
- if (modelHash == 0 || modelHash == 0xFFFFFFFF)
- continue;
- // Verify that this hash corresponds to a valid vehicle model
- if (STREAMING::IS_MODEL_IN_CDIMAGE(modelHash) &&
- STREAMING::IS_MODEL_A_VEHICLE(modelHash))
- {
- const char* name = VEHICLE::GET_DISPLAY_NAME_FROM_VEHICLE_MODEL(modelHash);
- // Skip if model name is invalid or placeholder
- if (name && strlen(name) > 0 && strcmp(name, "CARNOTFOUND") != 0)
- {
- bool duplicate = false;
- // Avoid adding duplicate entries
- for (int i = 0; i < g_vehicleCount; i++)
- {
- if (g_vehicles[i].hash == modelHash)
- {
- duplicate = true;
- break;
- }
- }
- // Store new vehicle entry
- if (!duplicate && g_vehicleCount < 500)
- {
- g_vehicles[g_vehicleCount].hash = modelHash;
- strncpy(g_vehicles[g_vehicleCount].name, name, 63);
- g_vehicles[g_vehicleCount].name[63] = '\0';
- g_vehicleCount++;
- }
- }
- }
- }
- }
- g_vehiclesScanned = true;
- printf("=== Scan complete! Found %d vehicles ===\n", g_vehicleCount);
- }
- This code scans game memory to collect all vehicle models currently available.
- It’s mainly for GTA V (PS3 1.27 / 1.28), but the logic applies to other platforms too.
- Just make sure to run it safely — ideally during game load or in a separate thread —
- to prevent minor lag spikes or freezes.
Add Comment
Please, Sign In to add comment