Skip to content

Commit 5a1e110

Browse files
committed
General: Code cleanup
* Restore the config macros. Now hopefully fixed with the Zc:preprocessor compiler option * Use CMAKE_MSVC_RUNTIME_LIBRARY instead of replacing flags manually. (They didn't work before because minimum cmake level wasn't high enough and as such the policy that enabled the option wasn't active) * Renamed rainbomizer.asi output to use the project name (V.Rainbomizer) * Added Forced Vehicle config option * Removed unused natives pattern searches
1 parent f9e0e86 commit 5a1e110

File tree

11 files changed

+58
-117
lines changed

11 files changed

+58
-117
lines changed

.github/workflows/main.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ jobs:
2222
nmake
2323
mkdir output
2424
mkdir output/rainbomizer
25-
cp rainbomizer.asi output/V.Rainbomizer.asi
25+
cp V.Rainbomizer.asi output/V.Rainbomizer.asi
2626
cp -r ../data output/rainbomizer/data/
2727
rm output/rainbomizer/data/update.sh
2828
rm output/rainbomizer/data/README.md

CMakeLists.txt

Lines changed: 9 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
cmake_minimum_required(VERSION 3.1.5)
2-
project(rainbomizer_v)
1+
cmake_minimum_required(VERSION 3.15)
2+
project(V.Rainbomizer)
33

44
include(cmake/Minhook.cmake)
55

@@ -8,19 +8,9 @@ option(ENABLE_DEBUG_MENU "Enables an imgui-menu for debugging purposes")
88
# C++20
99
if (MSVC_VERSION GREATER_EQUAL "1900")
1010
set(CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>")
11-
# Because CMAKE_MSVC_RUNTIME_LIBRARY doesn't work for whatever reason
12-
set(CompilerFlags
13-
CMAKE_CXX_FLAGS
14-
CMAKE_CXX_FLAGS_DEBUG
15-
CMAKE_CXX_FLAGS_RELEASE
16-
CMAKE_C_FLAGS
17-
CMAKE_C_FLAGS_DEBUG
18-
CMAKE_C_FLAGS_RELEASE
19-
)
20-
foreach(CompilerFlag ${CompilerFlags})
21-
string(REPLACE "/MD" "/MT" ${CompilerFlag} "${${CompilerFlag}}")
22-
endforeach()
23-
11+
if (CMAKE_CXX_COMPILER_ID STREQUAL "MSVC")
12+
add_compile_options(/Zc:preprocessor)
13+
endif()
2414
add_definitions(-D_CRT_SECURE_NO_WARNINGS)
2515
endif()
2616

@@ -41,18 +31,13 @@ file(GLOB_RECURSE SOURCES CONFIGURE_DEPENDS
4131
lib/*.cc
4232
lib/Patterns/*.cpp)
4333

44-
add_library("rainbomizer" SHARED ${SOURCES} )
34+
add_library(${PROJECT_NAME} SHARED ${SOURCES} )
4535

4636
if (ENABLE_DEBUG_MENU)
4737
include(cmake/DebugImgui.cmake)
4838
endif()
4939

5040
# Properties
51-
set_target_properties("rainbomizer" PROPERTIES SUFFIX ".asi")
52-
target_link_libraries("rainbomizer" PUBLIC dbghelp minhook)
53-
target_compile_definitions("rainbomizer" PUBLIC NOMINMAX)
54-
if (CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
55-
56-
else()
57-
target_compile_features("rainbomizer" PRIVATE cxx_auto_type)
58-
endif()
41+
set_target_properties(${PROJECT_NAME} PROPERTIES SUFFIX ".asi")
42+
target_link_libraries(${PROJECT_NAME} PUBLIC dbghelp minhook)
43+
target_compile_definitions(${PROJECT_NAME} PUBLIC NOMINMAX)

cmake/DebugImgui.cmake

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ include(cmake/fmt.cmake)
33

44
file(GLOB_RECURSE SOURCES CONFIGURE_DEPENDS src/debug/*.cc)
55

6-
target_sources("rainbomizer" PUBLIC ${SOURCES})
7-
target_compile_definitions("rainbomizer" PRIVATE -DENABLE_DEBUG_MENU)
8-
target_link_libraries ("rainbomizer" PUBLIC fmt imgui dxguid dwmapi imm32)
6+
target_sources(${PROJECT_NAME} PUBLIC ${SOURCES})
7+
target_compile_definitions(${PROJECT_NAME} PRIVATE -DENABLE_DEBUG_MENU)
8+
target_link_libraries (${PROJECT_NAME} PUBLIC fmt imgui dxguid dwmapi imm32)
99

cmake/DebugServer.cmake

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,13 @@ if (TARGET example64)
1515
PROPERTIES EXCLUDE_FROM_ALL true)
1616
endif()
1717

18-
target_sources("rainbomizer" PUBLIC ${SOURCES})
19-
target_compile_definitions("rainbomizer" PRIVATE -DENABLE_DEBUG_SERVER)
20-
target_precompile_headers("rainbomizer" PRIVATE
18+
target_sources(${PROJECT_NAME} PUBLIC ${SOURCES})
19+
target_compile_definitions(${PROJECT_NAME} PRIVATE -DENABLE_DEBUG_SERVER)
20+
target_precompile_headers(${PROJECT_NAME} PRIVATE
2121
<nlohmann/json.hpp>
2222
<App.h>
2323
)
24-
target_link_libraries ("rainbomizer" PUBLIC
24+
target_link_libraries (${PROJECT_NAME} PUBLIC
2525
uWebSockets
2626
nlohmann_json::nlohmann_json
2727
fmt)

lib/CStreaming.hh

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,9 +82,10 @@ public:
8282
GetModelIndex (uint32_t hash)
8383
{
8484
uint32_t index = -1;
85-
GetModelAndIndexByHash (hash, index);
85+
if (!GetModelAndIndexByHash (hash, index))
86+
return -1;
8687

87-
return index;
88+
return index & 0xFFFF;
8889
}
8990

9091
static inline uint32_t

lib/Natives.cc

Lines changed: 0 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -2,57 +2,31 @@
22
#include "Utils.hh"
33
#include <CTheScripts.hh>
44

5-
int (*__CREATE_CAR) (uint32_t hash, Vector3_native *coords, double heading,
6-
bool isNetwork, bool thisScriptCheck);
75
void (*__REQUEST_MODEL) (uint32_t hash);
8-
void (*__LOAD_ALL_OBJECTS_NOW) ();
96
unsigned short (*__GET_VEHICLE_MODEL_NUMBER_OF_SEATS) (uint32_t hash);
107

118
void
129
InitialiseNatives ()
1310
{
14-
ConvertCall (
15-
hook::get_pattern ("8b ec ? 83 ec 50 f3 0f 10 02 f3 0f 10 4a 08", -17),
16-
__CREATE_CAR);
17-
1811
ConvertCall (
1912
hook::get_pattern (
2013
"8b d9 0d ff ff ff 0f c7 ? ? ff ff 00 00 25 ff ff ff 0f 89", -25),
2114
__REQUEST_MODEL);
2215

23-
ConvertCall (hook::get_pattern (
24-
"? 83 ec 28 ? 8d 0d ? ? ? ? ? 33 c0 b2 01 "),
25-
__LOAD_ALL_OBJECTS_NOW);
26-
2716
ConvertCall (
2817
hook::get_pattern (
2918
"8a 88 9d 00 00 00 80 e1 1f 80 f9 05 75 ? ? 8b 88 b0 00 00 00 ",
3019
-27),
3120
__GET_VEHICLE_MODEL_NUMBER_OF_SEATS);
3221
}
3322

34-
/*******************************************************/
35-
int
36-
CREATE_CAR (uint32_t hash, Vector3_native *coords, double heading,
37-
bool isNetwork, bool thisScriptCheck)
38-
{
39-
return __CREATE_CAR (hash, coords, heading, isNetwork, thisScriptCheck);
40-
}
41-
4223
/*******************************************************/
4324
void
4425
REQUEST_MODEL (uint32_t hash)
4526
{
4627
return __REQUEST_MODEL (hash);
4728
}
4829

49-
/*******************************************************/
50-
void
51-
LOAD_ALL_OBJECTS_NOW ()
52-
{
53-
return __LOAD_ALL_OBJECTS_NOW ();
54-
}
55-
5630
/*******************************************************/
5731
unsigned short
5832
GET_VEHICLE_MODEL_NUMBER_OF_SEATS (uint32_t vehicleHash)

lib/rage.hh

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -326,15 +326,15 @@ struct atFixedArray : public atArrayBase<T[Size]>
326326
struct atString
327327
{
328328
char *m_szString;
329-
short m_nLength;
330-
short m_nCapacity;
329+
unsigned short m_nLength;
330+
unsigned short m_nCapacity;
331331

332332
atString () = default;
333333

334334
atString (const char *str)
335335
{
336336
m_szString = const_cast<char *> (str);
337-
m_nLength = strlen (str);
337+
m_nLength = static_cast<unsigned short> (strlen (str));
338338
m_nCapacity = m_nLength;
339339
}
340340
};

src/colours/weather.cc

Lines changed: 4 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -162,25 +162,10 @@ class WeatherRandomizer
162162
/*******************************************************/
163163
WeatherRandomizer ()
164164
{
165-
if (!ConfigManager ::ReadConfig (
166-
"TimecycleRandomizer",
167-
std::make_pair ("RandomizeWeather",
168-
&Config ().RandomizeWeather),
169-
std::make_pair ("RandomizeTimecycle",
170-
&Config ().RandomizeTimecycle),
171-
std::make_pair ("RandomizeTimecycleOdds",
172-
&Config ().RandomizeTimecycleOdds),
173-
std::make_pair ("RandomizeTimeOdds",
174-
&Config ().RandomizeTimeOdds),
175-
std::make_pair ("RandomizeEveryFade",
176-
&Config ().RandomizeEveryFade),
177-
std::make_pair ("RainOdds", &Config ().RainOdds),
178-
std::make_pair ("ThunderstormOdds",
179-
&Config ().ThunderstormOdds),
180-
std::make_pair ("RandomSnow", &Config ().RandomSnow),
181-
std::make_pair ("SnowOdds", &Config ().SnowOdds)))
182-
return;
183-
;
165+
RB_C_DO_CONFIG ("TimecycleRandomizer", RandomizeWeather,
166+
RandomizeTimecycle, RandomizeTimecycleOdds,
167+
RandomizeTimeOdds, RandomizeEveryFade, RainOdds,
168+
ThunderstormOdds, RandomSnow, SnowOdds);
184169

185170
InitialiseAllComponents ();
186171

src/common/events.hh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
#include <vector>
77

88
struct scrProgram;
9-
struct scrThreadContext;
9+
class scrThreadContext;
1010

1111
namespace Rainbomizer {
1212

src/sounds/voicelines.cc

Lines changed: 5 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -418,25 +418,11 @@ class VoiceLineRandomizer
418418
/*******************************************************/
419419
VoiceLineRandomizer ()
420420
{
421-
if (!ConfigManager ::ReadConfig (
422-
"VoiceLineRandomizer",
423-
std::make_pair ("IncludeDLCLines", &Config ().IncludeDLCLines),
424-
std::make_pair ("TrulyRandomDuration",
425-
&Config ().TrulyRandomDuration),
426-
std::make_pair ("OrderedRandomDuration",
427-
&Config ().OrderedRandomDuration),
428-
std::make_pair ("SomeRandomDuration",
429-
&Config ().SomeRandomDuration),
430-
std::make_pair ("NoRandomDuration",
431-
&Config ().NoRandomDuration),
432-
std::make_pair ("SameSpeakerPercentage",
433-
&Config ().SameSpeakerPercentage),
434-
std::make_pair ("PercentageRandomOnSomeRandom",
435-
&Config ().PercentageRandomOnSomeRandom),
436-
std::make_pair ("OrderedDialogueChangeFrequency",
437-
&Config ().OrderedDialogueChangeFrequency)))
438-
return;
439-
;
421+
RB_C_DO_CONFIG ("VoiceLineRandomizer", IncludeDLCLines,
422+
TrulyRandomDuration, OrderedRandomDuration,
423+
SomeRandomDuration, NoRandomDuration,
424+
SameSpeakerPercentage, PercentageRandomOnSomeRandom,
425+
OrderedDialogueChangeFrequency);
440426

441427
InitialiseAllComponents ();
442428
InitialiseHooks ();

0 commit comments

Comments
 (0)