Skip to content

Commit 4679d93

Browse files
committed
Vehicle Appearance Randomizer: Add vehicle-upgrades randomization
* Renamed ColourRandomizer to HudRandomizer. * Moved Vehicle Colour Randomizer to VehicleAppearanceRandomizer. * Updated config debug interface to remove temporary variables and update it to group effects by table name.
1 parent 5a1e110 commit 4679d93

File tree

10 files changed

+304
-128
lines changed

10 files changed

+304
-128
lines changed

build-count.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
520
1+
524

config.toml

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,8 @@ RainbomizerCredits = true
2626

2727
TrafficRandomizer = true
2828
DispatchRandomizer = true
29-
ColourRandomizer = true
29+
HudRandomizer = true
30+
VehicleAppearanceRandomizer = true
3031
WeaponRandomizer = true
3132
WeaponStatsRandomizer = true
3233
CutSceneRandomizer = true
@@ -126,10 +127,14 @@ EnableHelis = true
126127
EnableBoats = true # Don't be a boat hater, keep this enabled :wink:
127128

128129
#######################################################
129-
[ColourRandomizer]
130+
[VehicleAppearanceRandomizer]
130131

131-
RandomizeHudColours = true
132132
RandomizeCarColours = true
133+
RandomizeCarUpgrades = true
134+
135+
# Value of 50 = 50% of cars will have random horn/armour
136+
RandomizeHornOdds = 45
137+
RandomizeArmourOdds = 45
133138

134139
#######################################################
135140
[ScriptVehicleRandomizer]

lib/CTheScripts.cc

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,13 @@
33
#include "Utils.hh"
44
#include "NativeTranslationTable.hh"
55
#include "common/events.hh"
6+
#include <cstdint>
67
#include <memory>
78

89
#include <windows.h>
910

1011
CEntity *(*fwScriptGuid_GetBaseFromGuid) (uint32_t) = nullptr;
12+
uint32_t (*fwScriptGuid_CreateGuid) (CEntity *) = nullptr;
1113

1214
/*******************************************************/
1315
std::unique_ptr<NativeManager::NativeFunc[]>
@@ -177,10 +179,22 @@ CTheScripts::InitialisePatterns ()
177179
"83 f9 ff 74 ? ? 8b 0d ? ? ? ? 44 8b c1 ? 8b"),
178180
fwScriptGuid_GetBaseFromGuid);
179181

182+
ConvertCall (hook::get_pattern (
183+
"48 F7 F9 49 8B 48 08 48 63 D0 C1 E0 08 0F B6 1C 11 03 D8",
184+
-0x68),
185+
fwScriptGuid_CreateGuid);
186+
180187
Rainbomizer::Events ().OnInit +=
181188
[] (bool) { NativeManager::Initialise (); };
182189
}
183190

191+
/*******************************************************/
192+
uint32_t
193+
fwScriptGuid::CreateGuid (CEntity *entity)
194+
{
195+
return fwScriptGuid_CreateGuid (entity);
196+
}
197+
184198
/*******************************************************/
185199
CEntity *
186200
fwScriptGuid::GetBaseFromGuid (uint32_t guid)

lib/CTheScripts.hh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ class fwScriptGuid
2020
{
2121
public:
2222
static CEntity *GetBaseFromGuid (uint32_t guid);
23+
24+
static uint32_t CreateGuid (CEntity *entity);
2325
};
2426

2527
/* Utility Classes */

src/colours/colours.cc

Lines changed: 15 additions & 107 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,21 @@
1-
#include <CHud.hh>
1+
#include <map>
2+
#include <cstdint>
3+
24
#include <Utils.hh>
3-
#include "CARGB.hh"
4-
#include "common/config.hh"
5-
#include "HSL.hh"
5+
6+
#include <HSL.hh>
7+
#include <CHud.hh>
8+
#include <CARGB.hh>
9+
610
#include "common/logger.hh"
7-
#include <CVehicle.hh>
8-
#include <cstdint>
9-
#include <map>
10-
#include <stdexcept>
1111
#include "common/events.hh"
12-
#include <common/minhook.hh>
12+
#include "common/config.hh"
1313

1414
void (*CHud__SetHudColour) (int, int, int, int, int);
15-
uint32_t (*CCustomShaderEffectVehicle_SetForVehicle_134) (
16-
CCustomShaderEffectVehicle *, CVehicle *);
1715

