From 27f69d6152c1243255b82480eb3fe66064a519f5 Mon Sep 17 00:00:00 2001 From: jadebenn Date: Sat, 3 Feb 2024 16:42:24 -0600 Subject: [PATCH] Update in response to feedback --- dCommon/GeneralUtils.h | 2 +- dCommon/dEnums/dCommonVars.h | 7 +++++++ dGame/dComponents/TriggerComponent.cpp | 10 +++++----- .../ControlBehaviorMessages/BehaviorMessageBase.cpp | 8 ++++---- .../ControlBehaviorMessages/BehaviorMessageBase.h | 6 +++--- dGame/dUtilities/SlashCommandHandler.cpp | 2 -- dMasterServer/InstanceManager.cpp | 2 +- dNet/AuthPackets.cpp | 12 ++++++------ dScripts/02_server/Map/AM/AmSkullkinTower.cpp | 2 +- dZoneManager/Level.cpp | 12 ++++++------ 10 files changed, 34 insertions(+), 29 deletions(-) diff --git a/dCommon/GeneralUtils.h b/dCommon/GeneralUtils.h index 84f5dcb9..3a129692 100644 --- a/dCommon/GeneralUtils.h +++ b/dCommon/GeneralUtils.h @@ -176,7 +176,7 @@ namespace GeneralUtils { template [[nodiscard]] std::optional TryParse(const char* const str, const char* const strEnd = NULL) noexcept try { - return std::make_optional(std::stold(str)); + return std::stold(str); } catch (...) { return std::nullopt; } diff --git a/dCommon/dEnums/dCommonVars.h b/dCommon/dEnums/dCommonVars.h index f4f8fdfb..410deae9 100644 --- a/dCommon/dEnums/dCommonVars.h +++ b/dCommon/dEnums/dCommonVars.h @@ -27,6 +27,13 @@ constexpr uint32_t highFrameDelta = FRAMES_TO_MS(highFramerate); constexpr uint32_t mediumFrameDelta = FRAMES_TO_MS(mediumFramerate); constexpr uint32_t lowFrameDelta = FRAMES_TO_MS(lowFramerate); +//========== CLIENT VERSION DEFAULTS =========== +namespace ClientVersion { + constexpr uint16_t major = 1; + constexpr uint16_t current = 10; + constexpr uint16_t minor = 64; +} + //========== MACROS =========== #define HEADER_SIZE 8 diff --git a/dGame/dComponents/TriggerComponent.cpp b/dGame/dComponents/TriggerComponent.cpp index 1a1cd171..eae0476e 100644 --- a/dGame/dComponents/TriggerComponent.cpp +++ b/dGame/dComponents/TriggerComponent.cpp @@ -22,8 +22,8 @@ TriggerComponent::TriggerComponent(Entity* parent, const std::string triggerInfo std::vector tokens = GeneralUtils::SplitString(triggerInfo, ':'); - const auto sceneID = GeneralUtils::TryParse(tokens.at(0)).value(); - const auto triggerID = GeneralUtils::TryParse(tokens.at(1)).value(); + const auto sceneID = GeneralUtils::TryParse(tokens.at(0)).value_or(0); + const auto triggerID = GeneralUtils::TryParse(tokens.at(1)).value_or(0); m_Trigger = Game::zoneManager->GetZone()->GetTrigger(sceneID, triggerID); @@ -189,7 +189,7 @@ void TriggerComponent::HandleFireEvent(Entity* targetEntity, std::string args) { } void TriggerComponent::HandleDestroyObject(Entity* targetEntity, std::string args){ - const eKillType killType = GeneralUtils::TryParse(args).value_or(eKillType::SILENT); + const eKillType killType = GeneralUtils::TryParse(args).value_or(eKillType::VIOLENT); targetEntity->Smash(m_Parent->GetObjectID(), killType); } @@ -254,7 +254,7 @@ void TriggerComponent::HandleRepelObject(Entity* targetEntity, std::string args) LOG_DEBUG("Phantom Physics component not found!"); return; } - const float forceMultiplier = GeneralUtils::TryParse(args).value(); + const float forceMultiplier = GeneralUtils::TryParse(args).value_or(1.0f); phantomPhysicsComponent->SetPhysicsEffectActive(true); phantomPhysicsComponent->SetEffectType(ePhysicsEffectType::REPULSE); @@ -356,7 +356,7 @@ void TriggerComponent::HandleCastSkill(Entity* targetEntity, std::string args){ LOG_DEBUG("Skill component not found!"); return; } - const uint32_t skillId = GeneralUtils::TryParse(args).value(); + const uint32_t skillId = GeneralUtils::TryParse(args).value_or(0); skillComponent->CastSkill(skillId, targetEntity->GetObjectID()); } diff --git a/dGame/dPropertyBehaviors/ControlBehaviorMessages/BehaviorMessageBase.cpp b/dGame/dPropertyBehaviors/ControlBehaviorMessages/BehaviorMessageBase.cpp index 0aad74dd..b3f240d1 100644 --- a/dGame/dPropertyBehaviors/ControlBehaviorMessages/BehaviorMessageBase.cpp +++ b/dGame/dPropertyBehaviors/ControlBehaviorMessages/BehaviorMessageBase.cpp @@ -5,7 +5,7 @@ #include "dCommonVars.h" BehaviorMessageBase::BehaviorMessageBase(AMFArrayValue* arguments) { - this->behaviorId = GetBehaviorIdFromArgument(arguments); + m_BehaviorId = GetBehaviorIdFromArgument(arguments); } int32_t BehaviorMessageBase::GetBehaviorIdFromArgument(AMFArrayValue* arguments) { @@ -13,13 +13,13 @@ int32_t BehaviorMessageBase::GetBehaviorIdFromArgument(AMFArrayValue* arguments) auto* behaviorIDValue = arguments->Get(key); if (behaviorIDValue && behaviorIDValue->GetValueType() == eAmf::String) { - this->behaviorId = - GeneralUtils::TryParse(behaviorIDValue->GetValue()).value_or(this->behaviorId); + m_BehaviorId = + GeneralUtils::TryParse(behaviorIDValue->GetValue()).value_or(m_BehaviorId); } else if (arguments->Get(key) && arguments->Get(key)->GetValueType() != eAmf::Undefined) { throw std::invalid_argument("Unable to find behavior ID"); } - return this->behaviorId; + return m_BehaviorId; } int32_t BehaviorMessageBase::GetActionIndexFromArgument(AMFArrayValue* arguments, const std::string& keyName) { diff --git a/dGame/dPropertyBehaviors/ControlBehaviorMessages/BehaviorMessageBase.h b/dGame/dPropertyBehaviors/ControlBehaviorMessages/BehaviorMessageBase.h index 8a841d7f..374ef30f 100644 --- a/dGame/dPropertyBehaviors/ControlBehaviorMessages/BehaviorMessageBase.h +++ b/dGame/dPropertyBehaviors/ControlBehaviorMessages/BehaviorMessageBase.h @@ -16,13 +16,13 @@ enum class BehaviorState : uint32_t; class BehaviorMessageBase { public: static inline int32_t DefaultBehaviorId = -1; - const int32_t GetBehaviorId() const { return behaviorId; }; - bool IsDefaultBehaviorId() { return behaviorId == DefaultBehaviorId; }; + const int32_t GetBehaviorId() const { return m_BehaviorId; }; + bool IsDefaultBehaviorId() { return m_BehaviorId == DefaultBehaviorId; }; BehaviorMessageBase(AMFArrayValue* arguments); protected: int32_t GetBehaviorIdFromArgument(AMFArrayValue* arguments); int32_t GetActionIndexFromArgument(AMFArrayValue* arguments, const std::string& keyName = "actionIndex"); - int32_t behaviorId = DefaultBehaviorId; + int32_t m_BehaviorId = DefaultBehaviorId; }; #endif //!__BEHAVIORMESSAGEBASE__H__ diff --git a/dGame/dUtilities/SlashCommandHandler.cpp b/dGame/dUtilities/SlashCommandHandler.cpp index 2c720d54..b4d1c787 100644 --- a/dGame/dUtilities/SlashCommandHandler.cpp +++ b/dGame/dUtilities/SlashCommandHandler.cpp @@ -1902,8 +1902,6 @@ void SlashCommandHandler::HandleChatCommand(const std::u16string& command, Entit if (chatCommand == "inspect" && entity->GetGMLevel() >= eGameMasterLevel::DEVELOPER && args.size() >= 1) { Entity* closest = nullptr; - //eReplicaComponentType component; - std::u16string ldf; bool isLDF = false; diff --git a/dMasterServer/InstanceManager.cpp b/dMasterServer/InstanceManager.cpp index 44ef66c4..4f64f418 100644 --- a/dMasterServer/InstanceManager.cpp +++ b/dMasterServer/InstanceManager.cpp @@ -18,7 +18,7 @@ InstanceManager::InstanceManager(Logger* logger, const std::string& externalIP) mLogger = logger; mExternalIP = externalIP; m_LastPort = - GeneralUtils::TryParse(Game::config->GetValue("world_port_start")).value_or(m_LastPort); + GeneralUtils::TryParse(Game::config->GetValue("world_port_start")).value_or(m_LastPort); m_LastInstanceID = LWOINSTANCEID_INVALID; } diff --git a/dNet/AuthPackets.cpp b/dNet/AuthPackets.cpp index 1f254569..49210853 100644 --- a/dNet/AuthPackets.cpp +++ b/dNet/AuthPackets.cpp @@ -241,12 +241,12 @@ void AuthPackets::SendLoginResponse(dServer* server, const SystemAddress& sysAdd loginResponse.Write(LUString(Game::config->GetValue("event_7"))); loginResponse.Write(LUString(Game::config->GetValue("event_8"))); - uint16_t version_major = 1; - uint16_t version_current = 10; - uint16_t version_minor = 64; - version_major = GeneralUtils::TryParse(Game::config->GetValue("version_major")).value_or(version_major); - version_current = GeneralUtils::TryParse(Game::config->GetValue("version_current")).value_or(version_current); - version_minor = GeneralUtils::TryParse(Game::config->GetValue("version_minor")).value_or(version_minor); + const uint16_t version_major = + GeneralUtils::TryParse(Game::config->GetValue("version_major")).value_or(ClientVersion::major); + const uint16_t version_current = + GeneralUtils::TryParse(Game::config->GetValue("version_current")).value_or(ClientVersion::current); + const uint16_t version_minor = + GeneralUtils::TryParse(Game::config->GetValue("version_minor")).value_or(ClientVersion::minor); loginResponse.Write(version_major); loginResponse.Write(version_current); diff --git a/dScripts/02_server/Map/AM/AmSkullkinTower.cpp b/dScripts/02_server/Map/AM/AmSkullkinTower.cpp index 371ff743..1eaad3c9 100644 --- a/dScripts/02_server/Map/AM/AmSkullkinTower.cpp +++ b/dScripts/02_server/Map/AM/AmSkullkinTower.cpp @@ -144,7 +144,7 @@ void AmSkullkinTower::OnChildRemoved(Entity* self, Entity* child) { ); for (const auto& mission : missions) { - const auto missionID = GeneralUtils::TryParse(mission); + const auto missionID = GeneralUtils::TryParse(mission); if (!missionID) continue; missionIDs.push_back(missionID.value()); diff --git a/dZoneManager/Level.cpp b/dZoneManager/Level.cpp index eae71b80..01d63888 100644 --- a/dZoneManager/Level.cpp +++ b/dZoneManager/Level.cpp @@ -211,12 +211,12 @@ void Level::ReadSceneObjectDataChunk(std::istream& file, Header& header) { CDFeatureGatingTable* featureGatingTable = CDClientManager::Instance().GetTable(); CDFeatureGating gating; - gating.major = 1; - gating.current = 10; - gating.minor = 64; - gating.major = GeneralUtils::TryParse(Game::config->GetValue("version_major")).value_or(gating.major); - gating.current = GeneralUtils::TryParse(Game::config->GetValue("version_current")).value_or(gating.current); - gating.minor = GeneralUtils::TryParse(Game::config->GetValue("version_minor")).value_or(gating.minor); + gating.major = + GeneralUtils::TryParse(Game::config->GetValue("version_major")).value_or(ClientVersion::major); + gating.current = + GeneralUtils::TryParse(Game::config->GetValue("version_current")).value_or(ClientVersion::current); + gating.minor = + GeneralUtils::TryParse(Game::config->GetValue("version_minor")).value_or(ClientVersion::minor); const auto zoneControlObject = Game::zoneManager->GetZoneControlObject(); DluAssert(zoneControlObject != nullptr);