|
| 1 | +#include <rage.hh> |
| 2 | +#include <Utils.hh> |
| 3 | +#include <CStreaming.hh> |
| 4 | + |
| 5 | +#include <common/minhook.hh> |
| 6 | +#include <common/logger.hh> |
| 7 | +#include <common/config.hh> |
| 8 | + |
| 9 | +#include <common/common.hh> |
| 10 | + |
| 11 | +class CCarGen; |
| 12 | + |
| 13 | +class CarGeneratorRandomizer |
| 14 | +{ |
| 15 | + |
| 16 | + RB_C_CONFIG_START |
| 17 | + { |
| 18 | + bool Enable = true; |
| 19 | + bool ForceOnRandomGens = false; |
| 20 | + std::string Vehicle = ""; |
| 21 | + } |
| 22 | + RB_C_CONFIG_END |
| 23 | + |
| 24 | + /*******************************************************/ |
| 25 | + static uint32_t |
| 26 | + GetRandomVehicleModel (uint32_t orig) |
| 27 | + { |
| 28 | + if (orig == 0 && !Config ().ForceOnRandomGens) |
| 29 | + return orig; |
| 30 | + |
| 31 | + if (Config ().Vehicle.size ()) |
| 32 | + return rage::atStringHash (Config ().Vehicle); |
| 33 | + |
| 34 | + return GetRandomElement (Rainbomizer::Common::GetVehicleHashes ()); |
| 35 | + } |
| 36 | + |
| 37 | + /*******************************************************/ |
| 38 | + template <auto &CCarGen__Init> |
| 39 | + static void |
| 40 | + RandomizeCarGenerator (CCarGen *p1, float x, float y, float z, float rotX, |
| 41 | + float rotY, float rotZ, uint32_t modelHash, |
| 42 | + int32_t colPrim, int32_t colSec, int32_t colTert, |
| 43 | + int32_t colQuat, int32_t col5, int32_t col6, |
| 44 | + uint32_t flags, uint32_t p14, uint64_t p15, |
| 45 | + uint64_t p16, uint64_t p17, uint32_t *vehicleGroup, |
| 46 | + uint64_t p19, uint64_t p20, uint64_t p21, |
| 47 | + uint64_t p22) |
| 48 | + { |
| 49 | +#ifdef LOG_CREATED_GENERATORS |
| 50 | + Rainbomizer::Logger::LogMessage ( |
| 51 | + "CCarGen(%p %f %f %f %f %f %f %x %x " |
| 52 | + "%x %x %x %x %x %x %x %x %x %x %x %x %x %x %x)", |
| 53 | + p1, x, y, z, rotX, rotY, rotZ, modelHash, colPrim, colSec, colTert, |
| 54 | + colQuat, col5, col6, flags, p14, p15, p16, p17, *vehicleGroup, p19, |
| 55 | + p20, p21, p22); |
| 56 | +#endif |
| 57 | + |
| 58 | + if (Config().Enable) |
| 59 | + { |
| 60 | + *vehicleGroup = 0; |
| 61 | + |
| 62 | + // Remove flags that make it spawn ambulance/firetruck/police car |
| 63 | + flags &= (~(0b11001100)); |
| 64 | + |
| 65 | + // 0 to get the engine to randomize them (still need a way to |
| 66 | + // control the randomness). |
| 67 | + |
| 68 | + // If you set the model hash directly here, the randomness |
| 69 | + // doesn't work as intended. (I'm guessing some sort of conflict |
| 70 | + // or bounds checks by the game) |
| 71 | + modelHash = 0; |
| 72 | + } |
| 73 | + |
| 74 | + return CCarGen__Init (p1, x, y, z, rotX, rotY, rotZ, modelHash, colPrim, |
| 75 | + colSec, colTert, colQuat, col5, col6, flags, p14, p15, p16, |
| 76 | + p17, vehicleGroup, p19, p20, p21, p22); |
| 77 | + } |
| 78 | + |
| 79 | +public: |
| 80 | + /*******************************************************/ |
| 81 | + CarGeneratorRandomizer () |
| 82 | + { |
| 83 | + RB_C_DO_CONFIG ("CarGeneratorRandomizer", Enable, Vehicle, ForceOnRandomGens); |
| 84 | + |
| 85 | + REGISTER_HOOK ("f3 0f 11 7c ? ? f3 0f 11 74 ? ? e8 ? ? ? ? ? 01 25 ? ? " |
| 86 | + "? ? ? 84 f6 74 ?", |
| 87 | + 12, RandomizeCarGenerator, void, CCarGen *, float, float, |
| 88 | + float, float, float, float, uint32_t, int32_t, int32_t, |
| 89 | + int32_t, int32_t, int32_t, int32_t, uint32_t, uint32_t, uint64_t, uint64_t, uint64_t, |
| 90 | + uint32_t *, uint64_t, uint64_t, uint64_t, uint64_t); |
| 91 | + } |
| 92 | +} g_CarGeneratorRandomizer; |
0 commit comments