|
| 1 | +#pragma once |
| 2 | + |
| 3 | +#include <common/common.hh> |
| 4 | + |
| 5 | +#include <Utils.hh> |
| 6 | + |
| 7 | +#include <CPopulation.hh> |
| 8 | +#include <CAmbientModelSets.hh> |
| 9 | +#include <cstdint> |
| 10 | + |
| 11 | +/* Common helper class for both ped randomizer and traffic randomizer to |
| 12 | + * randomize model sets related to vehicles and peds to add more variety */ |
| 13 | +class ModelsListRandomizer |
| 14 | +{ |
| 15 | + inline static bool sm_RandomizePeds = false; |
| 16 | + inline static bool sm_RandomizeVehs = false; |
| 17 | + |
| 18 | + /*******************************************************/ |
| 19 | + template <typename T, typename T2> |
| 20 | + static void |
| 21 | + RandomizeGroup (T &array, const T2 &hashes) |
| 22 | + { |
| 23 | + for (auto &grp : array) |
| 24 | + { |
| 25 | + for (auto &model : grp.Models) |
| 26 | + model.Name = GetRandomElement (hashes); |
| 27 | + } |
| 28 | + } |
| 29 | + |
| 30 | + /*******************************************************/ |
| 31 | + static auto & |
| 32 | + GetAmbientModelSets (AmbientModelSetType id) |
| 33 | + { |
| 34 | + return CAmbientModelSetsManager::Get ()->aSets[id].ModelSets; |
| 35 | + } |
| 36 | + |
| 37 | + /*******************************************************/ |
| 38 | + template <typename T> |
| 39 | + static void |
| 40 | + RandomizeModelSet (AmbientModelSetType type, const T &hashes) |
| 41 | + { |
| 42 | + for (auto &grp : GetAmbientModelSets (type)) |
| 43 | + { |
| 44 | + for (auto &model : grp->Models) |
| 45 | + model.Name = GetRandomElement (hashes); |
| 46 | + } |
| 47 | + } |
| 48 | + |
| 49 | + /*******************************************************/ |
| 50 | + template <auto &CPopGroupList__GetVehGroup> |
| 51 | + static bool |
| 52 | + RandomizePedGroups (CPopGroupList *grps, uint32_t name, uint32_t *out) |
| 53 | + { |
| 54 | + auto &PedHashes = Rainbomizer::Common::GetPedHashes (); |
| 55 | + auto &VehHashes = Rainbomizer::Common::GetVehicleHashes (); |
| 56 | + |
| 57 | + if (sm_RandomizePeds) |
| 58 | + { |
| 59 | + RandomizeGroup (grps->pedGroups, PedHashes); |
| 60 | + RandomizeModelSet (AMBIENT_PED_MODEL_SET, PedHashes); |
| 61 | + } |
| 62 | + |
| 63 | + if (sm_RandomizeVehs) |
| 64 | + { |
| 65 | + RandomizeGroup (grps->vehGroups, VehHashes); |
| 66 | + RandomizeModelSet (AMBIENT_VEHICLE_MODEL_SET, VehHashes); |
| 67 | + } |
| 68 | + |
| 69 | + return CPopGroupList__GetVehGroup (grps, name, out); |
| 70 | + } |
| 71 | + |
| 72 | + /*******************************************************/ |
| 73 | + static void |
| 74 | + InitialiseHooks () |
| 75 | + { |
| 76 | + static bool s_Initialised = false; |
| 77 | + |
| 78 | + if (std::exchange(s_Initialised, true)) |
| 79 | + return; |
| 80 | + |
| 81 | + REGISTER_HOOK ("ba fc 76 c4 68 e8", 5, RandomizePedGroups, bool, |
| 82 | + CPopGroupList *, uint32_t, uint32_t *); |
| 83 | + } |
| 84 | + |
| 85 | +public: |
| 86 | + /*******************************************************/ |
| 87 | + static void |
| 88 | + Initialise (bool peds, bool vehs) |
| 89 | + { |
| 90 | + sm_RandomizePeds = peds ? true : sm_RandomizePeds; |
| 91 | + sm_RandomizeVehs = peds ? true : sm_RandomizeVehs; |
| 92 | + |
| 93 | + if (peds || vehs) |
| 94 | + { |
| 95 | + InitialiseHooks (); |
| 96 | + } |
| 97 | + } |
| 98 | +}; |
0 commit comments