Skip to content

Commit 0e477f7

Browse files
committed
Implement PickupsRandomizer
1 parent 8df0d1a commit 0e477f7

File tree

11 files changed

+365
-187
lines changed

11 files changed

+365
-187
lines changed

config.toml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ Patterns = [
8484
{ thread = "finalec", ped = 0, weapon = 28, allowed = ["slot"]},
8585
{ thread = "drugs1", weapon = 28, allowed = ["slot"]},
8686
{ weapon = 43, allowed = [43]},
87+
{ weapon = 44, allowed = [44, 45]},
8788
{ thread = "sweet1", weapon = 41, allowed = [41]},
8889
{ thread = "heist5", weapon = 38, allowed = ["slot"]},
8990
{ thread = "zero1", weapon = 38, allowed = ["slot"]},
@@ -96,6 +97,12 @@ Patterns = [
9697
{ thread = "casino9", weapon = 22, allowed = [22, 23, 24]}
9798
]
9899

100+
#######################################################
101+
[PickupsRandomizer]
102+
103+
Enabled = true
104+
ReplaceWithWeaponsOnly = true # Does nothing yet
105+
99106
#######################################################
100107
[ParkedCarRandomizer]
101108

@@ -114,6 +121,8 @@ Enabled = true
114121
Enabled = true
115122
MatchSubtitles = true
116123
AudioEventsFile = "data/AudioEvents.txt" # Relative to game directory
124+
ForceAudioLineEnabled = false
125+
ForceAudioLine = 0
117126

118127
#######################################################
119128
[ScriptVehicleRandomizer]

include/config.hh

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -112,14 +112,22 @@ struct HandlingConfig : public BaseConfig
112112
/*******************************************************/
113113
struct WeaponConfig : public BaseConfig
114114
{
115-
bool enabled = false;
115+
bool enabled = true;
116116
bool playerRandomization = true;
117117
bool skipChecks = false;
118118
std::vector<WeaponPattern> patterns = {};
119119

120120
void Read (std::shared_ptr<cpptoml::table> table);
121121
};
122122

123+
/*******************************************************/
124+
struct PickupsConfig : public BaseConfig
125+
{
126+
bool sameType = false;
127+
128+
void Read (std::shared_ptr<cpptoml::table> table);
129+
};
130+
123131
/*******************************************************/
124132
struct ParkedCarConfig : public BaseConfig
125133
{
@@ -139,8 +147,10 @@ struct LicensePlateConfig : public BaseConfig
139147
struct SoundsConfig : public BaseConfig
140148
{
141149

142-
bool matchSubtitles = true;
143-
std::string audioEventsFile = "data/AudioEvents.txt";
150+
bool matchSubtitles = true;
151+
std::string audioEventsFile = "data/AudioEvents.txt";
152+
bool forceAudioEnabled = false;
153+
int forceAudioID = -1;
144154

145155
void Read (std::shared_ptr<cpptoml::table> table);
146156
};
@@ -162,6 +172,7 @@ struct Configs
162172
CheatConfig cheat;
163173
HandlingConfig handling;
164174
WeaponConfig weapon;
175+
PickupsConfig pickups;
165176
ParkedCarConfig parkedCar;
166177
LicensePlateConfig licensePlate;
167178
SoundsConfig sounds;

include/config_default.hh

Lines changed: 211 additions & 183 deletions
Large diffs are not rendered by default.

include/functions.hh

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -280,6 +280,14 @@ struct CPed
280280
void *CCopPed__CCopPed (int type);
281281
};
282282

283+
struct CPickups
284+
{
285+
static int GenerateNewOne (float x, float y, float z, unsigned int modelId,
286+
char pickupType, int ammo,
287+
unsigned int moneyPerDay, char isEmpty,
288+
char *message);
289+
};
290+
283291
struct CBaseModelInfo
284292
{
285293
public:

include/pickups.hh

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
2+
#pragma once
3+
4+
class PickupsRandomizer
5+
{
6+
static PickupsRandomizer *mInstance;
7+
8+
PickupsRandomizer (){};
9+
static void DestroyInstance ();
10+
11+
public:
12+
/// Returns the static instance for PickupsRandomizer.
13+
static PickupsRandomizer *GetInstance ();
14+
15+
/// Initialises Hooks/etc.
16+
void Initialise ();
17+
};

include/weapons.hh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
struct CPed;
44

5+
int *GetWeaponInfo (int weaponId, char skill);
6+
57
class WeaponRandomizer
68
{
79
static WeaponRandomizer *mInstance;

src/config.cc

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,20 @@ ParkedCarConfig::Read (std::shared_ptr<cpptoml::table> table)
193193
CONFIG (table, randomizeRandomSpawns, "RandomizeRandomSpawns", bool);
194194
}
195195

196+
/*******************************************************/
197+
void
198+
PickupsConfig::Read (std::shared_ptr<cpptoml::table> table)
199+
{
200+
if (!table)
201+
return;
202+
203+
BaseConfig::Read (table);
204+
205+
puts ("Reading Pickups");
206+
207+
CONFIG (table, sameType, "ReplaceWithWeaponsOnly", bool);
208+
}
209+
196210
/*******************************************************/
197211
void
198212
SoundsConfig::Read (std::shared_ptr<cpptoml::table> table)
@@ -204,6 +218,8 @@ SoundsConfig::Read (std::shared_ptr<cpptoml::table> table)
204218

205219
CONFIG (table, matchSubtitles, "MatchSubtitles", bool);
206220
CONFIG (table, audioEventsFile, "AudioEventsFile", std::string);
221+
CONFIG (table, forceAudioEnabled, "ForceAudioLineEnabled", bool);
222+
CONFIG (table, forceAudioID, "ForceAudioLine", int);
207223
}
208224

209225
/*******************************************************/
@@ -278,6 +294,7 @@ ConfigManager::Initialise (const std::string &file)
278294
mConfigs.handling.Read (config->get_table ("HandlingRandomizer"));
279295
mConfigs.weapon.Read (config->get_table ("WeaponRandomizer"));
280296
mConfigs.parkedCar.Read (config->get_table ("ParkedCarRandomizer"));
297+
mConfigs.pickups.Read (config->get_table ("PickupsRandomizer"));
281298
mConfigs.licensePlate.Read (config->get_table ("LicensePlateRandomizer"));
282299
mConfigs.sounds.Read (config->get_table ("SoundsRandomizer"));
283300
mConfigs.scriptVehicle.Read (config->get_table ("ScriptVehicleRandomizer"));

src/functions.cc

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -322,6 +322,16 @@ CRunningScript::GetPointerToScriptVariable (int a2)
322322
return CallMethodAndReturn<char *, 0x464790> (this, a2);
323323
}
324324

