Skip to content

Commit

Permalink
ChaosMod: Enable (almost) all warnings for GCC/Clang & treat all of them
Browse files Browse the repository at this point in the history
Decrease the warning level of MSVC to W2 and mark all warnings as errors for all compilers.

Also use this ooportunity to finally raise the cmake version.
  • Loading branch information
pongo1231 committed Jan 31, 2025
1 parent 53b281c commit 3d7b559
Show file tree
Hide file tree
Showing 72 changed files with 305 additions and 330 deletions.
8 changes: 4 additions & 4 deletions ChaosMod/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
cmake_minimum_required(VERSION 3.13)

cmake_minimum_required(VERSION 3.31)
project(ChaosMod)

file(GLOB ROOT_SRC ${PROJECT_SOURCE_DIR}/*.cpp)
Expand All @@ -12,6 +11,7 @@ target_precompile_headers(ChaosMod PUBLIC stdafx.cpp)

set_target_properties(ChaosMod PROPERTIES SUFFIX ".asi")
set_target_properties(ChaosMod PROPERTIES CXX_STANDARD 20)
set_target_properties(ChaosMod PROPERTIES CXX_SCAN_FOR_MODULES OFF)

target_compile_definitions(ChaosMod PUBLIC $<$<CONFIG:Debug>:CHAOSDEBUG>)
target_compile_definitions(ChaosMod PUBLIC NDEBUG)
Expand All @@ -37,9 +37,9 @@ target_link_directories(ChaosMod PUBLIC ${PROJECT_SOURCE_DIR}/../vendor/lua)
target_link_libraries(ChaosMod PUBLIC ${link_libs})

if (CMAKE_CXX_COMPILER_ID MATCHES "MSVC")
target_compile_options(ChaosMod PUBLIC -DUNICODE -D_UNICODE -DNOMINMAX /Zi /GT)
target_compile_options(ChaosMod PUBLIC /Zi /GT /W2 /WX -DUNICODE -D_UNICODE -DNOMINMAX -D_CRT_SECURE_NO_WARNINGS)
target_link_options(ChaosMod PUBLIC /DEBUG /OPT:REF /OPT:ICF)
else()
target_compile_options(ChaosMod PUBLIC -municode)
target_compile_options(ChaosMod PUBLIC -municode -flarge-source-files -Werror -Wall -Wextra -Wno-unused-parameter -Wno-missing-field-initializers -Wno-unused-variable -Wno-maybe-uninitialized -Wno-array-bounds -Wno-unused-but-set-variable)
target_link_options(ChaosMod PUBLIC -static)
endif()
30 changes: 15 additions & 15 deletions ChaosMod/Components/CrossingChallenge.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
#include "Components/EffectDispatchTimer.h"
#include "Main.h"
#include "Memory/WeaponPool.h"
#include "Util/ScriptText.h"
#include "Util/OptionsManager.h"
#include "Util/ScriptText.h"

void CrossingChallenge::SetStartParams()
{
Expand All @@ -14,8 +14,8 @@ void CrossingChallenge::SetStartParams()
if (m_StartVehicleHash)
{
LoadModel(m_StartVehicleHash);
Vehicle vehicle = CREATE_VEHICLE(m_StartVehicleHash, m_StartLocation.x, m_StartLocation.y,
m_StartLocation.z, m_StartHeading, true, false, false);
Vehicle vehicle = CREATE_VEHICLE(m_StartVehicleHash, m_StartLocation.x, m_StartLocation.y, m_StartLocation.z,
m_StartHeading, true, false, false);
SET_PED_INTO_VEHICLE(player, vehicle, -1);
}

Expand Down Expand Up @@ -59,8 +59,8 @@ void CrossingChallenge::ControlRespawn()
SET_TIME_SCALE(1.f);
ANIMPOSTFX_STOP_ALL();
NETWORK_REQUEST_CONTROL_OF_ENTITY(player);
NETWORK_RESURRECT_LOCAL_PLAYER(m_StartLocation.x, m_StartLocation.y, m_StartLocation.z, m_StartHeading,
false, false, false);
NETWORK_RESURRECT_LOCAL_PLAYER(m_StartLocation.x, m_StartLocation.y, m_StartLocation.z, m_StartHeading, false,
false, false);
WAIT(2000);
if (vehicle)
{
Expand All @@ -86,15 +86,15 @@ void CrossingChallenge::ControlRespawn()
DISPLAY_HUD(true);
FREEZE_ENTITY_POSITION(player, false);

m_TickCount = 0;
m_TickCount = 0;
m_EffectsCount = 0;
m_TimerStarted = false;
}
}

static bool LoadScaleform(int &handle, bool &loading, const std::string &name)
{
if (!handle || !loading && !HAS_SCALEFORM_MOVIE_LOADED(handle))
if (!handle || (!loading && !HAS_SCALEFORM_MOVIE_LOADED(handle)))
{
handle = REQUEST_SCALEFORM_MOVIE(name.c_str());
loading = true;
Expand Down Expand Up @@ -200,12 +200,12 @@ void CrossingChallenge::SaveConfig()
m_ConfigFile.SetValue<float>("StartLocationX", m_StartLocation.x);
m_ConfigFile.SetValue<float>("StartLocationY", m_StartLocation.y);
m_ConfigFile.SetValue<float>("StartLocationZ", m_StartLocation.z);
m_ConfigFile.SetValue<float>("StartVehicle", m_StartVehicleHash);
m_ConfigFile.SetValue<Hash>("StartHeading", m_StartHeading);
m_ConfigFile.SetValue<Hash>("StartVehicle", m_StartVehicleHash);
m_ConfigFile.SetValue<float>("StartHeading", m_StartHeading);
m_ConfigFile.SetValue<float>("StartCameraHeading", m_StartCameraHeading);
m_ConfigFile.SetValue<float>("StartWeather1", m_StartWeatherType1);
m_ConfigFile.SetValue<Hash>("StartWeather1", m_StartWeatherType1);
m_ConfigFile.SetValue<Hash>("StartWeather2", m_StartWeatherType2);
m_ConfigFile.SetValue<Hash>("StartWeatherPercent", m_StartWeatherPercent);
m_ConfigFile.SetValue<float>("StartWeatherPercent", m_StartWeatherPercent);
m_ConfigFile.SetValue<int>("StartHours", m_ClockHours);
m_ConfigFile.SetValue<int>("StartMinutes", m_ClockMinutes);
m_ConfigFile.SetValue<int>("StartSeconds", m_ClockSeconds);
Expand All @@ -224,7 +224,7 @@ void CrossingChallenge::SaveConfig()

void CrossingChallenge::CaptureStart()
{
Ped player = PLAYER_PED_ID();
Ped player = PLAYER_PED_ID();

m_StartEnabled = true;
m_StartLocation = GET_ENTITY_COORDS(player, false);
Expand Down Expand Up @@ -413,7 +413,7 @@ void CrossingChallenge::ShowHelpButtons()
DRAW_SCALEFORM_MOVIE_FULLSCREEN(m_ButtonsScaleformHandle, 255, 255, 255, 255, 0);
}

static void HandleBlip(Blip& blip, Vector3 coords, int color, const std::string &name)
static void HandleBlip(Blip &blip, Vector3 coords, int color, const std::string &name)
{
if (!blip || !DOES_BLIP_EXIST(blip))
{
Expand Down Expand Up @@ -524,7 +524,7 @@ void CrossingChallenge::OnRun()
GetComponent<EffectDispatchTimer>()->SetTimerEnabled(true);
}

m_TickCount = 0;
m_TickCount = 0;
m_EffectsCount = 0;
m_TimerStarted = false;

Expand Down Expand Up @@ -553,7 +553,7 @@ void CrossingChallenge::OnRun()
ControlPassed();

int deltaTicks = GetTickCount64() - m_LastTick;
m_LastTick = GetTickCount64();
m_LastTick = GetTickCount64();
if (m_TimerStarted && deltaTicks < 1000)
m_TickCount += deltaTicks;

Expand Down
20 changes: 10 additions & 10 deletions ChaosMod/Components/DebugMenu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ DebugMenu::DebugMenu() : Component()
std::sort(m_Effects.begin(), m_Effects.end(),
[](const DebugEffect &a, const DebugEffect &b)
{
for (int idx = 0;; idx++)
for (size_t idx = 0;; idx++)
{
if (idx >= a.EffectName.size())
return false;
Expand Down Expand Up @@ -83,16 +83,16 @@ void DebugMenu::OnRun()
GetComponent<EffectDispatcher>()->DispatchEffect(m_Effects[m_SelectedIdx].Id);
}

float y = .1f;
WORD remainingDrawItems = MAX_VIS_ITEMS;
float y = .1f;
size_t remainingDrawItems = MAX_VIS_ITEMS;

for (int i = 0; remainingDrawItems > 0; i++)
for (int64_t i = 0; remainingDrawItems > 0; i++)
{
short overflow = MAX_VIS_ITEMS / 2 - (m_Effects.size() - 1 - m_SelectedIdx);
int64_t bias = MAX_VIS_ITEMS / 2 - (m_Effects.size() - 1 - m_SelectedIdx);

if (i < 0 || i < m_SelectedIdx - remainingDrawItems / 2 - (overflow > 0 ? overflow : 0))
if (i < static_cast<int64_t>(m_SelectedIdx - remainingDrawItems / 2 - (bias > 0 ? bias : 0)))
continue;
else if (i >= m_Effects.size())
else if (i >= static_cast<int64_t>(m_Effects.size()))
break;

BEGIN_TEXT_COMMAND_DISPLAY_TEXT("STRING");
Expand Down Expand Up @@ -153,7 +153,7 @@ void DebugMenu::OnKeyInput(DWORD key, bool repeated, bool isUpNow, bool isCtrlPr

break;
case VK_DOWN:
if (++m_SelectedIdx >= m_Effects.size())
if (static_cast<size_t>(++m_SelectedIdx) >= m_Effects.size())
m_SelectedIdx = 0;

break;
Expand All @@ -167,7 +167,7 @@ void DebugMenu::OnKeyInput(DWORD key, bool repeated, bool isUpNow, bool isCtrlPr
if (searchChar++ == SCHAR_MAX)
searchChar = SCHAR_MIN;

for (int idx = 0; idx < m_Effects.size(); idx++)
for (size_t idx = 0; idx < m_Effects.size(); idx++)
{
if (std::tolower(m_Effects[idx].EffectName[0]) == searchChar)
{
Expand All @@ -192,7 +192,7 @@ void DebugMenu::OnKeyInput(DWORD key, bool repeated, bool isUpNow, bool isCtrlPr
if (searchChar-- == SCHAR_MIN)
searchChar = SCHAR_MAX;

for (int idx = 0; idx < m_Effects.size(); idx++)
for (size_t idx = 0; idx < m_Effects.size(); idx++)
{
if (std::tolower(m_Effects[idx].EffectName[0]) == searchChar)
{
Expand Down
11 changes: 5 additions & 6 deletions ChaosMod/Components/DebugMenu.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,9 @@

#include "Effects/EffectIdentifier.h"

#include <cstdint>
#include <vector>

using DWORD = unsigned long;

class DebugMenu : public Component
{
struct DebugEffect
Expand All @@ -25,11 +24,11 @@ class DebugMenu : public Component

bool m_IsEnabled;

int m_SelectedIdx = 0;
bool m_Visible = false;
int64_t m_SelectedIdx = 0;
bool m_Visible = false;

DWORD m_RepeatTime = 0;
bool m_DispatchEffect = false;
std::uint32_t m_RepeatTime = 0;
bool m_DispatchEffect = false;

public:
DebugMenu();
Expand Down
13 changes: 7 additions & 6 deletions ChaosMod/Components/EffectDispatchTimer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ EffectDispatchTimer::EffectDispatchTimer(const std::array<BYTE, 3> &timerColor)
m_DistanceChaosState.EnableDistanceBasedEffectDispatch = g_OptionsManager.GetConfigValue(
{ "EnableDistanceBasedEffectDispatch" }, OPTION_DEFAULT_DISTANCE_BASED_DISPATCH_ENABLED);
m_DistanceChaosState.DistanceToActivateEffect =
g_OptionsManager.GetConfigValue({ "DistanceToActivateEffect" }, OPTION_DEFAULT_EFFECT_SPAWN_DISTANCE);
g_OptionsManager.GetConfigValue<float>({ "DistanceToActivateEffect" }, OPTION_DEFAULT_EFFECT_SPAWN_DISTANCE);
m_DistanceChaosState.DistanceType = static_cast<DistanceChaosState::TravelledDistanceType>(
g_OptionsManager.GetConfigValue({ "DistanceType" }, OPTION_DEFAULT_DISTANCE_TYPE));
}
Expand Down Expand Up @@ -128,16 +128,17 @@ std::uint64_t EffectDispatchTimer::GetTimer() const

void EffectDispatchTimer::ResetTimer()
{
m_TimerPercentage = 0.f;
m_Timer = GetTickCount64();
m_TimerPercentage = 0.f;
m_Timer = GetTickCount64();
m_DistanceChaosState.SavedPosition = GET_ENTITY_COORDS(PLAYER_PED_ID(), false);
}

int EffectDispatchTimer::GetRemainingTimerTime() const
{
return std::ceil(m_EffectSpawnTime
/ (!ComponentExists<MetaModifiers>() ? 1.f : GetComponent<MetaModifiers>()->TimerSpeedModifier)
* (1.f - m_TimerPercentage));
return static_cast<int>(
std::ceil(m_EffectSpawnTime
/ (!ComponentExists<MetaModifiers>() ? 1.f : GetComponent<MetaModifiers>()->TimerSpeedModifier)
* (1.f - m_TimerPercentage)));
}

bool EffectDispatchTimer::ShouldDispatchEffectNow() const
Expand Down
14 changes: 6 additions & 8 deletions ChaosMod/Components/EffectDispatcher.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,7 @@ static void _DispatchEffect(EffectDispatcher *effectDispatcher, const EffectDisp
// Reset weight of this effect (or every effect in group) to reduce chance of same effect (group) happening multiple
// times in a row
if (effectData.GroupType.empty())
{
effectData.Weight = effectData.WeightMult;
}
else
{
for (auto &effectData : filteredEffects)
Expand Down Expand Up @@ -132,7 +130,7 @@ static void _DispatchEffect(EffectDispatcher *effectDispatcher, const EffectDisp
if (!entry.Suffix.empty())
effectName << " " << entry.Suffix;

int effectDuration = 0;
float effectDuration = 0;
switch (effectData.TimedType)
{
case EffectTimedType::NotTimed:
Expand Down Expand Up @@ -199,15 +197,15 @@ static void _OnRunEffects(LPVOID data)
while (true)
{
auto curTime = GetTickCount64();
int deltaTime =
float deltaTime =
!ComponentExists<EffectDispatchTimer>()
? 0
: (curTime - lastTime)
* (ComponentExists<MetaModifiers>() ? GetComponent<MetaModifiers>()->EffectDurationModifier
: 1.f);
// The game was paused
if (deltaTime > 1000)
deltaTime = 0;
if (deltaTime > 1000.f)
deltaTime = 0.f;

lastTime = curTime;

Expand Down Expand Up @@ -279,7 +277,7 @@ void EffectDispatcher::OnRun()
DrawEffectTexts();
}

void EffectDispatcher::UpdateEffects(int deltaTime)
void EffectDispatcher::UpdateEffects(float deltaTime)
{
if (m_ClearEffectsState != ClearEffectsState::None)
{
Expand Down Expand Up @@ -396,7 +394,7 @@ void EffectDispatcher::UpdateEffects(int deltaTime)
}
}

void EffectDispatcher::UpdateMetaEffects(int deltaTime)
void EffectDispatcher::UpdateMetaEffects(float deltaTime)
{
if (!SharedState.MetaEffectsEnabled)
return;
Expand Down
4 changes: 2 additions & 2 deletions ChaosMod/Components/EffectDispatcher.h
Original file line number Diff line number Diff line change
Expand Up @@ -116,8 +116,8 @@ class EffectDispatcher : public Component
void DispatchRandomEffect(DispatchEffectFlags dispatchEffectFlags = DispatchEffectFlag_None,
const std::string &suffix = {});

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

void ClearEffect(const EffectIdentifier &effectId);
enum ClearEffectsFlags
Expand Down
17 changes: 9 additions & 8 deletions ChaosMod/Components/LuaScripts.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,7 @@ class LuaHolder
return _TryParseVector3(&m_Data, x, y, z) ? LuaVector3(x, y, z) : LuaVector3();
}

#pragma GCC diagnostic ignored "-Wstrict-aliasing"
return *reinterpret_cast<T *>(&m_Data);
}

Expand Down Expand Up @@ -804,7 +805,7 @@ LuaScripts::ParseScript(std::string scriptName, const std::string &script, Parse
else
{
effectData.TimedType = EffectTimedType::Custom;
effectData.CustomTime = (std::max)(1, *durationOpt);
effectData.CustomTime = static_cast<float>(std::max(1, *durationOpt));
}
}
else
Expand All @@ -817,7 +818,7 @@ LuaScripts::ParseScript(std::string scriptName, const std::string &script, Parse
{
effectData.TimedType = static_cast<EffectTimedType>(settingOverrides["TimedType"]);
}
catch (nlohmann::json::exception)
catch (nlohmann::json::exception &)
{
}
try
Expand All @@ -826,21 +827,21 @@ LuaScripts::ParseScript(std::string scriptName, const std::string &script, Parse
if (effectData.CustomTime > 0)
effectData.TimedType = EffectTimedType::Custom;
}
catch (nlohmann::json::exception)
catch (nlohmann::json::exception &)
{
}

const sol::optional<int> &weightMultOpt = effectInfo["WeightMultiplier"];
if (weightMultOpt)
{
effectData.WeightMult = (std::max)(1, *weightMultOpt);
effectData.WeightMult = static_cast<float>(std::max(1, *weightMultOpt));
effectData.Weight = effectData.WeightMult;
}
try
{
effectData.WeightMult = settingOverrides["WeightMult"];
}
catch (nlohmann::json::exception)
catch (nlohmann::json::exception &)
{
}

Expand All @@ -855,7 +856,7 @@ LuaScripts::ParseScript(std::string scriptName, const std::string &script, Parse
{
effectData.SetAttribute(EffectAttributes::ExcludedFromVoting, settingOverrides["ExcludedFromVoting"]);
}
catch (nlohmann::json::exception)
catch (nlohmann::json::exception &)
{
}

Expand Down Expand Up @@ -914,7 +915,7 @@ LuaScripts::ParseScript(std::string scriptName, const std::string &script, Parse
{
effectData.ShortcutKeycode = settingOverrides["ShortcutKeycode"];
}
catch (nlohmann::json::exception)
catch (nlohmann::json::exception &)
{
}

Expand All @@ -924,7 +925,7 @@ LuaScripts::ParseScript(std::string scriptName, const std::string &script, Parse
if (!name.empty())
effectData.CustomName = name;
}
catch (nlohmann::json::exception)
catch (nlohmann::json::exception &)
{
}

Expand Down
Loading

0 comments on commit 3d7b559

Please sign in to comment.