Skip to content

Commit

Permalink
Ped Randomizer: Randomize Ambient Model Sets for more variety
Browse files Browse the repository at this point in the history
  • Loading branch information
Parik27 committed Jul 29, 2021
1 parent dd049f1 commit 78a4f66
Show file tree
Hide file tree
Showing 8 changed files with 79 additions and 5 deletions.
2 changes: 1 addition & 1 deletion build-count.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
470
471
9 changes: 9 additions & 0 deletions lib/CAmbientModelSets.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#include "CAmbientModelSets.hh"
#include "Utils.hh"

void
CAmbientModelSetsManager::InitialisePatterns ()
{
sm_Instance = GetRelativeReference<CAmbientModelSetsManager *> (
"? 8b 0d ? ? ? ? ? 8b c3 8b d0 e8 ? ? ? ?", 3, 7);
}
51 changes: 51 additions & 0 deletions lib/CAmbientModelSets.hh
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
#pragma once

#include <cstdint>
#include <rage.hh>

enum AmbientModelSetType
{
AMBIENT_PED_MODEL_SET = 0,
AMBIENT_PROP_MODEL_SET,
AMBIENT_VEHICLE_MODEL_SET
};

struct CAmbientModel
{
uint32_t Name;
uint32_t field_0x4;
void * Variations;
float Probability;
uint32_t field_0x14;
};

struct CAmbientModelSet
{
void * vft;
uint32_t Name;
uint32_t field_0xc;
struct atArray<CAmbientModel> Models;
uint32_t field_0x1c;
};

struct CAmbientModelSets
{
atArray<CAmbientModelSet *> ModelSets;
uint8_t field_0xc[28];
};

struct CAmbientModelSetsManager
{
uint8_t field_0x0[16];
struct CAmbientModelSets aSets[3];

inline static CAmbientModelSetsManager **sm_Instance;

static CAmbientModelSetsManager *
Get ()
{
return *sm_Instance;
}

static void InitialisePatterns ();
};
2 changes: 2 additions & 0 deletions lib/Utils.cc
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
#include "CTask.hh"
#include "CModelIndices.hh"
#include "CCredits.hh"
#include "CAmbientModelSets.hh"

#include "Utils.hh"

Expand Down Expand Up @@ -133,6 +134,7 @@ InitialiseAllComponents ()
aiTask::InitialisePatterns ();
CModelIndices::InitialisePatterns ();
CCreditArray::InitialisePatterns ();
CAmbientModelSetsManager::InitialisePatterns ();

#ifndef NO_PARSER_UTILS
ParserUtils::Register ();
Expand Down
2 changes: 1 addition & 1 deletion src/mission/missions_PlayerSwitch.cc
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ MissionRandomizer_PlayerSwitcher::CheckCurrentPlayer (ePlayerIndex index)
== int (eCharacter::_))
{
uint32_t hash = 0;
auto *playerModel = PedRandomizerCompatibility::GetOriginalModel (
auto *playerModel = PedRandomizer_Compatibility::GetOriginalModel (
CPedFactory::Get ()->pPlayer);

switch (index)
Expand Down
2 changes: 1 addition & 1 deletion src/peds/peds_AnimalFixes.hh
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class PedRandomizer_AnimalFixes
static aiTask *FixFallingPeds (CPed *_this, CPed *ped,
bool *spawningPreference);

void FixLadderClimbAsAnimal ();
static void FixLadderClimbAsAnimal ();

public:
static void Initialise ();
Expand Down
4 changes: 2 additions & 2 deletions src/peds/peds_PlayerFixes.hh
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ class PedRandomizer_PlayerFixes
CorrectPlayerObjIdx (CutSceneManager *mgr)
{
CPed * player = CPedFactory::Get ()->pPlayer;
CBaseModelInfo *model = PedRandomizerCompatibility::GetOriginalModel (
CBaseModelInfo *model = PedRandomizer_Compatibility::GetOriginalModel (
CPedFactory::Get ()->pPlayer);

// Restore original model for this function and change it back after
Expand Down Expand Up @@ -179,7 +179,7 @@ class PedRandomizer_PlayerFixes
{
CPlayerPedSaveStructure__PreSave (save);

uint32_t origHash = PedRandomizerCompatibility::GetOriginalModel (
uint32_t origHash = PedRandomizer_Compatibility::GetOriginalModel (
CPedFactory::Get ()->pPlayer)
->m_nHash;

Expand Down
12 changes: 12 additions & 0 deletions src/peds/peds_Streaming.hh
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

#include <rage.hh>
#include <CPopulation.hh>
#include <CAmbientModelSets.hh>

#include <ctime>

Expand Down Expand Up @@ -125,12 +126,23 @@ class PedRandomizer_Streaming
RandomizePedGroups (CPopGroupList *grps, uint32_t name, uint32_t *out)
{
auto &PedHashes = Rainbomizer::Common::GetPedHashes ();

// Pop Groups
for (auto &grp : grps->pedGroups)
{
for (auto &model : grp.models)
model.Name = GetRandomElement (PedHashes);
}

// Ambient Model Sets (used for Scenarios)
for (auto &models : CAmbientModelSetsManager::Get ()
->aSets[AMBIENT_PED_MODEL_SET]
.ModelSets)
{
for (auto &model : models->Models)
model.Name = GetRandomElement (PedHashes);
}

return CPopGroupList__GetVehGroup (grps, name, out);
}

Expand Down

0 comments on commit 78a4f66

Please sign in to comment.