Skip to content

Commit 2c1520b

Browse files
committed
Vehicle Upgrades Randomizer: Stability Improvements
* Vehicle upgrades are applied on-at-a-time now to make sure the game doesn't get too many stream requests at the same time. * In addition, the stream request pool is also checked to make sure it has reasonable free slots before requesting more vehicle upgrades. * Added License Plate Randomization using data file with names of contributors, patrons and others.
1 parent 4679d93 commit 2c1520b

File tree

16 files changed

+609
-182
lines changed

16 files changed

+609
-182
lines changed

build-count.txt

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

cmake/DebugImgui.cmake

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
include(cmake/imgui.cmake)
2+
include(cmake/implot.cmake)
23
include(cmake/fmt.cmake)
34

45
file(GLOB_RECURSE SOURCES CONFIGURE_DEPENDS src/debug/*.cc)
56

67
target_sources(${PROJECT_NAME} PUBLIC ${SOURCES})
78
target_compile_definitions(${PROJECT_NAME} PRIVATE -DENABLE_DEBUG_MENU)
8-
target_link_libraries (${PROJECT_NAME} PUBLIC fmt imgui dxguid dwmapi imm32)
9+
target_link_libraries (${PROJECT_NAME} PUBLIC fmt imgui dxguid dwmapi imm32 implot)
910

cmake/implot.cmake

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
include(FetchContent)
2+
FetchContent_Declare(LIB_implot
3+
GIT_REPOSITORY https://github.com/epezent/implot
4+
GIT_TAG v0.12)
5+
6+
message("Fetching implot from GitHub...")
7+
8+
FetchContent_MakeAvailable (LIB_implot)
9+
FetchContent_GetProperties(LIB_implot
10+
SOURCE_DIR LIB_implot_SOURCE_DIR)
11+
12+
file(GLOB SOURCES CONFIGURE_DEPENDS
13+
${LIB_implot_SOURCE_DIR}/implot.cpp
14+
${LIB_implot_SOURCE_DIR}/implot_items.cpp
15+
)
16+
17+
add_library (implot STATIC ${SOURCES})
18+
target_include_directories(implot PUBLIC
19+
${LIB_implot_SOURCE_DIR}
20+
)
21+
22+
target_link_libraries(implot PUBLIC imgui)

data/LicensePlates.txt

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
P4R1K
2+
FRYT3RP
3+
123R0B0
4+
5P33DY
5+
M0X1
6+
HUG0 0N3
7+
G1B5T4CK
8+
9+
N4BN00B
10+
M4T3CZK
11+
V31G4R
12+
1GU4N4
13+
5R3W0
14+
R13K3LT
15+
W4R15
16+
M4DM4N
17+
18+
DV1P3R4U
19+
H4YW1R3
20+
JUR4YJ
21+
53RR4N0
22+
5H1N3
23+
T4R45
24+
25+
DRDR3
26+
L0RDM4U5
27+
M1CH43L
28+
FR4NKL1N
29+
L4M4R
30+
B1RD
31+
P1G
32+
C4T
33+
D0G
34+
VR00M
35+
GT4K1D
36+
N1K0
37+
R0M4N

lib/CPools.cc

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ CPools::InitialisePatterns ()
1111

1212
g_pVehicleStructPool = GetRelativeReference<CPool<CVehicleStruct> *> (
1313
"c7 44 ? ? ? ? ? ? 83 64 ? ? 00 e8 ? ? ? ? ? 89 ? ? ? ? ? eb", 21, 25);
14-
}
1514

16-
CPool<CVehicleStruct> **CPools::g_pVehicleStructPool;
15+
g_pVehicleStreamRequestGfxPool
16+
= GetRelativeReference<CPool<CVehicleStreamRequestGfx> *> (
17+
"8b 15 ? ? ? ? ? 8b ? ? 83 c1 10 e8 ? ? ? ? ? 8b 0d", 21, 25);
18+
}

lib/CPools.hh

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,13 @@ public:
2222
return m_nCount & 0x3fffffff;
2323
}
2424

25+
/* Returns number of free slots in the pool */
26+
uint32_t
27+
GetFree ()
28+
{
29+
return m_nMaxElements - GetCount ();
30+
}
31+
2532
// Because why not, right? :P
2633
class CPoolIterator
2734
{
@@ -138,17 +145,26 @@ public:
138145
static_assert (sizeof (CPool<void *>) == 40);
139146

140147
struct CVehicleStruct;
148+
struct CVehicleStreamRequestGfx;
141149

142150
class CPools
143151
{
144152
public:
145-
static CPool<CVehicleStruct> **g_pVehicleStructPool;
153+
inline static CPool<CVehicleStruct> **g_pVehicleStructPool;
154+
inline static CPool<CVehicleStreamRequestGfx> *
155+
*g_pVehicleStreamRequestGfxPool;
146156

147157
inline static CPool<CVehicleStruct> *&
148158
GetVehicleStructPool ()
149159
{
150160
return *g_pVehicleStructPool;
151161
};
152162

163+
inline static auto *&
164+
GetVehicleStreamRequestGxtPool ()
165+
{
166+
return *g_pVehicleStreamRequestGfxPool;
167+
};
168+
153169
static void InitialisePatterns ();
154170
};

lib/HSL.hh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
#pragma once
2+
13
#include "CMath.hh"
24
#include "CARGB.hh"
35
#include <cmath>

src/common/parser.hh

Lines changed: 65 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,68 @@ public:
143143
}
144144
};
145145

