From 4b3b5952270e986b9bad1d6f2112c3f32928cb06 Mon Sep 17 00:00:00 2001 From: jadebenn Date: Mon, 25 Dec 2023 14:32:04 -0600 Subject: [PATCH 01/12] cast and code cleanup --- CMakeLists.txt | 2 +- dChatServer/ChatPacketHandler.cpp | 10 +++--- dChatServer/PlayerContainer.cpp | 2 +- dCommon/AmfSerialize.cpp | 4 +-- dCommon/LDFFormat.h | 22 ++++++------- dCommon/Metrics.cpp | 32 +++++++++---------- dCommon/dEnums/StringifiedEnum.h | 2 +- dCommon/dEnums/dCommonVars.h | 4 +-- .../CDComponentsRegistryTable.cpp | 8 ++--- dDatabase/GameDatabase/MigrationRunner.cpp | 4 +-- dGame/Entity.cpp | 4 +-- dGame/EntityManager.cpp | 12 +++---- dGame/dComponents/BaseCombatAIComponent.cpp | 2 +- dGame/dComponents/BuffComponent.cpp | 6 ++-- dGame/dComponents/CharacterComponent.cpp | 8 ++--- dGame/dComponents/DestroyableComponent.cpp | 2 +- dGame/dComponents/ModuleAssemblyComponent.cpp | 2 +- dGame/dComponents/MovingPlatformComponent.cpp | 8 ++--- dGame/dComponents/PetComponent.cpp | 8 ++--- .../dComponents/PropertyEntranceComponent.cpp | 2 +- dGame/dComponents/RacingControlComponent.cpp | 6 ++-- dGame/dComponents/RebuildComponent.cpp | 4 +-- .../dComponents/ScriptedActivityComponent.cpp | 4 +-- dGame/dGameMessages/GameMessages.cpp | 6 ++-- dGame/dGameMessages/PropertyDataMessage.cpp | 22 ++++++------- .../PropertySelectQueryProperty.cpp | 12 +++---- dGame/dInventory/Item.cpp | 2 +- dGame/dUtilities/SlashCommandHandler.cpp | 2 +- dNavigation/dTerrain/RawChunk.cpp | 18 +++++------ dNet/AuthPackets.cpp | 32 +++++++++---------- dNet/ChatPackets.cpp | 28 ++++++++-------- dNet/PacketUtils.cpp | 2 +- dNet/WorldPackets.cpp | 6 ++-- dScripts/02_server/Map/NS/NsLegoClubDoor.cpp | 2 +- dScripts/02_server/Map/NS/NsLupTeleport.cpp | 2 +- .../02_server/Map/NS/Waves/ZoneNsWaves.cpp | 2 +- .../boss_instance/NjMonastryBossInstance.cpp | 10 +++--- dScripts/BaseSurvivalServer.cpp | 4 +-- dScripts/BaseWavesServer.cpp | 8 ++--- .../ai/MINIGAME/SG_GF/SERVER/SGCannon.cpp | 8 ++--- dZoneManager/Zone.cpp | 2 +- dZoneManager/Zone.h | 4 +-- 42 files changed, 165 insertions(+), 165 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 7e9823467..0a05b6f9e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -58,7 +58,7 @@ if(UNIX) if(APPLE) set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=gnu++17 -O2 -Wuninitialized -D_GLIBCXX_USE_CXX11_ABI=0 -D_GLIBCXX_USE_CXX17_ABI=0 -fPIC") else() - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=gnu++17 -O2 -Wuninitialized -D_GLIBCXX_USE_CXX11_ABI=0 -D_GLIBCXX_USE_CXX17_ABI=0 -static-libgcc -fPIC -lstdc++fs") + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=gnu++17 -O2 -Wuninitialized -D_GLIBCXX_USE_CXX11_ABI=0 -D_GLIBCXX_USE_CXX17_ABI=0 -Wold-style-cast -static-libgcc -fPIC -lstdc++fs") endif() if (__dynamic AND CMAKE_CXX_COMPILER_ID STREQUAL "GNU") set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -rdynamic") diff --git a/dChatServer/ChatPacketHandler.cpp b/dChatServer/ChatPacketHandler.cpp index 46a54888e..d1f0fc747 100644 --- a/dChatServer/ChatPacketHandler.cpp +++ b/dChatServer/ChatPacketHandler.cpp @@ -66,7 +66,7 @@ void ChatPacketHandler::HandleFriendlistRequest(Packet* packet) { BitStreamUtils::WriteHeader(bitStream, eConnectionType::CLIENT, eClientMessageType::GET_FRIENDS_LIST_RESPONSE); bitStream.Write(0); bitStream.Write(1); //Length of packet -- just writing one as it doesn't matter, client skips it. - bitStream.Write((uint16_t)player->friends.size()); + bitStream.Write(player->friends.size()); for (auto& data : player->friends) { data.Serialize(bitStream); @@ -705,7 +705,7 @@ void ChatPacketHandler::SendTeamInviteConfirm(PlayerData* receiver, bool bLeader bitStream.Write(ucLootFlag); bitStream.Write(ucNumOfOtherPlayers); bitStream.Write(ucResponseCode); - bitStream.Write(static_cast(wsLeaderName.size())); + bitStream.Write(wsLeaderName.size()); for (const auto character : wsLeaderName) { bitStream.Write(character); } @@ -730,7 +730,7 @@ void ChatPacketHandler::SendTeamStatus(PlayerData* receiver, LWOOBJID i64LeaderI bitStream.Write(0); // BinaryBuffe, no clue what's in here bitStream.Write(ucLootFlag); bitStream.Write(ucNumOfOtherPlayers); - bitStream.Write(static_cast(wsLeaderName.size())); + bitStream.Write(wsLeaderName.size()); for (const auto character : wsLeaderName) { bitStream.Write(character); } @@ -771,7 +771,7 @@ void ChatPacketHandler::SendTeamAddPlayer(PlayerData* receiver, bool bIsFreeTria bitStream.Write(bLocal); bitStream.Write(bNoLootOnDeath); bitStream.Write(i64PlayerID); - bitStream.Write(static_cast(wsPlayerName.size())); + bitStream.Write(wsPlayerName.size()); for (const auto character : wsPlayerName) { bitStream.Write(character); } @@ -802,7 +802,7 @@ void ChatPacketHandler::SendTeamRemovePlayer(PlayerData* receiver, bool bDisband bitStream.Write(bLocal); bitStream.Write(i64LeaderID); bitStream.Write(i64PlayerID); - bitStream.Write(static_cast(wsPlayerName.size())); + bitStream.Write(wsPlayerName.size()); for (const auto character : wsPlayerName) { bitStream.Write(character); } diff --git a/dChatServer/PlayerContainer.cpp b/dChatServer/PlayerContainer.cpp index d9b33825f..f309ea0a4 100644 --- a/dChatServer/PlayerContainer.cpp +++ b/dChatServer/PlayerContainer.cpp @@ -354,7 +354,7 @@ void PlayerContainer::UpdateTeamsOnWorld(TeamData* team, bool deleteTeam) { if (!deleteTeam) { bitStream.Write(team->lootFlag); - bitStream.Write(static_cast(team->memberIDs.size())); + bitStream.Write(team->memberIDs.size()); for (const auto memberID : team->memberIDs) { bitStream.Write(memberID); } diff --git a/dCommon/AmfSerialize.cpp b/dCommon/AmfSerialize.cpp index 08f1eaadb..5898874e4 100644 --- a/dCommon/AmfSerialize.cpp +++ b/dCommon/AmfSerialize.cpp @@ -105,8 +105,8 @@ void WriteFlagNumber(RakNet::BitStream* bs, uint32_t v) { * RakNet writes in the correct byte order - do not reverse this. */ void WriteAMFString(RakNet::BitStream* bs, const std::string& str) { - WriteFlagNumber(bs, (uint32_t)str.size()); - bs->Write(str.c_str(), (uint32_t)str.size()); + WriteFlagNumber(bs, static_cast(str.size())); + bs->Write(str.c_str(), static_cast(str.size())); } /** diff --git a/dCommon/LDFFormat.h b/dCommon/LDFFormat.h index 0921d04c0..7bcc91a25 100644 --- a/dCommon/LDFFormat.h +++ b/dCommon/LDFFormat.h @@ -63,15 +63,15 @@ class LDFData: public LDFBaseData { //! Writes the key to the packet void WriteKey(RakNet::BitStream* packet) { - packet->Write(static_cast(this->key.length() * sizeof(uint16_t))); + packet->Write(this->key.length() * sizeof(uint16_t)); for (uint32_t i = 0; i < this->key.length(); ++i) { - packet->Write(static_cast(this->key[i])); + packet->Write(this->key[i]); } } //! Writes the value to the packet void WriteValue(RakNet::BitStream* packet) { - packet->Write(static_cast(this->GetValueType())); + packet->Write(this->GetValueType()); packet->Write(this->value); } @@ -179,30 +179,30 @@ template<> inline eLDFType LDFData::GetValueType(void) { return LDF // The specialized version for std::u16string (UTF-16) template<> inline void LDFData::WriteValue(RakNet::BitStream* packet) { - packet->Write(static_cast(this->GetValueType())); + packet->Write(this->GetValueType()); - packet->Write(static_cast(this->value.length())); + packet->Write(this->value.length()); for (uint32_t i = 0; i < this->value.length(); ++i) { - packet->Write(static_cast(this->value[i])); + packet->Write(this->value[i]); } } // The specialized version for bool template<> inline void LDFData::WriteValue(RakNet::BitStream* packet) { - packet->Write(static_cast(this->GetValueType())); + packet->Write(this->GetValueType()); - packet->Write(static_cast(this->value)); + packet->Write(this->value); } // The specialized version for std::string (UTF-8) template<> inline void LDFData::WriteValue(RakNet::BitStream* packet) { - packet->Write(static_cast(this->GetValueType())); + packet->Write(this->GetValueType()); - packet->Write(static_cast(this->value.length())); + packet->Write(this->value.length()); for (uint32_t i = 0; i < this->value.length(); ++i) { - packet->Write(static_cast(this->value[i])); + packet->Write(this->value[i]); } } diff --git a/dCommon/Metrics.cpp b/dCommon/Metrics.cpp index b97b54352..8df431472 100644 --- a/dCommon/Metrics.cpp +++ b/dCommon/Metrics.cpp @@ -193,34 +193,34 @@ size_t Metrics::GetPeakRSS() { /* Windows -------------------------------------------------- */ PROCESS_MEMORY_COUNTERS info; GetProcessMemoryInfo(GetCurrentProcess(), &info, sizeof(info)); - return (size_t)info.PeakWorkingSetSize; + return static_cast(info.PeakWorkingSetSize); #elif (defined(_AIX) || defined(__TOS__AIX__)) || (defined(__sun__) || defined(__sun) || defined(sun) && (defined(__SVR4) || defined(__svr4__))) /* AIX and Solaris ------------------------------------------ */ struct psinfo psinfo; int fd = -1; if ((fd = open("/proc/self/psinfo", O_RDONLY)) == -1) - return (size_t)0L; /* Can't open? */ + return static_cast(0L); /* Can't open? */ if (read(fd, &psinfo, sizeof(psinfo)) != sizeof(psinfo)) { close(fd); - return (size_t)0L; /* Can't read? */ + return static_cast(0L); /* Can't read? */ } close(fd); - return (size_t)(psinfo.pr_rssize * 1024L); + return static_cast(psinfo.pr_rssize * 1024L); #elif defined(__unix__) || defined(__unix) || defined(unix) || (defined(__APPLE__) && defined(__MACH__)) /* BSD, Linux, and OSX -------------------------------------- */ struct rusage rusage; getrusage(RUSAGE_SELF, &rusage); #if defined(__APPLE__) && defined(__MACH__) - return (size_t)rusage.ru_maxrss; + return static_cast(rusage.ru_maxrss); #else - return (size_t)(rusage.ru_maxrss * 1024L); + return static_cast(rusage.ru_maxrss * 1024L); #endif #else /* Unknown OS ----------------------------------------------- */ - return (size_t)0L; /* Unsupported. */ + return static_cast(0L); /* Unsupported. */ #endif } @@ -234,33 +234,33 @@ size_t Metrics::GetCurrentRSS() { /* Windows -------------------------------------------------- */ PROCESS_MEMORY_COUNTERS info; GetProcessMemoryInfo(GetCurrentProcess(), &info, sizeof(info)); - return (size_t)info.WorkingSetSize; + return static_cast(info.WorkingSetSize); #elif defined(__APPLE__) && defined(__MACH__) /* OSX ------------------------------------------------------ */ struct mach_task_basic_info info; mach_msg_type_number_t infoCount = MACH_TASK_BASIC_INFO_COUNT; - if (task_info(mach_task_self(), MACH_TASK_BASIC_INFO, - (task_info_t)&info, &infoCount) != KERN_SUCCESS) - return (size_t)0L; /* Can't access? */ - return (size_t)info.resident_size; + if (static_cast(mach_task_self(), MACH_TASK_BASIC_INFO, + static_cast(&info), &infoCount) != KERN_SUCCESS) + return static_cast(0L); /* Can't access? */ + return static_cast(info.resident_size); #elif defined(__linux__) || defined(__linux) || defined(linux) || defined(__gnu_linux__) /* Linux ---------------------------------------------------- */ long rss = 0L; FILE* fp = NULL; if ((fp = fopen("/proc/self/statm", "r")) == NULL) - return (size_t)0L; /* Can't open? */ + return static_cast(0L); /* Can't open? */ if (fscanf(fp, "%*s%ld", &rss) != 1) { fclose(fp); - return (size_t)0L; /* Can't read? */ + return static_cast(0L); /* Can't read? */ } fclose(fp); - return (size_t)rss * (size_t)sysconf(_SC_PAGESIZE); + return static_cast(rss) * static_cast(sysconf(_SC_PAGESIZE)); #else /* AIX, BSD, Solaris, and Unknown OS ------------------------ */ - return (size_t)0L; /* Unsupported. */ + return static_cast(0L); /* Unsupported. */ #endif } diff --git a/dCommon/dEnums/StringifiedEnum.h b/dCommon/dEnums/StringifiedEnum.h index ee7402ec2..16eafdca3 100644 --- a/dCommon/dEnums/StringifiedEnum.h +++ b/dCommon/dEnums/StringifiedEnum.h @@ -10,13 +10,13 @@ namespace StringifiedEnum { static_assert(std::is_enum_v, "Not an enum"); // Check type constexpr auto sv = &magic_enum::enum_entries(); - std::string_view output; const auto it = std::lower_bound( sv->begin(), sv->end(), e, [&](const std::pair& lhs, const T rhs) { return lhs.first < rhs; } ); + std::string_view output; if (it != sv->end() && it->first == e) { output = it->second; } else { diff --git a/dCommon/dEnums/dCommonVars.h b/dCommon/dEnums/dCommonVars.h index dc7a1d545..513e9c8fd 100644 --- a/dCommon/dEnums/dCommonVars.h +++ b/dCommon/dEnums/dCommonVars.h @@ -148,11 +148,11 @@ struct FriendData { if (size > maxSize) size = maxSize; for (uint32_t i = 0; i < size; ++i) { - bitStream.Write(static_cast(friendName[i])); + bitStream.Write(friendName[i]); } for (uint32_t j = 0; j < remSize; ++j) { - bitStream.Write(static_cast(0)); + bitStream.Write(0); } bitStream.Write(0); //??? diff --git a/dDatabase/CDClientDatabase/CDClientTables/CDComponentsRegistryTable.cpp b/dDatabase/CDClientDatabase/CDClientTables/CDComponentsRegistryTable.cpp index ac547a241..e6b293388 100644 --- a/dDatabase/CDClientDatabase/CDClientTables/CDComponentsRegistryTable.cpp +++ b/dDatabase/CDClientDatabase/CDClientTables/CDComponentsRegistryTable.cpp @@ -10,7 +10,7 @@ void CDComponentsRegistryTable::LoadValuesFromDatabase() { entry.component_type = static_cast(tableData.getIntField("component_type", 0)); entry.component_id = tableData.getIntField("component_id", -1); - this->mappedEntries.insert_or_assign(((uint64_t)entry.component_type) << 32 | ((uint64_t)entry.id), entry.component_id); + this->mappedEntries.insert_or_assign(static_cast(entry.component_type) << 32 | static_cast(entry.id), entry.component_id); this->mappedEntries.insert_or_assign(entry.id, 0); tableData.nextRow(); @@ -22,7 +22,7 @@ void CDComponentsRegistryTable::LoadValuesFromDatabase() { int32_t CDComponentsRegistryTable::GetByIDAndType(uint32_t id, eReplicaComponentType componentType, int32_t defaultValue) { auto exists = mappedEntries.find(id); if (exists != mappedEntries.end()) { - auto iter = mappedEntries.find(((uint64_t)componentType) << 32 | ((uint64_t)id)); + auto iter = mappedEntries.find(static_cast(componentType) << 32 | static_cast(id)); return iter == mappedEntries.end() ? defaultValue : iter->second; } @@ -38,14 +38,14 @@ int32_t CDComponentsRegistryTable::GetByIDAndType(uint32_t id, eReplicaComponent entry.component_type = static_cast(tableData.getIntField("component_type", 0)); entry.component_id = tableData.getIntField("component_id", -1); - this->mappedEntries.insert_or_assign(((uint64_t)entry.component_type) << 32 | ((uint64_t)entry.id), entry.component_id); + this->mappedEntries.insert_or_assign(staitc_cast(entry.component_type) << 32 | static_cast(entry.id), entry.component_id); tableData.nextRow(); } mappedEntries.insert_or_assign(id, 0); - auto iter = this->mappedEntries.find(((uint64_t)componentType) << 32 | ((uint64_t)id)); + auto iter = this->mappedEntries.find(static_cast(componentType) << 32 | static_cast(id)); return iter == this->mappedEntries.end() ? defaultValue : iter->second; } diff --git a/dDatabase/GameDatabase/MigrationRunner.cpp b/dDatabase/GameDatabase/MigrationRunner.cpp index 6bc3954da..8034a3e20 100644 --- a/dDatabase/GameDatabase/MigrationRunner.cpp +++ b/dDatabase/GameDatabase/MigrationRunner.cpp @@ -95,7 +95,7 @@ void MigrationRunner::RunSQLiteMigrations() { // Check if there is an entry in the migration history table on the cdclient database. cdstmt = CDClientDatabase::CreatePreppedStmt("SELECT name FROM migration_history WHERE name = ?;"); - cdstmt.bind((int32_t) 1, migration.name.c_str()); + cdstmt.bind(static_cast(1), migration.name.c_str()); auto cdres = cdstmt.execQuery(); if (!cdres.eof()) continue; @@ -124,7 +124,7 @@ void MigrationRunner::RunSQLiteMigrations() { // Insert into cdclient database. cdstmt = CDClientDatabase::CreatePreppedStmt("INSERT INTO migration_history (name) VALUES (?);"); - cdstmt.bind((int32_t) 1, migration.name.c_str()); + cdstmt.bind(static_cast(1), migration.name.c_str()); cdstmt.execQuery(); CDClientDatabase::ExecuteQuery("COMMIT;"); } diff --git a/dGame/Entity.cpp b/dGame/Entity.cpp index cbbbb4d4c..0caeada8f 100644 --- a/dGame/Entity.cpp +++ b/dGame/Entity.cpp @@ -982,9 +982,9 @@ void Entity::WriteBaseReplicaData(RakNet::BitStream* outBitStream, eReplicaPacke } outBitStream->Write(m_ChildEntities.size() > 0); if (m_ChildEntities.size() > 0) { - outBitStream->Write((uint16_t)m_ChildEntities.size()); + outBitStream->Write(m_ChildEntities.size()); for (Entity* child : m_ChildEntities) { - outBitStream->Write((uint64_t)child->GetObjectID()); + outBitStream->Write(child->GetObjectID()); } } } diff --git a/dGame/EntityManager.cpp b/dGame/EntityManager.cpp index cfbd71d95..493e910e5 100644 --- a/dGame/EntityManager.cpp +++ b/dGame/EntityManager.cpp @@ -181,8 +181,8 @@ void EntityManager::SerializeEntities() { m_SerializationCounter++; RakNet::BitStream stream; - stream.Write(static_cast(ID_REPLICA_MANAGER_SERIALIZE)); - stream.Write(static_cast(entity->GetNetworkId())); + stream.Write(ID_REPLICA_MANAGER_SERIALIZE); + stream.Write(entity->GetNetworkId()); entity->WriteBaseReplicaData(&stream, eReplicaPacketType::SERIALIZATION); entity->WriteComponents(&stream, eReplicaPacketType::SERIALIZATION); @@ -366,9 +366,9 @@ void EntityManager::ConstructEntity(Entity* entity, const SystemAddress& sysAddr RakNet::BitStream stream; - stream.Write(static_cast(ID_REPLICA_MANAGER_CONSTRUCTION)); + stream.Write(ID_REPLICA_MANAGER_CONSTRUCTION); stream.Write(true); - stream.Write(static_cast(entity->GetNetworkId())); + stream.Write(entity->GetNetworkId()); entity->WriteBaseReplicaData(&stream, eReplicaPacketType::CONSTRUCTION); entity->WriteComponents(&stream, eReplicaPacketType::CONSTRUCTION); @@ -416,8 +416,8 @@ void EntityManager::DestructEntity(Entity* entity, const SystemAddress& sysAddr) RakNet::BitStream stream; - stream.Write(static_cast(ID_REPLICA_MANAGER_DESTRUCTION)); - stream.Write(static_cast(entity->GetNetworkId())); + stream.Write(ID_REPLICA_MANAGER_DESTRUCTION); + stream.Write(entity->GetNetworkId()); Game::server->Send(&stream, sysAddr, sysAddr == UNASSIGNED_SYSTEM_ADDRESS); diff --git a/dGame/dComponents/BaseCombatAIComponent.cpp b/dGame/dComponents/BaseCombatAIComponent.cpp index 1961e6d6c..26b95fa81 100644 --- a/dGame/dComponents/BaseCombatAIComponent.cpp +++ b/dGame/dComponents/BaseCombatAIComponent.cpp @@ -523,7 +523,7 @@ bool BaseCombatAIComponent::IsMech() { void BaseCombatAIComponent::Serialize(RakNet::BitStream* outBitStream, bool bIsInitialUpdate) { outBitStream->Write(m_DirtyStateOrTarget || bIsInitialUpdate); if (m_DirtyStateOrTarget || bIsInitialUpdate) { - outBitStream->Write(uint32_t(m_State)); + outBitStream->Write(m_State); outBitStream->Write(m_Target); m_DirtyStateOrTarget = false; } diff --git a/dGame/dComponents/BuffComponent.cpp b/dGame/dComponents/BuffComponent.cpp index c901c19d2..80c294566 100644 --- a/dGame/dComponents/BuffComponent.cpp +++ b/dGame/dComponents/BuffComponent.cpp @@ -41,7 +41,7 @@ void BuffComponent::Serialize(RakNet::BitStream* outBitStream, bool bIsInitialUp for (const auto& [id, buff] : m_Buffs) { outBitStream->Write(id); outBitStream->Write(buff.time != 0.0f); - if (buff.time != 0.0f) outBitStream->Write(static_cast(buff.time * 1000.0f)); + if (buff.time != 0.0f) outBitStream->Write(buff.time * 1000.0f); outBitStream->Write(buff.cancelOnDeath); outBitStream->Write(buff.cancelOnZone); outBitStream->Write(buff.cancelOnDamaged); @@ -147,8 +147,8 @@ void BuffComponent::ApplyBuff(const int32_t id, const float duration, const LWOO addedByTeammate = std::count(team->members.begin(), team->members.end(), m_Parent->GetObjectID()) > 0; } - GameMessages::SendAddBuff(const_cast(m_Parent->GetObjectID()), source, (uint32_t)id, - (uint32_t)duration * 1000, addImmunity, cancelOnDamaged, cancelOnDeath, + GameMessages::SendAddBuff(const_cast(m_Parent->GetObjectID()), source, static_cast(id), + static_cast(duration) * 1000, addImmunity, cancelOnDamaged, cancelOnDeath, cancelOnLogout, cancelOnRemoveBuff, cancelOnUi, cancelOnUnequip, cancelOnZone, addedByTeammate, applyOnTeammates); float tick = 0; diff --git a/dGame/dComponents/CharacterComponent.cpp b/dGame/dComponents/CharacterComponent.cpp index 1e4412931..7ee174b51 100644 --- a/dGame/dComponents/CharacterComponent.cpp +++ b/dGame/dComponents/CharacterComponent.cpp @@ -135,7 +135,7 @@ void CharacterComponent::Serialize(RakNet::BitStream* outBitStream, bool bIsInit outBitStream->Write0(); outBitStream->Write(m_IsLanding); if (m_IsLanding) { - outBitStream->Write(uint16_t(m_LastRocketConfig.size())); + outBitStream->Write(m_LastRocketConfig.size()); for (uint16_t character : m_LastRocketConfig) { outBitStream->Write(character); } @@ -157,7 +157,7 @@ void CharacterComponent::Serialize(RakNet::BitStream* outBitStream, bool bIsInit outBitStream->Write(m_DirtySocialInfo); if (m_DirtySocialInfo) { outBitStream->Write(m_GuildID); - outBitStream->Write(static_cast(m_GuildName.size())); + outBitStream->Write(m_GuildName.size()); if (!m_GuildName.empty()) outBitStream->WriteBits(reinterpret_cast(m_GuildName.c_str()), static_cast(m_GuildName.size()) * sizeof(wchar_t) * 8); @@ -515,9 +515,9 @@ void CharacterComponent::TrackPositionUpdate(const NiPoint3& newPosition) { const auto distance = NiPoint3::Distance(newPosition, m_Parent->GetPosition()); if (m_IsRacing) { - UpdatePlayerStatistic(DistanceDriven, (uint64_t)distance); + UpdatePlayerStatistic(DistanceDriven, static_cast(distance)); } else { - UpdatePlayerStatistic(MetersTraveled, (uint64_t)distance); + UpdatePlayerStatistic(MetersTraveled, static_cast(distance)); } } diff --git a/dGame/dComponents/DestroyableComponent.cpp b/dGame/dComponents/DestroyableComponent.cpp index 8c5321f4f..676fe9ace 100644 --- a/dGame/dComponents/DestroyableComponent.cpp +++ b/dGame/dComponents/DestroyableComponent.cpp @@ -154,7 +154,7 @@ void DestroyableComponent::Serialize(RakNet::BitStream* outBitStream, bool bIsIn outBitStream->Write(m_fMaxArmor); outBitStream->Write(m_fMaxImagination); - outBitStream->Write(uint32_t(m_FactionIDs.size())); + outBitStream->Write(m_FactionIDs.size()); for (size_t i = 0; i < m_FactionIDs.size(); ++i) { outBitStream->Write(m_FactionIDs[i]); } diff --git a/dGame/dComponents/ModuleAssemblyComponent.cpp b/dGame/dComponents/ModuleAssemblyComponent.cpp index 9089c14c1..5b7042dff 100644 --- a/dGame/dComponents/ModuleAssemblyComponent.cpp +++ b/dGame/dComponents/ModuleAssemblyComponent.cpp @@ -57,7 +57,7 @@ void ModuleAssemblyComponent::Serialize(RakNet::BitStream* outBitStream, bool bI outBitStream->Write(m_UseOptionalParts); - outBitStream->Write(static_cast(m_AssemblyPartsLOTs.size())); + outBitStream->Write(m_AssemblyPartsLOTs.size()); for (char16_t character : m_AssemblyPartsLOTs) { outBitStream->Write(character); } diff --git a/dGame/dComponents/MovingPlatformComponent.cpp b/dGame/dComponents/MovingPlatformComponent.cpp index a95735fd1..44cd75b07 100644 --- a/dGame/dComponents/MovingPlatformComponent.cpp +++ b/dGame/dComponents/MovingPlatformComponent.cpp @@ -35,7 +35,7 @@ MoverSubComponent::~MoverSubComponent() = default; void MoverSubComponent::Serialize(RakNet::BitStream* outBitStream, bool bIsInitialUpdate) { outBitStream->Write(true); - outBitStream->Write(static_cast(mState)); + outBitStream->Write(mState); outBitStream->Write(mDesiredWaypointIndex); outBitStream->Write(mShouldStopAtDesiredWaypoint); outBitStream->Write(mInReverse); @@ -90,9 +90,9 @@ void MovingPlatformComponent::Serialize(RakNet::BitStream* outBitStream, bool bI // Is on rail outBitStream->Write1(); - outBitStream->Write(static_cast(m_PathName.size())); + outBitStream->Write(m_PathName.size()); for (const auto& c : m_PathName) { - outBitStream->Write(static_cast(c)); + outBitStream->Write(c); } // Starting point @@ -107,7 +107,7 @@ void MovingPlatformComponent::Serialize(RakNet::BitStream* outBitStream, bool bI if (hasPlatform) { auto* mover = static_cast(m_MoverSubComponent); - outBitStream->Write(static_cast(m_MoverSubComponentType)); + outBitStream->Write(m_MoverSubComponentType); if (m_MoverSubComponentType == eMoverSubComponentType::simpleMover) { // TODO diff --git a/dGame/dComponents/PetComponent.cpp b/dGame/dComponents/PetComponent.cpp index 1780437ec..144f64410 100644 --- a/dGame/dComponents/PetComponent.cpp +++ b/dGame/dComponents/PetComponent.cpp @@ -113,8 +113,8 @@ void PetComponent::Serialize(RakNet::BitStream* outBitStream, bool bIsInitialUpd outBitStream->Write1(); // Always serialize as dirty for now - outBitStream->Write(static_cast(m_Status)); - outBitStream->Write(static_cast(tamed ? m_Ability : PetAbilityType::Invalid)); // Something with the overhead icon? + outBitStream->Write(m_Status); + outBitStream->Write(tamed ? m_Ability : PetAbilityType::Invalid); // Something with the overhead icon? const bool interacting = m_Interaction != LWOOBJID_EMPTY; @@ -136,12 +136,12 @@ void PetComponent::Serialize(RakNet::BitStream* outBitStream, bool bIsInitialUpd const auto nameData = GeneralUtils::UTF8ToUTF16(m_Name); const auto ownerNameData = GeneralUtils::UTF8ToUTF16(m_OwnerName); - outBitStream->Write(static_cast(nameData.size())); + outBitStream->Write(nameData.size()); for (const auto c : nameData) { outBitStream->Write(c); } - outBitStream->Write(static_cast(ownerNameData.size())); + outBitStream->Write(ownerNameData.size()); for (const auto c : ownerNameData) { outBitStream->Write(c); } diff --git a/dGame/dComponents/PropertyEntranceComponent.cpp b/dGame/dComponents/PropertyEntranceComponent.cpp index 4d7ea16dc..83f3ccdc9 100644 --- a/dGame/dComponents/PropertyEntranceComponent.cpp +++ b/dGame/dComponents/PropertyEntranceComponent.cpp @@ -187,7 +187,7 @@ void PropertyEntranceComponent::OnPropertyEntranceSync(Entity* entity, bool incl propertyLookup->setString(2, searchString.c_str()); propertyLookup->setString(3, searchString.c_str()); propertyLookup->setString(4, searchString.c_str()); - propertyLookup->setInt(5, sortMethod == SORT_TYPE_FEATURED || sortMethod == SORT_TYPE_FRIENDS ? (uint32_t)PropertyPrivacyOption::Friends : (uint32_t)PropertyPrivacyOption::Public); + propertyLookup->setInt(5, sortMethod == SORT_TYPE_FEATURED || sortMethod == SORT_TYPE_FRIENDS ? static_cast(PropertyPrivacyOption::Friends) : static_cast(PropertyPrivacyOption::Public)); propertyLookup->setInt(6, numResults); propertyLookup->setInt(7, startIndex); diff --git a/dGame/dComponents/RacingControlComponent.cpp b/dGame/dComponents/RacingControlComponent.cpp index 6c8df2804..278d3f44f 100644 --- a/dGame/dComponents/RacingControlComponent.cpp +++ b/dGame/dComponents/RacingControlComponent.cpp @@ -439,7 +439,7 @@ void RacingControlComponent::Serialize(RakNet::BitStream* outBitStream, bool bIs // BEGIN Scripted Activity outBitStream->Write1(); - outBitStream->Write(static_cast(m_RacingPlayers.size())); + outBitStream->Write(m_RacingPlayers.size()); for (const auto& player : m_RacingPlayers) { outBitStream->Write(player.playerID); @@ -461,7 +461,7 @@ void RacingControlComponent::Serialize(RakNet::BitStream* outBitStream, bool bIs // END Scripted Activity outBitStream->Write1(); - outBitStream->Write(static_cast(m_RacingPlayers.size())); + outBitStream->Write(m_RacingPlayers.size()); outBitStream->Write(!m_AllPlayersReady); if (!m_AllPlayersReady) { @@ -495,7 +495,7 @@ void RacingControlComponent::Serialize(RakNet::BitStream* outBitStream, bool bIs outBitStream->Write(bIsInitialUpdate); if (bIsInitialUpdate) { outBitStream->Write(m_RemainingLaps); - outBitStream->Write(static_cast(m_PathName.size())); + outBitStream->Write(m_PathName.size()); for (const auto character : m_PathName) { outBitStream->Write(character); } diff --git a/dGame/dComponents/RebuildComponent.cpp b/dGame/dComponents/RebuildComponent.cpp index bcdf4f707..25bab2e50 100644 --- a/dGame/dComponents/RebuildComponent.cpp +++ b/dGame/dComponents/RebuildComponent.cpp @@ -81,14 +81,14 @@ void RebuildComponent::Serialize(RakNet::BitStream* outBitStream, bool bIsInitia Entity* builder = GetBuilder(); if (builder) { - outBitStream->Write((uint32_t)1); + outBitStream->Write(1); outBitStream->Write(builder->GetObjectID()); for (int i = 0; i < 10; i++) { outBitStream->Write(0.0f); } } else { - outBitStream->Write((uint32_t)0); + outBitStream->Write(0); } // END Scripted Activity diff --git a/dGame/dComponents/ScriptedActivityComponent.cpp b/dGame/dComponents/ScriptedActivityComponent.cpp index 838fe5edd..8bcddd052 100644 --- a/dGame/dComponents/ScriptedActivityComponent.cpp +++ b/dGame/dComponents/ScriptedActivityComponent.cpp @@ -468,7 +468,7 @@ float_t ScriptedActivityComponent::GetActivityValue(LWOOBJID playerID, uint32_t auto* data = GetActivityPlayerData(playerID); if (data != nullptr) { - value = data->values[std::min(index, (uint32_t)9)]; + value = data->values[std::min(index, static_cast(9))]; } return value; @@ -477,7 +477,7 @@ float_t ScriptedActivityComponent::GetActivityValue(LWOOBJID playerID, uint32_t void ScriptedActivityComponent::SetActivityValue(LWOOBJID playerID, uint32_t index, float_t value) { auto* data = AddActivityPlayerData(playerID); if (data != nullptr) { - data->values[std::min(index, (uint32_t)9)] = value; + data->values[std::min(index, static_cast(9))] = value; } Game::entityManager->SerializeEntity(m_Parent); diff --git a/dGame/dGameMessages/GameMessages.cpp b/dGame/dGameMessages/GameMessages.cpp index 09f9fdbb9..a21ee992b 100644 --- a/dGame/dGameMessages/GameMessages.cpp +++ b/dGame/dGameMessages/GameMessages.cpp @@ -389,7 +389,7 @@ void GameMessages::SendPlatformResync(Entity* entity, const SystemAddress& sysAd bitStream.Write(bReverse); bitStream.Write(bStopAtDesiredWaypoint); bitStream.Write(eCommand); - bitStream.Write(static_cast(movementState)); + bitStream.Write(movementState); bitStream.Write(eUnexpectedCommand); bitStream.Write(fIdleTimeElapsed); bitStream.Write(fMoveTimeElapsed); @@ -5282,7 +5282,7 @@ void GameMessages::HandleRequestDie(RakNet::BitStream* inStream, Entity* entity) /*uint32_t deathTypeLength = deathType.size(); inStream->Read(deathTypeLength); for (uint32_t k = 0; k < deathTypeLength; k++) { - inStream->Read(static_cast(deathType[k])); + inStream->Read(deathType[k]); }*/ inStream->Read(directionRelative_AngleXZ); @@ -6070,7 +6070,7 @@ void GameMessages::HandleUpdatePlayerStatistic(RakNet::BitStream* inStream, Enti auto* characterComponent = entity->GetComponent(); if (characterComponent != nullptr) { - characterComponent->UpdatePlayerStatistic((StatisticID)updateID, (uint64_t)std::max(updateValue, int64_t(0))); + characterComponent->UpdatePlayerStatistic((StatisticID)updateID, static_cast(std::max(updateValue, static_cast(0)))); } } diff --git a/dGame/dGameMessages/PropertyDataMessage.cpp b/dGame/dGameMessages/PropertyDataMessage.cpp index e39cfeca0..29bc8ea93 100644 --- a/dGame/dGameMessages/PropertyDataMessage.cpp +++ b/dGame/dGameMessages/PropertyDataMessage.cpp @@ -17,21 +17,21 @@ void GameMessages::PropertyDataMessage::Serialize(RakNet::BitStream& stream) con stream.Write(cloneId); // clone id const auto& name = GeneralUtils::UTF8ToUTF16(Name); - stream.Write(uint32_t(name.size())); + stream.Write(name.size()); for (uint32_t i = 0; i < name.size(); ++i) { - stream.Write(uint16_t(name[i])); + stream.Write(name[i]); } const auto& description = GeneralUtils::UTF8ToUTF16(Description); - stream.Write(uint32_t(description.size())); + stream.Write(description.size()); for (uint32_t i = 0; i < description.size(); ++i) { - stream.Write(uint16_t(description[i])); + stream.Write(description[i]); } const auto& owner = GeneralUtils::UTF8ToUTF16(OwnerName); - stream.Write(uint32_t(owner.size())); + stream.Write(owner.size()); for (uint32_t i = 0; i < owner.size(); ++i) { - stream.Write(uint16_t(owner[i])); + stream.Write(owner[i]); } stream.Write(OwnerId); @@ -49,9 +49,9 @@ void GameMessages::PropertyDataMessage::Serialize(RakNet::BitStream& stream) con stream.Write(0); const auto& spawn = GeneralUtils::ASCIIToUTF16(SpawnName); - stream.Write(uint32_t(spawn.size())); + stream.Write(spawn.size()); for (uint32_t i = 0; i < spawn.size(); ++i) { - stream.Write(uint16_t(spawn[i])); + stream.Write(spawn[i]); } stream.Write(0); // String length @@ -71,9 +71,9 @@ void GameMessages::PropertyDataMessage::Serialize(RakNet::BitStream& stream) con // Does this go here??? // const auto& rejectionReasonConverted = GeneralUtils::UTF8ToUTF16(rejectionReason); - // stream.Write(uint32_t(rejectionReasonConverted.size())); + // stream.Write(rejectionReasonConverted.size()); // for (uint32_t i = 0; i < rejectionReasonConverted.size(); ++i) { - // stream.Write(uint16_t(rejectionReasonConverted[i])); + // stream.Write(rejectionReasonConverted[i]); // } stream.Write(0); @@ -93,7 +93,7 @@ void GameMessages::PropertyDataMessage::Serialize(RakNet::BitStream& stream) con stream.Write(PrivacyOption); - stream.Write(uint32_t(Paths.size())); + stream.Write(Paths.size()); for (const auto& path : Paths) { stream.Write(path.x); diff --git a/dGame/dGameMessages/PropertySelectQueryProperty.cpp b/dGame/dGameMessages/PropertySelectQueryProperty.cpp index 6e9758795..2a2567644 100644 --- a/dGame/dGameMessages/PropertySelectQueryProperty.cpp +++ b/dGame/dGameMessages/PropertySelectQueryProperty.cpp @@ -4,21 +4,21 @@ void PropertySelectQueryProperty::Serialize(RakNet::BitStream& stream) const { stream.Write(CloneId); const auto& owner = GeneralUtils::UTF8ToUTF16(OwnerName); - stream.Write(uint32_t(owner.size())); + stream.Write(owner.size()); for (uint32_t i = 0; i < owner.size(); ++i) { - stream.Write(static_cast(owner[i])); + stream.Write(owner[i]); } const auto& name = GeneralUtils::UTF8ToUTF16(Name); - stream.Write(uint32_t(name.size())); + stream.Write(name.size()); for (uint32_t i = 0; i < name.size(); ++i) { - stream.Write(static_cast(name[i])); + stream.Write(name[i]); } const auto& description = GeneralUtils::UTF8ToUTF16(Description); - stream.Write(uint32_t(description.size())); + stream.Write(description.size()); for (uint32_t i = 0; i < description.size(); ++i) { - stream.Write(static_cast(description[i])); + stream.Write(description[i]); } stream.Write(Reputation); diff --git a/dGame/dInventory/Item.cpp b/dGame/dInventory/Item.cpp index 9e4b46f6d..06c6900f1 100644 --- a/dGame/dInventory/Item.cpp +++ b/dGame/dInventory/Item.cpp @@ -251,7 +251,7 @@ bool Item::Consume() { auto skills = skillsTable->Query([=](const CDObjectSkills entry) { return entry.objectTemplate == static_cast(lot); - }); + }); auto success = false; diff --git a/dGame/dUtilities/SlashCommandHandler.cpp b/dGame/dUtilities/SlashCommandHandler.cpp index 05817e3b9..41b3c21de 100644 --- a/dGame/dUtilities/SlashCommandHandler.cpp +++ b/dGame/dUtilities/SlashCommandHandler.cpp @@ -1792,7 +1792,7 @@ void SlashCommandHandler::HandleChatCommand(const std::u16string& command, Entit totalRuns += 1; bool doBreak = false; for (const auto& kv : lootRoll) { - if ((uint32_t)kv.first == targetLot) { + if (static_cast(kv.first) == targetLot) { doBreak = true; } } diff --git a/dNavigation/dTerrain/RawChunk.cpp b/dNavigation/dTerrain/RawChunk.cpp index e4f753cd4..fe7ac8a2d 100644 --- a/dNavigation/dTerrain/RawChunk.cpp +++ b/dNavigation/dTerrain/RawChunk.cpp @@ -20,40 +20,40 @@ RawChunk::RawChunk(std::ifstream& stream) { uint32_t colorMapSize; BinaryIO::BinaryRead(stream, colorMapSize); - stream.seekg((uint32_t)stream.tellg() + (colorMapSize * colorMapSize * 4)); + stream.seekg(static_cast(stream.tellg()) + (colorMapSize * colorMapSize * 4)); uint32_t lightmapSize; BinaryIO::BinaryRead(stream, lightmapSize); - stream.seekg((uint32_t)stream.tellg() + (lightmapSize)); + stream.seekg(static_cast(stream.tellg()) + (lightmapSize)); uint32_t colorMapSize2; BinaryIO::BinaryRead(stream, colorMapSize2); - stream.seekg((uint32_t)stream.tellg() + (colorMapSize2 * colorMapSize2 * 4)); + stream.seekg(static_cast(stream.tellg()) + (colorMapSize2 * colorMapSize2 * 4)); uint8_t unknown; BinaryIO::BinaryRead(stream, unknown); uint32_t blendmapSize; BinaryIO::BinaryRead(stream, blendmapSize); - stream.seekg((uint32_t)stream.tellg() + (blendmapSize)); + stream.seekg(static_cast(stream.tellg()) + (blendmapSize)); uint32_t pointSize; BinaryIO::BinaryRead(stream, pointSize); - stream.seekg((uint32_t)stream.tellg() + (pointSize * 9 * 4)); + stream.seekg(static_cast(stream.tellg()) + (pointSize * 9 * 4)); - stream.seekg((uint32_t)stream.tellg() + (colorMapSize * colorMapSize)); + stream.seekg(static_cast(stream.tellg()) + (colorMapSize * colorMapSize)); uint32_t endCounter; BinaryIO::BinaryRead(stream, endCounter); - stream.seekg((uint32_t)stream.tellg() + (endCounter * 2)); + stream.seekg(static_cast(stream.tellg()) + (endCounter * 2)); if (endCounter != 0) { - stream.seekg((uint32_t)stream.tellg() + (32)); + stream.seekg(static_cast(stream.tellg()) + (32)); for (int i = 0; i < 0x10; i++) { uint16_t finalCountdown; BinaryIO::BinaryRead(stream, finalCountdown); - stream.seekg((uint32_t)stream.tellg() + (finalCountdown * 2)); + stream.seekg(static_cast(stream.tellg()) + (finalCountdown * 2)); } } diff --git a/dNet/AuthPackets.cpp b/dNet/AuthPackets.cpp index 4e84eeca3..da375193c 100644 --- a/dNet/AuthPackets.cpp +++ b/dNet/AuthPackets.cpp @@ -64,12 +64,12 @@ void AuthPackets::SendHandshake(dServer* server, const SystemAddress& sysAddr, c return; } bitStream.Write(netVersion); - bitStream.Write(uint32_t(0x93)); + bitStream.Write(0x93); if (serverType == ServerType::Auth) bitStream.Write(uint32_t(1)); //Conn: auth - else bitStream.Write(uint32_t(4)); //Conn: world + else bitStream.Write(4); //Conn: world - bitStream.Write(uint32_t(0)); //Server process ID + bitStream.Write(0); //Server process ID bitStream.Write(nextServerPort); server->Send(&bitStream, sysAddr, false); @@ -155,7 +155,7 @@ void AuthPackets::SendLoginResponse(dServer* server, const SystemAddress& sysAdd RakNet::BitStream packet; BitStreamUtils::WriteHeader(packet, eConnectionType::CLIENT, eClientMessageType::LOGIN_RESPONSE); - packet.Write(static_cast(responseCode)); + packet.Write(responseCode); // Event Gating packet.Write(LUString(Game::config->GetValue("event_1"))); @@ -189,8 +189,8 @@ void AuthPackets::SendLoginResponse(dServer* server, const SystemAddress& sysAdd packet.Write(LUString("")); // Write the Character and Chat Ports - packet.Write(static_cast(wServerPort)); - packet.Write(static_cast(0)); + packet.Write(wServerPort); + packet.Write(0); // CDN Key packet.Write(LUString("")); @@ -198,26 +198,26 @@ void AuthPackets::SendLoginResponse(dServer* server, const SystemAddress& sysAdd // CDN Ticket packet.Write(LUString("00000000-0000-0000-0000-000000000000", 37)); - packet.Write(static_cast(0)); // Language + packet.Write(0); // Language // Write the localization packet.Write(LUString("US", 3)); - packet.Write(static_cast(false)); // Just upgraded from F2P - packet.Write(static_cast(false)); // User is F2P - packet.Write(static_cast(0)); // Time Remaining in F2P + packet.Write(false); // Just upgraded from F2P + packet.Write(false); // User is F2P + packet.Write(0); // Time Remaining in F2P // Write custom error message - packet.Write(static_cast(errorMsg.length())); + packet.Write(errorMsg.length()); packet.Write(LUWString(errorMsg, static_cast(errorMsg.length()))); // Here write auth logs - packet.Write(static_cast(20)); + packet.Write(20); for (uint32_t i = 0; i < 20; ++i) { - packet.Write(static_cast(8)); - packet.Write(static_cast(44)); - packet.Write(static_cast(14000)); - packet.Write(static_cast(0)); + packet.Write(8); + packet.Write(44); + packet.Write(14000); + packet.Write(0); } server->Send(&packet, sysAddr, false); diff --git a/dNet/ChatPackets.cpp b/dNet/ChatPackets.cpp index 20f8aafaf..63eff5ef5 100644 --- a/dNet/ChatPackets.cpp +++ b/dNet/ChatPackets.cpp @@ -17,20 +17,20 @@ void ChatPackets::SendChatMessage(const SystemAddress& sysAddr, char chatChannel CBITSTREAM; BitStreamUtils::WriteHeader(bitStream, eConnectionType::CHAT, eChatMessageType::GENERAL_CHAT_MESSAGE); - bitStream.Write(static_cast(0)); + bitStream.Write(0); bitStream.Write(chatChannel); - bitStream.Write(static_cast(message.size())); + bitStream.Write(message.size()); bitStream.Write(LUWString(senderName)); bitStream.Write(playerObjectID); - bitStream.Write(static_cast(0)); - bitStream.Write(static_cast(0)); + bitStream.Write(0); + bitStream.Write(0); for (uint32_t i = 0; i < message.size(); ++i) { - bitStream.Write(static_cast(message[i])); + bitStream.Write(message[i]); } - bitStream.Write(static_cast(0)); + bitStream.Write(0); SEND_PACKET_BROADCAST; } @@ -39,21 +39,21 @@ void ChatPackets::SendSystemMessage(const SystemAddress& sysAddr, const std::u16 CBITSTREAM; BitStreamUtils::WriteHeader(bitStream, eConnectionType::CHAT, eChatMessageType::GENERAL_CHAT_MESSAGE); - bitStream.Write(static_cast(0)); - bitStream.Write(static_cast(4)); + bitStream.Write(0); + bitStream.Write(4); - bitStream.Write(static_cast(message.size())); + bitStream.Write(message.size()); bitStream.Write(LUWString("", 33)); - bitStream.Write(static_cast(0)); - bitStream.Write(static_cast(0)); - bitStream.Write(static_cast(0)); + bitStream.Write(0); + bitStream.Write(0); + bitStream.Write(0); for (uint32_t i = 0; i < message.size(); ++i) { - bitStream.Write(static_cast(message[i])); + bitStream.Write(message[i]); } - bitStream.Write(static_cast(0)); + bitStream.Write(0); //This is so Wincent's announcement works: if (sysAddr != UNASSIGNED_SYSTEM_ADDRESS) { diff --git a/dNet/PacketUtils.cpp b/dNet/PacketUtils.cpp index 6b39c2f24..95c3b2b1d 100644 --- a/dNet/PacketUtils.cpp +++ b/dNet/PacketUtils.cpp @@ -45,7 +45,7 @@ std::string PacketUtils::ReadString(uint32_t startLoc, Packet* packet, bool wide if (packet->length > startLoc) { uint32_t i = 0; - while (packet->data[startLoc + i] != '\0' && packet->length > (uint32_t)(startLoc + i) && maxLen > i) { + while (packet->data[startLoc + i] != '\0' && packet->length > static_cast(startLoc + i) && maxLen > i) { readString.push_back(packet->data[startLoc + i]); if (wide) { diff --git a/dNet/WorldPackets.cpp b/dNet/WorldPackets.cpp index 1ee98c837..2da11d593 100644 --- a/dNet/WorldPackets.cpp +++ b/dNet/WorldPackets.cpp @@ -226,9 +226,9 @@ void WorldPackets::SendGMLevelChange(const SystemAddress& sysAddr, bool success, BitStreamUtils::WriteHeader(bitStream, eConnectionType::CLIENT, eClientMessageType::MAKE_GM_RESPONSE); bitStream.Write(success); - bitStream.Write(static_cast(highestLevel)); - bitStream.Write(static_cast(prevLevel)); - bitStream.Write(static_cast(newLevel)); + bitStream.Write(highestLevel); + bitStream.Write(prevLevel); + bitStream.Write(newLevel); SEND_PACKET; } diff --git a/dScripts/02_server/Map/NS/NsLegoClubDoor.cpp b/dScripts/02_server/Map/NS/NsLegoClubDoor.cpp index 35d4735c2..196386274 100644 --- a/dScripts/02_server/Map/NS/NsLegoClubDoor.cpp +++ b/dScripts/02_server/Map/NS/NsLegoClubDoor.cpp @@ -4,7 +4,7 @@ #include "Amf3.h" void NsLegoClubDoor::OnStartup(Entity* self) { - self->SetVar(u"currentZone", (int32_t)Game::zoneManager->GetZoneID().GetMapID()); + self->SetVar(u"currentZone", static_castGame::zoneManager->GetZoneID().GetMapID()); self->SetVar(u"choiceZone", m_ChoiceZoneID); self->SetVar(u"teleportAnim", m_TeleportAnim); self->SetVar(u"teleportString", m_TeleportString); diff --git a/dScripts/02_server/Map/NS/NsLupTeleport.cpp b/dScripts/02_server/Map/NS/NsLupTeleport.cpp index c75143fcc..6886b4cdc 100644 --- a/dScripts/02_server/Map/NS/NsLupTeleport.cpp +++ b/dScripts/02_server/Map/NS/NsLupTeleport.cpp @@ -4,7 +4,7 @@ #include "Amf3.h" void NsLupTeleport::OnStartup(Entity* self) { - self->SetVar(u"currentZone", (int32_t)Game::zoneManager->GetZoneID().GetMapID()); + self->SetVar(u"currentZone", static_cast(Game::zoneManager->GetZoneID().GetMapID())); self->SetVar(u"choiceZone", m_ChoiceZoneID); self->SetVar(u"teleportAnim", m_TeleportAnim); self->SetVar(u"teleportString", m_TeleportString); diff --git a/dScripts/02_server/Map/NS/Waves/ZoneNsWaves.cpp b/dScripts/02_server/Map/NS/Waves/ZoneNsWaves.cpp index 184132fef..43ba30df3 100644 --- a/dScripts/02_server/Map/NS/Waves/ZoneNsWaves.cpp +++ b/dScripts/02_server/Map/NS/Waves/ZoneNsWaves.cpp @@ -437,7 +437,7 @@ std::vector ZoneNsWaves::GetWaves() { }, {}, {}, "Treasure_Camera", 5.0f, - (uint32_t)-1, + static_cast(-1), true, 60, }, diff --git a/dScripts/02_server/Map/njhub/boss_instance/NjMonastryBossInstance.cpp b/dScripts/02_server/Map/njhub/boss_instance/NjMonastryBossInstance.cpp index 137a9ed35..4a182d3d0 100644 --- a/dScripts/02_server/Map/njhub/boss_instance/NjMonastryBossInstance.cpp +++ b/dScripts/02_server/Map/njhub/boss_instance/NjMonastryBossInstance.cpp @@ -53,9 +53,9 @@ void NjMonastryBossInstance::OnPlayerLoaded(Entity* self, Entity* player) { // Buff the player auto* destroyableComponent = player->GetComponent(); if (destroyableComponent != nullptr) { - destroyableComponent->SetHealth((int32_t)destroyableComponent->GetMaxHealth()); - destroyableComponent->SetArmor((int32_t)destroyableComponent->GetMaxArmor()); - destroyableComponent->SetImagination((int32_t)destroyableComponent->GetMaxImagination()); + destroyableComponent->SetHealth(static_cast(destroyableComponent->GetMaxHealth())); + destroyableComponent->SetArmor(static_cast(destroyableComponent->GetMaxArmor())); + destroyableComponent->SetImagination(static_cast(destroyableComponent->GetMaxImagination())); } // Add player ID to instance @@ -309,7 +309,7 @@ void NjMonastryBossInstance::HandleLowerFrakjawSpawned(Entity* self, Entity* low if (destroyableComponent != nullptr) { const auto doubleHealth = destroyableComponent->GetHealth() * 2; destroyableComponent->SetHealth(doubleHealth); - destroyableComponent->SetMaxHealth((float_t)doubleHealth); + destroyableComponent->SetMaxHealth(static_cast(doubleHealth)); } ActivityTimerStart(self, FrakjawSpawnInTimer + std::to_string(lowerFrakjaw->GetObjectID()), @@ -328,7 +328,7 @@ void NjMonastryBossInstance::HandleLowerFrakjawHit(Entity* self, Entity* lowerFr return; // Progress the fight to the last wave if frakjaw has less than 50% of his health left - if (destroyableComponent->GetHealth() <= (uint32_t)destroyableComponent->GetMaxHealth() / 2 && !self->GetVar(OnLastWaveVarbiale)) { + if (destroyableComponent->GetHealth() <= static_cast(destroyableComponent->GetMaxHealth()) / 2 && !self->GetVar(OnLastWaveVarbiale)) { self->SetVar(OnLastWaveVarbiale, true); // Stun frakjaw during the cinematic diff --git a/dScripts/BaseSurvivalServer.cpp b/dScripts/BaseSurvivalServer.cpp index ffa86968b..761ca509f 100644 --- a/dScripts/BaseSurvivalServer.cpp +++ b/dScripts/BaseSurvivalServer.cpp @@ -115,7 +115,7 @@ void BaseSurvivalServer::BasePlayerExit(Entity* self, Entity* player) { SetActivityValue(self, player->GetObjectID(), 1, 0); self->SetNetworkVar(NumberOfPlayersVariable, - std::min((uint32_t)0, self->GetNetworkVar(NumberOfPlayersVariable) - 1)); + std::min(static_cast(0), self->GetNetworkVar(NumberOfPlayersVariable) - 1)); } void BaseSurvivalServer::BaseFireEvent(Entity* self, Entity* sender, const std::string& args, int32_t param1, int32_t param2, @@ -421,7 +421,7 @@ void BaseSurvivalServer::SpawnerReset(SpawnerNetworkCollection& spawnerNetworkCo } } - state.totalSpawned = std::max((uint32_t)totalSpawned, state.totalSpawned); + state.totalSpawned = std::max(static_cast(totalSpawned), state.totalSpawned); } void BaseSurvivalServer::SpawnerUpdate(Entity* self, SpawnerNetworkCollection& spawnerNetworkCollection, uint32_t amount) { diff --git a/dScripts/BaseWavesServer.cpp b/dScripts/BaseWavesServer.cpp index 1090d8c54..7482c920e 100644 --- a/dScripts/BaseWavesServer.cpp +++ b/dScripts/BaseWavesServer.cpp @@ -95,7 +95,7 @@ void BaseWavesServer::BasePlayerExit(Entity* self, Entity* player) { SetActivityValue(self, player->GetObjectID(), 2, 0); self->SetNetworkVar(NumberOfPlayersVariable, - std::min((uint32_t)0, self->GetNetworkVar(NumberOfPlayersVariable) - 1)); + std::min(static_cast(0), self->GetNetworkVar(NumberOfPlayersVariable) - 1)); } // Done @@ -212,7 +212,7 @@ void BaseWavesServer::OnActivityTimerDone(Entity* self, const std::string& name) const auto currentTime = ActivityTimerGetCurrentTime(self, ClockTickTimer); const auto currentWave = state.waveNumber; - self->SetNetworkVar(WaveCompleteVariable, { currentWave, (uint32_t)currentTime }); + self->SetNetworkVar(WaveCompleteVariable, { currentWave, static_cast(currentTime) }); } else if (name == GameOverWinTimer) { GameOver(self, true); } else if (name == CinematicDoneTimer) { @@ -421,7 +421,7 @@ void BaseWavesServer::SpawnWave(Entity* self) { const auto wave = waves.at(state.waveNumber); // Handles meta info to the client about the current round - if (wave.winDelay != (uint32_t)-1) { + if (wave.winDelay != static_cast(-1)) { self->SetNetworkVar(WonWaveVariable, true); // Close the game if we don't expect a notification from an other entity to end it @@ -548,7 +548,7 @@ bool BaseWavesServer::UpdateSpawnedEnemies(Entity* self, LWOOBJID enemyID, uint3 } // Might seem odd to send the next wave but the client isn't 0-indexed so it thinks it completed the correct wave - self->SetNetworkVar(WaveCompleteVariable, { state.waveNumber, (uint32_t)currentTime }); + self->SetNetworkVar(WaveCompleteVariable, { state.waveNumber, static_cast(currentTime) }); return true; } diff --git a/dScripts/ai/MINIGAME/SG_GF/SERVER/SGCannon.cpp b/dScripts/ai/MINIGAME/SG_GF/SERVER/SGCannon.cpp index 2c520670b..26047d8e1 100644 --- a/dScripts/ai/MINIGAME/SG_GF/SERVER/SGCannon.cpp +++ b/dScripts/ai/MINIGAME/SG_GF/SERVER/SGCannon.cpp @@ -171,7 +171,7 @@ void SGCannon::SuperChargeTimerFunc(Entity* self) { void SGCannon::SpawnWaveTimerFunc(Entity* self) { if (self->GetVar(GameStartedVariable)) { self->SetVar(WaveStatusVariable, true); - const auto wave = (int32_t)self->GetVar(ThisWaveVariable); + const auto wave = static_cast(self->GetVar(ThisWaveVariable)); if (wave != 0 && self->GetVar(SuperChargePausedVariable)) { StartChargedCannon(self, self->GetVar(CurrentSuperChargedTimeVariable)); @@ -187,7 +187,7 @@ void SGCannon::SpawnWaveTimerFunc(Entity* self) { LOG("Current wave spawn: %i/%i", wave, m_Waves.size()); // All waves completed - const auto timeLimit = (float_t)self->GetVar(TimeLimitVariable); + const auto timeLimit = static_cast(self->GetVar(TimeLimitVariable)); if (wave >= m_Waves.size()) { ActivityTimerStart(self, GameOverTimer, timeLimit, timeLimit); } else { @@ -262,7 +262,7 @@ void SGCannon::GameOverTimerFunc(Entity* self) { void SGCannon::DoSpawnTimerFunc(Entity* self, const std::string& name) { if (self->GetVar(GameStartedVariable)) { LOG_DEBUG("time name %s %s", name.c_str(), name.substr(7).c_str()); - const auto spawnNumber = (uint32_t)std::stoi(name.substr(7)); + const auto spawnNumber = static_cast(std::stoi(name.substr(7))); const auto& activeSpawns = self->GetVar>(ActiveSpawnsVariable); LOG_DEBUG("size %i, %i", activeSpawns.size(), spawnNumber); if (activeSpawns.size() <= spawnNumber) { @@ -555,7 +555,7 @@ void SGCannon::PlaySceneAnimation(Entity* self, const std::u16string& animationN } void SGCannon::PauseChargeCannon(Entity* self) { - const auto time = std::max((uint32_t)std::ceil(ActivityTimerGetCurrentTime(self, SuperChargeTimer)), (uint32_t)1); + const auto time = std::max(static_cast(std::ceil(ActivityTimerGetCurrentTime(self, SuperChargeTimer))), static_cast(1)); self->SetVar(SuperChargePausedVariable, true); self->SetVar(CurrentSuperChargedTimeVariable, time); diff --git a/dZoneManager/Zone.cpp b/dZoneManager/Zone.cpp index 463f0a8af..942c9c135 100644 --- a/dZoneManager/Zone.cpp +++ b/dZoneManager/Zone.cpp @@ -59,7 +59,7 @@ void Zone::LoadZoneIntoMemory() { if (m_FileFormatVersion >= Zone::FileFormatVersion::Alpha) BinaryIO::BinaryRead(file, mapRevision); BinaryIO::BinaryRead(file, m_WorldID); - if ((uint16_t)m_WorldID != m_ZoneID.GetMapID()) LOG("WorldID: %i doesn't match MapID %i! Is this intended?", m_WorldID, m_ZoneID.GetMapID()); + if (m_WorldID != m_ZoneID.GetMapID()) LOG("WorldID: %i doesn't match MapID %i! Is this intended?", m_WorldID, m_ZoneID.GetMapID()); AddRevision(LWOSCENEID_INVALID, mapRevision); diff --git a/dZoneManager/Zone.h b/dZoneManager/Zone.h index a62a81edc..916f0b86b 100644 --- a/dZoneManager/Zone.h +++ b/dZoneManager/Zone.h @@ -213,7 +213,7 @@ class Zone { LUTriggers::Trigger* GetTrigger(uint32_t sceneID, uint32_t triggerID); const Path* GetPath(std::string name) const; - uint32_t GetWorldID() const { return m_WorldID; } + LWOMAPID GetWorldID() const { return m_WorldID; } [[nodiscard]] std::string GetZoneName() const { return m_ZoneName; } std::string GetZoneRawPath() const { return m_ZoneRawPath; } std::string GetZonePath() const { return m_ZonePath; } @@ -231,7 +231,7 @@ class Zone { uint32_t m_NumberOfSceneTransitionsLoaded; FileFormatVersion m_FileFormatVersion; uint32_t m_CheckSum; - uint32_t m_WorldID; //should be equal to the MapID + LWOMAPID m_WorldID; //should be equal to the MapID NiPoint3 m_Spawnpoint; NiQuaternion m_SpawnpointRotation; uint32_t m_SceneCount; From b9e6f6c6aabf270625a32090c4edca4c7e117979 Mon Sep 17 00:00:00 2001 From: jadebenn Date: Mon, 25 Dec 2023 23:09:14 -0600 Subject: [PATCH 02/12] cast cleanup --- CMakeLists.txt | 2 +- dCommon/AmfSerialize.cpp | 12 +++++----- dCommon/BrickByBrickFix.cpp | 2 +- dCommon/CMakeLists.txt | 6 +++++ dCommon/Diagnostics.cpp | 8 +++---- dCommon/GeneralUtils.cpp | 2 +- dCommon/MD5.cpp | 6 ++--- dCommon/Metrics.cpp | 2 +- dCommon/NiPoint3.cpp | 23 ++++++++++++++----- dCommon/SHA512.cpp | 4 ++-- dCommon/dClient/AssetManager.cpp | 12 +++++----- dCommon/dClient/Pack.cpp | 8 +++---- .../CDComponentsRegistryTable.cpp | 3 +-- .../CDClientTables/CDMissionEmailTable.cpp | 3 +-- dDatabase/CMakeLists.txt | 5 ++++ dGame/CMakeLists.txt | 5 ++++ dGame/dBehaviors/Behavior.cpp | 4 ++-- dGame/dBehaviors/BehaviorContext.cpp | 2 +- dGame/dBehaviors/SwitchMultipleBehavior.cpp | 2 +- dGame/dComponents/BaseCombatAIComponent.cpp | 6 ++--- dGame/dComponents/BaseCombatAIComponent.h | 2 +- dGame/dComponents/BuffComponent.cpp | 2 +- dGame/dComponents/CharacterComponent.cpp | 2 +- dGame/dComponents/DestroyableComponent.cpp | 2 +- dGame/dComponents/MissionComponent.cpp | 2 +- dGame/dComponents/MovingPlatformComponent.cpp | 4 ++-- dGame/dComponents/PetComponent.cpp | 4 ++-- dGame/dComponents/PetComponent.h | 2 +- .../dComponents/PropertyEntranceComponent.cpp | 4 ++-- .../PropertyManagementComponent.cpp | 2 +- dGame/dComponents/RacingControlComponent.cpp | 18 +++++++-------- dGame/dComponents/SkillComponent.cpp | 8 +++---- dGame/dGameMessages/GameMessageHandler.cpp | 6 ++--- dGame/dGameMessages/GameMessages.cpp | 10 ++++---- dGame/dInventory/ItemSet.cpp | 2 +- dGame/dMission/Mission.cpp | 4 ++-- dGame/dUtilities/Loot.cpp | 4 ++-- dGame/dUtilities/Preconditions.cpp | 2 +- dGame/dUtilities/SlashCommandHandler.cpp | 16 ++++++------- dMasterServer/CMakeLists.txt | 5 ++++ dNavigation/CMakeLists.txt | 5 ++++ dNavigation/dNavMesh.cpp | 2 +- dNet/AuthPackets.cpp | 2 +- dNet/BitStreamUtils.h | 4 ++-- dNet/CMakeLists.txt | 5 ++++ dNet/WorldPackets.cpp | 6 ++--- dPhysics/CMakeLists.txt | 5 ++++ .../02_server/Map/AG/NpcAgCourseStarter.cpp | 6 ++--- dScripts/02_server/Map/AM/AmDrawBridge.cpp | 2 +- dScripts/02_server/Map/NS/NsLegoClubDoor.cpp | 2 +- .../boss_instance/NjMonastryBossInstance.cpp | 2 +- dScripts/BaseSurvivalServer.cpp | 2 +- dScripts/BaseWavesServer.cpp | 2 +- dScripts/CMakeLists.txt | 5 ++++ .../ai/MINIGAME/SG_GF/SERVER/SGCannon.cpp | 4 ++-- .../OBJECTS/FvRaceSmashEggImagineServer.cpp | 4 ++-- .../RACING/OBJECTS/RaceImagineCrateServer.cpp | 2 +- .../ai/RACING/OBJECTS/RaceImaginePowerup.cpp | 2 +- .../ai/RACING/OBJECTS/RaceSmashServer.cpp | 4 ++-- dWorldServer/CMakeLists.txt | 4 ++++ dZoneManager/CMakeLists.txt | 5 ++++ 61 files changed, 176 insertions(+), 117 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 0a05b6f9e..7e9823467 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -58,7 +58,7 @@ if(UNIX) if(APPLE) set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=gnu++17 -O2 -Wuninitialized -D_GLIBCXX_USE_CXX11_ABI=0 -D_GLIBCXX_USE_CXX17_ABI=0 -fPIC") else() - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=gnu++17 -O2 -Wuninitialized -D_GLIBCXX_USE_CXX11_ABI=0 -D_GLIBCXX_USE_CXX17_ABI=0 -Wold-style-cast -static-libgcc -fPIC -lstdc++fs") + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=gnu++17 -O2 -Wuninitialized -D_GLIBCXX_USE_CXX11_ABI=0 -D_GLIBCXX_USE_CXX17_ABI=0 -static-libgcc -fPIC -lstdc++fs") endif() if (__dynamic AND CMAKE_CXX_COMPILER_ID STREQUAL "GNU") set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -rdynamic") diff --git a/dCommon/AmfSerialize.cpp b/dCommon/AmfSerialize.cpp index 5898874e4..3072b8e15 100644 --- a/dCommon/AmfSerialize.cpp +++ b/dCommon/AmfSerialize.cpp @@ -54,17 +54,17 @@ void RakNet::BitStream::Write(AMFBaseValue& value) { * RakNet writes in the correct byte order - do not reverse this. */ void WriteUInt29(RakNet::BitStream* bs, uint32_t v) { - unsigned char b4 = (unsigned char)v; + unsigned char b4 = static_cast(v); if (v < 0x00200000) { b4 = b4 & 0x7F; if (v > 0x7F) { unsigned char b3; v = v >> 7; - b3 = ((unsigned char)(v)) | 0x80; + b3 = static_cast(v) | 0x80; if (v > 0x7F) { unsigned char b2; v = v >> 7; - b2 = ((unsigned char)(v)) | 0x80; + b2 = static_cast(v) | 0x80; bs->Write(b2); } @@ -76,11 +76,11 @@ void WriteUInt29(RakNet::BitStream* bs, uint32_t v) { unsigned char b3; v = v >> 8; - b3 = ((unsigned char)(v)) | 0x80; + b3 = static_cast(v) | 0x80; v = v >> 7; - b2 = ((unsigned char)(v)) | 0x80; + b2 = static_cast(v) | 0x80; v = v >> 7; - b1 = ((unsigned char)(v)) | 0x80; + b1 = static_cast(v) | 0x80; bs->Write(b1); bs->Write(b2); diff --git a/dCommon/BrickByBrickFix.cpp b/dCommon/BrickByBrickFix.cpp index f8a9e0220..b771c9861 100644 --- a/dCommon/BrickByBrickFix.cpp +++ b/dCommon/BrickByBrickFix.cpp @@ -51,7 +51,7 @@ uint32_t BrickByBrickFix::TruncateBrokenBrickByBrickXml() { if (actualUncompressedSize != -1) { uint32_t previousSize = completeUncompressedModel.size(); - completeUncompressedModel.append((char*)uncompressedChunk.get()); + completeUncompressedModel.append(reinterpret_cast(uncompressedChunk.get())); completeUncompressedModel.resize(previousSize + actualUncompressedSize); } else { LOG("Failed to inflate chunk %i for model %llu. Error: %i", chunkCount, model.id, err); diff --git a/dCommon/CMakeLists.txt b/dCommon/CMakeLists.txt index 1354c051b..13ffc6c97 100644 --- a/dCommon/CMakeLists.txt +++ b/dCommon/CMakeLists.txt @@ -31,6 +31,12 @@ add_library(dCommon STATIC ${DCOMMON_SOURCES}) target_link_libraries(dCommon bcrypt dDatabase tinyxml2) +# If using gcc, warn on old-style C casts +if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU") + set_source_files_properties(${DCOMMON_SOURCES} PROPERTIES COMPILE_FLAGS "-Wold-style-cast") +endif() + +# Handle zlib dependency if (UNIX) find_package(ZLIB REQUIRED) elseif (WIN32) diff --git a/dCommon/Diagnostics.cpp b/dCommon/Diagnostics.cpp index 264744f94..0fb84e6fd 100644 --- a/dCommon/Diagnostics.cpp +++ b/dCommon/Diagnostics.cpp @@ -197,10 +197,10 @@ void MakeBacktrace() { sigact.sa_sigaction = CritErrHdlr; sigact.sa_flags = SA_RESTART | SA_SIGINFO; - if (sigaction(SIGSEGV, &sigact, (struct sigaction*)nullptr) != 0 || - sigaction(SIGFPE, &sigact, (struct sigaction*)nullptr) != 0 || - sigaction(SIGABRT, &sigact, (struct sigaction*)nullptr) != 0 || - sigaction(SIGILL, &sigact, (struct sigaction*)nullptr) != 0) { + if (sigaction(SIGSEGV, &sigact, static_cast(nullptr)) != 0 || + sigaction(SIGFPE, &sigact, static_cast(nullptr)) != 0 || + sigaction(SIGABRT, &sigact, static_cast(nullptr)) != 0 || + sigaction(SIGILL, &sigact, static_cast(nullptr)) != 0) { fprintf(stderr, "error setting signal handler for %d (%s)\n", SIGSEGV, strsignal(SIGSEGV)); diff --git a/dCommon/GeneralUtils.cpp b/dCommon/GeneralUtils.cpp index 99ca687a7..b45165fa2 100644 --- a/dCommon/GeneralUtils.cpp +++ b/dCommon/GeneralUtils.cpp @@ -53,7 +53,7 @@ bool _IsSuffixChar(uint8_t c) { bool GeneralUtils::_NextUTF8Char(std::string_view& slice, uint32_t& out) { size_t rem = slice.length(); if (slice.empty()) return false; - const uint8_t* bytes = (const uint8_t*)&slice.front(); + const uint8_t* bytes = reinterpret_cast(&slice.front()); if (rem > 0) { uint8_t first = bytes[0]; if (first < 0x80) { // 1 byte character diff --git a/dCommon/MD5.cpp b/dCommon/MD5.cpp index d02b540d8..264d10082 100644 --- a/dCommon/MD5.cpp +++ b/dCommon/MD5.cpp @@ -133,8 +133,8 @@ void MD5::init() { // decodes input (unsigned char) into output (uint4). Assumes len is a multiple of 4. void MD5::decode(uint4 output[], const uint1 input[], size_type len) { for (unsigned int i = 0, j = 0; j < len; i++, j += 4) - output[i] = ((uint4)input[j]) | (((uint4)input[j + 1]) << 8) | - (((uint4)input[j + 2]) << 16) | (((uint4)input[j + 3]) << 24); + output[i] = static_cast(input[j]) | (static_cast(input[j + 1]) << 8) | + (static_cast(input[j + 2]) << 16) | (static_cast(input[j + 3]) << 24); } ////////////////////////////// @@ -278,7 +278,7 @@ void MD5::update(const unsigned char input[], size_type length) { // for convenience provide a verson with signed char void MD5::update(const char input[], size_type length) { - update((const unsigned char*)input, length); + update(reinterpret_cast(input), length); } ////////////////////////////// diff --git a/dCommon/Metrics.cpp b/dCommon/Metrics.cpp index 8df431472..4d58b83ce 100644 --- a/dCommon/Metrics.cpp +++ b/dCommon/Metrics.cpp @@ -107,7 +107,7 @@ void Metrics::EndMeasurement(MetricVariable variable) { } float Metrics::ToMiliseconds(int64_t nanoseconds) { - return (float)nanoseconds / 1e6; + return static_cast(nanoseconds) / 1e6; } std::string Metrics::MetricVariableToString(MetricVariable variable) { diff --git a/dCommon/NiPoint3.cpp b/dCommon/NiPoint3.cpp index 5ad06f302..d8abb739f 100644 --- a/dCommon/NiPoint3.cpp +++ b/dCommon/NiPoint3.cpp @@ -114,13 +114,13 @@ bool NiPoint3::operator!=(const NiPoint3& point) const { //! Operator for subscripting float& NiPoint3::operator[](int i) { float* base = &x; - return (float&)base[i]; + return const_cast(base[i]); } //! Operator for subscripting const float& NiPoint3::operator[](int i) const { const float* base = &x; - return (float&)base[i]; + return const_cast(base[i]); } //! Operator for addition of vectors @@ -181,7 +181,7 @@ bool NiPoint3::IsWithinAxisAlignedBox(const NiPoint3& minPoint, const NiPoint3& if (this->y < minPoint.y) return false; if (this->y > maxPoint.y) return false; - return (this->z < maxPoint.z&& this->z > minPoint.z); + return (this->z < maxPoint.z && this->z > minPoint.z); } //! Checks to see if the point (or vector) is within a sphere @@ -232,10 +232,21 @@ NiPoint3 NiPoint3::MoveTowards(const NiPoint3& current, const NiPoint3& target, float dx = target.x - current.x; float dy = target.y - current.y; float dz = target.z - current.z; - float lengthSquared = (float)((double)dx * (double)dx + (double)dy * (double)dy + (double)dz * (double)dz); - if ((double)lengthSquared == 0.0 || (double)maxDistanceDelta >= 0.0 && (double)lengthSquared <= (double)maxDistanceDelta * (double)maxDistanceDelta) + + float lengthSquared = static_cast( + static_cast(dx) * static_cast(dx) + + static_cast(dy) * static_cast(dy) + + static_cast(dz) * static_cast(dz) + ); + + if (static_cast(lengthSquared) == 0.0 + || static_cast(maxDistanceDelta) >= 0.0 + && static_cast(lengthSquared) + <= static_cast(maxDistanceDelta) * static_cast(maxDistanceDelta)) { return target; - float length = (float)std::sqrt((double)lengthSquared); + } + + float length = static_cast(std::sqrt(static_cast(lengthSquared))); return NiPoint3(current.x + dx / length * maxDistanceDelta, current.y + dy / length * maxDistanceDelta, current.z + dz / length * maxDistanceDelta); } diff --git a/dCommon/SHA512.cpp b/dCommon/SHA512.cpp index f5a71d997..ffd768db9 100644 --- a/dCommon/SHA512.cpp +++ b/dCommon/SHA512.cpp @@ -51,7 +51,7 @@ void SHA512::transform(const unsigned char* message, unsigned int block_nb) { uint64 t1, t2; const unsigned char* sub_block; int i, j; - for (i = 0; i < (int)block_nb; i++) { + for (i = 0; i < static_cast(block_nb); i++) { sub_block = message + (i << 7); for (j = 0; j < 16; j++) { SHA2_PACK64(&sub_block[j << 3], &w[j]); @@ -140,7 +140,7 @@ std::string sha512(std::string input) { memset(digest, 0, SHA512::DIGEST_SIZE); class SHA512 ctx; ctx.init(); - ctx.update((unsigned char*)input.c_str(), input.length()); + ctx.update(reinterpret_cast(const_cast(input.c_str())), input.length()); ctx.final(digest); char buf[2 * SHA512::DIGEST_SIZE + 1]; diff --git a/dCommon/dClient/AssetManager.cpp b/dCommon/dClient/AssetManager.cpp index 00bae6ce0..98a71e372 100644 --- a/dCommon/dClient/AssetManager.cpp +++ b/dCommon/dClient/AssetManager.cpp @@ -81,8 +81,8 @@ bool AssetManager::HasFile(const char* name) { std::replace(fixedName.begin(), fixedName.end(), '/', '\\'); if (fixedName.rfind("client\\res\\", 0) != 0) fixedName = "client\\res\\" + fixedName; - uint32_t crc = crc32b(0xFFFFFFFF, (uint8_t*)fixedName.c_str(), fixedName.size()); - crc = crc32b(crc, (Bytef*)"\0\0\0\0", 4); + uint32_t crc = crc32b(0xFFFFFFFF, reinterpret_cast(const_cast(fixedName.c_str())), fixedName.size()); + crc = crc32b(crc, reinterpret_cast(const_cast("\0\0\0\0")), 4); for (const auto& item : this->m_PackIndex->GetPackFileIndices()) { if (item.m_Crc == crc) { @@ -113,7 +113,7 @@ bool AssetManager::GetFile(const char* name, char** data, uint32_t* len) { #endif fseek(file, 0, SEEK_END); *len = ftell(file); - *data = (char*)malloc(*len); + *data = static_cast(malloc(*len)); fseek(file, 0, SEEK_SET); int32_t readInData = fread(*data, sizeof(uint8_t), *len, file); fclose(file); @@ -129,8 +129,8 @@ bool AssetManager::GetFile(const char* name, char** data, uint32_t* len) { fixedName = "client\\res\\" + fixedName; } int32_t packIndex = -1; - uint32_t crc = crc32b(0xFFFFFFFF, (uint8_t*)fixedName.c_str(), fixedName.size()); - crc = crc32b(crc, (Bytef*)"\0\0\0\0", 4); + uint32_t crc = crc32b(0xFFFFFFFF, reinterpret_cast(const_cast(fixedName.c_str())), fixedName.size()); + crc = crc32b(crc, reinterpret_cast(const_cast("\0\0\0\0")), 4); for (const auto& item : this->m_PackIndex->GetPackFileIndices()) { if (item.m_Crc == crc) { @@ -167,7 +167,7 @@ uint32_t AssetManager::crc32b(uint32_t base, uint8_t* message, size_t l) { crc = base; for (i = 0; i < l; i++) { // xor next byte to upper bits of crc - crc ^= (((unsigned int)message[i]) << 24); + crc ^= (static_cast(message[i]) << 24); for (j = 0; j < 8; j++) { // Do eight times. msb = crc >> 31; crc <<= 1; diff --git a/dCommon/dClient/Pack.cpp b/dCommon/dClient/Pack.cpp index 11345fc92..cf32a53fe 100644 --- a/dCommon/dClient/Pack.cpp +++ b/dCommon/dClient/Pack.cpp @@ -76,7 +76,7 @@ bool Pack::ReadFileFromPack(uint32_t crc, char** data, uint32_t* len) { fseek(file, pos, SEEK_SET); if (!isCompressed) { - char* tempData = (char*)malloc(pkRecord.m_UncompressedSize); + char* tempData = static_cast(malloc(pkRecord.m_UncompressedSize)); int32_t readInData = fread(tempData, sizeof(uint8_t), pkRecord.m_UncompressedSize, file); *data = tempData; @@ -90,7 +90,7 @@ bool Pack::ReadFileFromPack(uint32_t crc, char** data, uint32_t* len) { fseek(file, pos, SEEK_SET); - char* decompressedData = (char*)malloc(pkRecord.m_UncompressedSize); + char* decompressedData = static_cast(malloc(pkRecord.m_UncompressedSize)); uint32_t currentReadPos = 0; while (true) { @@ -100,12 +100,12 @@ bool Pack::ReadFileFromPack(uint32_t crc, char** data, uint32_t* len) { int32_t readInData = fread(&size, sizeof(uint32_t), 1, file); pos += 4; // Move pointer position 4 to the right - char* chunk = (char*)malloc(size); + char* chunk = static_cast(malloc(size)); int32_t readInData2 = fread(chunk, sizeof(int8_t), size, file); pos += size; // Move pointer position the amount of bytes read to the right int32_t err; - currentReadPos += ZCompression::Decompress((uint8_t*)chunk, size, reinterpret_cast(decompressedData + currentReadPos), ZCompression::MAX_SD0_CHUNK_SIZE, err); + currentReadPos += ZCompression::Decompress(reinterpret_cast(chunk), size, reinterpret_cast(decompressedData + currentReadPos), ZCompression::MAX_SD0_CHUNK_SIZE, err); free(chunk); } diff --git a/dDatabase/CDClientDatabase/CDClientTables/CDComponentsRegistryTable.cpp b/dDatabase/CDClientDatabase/CDClientTables/CDComponentsRegistryTable.cpp index e6b293388..3cf7ac621 100644 --- a/dDatabase/CDClientDatabase/CDClientTables/CDComponentsRegistryTable.cpp +++ b/dDatabase/CDClientDatabase/CDClientTables/CDComponentsRegistryTable.cpp @@ -38,7 +38,7 @@ int32_t CDComponentsRegistryTable::GetByIDAndType(uint32_t id, eReplicaComponent entry.component_type = static_cast(tableData.getIntField("component_type", 0)); entry.component_id = tableData.getIntField("component_id", -1); - this->mappedEntries.insert_or_assign(staitc_cast(entry.component_type) << 32 | static_cast(entry.id), entry.component_id); + this->mappedEntries.insert_or_assign(static_cast(entry.component_type) << 32 | static_cast(entry.id), entry.component_id); tableData.nextRow(); } @@ -49,4 +49,3 @@ int32_t CDComponentsRegistryTable::GetByIDAndType(uint32_t id, eReplicaComponent return iter == this->mappedEntries.end() ? defaultValue : iter->second; } - diff --git a/dDatabase/CDClientDatabase/CDClientTables/CDMissionEmailTable.cpp b/dDatabase/CDClientDatabase/CDClientTables/CDMissionEmailTable.cpp index 207d3815d..330acc18a 100644 --- a/dDatabase/CDClientDatabase/CDClientTables/CDMissionEmailTable.cpp +++ b/dDatabase/CDClientDatabase/CDClientTables/CDMissionEmailTable.cpp @@ -25,7 +25,7 @@ void CDMissionEmailTable::LoadValuesFromDatabase() { entry.notificationGroup = tableData.getIntField("notificationGroup", -1); entry.missionID = tableData.getIntField("missionID", -1); entry.attachmentLOT = tableData.getIntField("attachmentLOT", 0); - entry.localize = (bool)tableData.getIntField("localize", -1); + entry.localize = static_cast(tableData.getIntField("localize", -1)); entry.locStatus = tableData.getIntField("locStatus", -1); entry.gate_version = tableData.getStringField("gate_version", ""); @@ -50,4 +50,3 @@ std::vector CDMissionEmailTable::Query(std::function& CDMissionEmailTable::GetEntries() const { return this->entries; } - diff --git a/dDatabase/CMakeLists.txt b/dDatabase/CMakeLists.txt index 20f37becf..8bdcea341 100644 --- a/dDatabase/CMakeLists.txt +++ b/dDatabase/CMakeLists.txt @@ -14,3 +14,8 @@ endforeach() add_library(dDatabase STATIC ${DDATABASE_SOURCES}) target_link_libraries(dDatabase sqlite3 mariadbConnCpp) + +# If using gcc, warn on old-style C casts +if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU") + set_source_files_properties(${DDATABASE_SOURCES} PROPERTIES COMPILE_FLAGS "-Wold-style-cast") +endif() diff --git a/dGame/CMakeLists.txt b/dGame/CMakeLists.txt index 80f160426..59588b4ab 100644 --- a/dGame/CMakeLists.txt +++ b/dGame/CMakeLists.txt @@ -63,3 +63,8 @@ endforeach() add_library(dGame STATIC ${DGAME_SOURCES}) target_link_libraries(dGame dDatabase Recast Detour) + +# If using gcc, warn on old-style C casts +if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU") + set_source_files_properties(${DGAME_SOURCES} PROPERTIES COMPILE_FLAGS "-Wold-style-cast") +endif() diff --git a/dGame/dBehaviors/Behavior.cpp b/dGame/dBehaviors/Behavior.cpp index b32c7c520..c70b34c7b 100644 --- a/dGame/dBehaviors/Behavior.cpp +++ b/dGame/dBehaviors/Behavior.cpp @@ -368,11 +368,11 @@ void Behavior::PlayFx(std::u16string type, const LWOOBJID target, const LWOOBJID if (!type.empty()) { typeQuery.bind(1, typeString.c_str()); - typeQuery.bind(2, (int)effectId); + typeQuery.bind(2, static_cast(effectId)); result = typeQuery.execQuery(); } else { - idQuery.bind(1, (int)effectId); + idQuery.bind(1, static_cast(effectId)); result = idQuery.execQuery(); } diff --git a/dGame/dBehaviors/BehaviorContext.cpp b/dGame/dBehaviors/BehaviorContext.cpp index d23ee596e..77376558c 100644 --- a/dGame/dBehaviors/BehaviorContext.cpp +++ b/dGame/dBehaviors/BehaviorContext.cpp @@ -249,7 +249,7 @@ bool BehaviorContext::CalculateUpdate(const float deltaTime) { entry.behavior->SyncCalculation(this, bitStream, entry.branchContext); if (!clientInitalized) { - echo.sBitStream.assign((char*)bitStream->GetData(), bitStream->GetNumberOfBytesUsed()); + echo.sBitStream.assign(reinterpret_cast(bitStream->GetData()), bitStream->GetNumberOfBytesUsed()); // Write message RakNet::BitStream message; diff --git a/dGame/dBehaviors/SwitchMultipleBehavior.cpp b/dGame/dBehaviors/SwitchMultipleBehavior.cpp index 947c331fc..faaa0d232 100644 --- a/dGame/dBehaviors/SwitchMultipleBehavior.cpp +++ b/dGame/dBehaviors/SwitchMultipleBehavior.cpp @@ -42,7 +42,7 @@ void SwitchMultipleBehavior::Load() { "(select bP2.value FROM BehaviorParameter bP2 WHERE bP2.behaviorID = ?1 AND bP2.parameterID LIKE 'value %' " "AND replace(bP1.parameterID, 'behavior ', '') = replace(bP2.parameterID, 'value ', '')) as value " "FROM BehaviorParameter bP1 WHERE bP1.behaviorID = ?1 AND bP1.parameterID LIKE 'behavior %';"); - query.bind(1, (int)this->m_behaviorId); + query.bind(1, static_cast(this->m_behaviorId)); auto result = query.execQuery(); diff --git a/dGame/dComponents/BaseCombatAIComponent.cpp b/dGame/dComponents/BaseCombatAIComponent.cpp index 26b95fa81..508376292 100644 --- a/dGame/dComponents/BaseCombatAIComponent.cpp +++ b/dGame/dComponents/BaseCombatAIComponent.cpp @@ -40,7 +40,7 @@ BaseCombatAIComponent::BaseCombatAIComponent(Entity* parent, const uint32_t id): //Grab the aggro information from BaseCombatAI: auto componentQuery = CDClientDatabase::CreatePreppedStmt( "SELECT aggroRadius, tetherSpeed, pursuitSpeed, softTetherRadius, hardTetherRadius FROM BaseCombatAIComponent WHERE id = ?;"); - componentQuery.bind(1, (int)id); + componentQuery.bind(1, static_cast(id)); auto componentResult = componentQuery.execQuery(); @@ -77,7 +77,7 @@ BaseCombatAIComponent::BaseCombatAIComponent(Entity* parent, const uint32_t id): */ auto skillQuery = CDClientDatabase::CreatePreppedStmt( "SELECT skillID, cooldown, behaviorID FROM SkillBehavior WHERE skillID IN (SELECT skillID FROM ObjectSkills WHERE objectTemplate = ?);"); - skillQuery.bind(1, (int)parent->GetLOT()); + skillQuery.bind(1, static_cast(parent->GetLOT())); auto result = skillQuery.execQuery(); @@ -523,7 +523,7 @@ bool BaseCombatAIComponent::IsMech() { void BaseCombatAIComponent::Serialize(RakNet::BitStream* outBitStream, bool bIsInitialUpdate) { outBitStream->Write(m_DirtyStateOrTarget || bIsInitialUpdate); if (m_DirtyStateOrTarget || bIsInitialUpdate) { - outBitStream->Write(m_State); + outBitStream->Write(m_State); outBitStream->Write(m_Target); m_DirtyStateOrTarget = false; } diff --git a/dGame/dComponents/BaseCombatAIComponent.h b/dGame/dComponents/BaseCombatAIComponent.h index a08b008e4..8ae046113 100644 --- a/dGame/dComponents/BaseCombatAIComponent.h +++ b/dGame/dComponents/BaseCombatAIComponent.h @@ -19,7 +19,7 @@ class Entity; /** * The current state of the AI */ -enum class AiState : int { +enum class AiState : uint32_t { idle = 0, // Doing nothing aggro, // Waiting for an enemy to cross / running back to spawn tether, // Chasing an enemy diff --git a/dGame/dComponents/BuffComponent.cpp b/dGame/dComponents/BuffComponent.cpp index 80c294566..32d7d1d40 100644 --- a/dGame/dComponents/BuffComponent.cpp +++ b/dGame/dComponents/BuffComponent.cpp @@ -431,7 +431,7 @@ const std::vector& BuffComponent::GetBuffParameters(int32_t buffI } auto query = CDClientDatabase::CreatePreppedStmt("SELECT * FROM BuffParameters WHERE BuffID = ?;"); - query.bind(1, (int)buffId); + query.bind(1, static_cast(buffId)); auto result = query.execQuery(); diff --git a/dGame/dComponents/CharacterComponent.cpp b/dGame/dComponents/CharacterComponent.cpp index 7ee174b51..6ba7db299 100644 --- a/dGame/dComponents/CharacterComponent.cpp +++ b/dGame/dComponents/CharacterComponent.cpp @@ -229,7 +229,7 @@ void CharacterComponent::LoadFromXml(tinyxml2::XMLDocument* doc) { uint32_t mapID; child->QueryAttribute("map", &mapID); - m_ZoneStatistics.insert({ (LWOMAPID)mapID, statistics }); + m_ZoneStatistics.insert({ static_cast(mapID), statistics }); child = child->NextSiblingElement(); } diff --git a/dGame/dComponents/DestroyableComponent.cpp b/dGame/dComponents/DestroyableComponent.cpp index 676fe9ace..c90cadf58 100644 --- a/dGame/dComponents/DestroyableComponent.cpp +++ b/dGame/dComponents/DestroyableComponent.cpp @@ -380,7 +380,7 @@ void DestroyableComponent::AddFaction(const int32_t factionID, const bool ignore auto query = CDClientDatabase::CreatePreppedStmt( "SELECT enemyList FROM Factions WHERE faction = ?;"); - query.bind(1, (int)factionID); + query.bind(1, static_cast(factionID)); auto result = query.execQuery(); diff --git a/dGame/dComponents/MissionComponent.cpp b/dGame/dComponents/MissionComponent.cpp index 338690306..7219589af 100644 --- a/dGame/dComponents/MissionComponent.cpp +++ b/dGame/dComponents/MissionComponent.cpp @@ -458,7 +458,7 @@ const std::vector& MissionComponent::QueryAchievements(eMissionTaskTyp bool MissionComponent::RequiresItem(const LOT lot) { auto query = CDClientDatabase::CreatePreppedStmt( "SELECT type FROM Objects WHERE id = ?;"); - query.bind(1, (int)lot); + query.bind(1, static_cast(lot)); auto result = query.execQuery(); diff --git a/dGame/dComponents/MovingPlatformComponent.cpp b/dGame/dComponents/MovingPlatformComponent.cpp index 44cd75b07..c28d3ceab 100644 --- a/dGame/dComponents/MovingPlatformComponent.cpp +++ b/dGame/dComponents/MovingPlatformComponent.cpp @@ -35,7 +35,7 @@ MoverSubComponent::~MoverSubComponent() = default; void MoverSubComponent::Serialize(RakNet::BitStream* outBitStream, bool bIsInitialUpdate) { outBitStream->Write(true); - outBitStream->Write(mState); + outBitStream->Write(mState); outBitStream->Write(mDesiredWaypointIndex); outBitStream->Write(mShouldStopAtDesiredWaypoint); outBitStream->Write(mInReverse); @@ -107,7 +107,7 @@ void MovingPlatformComponent::Serialize(RakNet::BitStream* outBitStream, bool bI if (hasPlatform) { auto* mover = static_cast(m_MoverSubComponent); - outBitStream->Write(m_MoverSubComponentType); + outBitStream->Write(m_MoverSubComponentType); if (m_MoverSubComponentType == eMoverSubComponentType::simpleMover) { // TODO diff --git a/dGame/dComponents/PetComponent.cpp b/dGame/dComponents/PetComponent.cpp index 144f64410..901d74854 100644 --- a/dGame/dComponents/PetComponent.cpp +++ b/dGame/dComponents/PetComponent.cpp @@ -114,7 +114,7 @@ void PetComponent::Serialize(RakNet::BitStream* outBitStream, bool bIsInitialUpd outBitStream->Write1(); // Always serialize as dirty for now outBitStream->Write(m_Status); - outBitStream->Write(tamed ? m_Ability : PetAbilityType::Invalid); // Something with the overhead icon? + outBitStream->Write(tamed ? m_Ability : PetAbilityType::Invalid); // Something with the overhead icon? const bool interacting = m_Interaction != LWOOBJID_EMPTY; @@ -190,7 +190,7 @@ void PetComponent::OnUse(Entity* originator) { if (cached == buildCache.end()) { auto query = CDClientDatabase::CreatePreppedStmt( "SELECT ValidPiecesLXF, PuzzleModelLot, Timelimit, NumValidPieces, imagCostPerBuild FROM TamingBuildPuzzles WHERE NPCLot = ?;"); - query.bind(1, (int)m_Parent->GetLOT()); + query.bind(1, static_cast(m_Parent->GetLOT())); auto result = query.execQuery(); diff --git a/dGame/dComponents/PetComponent.h b/dGame/dComponents/PetComponent.h index 980bb1462..ca4b5a747 100644 --- a/dGame/dComponents/PetComponent.h +++ b/dGame/dComponents/PetComponent.h @@ -6,7 +6,7 @@ #include "Preconditions.h" #include "eReplicaComponentType.h" -enum class PetAbilityType +enum class PetAbilityType : uint32_t { Invalid, GoToObject, diff --git a/dGame/dComponents/PropertyEntranceComponent.cpp b/dGame/dComponents/PropertyEntranceComponent.cpp index 83f3ccdc9..9af714930 100644 --- a/dGame/dComponents/PropertyEntranceComponent.cpp +++ b/dGame/dComponents/PropertyEntranceComponent.cpp @@ -163,7 +163,7 @@ void PropertyEntranceComponent::OnPropertyEntranceSync(Entity* entity, bool incl const auto modApproved = playerPropertyLookupResults->getBoolean(10); const auto dateLastUpdated = playerPropertyLookupResults->getInt64(11); const auto reputation = playerPropertyLookupResults->getUInt(14); - const auto performanceCost = (float)playerPropertyLookupResults->getDouble(16); + const auto performanceCost = playerPropertyLookupResults->getFloat(16); //CHECK THIS playerEntry = SetPropertyValues(playerEntry, cloneId, character->GetName(), propertyName, propertyDescription, reputation, true, true, modApproved, true, true, privacyOption, dateLastUpdated, performanceCost); } else { @@ -203,7 +203,7 @@ void PropertyEntranceComponent::OnPropertyEntranceSync(Entity* entity, bool incl const auto modApproved = propertyEntry->getBoolean(10); const auto dateLastUpdated = propertyEntry->getInt(11); const float reputation = propertyEntry->getInt(14); - const auto performanceCost = (float)propertyEntry->getDouble(16); + const auto performanceCost = propertyEntry->getFloat(16); // CHECK THIS PropertySelectQueryProperty entry{}; diff --git a/dGame/dComponents/PropertyManagementComponent.cpp b/dGame/dComponents/PropertyManagementComponent.cpp index 7877b2c9c..de37308fe 100644 --- a/dGame/dComponents/PropertyManagementComponent.cpp +++ b/dGame/dComponents/PropertyManagementComponent.cpp @@ -92,7 +92,7 @@ std::vector PropertyManagementComponent::GetPaths() const { auto query = CDClientDatabase::CreatePreppedStmt( "SELECT path FROM PropertyTemplate WHERE mapID = ?;"); - query.bind(1, (int)zoneId); + query.bind(1, static_cast(zoneId)); auto result = query.execQuery(); diff --git a/dGame/dComponents/RacingControlComponent.cpp b/dGame/dComponents/RacingControlComponent.cpp index 278d3f44f..ef1d0f32d 100644 --- a/dGame/dComponents/RacingControlComponent.cpp +++ b/dGame/dComponents/RacingControlComponent.cpp @@ -401,18 +401,18 @@ void RacingControlComponent::HandleMessageBoxResponse(Entity* player, int32_t bu if (missionComponent == nullptr) return; - missionComponent->Progress(eMissionTaskType::RACING, 0, (LWOOBJID)eRacingTaskParam::COMPETED_IN_RACE); // Progress task for competing in a race - missionComponent->Progress(eMissionTaskType::RACING, data->smashedTimes, (LWOOBJID)eRacingTaskParam::SAFE_DRIVER); // Finish a race without being smashed. + missionComponent->Progress(eMissionTaskType::RACING, 0, static_cast(eRacingTaskParam::COMPETED_IN_RACE)); // Progress task for competing in a race + missionComponent->Progress(eMissionTaskType::RACING, data->smashedTimes, static_cast(eRacingTaskParam::SAFE_DRIVER)); // Finish a race without being smashed. // If solo racing is enabled OR if there are 3 players in the race, progress placement tasks. if (m_SoloRacing || m_LoadedPlayers > 2) { - missionComponent->Progress(eMissionTaskType::RACING, data->finished, (LWOOBJID)eRacingTaskParam::FINISH_WITH_PLACEMENT); // Finish in 1st place on a race + missionComponent->Progress(eMissionTaskType::RACING, data->finished, static_cast(eRacingTaskParam::FINISH_WITH_PLACEMENT)); // Finish in 1st place on a race if (data->finished == 1) { - missionComponent->Progress(eMissionTaskType::RACING, Game::zoneManager->GetZone()->GetWorldID(), (LWOOBJID)eRacingTaskParam::FIRST_PLACE_MULTIPLE_TRACKS); // Finish in 1st place on multiple tracks. - missionComponent->Progress(eMissionTaskType::RACING, Game::zoneManager->GetZone()->GetWorldID(), (LWOOBJID)eRacingTaskParam::WIN_RACE_IN_WORLD); // Finished first place in specific world. + missionComponent->Progress(eMissionTaskType::RACING, Game::zoneManager->GetZone()->GetWorldID(), static_cast(eRacingTaskParam::FIRST_PLACE_MULTIPLE_TRACKS)); // Finish in 1st place on multiple tracks. + missionComponent->Progress(eMissionTaskType::RACING, Game::zoneManager->GetZone()->GetWorldID(), static_cast(eRacingTaskParam::WIN_RACE_IN_WORLD)); // Finished first place in specific world. } if (data->finished == m_LoadedPlayers) { - missionComponent->Progress(eMissionTaskType::RACING, Game::zoneManager->GetZone()->GetWorldID(), (LWOOBJID)eRacingTaskParam::LAST_PLACE_FINISH); // Finished first place in specific world. + missionComponent->Progress(eMissionTaskType::RACING, Game::zoneManager->GetZone()->GetWorldID(), static_cast(eRacingTaskParam::LAST_PLACE_FINISH)); // Finished first place in specific world. } } } else if ((id == "ACT_RACE_EXIT_THE_RACE?" || id == "Exit") && button == m_ActivityExitConfirm) { @@ -794,7 +794,7 @@ void RacingControlComponent::Update(float deltaTime) { const auto& position = waypoint.position; - if (std::abs((int)respawnIndex - (int)player.respawnIndex) > 10 && + if (std::abs(static_cast(respawnIndex) - static_cast(player.respawnIndex)) > 10 && player.respawnIndex != path->pathWaypoints.size() - 1) { ++respawnIndex; @@ -848,7 +848,7 @@ void RacingControlComponent::Update(float deltaTime) { if (missionComponent != nullptr) { // Progress lap time tasks - missionComponent->Progress(eMissionTaskType::RACING, (lapTime) * 1000, (LWOOBJID)eRacingTaskParam::LAP_TIME); + missionComponent->Progress(eMissionTaskType::RACING, (lapTime) * 1000, static_cast(eRacingTaskParam::LAP_TIME)); if (player.lap == 3) { m_Finished++; @@ -864,7 +864,7 @@ void RacingControlComponent::Update(float deltaTime) { LeaderboardManager::SaveScore(playerEntity->GetObjectID(), m_ActivityID, static_cast(player.raceTime), static_cast(player.bestLapTime), static_cast(player.finished == 1)); // Entire race time - missionComponent->Progress(eMissionTaskType::RACING, (raceTime) * 1000, (LWOOBJID)eRacingTaskParam::TOTAL_TRACK_TIME); + missionComponent->Progress(eMissionTaskType::RACING, (raceTime) * 1000, static_cast(eRacingTaskParam::TOTAL_TRACK_TIME)); auto* characterComponent = playerEntity->GetComponent(); if (characterComponent != nullptr) { diff --git a/dGame/dComponents/SkillComponent.cpp b/dGame/dComponents/SkillComponent.cpp index 7762345e1..b65c7d216 100644 --- a/dGame/dComponents/SkillComponent.cpp +++ b/dGame/dComponents/SkillComponent.cpp @@ -89,7 +89,7 @@ void SkillComponent::SyncPlayerProjectile(const LWOOBJID projectileId, RakNet::B auto query = CDClientDatabase::CreatePreppedStmt( "SELECT behaviorID FROM SkillBehavior WHERE skillID = (SELECT skillID FROM ObjectSkills WHERE objectTemplate = ?);"); - query.bind(1, (int)sync_entry.lot); + query.bind(1, static_cast(sync_entry.lot)); auto result = query.execQuery(); @@ -299,7 +299,7 @@ SkillExecutionResult SkillComponent::CalculateBehavior(const uint32_t skillId, c } //start.optionalTargetID = target; - start.sBitStream.assign((char*)bitStream->GetData(), bitStream->GetNumberOfBytesUsed()); + start.sBitStream.assign(reinterpret_cast(bitStream->GetData()), bitStream->GetNumberOfBytesUsed()); // Write message RakNet::BitStream message; @@ -409,7 +409,7 @@ void SkillComponent::SyncProjectileCalculation(const ProjectileSyncEntry& entry) auto query = CDClientDatabase::CreatePreppedStmt( "SELECT behaviorID FROM SkillBehavior WHERE skillID = (SELECT skillID FROM ObjectSkills WHERE objectTemplate = ?);"); - query.bind(1, (int)entry.lot); + query.bind(1, static_cast(entry.lot)); auto result = query.execQuery(); if (result.eof()) { @@ -430,7 +430,7 @@ void SkillComponent::SyncProjectileCalculation(const ProjectileSyncEntry& entry) DoClientProjectileImpact projectileImpact; - projectileImpact.sBitStream.assign((char*)bitStream->GetData(), bitStream->GetNumberOfBytesUsed()); + projectileImpact.sBitStream.assign(reinterpret_cast(bitStream->GetData()), bitStream->GetNumberOfBytesUsed()); projectileImpact.i64OwnerID = this->m_Parent->GetObjectID(); projectileImpact.i64OrgID = entry.id; projectileImpact.i64TargetID = entry.branchContext.target; diff --git a/dGame/dGameMessages/GameMessageHandler.cpp b/dGame/dGameMessages/GameMessageHandler.cpp index 63b9d7e9a..b9e5284d6 100644 --- a/dGame/dGameMessages/GameMessageHandler.cpp +++ b/dGame/dGameMessages/GameMessageHandler.cpp @@ -269,7 +269,7 @@ void GameMessageHandler::HandleMessage(RakNet::BitStream* inStream, const System auto* skill_component = entity->GetComponent(); if (skill_component != nullptr) { - auto* bs = new RakNet::BitStream((unsigned char*)message.sBitStream.c_str(), message.sBitStream.size(), false); + auto* bs = new RakNet::BitStream(reinterpret_cast(const_cast(message.sBitStream.c_str())), message.sBitStream.size(), false); skill_component->SyncPlayerProjectile(message.i64LocalID, bs, message.i64TargetID); @@ -296,7 +296,7 @@ void GameMessageHandler::HandleMessage(RakNet::BitStream* inStream, const System bool success = false; if (behaviorId > 0) { - RakNet::BitStream* bs = new RakNet::BitStream((unsigned char*)startSkill.sBitStream.c_str(), startSkill.sBitStream.size(), false); + RakNet::BitStream* bs = new RakNet::BitStream(reinterpret_cast(const_cast(startSkill.sBitStream.c_str())), startSkill.sBitStream.size(), false); auto* skillComponent = entity->GetComponent(); @@ -353,7 +353,7 @@ void GameMessageHandler::HandleMessage(RakNet::BitStream* inStream, const System } if (usr != nullptr) { - RakNet::BitStream* bs = new RakNet::BitStream((unsigned char*)sync.sBitStream.c_str(), sync.sBitStream.size(), false); + RakNet::BitStream* bs = new RakNet::BitStream(reinterpret_cast(const_cast(sync.sBitStream.c_str())), sync.sBitStream.size(), false); auto* skillComponent = entity->GetComponent(); diff --git a/dGame/dGameMessages/GameMessages.cpp b/dGame/dGameMessages/GameMessages.cpp index a21ee992b..368237f38 100644 --- a/dGame/dGameMessages/GameMessages.cpp +++ b/dGame/dGameMessages/GameMessages.cpp @@ -389,7 +389,7 @@ void GameMessages::SendPlatformResync(Entity* entity, const SystemAddress& sysAd bitStream.Write(bReverse); bitStream.Write(bStopAtDesiredWaypoint); bitStream.Write(eCommand); - bitStream.Write(movementState); + bitStream.Write(static_cast(movementState)); bitStream.Write(eUnexpectedCommand); bitStream.Write(fIdleTimeElapsed); bitStream.Write(fMoveTimeElapsed); @@ -582,7 +582,7 @@ void GameMessages::SendNotifyMissionTask(Entity* entity, const SystemAddress& sy bitStream.Write(missionID); bitStream.Write(taskMask); - bitStream.Write((unsigned char)updates.size()); + bitStream.Write(updates.size()); for (uint32_t i = 0; i < updates.size(); ++i) { bitStream.Write(updates[i]); @@ -1950,7 +1950,7 @@ void GameMessages::SendBBBSaveResponse(const LWOOBJID& objectId, const LWOOBJID& bitStream.Write(buffer[i]); SEND_PACKET; - PacketUtils::SavePacket("eGameMessageType::BBB_SAVE_RESPONSE.bin", (char*)bitStream.GetData(), bitStream.GetNumberOfBytesUsed()); + PacketUtils::SavePacket("eGameMessageType::BBB_SAVE_RESPONSE.bin", reinterpret_cast(bitStream.GetData()), bitStream.GetNumberOfBytesUsed()); } // Property @@ -4916,7 +4916,7 @@ void GameMessages::HandleFireEventServerSide(RakNet::BitStream* inStream, Entity mapId = Game::zoneManager->GetZoneID().GetMapID(); // Fallback to sending the player back to the same zone. } - LOG("Player %llu has requested zone transfer to (%i, %i).", sender->GetObjectID(), (int)mapId, (int)cloneId); + LOG("Player %llu has requested zone transfer to (%i, %i).", sender->GetObjectID(), static_cast(mapId), static_cast(cloneId)); auto* character = player->GetCharacter(); @@ -6070,7 +6070,7 @@ void GameMessages::HandleUpdatePlayerStatistic(RakNet::BitStream* inStream, Enti auto* characterComponent = entity->GetComponent(); if (characterComponent != nullptr) { - characterComponent->UpdatePlayerStatistic((StatisticID)updateID, static_cast(std::max(updateValue, static_cast(0)))); + characterComponent->UpdatePlayerStatistic(static_cast(updateID), static_cast(std::max(updateValue, static_cast(0)))); } } diff --git a/dGame/dInventory/ItemSet.cpp b/dGame/dInventory/ItemSet.cpp index a8e587399..3364b63b5 100644 --- a/dGame/dInventory/ItemSet.cpp +++ b/dGame/dInventory/ItemSet.cpp @@ -19,7 +19,7 @@ ItemSet::ItemSet(const uint32_t id, InventoryComponent* inventoryComponent) { auto query = CDClientDatabase::CreatePreppedStmt( "SELECT skillSetWith2, skillSetWith3, skillSetWith4, skillSetWith5, skillSetWith6, itemIDs FROM ItemSets WHERE setID = ?;"); - query.bind(1, (int)id); + query.bind(1, static_cast(id)); auto result = query.execQuery(); diff --git a/dGame/dMission/Mission.cpp b/dGame/dMission/Mission.cpp index c190ec505..17de70a18 100644 --- a/dGame/dMission/Mission.cpp +++ b/dGame/dMission/Mission.cpp @@ -329,9 +329,9 @@ void Mission::Complete(const bool yieldRewards) { missionComponent->Progress(eMissionTaskType::META, info.id); - missionComponent->Progress(eMissionTaskType::RACING, info.id, (LWOOBJID)eRacingTaskParam::COMPLETE_ANY_RACING_TASK); + missionComponent->Progress(eMissionTaskType::RACING, info.id, static_cast(eRacingTaskParam::COMPLETE_ANY_RACING_TASK)); - missionComponent->Progress(eMissionTaskType::RACING, info.id, (LWOOBJID)eRacingTaskParam::COMPLETE_TRACK_TASKS); + missionComponent->Progress(eMissionTaskType::RACING, info.id, static_cast(eRacingTaskParam::COMPLETE_TRACK_TASKS)); auto* missionEmailTable = CDClientManager::Instance().GetTable(); diff --git a/dGame/dUtilities/Loot.cpp b/dGame/dUtilities/Loot.cpp index 09c465bf4..25c81e749 100644 --- a/dGame/dUtilities/Loot.cpp +++ b/dGame/dUtilities/Loot.cpp @@ -242,7 +242,7 @@ void Loot::GiveActivityLoot(Entity* player, Entity* source, uint32_t activityID, GiveLoot(player, selectedReward->LootMatrixIndex, eLootSourceType::ACTIVITY); - uint32_t coins = (int)(minCoins + GeneralUtils::GenerateRandomNumber(0, 1) * (maxCoins - minCoins)); + uint32_t coins = static_cast(minCoins + GeneralUtils::GenerateRandomNumber(0, 1) * (maxCoins - minCoins)); auto* character = player->GetCharacter(); @@ -280,7 +280,7 @@ void Loot::DropLoot(Entity* player, Entity* killedObject, std::unordered_map(0, 1) * (maxCoins - minCoins)); + uint32_t coins = static_cast(minCoins + GeneralUtils::GenerateRandomNumber(0, 1) * (maxCoins - minCoins)); GameMessages::SendDropClientLoot(player, source, LOT_NULL, coins, spawnPosition); } diff --git a/dGame/dUtilities/Preconditions.cpp b/dGame/dUtilities/Preconditions.cpp index 46ee7c183..12059b5bf 100644 --- a/dGame/dUtilities/Preconditions.cpp +++ b/dGame/dUtilities/Preconditions.cpp @@ -19,7 +19,7 @@ std::map Preconditions::cache = {}; Precondition::Precondition(const uint32_t condition) { auto query = CDClientDatabase::CreatePreppedStmt( "SELECT type, targetLOT, targetCount FROM Preconditions WHERE id = ?;"); - query.bind(1, (int)condition); + query.bind(1, static_cast(condition)); auto result = query.execQuery(); diff --git a/dGame/dUtilities/SlashCommandHandler.cpp b/dGame/dUtilities/SlashCommandHandler.cpp index 41b3c21de..104b12326 100644 --- a/dGame/dUtilities/SlashCommandHandler.cpp +++ b/dGame/dUtilities/SlashCommandHandler.cpp @@ -1191,9 +1191,9 @@ void SlashCommandHandler::HandleChatCommand(const std::u16string& command, Entit auto dest = static_cast(entity->GetComponent(eReplicaComponentType::DESTROYABLE)); if (dest) { - dest->SetHealth((int)dest->GetMaxHealth()); - dest->SetArmor((int)dest->GetMaxArmor()); - dest->SetImagination((int)dest->GetMaxImagination()); + dest->SetHealth(static_cast(dest->GetMaxHealth())); + dest->SetArmor(static_cast(dest->GetMaxArmor())); + dest->SetImagination(static_cast(dest->GetMaxImagination())); } Game::entityManager->SerializeEntity(entity); @@ -1317,7 +1317,7 @@ void SlashCommandHandler::HandleChatCommand(const std::u16string& command, Entit int32_t type; if (args.size() >= 2 && GeneralUtils::TryParse(args[1], type)) { - lootType = (eLootSourceType)type; + lootType = static_cast(type); } GameMessages::SendModifyLEGOScore(entity, entity->GetSystemAddress(), uscore, lootType); @@ -1357,7 +1357,7 @@ void SlashCommandHandler::HandleChatCommand(const std::u16string& command, Entit if (!characterComponent) return; auto levelComponent = entity->GetComponent(); auto query = CDClientDatabase::CreatePreppedStmt("SELECT requiredUScore from LevelProgressionLookup WHERE id = ?;"); - query.bind(1, (int)requestedLevel); + query.bind(1, static_cast(requestedLevel)); auto result = query.execQuery(); if (result.eof()) return; @@ -1741,13 +1741,13 @@ void SlashCommandHandler::HandleChatCommand(const std::u16string& command, Entit ChatPackets::SendSystemMessage( sysAddr, - u"Peak RSS: " + GeneralUtils::to_u16string((float)((double)Metrics::GetPeakRSS() / 1.024e6)) + + u"Peak RSS: " + GeneralUtils::to_u16string(static_cast(static_cast(Metrics::GetPeakRSS()) / 1.024e6)) + u"MB" ); ChatPackets::SendSystemMessage( sysAddr, - u"Current RSS: " + GeneralUtils::to_u16string((float)((double)Metrics::GetCurrentRSS() / 1.024e6)) + + u"Current RSS: " + GeneralUtils::to_u16string(static_cast(static_cast(Metrics::GetCurrentRSS()) / 1.024e6)) + u"MB" ); @@ -1807,7 +1807,7 @@ void SlashCommandHandler::HandleChatCommand(const std::u16string& command, Entit + u" times. It ran " + GeneralUtils::to_u16string(totalRuns) + u" times. Averaging out at " - + GeneralUtils::to_u16string((float)totalRuns / loops); + + GeneralUtils::to_u16string(static_cast(totalRuns) / loops); ChatPackets::SendSystemMessage(sysAddr, message); } diff --git a/dMasterServer/CMakeLists.txt b/dMasterServer/CMakeLists.txt index 2161681f8..ddba5c49a 100644 --- a/dMasterServer/CMakeLists.txt +++ b/dMasterServer/CMakeLists.txt @@ -12,3 +12,8 @@ target_link_libraries(MasterServer ${COMMON_LIBRARIES} dMasterServer) if(WIN32) add_dependencies(MasterServer WorldServer AuthServer ChatServer) endif() + +# If using gcc, warn on old-style C casts +if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU") + set_source_files_properties(${DMASTERSERVER_SOURCES} PROPERTIES COMPILE_FLAGS "-Wold-style-cast") +endif() diff --git a/dNavigation/CMakeLists.txt b/dNavigation/CMakeLists.txt index 4c03d24b2..f94ae4932 100644 --- a/dNavigation/CMakeLists.txt +++ b/dNavigation/CMakeLists.txt @@ -8,3 +8,8 @@ endforeach() add_library(dNavigation STATIC ${DNAVIGATION_SOURCES}) target_link_libraries(dNavigation Detour Recast) + +# If using gcc, warn on old-style C casts +if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU") + set_source_files_properties(${DNAVIGATION_SOURCES} PROPERTIES COMPILE_FLAGS "-Wold-style-cast") +endif() diff --git a/dNavigation/dNavMesh.cpp b/dNavigation/dNavMesh.cpp index c1d752bd9..ab9ed2d50 100644 --- a/dNavigation/dNavMesh.cpp +++ b/dNavigation/dNavMesh.cpp @@ -105,7 +105,7 @@ void dNavMesh::LoadNavmesh() { if (!tileHeader.tileRef || !tileHeader.dataSize) break; - unsigned char* data = (unsigned char*)dtAlloc(tileHeader.dataSize, DT_ALLOC_PERM); + unsigned char* data = static_cast(dtAlloc(tileHeader.dataSize, DT_ALLOC_PERM)); if (!data) break; memset(data, 0, tileHeader.dataSize); readLen = fread(data, tileHeader.dataSize, 1, fp); diff --git a/dNet/AuthPackets.cpp b/dNet/AuthPackets.cpp index da375193c..83c1f58e3 100644 --- a/dNet/AuthPackets.cpp +++ b/dNet/AuthPackets.cpp @@ -155,7 +155,7 @@ void AuthPackets::SendLoginResponse(dServer* server, const SystemAddress& sysAdd RakNet::BitStream packet; BitStreamUtils::WriteHeader(packet, eConnectionType::CLIENT, eClientMessageType::LOGIN_RESPONSE); - packet.Write(responseCode); + packet.Write(GeneralUtils::CastUnderlyingType(responseCode)); // Event Gating packet.Write(LUString(Game::config->GetValue("event_1"))); diff --git a/dNet/BitStreamUtils.h b/dNet/BitStreamUtils.h index 6daa1c176..7403d0e18 100644 --- a/dNet/BitStreamUtils.h +++ b/dNet/BitStreamUtils.h @@ -47,9 +47,9 @@ struct LUWString { namespace BitStreamUtils { template void WriteHeader(RakNet::BitStream& bitStream, eConnectionType connectionType, T internalPacketID) { - bitStream.Write(MessageID(ID_USER_PACKET_ENUM)); + bitStream.Write(ID_USER_PACKET_ENUM); bitStream.Write(connectionType); - bitStream.Write(static_cast(internalPacketID)); + bitStream.Write(static_cast(internalPacketID)); bitStream.Write(0); } diff --git a/dNet/CMakeLists.txt b/dNet/CMakeLists.txt index 938c04493..6fb830361 100644 --- a/dNet/CMakeLists.txt +++ b/dNet/CMakeLists.txt @@ -9,3 +9,8 @@ set(DNET_SOURCES "AuthPackets.cpp" add_library(dNet STATIC ${DNET_SOURCES}) target_link_libraries(dNet dCommon dDatabase) + +# If using gcc, warn on old-style C casts +if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU") + set_source_files_properties(${DNET_SOURCES} PROPERTIES COMPILE_FLAGS "-Wold-style-cast") +endif() diff --git a/dNet/WorldPackets.cpp b/dNet/WorldPackets.cpp index 2da11d593..1ee98c837 100644 --- a/dNet/WorldPackets.cpp +++ b/dNet/WorldPackets.cpp @@ -226,9 +226,9 @@ void WorldPackets::SendGMLevelChange(const SystemAddress& sysAddr, bool success, BitStreamUtils::WriteHeader(bitStream, eConnectionType::CLIENT, eClientMessageType::MAKE_GM_RESPONSE); bitStream.Write(success); - bitStream.Write(highestLevel); - bitStream.Write(prevLevel); - bitStream.Write(newLevel); + bitStream.Write(static_cast(highestLevel)); + bitStream.Write(static_cast(prevLevel)); + bitStream.Write(static_cast(newLevel)); SEND_PACKET; } diff --git a/dPhysics/CMakeLists.txt b/dPhysics/CMakeLists.txt index 5fe6adaae..0db387821 100644 --- a/dPhysics/CMakeLists.txt +++ b/dPhysics/CMakeLists.txt @@ -8,3 +8,8 @@ set(DPHYSICS_SOURCES "dpCollisionChecks.cpp" add_library(dPhysics STATIC ${DPHYSICS_SOURCES}) target_link_libraries(dPhysics Recast Detour) + +# If using gcc, warn on old-style C casts +if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU") + set_source_files_properties(${DPHYSICS_SOURCES} PROPERTIES COMPILE_FLAGS "-Wold-style-cast") +endif() diff --git a/dScripts/02_server/Map/AG/NpcAgCourseStarter.cpp b/dScripts/02_server/Map/AG/NpcAgCourseStarter.cpp index b47260f98..515603a0f 100644 --- a/dScripts/02_server/Map/AG/NpcAgCourseStarter.cpp +++ b/dScripts/02_server/Map/AG/NpcAgCourseStarter.cpp @@ -52,7 +52,7 @@ void NpcAgCourseStarter::OnMessageBoxResponse(Entity* self, Entity* sender, int3 time_t startTime = std::time(0) + 4; // Offset for starting timer - data->values[1] = *(float*)&startTime; + data->values[1] = *reinterpret_cast(&startTime); Game::entityManager->SerializeEntity(self); } else if (identifier == u"FootRaceCancel") { @@ -81,9 +81,9 @@ void NpcAgCourseStarter::OnFireEventServerSide(Entity* self, Entity* sender, std scriptedActivityComponent->RemoveActivityPlayerData(sender->GetObjectID()); } else if (args == "course_finish") { time_t endTime = std::time(0); - time_t finish = (endTime - *(time_t*)&data->values[1]); + time_t finish = (endTime - *reinterpret_cast(&data->values[1])); - data->values[2] = *(float*)&finish; + data->values[2] = *reinterpret_cast(&finish); auto* missionComponent = sender->GetComponent(); if (missionComponent != nullptr) { diff --git a/dScripts/02_server/Map/AM/AmDrawBridge.cpp b/dScripts/02_server/Map/AM/AmDrawBridge.cpp index e6b807645..11d52cd7d 100644 --- a/dScripts/02_server/Map/AM/AmDrawBridge.cpp +++ b/dScripts/02_server/Map/AM/AmDrawBridge.cpp @@ -99,7 +99,7 @@ void AmDrawBridge::MoveBridgeDown(Entity* self, Entity* bridge, bool down) { const auto travelTime = 2.0f; - forwardVect = forwardVect * (float)((degrees / travelTime) * (3.14f / 180.0f)); + forwardVect = forwardVect * static_cast((degrees / travelTime) * (3.14f / 180.0f)); simplePhysicsComponent->SetAngularVelocity(forwardVect); diff --git a/dScripts/02_server/Map/NS/NsLegoClubDoor.cpp b/dScripts/02_server/Map/NS/NsLegoClubDoor.cpp index 196386274..959466e93 100644 --- a/dScripts/02_server/Map/NS/NsLegoClubDoor.cpp +++ b/dScripts/02_server/Map/NS/NsLegoClubDoor.cpp @@ -4,7 +4,7 @@ #include "Amf3.h" void NsLegoClubDoor::OnStartup(Entity* self) { - self->SetVar(u"currentZone", static_castGame::zoneManager->GetZoneID().GetMapID()); + self->SetVar(u"currentZone", static_cast(Game::zoneManager->GetZoneID().GetMapID())); self->SetVar(u"choiceZone", m_ChoiceZoneID); self->SetVar(u"teleportAnim", m_TeleportAnim); self->SetVar(u"teleportString", m_TeleportString); diff --git a/dScripts/02_server/Map/njhub/boss_instance/NjMonastryBossInstance.cpp b/dScripts/02_server/Map/njhub/boss_instance/NjMonastryBossInstance.cpp index 4a182d3d0..ccb12e304 100644 --- a/dScripts/02_server/Map/njhub/boss_instance/NjMonastryBossInstance.cpp +++ b/dScripts/02_server/Map/njhub/boss_instance/NjMonastryBossInstance.cpp @@ -117,7 +117,7 @@ void NjMonastryBossInstance::OnPlayerExit(Entity* self, Entity* player) { void NjMonastryBossInstance::OnActivityTimerDone(Entity* self, const std::string& name) { auto split = GeneralUtils::SplitString(name, TimerSplitChar); auto timerName = split[0]; - auto objectID = split.size() > 1 ? (LWOOBJID)std::stoull(split[1]) : LWOOBJID_EMPTY; + auto objectID = split.size() > 1 ? static_cast(std::stoull(split[1])) : LWOOBJID_EMPTY; if (timerName == WaitingForPlayersTimer) { StartFight(self); diff --git a/dScripts/BaseSurvivalServer.cpp b/dScripts/BaseSurvivalServer.cpp index 761ca509f..93476d781 100644 --- a/dScripts/BaseSurvivalServer.cpp +++ b/dScripts/BaseSurvivalServer.cpp @@ -370,7 +370,7 @@ void BaseSurvivalServer::GameOver(Entity* self) { for (const auto& survivalMission : missionsToUpdate) { auto* mission = missionComponent->GetMission(survivalMission.first); - if (mission != nullptr && (uint32_t)time >= survivalMission.second + if (mission != nullptr && static_cast(time) >= survivalMission.second && (mission->GetMissionState() == eMissionState::ACTIVE || mission->GetMissionState() == eMissionState::COMPLETE_ACTIVE)) { diff --git a/dScripts/BaseWavesServer.cpp b/dScripts/BaseWavesServer.cpp index 7482c920e..9be198065 100644 --- a/dScripts/BaseWavesServer.cpp +++ b/dScripts/BaseWavesServer.cpp @@ -436,7 +436,7 @@ void BaseWavesServer::SpawnWave(Entity* self) { } } } else { - if (wave.timeLimit != (uint32_t)-1) { + if (wave.timeLimit != static_cast(-1)) { ActivityTimerStart(self, TimedWaveTimer, 1.0f, wave.timeLimit); self->SetNetworkVar(StartTimedWaveVariable, { wave.timeLimit, state.waveNumber + 1 }); } else { diff --git a/dScripts/CMakeLists.txt b/dScripts/CMakeLists.txt index ac600dbc2..a1d5ed44e 100644 --- a/dScripts/CMakeLists.txt +++ b/dScripts/CMakeLists.txt @@ -52,3 +52,8 @@ foreach(file ${DSCRIPTS_SOURCES_ZONE}) endforeach() set(DSCRIPTS_SOURCES ${DSCRIPTS_SOURCES} PARENT_SCOPE) + +# If using gcc, warn on old-style C casts +if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU") + set_source_files_properties(${DSCRIPTS_SOURCES} PROPERTIES COMPILE_FLAGS "-Wold-style-cast") +endif() diff --git a/dScripts/ai/MINIGAME/SG_GF/SERVER/SGCannon.cpp b/dScripts/ai/MINIGAME/SG_GF/SERVER/SGCannon.cpp index 26047d8e1..16262f2f6 100644 --- a/dScripts/ai/MINIGAME/SG_GF/SERVER/SGCannon.cpp +++ b/dScripts/ai/MINIGAME/SG_GF/SERVER/SGCannon.cpp @@ -634,7 +634,7 @@ void SGCannon::RegisterHit(Entity* self, Entity* target, const std::string& time ActivityTimerStart(self, timerName, respawnTime, respawnTime); } - int score = spawnInfo.score; + uint32_t score = spawnInfo.score; if (score > 0) { score += score * GetCurrentBonus(self); @@ -673,7 +673,7 @@ void SGCannon::RegisterHit(Entity* self, Entity* target, const std::string& time target->GetPosition() ); - auto newScore = (int)self->GetVar(TotalScoreVariable) + score; + uint32_t newScore = self->GetVar(TotalScoreVariable) + score; if (newScore < 0) { newScore = 0; diff --git a/dScripts/ai/RACING/OBJECTS/FvRaceSmashEggImagineServer.cpp b/dScripts/ai/RACING/OBJECTS/FvRaceSmashEggImagineServer.cpp index 2bdb03641..cdd0f89bd 100644 --- a/dScripts/ai/RACING/OBJECTS/FvRaceSmashEggImagineServer.cpp +++ b/dScripts/ai/RACING/OBJECTS/FvRaceSmashEggImagineServer.cpp @@ -30,8 +30,8 @@ void FvRaceSmashEggImagineServer::OnDie(Entity* self, Entity* killer) { } if (missionComponent == nullptr) return; // Dragon eggs have their own smash server so we handle mission progression for them here. - missionComponent->Progress(eMissionTaskType::RACING, 0, (LWOOBJID)eRacingTaskParam::SMASHABLES); - missionComponent->Progress(eMissionTaskType::RACING, self->GetLOT(), (LWOOBJID)eRacingTaskParam::SMASH_SPECIFIC_SMASHABLE); + missionComponent->Progress(eMissionTaskType::RACING, 0, static_cast(eRacingTaskParam::SMASHABLES)); + missionComponent->Progress(eMissionTaskType::RACING, self->GetLOT(), static_cast(eRacingTaskParam::SMASH_SPECIFIC_SMASHABLE)); } } diff --git a/dScripts/ai/RACING/OBJECTS/RaceImagineCrateServer.cpp b/dScripts/ai/RACING/OBJECTS/RaceImagineCrateServer.cpp index 20a3c0cce..8aff03652 100644 --- a/dScripts/ai/RACING/OBJECTS/RaceImagineCrateServer.cpp +++ b/dScripts/ai/RACING/OBJECTS/RaceImagineCrateServer.cpp @@ -50,7 +50,7 @@ void RaceImagineCrateServer::OnDie(Entity* self, Entity* killer) { // Progress racing smashable missions if (missionComponent == nullptr) return; - missionComponent->Progress(eMissionTaskType::RACING, 0, (LWOOBJID)eRacingTaskParam::SMASHABLES); + missionComponent->Progress(eMissionTaskType::RACING, 0, static_cast(eRacingTaskParam::SMASHABLES)); } } } diff --git a/dScripts/ai/RACING/OBJECTS/RaceImaginePowerup.cpp b/dScripts/ai/RACING/OBJECTS/RaceImaginePowerup.cpp index d55eeffd1..17e263fb5 100644 --- a/dScripts/ai/RACING/OBJECTS/RaceImaginePowerup.cpp +++ b/dScripts/ai/RACING/OBJECTS/RaceImaginePowerup.cpp @@ -32,6 +32,6 @@ void RaceImaginePowerup::OnFireEventServerSide(Entity* self, Entity* sender, std auto* missionComponent = sender->GetComponent(); if (missionComponent == nullptr) return; - missionComponent->Progress(eMissionTaskType::RACING, self->GetLOT(), (LWOOBJID)eRacingTaskParam::COLLECT_IMAGINATION); + missionComponent->Progress(eMissionTaskType::RACING, self->GetLOT(), static_cast(eRacingTaskParam::COLLECT_IMAGINATION)); } } diff --git a/dScripts/ai/RACING/OBJECTS/RaceSmashServer.cpp b/dScripts/ai/RACING/OBJECTS/RaceSmashServer.cpp index 5fcb2ff46..340ab98e3 100644 --- a/dScripts/ai/RACING/OBJECTS/RaceSmashServer.cpp +++ b/dScripts/ai/RACING/OBJECTS/RaceSmashServer.cpp @@ -23,9 +23,9 @@ void RaceSmashServer::OnDie(Entity* self, Entity* killer) { // Progress racing smashable missions if (missionComponent == nullptr) return; - missionComponent->Progress(eMissionTaskType::RACING, 0, (LWOOBJID)eRacingTaskParam::SMASHABLES); + missionComponent->Progress(eMissionTaskType::RACING, 0, static_cast(eRacingTaskParam::SMASHABLES)); // Progress missions that ask us to smash a specific smashable. - missionComponent->Progress(eMissionTaskType::RACING, self->GetLOT(), (LWOOBJID)eRacingTaskParam::SMASH_SPECIFIC_SMASHABLE); + missionComponent->Progress(eMissionTaskType::RACING, self->GetLOT(), static_cast(eRacingTaskParam::SMASH_SPECIFIC_SMASHABLE)); } } } diff --git a/dWorldServer/CMakeLists.txt b/dWorldServer/CMakeLists.txt index c616da878..f227fbd4a 100644 --- a/dWorldServer/CMakeLists.txt +++ b/dWorldServer/CMakeLists.txt @@ -9,3 +9,7 @@ add_executable(WorldServer "WorldServer.cpp") target_link_libraries(dWorldServer ${COMMON_LIBRARIES}) target_link_libraries(WorldServer ${COMMON_LIBRARIES} dChatFilter dGame dZoneManager dPhysics Detour Recast tinyxml2 dWorldServer dNavigation) +# If using gcc, warn on old-style C casts +if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU") + set_source_files_properties(${DWORLDSERVER_SOURCES} PROPERTIES COMPILE_FLAGS "-Wold-style-cast") +endif() diff --git a/dZoneManager/CMakeLists.txt b/dZoneManager/CMakeLists.txt index bbb22ba7d..cbddc4f3e 100644 --- a/dZoneManager/CMakeLists.txt +++ b/dZoneManager/CMakeLists.txt @@ -5,3 +5,8 @@ set(DZONEMANAGER_SOURCES "dZoneManager.cpp" add_library(dZoneManager STATIC ${DZONEMANAGER_SOURCES}) target_link_libraries(dZoneManager dPhysics) + +# If using gcc, warn on old-style C casts +if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU") + set_source_files_properties(${DZONEMANAGER_SOURCES} PROPERTIES COMPILE_FLAGS "-Wold-style-cast") +endif() From dbb16f5ffade7fb3e2627491e09c77308a39b848 Mon Sep 17 00:00:00 2001 From: jadebenn Date: Tue, 26 Dec 2023 16:28:59 -0600 Subject: [PATCH 03/12] bug fixes and improvements --- dCommon/Diagnostics.cpp | 11 ----------- dCommon/MD5.cpp | 6 +++--- dCommon/NiPoint3.cpp | 2 +- .../CDClientTables/CDMissionEmailTable.cpp | 2 +- dZoneManager/Zone.cpp | 6 +++--- dZoneManager/Zone.h | 4 ++-- 6 files changed, 10 insertions(+), 21 deletions(-) diff --git a/dCommon/Diagnostics.cpp b/dCommon/Diagnostics.cpp index 0fb84e6fd..6edc0b9a7 100644 --- a/dCommon/Diagnostics.cpp +++ b/dCommon/Diagnostics.cpp @@ -197,17 +197,6 @@ void MakeBacktrace() { sigact.sa_sigaction = CritErrHdlr; sigact.sa_flags = SA_RESTART | SA_SIGINFO; - if (sigaction(SIGSEGV, &sigact, static_cast(nullptr)) != 0 || - sigaction(SIGFPE, &sigact, static_cast(nullptr)) != 0 || - sigaction(SIGABRT, &sigact, static_cast(nullptr)) != 0 || - sigaction(SIGILL, &sigact, static_cast(nullptr)) != 0) { - fprintf(stderr, "error setting signal handler for %d (%s)\n", - SIGSEGV, - strsignal(SIGSEGV)); - - exit(EXIT_FAILURE); - } - std::set_terminate(OnTerminate); } #endif diff --git a/dCommon/MD5.cpp b/dCommon/MD5.cpp index 264d10082..d02b540d8 100644 --- a/dCommon/MD5.cpp +++ b/dCommon/MD5.cpp @@ -133,8 +133,8 @@ void MD5::init() { // decodes input (unsigned char) into output (uint4). Assumes len is a multiple of 4. void MD5::decode(uint4 output[], const uint1 input[], size_type len) { for (unsigned int i = 0, j = 0; j < len; i++, j += 4) - output[i] = static_cast(input[j]) | (static_cast(input[j + 1]) << 8) | - (static_cast(input[j + 2]) << 16) | (static_cast(input[j + 3]) << 24); + output[i] = ((uint4)input[j]) | (((uint4)input[j + 1]) << 8) | + (((uint4)input[j + 2]) << 16) | (((uint4)input[j + 3]) << 24); } ////////////////////////////// @@ -278,7 +278,7 @@ void MD5::update(const unsigned char input[], size_type length) { // for convenience provide a verson with signed char void MD5::update(const char input[], size_type length) { - update(reinterpret_cast(input), length); + update((const unsigned char*)input, length); } ////////////////////////////// diff --git a/dCommon/NiPoint3.cpp b/dCommon/NiPoint3.cpp index d8abb739f..db25d5286 100644 --- a/dCommon/NiPoint3.cpp +++ b/dCommon/NiPoint3.cpp @@ -246,7 +246,7 @@ NiPoint3 NiPoint3::MoveTowards(const NiPoint3& current, const NiPoint3& target, return target; } - float length = static_cast(std::sqrt(static_cast(lengthSquared))); + float length = std::sqrtf(lengthSquared); return NiPoint3(current.x + dx / length * maxDistanceDelta, current.y + dy / length * maxDistanceDelta, current.z + dz / length * maxDistanceDelta); } diff --git a/dDatabase/CDClientDatabase/CDClientTables/CDMissionEmailTable.cpp b/dDatabase/CDClientDatabase/CDClientTables/CDMissionEmailTable.cpp index 330acc18a..302dc0bc2 100644 --- a/dDatabase/CDClientDatabase/CDClientTables/CDMissionEmailTable.cpp +++ b/dDatabase/CDClientDatabase/CDClientTables/CDMissionEmailTable.cpp @@ -25,7 +25,7 @@ void CDMissionEmailTable::LoadValuesFromDatabase() { entry.notificationGroup = tableData.getIntField("notificationGroup", -1); entry.missionID = tableData.getIntField("missionID", -1); entry.attachmentLOT = tableData.getIntField("attachmentLOT", 0); - entry.localize = static_cast(tableData.getIntField("localize", -1)); + entry.localize = tableData.getBoolField("localize", -1); entry.locStatus = tableData.getIntField("locStatus", -1); entry.gate_version = tableData.getStringField("gate_version", ""); diff --git a/dZoneManager/Zone.cpp b/dZoneManager/Zone.cpp index 942c9c135..cbaccdedf 100644 --- a/dZoneManager/Zone.cpp +++ b/dZoneManager/Zone.cpp @@ -59,7 +59,7 @@ void Zone::LoadZoneIntoMemory() { if (m_FileFormatVersion >= Zone::FileFormatVersion::Alpha) BinaryIO::BinaryRead(file, mapRevision); BinaryIO::BinaryRead(file, m_WorldID); - if (m_WorldID != m_ZoneID.GetMapID()) LOG("WorldID: %i doesn't match MapID %i! Is this intended?", m_WorldID, m_ZoneID.GetMapID()); + if (static_cast(m_WorldID) != m_ZoneID.GetMapID()) LOG("WorldID: %i doesn't match MapID %i! Is this intended?", m_WorldID, m_ZoneID.GetMapID()); AddRevision(LWOSCENEID_INVALID, mapRevision); @@ -147,7 +147,7 @@ void Zone::LoadZoneIntoMemory() { } else { LOG("Failed to open: %s", m_ZoneFilePath.c_str()); } - + m_ZonePath = m_ZoneFilePath.substr(0, m_ZoneFilePath.rfind('/') + 1); } @@ -243,7 +243,7 @@ void Zone::LoadScene(std::istream& file) { void Zone::LoadLUTriggers(std::string triggerFile, SceneRef& scene) { auto file = Game::assetManager->GetFile((m_ZonePath + triggerFile).c_str()); - + std::stringstream data; data << file.rdbuf(); diff --git a/dZoneManager/Zone.h b/dZoneManager/Zone.h index 916f0b86b..a62a81edc 100644 --- a/dZoneManager/Zone.h +++ b/dZoneManager/Zone.h @@ -213,7 +213,7 @@ class Zone { LUTriggers::Trigger* GetTrigger(uint32_t sceneID, uint32_t triggerID); const Path* GetPath(std::string name) const; - LWOMAPID GetWorldID() const { return m_WorldID; } + uint32_t GetWorldID() const { return m_WorldID; } [[nodiscard]] std::string GetZoneName() const { return m_ZoneName; } std::string GetZoneRawPath() const { return m_ZoneRawPath; } std::string GetZonePath() const { return m_ZonePath; } @@ -231,7 +231,7 @@ class Zone { uint32_t m_NumberOfSceneTransitionsLoaded; FileFormatVersion m_FileFormatVersion; uint32_t m_CheckSum; - LWOMAPID m_WorldID; //should be equal to the MapID + uint32_t m_WorldID; //should be equal to the MapID NiPoint3 m_Spawnpoint; NiQuaternion m_SpawnpointRotation; uint32_t m_SceneCount; From 9c22b4cb81315db3f19b9b783dace3054042f8dc Mon Sep 17 00:00:00 2001 From: jadebenn Date: Tue, 26 Dec 2023 16:33:52 -0600 Subject: [PATCH 04/12] no getBoolField method exists --- .../CDClientDatabase/CDClientTables/CDMissionEmailTable.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/dDatabase/CDClientDatabase/CDClientTables/CDMissionEmailTable.cpp b/dDatabase/CDClientDatabase/CDClientTables/CDMissionEmailTable.cpp index 302dc0bc2..207d3815d 100644 --- a/dDatabase/CDClientDatabase/CDClientTables/CDMissionEmailTable.cpp +++ b/dDatabase/CDClientDatabase/CDClientTables/CDMissionEmailTable.cpp @@ -25,7 +25,7 @@ void CDMissionEmailTable::LoadValuesFromDatabase() { entry.notificationGroup = tableData.getIntField("notificationGroup", -1); entry.missionID = tableData.getIntField("missionID", -1); entry.attachmentLOT = tableData.getIntField("attachmentLOT", 0); - entry.localize = tableData.getBoolField("localize", -1); + entry.localize = (bool)tableData.getIntField("localize", -1); entry.locStatus = tableData.getIntField("locStatus", -1); entry.gate_version = tableData.getStringField("gate_version", ""); @@ -50,3 +50,4 @@ std::vector CDMissionEmailTable::Query(std::function& CDMissionEmailTable::GetEntries() const { return this->entries; } + From d0954e7c43b4d13e7db44a5d7a62e0752429c4eb Mon Sep 17 00:00:00 2001 From: jadebenn Date: Tue, 26 Dec 2023 16:42:50 -0600 Subject: [PATCH 05/12] fixes --- dCommon/NiPoint3.cpp | 2 +- .../CDClientDatabase/CDClientTables/CDMissionEmailTable.cpp | 3 +-- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/dCommon/NiPoint3.cpp b/dCommon/NiPoint3.cpp index db25d5286..f743dcf91 100644 --- a/dCommon/NiPoint3.cpp +++ b/dCommon/NiPoint3.cpp @@ -246,7 +246,7 @@ NiPoint3 NiPoint3::MoveTowards(const NiPoint3& current, const NiPoint3& target, return target; } - float length = std::sqrtf(lengthSquared); + float length = std::sqrt(lengthSquared); return NiPoint3(current.x + dx / length * maxDistanceDelta, current.y + dy / length * maxDistanceDelta, current.z + dz / length * maxDistanceDelta); } diff --git a/dDatabase/CDClientDatabase/CDClientTables/CDMissionEmailTable.cpp b/dDatabase/CDClientDatabase/CDClientTables/CDMissionEmailTable.cpp index 207d3815d..330acc18a 100644 --- a/dDatabase/CDClientDatabase/CDClientTables/CDMissionEmailTable.cpp +++ b/dDatabase/CDClientDatabase/CDClientTables/CDMissionEmailTable.cpp @@ -25,7 +25,7 @@ void CDMissionEmailTable::LoadValuesFromDatabase() { entry.notificationGroup = tableData.getIntField("notificationGroup", -1); entry.missionID = tableData.getIntField("missionID", -1); entry.attachmentLOT = tableData.getIntField("attachmentLOT", 0); - entry.localize = (bool)tableData.getIntField("localize", -1); + entry.localize = static_cast(tableData.getIntField("localize", -1)); entry.locStatus = tableData.getIntField("locStatus", -1); entry.gate_version = tableData.getStringField("gate_version", ""); @@ -50,4 +50,3 @@ std::vector CDMissionEmailTable::Query(std::function& CDMissionEmailTable::GetEntries() const { return this->entries; } - From b0e898d6f78de97876a91a2a38b5047e77343004 Mon Sep 17 00:00:00 2001 From: jadebenn Date: Tue, 26 Dec 2023 16:52:20 -0600 Subject: [PATCH 06/12] unbroke sg cannon scoring --- dScripts/ai/MINIGAME/SG_GF/SERVER/SGCannon.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/dScripts/ai/MINIGAME/SG_GF/SERVER/SGCannon.cpp b/dScripts/ai/MINIGAME/SG_GF/SERVER/SGCannon.cpp index 16262f2f6..de3f45db3 100644 --- a/dScripts/ai/MINIGAME/SG_GF/SERVER/SGCannon.cpp +++ b/dScripts/ai/MINIGAME/SG_GF/SERVER/SGCannon.cpp @@ -634,7 +634,7 @@ void SGCannon::RegisterHit(Entity* self, Entity* target, const std::string& time ActivityTimerStart(self, timerName, respawnTime, respawnTime); } - uint32_t score = spawnInfo.score; + int32_t score = spawnInfo.score; if (score > 0) { score += score * GetCurrentBonus(self); @@ -673,7 +673,7 @@ void SGCannon::RegisterHit(Entity* self, Entity* target, const std::string& time target->GetPosition() ); - uint32_t newScore = self->GetVar(TotalScoreVariable) + score; + auto newScore = self->GetVar(TotalScoreVariable) + score; if (newScore < 0) { newScore = 0; From f1621aa8ef1d6f9435fa12709a5107562acd3928 Mon Sep 17 00:00:00 2001 From: jadebenn Date: Tue, 26 Dec 2023 17:08:23 -0600 Subject: [PATCH 07/12] removing comments --- dGame/dComponents/PropertyEntranceComponent.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/dGame/dComponents/PropertyEntranceComponent.cpp b/dGame/dComponents/PropertyEntranceComponent.cpp index 9af714930..c49d89859 100644 --- a/dGame/dComponents/PropertyEntranceComponent.cpp +++ b/dGame/dComponents/PropertyEntranceComponent.cpp @@ -163,7 +163,7 @@ void PropertyEntranceComponent::OnPropertyEntranceSync(Entity* entity, bool incl const auto modApproved = playerPropertyLookupResults->getBoolean(10); const auto dateLastUpdated = playerPropertyLookupResults->getInt64(11); const auto reputation = playerPropertyLookupResults->getUInt(14); - const auto performanceCost = playerPropertyLookupResults->getFloat(16); //CHECK THIS + const auto performanceCost = playerPropertyLookupResults->getFloat(16); playerEntry = SetPropertyValues(playerEntry, cloneId, character->GetName(), propertyName, propertyDescription, reputation, true, true, modApproved, true, true, privacyOption, dateLastUpdated, performanceCost); } else { @@ -203,7 +203,7 @@ void PropertyEntranceComponent::OnPropertyEntranceSync(Entity* entity, bool incl const auto modApproved = propertyEntry->getBoolean(10); const auto dateLastUpdated = propertyEntry->getInt(11); const float reputation = propertyEntry->getInt(14); - const auto performanceCost = propertyEntry->getFloat(16); // CHECK THIS + const auto performanceCost = propertyEntry->getFloat(16); PropertySelectQueryProperty entry{}; From c82a4ccf9174174f050600c557a5b7809a8be871 Mon Sep 17 00:00:00 2001 From: jadebenn Date: Tue, 26 Dec 2023 17:29:02 -0600 Subject: [PATCH 08/12] Remove the c-style cast warning I added from CMakeLists now that they're gone (it triggers on 3rd party dependencies and slows down compilation) --- dCommon/CMakeLists.txt | 6 ------ dDatabase/CMakeLists.txt | 5 ----- dGame/CMakeLists.txt | 5 ----- dMasterServer/CMakeLists.txt | 5 ----- dNavigation/CMakeLists.txt | 5 ----- dNet/CMakeLists.txt | 5 ----- dPhysics/CMakeLists.txt | 5 ----- dScripts/CMakeLists.txt | 5 ----- dWorldServer/CMakeLists.txt | 4 ---- dZoneManager/CMakeLists.txt | 5 ----- 10 files changed, 50 deletions(-) diff --git a/dCommon/CMakeLists.txt b/dCommon/CMakeLists.txt index 13ffc6c97..1354c051b 100644 --- a/dCommon/CMakeLists.txt +++ b/dCommon/CMakeLists.txt @@ -31,12 +31,6 @@ add_library(dCommon STATIC ${DCOMMON_SOURCES}) target_link_libraries(dCommon bcrypt dDatabase tinyxml2) -# If using gcc, warn on old-style C casts -if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU") - set_source_files_properties(${DCOMMON_SOURCES} PROPERTIES COMPILE_FLAGS "-Wold-style-cast") -endif() - -# Handle zlib dependency if (UNIX) find_package(ZLIB REQUIRED) elseif (WIN32) diff --git a/dDatabase/CMakeLists.txt b/dDatabase/CMakeLists.txt index 8bdcea341..20f37becf 100644 --- a/dDatabase/CMakeLists.txt +++ b/dDatabase/CMakeLists.txt @@ -14,8 +14,3 @@ endforeach() add_library(dDatabase STATIC ${DDATABASE_SOURCES}) target_link_libraries(dDatabase sqlite3 mariadbConnCpp) - -# If using gcc, warn on old-style C casts -if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU") - set_source_files_properties(${DDATABASE_SOURCES} PROPERTIES COMPILE_FLAGS "-Wold-style-cast") -endif() diff --git a/dGame/CMakeLists.txt b/dGame/CMakeLists.txt index 59588b4ab..80f160426 100644 --- a/dGame/CMakeLists.txt +++ b/dGame/CMakeLists.txt @@ -63,8 +63,3 @@ endforeach() add_library(dGame STATIC ${DGAME_SOURCES}) target_link_libraries(dGame dDatabase Recast Detour) - -# If using gcc, warn on old-style C casts -if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU") - set_source_files_properties(${DGAME_SOURCES} PROPERTIES COMPILE_FLAGS "-Wold-style-cast") -endif() diff --git a/dMasterServer/CMakeLists.txt b/dMasterServer/CMakeLists.txt index ddba5c49a..2161681f8 100644 --- a/dMasterServer/CMakeLists.txt +++ b/dMasterServer/CMakeLists.txt @@ -12,8 +12,3 @@ target_link_libraries(MasterServer ${COMMON_LIBRARIES} dMasterServer) if(WIN32) add_dependencies(MasterServer WorldServer AuthServer ChatServer) endif() - -# If using gcc, warn on old-style C casts -if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU") - set_source_files_properties(${DMASTERSERVER_SOURCES} PROPERTIES COMPILE_FLAGS "-Wold-style-cast") -endif() diff --git a/dNavigation/CMakeLists.txt b/dNavigation/CMakeLists.txt index f94ae4932..4c03d24b2 100644 --- a/dNavigation/CMakeLists.txt +++ b/dNavigation/CMakeLists.txt @@ -8,8 +8,3 @@ endforeach() add_library(dNavigation STATIC ${DNAVIGATION_SOURCES}) target_link_libraries(dNavigation Detour Recast) - -# If using gcc, warn on old-style C casts -if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU") - set_source_files_properties(${DNAVIGATION_SOURCES} PROPERTIES COMPILE_FLAGS "-Wold-style-cast") -endif() diff --git a/dNet/CMakeLists.txt b/dNet/CMakeLists.txt index 6fb830361..938c04493 100644 --- a/dNet/CMakeLists.txt +++ b/dNet/CMakeLists.txt @@ -9,8 +9,3 @@ set(DNET_SOURCES "AuthPackets.cpp" add_library(dNet STATIC ${DNET_SOURCES}) target_link_libraries(dNet dCommon dDatabase) - -# If using gcc, warn on old-style C casts -if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU") - set_source_files_properties(${DNET_SOURCES} PROPERTIES COMPILE_FLAGS "-Wold-style-cast") -endif() diff --git a/dPhysics/CMakeLists.txt b/dPhysics/CMakeLists.txt index 0db387821..5fe6adaae 100644 --- a/dPhysics/CMakeLists.txt +++ b/dPhysics/CMakeLists.txt @@ -8,8 +8,3 @@ set(DPHYSICS_SOURCES "dpCollisionChecks.cpp" add_library(dPhysics STATIC ${DPHYSICS_SOURCES}) target_link_libraries(dPhysics Recast Detour) - -# If using gcc, warn on old-style C casts -if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU") - set_source_files_properties(${DPHYSICS_SOURCES} PROPERTIES COMPILE_FLAGS "-Wold-style-cast") -endif() diff --git a/dScripts/CMakeLists.txt b/dScripts/CMakeLists.txt index a1d5ed44e..ac600dbc2 100644 --- a/dScripts/CMakeLists.txt +++ b/dScripts/CMakeLists.txt @@ -52,8 +52,3 @@ foreach(file ${DSCRIPTS_SOURCES_ZONE}) endforeach() set(DSCRIPTS_SOURCES ${DSCRIPTS_SOURCES} PARENT_SCOPE) - -# If using gcc, warn on old-style C casts -if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU") - set_source_files_properties(${DSCRIPTS_SOURCES} PROPERTIES COMPILE_FLAGS "-Wold-style-cast") -endif() diff --git a/dWorldServer/CMakeLists.txt b/dWorldServer/CMakeLists.txt index f227fbd4a..c616da878 100644 --- a/dWorldServer/CMakeLists.txt +++ b/dWorldServer/CMakeLists.txt @@ -9,7 +9,3 @@ add_executable(WorldServer "WorldServer.cpp") target_link_libraries(dWorldServer ${COMMON_LIBRARIES}) target_link_libraries(WorldServer ${COMMON_LIBRARIES} dChatFilter dGame dZoneManager dPhysics Detour Recast tinyxml2 dWorldServer dNavigation) -# If using gcc, warn on old-style C casts -if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU") - set_source_files_properties(${DWORLDSERVER_SOURCES} PROPERTIES COMPILE_FLAGS "-Wold-style-cast") -endif() diff --git a/dZoneManager/CMakeLists.txt b/dZoneManager/CMakeLists.txt index cbddc4f3e..bbb22ba7d 100644 --- a/dZoneManager/CMakeLists.txt +++ b/dZoneManager/CMakeLists.txt @@ -5,8 +5,3 @@ set(DZONEMANAGER_SOURCES "dZoneManager.cpp" add_library(dZoneManager STATIC ${DZONEMANAGER_SOURCES}) target_link_libraries(dZoneManager dPhysics) - -# If using gcc, warn on old-style C casts -if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU") - set_source_files_properties(${DZONEMANAGER_SOURCES} PROPERTIES COMPILE_FLAGS "-Wold-style-cast") -endif() From f2d075555b31aeeabb5f6a148445cc0735d4712e Mon Sep 17 00:00:00 2001 From: jadebenn Date: Tue, 26 Dec 2023 20:00:31 -0600 Subject: [PATCH 09/12] (Hopefully) fix MacOS compilation error --- dCommon/Metrics.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/dCommon/Metrics.cpp b/dCommon/Metrics.cpp index 4d58b83ce..5232cf786 100644 --- a/dCommon/Metrics.cpp +++ b/dCommon/Metrics.cpp @@ -240,8 +240,8 @@ size_t Metrics::GetCurrentRSS() { /* OSX ------------------------------------------------------ */ struct mach_task_basic_info info; mach_msg_type_number_t infoCount = MACH_TASK_BASIC_INFO_COUNT; - if (static_cast(mach_task_self(), MACH_TASK_BASIC_INFO, - static_cast(&info), &infoCount) != KERN_SUCCESS) + if (task_info(mach_task_self(), MACH_TASK_BASIC_INFO, + reinterpret_cast(&info), &infoCount) != KERN_SUCCESS) return static_cast(0L); /* Can't access? */ return static_cast(info.resident_size); From e070785a445b2794797a44eb02588865bce766ba Mon Sep 17 00:00:00 2001 From: jadebenn Date: Wed, 27 Dec 2023 15:30:05 -0600 Subject: [PATCH 10/12] partially-implemented feedback --- dCommon/NiPoint3.cpp | 4 ++-- dGame/dGameMessages/GameMessages.cpp | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/dCommon/NiPoint3.cpp b/dCommon/NiPoint3.cpp index f743dcf91..3394deb7d 100644 --- a/dCommon/NiPoint3.cpp +++ b/dCommon/NiPoint3.cpp @@ -114,13 +114,13 @@ bool NiPoint3::operator!=(const NiPoint3& point) const { //! Operator for subscripting float& NiPoint3::operator[](int i) { float* base = &x; - return const_cast(base[i]); + return base[i]; } //! Operator for subscripting const float& NiPoint3::operator[](int i) const { const float* base = &x; - return const_cast(base[i]); + return base[i]; } //! Operator for addition of vectors diff --git a/dGame/dGameMessages/GameMessages.cpp b/dGame/dGameMessages/GameMessages.cpp index 368237f38..e6c1290be 100644 --- a/dGame/dGameMessages/GameMessages.cpp +++ b/dGame/dGameMessages/GameMessages.cpp @@ -1950,7 +1950,7 @@ void GameMessages::SendBBBSaveResponse(const LWOOBJID& objectId, const LWOOBJID& bitStream.Write(buffer[i]); SEND_PACKET; - PacketUtils::SavePacket("eGameMessageType::BBB_SAVE_RESPONSE.bin", reinterpret_cast(bitStream.GetData()), bitStream.GetNumberOfBytesUsed()); + //PacketUtils::SavePacket("eGameMessageType::BBB_SAVE_RESPONSE.bin", reinterpret_cast(bitStream.GetData()), bitStream.GetNumberOfBytesUsed()); } // Property From 9adbbcb1541a5256f1a3302f8559c09b64a89b2a Mon Sep 17 00:00:00 2001 From: jadebenn Date: Wed, 27 Dec 2023 16:49:13 -0600 Subject: [PATCH 11/12] more updates to account for feedback --- dCommon/Diagnostics.cpp | 11 ++++++++++ dCommon/SHA512.cpp | 6 +++-- .../ai/MINIGAME/SG_GF/SERVER/SGCannon.cpp | 22 +++++++++---------- 3 files changed, 26 insertions(+), 13 deletions(-) diff --git a/dCommon/Diagnostics.cpp b/dCommon/Diagnostics.cpp index 6edc0b9a7..2dd4a8501 100644 --- a/dCommon/Diagnostics.cpp +++ b/dCommon/Diagnostics.cpp @@ -197,6 +197,17 @@ void MakeBacktrace() { sigact.sa_sigaction = CritErrHdlr; sigact.sa_flags = SA_RESTART | SA_SIGINFO; + if (sigaction(SIGSEGV, &sigact, nullptr) != 0 || + sigaction(SIGFPE, &sigact, nullptr) != 0 || + sigaction(SIGABRT, &sigact, nullptr) != 0 || + sigaction(SIGILL, &sigact, nullptr) != 0) { + fprintf(stderr, "error setting signal handler for %d (%s)\n", + SIGSEGV, + strsignal(SIGSEGV)); + + exit(EXIT_FAILURE); + } + std::set_terminate(OnTerminate); } #endif diff --git a/dCommon/SHA512.cpp b/dCommon/SHA512.cpp index ffd768db9..e3c2d9f79 100644 --- a/dCommon/SHA512.cpp +++ b/dCommon/SHA512.cpp @@ -1,3 +1,5 @@ +// Source: http://www.zedwood.com/article/cpp-sha512-function + #include "SHA512.h" #include @@ -51,7 +53,7 @@ void SHA512::transform(const unsigned char* message, unsigned int block_nb) { uint64 t1, t2; const unsigned char* sub_block; int i, j; - for (i = 0; i < static_cast(block_nb); i++) { + for (i = 0; i < (int)block_nb; i++) { sub_block = message + (i << 7); for (j = 0; j < 16; j++) { SHA2_PACK64(&sub_block[j << 3], &w[j]); @@ -140,7 +142,7 @@ std::string sha512(std::string input) { memset(digest, 0, SHA512::DIGEST_SIZE); class SHA512 ctx; ctx.init(); - ctx.update(reinterpret_cast(const_cast(input.c_str())), input.length()); + ctx.update((unsigned char*)input.c_str(), input.length()); ctx.final(digest); char buf[2 * SHA512::DIGEST_SIZE + 1]; diff --git a/dScripts/ai/MINIGAME/SG_GF/SERVER/SGCannon.cpp b/dScripts/ai/MINIGAME/SG_GF/SERVER/SGCannon.cpp index de3f45db3..55c82b958 100644 --- a/dScripts/ai/MINIGAME/SG_GF/SERVER/SGCannon.cpp +++ b/dScripts/ai/MINIGAME/SG_GF/SERVER/SGCannon.cpp @@ -518,7 +518,7 @@ void SGCannon::SpawnObject(Entity* self, const SGEnemy& toSpawn, bool spawnNow) } void SGCannon::RecordPlayerScore(Entity* self) { - const auto totalScore = self->GetVar(TotalScoreVariable); + const auto totalScore = self->GetVar(TotalScoreVariable); const auto currentWave = self->GetVar(ThisWaveVariable); if (currentWave > 0) { @@ -587,17 +587,17 @@ void SGCannon::StopGame(Entity* self, bool cancel) { auto* missionComponent = player->GetComponent(); if (missionComponent != nullptr) { - missionComponent->Progress(eMissionTaskType::PERFORM_ACTIVITY, self->GetVar(TotalScoreVariable), self->GetObjectID(), "performact_score"); + missionComponent->Progress(eMissionTaskType::PERFORM_ACTIVITY, self->GetVar(TotalScoreVariable), self->GetObjectID(), "performact_score"); missionComponent->Progress(eMissionTaskType::PERFORM_ACTIVITY, self->GetVar(MaxStreakVariable), self->GetObjectID(), "performact_streak"); - missionComponent->Progress(eMissionTaskType::ACTIVITY, m_CannonLot, 0, "", self->GetVar(TotalScoreVariable)); + missionComponent->Progress(eMissionTaskType::ACTIVITY, m_CannonLot, 0, "", self->GetVar(TotalScoreVariable)); } - Loot::GiveActivityLoot(player, self, GetGameID(self), self->GetVar(TotalScoreVariable)); + Loot::GiveActivityLoot(player, self, GetGameID(self), self->GetVar(TotalScoreVariable)); SaveScore(self, player->GetObjectID(), - static_cast(self->GetVar(TotalScoreVariable)), static_cast(self->GetVar(MaxStreakVariable)), percentage); + static_cast(self->GetVar(TotalScoreVariable)), static_cast(self->GetVar(MaxStreakVariable)), percentage); - StopActivity(self, player->GetObjectID(), self->GetVar(TotalScoreVariable), self->GetVar(MaxStreakVariable), percentage); + StopActivity(self, player->GetObjectID(), self->GetVar(TotalScoreVariable), self->GetVar(MaxStreakVariable), percentage); self->SetNetworkVar(AudioFinalWaveDoneVariable, true); // Give the player the model rewards they earned @@ -609,7 +609,7 @@ void SGCannon::StopGame(Entity* self, bool cancel) { } self->SetNetworkVar(u"UI_Rewards", - GeneralUtils::to_u16string(self->GetVar(TotalScoreVariable)) + u"_0_0_0_0_0_0" + GeneralUtils::to_u16string(self->GetVar(TotalScoreVariable)) + u"_0_0_0_0_0_0" ); } @@ -652,7 +652,7 @@ void SGCannon::RegisterHit(Entity* self, Entity* target, const std::string& time auto lastSuperTotal = self->GetVar(u"LastSuperTotal"); - auto scScore = self->GetVar(TotalScoreVariable) - lastSuperTotal; + auto scScore = self->GetVar(TotalScoreVariable) - lastSuperTotal; LOG("LastSuperTotal: %i, scScore: %i, constants.chargedPoints: %i", lastSuperTotal, scScore, constants.chargedPoints @@ -661,7 +661,7 @@ void SGCannon::RegisterHit(Entity* self, Entity* target, const std::string& time if (!self->GetVar(SuperChargeActiveVariable) && scScore >= constants.chargedPoints && score >= 0) { StartChargedCannon(self); self->SetNetworkVar(u"SuperChargeBar", 100.0f); - self->SetVar(u"LastSuperTotal", self->GetVar(TotalScoreVariable)); + self->SetVar(u"LastSuperTotal", self->GetVar(TotalScoreVariable)); } UpdateStreak(self); @@ -679,7 +679,7 @@ void SGCannon::RegisterHit(Entity* self, Entity* target, const std::string& time newScore = 0; } - self->SetVar(TotalScoreVariable, newScore); + self->SetVar(TotalScoreVariable, newScore); self->SetNetworkVar(u"updateScore", newScore); @@ -1038,7 +1038,7 @@ void SGCannon::ResetVars(Entity* self) { self->SetVar(LastSuperTotalVariable, 0); self->SetVar(CurrentRewardVariable, LOT_NULL); self->SetVar>(RewardsVariable, {}); - self->SetVar(TotalScoreVariable, 0); + self->SetVar(TotalScoreVariable, 0); self->SetVar(u"m_curStreak", 0); self->SetNetworkVar(u"SuperChargeBar", 0); From a73ec2c76aa2d9e29d127542d1a3bc1d860d4942 Mon Sep 17 00:00:00 2001 From: jadebenn Date: Wed, 27 Dec 2023 19:42:35 -0600 Subject: [PATCH 12/12] change bool default --- .../CDClientDatabase/CDClientTables/CDMissionEmailTable.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dDatabase/CDClientDatabase/CDClientTables/CDMissionEmailTable.cpp b/dDatabase/CDClientDatabase/CDClientTables/CDMissionEmailTable.cpp index 330acc18a..0babef13e 100644 --- a/dDatabase/CDClientDatabase/CDClientTables/CDMissionEmailTable.cpp +++ b/dDatabase/CDClientDatabase/CDClientTables/CDMissionEmailTable.cpp @@ -25,7 +25,7 @@ void CDMissionEmailTable::LoadValuesFromDatabase() { entry.notificationGroup = tableData.getIntField("notificationGroup", -1); entry.missionID = tableData.getIntField("missionID", -1); entry.attachmentLOT = tableData.getIntField("attachmentLOT", 0); - entry.localize = static_cast(tableData.getIntField("localize", -1)); + entry.localize = static_cast(tableData.getIntField("localize", 1)); entry.locStatus = tableData.getIntField("locStatus", -1); entry.gate_version = tableData.getStringField("gate_version", "");