18-
class ColoursRandomizer
16+
class HudRandomizer
1917
{
20-
struct VehicleColourData
21-
{
22-
CARGB OriginalColours[4];
23-
CARGB RandomColours[4];
24-
};
25-
26-
inline static std::map<CVehicle *, VehicleColourData> mColourData;
27-
inline static std::map<uint32_t, CARGB> mHudCols;
28-
29-
RB_C_CONFIG_START
30-
{
31-
bool RandomizeHudColours = true;
32-
bool RandomizeCarColours = true;
33-
}
34-
RB_C_CONFIG_END
18+
inline static std::map<uint32_t, CARGB> mHudCols;
3519

3620
/*******************************************************/
3721
static void
@@ -52,59 +36,6 @@ class ColoursRandomizer
5236
CHud__SetHudColour (index, newColour.r, newColour.g, newColour.b, a);
5337
}
5438

55-
/*******************************************************/
56-
static void
57-
RestoreVehicleColourData (CCustomShaderEffectVehicle *shader, CVehicle *veh)
58-
{
59-
if (auto *data = LookupMap (mColourData, veh))
60-
{
61-
CARGB *colours = shader->GetColours ();
62-
63-
for (int i = 0; i < 4; i++)
64-
colours[i] = data->OriginalColours[i];
65-
}
66-
}
67-
68-
/*******************************************************/
69-
static bool
70-
StoreVehicleColourData (CCustomShaderEffectVehicle *shader, CVehicle *veh)
71-
{
72-
auto & data = mColourData[veh];
73-
CARGB *colours = shader->GetColours ();
74-
75-
bool changed = false;
76-
for (int i = 0; i < 4; i++)
77-
if (std::exchange (data.OriginalColours[i], colours[i])
78-
!= colours[i])
79-
changed = true;
80-
81-
return changed;
82-
}
83-
84-
/*******************************************************/
85-
static uint32_t
86-
RandomizeVehicleColour (CCustomShaderEffectVehicle *shader, CVehicle *veh)
87-
{
88-
RestoreVehicleColourData (shader, veh);
89-
90-
uint32_t ret
91-
= CCustomShaderEffectVehicle_SetForVehicle_134 (shader, veh);
92-
CARGB *colours = shader->GetColours ();
93-
94-
if (StoreVehicleColourData (shader, veh))
95-
{
96-
using Rainbomizer::HSL;
97-
for (int i = 0; i < 4; i++)
98-
mColourData[veh].RandomColours[i]
99-
= HSL (RandomFloat (360.0f), 1.0f, RandomFloat (1.0f));
100-
}
101-
102-
for (int i = 0; i < 4; i++)
103-
colours[i] = mColourData[veh].RandomColours[i];
104-
105-
return ret;
106-
}
107-
10839
/*******************************************************/
10940
static void
11041
RandomizeOnFade ()
@@ -113,41 +44,18 @@ class ColoursRandomizer
11344
SetNewHudColour (idx, col.r, col.g, col.b, col.a);
11445
}
11546

116-
/*******************************************************/
117-
void
118-
InitialiseCarColourHooks ()
119-
{
120-
MinHookWrapper::HookBranchDestination (
121-
"85 c9 74 ? ? 8b d3 e8 ? ? ? ? 84 c0 74 ? ? 84 ff 74", 7,
122-
CCustomShaderEffectVehicle_SetForVehicle_134,
123-
RandomizeVehicleColour);
124-
}
125-
12647
public:
12748
/*******************************************************/
128-
ColoursRandomizer ()
49+
HudRandomizer ()
12950
{
130-
if (!ConfigManager ::ReadConfig (
131-
"ColourRandomizer",
132-
std::make_pair ("RandomizeHudColours",
133-
&Config ().RandomizeHudColours),
134-
std::make_pair ("RandomizeCarColours",
135-
&Config ().RandomizeCarColours)))
51+
if (!ConfigManager::ReadConfig ("HudRandomizer"))
13652
return;
137-
;
13853

13954
InitialiseAllComponents ();
14055

14156
// Hud Colours
142-
// ----------
143-
if (Config ().RandomizeHudColours)
144-
RegisterHook ("8b ? ? ? ? ? 8b ? ? ? ? ? 8b cb 89 44 ? ? e8", 18,
145-
CHud__SetHudColour, SetNewHudColour);
146-
147-
// Car Colours
148-
// ---------
149-
if (Config ().RandomizeCarColours)
150-
InitialiseCarColourHooks ();
57+
RegisterHook ("8b ? ? ? ? ? 8b ? ? ? ? ? 8b cb 89 44 ? ? e8", 18,
58+
CHud__SetHudColour, SetNewHudColour);
15159

15260
Rainbomizer::Events ().OnFade += RandomizeOnFade;
15361
}

src/common/config.cc

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -96,8 +96,8 @@ ConfigManager::GetIsEnabled (const std::string &name)
9696
// Enabled key takes precedence over main table key.
9797

9898
bool enabled = true;
99-
ReadValue ("Randomizers", name, enabled);
100-
ReadValue (name, "Enabled", enabled);
99+
ReadValue ("Randomizers", name, enabled, true);
100+
ReadValue (name, "Enabled", enabled, true);
101101