146+
// Data file containing strings
147+
template <const char *FileName> class DataFileSourcedRandomizer
148+
{
149+
using Type = std::string;
150+
151+
private:
152+
struct ValueGroup
153+
{
154+
std::vector<Type> Values;
155+
std::vector<double> Weights;
156+
};
157+
158+
bool m_Initialised = false;
159+
ValueGroup m_List;
160+
161+
/*******************************************************/
162+
void
163+
Initialise ()
164+
{
165+
if (std::exchange (m_Initialised, true))
166+
return;
167+
168+
FILE *file = Rainbomizer::Common::GetRainbomizerDataFile (FileName);
169+
if (!file)
170+
return;
171+
172+
char line[512] = {0};
173+
while (fgets (line, 512, file))
174+
{
175+
if (strlen (line) < 3)
176+
continue;
177+
178+
double weight = 1.0;
179+
char model[256] = {0};
180+
181+
sscanf (line, "%s %lf ", model, &weight);
182+
183+
m_List.Values.push_back (model);
184+
m_List.Weights.push_back (weight);
185+
}
186+
}
187+
188+
public:
189+
/*******************************************************/
190+
bool
191+
RandomizeObject (Type &out)
192+
{
193+
Initialise ();
194+
195+
if (m_List.Values.size ())
196+
out = m_List.Values[RandomWeighed (m_List.Weights)];
197+
198+
return m_List.Values.size ();
199+
}
200+
201+
/*******************************************************/
202+
void
203+
AddSample (const Type value)
204+
{
205+
}
206+
};
207+
146208
template <typename T, T... Values> class ConstantValues
147209
{
148210
constexpr static std::array<T, sizeof...(Values)> m_Values{Values...};
@@ -341,16 +403,16 @@ public:
341403
void
342404
AddSample (T *base, uint32_t hash)
343405
{
344-
std::apply ([base,
345-
hash] (auto &...x) { (..., AddSample (x, base, hash)); },
406+
std::apply ([base, hash,
407+
this] (auto &...x) { (..., AddSample (x, base, hash)); },
346408
randomizers);
347409
}
348410

349411
template <typename T>
350412
void
351413
RandomizeObject (T *base, uint32_t hash)
352414
{
353-
std::apply ([base, hash] (
415+
std::apply ([base, hash, this] (
354416
auto &...x) { (..., RandomizeObject (x, base, hash)); },
355417
randomizers);
356418
}

src/debug/backend.cc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
#include <windows.h>
77

88
#include <imgui.h>
9+
#include <implot.h>
910
#include <imgui_impl_win32.h>
1011
#include <imgui_impl_dx11.h>
1112

@@ -146,6 +147,7 @@ class DebugServerBackend
146147
device->GetImmediateContext (&context);
147148

148149
ImGui::CreateContext ();
150+
ImPlot::CreateContext ();
149151
ImGui::StyleColorsDark ();
150152

151153
HWND window = FindMainWindow (GetCurrentProcessId ());

src/debug/config.hh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,8 @@ private:
5151
i.second);
5252
ImGui::PopID ();
5353
ImGui::NextColumn ();
54+
55+
ImGui::Columns ();
5456
}
5557
}
5658

0 commit comments

Comments
 (0)