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
1414void (*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-
12647public:
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 }
0 commit comments