325+
/*******************************************************/
326+
int
327+
CPickups::GenerateNewOne (float x, float y, float z, unsigned int modelId,
328+
char pickupType, int ammo, unsigned int moneyPerDay,
329+
char isEmpty, char *message)
330+
{
331+
return CallAndReturn<int, 0x456F20> (x, y, z, modelId, pickupType, ammo,
332+
moneyPerDay, isEmpty, message);
333+
}
334+
325335
/*******************************************************/
326336
void *
327337
CPool::GetAt (int handle, int size)

src/main.cc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
#include "weapons.hh"
3434
#include "config.hh"
3535
#include "autosave.hh"
36+
#include "pickups.hh"
3637

3738
///////////////////////////////////////////////
3839
// _ ____ _____ _ _ //
@@ -74,6 +75,7 @@ class Rainbomizer
7475
HandlingRandomizer::GetInstance ()->Initialise ();
7576
CheatRandomizer::GetInstance ()->Initialise ();
7677
WeaponRandomizer::GetInstance ()->Initialise ();
78+
PickupsRandomizer::GetInstance ()->Initialise ();
7779
AutoSave::GetInstance ()->Initialise ();
7880
}
7981

src/pickups.cc

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
#include "pickups.hh"
2+
#include <cstdlib>
3+
#include "logger.hh"
4+
#include "base.hh"
5+
#include "functions.hh"
6+
#include "config.hh"
7+
#include "weapons.hh"
8+
#include <injector/injector.hpp>
9+
10+
PickupsRandomizer *PickupsRandomizer::mInstance = nullptr;
11+
12+
/*******************************************************/
13+
int
14+
RandomizePickup (float x, float y, float z, unsigned int modelId,
15+
char pickupType, int ammo, unsigned int moneyPerDay,
16+
char isEmpty, char *message)
17+
{
18+
auto config = ConfigManager::GetInstance ()->GetConfigs ().pickups;
19+
20+
printf ("%05d %05d\r", modelId, ammo);
21+
if (ammo && modelId != 1212 && modelId != 367)
22+
{
23+
modelId
24+
= WeaponRandomizer::GetInstance ()->GetRandomWeapon (nullptr,
25+
0);
26+
modelId = GetWeaponInfo (modelId, 1)[3];
27+
}
28+
29+
return CPickups::GenerateNewOne (x, y, z, modelId, pickupType, ammo,
30+
moneyPerDay, isEmpty, message);
31+
}
32+
33+
/*******************************************************/
34+
void
35+
PickupsRandomizer::Initialise ()
36+
{
37+
auto config = ConfigManager::GetInstance ()->GetConfigs ().pickups;
38+
39+
if (!config.enabled)
40+
return;
41+
42+
for (int address :
43+
{0x00445098, 0x00445AFD, 0x004573C2, 0x00458A58, 0x00477983,
44+
0x0047E636, 0x480658, 0x00481744, 0x0048B243, 0x48CEB9, 0x00592103,
45+
0x005B49C6, 0x0067B6DE})
46+
{
47+
injector::MakeCALL (address, (void *) &RandomizePickup);
48+
}
49+
50+
Logger::GetLogger ()->LogMessage ("Intialised PickupsRandomizer");
51+
}
52+
53+
/*******************************************************/
54+
void
55+
PickupsRandomizer::DestroyInstance ()
56+
{
57+
if (PickupsRandomizer::mInstance)
58+
delete PickupsRandomizer::mInstance;
59+
}
60+
61+
/*******************************************************/
62+
PickupsRandomizer *
63+
PickupsRandomizer::GetInstance ()
64+
{
65+
if (!PickupsRandomizer::mInstance)
66+
{
67+
PickupsRandomizer::mInstance = new PickupsRandomizer ();
68+
atexit (&PickupsRandomizer::DestroyInstance);
69+
}
70+
return PickupsRandomizer::mInstance;
71+
}

0 commit comments

Comments
 (0)