Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master' into msgl
Browse files Browse the repository at this point in the history
  • Loading branch information
holysnipz committed Feb 17, 2024
2 parents e4bc798 + 2a1a3a8 commit cdedfd9
Show file tree
Hide file tree
Showing 20 changed files with 61 additions and 56 deletions.
2 changes: 1 addition & 1 deletion ChaosMod/Components/DebugSocket.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ static void OnExecScript(DebugSocket *debugSocket, std::shared_ptr<ix::Connectio
scriptName.resize(8);
for (int i = 0; i < 8; i++)
{
sprintf(scriptName.data() + i, "%x", g_Random.GetRandomInt(0, 16));
sprintf(scriptName.data() + i, "%x", g_RandomNoDeterm.GetRandomInt(0, 16));
}

json json;
Expand Down
3 changes: 2 additions & 1 deletion ChaosMod/Components/EffectDispatchTimer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ EffectDispatchTimer::EffectDispatchTimer(const std::array<BYTE, 3> &timerColor)
{
m_TimerColor = timerColor;

m_DrawTimerBar = !g_OptionsManager.GetConfigValue({ "DisableTimerBarDraw" }, OPTION_DEFAULT_NO_EFFECT_BAR);
m_EffectSpawnTime = g_OptionsManager.GetConfigValue({ "NewEffectSpawnTime" }, OPTION_DEFAULT_EFFECT_SPAWN_TIME);

m_DistanceChaosState.EnableDistanceBasedEffectDispatch = g_OptionsManager.GetConfigValue(
Expand Down Expand Up @@ -174,7 +175,7 @@ void EffectDispatchTimer::ResetFakeTimerPercentage()

void EffectDispatchTimer::OnRun()
{
if (!m_EnableTimer
if (!m_EnableTimer || !m_DrawTimerBar
|| (ComponentExists<MetaModifiers>()
&& (GetComponent<MetaModifiers>()->HideChaosUI || GetComponent<MetaModifiers>()->DisableChaos)))
{
Expand Down
1 change: 1 addition & 0 deletions ChaosMod/Components/EffectDispatchTimer.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ class EffectDispatchTimer : public Component
bool m_EnableTimer = true;
bool m_PauseTimer = false;
bool m_DispatchEffectsOnTimer = true;
bool m_DrawTimerBar = true;
std::uint16_t m_EffectSpawnTime = 0;
std::array<std::uint8_t, 3> m_TimerColor;
float m_TimerPercentage = 0.f;
Expand Down
7 changes: 3 additions & 4 deletions ChaosMod/Components/EffectDispatcher.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ static void _DispatchEffect(EffectDispatcher *effectDispatcher, const EffectDisp

auto playEffectDispatchSound = [&]()
{
if ((ComponentExists<MetaModifiers>() && !GetComponent<MetaModifiers>()->HideChaosUI)
if ((!ComponentExists<MetaModifiers>() || GetComponent<MetaModifiers>()->HideChaosUI)
&& ComponentExists<Mp3Manager>())
{
// Play global sound (if one exists)
Expand Down Expand Up @@ -220,10 +220,9 @@ static void _OnRunEffects(LPVOID data)
EffectDispatcher::EffectDispatcher(const std::array<BYTE, 3> &textColor, const std::array<BYTE, 3> &effectTimerColor)
: Component()
{
m_TextColor = textColor;
m_EffectTimerColor = effectTimerColor;
m_TextColor = textColor;
m_EffectTimerColor = effectTimerColor;

m_DisableDrawTimerBar = g_OptionsManager.GetConfigValue({ "DisableTimerBarDraw" }, OPTION_DEFAULT_NO_EFFECT_BAR);
m_DisableDrawEffectTexts =
g_OptionsManager.GetConfigValue({ "DisableEffectTextDraw" }, OPTION_DEFAULT_NO_TEXT_DRAW);

Expand Down
2 changes: 0 additions & 2 deletions ChaosMod/Components/EffectDispatcher.h
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,6 @@ class EffectDispatcher : public Component
std::array<std::uint8_t, 3> m_TextColor;
std::array<std::uint8_t, 3> m_EffectTimerColor;

bool m_DisableDrawTimerBar = false;
bool m_DisableDrawEffectTexts = false;

bool m_EnableNormalEffectDispatch = false;
Expand Down Expand Up @@ -134,7 +133,6 @@ class EffectDispatcher : public Component
void DispatchRandomEffect(DispatchEffectFlags dispatchEffectFlags = DispatchEffectFlag_None,
const std::string &suffix = {});

void UpdateTimer(int deltaTime);
void UpdateEffects(int deltaTime);
void UpdateMetaEffects(int deltaTime);

Expand Down
2 changes: 1 addition & 1 deletion ChaosMod/Components/Mp3Manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ void Mp3Manager::PlayChaosSoundFile(const std::string &soundFileName)
}

auto size = cachedSoundFiles.size();
auto chosenSound = size > 1 ? cachedSoundFiles[g_Random.GetRandomInt(0, size - 1)] : cachedSoundFiles[0];
auto chosenSound = size > 1 ? cachedSoundFiles[g_RandomNoDeterm.GetRandomInt(0, size - 1)] : cachedSoundFiles[0];

int error;
{
Expand Down
4 changes: 2 additions & 2 deletions ChaosMod/Components/Voting.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ void Voting::OnRun()
totalWeight += effectData.GetEffectWeight();
}

float chosen = g_Random.GetRandomFloat(0.f, totalWeight);
float chosen = g_RandomNoDeterm.GetRandomFloat(0.f, totalWeight);

totalWeight = 0.f;

Expand Down Expand Up @@ -369,7 +369,7 @@ bool Voting::Init()
auto str = _wcsdup(VOTING_PROXY_START_ARGS);
#ifdef _DEBUG
DWORD attributes = NULL;
if (DoesFileExist("chaosmod\\.forcenovotingconsole"))
if (DoesFeatureFlagExist("forcenovotingconsole"))
{
attributes = CREATE_NO_WINDOW;
}
Expand Down
2 changes: 1 addition & 1 deletion ChaosMod/Effects/Effect.h
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ class RegisterEffect
{
static bool disableEffectRegistration = []()
{
return DoesFileExist("chaosmod\\.disablebuiltineffects");
return DoesFeatureFlagExist("disablebuiltineffects");
}();

if (disableEffectRegistration)
Expand Down
5 changes: 0 additions & 5 deletions ChaosMod/Effects/EffectIdentifier.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,6 @@ class EffectIdentifier
return m_EffectId == other.GetEffectId();
}

inline bool operator!=(const EffectIdentifier &other) const
{
return !(*this == other);
}

inline bool IsScript() const
{
return m_IsScript;
Expand Down
3 changes: 3 additions & 0 deletions ChaosMod/Effects/db/Misc/MiscVehicleRain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ static void OnTick()

// Also apply random upgrades
SET_VEHICLE_MOD_KIT(veh, 0);

SET_VEHICLE_WHEEL_TYPE(veh, g_Random.GetRandomInt(0, 12));

for (int i = 0; i < 50; i++)
{
int max = GET_NUM_VEHICLE_MODS(veh, i);
Expand Down
2 changes: 1 addition & 1 deletion ChaosMod/Effects/db/Vehs/VehsSpawner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ static void OnStartRandom()
// Also apply random upgrades
SET_VEHICLE_MOD_KIT(veh, 0);

SET_VEHICLE_WHEEL_TYPE(veh, g_Random.GetRandomInt(0, 7));
SET_VEHICLE_WHEEL_TYPE(veh, g_Random.GetRandomInt(0, 12));

for (int i = 0; i < 50; i++)
{
Expand Down
2 changes: 1 addition & 1 deletion ChaosMod/Effects/db/Vehs/VehsUpgradeController.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ static void OnStartRandomUpgrades()
{
SET_VEHICLE_MOD_KIT(veh, 0);

SET_VEHICLE_WHEEL_TYPE(veh, g_Random.GetRandomInt(0, 7));
SET_VEHICLE_WHEEL_TYPE(veh, g_Random.GetRandomInt(0, 12));

for (int i = 0; i < 50; i++)
{
Expand Down
9 changes: 5 additions & 4 deletions ChaosMod/Main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ static void Init()
}();

static std::streambuf *oldStreamBuf;
if (DoesFileExist("chaosmod\\.enableconsole"))
if (DoesFeatureFlagExist("enableconsole"))
{
if (GetConsoleWindow())
{
Expand Down Expand Up @@ -145,9 +145,10 @@ static void Init()
g_OptionsManager.GetConfigValue<std::string>({ "EffectTimedTimerColor" }, OPTION_DEFAULT_TIMED_COLOR));

g_Random.SetSeed(g_OptionsManager.GetConfigValue({ "Seed" }, 0));
g_RandomNoDeterm.SetSeed(GetTickCount64());

std::set<std::string> blacklistedComponentNames;
if (DoesFileExist("chaosmod\\.blacklistedcomponents"))
if (DoesFeatureFlagExist("blacklistedcomponents"))
{
std::ifstream file("chaosmod\\.blacklistedcomponents");
if (!file.fail())
Expand Down Expand Up @@ -200,7 +201,7 @@ static void Init()
INIT_COMPONENT("HelpTextQueue", "script help text queue", HelpTextQueue);

#ifdef WITH_DEBUG_PANEL_SUPPORT
if (DoesFileExist("chaosmod\\.enabledebugsocket"))
if (DoesFeatureFlagExist("enabledebugsocket"))
{
INIT_COMPONENT("DebugSocket", "Debug Websocket", DebugSocket);
}
Expand Down Expand Up @@ -276,7 +277,7 @@ static void MainRun()
{
isDisabled = false;

if (DoesFileExist("chaosmod\\.clearlogfileonreset"))
if (DoesFeatureFlagExist("clearlogfileonreset"))
{
// Clear log
g_Log = std::ofstream(CHAOS_LOG_FILE);
Expand Down
6 changes: 3 additions & 3 deletions ChaosMod/Memory/Memory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ namespace Memory

MH_Initialize();

if (DoesFileExist("chaosmod\\.skipintro"))
if (DoesFeatureFlagExist("skipintro"))
{
// Splash screen
Handle handle = FindPattern("E8 ? ? ? ? 8B CF 40 88 2D");
Expand Down Expand Up @@ -58,7 +58,7 @@ namespace Memory
}
}

if (DoesFileExist("chaosmod\\.skipdlcs"))
if (DoesFeatureFlagExist("skipdlcs"))
{
Handle handle = FindPattern("84 C0 74 2C 48 8D 15 ? ? ? ? 48 8D 0D ? ? ? ? 45 33 C9 41 B0 01");
if (!handle.IsValid())
Expand All @@ -73,7 +73,7 @@ namespace Memory
}
}

if (DoesFileExist("chaosmod\\.blacklistedhooks"))
if (DoesFeatureFlagExist("blacklistedhooks"))
{
std::ifstream file("chaosmod\\.blacklistedhooks");
if (!file.fail())
Expand Down
16 changes: 8 additions & 8 deletions ChaosMod/Util/Color.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,20 +16,20 @@ struct Color
inline Color GetRandomColorRGB(std::uint8_t min = 0, std::uint8_t max = 255)
{
return {
(std::uint8_t)g_Random.GetRandomInt(min, max), // R
(std::uint8_t)g_Random.GetRandomInt(min, max), // G
(std::uint8_t)g_Random.GetRandomInt(min, max), // B
255 // A
(std::uint8_t)g_RandomNoDeterm.GetRandomInt(min, max), // R
(std::uint8_t)g_RandomNoDeterm.GetRandomInt(min, max), // G
(std::uint8_t)g_RandomNoDeterm.GetRandomInt(min, max), // B
255 // A
};
}

// Returns a random RGBA value with a random alpha.
inline Color GetRandomColorRGBA(std::uint8_t min = 0, std::uint8_t max = 255)
{
return {
(std::uint8_t)g_Random.GetRandomInt(min, max), // R
(std::uint8_t)g_Random.GetRandomInt(min, max), // G
(std::uint8_t)g_Random.GetRandomInt(min, max), // B
(std::uint8_t)g_Random.GetRandomInt(min, max) // A
(std::uint8_t)g_RandomNoDeterm.GetRandomInt(min, max), // R
(std::uint8_t)g_RandomNoDeterm.GetRandomInt(min, max), // G
(std::uint8_t)g_RandomNoDeterm.GetRandomInt(min, max), // B
(std::uint8_t)g_RandomNoDeterm.GetRandomInt(min, max) // A
};
}
4 changes: 2 additions & 2 deletions ChaosMod/Util/CrashHandler.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

inline LONG WINAPI CrashHandler(_EXCEPTION_POINTERS *exceptionInfo)
{
if (DoesFileExist("chaosmod\\.nodumps"))
if (DoesFeatureFlagExist("nodumps"))
{
return EXCEPTION_CONTINUE_SEARCH;
}
Expand All @@ -37,7 +37,7 @@ inline LONG WINAPI CrashHandler(_EXCEPTION_POINTERS *exceptionInfo)

DWORD flags = MiniDumpWithIndirectlyReferencedMemory | MiniDumpScanMemory;

if (DoesFileExist("chaosmod\\.fulldumps"))
if (DoesFeatureFlagExist("fulldumps"))
{
flags = MiniDumpWithFullMemory | MiniDumpWithHandleData | MiniDumpWithUnloadedModules
| MiniDumpWithProcessThreadData | MiniDumpWithFullMemoryInfo | MiniDumpWithThreadInfo;
Expand Down
5 changes: 5 additions & 0 deletions ChaosMod/Util/File.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,11 @@ inline bool DoesFileExist(std::string_view fileName)
return stat(fileName.data(), &temp) == 0;
}

inline bool DoesFeatureFlagExist(const std::string &featureFlagName)
{
return DoesFileExist("chaosmod\\." + featureFlagName);
}

inline std::vector<std::filesystem::directory_entry> GetFiles(std::string path, std::string extension, bool recursive,
std::vector<std::string> blacklistedFiles = {})
{
Expand Down
14 changes: 7 additions & 7 deletions ChaosMod/Util/PoolSpawner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ Ped CreateRandomPoolPed(float x, float y, float z, float heading)
Ped ped;
if (!pedModels.empty())
{
Hash model = pedModels[g_Random.GetRandomInt(0, pedModels.size() - 1)];
Hash model = pedModels[g_RandomNoDeterm.GetRandomInt(0, pedModels.size() - 1)];

ped = CreatePoolPed(4, model, x, y, z, heading);
}
Expand All @@ -154,20 +154,20 @@ Ped CreateRandomPoolPed(float x, float y, float z, float heading)
for (int i = 0; i < 12; i++)
{
int drawableAmount = GET_NUMBER_OF_PED_DRAWABLE_VARIATIONS(ped, i);
int drawable = drawableAmount == 0 ? 0 : g_Random.GetRandomInt(0, drawableAmount - 1);
int drawable = drawableAmount == 0 ? 0 : g_RandomNoDeterm.GetRandomInt(0, drawableAmount - 1);

int textureAmount = GET_NUMBER_OF_PED_TEXTURE_VARIATIONS(ped, i, drawable);
int texture = textureAmount == 0 ? 0 : g_Random.GetRandomInt(0, textureAmount - 1);
int texture = textureAmount == 0 ? 0 : g_RandomNoDeterm.GetRandomInt(0, textureAmount - 1);

SET_PED_COMPONENT_VARIATION(ped, i, drawable, texture, g_Random.GetRandomInt(0, 3));
SET_PED_COMPONENT_VARIATION(ped, i, drawable, texture, g_RandomNoDeterm.GetRandomInt(0, 3));

if (i < 4)
{
int propDrawableAmount = GET_NUMBER_OF_PED_PROP_DRAWABLE_VARIATIONS(ped, i);
int propDrawable = propDrawableAmount == 0 ? 0 : g_Random.GetRandomInt(0, propDrawableAmount - 1);
int propDrawable = propDrawableAmount == 0 ? 0 : g_RandomNoDeterm.GetRandomInt(0, propDrawableAmount - 1);

int propTextureAmount = GET_NUMBER_OF_PED_PROP_TEXTURE_VARIATIONS(ped, i, drawable);
int propTexture = propTextureAmount == 0 ? 0 : g_Random.GetRandomInt(0, propTextureAmount - 1);
int propTextureAmount = GET_NUMBER_OF_PED_PROP_TEXTURE_VARIATIONS(ped, i, drawable);
int propTexture = propTextureAmount == 0 ? 0 : g_RandomNoDeterm.GetRandomInt(0, propTextureAmount - 1);

SET_PED_PROP_INDEX(ped, i, propDrawable, propTexture, true);
}
Expand Down
1 change: 1 addition & 0 deletions ChaosMod/Util/Random.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,4 @@ class Random
};

inline Random g_Random;
inline Random g_RandomNoDeterm;
27 changes: 14 additions & 13 deletions ChaosMod/Util/Vehicle.h
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ inline Vehicle CreateRandomVehicleWithPeds(Vehicle oldHandle, const std::vector<
Hash newVehModel = 0;
do
{
newVehModel = vehicleModels[g_Random.GetRandomInt(0, vehicleModels.size() - 1)];
newVehModel = vehicleModels[g_RandomNoDeterm.GetRandomInt(0, vehicleModels.size() - 1)];
} while (GET_VEHICLE_MODEL_NUMBER_OF_SEATS(newVehModel) < seatPeds.size() || IS_THIS_MODEL_A_TRAIN(newVehModel)
|| GET_VEHICLE_MODEL_ACCELERATION(newVehModel) <= 0);

Expand Down Expand Up @@ -170,35 +170,36 @@ inline Vehicle CreateRandomVehicleWithPeds(Vehicle oldHandle, const std::vector<
// Also apply random upgrades
SET_VEHICLE_MOD_KIT(newVehicle, 0);

SET_VEHICLE_WHEEL_TYPE(newVehicle, g_Random.GetRandomInt(0, 7));
SET_VEHICLE_WHEEL_TYPE(newVehicle, g_RandomNoDeterm.GetRandomInt(0, 12));

for (int i = 0; i < 50; i++)
{
int max = GET_NUM_VEHICLE_MODS(newVehicle, i);
if (max > 0)
{
SET_VEHICLE_MOD(newVehicle, i, g_Random.GetRandomInt(0, max - 1), g_Random.GetRandomInt(0, 1));
SET_VEHICLE_MOD(newVehicle, i, g_RandomNoDeterm.GetRandomInt(0, max - 1),
g_RandomNoDeterm.GetRandomInt(0, 1));
}

TOGGLE_VEHICLE_MOD(newVehicle, i, g_Random.GetRandomInt(0, 1));
TOGGLE_VEHICLE_MOD(newVehicle, i, g_RandomNoDeterm.GetRandomInt(0, 1));
}

SET_VEHICLE_TYRES_CAN_BURST(newVehicle, g_Random.GetRandomInt(0, 1));
SET_VEHICLE_WINDOW_TINT(newVehicle, g_Random.GetRandomInt(0, 6));
SET_VEHICLE_TYRES_CAN_BURST(newVehicle, g_RandomNoDeterm.GetRandomInt(0, 1));
SET_VEHICLE_WINDOW_TINT(newVehicle, g_RandomNoDeterm.GetRandomInt(0, 6));

SET_VEHICLE_CUSTOM_PRIMARY_COLOUR(newVehicle, g_Random.GetRandomInt(0, 255), g_Random.GetRandomInt(0, 255),
g_Random.GetRandomInt(0, 255));
SET_VEHICLE_CUSTOM_SECONDARY_COLOUR(newVehicle, g_Random.GetRandomInt(0, 255), g_Random.GetRandomInt(0, 255),
g_Random.GetRandomInt(0, 255));
SET_VEHICLE_CUSTOM_PRIMARY_COLOUR(newVehicle, g_RandomNoDeterm.GetRandomInt(0, 255),
g_RandomNoDeterm.GetRandomInt(0, 255), g_RandomNoDeterm.GetRandomInt(0, 255));
SET_VEHICLE_CUSTOM_SECONDARY_COLOUR(newVehicle, g_RandomNoDeterm.GetRandomInt(0, 255),
g_RandomNoDeterm.GetRandomInt(0, 255), g_RandomNoDeterm.GetRandomInt(0, 255));

_SET_VEHICLE_NEON_LIGHTS_COLOUR(newVehicle, g_Random.GetRandomInt(0, 255), g_Random.GetRandomInt(0, 255),
g_Random.GetRandomInt(0, 255));
_SET_VEHICLE_NEON_LIGHTS_COLOUR(newVehicle, g_RandomNoDeterm.GetRandomInt(0, 255),
g_RandomNoDeterm.GetRandomInt(0, 255), g_RandomNoDeterm.GetRandomInt(0, 255));
for (int i = 0; i < 4; i++)
{
_SET_VEHICLE_NEON_LIGHT_ENABLED(newVehicle, i, true);
}

_SET_VEHICLE_XENON_LIGHTS_COLOR(newVehicle, g_Random.GetRandomInt(0, 12));
_SET_VEHICLE_XENON_LIGHTS_COLOR(newVehicle, g_RandomNoDeterm.GetRandomInt(0, 12));

return newVehicle;
}
Expand Down

0 comments on commit cdedfd9

Please sign in to comment.