102102
Rainbomizer::Logger::LogMessage ("%s: %s", name.c_str (),
103103
(enabled) ? "Yes" : "No");
@@ -108,7 +108,7 @@ ConfigManager::GetIsEnabled (const std::string &name)
108108
template <typename T>
109109
void
110110
ConfigManager::ReadValue (const std::string &tableName, const std::string &key,
111-
T &out)
111+
T &out, bool tmp)
112112
{
113113
auto table = m_pConfig->get_table (tableName);
114114
auto defTable = m_pDefaultConfig->get_table (tableName);
@@ -137,13 +137,15 @@ ConfigManager::ReadValue (const std::string &tableName, const std::string &key,
137137
#endif
138138

139139
#ifdef ENABLE_DEBUG_MENU
140-
ConfigDebugInterface::AddConfigOption (tableName + '.' + key, &out);
140+
if (!tmp)
141+
ConfigDebugInterface::AddConfigOption (tableName, key, &out);
141142
#endif
142143
}
143144

144145
#define READ_VALUE_ADD_TYPE(type) \
145-
template void ConfigManager::ReadValue<type> ( \
146-
const std::string &tableName, const std::string &key, type &out);
146+
template void ConfigManager::ReadValue<type> (const std::string &, \
147+
const std::string &, type &, \
148+
bool);
147149

148150
READ_VALUE_ADD_TYPE (bool)
149151
READ_VALUE_ADD_TYPE (int)

src/common/config.hh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ class ConfigManager
2222

2323
template <typename T>
2424
void ReadValue (const std::string &tableName, const std::string &key,
25-
T &out);
25+
T &out, bool tmp = false);
2626

2727
bool GetIsEnabled (const std::string &name);
2828

src/common/configDefault.hh

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,8 @@ RainbomizerCredits = true
2727
2828
TrafficRandomizer = true
2929
DispatchRandomizer = true
30-
ColourRandomizer = true
30+
HudRandomizer = true
31+
VehicleAppearanceRandomizer = true
3132
WeaponRandomizer = true
3233
WeaponStatsRandomizer = true
3334
CutSceneRandomizer = true
@@ -127,10 +128,14 @@ EnableHelis = true
127128
EnableBoats = true # Don't be a boat hater, keep this enabled :wink:
128129
129130
#######################################################
130-
[ColourRandomizer]
131+
[VehicleAppearanceRandomizer]
131132
132-
RandomizeHudColours = true
133133
RandomizeCarColours = true
134+
RandomizeCarUpgrades = true
135+
136+
# Value of 50 = 50% of cars will have random horn/armour
137+
RandomizeHornOdds = 45
138+
RandomizeArmourOdds = 45
134139
135140
#######################################################
136141
[ScriptVehicleRandomizer]

src/debug/config.hh

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,22 +11,23 @@
1111
class ConfigDebugInterface : public DebugInterface
1212
{
1313
public:
14-
using Type = std::variant<int *, std::string *, bool *, double *>;
14+
using Type = std::variant<int *, std::string *, bool *, double *>;
15+
using ConfigGroup = std::map<std::string, Type>;
1516

1617
private:
1718
static auto &
1819
GetConfigOptions ()
1920
{
20-
static std::map<std::string, Type> sm_ConfigOptions;
21-
return sm_ConfigOptions;
21+
static std::map<std::string, ConfigGroup> sm_ConfigGroups;
22+
return sm_ConfigGroups;
2223
}
2324

2425
static ConfigDebugInterface sm_Instance;
2526

2627
void
27-
Draw () override
28+
DrawConfigGroup (ConfigGroup &group)
2829
{
29-
for (auto i : GetConfigOptions ())
30+
for (auto &i : group)
3031
{
3132
ImGui::Columns (2);
3233

@@ -53,12 +54,27 @@ private:
5354
}
5455
}
5556

57+
void
58+
Draw () override
59+
{
60+
for (auto &i : GetConfigOptions ())
61+
{
62+
if (ImGui::CollapsingHeader (i.first.c_str ()))
63+
{
64+
ImGui::PushID (i.first.c_str ());
65+
DrawConfigGroup (i.second);
66+
ImGui::PopID ();
67+
}
68+
}
69+
}
70+
5671
public:
5772
template <typename T>
5873
static void
59-
AddConfigOption (std::string_view path, T *data)
74+
AddConfigOption (const std::string &tableName, const std::string &key,
75+
T *data)
6076
{
61-
GetConfigOptions ()[std::string (path)] = data;
77+
GetConfigOptions ()[tableName][key] = data;
6278
}
6379

6480
const char *

0 commit comments

Comments
 (0)